mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-14 06:23:07 +01:00
allow to convert 2 rudder instances
This commit is contained in:
@@ -192,7 +192,8 @@ class GwBoatData{
|
||||
GWBOATDATA(double,HDOP,4000,formatDop)
|
||||
GWBOATDATA(double,PDOP,4000,formatDop)
|
||||
GWBOATDATA(double,VDOP,4000,formatDop)
|
||||
GWBOATDATA(double,RPOS,4000,formatCourse) //RudderPosition
|
||||
GWBOATDATA(double,RPOS,4000,formatWind) //RudderPosition
|
||||
GWBOATDATA(double,PRPOS,4000,formatWind) //second rudder pos
|
||||
GWBOATDATA(double,LAT,4000,formatLatitude)
|
||||
GWBOATDATA(double,LON,4000,formatLongitude)
|
||||
GWBOATDATA(double,ALT,4000,formatFixed0) //altitude
|
||||
|
||||
@@ -62,7 +62,6 @@ class N2kToNMEA0183Functions : public N2kDataToNMEA0183
|
||||
{
|
||||
|
||||
private:
|
||||
int minXdrInterval=100; //minimal interval between 2 sends of the same transducer
|
||||
GwXDRMappings *xdrMappings;
|
||||
ConverterList<N2kToNMEA0183Functions,tN2kMsg> converters;
|
||||
std::map<String,unsigned long> lastSendTransducers;
|
||||
@@ -75,7 +74,7 @@ private:
|
||||
auto it=lastSendTransducers.find(entry.transducer);
|
||||
unsigned long now=millis();
|
||||
if (it != lastSendTransducers.end()){
|
||||
if ((it->second + minXdrInterval) > now) return false;
|
||||
if ((it->second + config.minXdrInterval) > now) return false;
|
||||
}
|
||||
lastSendTransducers[entry.transducer]=now;
|
||||
if (! xdrOpened){
|
||||
@@ -611,24 +610,34 @@ private:
|
||||
|
||||
if (ParseN2kRudder(N2kMsg, RudderPosition, Instance, RudderDirectionOrder, AngleOrder))
|
||||
{
|
||||
|
||||
updateDouble(boatData->RPOS, RudderPosition);
|
||||
if (Instance != 0)
|
||||
bool main=false;
|
||||
if (Instance == config.starboardRudderInstance){
|
||||
updateDouble(boatData->RPOS, RudderPosition);
|
||||
main=true;
|
||||
}
|
||||
else if (Instance == config.portRudderInstance){
|
||||
updateDouble(boatData->PRPOS, RudderPosition);
|
||||
}
|
||||
else{
|
||||
return;
|
||||
}
|
||||
|
||||
tNMEA0183Msg NMEA0183Msg;
|
||||
|
||||
if (!NMEA0183Msg.Init("RSA", talkerId))
|
||||
return;
|
||||
if (!NMEA0183Msg.AddDoubleField(formatCourse(RudderPosition)))
|
||||
return;
|
||||
if (!NMEA0183Msg.AddStrField("A"))
|
||||
return;
|
||||
if (!NMEA0183Msg.AddDoubleField(0.0))
|
||||
return;
|
||||
if (!NMEA0183Msg.AddStrField("A"))
|
||||
return;
|
||||
|
||||
if (main){
|
||||
if (!NMEA0183Msg.AddDoubleField(formatWind(RudderPosition)))return;
|
||||
if (!NMEA0183Msg.AddStrField("A"))return;
|
||||
if (!NMEA0183Msg.AddDoubleField(0.0))return;
|
||||
if (!NMEA0183Msg.AddStrField("V"))return;
|
||||
}
|
||||
else{
|
||||
if (!NMEA0183Msg.AddDoubleField(0.0))return;
|
||||
if (!NMEA0183Msg.AddStrField("V"))return;
|
||||
if (!NMEA0183Msg.AddDoubleField(formatWind(RudderPosition)))return;
|
||||
if (!NMEA0183Msg.AddStrField("A"))return;
|
||||
}
|
||||
SendMessage(NMEA0183Msg);
|
||||
}
|
||||
}
|
||||
@@ -1508,7 +1517,7 @@ private:
|
||||
public:
|
||||
N2kToNMEA0183Functions(GwLog *logger, GwBoatData *boatData,
|
||||
SendNMEA0183MessageCallback callback,
|
||||
String talkerId, GwXDRMappings *xdrMappings, int minXdrInterval)
|
||||
String talkerId, GwXDRMappings *xdrMappings, const Config &cfg)
|
||||
: N2kDataToNMEA0183(logger, boatData, callback,talkerId)
|
||||
{
|
||||
LastPosSend = 0;
|
||||
@@ -1518,7 +1527,7 @@ private:
|
||||
this->logger = logger;
|
||||
this->boatData = boatData;
|
||||
this->xdrMappings=xdrMappings;
|
||||
this->minXdrInterval=minXdrInterval;
|
||||
this->config=cfg;
|
||||
registerConverters();
|
||||
}
|
||||
virtual void loop()
|
||||
@@ -1535,8 +1544,8 @@ private:
|
||||
|
||||
N2kDataToNMEA0183* N2kDataToNMEA0183::create(GwLog *logger, GwBoatData *boatData,
|
||||
SendNMEA0183MessageCallback callback, String talkerId, GwXDRMappings *xdrMappings,
|
||||
int minXdrInterval){
|
||||
const N2kDataToNMEA0183::Config &cfg){
|
||||
LOG_DEBUG(GwLog::LOG,"creating N2kToNMEA0183");
|
||||
return new N2kToNMEA0183Functions(logger,boatData,callback, talkerId,xdrMappings,minXdrInterval);
|
||||
return new N2kToNMEA0183Functions(logger,boatData,callback, talkerId,xdrMappings,cfg);
|
||||
}
|
||||
//*****************************************************************************
|
||||
|
||||
@@ -36,8 +36,14 @@ class N2kDataToNMEA0183
|
||||
{
|
||||
public:
|
||||
typedef std::function<void(const tNMEA0183Msg &NMEA0183Msg,int id)> SendNMEA0183MessageCallback;
|
||||
|
||||
class Config{
|
||||
public:
|
||||
int minXdrInterval=100;
|
||||
int starboardRudderInstance=0;
|
||||
int portRudderInstance=-1; //ignore
|
||||
};
|
||||
protected:
|
||||
Config config;
|
||||
GwLog *logger;
|
||||
GwBoatData *boatData;
|
||||
int sourceId=0;
|
||||
@@ -49,7 +55,7 @@ protected:
|
||||
|
||||
public:
|
||||
static N2kDataToNMEA0183* create(GwLog *logger, GwBoatData *boatData, SendNMEA0183MessageCallback callback,
|
||||
String talkerId, GwXDRMappings *xdrMappings,int minXdrInterval=100);
|
||||
String talkerId, GwXDRMappings *xdrMappings,const Config &cfg);
|
||||
virtual void HandleMsg(const tN2kMsg &N2kMsg, int sourceId) = 0;
|
||||
virtual void loop();
|
||||
virtual ~N2kDataToNMEA0183(){}
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
|
||||
class GWDMS22B : public SSISensor{
|
||||
int zero=2047;
|
||||
bool invt=false;
|
||||
public:
|
||||
using SSISensor::SSISensor;
|
||||
virtual bool preinit(GwApi * api){
|
||||
@@ -105,7 +106,8 @@ class GWDMS22B : public SSISensor{
|
||||
LOG_DEBUG(GwLog::ERROR,"unable to measure %s: %d",prefix.c_str(),(int)res);
|
||||
}
|
||||
double resolved=(((int)value-zero)*360.0/mask);
|
||||
LOG_DEBUG(GwLog::LOG,"measure %s : %d, resolved: %f",prefix.c_str(),value,(float)resolved);
|
||||
if (invt) resolved=-resolved;
|
||||
LOG_DEBUG(GwLog::DEBUG,"measure %s : %d, resolved: %f",prefix.c_str(),value,(float)resolved);
|
||||
tN2kMsg msg;
|
||||
SetN2kRudder(msg,DegToRad(resolved),iid);
|
||||
api->sendN2kMessage(msg);
|
||||
@@ -116,6 +118,7 @@ class GWDMS22B : public SSISensor{
|
||||
CFG_GET(iid,PRFX); \
|
||||
CFG_GET(fintv,PRFX); \
|
||||
CFG_GET(zero,PRFX); \
|
||||
CFG_GET(invt,PRFX); \
|
||||
bits=12; \
|
||||
clock=500000; \
|
||||
cs=GW ## PRFX ## _CS; \
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
//for SSI refer to https://www.posital.com/media/posital_media/documents/AbsoluteEncoders_Context_Technology_SSI_AppNote.pdf
|
||||
#ifndef _GWSPISENSOR_H
|
||||
#define _GWSPISENSOR_H
|
||||
#include <driver/spi_master.h>
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
{
|
||||
"b": "1",
|
||||
"i": "11",
|
||||
"n": "11"
|
||||
"n": "0"
|
||||
},
|
||||
{
|
||||
"b": "1",
|
||||
"i": "12",
|
||||
"n": "12"
|
||||
"n": "1"
|
||||
},
|
||||
{
|
||||
"b": "1",
|
||||
@@ -86,6 +86,17 @@
|
||||
"capabilities": {
|
||||
"DMS22B$i": "true"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "DMS22B$iinvt",
|
||||
"label": "DMS22BX$i invert",
|
||||
"type": "boolean",
|
||||
"default": "false",
|
||||
"description": "Invert the direction of the $i. SSI DMS22B rotary encoder (bus $b)",
|
||||
"category": "spisensors$b",
|
||||
"capabilities": {
|
||||
"DMS22B$i": "true"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user