Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / telemetry / smartport.h
blob0a682b2165c1037e565e3273ba8733dfd6c56130
1 /*
2 * smartport.h
4 * Created on: 25 October 2014
5 * Author: Frank26080115
6 */
8 #pragma once
10 #include <stdbool.h>
11 #include <stdint.h>
13 #include "common/time.h"
15 #define SMARTPORT_MSP_TX_BUF_SIZE 256
16 #define SMARTPORT_MSP_RX_BUF_SIZE 64
18 enum
20 FSSP_START_STOP = 0x7E,
22 FSSP_DLE = 0x7D,
23 FSSP_DLE_XOR = 0x20,
25 FSSP_DATA_FRAME = 0x10,
26 FSSP_MSPC_FRAME_SMARTPORT = 0x30, // MSP client frame
27 FSSP_MSPC_FRAME_FPORT = 0x31, // MSP client frame
28 FSSP_MSPS_FRAME = 0x32, // MSP server frame
30 // ID of sensor. Must be something that is polled by FrSky RX
31 FSSP_SENSOR_ID1 = 0x1B,
32 FSSP_SENSOR_ID2 = 0x0D,
33 FSSP_SENSOR_ID3 = 0x34,
34 FSSP_SENSOR_ID4 = 0x67
35 // there are 32 ID's polled by smartport master
36 // remaining 3 bits are crc (according to comments in openTx code)
39 typedef struct smartPortPayload_s {
40 uint8_t frameId;
41 uint16_t valueId;
42 uint32_t data;
43 } __attribute__((packed)) smartPortPayload_t;
45 typedef void smartPortWriteFrameFn(const smartPortPayload_t *payload);
46 typedef bool smartPortCheckQueueEmptyFn(void);
48 bool initSmartPortTelemetry(void);
49 void checkSmartPortTelemetryState(void);
50 bool initSmartPortTelemetryExternal(smartPortWriteFrameFn *smartPortWriteFrameExternal);
52 void handleSmartPortTelemetry(void);
53 void processSmartPortTelemetry(smartPortPayload_t *payload, volatile bool *hasRequest, const uint32_t *requestTimeout);
55 smartPortPayload_t *smartPortDataReceive(uint16_t c, bool *clearToSend, smartPortCheckQueueEmptyFn *checkQueueEmpty, bool withChecksum);
57 struct serialPort_s;
58 void smartPortWriteFrameSerial(const smartPortPayload_t *payload, struct serialPort_s *port, uint16_t checksum);
59 void smartPortSendByte(uint8_t c, uint16_t *checksum, struct serialPort_s *port);
60 bool smartPortPayloadContainsMSP(const smartPortPayload_t *payload);