commit 1801afeb4f76c04cee51d3de918b7bdcfd138305 Author: cfif Date: Thu May 29 11:51:36 2025 +0300 Изменения на новый модем GSM diff --git a/Inc/AtGsmA76xx.h b/Inc/AtGsmA76xx.h new file mode 100644 index 0000000..c117d79 --- /dev/null +++ b/Inc/AtGsmA76xx.h @@ -0,0 +1,33 @@ +// +// Created by cfif on 25.01.23. +// + +#ifndef GONEC_GSM_ATGGMSIM800F_H +#define GONEC_GSM_ATGGMSIM800F_H + +#include +#include "AtCmdCommonProtected.h" +#include "AsciiStringParsingUtils.h" +#include "AtGsm_NetworkRegistrationStatus.h" + +// +// Created by cfif on 25.01.23. +// +#include "AtGsmA76xx.h" +#include "stdlib.h" + +// начало-------------------------- Служебные ---------------------------------------------------------------------- +// начало-------------------------- Служебные ---------------------------------------------------------------------- +// начало-------------------------- Служебные ---------------------------------------------------------------------- + +// IMEI +AtCommandResult AtGsm_Simcom_A76xx_GET_CGSN(tAtCmd *env, char *acpString, size_t *acpStringLen); +AtCommandResult AtGsm_Simcom_A76xx_CCID(tAtCmd *env, char *acpString, size_t *acpStringLen); + + +// конец-------------------------- Служебные ---------------------------------------------------------------------- +// конец-------------------------- Служебные ---------------------------------------------------------------------- +// конец-------------------------- Служебные ---------------------------------------------------------------------- + + +#endif //GONEC_GSM_ATGGMSIM800F_H diff --git a/Src/AtGsmA76xx.c b/Src/AtGsmA76xx.c new file mode 100644 index 0000000..aa92ae7 --- /dev/null +++ b/Src/AtGsmA76xx.c @@ -0,0 +1,91 @@ +// +// Created by cfif on 25.01.23. +// +#include "AtGsmA76xx.h" +#include "stdlib.h" +#include "memory.h" + +// начало-------------------------- Служебные ---------------------------------------------------------------------- +// начало-------------------------- Служебные ---------------------------------------------------------------------- +// начало-------------------------- Служебные ---------------------------------------------------------------------- + +// IMEI +AtCommandResult AtGsm_Simcom_A76xx_GET_CGSN(tAtCmd *env, char *acpString, size_t *acpStringLen) { + AtCmdPrepare(env); + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CGSN"); + AtCmdTxSendLn(env); + + + uint32_t timeout = env->stdRxTimeout; + uint32_t endMs = SystemGetMs() + timeout; + uint32_t leftMs = timeout; + + while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) { + leftMs = endMs - SystemGetMs(); + + if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + + } else if (AtCmdRxBeginWithStatic(env, "AT+CGSN")) { + while (AtCmdReceiveNextLine(env, 1000) == AT_OK) { + *acpStringLen = env->rxBuffer.len - 2; + memcpy(acpString, env->rxBuffer.data, *acpStringLen); + AtCmdRxClear(env); + return AtCmdOkErrAnswer(env, env->stdRxTimeout); + } + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + +AtCommandResult AtGsm_Simcom_A76xx_CCID(tAtCmd *env, char *acpString, size_t *acpStringLen) { + AtCmdPrepare(env); + + AtCmdTxClear(env); + AtCmdTxAddStatic(env, "AT+CICCID"); + AtCmdTxSendLn(env); + + + uint32_t timeout = env->stdRxTimeout; + uint32_t endMs = SystemGetMs() + timeout; + uint32_t leftMs = timeout; + + while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) { + leftMs = endMs - SystemGetMs(); + + if (AtCmdRxBeginWithStatic(env, "ERROR")) { + AtCmdRxClear(env); + return AT_ERROR; + + } else if (AtCmdRxBeginWithStatic(env, "+CCID: ")) { + while (AtCmdReceiveNextLine(env, 1000) == AT_OK) { + char *start = env->rxBuffer.data + sizeof("+CCID:"); + *acpStringLen = env->rxBuffer.len - sizeof("+CCID:") - 2; + memcpy(acpString, start, *acpStringLen); + AtCmdRxClear(env); + return AtCmdOkErrAnswer(env, env->stdRxTimeout); + } + + } else { + AtCmdProcessUnresolvedLine(env); + AtCmdRxClear(env); + continue; + } + } + + return AT_TIMEOUT; +} + + +// конец-------------------------- Служебные ---------------------------------------------------------------------- +// конец-------------------------- Служебные ---------------------------------------------------------------------- +// конец-------------------------- Служебные ---------------------------------------------------------------------- + diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..df826f8 --- /dev/null +++ b/modular.json @@ -0,0 +1,22 @@ +{ + "dep": [ + { + "type": "git", + "provider": "GONEC_NEW", + "repo": "AsciiStringAssemblingUtils" + }, + { + "type": "git", + "provider": "GONEC_NEW", + "repo": "AtGsmCommon" + } + ], + "cmake": { + "inc_dirs": [ + "Inc" + ], + "srcs": [ + "Src/**.c" + ] + } +} \ No newline at end of file