63 lines
1.6 KiB
C
Executable File
63 lines
1.6 KiB
C
Executable File
//
|
|
// Created by xemon on 15.12.22.
|
|
//
|
|
#include <SystemDelayInterface.h>
|
|
#include "AtCmdCommonProtected.h"
|
|
#include "AsciiStringParsingUtils.h"
|
|
#include "AtGsm_NetworkRegistrationStatus.h"
|
|
|
|
AtCommandResult AtGsm_NetworkRegistrationStatus(
|
|
tAtCmd *env,
|
|
tAtGsm_NetworkRegistrationReportMode *mode,
|
|
tAtGsm_NetworkRegistrationState *state
|
|
) {
|
|
|
|
|
|
AtCmdPrepare(env);
|
|
AtCmdSendStatic(env, "AT+CREG?\r\n");
|
|
|
|
|
|
uint32_t timeout = 5000;
|
|
uint32_t endMs = SystemGetMs() + timeout;
|
|
uint32_t leftMs = timeout;
|
|
|
|
while (AtCmdReceiveNextLine(env, leftMs) == AT_OK) {
|
|
leftMs = endMs - SystemGetMs();
|
|
|
|
if (AtCmdRxBeginWithStatic(env, "AT+CREG")) {
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
|
|
} else if (AtCmdRxBeginWithStatic(env, "OK")) {
|
|
AtCmdRxClear(env);
|
|
return AT_OK;
|
|
|
|
} else if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
AtCmdRxClear(env);
|
|
return AT_ERROR;
|
|
|
|
} else if (AtCmdRxBeginWithStatic(env, "+CREG: ")) {
|
|
|
|
char *front;
|
|
char *div = env->rxBuffer.data + sizeof("+CREG:");
|
|
char *end = div + env->rxBuffer.len;
|
|
|
|
if (iAsciiStringMoveToNextParsingBlock(&front, &div, end, ',')) {
|
|
*(char *) mode = *front;
|
|
}
|
|
|
|
if (iAsciiStringMoveToNextParsingBlock(&front, &div, end, ',')) {
|
|
*(char *) state = *front;
|
|
}
|
|
|
|
AtCmdRxClear(env);
|
|
} else {
|
|
AtCmdProcessUnresolvedLine(env);
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return AT_ERROR;
|
|
}
|