CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_EFI/AP_EFI_Serial_MS.h
Views: 1798
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
#pragma once
16
17
#include "AP_EFI_config.h"
18
19
#if AP_EFI_SERIAL_MS_ENABLED
20
21
#include "AP_EFI.h"
22
#include "AP_EFI_Backend.h"
23
24
// RPM Threshold for fuel consumption estimator
25
#define RPM_THRESHOLD 100
26
27
class AP_EFI_Serial_MS: public AP_EFI_Backend {
28
29
public:
30
// Constructor with initialization
31
AP_EFI_Serial_MS(AP_EFI &_frontend);
32
33
// Update the state structure
34
void update() override;
35
36
private:
37
AP_HAL::UARTDriver *port;
38
void parse_realtime_data();
39
bool read_incoming_realtime_data();
40
void send_request(uint8_t table, uint16_t first_offset, uint16_t last_offset);
41
uint8_t read_byte_CRC32();
42
uint32_t CRC32_compute_byte(uint32_t inCrc32, uint8_t data);
43
44
// Serial Protocol Variables
45
uint32_t checksum;
46
uint8_t step;
47
uint8_t response_flag;
48
uint16_t message_counter;
49
uint32_t last_request_ms;
50
51
// confirmed that last command was ok
52
bool last_command_confirmed;
53
54
// Command Response Codes
55
enum response_codes {
56
RESPONSE_WRITE_OK =0x00,
57
RESPONSE_REALTIME_DATA,
58
RESPONSE_PAGE_DATA,
59
RESPONSE_CONFIG_ERROR,
60
RESPONSE_PAGE10_OK,
61
RESPONSE_CAN_DATA,
62
// Error Responses
63
ERR_UNDERRUN = 0X80,
64
ERR_OVERRUN,
65
ERR_CRC_FAILURE,
66
ERR_UNRECOGNIZED_COMMAND,
67
ERR_OUT_OF_RANGE,
68
ERR_SERIAL_BUSY,
69
ERR_FLASH_LOCKED,
70
ERR_SEQ_FAIL_1,
71
ERR_SEQ_FAIL_2,
72
ERR_CAN_QUEUE_FULL,
73
ERR_CAN_TIMEOUT,
74
ERR_CAN_FAILURE,
75
ERR_PARITY,
76
ERR_FRAMING,
77
ERR_SERIAL_NOISE,
78
ERR_TXMODE_RANGE,
79
ERR_UNKNOWN
80
};
81
82
// Realtime Data Table Locations
83
enum realtime_data {
84
PW1_MSB = 2,
85
PW1_LSB,
86
RPM_MSB = 6,
87
RPM_LSB,
88
ADVANCE_MSB,
89
ADVANCE_LSB,
90
ENGINE_BM = 11,
91
BAROMETER_MSB = 16,
92
BAROMETER_LSB,
93
MAP_MSB,
94
MAP_LSB,
95
MAT_MSB,
96
MAT_LSB,
97
CHT_MSB,
98
CHT_LSB,
99
TPS_MSB,
100
TPS_LSB,
101
AFR1_MSB = 28,
102
AFR1_LSB,
103
AFR2_MSB,
104
AFR2_LSB,
105
DWELL_MSB = 62,
106
DWELL_LSB,
107
LOAD = 66,
108
FUEL_PRESSURE_MSB = 128,
109
FUEL_PRESSURE_LSB,
110
// Helpers used when sending request
111
RT_FIRST_OFFSET = PW1_MSB,
112
RT_LAST_OFFSET = FUEL_PRESSURE_LSB
113
};
114
};
115
116
#endif // AP_EFI_SERIAL_MS_ENABLED
117
118