-
Notifications
You must be signed in to change notification settings - Fork 1
/
seatalk_wifi.h
158 lines (134 loc) · 4.83 KB
/
seatalk_wifi.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Anthony Tonizzo - 2022
#ifndef __SEATALK_WIFI_H__
#define __SEATALK_WIFI_H__
typedef enum
{
// The SM_STATE_SEEK_CMD looks for a byte from
// the input data stream that comes with the
// parity bit set.
SM_STATE_SEEK_CMD = 0,
// The SM_STATE_PAYLOAD collects the payload
// bytes for the specific command just received
// during the SM_STATE_SEEK_CMD state. The number
// of bytes to receive is held in the
// seatalk_commands[] structure.
SM_STATE_PAYLOAD = 1,
// The SM_STATE_SANITY_CHECK is meant to check if
// the stream of payload bytes that was received
// is correct.
SM_STATE_SANITY_CHECK = 2,
// The SM_STATE_FORMAT state extract any relevant
// information from the payload bytes.
SM_STATE_FORMAT = 3,
// The SM_STATE_SEND state creates the NMEA sentence
// and sends it out via the nmea_server.
SM_STATE_SEND = 4,
// The SM_STATE_PRETTYPRINT state prints out a message
// to log the SeaTalk sentence that was just processed.
SM_STATE_PRETTYPRINT = 5,
} sm_state_t;
typedef enum
{
SEATALK_APPARENT_WIND_ANGLE = 0x10,
SEATALK_APPARENT_WIND_SPEED = 0x11,
SEATALK_LAMP_INTENSITY = 0x30,
SEATALK_UNSUPPORTED = 0xFFFF,
} seatalk_cmd_t;
struct __cmd
{
seatalk_cmd_t cmd; // Command byte.
uint8_t bytes; // Number of bytes other than the
// command byte.
const char *cmd_name; // Command name for pretty print.
};
typedef enum
{
TEXT_ATTRIB_NORMAL = 00,
TEXT_ATTRIB_FG_BLACK = 30,
TEXT_ATTRIB_FG_RED = 31,
TEXT_ATTRIB_FG_GREEN = 32,
TEXT_ATTRIB_FG_YELLOW = 33,
TEXT_ATTRIB_FG_BLUE = 34,
TEXT_ATTRIB_FG_MAGENTA = 35,
TEXT_ATTRIB_FG_CYAN = 36,
TEXT_ATTRIB_FG_WHITE = 37,
TEXT_ATTRIB_BG_BLACK = 40,
TEXT_ATTRIB_BG_RED = 41,
TEXT_ATTRIB_BG_GREEN = 42,
TEXT_ATTRIB_BG_YELLOW = 43,
TEXT_ATTRIB_BG_BLUE = 44,
TEXT_ATTRIB_BG_MAGENTA = 45,
TEXT_ATTRIB_BG_CYAN = 46,
TEXT_ATTRIB_BG_WHITE = 47
} text_attribute_t;
#define SEATALK_CMD_COLUMN 32
#define SEATALK_ARG_COLUMN 60
#define SEATALK_DATARATE 4800
#define LOGPORT_DATARATE 115200
#define NMEA_SERVER_DEFAULT_PORT 3030
#define NMEA_DEFAULT_TALKER "LR"
struct __status
{
volatile uint32_t serial_logger : 1;
volatile uint32_t telnet_logger : 1;
volatile uint32_t slogger_baudrate : 3;
volatile uint32_t colorize_prettyprint : 1;
volatile uint32_t activity_led : 1;
volatile uint32_t wifi_power : 8;
volatile uint32_t enable_ota : 1;
volatile uint32_t signalk_udp_enable : 1;
uint32_t : 15;
};
typedef struct __status status_t;
struct __wind_data
{
volatile uint32_t filter_angle_enable : 1;
volatile uint32_t filter_speed_enable : 1;
volatile uint32_t angle_ma_length : 8;
volatile uint32_t speed_ma_length : 8;
uint32_t : 14;
};
typedef struct __wind_data wind_data_t;
struct __sensor_data
{
volatile status_t status;
volatile uint32_t nmea_port;
volatile uint8_t hostname[32];
volatile uint8_t nmea_talker[3];
wind_data_t wind_data;
volatile uint8_t signalk_udp_ip[4];
volatile uint32_t signalk_udp_port;
volatile uint8_t reserved[1];
volatile uint32_t magic_number;
};
typedef struct __sensor_data sensor_data_t;
extern sensor_data_t sensor_data, sensor_data_mem;
#define FIRMWARE_VERSION "2.0"
#define EEPROM_SIZE sizeof(sensor_data_t)
#define MAGIC_NUMBER 0xABBACAFE
#define DEFAULT_HOSTNAME "wind"
#define WIND_ANGLE_FILTER_TAPS 16
extern unsigned int wind_angle_history[WIND_ANGLE_FILTER_TAPS];
extern unsigned int last_wind_angle;
#define WIND_SPEED_FILTER_TAPS 16
extern unsigned int wind_speed_history[WIND_SPEED_FILTER_TAPS];
extern unsigned int last_wind_speed;
#define ACTIVITY_LED 12
#define DEFAULT_SIGNALK_SOURCE "Raymarine ST40 Wind"
extern const int baudrates[];
void print_attribute(text_attribute_t);
unsigned long float_to_str(char *, float, int);
extern const char homepage[];
#endif