SELKIELogger  1.0.0
N2KTypes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Swansea University
3  *
4  * This file is part of the SELKIELogger suite of tools.
5  *
6  * SELKIELogger is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * SELKIELogger is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this SELKIELogger product.
18  * If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef SELKIELoggerN2K_Types
22 #define SELKIELoggerN2K_Types
23 
34 #include "SELKIELoggerBase.h"
35 #include <stdbool.h>
36 #include <stdint.h>
37 
43 /*
44  * Logic from CANHandler.cs
45 
46  * N2kFrame build process
47  *
48  * Extract Header
49  * If fast packet (multipart message):
50  * Check if part of existing sequence in pending list
51  * If end of sequence, assemble data and return
52  * Else, add to pending list and return nothing
53  * Else if valid start of fast packet sequence, add to pending list
54  * Else, discard and return nothing
55  * Else
56  * Return Frame
57  *
58  */
59 
60 /*
61  * From CANReader
62  * Actisense devices:
63  *
64  */
65 
66 #define ACT_ESC 0x10
67 #define ACT_SOT 0x02
68 #define ACT_EOT 0x03
69 #define ACT_N2K 0x93
70 #define ACT_BEM 0xA0
71 
80 typedef struct {
81  // Header not stored: ACT_ESC ACT_SOT ACT_N2K
82  uint8_t length;
83  uint8_t priority;
84  uint32_t PGN;
85  uint8_t dst;
86  uint8_t src;
87  uint32_t timestamp;
88  uint8_t datalen;
89  uint8_t *data;
95  uint8_t csum;
96  // Footer not stored (ACT_ESC ACT_EOT)
98 
100 bool n2k_act_to_bytes(const n2k_act_message *act, uint8_t **out, size_t *len);
101 
103 bool n2k_act_from_bytes(const uint8_t *in, const size_t len, n2k_act_message **msg, size_t *pos, bool debug);
104 
106 uint8_t n2k_act_checksum(const n2k_act_message *msg);
107 
109 void n2k_act_print(const n2k_act_message *msg);
110 
112 #endif
bool n2k_act_from_bytes(const uint8_t *in, const size_t len, n2k_act_message **msg, size_t *pos, bool debug)
Convert a series of recieved bytes from ACT gateway devices into a message representation.
Definition: N2KTypes.c:98
void n2k_act_print(const n2k_act_message *msg)
Print representation of an n2k_act_message to standard output.
Definition: N2KTypes.c:275
uint8_t n2k_act_checksum(const n2k_act_message *msg)
Calculate checksum for n2k_act_message.
Definition: N2KTypes.c:248
bool n2k_act_to_bytes(const n2k_act_message *act, uint8_t **out, size_t *len)
Convert N2K message to a series of bytes compatible with ACT gateway devices.
Definition: N2KTypes.c:38
uint8_t csum
Definition: N2KTypes.h:95
uint8_t priority
N2K Message priority value.
Definition: N2KTypes.h:83
uint32_t PGN
24 bit PGN identifier
Definition: N2KTypes.h:84
uint8_t * data
Message payload.
Definition: N2KTypes.h:89
uint8_t datalen
Length of *data.
Definition: N2KTypes.h:88
uint8_t dst
Message destination.
Definition: N2KTypes.h:85
uint32_t timestamp
Message timestamp.
Definition: N2KTypes.h:87
uint8_t src
Message source.
Definition: N2KTypes.h:86
uint8_t length
Counted from priority to csum.
Definition: N2KTypes.h:82