move serial channel mode to serial channel type (integer)
This commit is contained in:
parent
f36dd37b8b
commit
8c7540d956
|
@ -102,6 +102,29 @@ static SerialParam *getSerialParam(int id){
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void GwChannelList:: addSerial(HardwareSerial *stream,int id,int type,int rx,int tx){
|
||||
const char *mode=nullptr;
|
||||
switch (type)
|
||||
{
|
||||
case GWSERIAL_TYPE_UNI:
|
||||
mode="UNI";
|
||||
break;
|
||||
case GWSERIAL_TYPE_BI:
|
||||
mode="BI";
|
||||
break;
|
||||
case GWSERIAL_TYPE_RX:
|
||||
mode="RX";
|
||||
break;
|
||||
case GWSERIAL_TYPE_TX:
|
||||
mode="TX";
|
||||
break;
|
||||
}
|
||||
if (mode == nullptr) {
|
||||
LOG_DEBUG(GwLog::ERROR,"unknown serial type %d",type);
|
||||
return;
|
||||
}
|
||||
addSerial(stream,id,mode,rx,tx);
|
||||
}
|
||||
void GwChannelList::addSerial(HardwareSerial *serialStream,int id,const String &mode,int rx,int tx){
|
||||
SerialParam *param=getSerialParam(id);
|
||||
if (param == nullptr){
|
||||
|
@ -112,6 +135,7 @@ void GwChannelList::addSerial(HardwareSerial *serialStream,int id,const String &
|
|||
logger->logDebug(GwLog::ERROR,"useless config for serial %d: both rx/tx undefined");
|
||||
return;
|
||||
}
|
||||
modes[id]=String(mode);
|
||||
bool canRead=false;
|
||||
bool canWrite=false;
|
||||
if (mode == "BI"){
|
||||
|
@ -155,6 +179,7 @@ void GwChannelList::addSerial(HardwareSerial *serialStream,int id,const String &
|
|||
LOG_DEBUG(GwLog::LOG, "%s", channel->toString().c_str());
|
||||
theChannels.push_back(channel);
|
||||
}
|
||||
|
||||
void GwChannelList::begin(bool fallbackSerial){
|
||||
LOG_DEBUG(GwLog::DEBUG,"GwChannelList::begin");
|
||||
GwChannel *channel=NULL;
|
||||
|
@ -205,8 +230,12 @@ void GwChannelList::begin(bool fallbackSerial){
|
|||
#ifndef GWSERIAL_RX
|
||||
#define GWSERIAL_RX -1
|
||||
#endif
|
||||
#ifdef GWSERIAL_MODE
|
||||
addSerial(&Serial1,SERIAL1_CHANNEL_ID,GWSERIAL_MODE,GWSERIAL_RX,GWSERIAL_TX);
|
||||
#ifdef GWSERIAL_TYPE
|
||||
addSerial(&Serial1,SERIAL1_CHANNEL_ID,GWSERIAL_TYPE,GWSERIAL_RX,GWSERIAL_TX);
|
||||
#else
|
||||
#ifdef GWSERIAL_MODE
|
||||
addSerial(&Serial1,SERIAL1_CHANNEL_ID,GWSERIAL_MODE,GWSERIAL_RX,GWSERIAL_TX);
|
||||
#endif
|
||||
#endif
|
||||
//serial 2
|
||||
#ifndef GWSERIAL2_TX
|
||||
|
@ -215,8 +244,12 @@ void GwChannelList::begin(bool fallbackSerial){
|
|||
#ifndef GWSERIAL2_RX
|
||||
#define GWSERIAL2_RX -1
|
||||
#endif
|
||||
#ifdef GWSERIAL2_MODE
|
||||
addSerial(&Serial2,SERIAL2_CHANNEL_ID,GWSERIAL2_MODE,GWSERIAL2_RX,GWSERIAL2_TX);
|
||||
#ifdef GWSERIAL2_TYPE
|
||||
addSerial(&Serial2,SERIAL2_CHANNEL_ID,GWSERIAL2_TYPE,GWSERIAL2_RX,GWSERIAL2_TX);
|
||||
#else
|
||||
#ifdef GWSERIAL2_MODE
|
||||
addSerial(&Serial2,SERIAL2_CHANNEL_ID,GWSERIAL2_MODE,GWSERIAL2_RX,GWSERIAL2_TX);
|
||||
#endif
|
||||
#endif
|
||||
//tcp client
|
||||
bool tclEnabled=config->getBool(config->tclEnabled);
|
||||
|
@ -245,6 +278,11 @@ void GwChannelList::begin(bool fallbackSerial){
|
|||
LOG_DEBUG(GwLog::LOG,"%s",channel->toString().c_str());
|
||||
logger->flush();
|
||||
}
|
||||
String GwChannelList::getMode(int id){
|
||||
auto it=modes.find(id);
|
||||
if (it != modes.end()) return it->second;
|
||||
return "UNKNOWN";
|
||||
}
|
||||
int GwChannelList::getJsonSize(){
|
||||
int rt=0;
|
||||
allChannels([&](GwChannel *c){
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <WString.h>
|
||||
#include "GwChannel.h"
|
||||
#include "GwLog.h"
|
||||
|
@ -26,10 +27,11 @@ class GwChannelList{
|
|||
GwConfigHandler *config;
|
||||
typedef std::vector<GwChannel *> ChannelList;
|
||||
ChannelList theChannels;
|
||||
|
||||
std::map<int,String> modes;
|
||||
GwSocketServer *sockets;
|
||||
GwTcpClient *client;
|
||||
void addSerial(HardwareSerial *stream,int id,const String &mode,int rx,int tx);
|
||||
void addSerial(HardwareSerial *stream,int id,int type,int rx,int tx);
|
||||
public:
|
||||
GwChannelList(GwLog *logger, GwConfigHandler *config);
|
||||
typedef std::function<void(GwChannel *)> ChannelAction;
|
||||
|
@ -42,6 +44,6 @@ class GwChannelList{
|
|||
//single channel
|
||||
GwChannel *getChannelById(int sourceId);
|
||||
void fillStatus(GwApi::Status &status);
|
||||
|
||||
String getMode(int id);
|
||||
|
||||
};
|
||||
|
|
|
@ -13,6 +13,11 @@
|
|||
*/
|
||||
#ifndef _GWHARDWARE_H
|
||||
#define _GWHARDWARE_H
|
||||
#define GWSERIAL_TYPE_UNI 1
|
||||
#define GWSERIAL_TYPE_BI 2
|
||||
#define GWSERIAL_TYPE_RX 3
|
||||
#define GWSERIAL_TYPE_TX 4
|
||||
|
||||
#include <HardwareSerial.h>
|
||||
#include "GwUserTasks.h"
|
||||
|
||||
|
@ -117,7 +122,7 @@
|
|||
#define ESP32_CAN_RX_PIN GPIO_NUM_4
|
||||
//serial input only
|
||||
#define GWSERIAL_RX GPIO_NUM_16
|
||||
#define GWSERIAL_MODE "RX"
|
||||
#define GWSERIAL_TYPE GWSERIAL_TYPE_RX
|
||||
|
||||
#define GWBUTTON_PIN GPIO_NUM_0
|
||||
#define GWBUTTON_ACTIVE LOW
|
||||
|
@ -132,26 +137,26 @@
|
|||
#ifdef SERIAL_GROOVE_485
|
||||
#define GWSERIAL_TX GROOVE_PIN_1
|
||||
#define GWSERIAL_RX GROOVE_PIN_2
|
||||
#define GWSERIAL_MODE "UNI"
|
||||
#define GWSERIAL_TYPE GWSERIAL_TYPE_UNI
|
||||
#endif
|
||||
#ifdef SERIAL_GROOVE_232
|
||||
#define GWSERIAL_TX GROOVE_PIN_1
|
||||
#define GWSERIAL_RX GROOVE_PIN_2
|
||||
#define GWSERIAL_MODE "BI"
|
||||
#define GWSERIAL_TYPE GWSERIAL_TYPE_BI
|
||||
#endif
|
||||
|
||||
//M5 Serial (Atomic RS232 Base)
|
||||
#ifdef M5_SERIAL_KIT_232
|
||||
#define GWSERIAL_TX BOARD_LEFT2
|
||||
#define GWSERIAL_RX BOARD_LEFT1
|
||||
#define GWSERIAL_MODE "BI"
|
||||
#define GWSERIAL_TYPE GWSERIAL_TYPE_BI
|
||||
#endif
|
||||
|
||||
//M5 Serial (Atomic RS485 Base)
|
||||
#ifdef M5_SERIAL_KIT_485
|
||||
#define GWSERIAL_TX BOARD_LEFT2
|
||||
#define GWSERIAL_RX BOARD_LEFT1
|
||||
#define GWSERIAL_MODE "UNI"
|
||||
#define GWSERIAL_TYPE GWSERIAL_TYPE_UNI
|
||||
#endif
|
||||
|
||||
//can kit for M5 Atom
|
||||
|
@ -165,5 +170,4 @@
|
|||
#define ESP32_CAN_RX_PIN GROOVE_PIN_2
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
|
16
src/main.cpp
16
src/main.cpp
|
@ -126,7 +126,7 @@ class Nmea2kTwaiLog : public Nmea2kTwai{
|
|||
#define ESP32_CAN_RX_PIN GPIO_NUM_NC
|
||||
#endif
|
||||
|
||||
Nmea2kTwai &NMEA2000=*(new Nmea2kTwaiLog(ESP32_CAN_TX_PIN,ESP32_CAN_RX_PIN,CAN_RECOVERY_PERIOD,&logger));
|
||||
Nmea2kTwai &NMEA2000=*(new Nmea2kTwaiLog((gpio_num_t)ESP32_CAN_TX_PIN,(gpio_num_t)ESP32_CAN_RX_PIN,CAN_RECOVERY_PERIOD,&logger));
|
||||
|
||||
#ifdef GWBUTTON_PIN
|
||||
bool fixedApPass=false;
|
||||
|
@ -433,18 +433,8 @@ class CapabilitiesRequest : public GwRequestMessage{
|
|||
it != userCodeHandler.getCapabilities()->end();it++){
|
||||
json[it->first]=it->second;
|
||||
}
|
||||
#ifdef GWSERIAL_MODE
|
||||
String serial(F(GWSERIAL_MODE));
|
||||
#else
|
||||
String serial(F("NONE"));
|
||||
#endif
|
||||
json["serialmode"]=serial;
|
||||
#ifdef GWSERIAL2_MODE
|
||||
String serial2(F(GWSERIAL2_MODE));
|
||||
#else
|
||||
String serial2(F("NONE"));
|
||||
#endif
|
||||
json["serial2mode"]=serial2;
|
||||
json["serialmode"]=channels.getMode(SERIAL1_CHANNEL_ID);
|
||||
json["serial2mode"]=channels.getMode(SERIAL2_CHANNEL_ID);
|
||||
#ifdef GWBUTTON_PIN
|
||||
json["hardwareReset"]="true";
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue