WiP: Added URC support to ATParser

This commit is contained in:
Mati
2019-07-17 16:26:59 +02:00
parent f543aee9a6
commit fb2c58f0c2
6 changed files with 107 additions and 31 deletions

View File

@@ -13,6 +13,7 @@
#include "bsp/cellular/bsp_cellular.hpp"
#include "ticks.hpp"
#include "InOutSerialWorker.hpp"
#include "MuxDaemon.hpp"
std::optional<std::unique_ptr<ATParser>>
ATParser::Create(MuxDaemon *mux, InOutSerialWorker *inOutSerial, bsp::Cellular *cellular) {
@@ -25,10 +26,61 @@ ATParser::Create(MuxDaemon *mux, InOutSerialWorker *inOutSerial, bsp::Cellular *
}
}
ATParser::ATParser(MuxDaemon *mux, InOutSerialWorker *inOutSerial, bsp::Cellular *cellular) : mux(mux),inOutSerialWorker(inOutSerial),cellular(cellular) {
ATParser::ATParser(MuxDaemon *mux, InOutSerialWorker *inOutSerial, bsp::Cellular *cellular) : mux(mux),
inOutSerialWorker(
inOutSerial),
cellular(cellular) {
isInitialized = true;
}
std::vector<ATParser::Urc> ATParser::ParseURC() {
std::vector<ATParser::Urc> resp;
size_t maxPos = 0;
cpp_freertos::LockGuard lock(mutex);
auto pos = responseBuffer.find("RDY");
if (pos != std::string::npos) {
resp.push_back(ATParser::Urc::MeInitializationSuccessful);
maxPos = std::max(pos + strlen("RDY"), maxPos);
}
pos = responseBuffer.find("+CFUN: 1");
if (pos != std::string::npos) {
resp.push_back(ATParser::Urc::FullFuncionalityAvailable);
maxPos = std::max(pos + strlen("+CFUN: 1"), maxPos);
}
pos = responseBuffer.find("+CPIN: READY");
if (pos != std::string::npos) {
resp.push_back(ATParser::Urc::SimCardReady);
maxPos = std::max(pos + strlen("+CPIN: READY"), maxPos);
}
pos = responseBuffer.find("+QIND: SMS DONE");
if (pos != std::string::npos) {
resp.push_back(ATParser::Urc::SMSInitializationComplete);
maxPos = std::max(pos + strlen("+QIND: SMS DONE"), maxPos);
}
pos = responseBuffer.find("+QIND: PB DONE");
if (pos != std::string::npos) {
resp.push_back(ATParser::Urc::PhonebookInitializationComplete);
maxPos = std::max(pos + strlen("+QIND: PB DONE"), maxPos);
}
// manage string buffer
if(responseBuffer.size() >= maxPos){
responseBuffer.erase();
}
else{
responseBuffer = responseBuffer.substr(maxPos);
}
return resp;
}
int ATParser::ProcessNewData() {
char rawBuffer[256] = {0};
@@ -41,8 +93,17 @@ int ATParser::ProcessNewData() {
}
// Received response data without active request, drop it
else {
responseBuffer.erase();
LOG_INFO("Received unneeded data");
urcs = ParseURC();
// GSM modem is considered as fully operational when it outputs URCs specified below:
// 1) RDY
// 2) +CFUN: 1
// 3) +CPIN: READY
// 4) +QIND: SMS DONE
// 5) +QIND: PB DONE
if(urcs.size() == 5){
mux->StartMultiplexer();
}
}
return 1;
}
@@ -79,13 +140,12 @@ std::vector<std::string> ATParser::SendCommand(const char *cmd, size_t rxCount,
if (tokens.size() < rxCount) {
goto wait_for_data;
}
blockedTaskHandle = nullptr;
return tokens;
} else {
//timeout
blockedTaskHandle = nullptr;
return tokens;
}
blockedTaskHandle = nullptr;
responseBuffer.erase(); // TODO:M.P is it okay to flush buffer here ?
return tokens;
}
std::vector<std::string> ATParser::Tokenizer(std::string &input, uint32_t maxTokenCount,