Skip to content

Commit 210c155

Browse files
committed
NMEA 4.0 tag block
1 parent c9905c2 commit 210c155

File tree

8 files changed

+315
-49
lines changed

8 files changed

+315
-49
lines changed

Source/IO/File.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ namespace IO
6868
}
6969
}
7070
}
71+
else if (fmt == MessageFormat::NMEA_TAG)
72+
{
73+
for (int i = 0; i < len; i++)
74+
{
75+
if (!filter.include(data[i]))
76+
continue;
77+
78+
file << data[i].getNMEATagBlock();
79+
}
80+
}
7181
else if (fmt == MessageFormat::BINARY_NMEA)
7282
{
7383
for (int i = 0; i < len; i++)

Source/IO/Network.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,16 @@ namespace IO
390390
SendTo((s + "\r\n").c_str());
391391
}
392392
}
393+
else if (fmt == MessageFormat::NMEA_TAG)
394+
{
395+
for (int i = 0; i < len; i++)
396+
{
397+
if (!filter.include(data[i]))
398+
continue;
399+
400+
SendTo(data[i].getNMEATagBlock());
401+
}
402+
}
393403
else if (fmt == MessageFormat::BINARY_NMEA)
394404
{
395405
for (int i = 0; i < len; i++)
@@ -626,6 +636,26 @@ namespace IO
626636
}
627637
}
628638
}
639+
else if (fmt == MessageFormat::NMEA_TAG)
640+
{
641+
for (int i = 0; i < len; i++)
642+
{
643+
if (!filter.include(data[i]))
644+
continue;
645+
646+
if (SendTo(data[i].getNMEATagBlock()) < 0)
647+
{
648+
first_message = true;
649+
if (!persistent)
650+
{
651+
Error() << "TCP feed: requesting termination.";
652+
StopRequest();
653+
}
654+
}
655+
else
656+
first_message = false;
657+
}
658+
}
629659
else if ((fmt == MessageFormat::COMMUNITY_HUB && !first_message) || fmt == MessageFormat::BINARY_NMEA)
630660
{
631661
for (int i = 0; i < len; i++)
@@ -851,6 +881,16 @@ namespace IO
851881
}
852882
}
853883
}
884+
else if (fmt == MessageFormat::NMEA_TAG)
885+
{
886+
for (int i = 0; i < len; i++)
887+
{
888+
if (!filter.include(data[i]))
889+
continue;
890+
891+
SendAllDirect(data[i].getNMEATagBlock());
892+
}
893+
}
854894
else if (fmt == MessageFormat::BINARY_NMEA)
855895
{
856896
for (int i = 0; i < len; i++)

Source/IO/Screen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ namespace IO
5656
switch (fmt)
5757
{
5858
case MessageFormat::NMEA:
59-
case MessageFormat::NMEA_TAG:
6059
for (const auto &s : data[i].NMEA)
6160
std::cout << s << std::endl;
6261
break;
62+
case MessageFormat::NMEA_TAG:
63+
std::cout << data[i].getNMEATagBlock();
64+
break;
6365
case MessageFormat::FULL:
6466
for (const auto &s : data[i].NMEA)
6567
{

Source/Marine/Message.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,39 @@ namespace AIS
132132
return ss.str();
133133
}
134134

135+
std::string Message::getNMEATagBlock() const
136+
{
137+
static int groupId = 0;
138+
groupId = (groupId % 9999) + 1; // Recycle 1-9999
139+
140+
std::string result;
141+
int total = NMEA.size();
142+
int seq = 1;
143+
144+
// Use station ID with 's' prefix as source
145+
std::string src = "s" + std::to_string(station);
146+
147+
for (const auto &nmea : NMEA)
148+
{
149+
std::stringstream tb;
150+
tb << "s:" << src << ",c:" << rxtime << ",g:" << seq << "-" << total << "-" << groupId;
151+
152+
// Calculate checksum for tag block
153+
std::string tbs = tb.str();
154+
int check = 0;
155+
for (char c : tbs)
156+
check ^= c;
157+
158+
std::stringstream ss;
159+
ss << "\\" << tbs << "*" << std::hex << std::uppercase << std::setfill('0') << std::setw(2) << check << "\\" << nmea << "\r\n";
160+
161+
result += ss.str();
162+
seq++;
163+
}
164+
165+
return result;
166+
}
167+
135168
std::string Message::getBinaryNMEA(const TAG &tag, bool crc) const
136169
{
137170
std::string packet;

Source/Marine/Message.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ namespace AIS
7676
}
7777

7878
std::string getNMEAJSON(unsigned mode, float level, float ppm, int status, const std::string &hardware, int version, Type driver, bool include_ss = false, uint32_t ipv4 = 0, const std::string &uid = "") const;
79+
std::string getNMEATagBlock() const;
7980
std::string getBinaryNMEA(const TAG &tag, bool crc = false) const;
8081

8182
std::string getRxTime() const

0 commit comments

Comments
 (0)