-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
protocol.h
149 lines (120 loc) · 3.44 KB
/
protocol.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
/*
* Copyright (C) 2014 OpenUAS
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
/**
* @file modules/digital_cam/catia/protocol.h
*
* |STX|length|... payload=(length-4) bytes ...|Checksum A|Checksum B|
*
* where checksum is computed over length and payload:
* @code
* mora_ck_a = mora_ck_b = length
* for each byte b in payload
* mora_ck_a += b;
* mora_ck_b += mora_ck_a;
* @endcode
*/
#ifndef MORA_TRANSPORT_H
#define MORA_TRANSPORT_H
#include <inttypes.h>
#include <stdbool.h>
#include "std.h"
/////////////////////////////////////////////////////////////////////
// MESSAGES
#define MORA_SHOOT 1
#define MORA_SHOOT_MSG_SIZE (4*10)
// 7 * 4 bytes int32_t
// nr, lat, lon, h, phi, theta, psi
union dc_shot_union {
struct {
int32_t nr;
int32_t lat;
int32_t lon;
int32_t alt;
int32_t phi;
int32_t theta;
int32_t psi;
int32_t vground;
int32_t course;
int32_t groundalt;
} data;
uint8_t bin[MORA_SHOOT_MSG_SIZE];
int32_t i[10];
};
#define MORA_BUFFER_EMPTY 2
// 0 bytes payload: null
#define MORA_PAYLOAD 3
#define MORA_PAYLOAD_MSG_SIZE 70
// 72 bytes
#define MORA_STATUS 4
#define MORA_STATUS_MSG_SIZE (4*2)
// 4*2 bytes
union mora_status_union {
struct mora_status_struct {
uint16_t cpu;
uint16_t threads;
uint16_t shots;
uint16_t extra;
} data;
uint8_t bin[MORA_STATUS_MSG_SIZE];
};
/////////////////////////////////////////////////////////////////////
// SENDING
extern uint8_t mora_ck_a, mora_ck_b;
#define STX 0x99
#define MoraSizeOf(_payload) (_payload+5)
#define MoraPutUint8( _byte) { \
mora_ck_a += _byte; \
mora_ck_b += mora_ck_a; \
CameraLinkTransmit(_byte); \
}
#define MoraHeader(msg_id, payload_len) { \
CameraLinkTransmit(STX); \
uint8_t msg_len = MoraSizeOf( payload_len); \
CameraLinkTransmit(msg_len); \
mora_ck_a = msg_len; mora_ck_b = msg_len; \
MoraPutUint8(msg_id); \
}
#define MoraTrailer() { \
CameraLinkTransmit(mora_ck_a); \
CameraLinkTransmit(mora_ck_b); \
}
#define MoraPut1ByteByAddr( _byte) { \
uint8_t _x = *(_byte); \
MoraPutUint8( _x); \
}
/////////////////////////////////////////////////////////////////////
// PARSING
struct mora_transport {
// generic interface
uint8_t payload[256];
uint8_t error;
uint8_t msg_id;
bool msg_received;
uint8_t payload_len;
// specific pprz transport variables
uint8_t status;
uint8_t payload_idx;
uint8_t ck_a, ck_b;
};
extern struct mora_transport mora_protocol;
void parse_mora(struct mora_transport *t, uint8_t c);
#endif