58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
//
|
|
// Created by cfif on 07.06.2024.
|
|
//
|
|
#include <SystemDelayInterface.h>
|
|
#include "AtCmdCommonProtected.h"
|
|
#include "AsciiStringParsingUtils.h"
|
|
#include "AtGsmEpsNetworkRegistrationStatus.h"
|
|
#include "stdlib.h"
|
|
|
|
AtCommandResult AtGsm_EpsNetworkRegistrationStatus(
|
|
tAtCmd *env,
|
|
uint8_t *status
|
|
) {
|
|
|
|
AtCmdPrepare(env);
|
|
AtCmdRxClear(env);
|
|
AtCmdSendStatic(env, "AT+CNSMOD?\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, "AT+CNSMOD")) {
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
|
|
} else if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
AtCmdRxClear(env);
|
|
return AT_ERROR;
|
|
|
|
} else if (AtCmdRxBeginWithStatic(env, "+CNSMOD: ")) {
|
|
|
|
char *front;
|
|
char *div = env->rxBuffer.data + sizeof("+CNSMOD:") - 1;
|
|
char *end = div + env->rxBuffer.len;
|
|
|
|
if (iAsciiStringMoveToNextParsingBlock(&front, &div, end, ',')) {
|
|
uint8_t n = atoi(front);
|
|
}
|
|
|
|
if (iAsciiStringMoveToNextParsingBlock(&front, &div, end, ',')) {
|
|
*(uint8_t *) status = atoi(front);
|
|
}
|
|
|
|
AtCmdRxClear(env);
|
|
return AT_OK;
|
|
} else {
|
|
AtCmdProcessUnresolvedLine(env);
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return AT_ERROR;
|
|
} |