From 0a3c8470dc6d42a645b0fd6df86262642210f6e7 Mon Sep 17 00:00:00 2001 From: cfif Date: Thu, 19 Dec 2024 14:34:54 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=81=D0=B1=D0=BE=D0=B9=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=B5=D0=BC=D0=BD=D0=B8=D0=BA=D0=B0=20=D0=B8=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=B5=D0=BC=20=D0=BD=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B2=20=D0=B4=D1=80=D1=83=D0=B3=D0=BE=D0=B9=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/AtGsmGNSS.h | 23 ++++++++++ Src/AtGsmGNSS.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 Inc/AtGsmGNSS.h create mode 100644 Src/AtGsmGNSS.c diff --git a/Inc/AtGsmGNSS.h b/Inc/AtGsmGNSS.h new file mode 100644 index 0000000..4e23011 --- /dev/null +++ b/Inc/AtGsmGNSS.h @@ -0,0 +1,23 @@ +// +// Created by cfif on 19.12.2024. +// + +#ifndef UVEOS_ON_NATION_ATGSMGNSS_H +#define UVEOS_ON_NATION_ATGSMGNSS_H + +#include "AtCmdBase.h" + +AtCommandResult AtGsm_ReceiverGnssStartStop( + tAtCmd *env, + bool isStartStop +); + +AtCommandResult AtGsm_ReceiverGnssClearBuffer( + tAtCmd *env +); + +AtCommandResult AtGsm_ReceiverGnssResetColdstart( + tAtCmd *env +); + +#endif //UVEOS_ON_NATION_ATGSMGNSS_H diff --git a/Src/AtGsmGNSS.c b/Src/AtGsmGNSS.c new file mode 100644 index 0000000..3bfa70c --- /dev/null +++ b/Src/AtGsmGNSS.c @@ -0,0 +1,114 @@ +// +// Created by cfif on 19.12.2024. +// +#include +#include "AtCmdCommonProtected.h" +#include "AsciiStringParsingUtils.h" +#include "AtGsmQuerySignalQuality.h" +#include "stdlib.h" + +AtCommandResult AtGsm_ReceiverGnssStartStop( + tAtCmd *env, + bool isStartStop +) { + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT$GPSP="); + AtCmdTxAddChar(env, isStartStop ? '1' : '0'); + AtCmdTxSendLn(env); + + uint32_t timeout = 1000; + uint32_t endMs = SystemGetMs() + timeout; + uint32_t leftMs = timeout; + + while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) { + leftMs = endMs - SystemGetMs(); + + if (AtCmdRxBeginWithStatic(env, "OK")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else if (AtCmdRxBeginWithStatic(env, "+CME ERROR: ")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + +AtCommandResult AtGsm_ReceiverGnssResetColdstart( + tAtCmd *env +) { + + AtCmdPrepare(env); + + AtCmdTxClear(env); + AtCmdSendStatic(env, "AT$GPSR=1\r\n"); + + uint32_t timeout = 1000; + uint32_t endMs = SystemGetMs() + timeout; + uint32_t leftMs = timeout; + + while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) { + leftMs = endMs - SystemGetMs(); + + if (AtCmdRxBeginWithStatic(env, "OK")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else if (AtCmdRxBeginWithStatic(env, "+CME ERROR: ")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + +AtCommandResult AtGsm_ReceiverGnssClearBuffer( + tAtCmd *env +) { + + AtCmdPrepare(env); + + AtCmdTxClear(env); + AtCmdSendStatic(env, "AT$GPSNVRAM=15,0\r\n"); + + uint32_t timeout = 1000; + uint32_t endMs = SystemGetMs() + timeout; + uint32_t leftMs = timeout; + + while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) { + leftMs = endMs - SystemGetMs(); + + if (AtCmdRxBeginWithStatic(env, "OK")) { + AtCmdRxClear(env); + return AT_OK; + } else if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + } else if (AtCmdRxBeginWithStatic(env, "+CME ERROR: ")) { + AtCmdRxClear(env); + return AT_ERROR; + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} \ No newline at end of file