Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
syslink.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
29#include "syslink.h"
30
31const char *syslink_stx = "\xbc\xcf";
32
38
40{
41
42 switch (state->state) {
44 if (c == syslink_stx[state->index]) {
45 state->index++;
46 } else {
47 state->index = 0;
48 }
49
50 if (syslink_stx[state->index] == '\x00') {
52 }
53
54 break;
55
57 msg->type = c;
59 break;
60
62 msg->length = c;
63
64 if (c > SYSLINK_MAX_DATA_LEN) { // Too long
66 } else {
68 }
69
70 state->index = 0;
71 break;
72
74 msg->data[state->index++] = c;
75
76 if (state->index >= msg->length) {
78 state->index = 0;
80 }
81
82 break;
83
85 if (c != msg->cksum[state->index]) {
86 // fail checksum
88 state->index = 0;
89 break;
90 }
91
92 state->index++;
93
94 if (state->index >= (int)sizeof(msg->cksum)) {
96 state->index = 0;
97 return true; // message is correct, return true
98 }
99
100 break;
101 }
102
103 return false;
104
105}
106
107/*
108 Computes Fletcher 8bit checksum per RFC1146
109A := A + D[i]
110B := B + A
111*/
113{
114 uint8_t a = 0, b = 0;
115 uint8_t *Di = (uint8_t *)msg, *end = Di + (2 + msg->length) * sizeof(uint8_t);
116
117 while (Di < end) {
118 a = a + *Di;
119 b = b + a;
120 ++Di;
121 }
122
123 msg->cksum[0] = a;
124 msg->cksum[1] = b;
125}
struct State state
Definition state.c:36
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
uint16_t foo
Definition main_demo5.c:58
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
float b
Definition wedgebug.c:202