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

Merge branch 'wellenvogel:master' into master

This commit is contained in:
norbert-walter
2022-01-25 09:57:35 +01:00
committed by GitHub
10 changed files with 136 additions and 48 deletions

View File

@@ -102,8 +102,8 @@ void GwChannelList::begin(bool fallbackSerial){
theChannels.push_back(channel);
//serial 1
bool serCanRead=false;
bool serCanWrite=false;
bool serCanRead=true;
bool serCanWrite=true;
int serialrx=-1;
int serialtx=-1;
#ifdef GWSERIAL_MODE

View File

@@ -114,6 +114,16 @@ int GwConfigHandler::getInt(const String name,int defaultv) const{
if (!i) return defaultv;
return i->asInt();
}
void GwConfigHandler::stopChanges(){
allowChanges=false;
}
bool GwConfigHandler::setValue(String name,String value){
if (! allowChanges) return false;
GwConfigInterface *i=getConfigItem(name,false);
if (!i) return false;
i->value=value;
return true;
}
void GwNmeaFilter::handleToken(String token, int index){
switch(index){

View File

@@ -14,11 +14,13 @@ class GwConfigHandler: public GwConfigDefinitions{
GwLog *logger;
typedef std::map<String,String> StringMap;
StringMap changedValues;
boolean allowChanges=true;
public:
public:
GwConfigHandler(GwLog *logger);
bool loadConfig();
bool saveConfig();
void stopChanges();
bool updateValue(String name, String value);
bool reset(bool save);
String toString() const;
@@ -27,6 +29,12 @@ class GwConfigHandler: public GwConfigDefinitions{
bool getBool(const String name,bool defaultv=false) const ;
int getInt(const String name,int defaultv=0) const;
GwConfigInterface * getConfigItem(const String name, bool dummy=false) const;
/**
* change the value of a config item
* will become a noop after stopChanges has been called
* !use with care! no checks of the value
*/
bool setValue(String name, String value);
private:
};
#endif

View File

@@ -10,6 +10,13 @@
*/
void exampleInit(GwApi *api){
api->getLogger()->logDebug(GwLog::LOG,"example init running");
//this example is a more or less useless example how you could set some
//config value to a fixed value
//you can only set config values within the init function
//you could also compute this value from some own configuration
//for this example it would make a lot of sense to declare a capability
//to hide this config item from the UI - see header file
api->getConfig()->setValue(api->getConfig()->minXdrInterval,"50");
}
#define INVALID_COORD -99999
class GetBoatDataRequest: public GwMessage{
@@ -84,6 +91,7 @@ void exampleTask(GwApi *api){
bool hasPosition=false;
bool hasPosition2=false;
LOG_DEBUG(GwLog::DEBUG,"example switch ist %s",exampleSwitch?"true":"false");
LOG_DEBUG(GwLog::DEBUG,"minXdrInterval=%d",api->getConfig()->getInt(api->getConfig()->minXdrInterval));
GwApi::BoatValue *longitude=new GwApi::BoatValue(F("Longitude"));
GwApi::BoatValue *latitude=new GwApi::BoatValue(F("Latitude"));
GwApi::BoatValue *testValue=new GwApi::BoatValue(boatItemName);

View File

@@ -43,4 +43,7 @@ DECLARE_INITFUNCTION(exampleInit);
//elements when this capability is set correctly
DECLARE_CAPABILITY(testboard,true);
DECLARE_CAPABILITY(testboard2,true);
//hide some config value
//just set HIDE + the name of the config item to true
DECLARE_CAPABILITY(HIDEminXdrInterval,true);
#endif

View File

@@ -83,11 +83,24 @@ class MyAisDecoder : public AIS::AisDecoder
tN2kMsg N2kMsg;
// PGN129038
SetN2kAISClassAPosition(N2kMsg, _uMsgType, (tN2kAISRepeat)_Repeat, _uMmsi,
_iPosLat / 600000.0, _iPosLon / 600000.0,
_bPosAccuracy, _Raim, _timestamp,
decodeCog(_iCog) , _uSog * knToms / 10.0,
decodeHeading(_iHeading), decodeRot(_iRot), (tN2kAISNavStatus)_uNavstatus);
N2kMsg.SetPGN(129038L);
N2kMsg.Priority = 4;
N2kMsg.AddByte((_Repeat & 0x03) << 6 | (_uMsgType & 0x3f));
N2kMsg.Add4ByteUInt(_uMmsi);
N2kMsg.Add4ByteDouble(_iPosLon / 600000.0, 1e-07);
N2kMsg.Add4ByteDouble(_iPosLat / 600000.0, 1e-07);
N2kMsg.AddByte((_timestamp & 0x3f) << 2 | (_Raim & 0x01) << 1 | (_bPosAccuracy & 0x01));
N2kMsg.Add2ByteUDouble(decodeCog(_iCog), 1e-04);
N2kMsg.Add2ByteUDouble(_uSog * knToms/10.0, 0.01);
N2kMsg.AddByte(0x00); // Communication State (19 bits)
N2kMsg.AddByte(0x00);
N2kMsg.AddByte(0x00); // AIS transceiver information (5 bits)
N2kMsg.Add2ByteUDouble(decodeHeading(_iHeading), 1e-04);
N2kMsg.Add2ByteDouble(decodeRot(_iRot), 3.125E-05); // 1e-3/32.0
N2kMsg.AddByte(0xF0 | (_uNavstatus & 0x0f));
N2kMsg.AddByte(0xff); // Reserved
N2kMsg.AddByte(0xff); // SID (NA)
send(N2kMsg);
}
@@ -124,17 +137,23 @@ class MyAisDecoder : public AIS::AisDecoder
uint16_t eta_days = tNMEA0183Msg::makeTime(tm) / (24UL * 3600UL);
tN2kMsg N2kMsg;
char CS[30];
char Name[30];
char Dest[30];
strncpy(CS, _strCallsign.c_str(), sizeof(CS)-1);
CS[29]=0;
strncpy(Name, _strName.c_str(), sizeof(Name)-1);
Name[29]=0;
strncpy(Dest, _strDestination.c_str(), sizeof(Dest)-1);
Dest[29]=0;
char CS[8];
char Name[21];
char Dest[21];
strncpy(CS, _strCallsign.c_str(), sizeof(CS) - 1);
CS[7] = 0;
for (int i = strlen(CS); i < 7; i++) CS[i] = 32;
strncpy(Name, _strName.c_str(), sizeof(Name) - 1);
Name[20] = 0;
for (int i = strlen(Name); i < 20; i++) Name[i] = 32;
strncpy(Dest, _strDestination.c_str(), sizeof(Dest) - 1);
Dest[20] = 0;
for (int i = strlen(Dest); i < 20; i++) Dest[i] = 32;
// PGN129794
SetN2kAISClassAStatic(N2kMsg, _uMsgType, (tN2kAISRepeat) _repeat, _uMmsi,
_uImo, CS, Name, _uType, _uToBow + _uToStern,
@@ -205,9 +224,10 @@ class MyAisDecoder : public AIS::AisDecoder
// PGN129040
char Name[21] = "";
char Name[21];
strncpy(Name, _strName.c_str(), sizeof(Name)-1);
Name[20]=0;
for (int i = strlen(Name); i < 20; i++) Name[i] = 32;
N2kMsg.SetPGN(129040UL);
N2kMsg.Priority = 4;
@@ -230,6 +250,7 @@ class MyAisDecoder : public AIS::AisDecoder
N2kMsg.AddStr(Name, 20);
N2kMsg.AddByte((_dte & 0x01) | (_assigned & 0x01) << 1) ;
N2kMsg.AddByte(0);
N2kMsg.AddByte(0xff); // Sequence ID (Not Available)
send(N2kMsg);
}
@@ -244,9 +265,11 @@ class MyAisDecoder : public AIS::AisDecoder
//Serial.println("24A");
tN2kMsg N2kMsg;
char Name[30];
strncpy(Name, _strName.c_str(), sizeof(Name)-1);
Name[29]=0;
char Name[21];
strncpy(Name, _strName.c_str(), sizeof(Name) - 1);
Name[20]=0;
for (int i = strlen(Name); i < 20; i++) Name[i] = 32;
// PGN129809
SetN2kAISClassBStaticPartA(N2kMsg, _uMsgType, (tN2kAISRepeat) _repeat, _uMmsi, Name);
@@ -263,13 +286,17 @@ class MyAisDecoder : public AIS::AisDecoder
tN2kMsg N2kMsg;
char CS[30];
char Vendor[30];
char CS[8];
char Vendor[8];
strncpy(CS, _strCallsign.c_str(), sizeof(CS)-1);
CS[29]=0;
strncpy(Vendor, _strVendor.c_str(), sizeof(Vendor)-1);
Vendor[29]=0;
strncpy(CS, _strCallsign.c_str(), sizeof(CS) - 1);
CS[7] = 0;
for (int i = strlen(CS); i < 7; i++) CS[i] = 32;
strncpy(Vendor, _strVendor.c_str(), sizeof(Vendor) - 1);
Vendor[7] = 0;
for (int i = strlen(Vendor); i < 7; i++) Vendor[i] = 32;
// PGN129810
SetN2kAISClassBStaticPartB(N2kMsg, _uMsgType, (tN2kAISRepeat)_repeat, _uMmsi,