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