114 lines
3.1 KiB
C
114 lines
3.1 KiB
C
//
|
|
// Created by xemon on 15.12.22.
|
|
//
|
|
#include <SystemDelayInterface.h>
|
|
#include "AtCmdCommonProtected.h"
|
|
#include "AsciiStringParsingUtils.h"
|
|
#include "AtGsm_NetworkRegistrationStatus.h"
|
|
//
|
|
//AtCommandResult AtGsm_NetworkRegistration(
|
|
// tAtCmd *env,
|
|
// tAtGsm_NetworkRegistrationReportMode *mode,
|
|
// tAtGsm_NetworkRegistrationState *state
|
|
//) {
|
|
//
|
|
//
|
|
// AtCmdPrepare(env);
|
|
// AtCmdSendStatic(env, "AT+COPS?\r\n");
|
|
//
|
|
//
|
|
// uint32_t timeout = 500;
|
|
// uint32_t endMs = SystemGetMs() + timeout;
|
|
// uint32_t leftMs = timeout;
|
|
//
|
|
// while ((AtCmdReceiveNextLine(env, leftMs) == AT_OK) && (SystemGetMs() < endMs)) {
|
|
// 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;
|
|
//}
|
|
|
|
AtCommandResult AtGsm_NetworkRegistrationStatus(
|
|
tAtCmd *env,
|
|
tAtGsm_NetworkRegistrationReportMode *mode,
|
|
tAtGsm_NetworkRegistrationState *state
|
|
) {
|
|
|
|
|
|
AtCmdPrepare(env);
|
|
AtCmdSendStatic(env, "AT+CREG?\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+CREG")) {
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
} 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);
|
|
return AT_OK;
|
|
} else {
|
|
AtCmdProcessUnresolvedLine(env);
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return AT_ERROR;
|
|
}
|