61 lines
1.6 KiB
C
61 lines
1.6 KiB
C
//
|
|
// Created by cfif on 07.06.2024.
|
|
//
|
|
#include <SystemDelayInterface.h>
|
|
#include "AtCmdCommonProtected.h"
|
|
#include "AsciiStringParsingUtils.h"
|
|
#include "AtGsmQuerySignalQuality.h"
|
|
#include "stdlib.h"
|
|
|
|
AtCommandResult AtGsm_QuerySignalQuality(
|
|
tAtCmd *env,
|
|
uint8_t *rssi
|
|
) {
|
|
|
|
AtCmdPrepare(env);
|
|
AtCmdRxClear(env);
|
|
AtCmdSendStatic(env, "AT+CSQ\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+CSQ")) {
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
|
|
} else if (AtCmdRxBeginWithStatic(env, "ERROR")) {
|
|
AtCmdRxClear(env);
|
|
return AT_ERROR;
|
|
|
|
} else if (AtCmdRxBeginWithStatic(env, "+CSQ: ")) {
|
|
|
|
char *front;
|
|
char *div = env->rxBuffer.data + sizeof("+CSQ:") - 1;
|
|
char *end = div + env->rxBuffer.len;
|
|
|
|
uint8_t Ber = 0;
|
|
uint8_t Rssi = 0;
|
|
if (iAsciiStringMoveToNextParsingBlock(&front, &div, end, ',')) {
|
|
Rssi = atoi(front);
|
|
*(uint8_t *) rssi = Rssi;
|
|
}
|
|
|
|
if (iAsciiStringMoveToNextParsingBlock(&front, &div, end, ',')) {
|
|
Ber = atoi(front);
|
|
}
|
|
|
|
AtCmdRxClear(env);
|
|
return AT_OK;
|
|
} else {
|
|
AtCmdProcessUnresolvedLine(env);
|
|
AtCmdRxClear(env);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return AT_ERROR;
|
|
} |