24#ifndef PROTOCORE_NMEA2000_H
25#define PROTOCORE_NMEA2000_H
29#if PROTOCORE_ENABLE_NMEA2000
36#define N2K_FP_SEQ_SHIFT 5
37#define N2K_FP_FRAME_MASK 0x1Fu
38#define N2K_FP_F0_DATA 6u
39#define N2K_FP_FN_DATA 7u
60 uint8_t buf[PROTOCORE_N2K_FP_MAX];
64uint8_t protocore_n2k_fastpacket_num_frames(uint16_t total_len);
70embed_bool protocore_n2k_fastpacket_build_frame(
CanFrame *out, uint8_t seq, uint8_t frame_idx, uint8_t priority,
71 uint32_t pgn, uint8_t sa, uint8_t da,
const uint8_t *data,
75void protocore_n2k_fastpacket_reset(N2kFastPacketRx *rx);
78N2kFpResult protocore_n2k_fastpacket_feed(N2kFastPacketRx *rx,
const CanFrame *f);
81embed_bool protocore_n2k_build_single(
CanFrame *out, uint8_t priority, uint32_t pgn, uint8_t sa, uint8_t da,
82 const uint8_t *data, uint8_t len);
91#define N2K_PGN_POSITION_RAPID 129025u
92#define N2K_PGN_COG_SOG_RAPID 129026u
93#define N2K_PGN_ENGINE_RAPID 127488u
94#define N2K_PGN_ENGINE_DYNAMIC 127489u
95#define N2K_PGN_WIND_DATA 130306u
96#define N2K_PGN_SPEED 128259u
97#define N2K_PGN_WATER_DEPTH 128267u
98#define N2K_PGN_VESSEL_HEADING 127250u
99#define N2K_PGN_RUDDER 127245u
100#define N2K_PGN_ATTITUDE 127257u
101#define N2K_PGN_TEMPERATURE 130312u
104#define N2K_TEMP_SRC_SEA 0
105#define N2K_TEMP_SRC_OUTSIDE 1
106#define N2K_TEMP_SRC_INSIDE 2
107#define N2K_TEMP_SRC_ENGINE_ROOM 3
108#define N2K_TEMP_SRC_MAIN_CABIN 4
109#define N2K_TEMP_SRC_LIVE_WELL 5
110#define N2K_TEMP_SRC_BAIT_WELL 6
111#define N2K_TEMP_SRC_REFRIGERATION 7
112#define N2K_TEMP_SRC_HEATING_SYSTEM 8
113#define N2K_TEMP_SRC_FREEZER 13
114#define N2K_TEMP_SRC_EXHAUST_GAS 14
117#define N2K_COG_REF_TRUE 0
118#define N2K_COG_REF_MAGNETIC 1
119#define N2K_COG_REF_ERROR 2
120#define N2K_COG_REF_NULL 3
123#define N2K_HEADING_REF_TRUE 0
124#define N2K_HEADING_REF_MAGNETIC 1
127#define N2K_WIND_REF_TRUE_NORTH 0
128#define N2K_WIND_REF_MAGNETIC 1
129#define N2K_WIND_REF_APPARENT 2
130#define N2K_WIND_REF_TRUE_BOAT 3
131#define N2K_WIND_REF_TRUE_WATER 4
146 embed_bool cog_valid;
148 embed_bool sog_valid;
156 embed_bool speed_valid;
158 embed_bool boost_valid;
160 embed_bool tilt_valid;
165#define N2K_RUDDER_NO_ORDER 0
166#define N2K_RUDDER_MOVE_TO_STARBOARD 1
167#define N2K_RUDDER_MOVE_TO_PORT 2
173 uint8_t direction_order;
174 embed_bool angle_order_valid;
175 float angle_order_rad;
176 embed_bool position_valid;
184 embed_bool yaw_valid;
186 embed_bool pitch_valid;
188 embed_bool roll_valid;
199 embed_bool actual_valid;
201 embed_bool set_valid;
211 embed_bool oil_pressure_valid;
212 float oil_pressure_pa;
213 embed_bool oil_temp_valid;
215 embed_bool coolant_temp_valid;
216 float coolant_temp_c;
217 embed_bool alt_voltage_valid;
219 embed_bool fuel_rate_valid;
221 embed_bool engine_hours_valid;
222 uint32_t engine_hours_s;
223 embed_bool coolant_pressure_valid;
224 float coolant_pressure_pa;
225 embed_bool fuel_pressure_valid;
226 float fuel_pressure_pa;
227 uint16_t discrete_status_1;
228 uint16_t discrete_status_2;
229 embed_bool load_valid;
231 embed_bool torque_valid;
239 embed_bool speed_valid;
241 embed_bool angle_valid;
247#define N2K_SPEED_TYPE_PADDLE_WHEEL 0
248#define N2K_SPEED_TYPE_PITOT_TUBE 1
249#define N2K_SPEED_TYPE_DOPPLER 2
250#define N2K_SPEED_TYPE_CORRELATION 3
251#define N2K_SPEED_TYPE_ELECTROMAGNETIC 4
257 embed_bool water_valid;
259 embed_bool ground_valid;
261 uint8_t water_ref_type;
268 embed_bool depth_valid;
277 embed_bool heading_valid;
288embed_bool protocore_n2k_decode_position_rapid(
const uint8_t *payload,
size_t len, N2kPositionRapid *out);
294embed_bool protocore_n2k_decode_cog_sog_rapid(
const uint8_t *payload,
size_t len, N2kCogSogRapid *out);
300embed_bool protocore_n2k_decode_engine_rapid(
const uint8_t *payload,
size_t len, N2kEngineRapid *out);
307embed_bool protocore_n2k_decode_engine_dynamic(
const uint8_t *payload,
size_t len, N2kEngineDynamic *out);
313embed_bool protocore_n2k_decode_rudder(
const uint8_t *payload,
size_t len, N2kRudder *out);
319embed_bool protocore_n2k_decode_attitude(
const uint8_t *payload,
size_t len, N2kAttitude *out);
325embed_bool protocore_n2k_decode_temperature(
const uint8_t *payload,
size_t len, N2kTemperature *out);
332 embed_bool voltage_valid;
334 embed_bool current_valid;
336 embed_bool temp_valid;
346embed_bool protocore_n2k_decode_battery_status(
const uint8_t *payload,
size_t len, N2kBatteryStatus *out);
349#define PROTOCORE_N2K_FLUID_FUEL 0
350#define PROTOCORE_N2K_FLUID_WATER 1
351#define PROTOCORE_N2K_FLUID_GRAY_WATER 2
352#define PROTOCORE_N2K_FLUID_LIVE_WELL 3
353#define PROTOCORE_N2K_FLUID_OIL 4
354#define PROTOCORE_N2K_FLUID_BLACK_WATER 5
361 embed_bool level_valid;
363 embed_bool capacity_valid;
372embed_bool protocore_n2k_decode_fluid_level(
const uint8_t *payload,
size_t len, N2kFluidLevel *out);
375#define PROTOCORE_N2K_PRESSURE_ATMOSPHERIC 0
376#define PROTOCORE_N2K_PRESSURE_WATER 1
377#define PROTOCORE_N2K_PRESSURE_STEAM 2
378#define PROTOCORE_N2K_PRESSURE_COMPRESSED_AIR 3
379#define PROTOCORE_N2K_PRESSURE_HYDRAULIC 4
380#define PROTOCORE_N2K_PRESSURE_FILTER 5
381#define PROTOCORE_N2K_PRESSURE_ALTIMETER_SETTING 6
382#define PROTOCORE_N2K_PRESSURE_OIL 7
383#define PROTOCORE_N2K_PRESSURE_FUEL 8
391 embed_bool pressure_valid;
400embed_bool protocore_n2k_decode_actual_pressure(
const uint8_t *payload,
size_t len, N2kActualPressure *out);
406embed_bool protocore_n2k_decode_wind_data(
const uint8_t *payload,
size_t len, N2kWindData *out);
412embed_bool protocore_n2k_decode_speed(
const uint8_t *payload,
size_t len, N2kSpeed *out);
418embed_bool protocore_n2k_decode_water_depth(
const uint8_t *payload,
size_t len, N2kWaterDepth *out);
424embed_bool protocore_n2k_decode_vessel_heading(
const uint8_t *payload,
size_t len, N2kVesselHeading *out);
EMBED_ENUM_BYTE(ProtoConn, PROTO_NONE=0, PROTO_HTTP=1, PROTO_TELNET=2, PROTO_SSH=3, PROTO_MODBUS=4, PROTO_OPCUA=5, PROTO_SSH_RFWD=6, PROTO_RELAY=7, PROTO_BRIDGE=8, PROTO_NTRIP_CASTER=9, PROTO_MESH=10, PROTO_UDP=11,)
Application protocol spoken on a listener port or connection slot.
Shared CAN 2.0 frame type for the CAN-based industrial codecs (one source of truth).
SAE J1939 message codec (PROTOCORE_ENABLE_J1939) - the heavy-duty-vehicle / agriculture / marine / ge...