This commit is contained in:
cfif 2024-12-09 15:46:51 +03:00
parent e36b7928cd
commit 263b152442
2 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,15 @@
//
// Created by cfif on 07.06.2024.
//
#ifndef SMART_COMPONENTS_ATGSMQUERYSIGNALQUALITY_H
#define SMART_COMPONENTS_ATGSMQUERYSIGNALQUALITY_H
#include "AtCmdBase.h"
AtCommandResult AtGsm_QuerySignalQuality(
tAtCmd *env,
uint8_t *rssi
);
#endif //SMART_COMPONENTS_ATGSMQUERYSIGNALQUALITY_H

View File

@ -0,0 +1,61 @@
//
// 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;
}