Skip to content

Commit

Permalink
add pgns 130824/130845
Browse files Browse the repository at this point in the history
  • Loading branch information
vyacht committed Nov 7, 2017
1 parent c95f60b commit e576b48
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 24 deletions.
84 changes: 83 additions & 1 deletion driver_vyspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ static gps_mask_t hnd_130306(unsigned char *bu, int len, struct PGN *pgn, struct
static gps_mask_t hnd_130310(unsigned char *bu, int len, struct PGN *pgn, struct gps_device_t *session);
static gps_mask_t hnd_130311(unsigned char *bu, int len, struct PGN *pgn, struct gps_device_t *session);
static gps_mask_t hnd_130312(unsigned char *bu, int len, struct PGN *pgn, struct gps_device_t *session);
static gps_mask_t hnd_130824(unsigned char *bu, int len, struct PGN *pgn, struct gps_device_t *session);
static gps_mask_t hnd_130845(unsigned char *bu, int len, struct PGN *pgn, struct gps_device_t *session);
static gps_mask_t hnd_130850(unsigned char *bu, int len, struct PGN *pgn, struct gps_device_t *session);

static gps_mask_t hnd_unknown(unsigned char *bu, int len, struct PGN *pgn, struct gps_device_t *session);
Expand Down Expand Up @@ -167,8 +169,10 @@ static struct PGN pgnlist[] = {
{130310, 0, 4, 1, 0, hnd_130310, "NAV Water Temp., Outside Air Temp., Atmospheric Pressure"},
{130311, 0, 4, 1, 0, hnd_130311, "NAV Temperature"},
{130312, 0, 4, 1, 0, hnd_130312, "NAV Temperature"},
{130824, 0, 0, 0, 0, hnd_130824, "Maretron: Annunciator"},
{130845, 0, 0, 0, 0, hnd_130845, "Simnet: Compass stuff"},
{130850, 0, 0, 0, 0, hnd_130850, "Simnet Autopilot Commands"},

{ 0, 0, 0, 0, 0, hnd_unknown, "Unkown sentence"},

};
Expand Down Expand Up @@ -3317,6 +3321,81 @@ static gps_mask_t hnd_130312(unsigned char *bu, int len, struct PGN *pgn, struct
return mask;
}

/**
* \todo PGN 130850: Maretron Annuntiator
*/
static gps_mask_t hnd_130824(unsigned char *bu, int len UNUSED, struct PGN *pgn UNUSED, struct gps_device_t *session) {
/*
{ "Maretron: Annunciator", 130824, false, 9, 0,
{ { "Manufacturer Code", 11, RES_MANUFACTURER, false, "=137", "Maretron" }
, { "Reserved", 2, RES_NOTUSED, false, 0, "" }
, { "Industry Code", 3, RES_LOOKUP, false, "=4", "Marine Industry" }
, { "Field 4", BYTES(1), 1, false, 0, "" }
, { "Field 5", BYTES(1), 1, false, 0, "" }
, { "Field 6", BYTES(2), 1, false, 0, "" }
, { "Field 7", BYTES(1), 1, false, 0, "" }
, { "Field 8", BYTES(2), 1, false, 0, "" }
, { 0 }
}
}
*/
uint16_t code = getleu16(bu, 0);

uint16_t man = (code >> 5); // 11 bit manu
uint16_t ind = (code >> 0) & 0x07; // 3 bit industry

print_data(session->context, bu, len, pgn);
gpsd_report(session->context->debug, LOG_DATA,
"pgn %6d(%3d): unkown\n", pgn->pgn, session->driver.nmea2000.unit);
gpsd_report(session->context->debug, LOG_IO,
" manu = %u, ind= %u\n",
man, ind);

return 0;
}

/**
* \todo PGN 130850: Simnet Compass stuff
*/
static gps_mask_t hnd_130845(unsigned char *bu, int len UNUSED, struct PGN *pgn UNUSED, struct gps_device_t *session)
{
/*
{ "Simnet: Compass Heading Offset", 130845, false, 0x0e, 0,
{ { "Manufacturer Code", 11, RES_MANUFACTURER, false, "=1857", "Simrad" }
, { "Reserved", 2, RES_NOTUSED, false, 0, "" }
, { "Industry Code", 3, RES_LOOKUP, false, "=4", "Marine Industry" }
, { "Message ID", 6, 1, false, 0, "" }
, { "Repeat indicator", 2, RES_LOOKUP, false, LOOKUP_REPEAT_INDICATOR, "" }
, { "Unused", BYTES(3), 1, false, 0, "" }
, { "Type", BYTES(2), 1, false, "=0", "Heading Offset" }
, { "A", BYTES(2), RES_NOTUSED, false, 0, "" }
, { "Angle", BYTES(2), RES_RADIANS, true, "rad", "" }
, { "Unused", BYTES(2), RES_NOTUSED, false, 0, "" }
, { 0 }
}
}
*/
uint16_t code = getleu16(bu, 0);

uint16_t man = (code >> 5); // 11 bit manu
// 2 bit - ignored
uint16_t ind = (code >> 0) & 0x07; // 3 bit industry

uint8_t msg_id = (bu[2] >> 2);
uint8_t repeat_id = (bu[2] & 0xfc);

uint16_t type_id = getleu16(bu, 6);

print_data(session->context, bu, len, pgn);
gpsd_report(session->context->debug, LOG_DATA,
"pgn %6d(%3d): unkown\n", pgn->pgn, session->driver.nmea2000.unit);
gpsd_report(session->context->debug, LOG_IO,
" manu = %u, ind= %u, msg= %u, rpt= %u, type= %u\n",
man, ind, msg_id, repeat_id, type_id);

return 0;
}

/**
* \todo PGN 130850: Simnet AP command
*/
Expand Down Expand Up @@ -3350,6 +3429,9 @@ static gps_mask_t hnd_130850(unsigned char *bu, int len UNUSED, struct PGN *pgn
}
*/

print_data(session->context, bu, len, pgn);
gpsd_report(session->context->debug, LOG_DATA,
"pgn %6d(%3d): unkown\n", pgn->pgn, session->driver.nmea2000.unit);
gpsd_report(session->context->debug, LOG_IO,
" manu = %u, ind= %u, prop= %u, dev= %u, ev= %u, dir= %u, deg= %.02f\n",
man, ind, prop_id, dev_id, event, dir_id, rad*RAD_2_DEG * 0.0001);
Expand Down
4 changes: 3 additions & 1 deletion gpssim.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,9 @@ void decode_file(struct gps_device_t * session, char * filename) {
strncpy(buffer, line, end - line); buffer[end - line] = 0;
gpsd_report(session->context->debug, LOG_SPIN,
"Retrieved line %s of length %ld\n", buffer, end - line);
decode_line(session, buffer);

if((end -line) > 0)
decode_line(session, buffer);

} else {

Expand Down
40 changes: 18 additions & 22 deletions nmea2000.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
// #include "printf.h"
#include "gpsd.h"

uint8_t vy_printf(const char *format, ...) {
va_list ap;
va_start(ap, format);
gpsd_report(0, 10, format, ap);
va_end(ap);
return 0;
}
#define vy_printf printf


uint32_t nmea2000_packet_count; // count number of all packets completed (fast and single)
Expand Down Expand Up @@ -76,6 +70,8 @@ uint32_t n2k_fixed_fast_list[] = {
129802,
129809,
129810,
130824,
130845,
130935, // observed in AIS
130842, // observed in AIS
262161,
Expand Down Expand Up @@ -213,8 +209,8 @@ int nmea2000_parsemsg(struct nmea2000_raw_frame * frame) {

if(frame->data[1] > NMEA2000_MAX_PACKET_LENGTH) {

vy_printf("I: <= N2K %lu,fi:%02x,l:%u,s:%02x,d:%02x - ERROR\n",
pgn, (uint16_t)frame->data[0], (uint16_t)frame->data[1], saddr, daddr);
vy_printf("I: <= N2K %u,fi:%02x,l:%u,s:%02x,d:%02x - ERROR\n",
pgn, (uint8_t)frame->data[0], (uint8_t)frame->data[1], saddr, daddr);
nmea2000_packet_error_count++;
return -1;
}
Expand All @@ -229,8 +225,8 @@ int nmea2000_parsemsg(struct nmea2000_raw_frame * frame) {
if(packet->state == incomplete)
nmea2000_packet_cancel_count++;

vy_printf("I: <= N2K %lu,s:%02x,mb:%u,fi:%02x,pl:%u\n",
pgn, saddr, (uint16_t)mb, (uint16_t)frame->data[0], (uint16_t)frame->data[1]);
vy_printf("I: <= N2K %u,s:%02x,mb:%u,fi:%02x,pl:%u\n",
pgn, saddr, (uint16_t)mb, (uint8_t)frame->data[0], (uint8_t)frame->data[1]);

packet->state = incomplete;

Expand All @@ -254,8 +250,8 @@ int nmea2000_parsemsg(struct nmea2000_raw_frame * frame) {
// continue pending fast transmission

if(saddr_packet[saddr] > 0x1F) {
vy_printf("I: <= N2K N2K %lu,s:%02x,os:%02x - ERROR MB\n",
pgn, saddr, (uint16_t)saddr_packet[saddr]);
vy_printf("I: <= N2K N2K %u,s:%02x,os:%02x - ERROR MB\n",
pgn, saddr, (uint8_t)saddr_packet[saddr]);
nmea2000_packet_error_count++;
return -1;
}
Expand All @@ -267,8 +263,8 @@ int nmea2000_parsemsg(struct nmea2000_raw_frame * frame) {

if(packet->saddr != saddr) {
// could be a stale canceled packet that was taken by a new saddr
vy_printf("I: <= N2K N2K %lu,s:%02x,mb:%u,os:%02x - STALE\n",
pgn, saddr, (uint16_t)mb, (uint16_t)packet->saddr);
vy_printf("I: <= N2K %u,s:%02x,mb:%u,os:%02x - STALE\n",
pgn, saddr, (uint8_t)mb, (uint16_t)packet->saddr);
return -1;
}

Expand All @@ -295,12 +291,12 @@ int nmea2000_parsemsg(struct nmea2000_raw_frame * frame) {
packet->ptr = 0;
nmea2000_packet_count++;

vy_printf("I: <= N2K %lu,s:%02x,mb:%u,fi:%02x,fl:%u\n",
pgn, saddr, (uint16_t)mb, (uint16_t)frame->data[0],(uint16_t)frame->len);
vy_printf("I: <= N2K %u,s:%02x,mb:%u,fi:%02x,fl:%u\n",
pgn, saddr, (uint8_t)mb, (uint8_t)frame->data[0],(uint8_t)frame->len);
} else {

vy_printf("I: <= N2K %lu,s:%02x,mb:%u,fi:%02x\n",
pgn, saddr, (uint16_t)mb, (uint16_t)frame->data[0]);
vy_printf("I: <= N2K %u,s:%02x,mb:%u,fi:%02x\n",
pgn, saddr, (uint8_t)mb, (uint8_t)frame->data[0]);
packet->idx += 1;

}
Expand All @@ -310,8 +306,8 @@ int nmea2000_parsemsg(struct nmea2000_raw_frame * frame) {
} else {

// error - missing or wrong index
vy_printf("I: <= N2K %lu,s:%02x,mb:%u,pi:%02x,fi:%02x - ERROR\n",
pgn, saddr, (uint16_t)mb, packet->idx, (uint16_t)frame->data[0]);
vy_printf("I: <= N2K %u,s:%02x,mb:%u,pi:%02x,fi:%02x - ERROR\n",
pgn, saddr, (uint8_t)mb, packet->idx, (uint8_t)frame->data[0]);

packet->idx = 0;
packet->fast_packet_len = 0;
Expand All @@ -331,7 +327,7 @@ int nmea2000_parsemsg(struct nmea2000_raw_frame * frame) {
return -1;
}

vy_printf("I: <= N2K %lu,s:%02x\n", pgn, saddr);
vy_printf("I: <= N2K %u,s:%02x\n", pgn, saddr);
packet = &nmea2000_packets[32];

packet->ptr = 0;
Expand Down

0 comments on commit e576b48

Please sign in to comment.