Compare commits

...

8 commits

11 changed files with 136 additions and 63 deletions

View file

@ -25,7 +25,7 @@
*/ */
#include "ovms_log.h" #include "ovms_log.h"
static const char *TAG = "canformat-crtd"; static const char *TAG = "canformat-cs11";
#include <errno.h> #include <errno.h>
#include "pcp.h" #include "pcp.h"

View file

@ -25,44 +25,44 @@
*/ */
#include "ovms_log.h" #include "ovms_log.h"
static const char *TAG = "canformat-lawricel"; static const char *TAG = "canformat-lawicel";
#include <errno.h> #include <errno.h>
#include "pcp.h" #include "pcp.h"
#include "canformat_lawricel.h" #include "canformat_lawicel.h"
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Initialisation and Registration // Initialisation and Registration
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
class OvmsCanFormatLawricelInit class OvmsCanFormatLawicelInit
{ {
public: OvmsCanFormatLawricelInit(); public: OvmsCanFormatLawicelInit();
} MyOvmsCanFormatLawricelTInit __attribute__ ((init_priority (4505))); } MyOvmsCanFormatLawicelTInit __attribute__ ((init_priority (4505)));
OvmsCanFormatLawricelInit::OvmsCanFormatLawricelInit() OvmsCanFormatLawicelInit::OvmsCanFormatLawicelInit()
{ {
ESP_LOGI(TAG, "Registering CAN Format: LAWRICEL (4505)"); ESP_LOGI(TAG, "Registering CAN Format: LAWICEL (4505)");
MyCanFormatFactory.RegisterCanFormat<canformat_lawricel>("lawricel"); MyCanFormatFactory.RegisterCanFormat<canformat_lawicel>("lawicel");
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Base GVRET implementation (utility) // Base GVRET implementation (utility)
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
canformat_lawricel::canformat_lawricel(const char* type) canformat_lawicel::canformat_lawicel(const char* type)
: canformat(type) : canformat(type)
{ {
} }
canformat_lawricel::~canformat_lawricel() canformat_lawicel::~canformat_lawicel()
{ {
} }
std::string canformat_lawricel::get(CAN_log_message_t* message) std::string canformat_lawicel::get(CAN_log_message_t* message)
{ {
char buf[CANFORMAT_LAWRICEL_MAXLEN]; char buf[CANFORMAT_LAWICEL_MAXLEN];
if ((message->type != CAN_LogFrame_RX)&& if ((message->type != CAN_LogFrame_RX)&&
(message->type != CAN_LogFrame_TX)) (message->type != CAN_LogFrame_TX))
@ -87,12 +87,12 @@ std::string canformat_lawricel::get(CAN_log_message_t* message)
return std::string(buf); return std::string(buf);
} }
std::string canformat_lawricel::getheader(struct timeval *time) std::string canformat_lawicel::getheader(struct timeval *time)
{ {
return std::string(""); return std::string("");
} }
size_t canformat_lawricel::put(CAN_log_message_t* message, uint8_t *buffer, size_t len, bool* hasmore, canlogconnection* clc) size_t canformat_lawicel::put(CAN_log_message_t* message, uint8_t *buffer, size_t len, bool* hasmore, canlogconnection* clc)
{ {
if (m_buf.FreeSpace()==0) SetServeDiscarding(true); // Buffer full, so discard from now on if (m_buf.FreeSpace()==0) SetServeDiscarding(true); // Buffer full, so discard from now on
if (IsServeDiscarding()) return len; // Quick return if discarding if (IsServeDiscarding()) return len; // Quick return if discarding

View file

@ -24,18 +24,18 @@
; THE SOFTWARE. ; THE SOFTWARE.
*/ */
#ifndef __CANFORMAT_LAWRICEL_H__ #ifndef __CANFORMAT_LAWICEL_H__
#define __CANFORMAT_LAWRICEL_H__ #define __CANFORMAT_LAWICEL_H__
#include "canformat.h" #include "canformat.h"
#define CANFORMAT_LAWRICEL_MAXLEN 48 #define CANFORMAT_LAWICEL_MAXLEN 48
class canformat_lawricel : public canformat class canformat_lawicel : public canformat
{ {
public: public:
canformat_lawricel(const char* type); canformat_lawicel(const char* type);
virtual ~canformat_lawricel(); virtual ~canformat_lawicel();
public: public:
virtual std::string get(CAN_log_message_t* message); virtual std::string get(CAN_log_message_t* message);
@ -43,4 +43,4 @@ class canformat_lawricel : public canformat
virtual size_t put(CAN_log_message_t* message, uint8_t *buffer, size_t len, bool* hasmore, canlogconnection* clc=NULL); virtual size_t put(CAN_log_message_t* message, uint8_t *buffer, size_t len, bool* hasmore, canlogconnection* clc=NULL);
}; };
#endif // __CANFORMAT_LAWRICEL_H__ #endif // __CANFORMAT_LAWICEL_H__

View file

@ -34,7 +34,6 @@ static const char *TAG = "canlog-tcpclient";
#include "canformat.h" #include "canformat.h"
#include "canlog_tcpclient.h" #include "canlog_tcpclient.h"
#include "ovms_config.h" #include "ovms_config.h"
#include "ovms_peripherals.h"
canlog_tcpclient* MyCanLogTcpClient = NULL; canlog_tcpclient* MyCanLogTcpClient = NULL;
@ -83,9 +82,9 @@ OvmsCanLogTcpClientInit::OvmsCanLogTcpClientInit()
{ {
// We have a place to put our command tree.. // We have a place to put our command tree..
OvmsCommand* start = cmd_can_log_start->RegisterCommand("tcpclient", "CAN logging as TCP client"); OvmsCommand* start = cmd_can_log_start->RegisterCommand("tcpclient", "CAN logging as TCP client");
OvmsCommand* discard = start->RegisterCommand("discard","CAN logging as TCP client (discard mode)"); OvmsCommand* discard = start->RegisterCommand("discard", "CAN logging as TCP client (discard mode)");
OvmsCommand* simulate = start->RegisterCommand("simulate","CAN logging as TCP client (simulate mode)"); OvmsCommand* simulate = start->RegisterCommand("simulate", "CAN logging as TCP client (simulate mode)");
OvmsCommand* transmit = start->RegisterCommand("transmit","CAN logging as TCP client (transmit mode)"); OvmsCommand* transmit = start->RegisterCommand("transmit", "CAN logging as TCP client (transmit mode)");
MyCanFormatFactory.RegisterCommandSet(discard, "Start CAN logging as TCP client (discard mode)", MyCanFormatFactory.RegisterCommandSet(discard, "Start CAN logging as TCP client (discard mode)",
can_log_tcpclient_start, can_log_tcpclient_start,
"<host:port> [filter1] ... [filterN]\n" "<host:port> [filter1] ... [filterN]\n"
@ -164,23 +163,25 @@ bool canlog_tcpclient::Open()
opts.error_string = &err; opts.error_string = &err;
if (mg_connect_opt(mgr, m_path.c_str(), tcMongooseHandler, opts) != NULL) if (mg_connect_opt(mgr, m_path.c_str(), tcMongooseHandler, opts) != NULL)
{ {
return true; // Wait 10s max for connection establishment...
m_connecting.Take(pdMS_TO_TICKS(10*1000));
return m_isopen;
} }
else else
{ {
ESP_LOGE(TAG,"Could not connect to %s",m_path.c_str()); ESP_LOGE(TAG, "Could not connect to %s", m_path.c_str());
return false; return false;
} }
} }
else else
{ {
ESP_LOGI(TAG,"Delay TCP client (as network manager not up)"); ESP_LOGI(TAG, "Delay TCP client (as network manager not up)");
return true; return true;
} }
} }
else else
{ {
ESP_LOGE(TAG,"Network manager is not available"); ESP_LOGE(TAG, "Network manager is not available");
return false; return false;
} }
} }
@ -221,9 +222,9 @@ void canlog_tcpclient::MongooseHandler(struct mg_connection *nc, int ev, void *p
int *success = (int*)p; int *success = (int*)p;
ESP_LOGV(TAG, "MongooseHandler(MG_EV_CONNECT=%d)",*success); ESP_LOGV(TAG, "MongooseHandler(MG_EV_CONNECT=%d)",*success);
if (*success == 0) if (*success == 0)
{ // Successful connection { // Connection successful
OvmsRecMutexLock lock(&m_cmmutex); OvmsRecMutexLock lock(&m_cmmutex);
ESP_LOGI(TAG, "Connection successful to %s",m_path.c_str()); ESP_LOGI(TAG, "Connection successful to %s", m_path.c_str());
canlogconnection* clc = new canlogconnection(this, m_format, m_mode); canlogconnection* clc = new canlogconnection(this, m_format, m_mode);
clc->m_nc = nc; clc->m_nc = nc;
clc->m_peer = m_path; clc->m_peer = m_path;
@ -236,11 +237,11 @@ void canlog_tcpclient::MongooseHandler(struct mg_connection *nc, int ev, void *p
} }
} }
else else
{ { // Connection failed
// Connection failed ESP_LOGE(TAG, "Connection failed to %s", m_path.c_str());
ESP_LOGE(TAG, "Connection failed to %s",m_path.c_str());
m_isopen = false; m_isopen = false;
} }
m_connecting.Give();
} }
break; break;
case MG_EV_CLOSE: case MG_EV_CLOSE:
@ -248,7 +249,7 @@ void canlog_tcpclient::MongooseHandler(struct mg_connection *nc, int ev, void *p
if (m_isopen) if (m_isopen)
{ {
OvmsRecMutexLock lock(&m_cmmutex); OvmsRecMutexLock lock(&m_cmmutex);
ESP_LOGE(TAG,"Disconnected from %s",m_path.c_str()); ESP_LOGE(TAG, "Disconnected from %s", m_path.c_str());
m_isopen = false; m_isopen = false;
auto k = m_connmap.find(nc); auto k = m_connmap.find(nc);
if (k != m_connmap.end()) if (k != m_connmap.end())

View file

@ -31,6 +31,7 @@
#include "canlog.h" #include "canlog.h"
#include "ovms_netmanager.h" #include "ovms_netmanager.h"
#include "ovms_mutex.h" #include "ovms_mutex.h"
#include "ovms_semaphore.h"
class canlog_tcpclient : public canlog class canlog_tcpclient : public canlog
{ {
@ -48,6 +49,7 @@ class canlog_tcpclient : public canlog
public: public:
std::string m_path; std::string m_path;
OvmsSemaphore m_connecting;
}; };
#endif // __CANLOG_TCP_CLIENT_H__ #endif // __CANLOG_TCP_CLIENT_H__

View file

@ -257,6 +257,7 @@ class modemdriver : public InternalRamAllocated
protected: protected:
unsigned int m_powercyclefactor; unsigned int m_powercyclefactor;
modem* m_modem; modem* m_modem;
int m_statuspoller_step;
}; };
template<typename Type> modemdriver* CreateCellularModemDriver() template<typename Type> modemdriver* CreateCellularModemDriver()

View file

@ -61,6 +61,7 @@ modemdriver::modemdriver()
{ {
m_modem = MyPeripherals->m_cellular_modem; m_modem = MyPeripherals->m_cellular_modem;
m_powercyclefactor = 0; m_powercyclefactor = 0;
m_statuspoller_step = 0;
} }
modemdriver::~modemdriver() modemdriver::~modemdriver()
@ -154,11 +155,13 @@ void modemdriver::StatusPoller()
bool modemdriver::State1Leave(modem::modem_state1_t oldstate) bool modemdriver::State1Leave(modem::modem_state1_t oldstate)
{ {
m_statuspoller_step = 0;
return false; return false;
} }
bool modemdriver::State1Enter(modem::modem_state1_t newstate) bool modemdriver::State1Enter(modem::modem_state1_t newstate)
{ {
m_statuspoller_step = 0;
return false; return false;
} }
@ -169,5 +172,9 @@ modem::modem_state1_t modemdriver::State1Activity(modem::modem_state1_t curstate
modem::modem_state1_t modemdriver::State1Ticker1(modem::modem_state1_t curstate) modem::modem_state1_t modemdriver::State1Ticker1(modem::modem_state1_t curstate)
{ {
if (m_statuspoller_step > 0)
{
StatusPoller();
}
return curstate; return curstate;
} }

View file

@ -69,17 +69,43 @@ const char* simcom5360::GetName()
void simcom5360::StatusPoller() void simcom5360::StatusPoller()
{ {
if (m_modem->m_mux != NULL) if (m_modem->m_mux != NULL)
{ m_modem->muxtx(GetMuxChannelPOLL(), "AT+CREG?;+CCLK?;+CSQ;+CPSI?;+COPS?\r\n"); } {
// The ESP32 UART queue has a capacity of 128 bytes, NMEA and PPP data may be
// coming in concurrently, and we cannot use flow control.
// Reduce the queue stress by distributing the status poll:
switch (++m_statuspoller_step)
{
case 1:
m_modem->muxtx(GetMuxChannelPOLL(), "AT+CREG?;+CCLK?;+CSQ\r\n");
// → ~ 55 bytes, e.g.
// +CREG: 1,5 +CCLK: "22/10/02,09:33:27+08" +CSQ: 24,99
break;
case 2:
m_modem->muxtx(GetMuxChannelPOLL(), "AT+CPSI?\r\n");
// → ~ 60 bytes, e.g.
// +CPSI: GSM,Online,262-02,0x011f,14822,4 EGSM 900,-67,0,40-40
break;
case 3:
m_modem->muxtx(GetMuxChannelPOLL(), "AT+COPS?\r\n");
// → ~ 35 bytes, e.g.
// +COPS: 0,0,"vodafone.de Hologram",0
// done, fallthrough:
default:
m_statuspoller_step = 0;
break;
}
}
} }
bool simcom5360::State1Leave(modem::modem_state1_t oldstate) bool simcom5360::State1Leave(modem::modem_state1_t oldstate)
{ {
return false; return modemdriver::State1Leave(oldstate);
} }
bool simcom5360::State1Enter(modem::modem_state1_t newstate) bool simcom5360::State1Enter(modem::modem_state1_t newstate)
{ {
return false; return modemdriver::State1Enter(newstate);
} }
modem::modem_state1_t simcom5360::State1Activity(modem::modem_state1_t curstate) modem::modem_state1_t simcom5360::State1Activity(modem::modem_state1_t curstate)
@ -93,7 +119,7 @@ modem::modem_state1_t simcom5360::State1Activity(modem::modem_state1_t curstate)
return modem::None; return modem::None;
} }
return curstate; return modemdriver::State1Activity(curstate);
} }
modem::modem_state1_t simcom5360::State1Ticker1(modem::modem_state1_t curstate) modem::modem_state1_t simcom5360::State1Ticker1(modem::modem_state1_t curstate)
@ -131,5 +157,5 @@ modem::modem_state1_t simcom5360::State1Ticker1(modem::modem_state1_t curstate)
return modem::None; return modem::None;
} }
return curstate; return modemdriver::State1Ticker1(curstate);
} }

View file

@ -91,7 +91,33 @@ void simcom7600::StartupNMEA()
void simcom7600::StatusPoller() void simcom7600::StatusPoller()
{ {
if (m_modem->m_mux != NULL) if (m_modem->m_mux != NULL)
{ m_modem->muxtx(GetMuxChannelPOLL(), "AT+CREG?;+CGREG?;+CEREG?;+CCLK?;+CSQ;+CPSI?;+COPS?\r\n"); } {
// The ESP32 UART queue has a capacity of 128 bytes, NMEA and PPP data may be
// coming in concurrently, and we cannot use flow control.
// Reduce the queue stress by distributing the status poll:
switch (++m_statuspoller_step)
{
case 1:
m_modem->muxtx(GetMuxChannelPOLL(), "AT+CREG?;+CGREG?;+CEREG?;+CCLK?;+CSQ\r\n");
// → ~ 80 bytes, e.g.
// +CREG: 1,5 +CGREG: 1,5 +CEREG: 1,5 +CCLK: "22/09/09,12:54:41+08" +CSQ: 13,99
break;
case 2:
m_modem->muxtx(GetMuxChannelPOLL(), "AT+CPSI?\r\n");
// → ~ 85 bytes, e.g.
// +CPSI: LTE,Online,262-02,0xB0F5,13179412,448,EUTRAN-BAND1,100,4,4,-122,-1184,-874,9
break;
case 3:
m_modem->muxtx(GetMuxChannelPOLL(), "AT+COPS?\r\n");
// → ~ 35 bytes, e.g.
// +COPS: 0,0,"vodafone.de Hologram",7
// done, fallthrough:
default:
m_statuspoller_step = 0;
break;
}
}
} }
void simcom7600::PowerCycle() void simcom7600::PowerCycle()
@ -111,12 +137,12 @@ void simcom7600::PowerCycle()
bool simcom7600::State1Leave(modem::modem_state1_t oldstate) bool simcom7600::State1Leave(modem::modem_state1_t oldstate)
{ {
return false; return modemdriver::State1Leave(oldstate);
} }
bool simcom7600::State1Enter(modem::modem_state1_t newstate) bool simcom7600::State1Enter(modem::modem_state1_t newstate)
{ {
return false; return modemdriver::State1Enter(newstate);
} }
modem::modem_state1_t simcom7600::State1Activity(modem::modem_state1_t curstate) modem::modem_state1_t simcom7600::State1Activity(modem::modem_state1_t curstate)
@ -130,7 +156,7 @@ modem::modem_state1_t simcom7600::State1Activity(modem::modem_state1_t curstate)
return modem::None; return modem::None;
} }
return curstate; return modemdriver::State1Activity(curstate);
} }
modem::modem_state1_t simcom7600::State1Ticker1(modem::modem_state1_t curstate) modem::modem_state1_t simcom7600::State1Ticker1(modem::modem_state1_t curstate)
@ -156,5 +182,5 @@ modem::modem_state1_t simcom7600::State1Ticker1(modem::modem_state1_t curstate)
return modem::None; return modem::None;
} }
return curstate; return modemdriver::State1Ticker1(curstate);
} }

