-
Notifications
You must be signed in to change notification settings - Fork 37
/
packet_handler.h
47 lines (40 loc) · 1.82 KB
/
packet_handler.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
/*
* AIS packet handler for MSP430 + Si4362
* Author: Adrian Studer
* License: CC BY-SA Creative Commons Attribution-ShareAlike
* https://creativecommons.org/licenses/by-sa/4.0/
* Please contact the author if you want to use this work in a closed-source project
*/
#ifndef PACKET_HANDLER_H_
#define PACKET_HANDLER_H_
// functions to manage packet handler operation
void ph_setup(void); // setup packet handler, e.g. configuring input pins
void ph_start(void); // start receiving packages
void ph_stop(void); // stop receiving packages
// packet handler states
enum PH_STATE {
PH_STATE_OFF = 0,
PH_STATE_RESET, // reset/restart packet handler
PH_STATE_WAIT_FOR_SYNC, // wait for preamble (010101..) and start flag (0x7e)
PH_STATE_PREFETCH, // receive first 8 bits of packet
PH_STATE_RECEIVE_PACKET // receive packet payload
};
// packet handler errors
enum PH_ERROR {
PH_ERROR_NONE = 0,
PH_ERROR_STUFFBIT, // invalid stuff-bit
PH_ERROR_NOEND, // no end flag after more than 1020 bits, message too long
PH_ERROR_CRC, // CRC error
PH_ERROR_RSSI_DROP // signal strength fell below threshold
};
uint8_t ph_get_state(void); // get current state of packet handler
uint8_t ph_get_last_error(void); // get last packet handler error, will clear error
uint8_t ph_get_radio_channel(void); // get current radio channel
int16_t ph_get_radio_rssi(void); // get RSSI in dBm at last sync
uint8_t ph_get_message_type(void); // get last AIS message type
// functions to test packet handler operation, DISCONNECT MODEM BEFORE TESTING!
#ifdef TEST
void test_ph_setup(void); // setup pins for emulation
void test_ph_send_packet(const char* message); // send AIS packet in message (NMEA encoded AIS payload http://gpsd.berlios.de/AIVDM.html#_aivdm_aivdo_payload_armoring)
#endif
#endif /* PACKET_HANDLER_H_ */