1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-13 05:53:06 +01:00

add status to Api

This commit is contained in:
wellenvogel
2022-01-03 18:59:17 +01:00
parent 73eee8461e
commit 2a56adf3c5
10 changed files with 132 additions and 0 deletions

View File

@@ -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();
}

View File

@@ -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();
};

View File

@@ -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();
}
}

View File

@@ -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);
};