View file

@ -1075,25 +1075,35 @@ OvmsVehicle::vehicle_command_t OvmsVehicle::CommandStat(int verbosity, OvmsWrite
writer->printf("SOC: %s\n", (char*) StdMetrics.ms_v_bat_soc->AsUnitString("-", Native, 1).c_str()); writer->printf("SOC: %s\n", (char*) StdMetrics.ms_v_bat_soc->AsUnitString("-", Native, 1).c_str());
const char* range_ideal = StdMetrics.ms_v_bat_range_ideal->AsUnitString("-", rangeUnit, 0).c_str(); if (StdMetrics.ms_v_bat_range_ideal->IsDefined())
if (*range_ideal != '-') {
writer->printf("Ideal range: %s\n", range_ideal); const std::string& range_ideal = StdMetrics.ms_v_bat_range_ideal->AsUnitString("-", rangeUnit, 0);
writer->printf("Ideal range: %s\n", range_ideal.c_str());
}
const char* range_est = StdMetrics.ms_v_bat_range_est->AsUnitString("-", rangeUnit, 0).c_str(); if (StdMetrics.ms_v_bat_range_est->IsDefined())
if (*range_est != '-') {
writer->printf("Est. range: %s\n", range_est); const std::string& range_est = StdMetrics.ms_v_bat_range_est->AsUnitString("-", rangeUnit, 0);
writer->printf("Est. range: %s\n", range_est.c_str());
}
const char* odometer = StdMetrics.ms_v_pos_odometer->AsUnitString("-", rangeUnit, 1).c_str(); if (StdMetrics.ms_v_pos_odometer->IsDefined())
if (*odometer != '-') {
writer->printf("ODO: %s\n", odometer); const std::string& odometer = StdMetrics.ms_v_pos_odometer->AsUnitString("-", rangeUnit, 1);
writer->printf("ODO: %s\n", odometer.c_str());
}
const char* cac = StdMetrics.ms_v_bat_cac->AsUnitString("-", Native, 1).c_str(); if (StdMetrics.ms_v_bat_cac->IsDefined())
if (*cac != '-') {
writer->printf("CAC: %s\n", cac); const std::string& cac = StdMetrics.ms_v_bat_cac->AsUnitString("-", Native, 1);
writer->printf("CAC: %s\n", cac.c_str());
}
const char* soh = StdMetrics.ms_v_bat_soh->AsUnitString("-", Native, 0).c_str(); if (StdMetrics.ms_v_bat_soh->IsDefined())
if (*soh != '-') {
writer->printf("SOH: %s\n", soh); const std::string& soh = StdMetrics.ms_v_bat_soh->AsUnitString("-", Native, 0);
writer->printf("SOH: %s\n", soh.c_str());
}
return Success; return Success;
} }

View file

@ -56,8 +56,8 @@ void OvmsVehicleRenaultZoePh2OBD::IncomingLBC(uint16_t type, uint16_t pid, const
StandardMetrics.ms_v_bat_cac->SetValue(Bat_cell_capacity * CAN_UINT(0) * 0.0001); StandardMetrics.ms_v_bat_cac->SetValue(Bat_cell_capacity * CAN_UINT(0) * 0.0001);
ESP_LOGD(TAG, "9002 LBC mt_bat_lbc_soc: %f", bat_soc); //ESP_LOGD(TAG, "9002 LBC mt_bat_lbc_soc: %f", bat_soc);
ESP_LOGD(TAG, "9002 LBC mt_bat_lbc_soc calculated: %f", bat_soc + (bat_soc * 0.03)); //ESP_LOGD(TAG, "9002 LBC mt_bat_lbc_soc calculated: %f", bat_soc + (bat_soc * 0.03));
break; break;
} }
case 0x9003: { //Battery SOH case 0x9003: { //Battery SOH