Original project changes: Enhance "cellular cmd" to show output from modem

This commit is contained in:
Carsten Schmiemann 2022-09-08 11:45:47 +02:00
parent a0ec7148db
commit 7ea81e8fa4
2 changed files with 38 additions and 5 deletions

View File

@ -285,6 +285,8 @@ modem::modem(const char* name, uart_port_t uartnum, int baud, int rxpin, int txp
m_mux = NULL;
m_ppp = NULL;
m_driver = NULL;
m_cmd_running = false;
m_cmd_output.clear();
ClearNetMetrics();
StartTask();
@ -988,6 +990,12 @@ void modem::StandardLineHandler(int channel, OvmsBuffer* buf, std::string line)
if (line.length() == 0)
return;
if ((m_cmd_running)&&(channel == m_mux_channel_CMD))
{
m_cmd_output.append(line);
m_cmd_output.append("\r\n");
}
// expecting continuation of previous line?
if (m_line_unfinished == channel)
{
@ -1139,6 +1147,7 @@ void modem::StandardLineHandler(int channel, OvmsBuffer* buf, std::string line)
MyEvents.SignalEvent("system.modem.simnotinserted", NULL);
StandardMetrics.ms_m_net_mdm_iccid->SetValue(line.substr(12));
}
// MMI/USSD response (URC):
// sent on all free channels, so we only process m_mux_channel_CMD
else if (channel == m_mux_channel_CMD && line.compare(0, 7, "+CUSD: ") == 0)
@ -1592,6 +1601,10 @@ void cellular_muxtx(int verbosity, OvmsWriter* writer, OvmsCommand* cmd, int arg
void cellular_cmd(int verbosity, OvmsWriter* writer, OvmsCommand* cmd, int argc, const char* const* argv)
{
std::string msg;
MyModem->m_cmd_output.clear();
MyModem->m_cmd_running = true;
for (int k=0; k<argc; k++)
{
if (k>0)
@ -1601,14 +1614,31 @@ void cellular_cmd(int verbosity, OvmsWriter* writer, OvmsCommand* cmd, int argc,
msg.append(argv[k]);
}
msg.append("\r\n");
bool sent = MyModem->txcmd(msg.c_str(),msg.length());
if (!MyModem->txcmd(msg.c_str(),msg.length()))
{
if (verbosity >= COMMAND_RESULT_MINIMAL)
{
writer->puts("ERROR: MODEM command channel not available!");
}
return;
}
// Wait for output to stabilise
size_t cmdsize = UINT_MAX;
size_t iter = 0;
while ((MyModem->m_cmd_output.size() != cmdsize) && (iter < 5))
{
iter++;
cmdsize = MyModem->m_cmd_output.size();
vTaskDelay(pdMS_TO_TICKS(500));
}
MyModem->m_cmd_running = false;
if (verbosity >= COMMAND_RESULT_MINIMAL)
{
if (sent)
writer->puts("MODEM command has been sent.");
else
writer->puts("ERROR: MODEM command channel not available!");
writer->write(MyModem->m_cmd_output.c_str(), MyModem->m_cmd_output.size());
}
MyModem->m_cmd_output.clear();
}
void cellular_status(int verbosity, OvmsWriter* writer, OvmsCommand* cmd, int argc, const char* const* argv)

View File

@ -150,6 +150,9 @@ class modem : public pcp, public InternalRamAllocated
GsmPPPOS* m_ppp;
GsmNMEA* m_nmea;
bool m_cmd_running;
std::string m_cmd_output;
public:
// Modem power control and initialisation
virtual void SetPowerMode(PowerMode powermode);