Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
Fix for 130314,
Fix for response to ISO Address Claim
Fix for Device Information
  • Loading branch information
ttlappalainen committed Jun 5, 2017
1 parent 9af1b7a commit 2b13a91
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
17 changes: 17 additions & 0 deletions Examples/DataDisplay2/DataDisplay2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void COGSOG(const tN2kMsg &N2kMsg);
void GNSS(const tN2kMsg &N2kMsg);
void Attitude(const tN2kMsg &N2kMsg);
void Heading(const tN2kMsg &N2kMsg);
void Pressure(const tN2kMsg &N2kMsg);

tNMEA2000Handler NMEA2000Handlers[]={
{126992L,&SystemTime},
Expand All @@ -54,6 +55,7 @@ tNMEA2000Handler NMEA2000Handlers[]={
{129029L,&GNSS},
{130310L,&OutsideEnvironmental},
{130312L,&Temperature},
{130314L,&Pressure},
{130316L,&TemperatureExt},
{0,0}
};
Expand Down Expand Up @@ -284,6 +286,21 @@ void Temperature(const tN2kMsg &N2kMsg) {
}
}

//*****************************************************************************
void Pressure(const tN2kMsg &N2kMsg) {
unsigned char SID;
unsigned char Instance;
tN2kPressureSource PressureSource;
double ActualPressure;

if ( ParseN2kPressure(N2kMsg,SID,Instance,PressureSource,ActualPressure) ) {
OutputStream->print("Pressure source: "); PrintN2kEnumType(PressureSource,OutputStream,false);
PrintLabelValWithConversionCheckUnDef(", pressure: ",ActualPressure,&PascalTomBar,true);
} else {
OutputStream->print("Failed to parse PGN: "); OutputStream->println(N2kMsg.PGN);
}
}

//*****************************************************************************
void TemperatureExt(const tN2kMsg &N2kMsg) {
unsigned char SID;
Expand Down
3 changes: 3 additions & 0 deletions Examples/MessageSender/MessageSender.ino
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ void SendN2kSlowData() {
SetN2kBinaryStatus(N2kMsg,2,N2kOnOff_On,N2kOnOff_Unavailable,N2kOnOff_Off);
NMEA2000.SendMsg(N2kMsg);

SetN2kPressure(N2kMsg,0,2,N2kps_Atmospheric,mBarToPascal(1024));
NMEA2000.SendMsg(N2kMsg);

tN2kBinaryStatus SwitchBoard;
N2kResetBinaryStatus(SwitchBoard);
N2kSetStatusBinaryOnStatus(SwitchBoard,N2kOnOff_On,7);
Expand Down
2 changes: 1 addition & 1 deletion N2kMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ void SetN2kPGN130314(tN2kMsg &N2kMsg, unsigned char SID, unsigned char PressureI
}

bool ParseN2kPGN130314(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &PressureInstance,
tN2kPressureSource &PressureSource, double ActualPressure) {
tN2kPressureSource &PressureSource, double &ActualPressure) {
if (N2kMsg.PGN != 130314L) return false;
int Index = 0;
SID=N2kMsg.GetByte(Index);
Expand Down
2 changes: 1 addition & 1 deletion N2kMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ inline void SetN2kPressure(tN2kMsg &N2kMsg, unsigned char SID, unsigned char Pre
SetN2kPGN130314(N2kMsg, SID, PressureInstance, PressureSource, Pressure);
}
bool ParseN2kPGN130314(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &PressureInstance,
tN2kPressureSource &PressureSource, double Pressure);
tN2kPressureSource &PressureSource, double &Pressure);
inline bool ParseN2kPressure(const tN2kMsg &N2kMsg, unsigned char &SID, unsigned char &PressureInstance,
tN2kPressureSource &PressureSource, double &Pressure) {
return ParseN2kPGN130314(N2kMsg, SID, PressureInstance, PressureSource, Pressure);
Expand Down
3 changes: 3 additions & 0 deletions N2kMessagesEnumToStr.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,7 @@ MakeN2kEnumTypeToStrFunc(tN2kTransmissionGear,tN2kTransmissionGearStrs)
const char* tN2kOnOffStrs[] = { "0", "1", "err", "NA" };
MakeN2kEnumTypeToStrFunc(tN2kOnOff,tN2kOnOffStrs)

const char* tN2kPressureStrs[] = { "atmospheric", "water", "steam", "compressed air", "Hydraulic" };
MakeN2kEnumTypeToStrFunc(tN2kPressureSource,tN2kPressureStrs)

#endif
4 changes: 2 additions & 2 deletions NMEA2000.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,8 @@ bool tNMEA2000::SendConfigurationInformation(int DeviceIndex) {
void tNMEA2000::RespondISORequest(const tN2kMsg &N2kMsg, unsigned long RequestedPGN, int iDev) {
switch (RequestedPGN) {
case 60928L: /*ISO Address Claim*/ // Someone is asking others to claim their addresses
SendIsoAddressClaim(N2kMsg.Source,iDev);
// I tracked traffic of my devices and noticed that they respond with broadcast address instead of caller address.
SendIsoAddressClaim(0xff,iDev);
break;
case 126464L:
HandlePGNListRequest(N2kMsg.Source,iDev);
Expand Down Expand Up @@ -912,7 +913,6 @@ void tNMEA2000::HandleISOAddressClaim(const tN2kMsg &N2kMsg) {

//*****************************************************************************
void tNMEA2000::HandleCommandedAddress(const tN2kMsg &N2kMsg) {
return;
//Serial.print(millis()); Serial.print(" Commanded address:"); Serial.println(N2kMsg.Destination);
int iDev=FindSourceDeviceIndex(N2kMsg.Destination);
if ( N2kMsg.Destination!=0xff && iDev==-1) return; // if destination is not for us, we do nothing
Expand Down
2 changes: 1 addition & 1 deletion NMEA2000.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class tDeviceInformation {
unsigned char GetDeviceFunction() { return DeviceInformation.DeviceFunction; }
void SetDeviceClass(unsigned char _DeviceClass) { DeviceInformation.DeviceClass=((_DeviceClass&0x7f)<<1); }
unsigned char GetDeviceClass() { return DeviceInformation.DeviceClass>>1; }
void SetIndustryGroup(unsigned char _IndustryGroup) { DeviceInformation.IndustryGroupAndSystemInstance=(DeviceInformation.IndustryGroupAndSystemInstance&0x0f) | (_IndustryGroup<<4); }
void SetIndustryGroup(unsigned char _IndustryGroup) { DeviceInformation.IndustryGroupAndSystemInstance=(DeviceInformation.IndustryGroupAndSystemInstance&0x0f) | (_IndustryGroup<<4) | 0x80; }
unsigned char GetIndustryGroup() { return DeviceInformation.IndustryGroupAndSystemInstance>>4; }
void SetSystemInstance(unsigned char _SystemInstance) { DeviceInformation.IndustryGroupAndSystemInstance=(DeviceInformation.IndustryGroupAndSystemInstance&0xf0) | (_SystemInstance&0x0f); }
unsigned char GetSystemInstance() { return DeviceInformation.IndustryGroupAndSystemInstance&0x0f; }
Expand Down

0 comments on commit 2b13a91

Please sign in to comment.