add status to Api
This commit is contained in:
parent
73eee8461e
commit
2a56adf3c5
lib
api
channel
counter
exampletask
usercode
wifi
src
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -71,5 +71,7 @@ class GwChannel{
|
|||
typedef std::function<void(const tN2kMsg &msg, int sourceId)> N2kHandler ;
|
||||
void parseActisense(N2kHandler handler);
|
||||
void sendActisense(const tN2kMsg &msg, int sourceId);
|
||||
unsigned long countRx();
|
||||
unsigned long countTx();
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -20,6 +20,7 @@ template<class T> class GwCounter{
|
|||
globalFail=0;
|
||||
globalOk=0;
|
||||
}
|
||||
unsigned long getGlobal(){return globalOk;}
|
||||
void add(T key){
|
||||
globalOk++;
|
||||
auto it=okCounter.find(key);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -99,6 +99,10 @@ public:
|
|||
GWSYNCHRONIZED(mainLock);
|
||||
api->getBoatDataValues(num,list);
|
||||
}
|
||||
virtual void getStatus(Status &status){
|
||||
GWSYNCHRONIZED(mainLock);
|
||||
api->getStatus(status);
|
||||
}
|
||||
virtual ~TaskApi(){};
|
||||
};
|
||||
|
||||
|
|
|
@ -23,5 +23,7 @@ class GwWifi{
|
|||
bool clientConnected();
|
||||
bool connectClient();
|
||||
String apIP();
|
||||
bool isApActive(){return apActive;}
|
||||
bool isClientActive(){return wifiClient->asBoolean();}
|
||||
};
|
||||
#endif
|
14
src/main.cpp
14
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue