diff --git a/lib/api/GwApi.h b/lib/api/GwApi.h index 8d83a63..afef372 100644 --- a/lib/api/GwApi.h +++ b/lib/api/GwApi.h @@ -30,6 +30,52 @@ class GwApi{ const String & getFormat() const{ return format; } + }; + + class Status{ + public: + bool wifiApOn=false; + bool wifiClientOn=false; + bool wifiClientConnected=false; + String wifiApIp; + String systemName; //is also AP SSID + String wifiApPass; + String wifiClientIp; + String wifiClientSSID; + unsigned long usbRx=0; + unsigned long usbTx=0; + unsigned long serRx=0; + unsigned long serTx=0; + unsigned long tcpSerRx=0; + unsigned long tcpSerTx=0; + int tcpClients=0; + unsigned long tcpClRx=0; + unsigned long tcpClTx=0; + bool tcpClientConnected=false; + unsigned long n2kRx=0; + unsigned long n2kTx=0; + void empty(){ + wifiApOn=false; + wifiClientOn=false; + wifiClientConnected=false; + wifiApIp=String(); + systemName=String(); //is also AP SSID + wifiApPass=String(); + wifiClientIp=String(); + wifiClientSSID=String(); + usbRx=0; + usbTx=0; + serRx=0; + serTx=0; + tcpSerRx=0; + tcpSerTx=0; + tcpClients=0; + tcpClRx=0; + tcpClTx=0; + tcpClientConnected=false; + n2kRx=0; + n2kTx=0; + } }; /** * thread safe methods - can directly be called from a user task @@ -58,6 +104,11 @@ class GwApi{ * just make sure to have the list being of appropriate size (numValues) */ virtual void getBoatDataValues(int numValues,BoatValue **list)=0; + + /** + * fill the status information + */ + virtual void getStatus(Status &status); /** * not thread safe methods * accessing boat data must only be executed from within the main thread diff --git a/lib/channel/GwChannel.cpp b/lib/channel/GwChannel.cpp index 40fbd48..451c572 100644 --- a/lib/channel/GwChannel.cpp +++ b/lib/channel/GwChannel.cpp @@ -208,3 +208,12 @@ bool GwChannel::isOwnSource(int id){ if (maxSourceId < 0) return id == sourceId; else return (id >= sourceId && id <= maxSourceId); } + +unsigned long GwChannel::countRx(){ + if (! countIn) return 0UL; + return countIn->getGlobal(); +} +unsigned long GwChannel::countTx(){ + if (! countOut) return 0UL; + return countOut->getGlobal(); +} diff --git a/lib/channel/GwChannel.h b/lib/channel/GwChannel.h index ec7a6c4..c187ba6 100644 --- a/lib/channel/GwChannel.h +++ b/lib/channel/GwChannel.h @@ -71,5 +71,7 @@ class GwChannel{ typedef std::function N2kHandler ; void parseActisense(N2kHandler handler); void sendActisense(const tN2kMsg &msg, int sourceId); + unsigned long countRx(); + unsigned long countTx(); }; diff --git a/lib/channel/GwChannelList.cpp b/lib/channel/GwChannelList.cpp index 72fd8c8..d20a393 100644 --- a/lib/channel/GwChannelList.cpp +++ b/lib/channel/GwChannelList.cpp @@ -190,4 +190,27 @@ GwChannel *GwChannelList::getChannelById(int sourceId){ if ((*it)->isOwnSource(sourceId)) return *it; } return NULL; +} + +void GwChannelList::fillStatus(GwApi::Status &status){ + GwChannel *channel=getChannelById(USB_CHANNEL_ID); + if (channel){ + status.usbRx=channel->countRx(); + status.usbTx=channel->countTx(); + } + channel=getChannelById(SERIAL1_CHANNEL_ID); + if (channel){ + status.serRx=channel->countRx(); + status.serTx=channel->countTx(); + } + channel=getChannelById(MIN_TCP_CHANNEL_ID); + if (channel){ + status.tcpSerRx=channel->countRx(); + status.tcpSerTx=channel->countTx(); + } + channel=getChannelById(TCP_CLIENT_CHANNEL_ID); + if (channel){ + status.tcpClRx=channel->countRx(); + status.tcpClTx=channel->countTx(); + } } \ No newline at end of file diff --git a/lib/channel/GwChannelList.h b/lib/channel/GwChannelList.h index 26329de..cbef1d4 100644 --- a/lib/channel/GwChannelList.h +++ b/lib/channel/GwChannelList.h @@ -6,6 +6,7 @@ #include "GwLog.h" #include "GWConfig.h" #include "GwJsonDocument.h" +#include "GwApi.h" //NMEA message channels #define N2K_CHANNEL_ID 0 @@ -38,6 +39,7 @@ class GwChannelList{ void toJson(GwJsonDocument &doc); //single channel GwChannel *getChannelById(int sourceId); + void fillStatus(GwApi::Status &status); }; diff --git a/lib/counter/GwCounter.h b/lib/counter/GwCounter.h index 6d4be4f..2280328 100644 --- a/lib/counter/GwCounter.h +++ b/lib/counter/GwCounter.h @@ -20,6 +20,7 @@ template class GwCounter{ globalFail=0; globalOk=0; } + unsigned long getGlobal(){return globalOk;} void add(T key){ globalOk++; auto it=okCounter.find(key); diff --git a/lib/exampletask/GwExampleTask.cpp b/lib/exampletask/GwExampleTask.cpp index 57fb613..18c4a77 100644 --- a/lib/exampletask/GwExampleTask.cpp +++ b/lib/exampletask/GwExampleTask.cpp @@ -88,6 +88,7 @@ void exampleTask(GwApi *api){ GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude")); GwApi::BoatValue *testValue=new GwApi::BoatValue(boatItemName); GwApi::BoatValue *valueList[]={longitude,latitude,testValue}; + GwApi::Status status; while(true){ delay(1000); /* @@ -162,6 +163,29 @@ void exampleTask(GwApi *api){ LOG_DEBUG(GwLog::LOG,"%s now invalid",testValue->getName().c_str()); } } + api->getStatus(status); + #define B(v) (v?"true":"false") + LOG_DEBUG(GwLog::LOG,"ST1:ap=%s,wc=%s,cc=%s", + B(status.wifiApOn), + B(status.wifiClientOn), + B(status.wifiClientConnected)); + LOG_DEBUG(GwLog::LOG,"ST2:sn=%s,ai=%s,ap=%s,cs=%s,ci=%s", + status.systemName.c_str(), + status.wifiApIp.c_str(), + status.wifiApPass.c_str(), + status.wifiClientSSID.c_str(), + status.wifiClientIp.c_str()); + LOG_DEBUG(GwLog::LOG,"ST3:ur=%ld,ut=%ld,sr=%ld,st=%ld,tr=%ld,tt=%ld,cr=%ld,ct=%ld,2r=%ld,2t=%ld", + status.usbRx, + status.usbTx, + status.serRx, + status.serTx, + status.tcpSerRx, + status.tcpSerTx, + status.tcpClRx, + status.tcpClTx, + status.n2kRx, + status.n2kTx); } vTaskDelete(NULL); diff --git a/lib/usercode/GwUserCode.cpp b/lib/usercode/GwUserCode.cpp index 6be082d..df5a633 100644 --- a/lib/usercode/GwUserCode.cpp +++ b/lib/usercode/GwUserCode.cpp @@ -99,6 +99,10 @@ public: GWSYNCHRONIZED(mainLock); api->getBoatDataValues(num,list); } + virtual void getStatus(Status &status){ + GWSYNCHRONIZED(mainLock); + api->getStatus(status); + } virtual ~TaskApi(){}; }; diff --git a/lib/wifi/GWWifi.h b/lib/wifi/GWWifi.h index bc75013..4ae3969 100644 --- a/lib/wifi/GWWifi.h +++ b/lib/wifi/GWWifi.h @@ -23,5 +23,7 @@ class GwWifi{ bool clientConnected(); bool connectClient(); String apIP(); + bool isApActive(){return apActive;} + bool isClientActive(){return wifiClient->asBoolean();} }; #endif \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 282f6fb..fd715de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -281,6 +281,20 @@ public: } } } + virtual void getStatus(Status &status){ + status.empty(); + status.wifiApOn=gwWifi.isApActive(); + status.wifiClientOn=gwWifi.isClientActive(); + status.wifiClientConnected=gwWifi.clientConnected(); + status.wifiApIp=gwWifi.apIP(); + status.systemName=systemName->asString(); + status.wifiApPass=config.getString(config.apPassword); + status.wifiClientIp=WiFi.localIP().toString(); + status.wifiClientSSID=config.getString(config.wifiSSID); + status.n2kRx=countNMEA2KIn.getGlobal(); + status.n2kTx=countNMEA2KOut.getGlobal(); + channels.fillStatus(status); + } virtual GwBoatData *getBoatData(){ return &boatData; }