-
Notifications
You must be signed in to change notification settings - Fork 4
/
NMEA0183AISMsg.h
92 lines (73 loc) · 3.04 KB
/
NMEA0183AISMsg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
NMEA0183AISMsg.h
Copyright (c) 2019 Ronnie Zeiller, www.zeiller.eu
Based on the works of Timo Lappalainen NMEA2000 and NMEA0183 Library
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef _tNMEA0183AISMsg_H_
#define _tNMEA0183AISMsg_H_
#include <NMEA0183Msg.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <stdint.h>
#include <math.h>
#include <string>
#ifndef AIS_MSG_MAX_LEN
#define AIS_MSG_MAX_LEN 100 // maximum length of AIS Payload
#endif
#ifndef AIS_BIN_MAX_LEN
#define AIS_BIN_MAX_LEN 500 // maximum length of AIS Binary Payload (before encoding to Ascii)
#endif
#define BITSET_LENGTH 120
class tNMEA0183AISMsg : public tNMEA0183Msg {
protected: // AIS-NMEA
std::bitset<BITSET_LENGTH> bset;
static const char *EmptyAISField; // 6bits 0 not used yet.....
static const char *AsciChar;
uint16_t iAddPldBin;
char Payload[AIS_MSG_MAX_LEN];
uint8_t iAddPld;
public:
char PayloadBin[AIS_BIN_MAX_LEN];
char PayloadBin2[AIS_BIN_MAX_LEN];
// Clear message
void ClearAIS();
public:
tNMEA0183AISMsg();
const char *GetPayload();
const char *GetPayloadType5_Part1();
const char *GetPayloadType5_Part2();
const char *GetPayloadType24_PartA();
const char *GetPayloadType24_PartB();
const char *GetPayloadBin() const { return PayloadBin; }
const tNMEA0183AISMsg& BuildMsg5Part1(tNMEA0183AISMsg &AISMsgn);
const tNMEA0183AISMsg& BuildMsg5Part2(tNMEA0183AISMsg &AISMsg);
const tNMEA0183AISMsg& BuildMsg24PartA(tNMEA0183AISMsg &AISMsg);
const tNMEA0183AISMsg& BuildMsg24PartB(tNMEA0183AISMsg &AISMsg);
// Generally Used
bool AddIntToPayloadBin(int32_t ival, uint16_t countBits);
bool AddBoolToPayloadBin(bool &bval, uint8_t size);
bool AddEncodedCharToPayloadBin(char *sval, size_t Length);
bool AddEmptyFieldToPayloadBin(uint8_t iBits);
bool ConvertBinaryAISPayloadBinToAscii(const char *payloadbin);
// AIS Helper functions
protected:
inline int32_t aRoundToInt(double x) {
return (x >= 0) ? (int32_t) floor(x + 0.5) : (int32_t) ceil(x - 0.5);
}
};
#endif