Skip to content

Commit d844bbf

Browse files
committed
merge branch telemetry-main into main
2 parents 7321b61 + 7def6f0 commit d844bbf

File tree

1,513 files changed

+1059547
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,513 files changed

+1059547
-7
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ Doxygen
3838
# cmake build cache
3939
**/cmake_build
4040

41-
**/.idea
42-
43-
4441
*.iml
4542
mbed-os-build/
4643

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[submodule "ETC/mbed-os"]
2-
path = ETC/mbed-os
3-
url = https://github.com/mbed-ce/mbed-os.git
4-
shallow = true
51
[submodule "BMS/lib-mbed-ltc681x"]
62
path = BMS/lib-mbed-ltc681x
73
url = https://github.com/formulaslug/lib-mbed-ltc681x.git

CANDecoder_bak/CANInterface.hpp

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#ifndef CAN_INTERFACE_HPP
2+
#define CAN_INTERFACE_HPP
3+
4+
#include "mbed.h"
5+
6+
/**
7+
* @brief Abstract interface for CAN communication
8+
* This enables dependency injection and mocking for testing
9+
*/
10+
class ICAN {
11+
public:
12+
virtual ~ICAN() = default;
13+
14+
/**
15+
* @brief Read a CAN message if available
16+
* @param msg Reference to store the received message
17+
* @return true if message was read, false if no message available
18+
*/
19+
virtual bool read(CANMessage& msg) = 0;
20+
21+
/**
22+
* @brief Send a CAN message
23+
* @param msg Message to send
24+
* @return true if message was sent successfully
25+
*/
26+
virtual bool write(const CANMessage& msg) = 0;
27+
28+
/**
29+
* @brief Check if CAN interface is ready
30+
* @return true if ready for communication
31+
*/
32+
virtual bool isReady() const = 0;
33+
};
34+
35+
/**
36+
* @brief Real CAN implementation using mbed CAN
37+
*/
38+
class MbedCAN : public ICAN {
39+
private:
40+
CAN& _can;
41+
42+
public:
43+
explicit MbedCAN(CAN& can) : _can(can) {}
44+
45+
bool read(CANMessage& msg) override {
46+
return _can.read(msg);
47+
}
48+
49+
bool write(const CANMessage& msg) override {
50+
return _can.write(msg);
51+
}
52+
53+
bool isReady() const override {
54+
return true; // mbed CAN is always ready after construction
55+
}
56+
};
57+
58+
/**
59+
* @brief Mock CAN implementation for testing on STM32
60+
*/
61+
class MockCAN : public ICAN {
62+
private:
63+
static constexpr size_t MAX_MESSAGES = 32;
64+
CANMessage _incomingMessages[MAX_MESSAGES];
65+
CANMessage _sentMessages[MAX_MESSAGES];
66+
size_t _incomingCount = 0;
67+
size_t _sentCount = 0;
68+
size_t _messageIndex = 0;
69+
bool _isReady = true;
70+
71+
public:
72+
// Test setup methods
73+
void injectMessage(const CANMessage& msg) {
74+
if (_incomingCount < MAX_MESSAGES) {
75+
_incomingMessages[_incomingCount++] = msg;
76+
}
77+
}
78+
79+
void setReady(bool ready) { _isReady = ready; }
80+
81+
// Verification methods
82+
size_t getSentMessageCount() const { return _sentCount; }
83+
const CANMessage& getSentMessage(size_t index) const { return _sentMessages[index]; }
84+
85+
void clearSentMessages() { _sentCount = 0; }
86+
void clearIncomingMessages() {
87+
_incomingCount = 0;
88+
_messageIndex = 0;
89+
}
90+
91+
// ICAN implementation
92+
bool read(CANMessage& msg) override {
93+
if (_messageIndex >= _incomingCount) {
94+
return false;
95+
}
96+
msg = _incomingMessages[_messageIndex++];
97+
return true;
98+
}
99+
100+
bool write(const CANMessage& msg) override {
101+
if (!_isReady || _sentCount >= MAX_MESSAGES) return false;
102+
_sentMessages[_sentCount++] = msg;
103+
return true;
104+
}
105+
106+
bool isReady() const override {
107+
return _isReady;
108+
}
109+
};
110+
111+
#endif // CAN_INTERFACE_HPP

CANDecoder_bak/CANProtocol.hpp

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
// CANProtocol.hpp
2+
// Types for extracting CAN messages from the CAN bus
3+
// (Refer to ../CANbus.dbc for the protocol)
4+
// Written by: Njeri Gachoka
5+
6+
#ifndef CANPROTOCOL_HPP
7+
#define CANPROTOCOL_HPP
8+
9+
#include "mbed.h"
10+
#include <cstdint>
11+
#include <stdbool.h>
12+
13+
namespace CAN_ID {
14+
// ACC
15+
constexpr uint16_t ACC_STATUS = 0x188;
16+
constexpr uint16_t ACC_SEG0_VOLTS = 0x191;
17+
constexpr uint16_t ACC_SEG1_VOLTS = 0x192;
18+
constexpr uint16_t ACC_SEG2_VOLTS = 0x193;
19+
constexpr uint16_t ACC_SEG3_VOLTS = 0x194;
20+
constexpr uint16_t ACC_SEG4_VOLTS = 0x195;
21+
constexpr uint16_t ACC_POWER = 0x288;
22+
constexpr uint16_t ACC_SEG0_TEMPS = 0x291;
23+
constexpr uint16_t ACC_SEG1_TEMPS = 0x292;
24+
constexpr uint16_t ACC_SEG2_TEMPS = 0x293;
25+
constexpr uint16_t ACC_SEG3_TEMPS = 0x294;
26+
constexpr uint16_t ACC_SEG4_TEMPS = 0x295;
27+
// ETC
28+
constexpr uint16_t ETC_STATUS = 0x189;
29+
// PDB
30+
constexpr uint16_t PDB_POWER_A = 0x19A;
31+
constexpr uint16_t PDB_POWER_B = 0x29B;
32+
// SME
33+
constexpr uint16_t SME_THROTTLE_DEMAND = 0x186;
34+
constexpr uint16_t SME_MAX_CURRENTS = 0x286;
35+
constexpr uint16_t SME_TRQSPD = 0x482;
36+
constexpr uint16_t SME_TEMP = 0x682;
37+
// TMAIN
38+
constexpr uint16_t TMAIN_DATA = 0x1A0;
39+
// TPERIPH
40+
constexpr uint16_t TPERIPH_BL_DATA = 0x1A4;
41+
constexpr uint16_t TPERIPH_BL_TIRETEMP = 0x2A3;
42+
constexpr uint16_t TPERIPH_BR_DATA = 0x1A5;
43+
constexpr uint16_t TPERIPH_BR_TIRETEMP = 0x2A4;
44+
constexpr uint16_t TPERIPH_FL_DATA = 0x1A2;
45+
constexpr uint16_t TPERIPH_FL_TIRETEMP = 0x2A1;
46+
constexpr uint16_t TPERIPH_FR_DATA = 0x1A3;
47+
constexpr uint16_t TPERIPH_FR_TIRETEMP = 0x2A2;
48+
// VDM
49+
constexpr uint32_t VDM_GPS_LAT_LONG = 0x000A0000;
50+
constexpr uint32_t VDM_GPS_DATA = 0x000A0001;
51+
constexpr uint32_t VDM_DATE_TIME = 0x000A0002;
52+
constexpr uint32_t VDM_ACCELERATION = 0x000A0003;
53+
constexpr uint32_t VDM_YAW_RATE = 0x000A0004;
54+
}
55+
56+
struct ACC_STATUS_t {
57+
uint8_t BMS_FAULT : 1; // bit 0
58+
uint8_t IMD_FAULT : 1; // bit 1
59+
uint8_t SHUTDOWN_STATE : 1; // bit 2
60+
uint8_t PRECHARGE_DONE : 1; // bit 3
61+
uint8_t PRECHARGING : 1; // bit 4
62+
uint8_t CHARGING : 1; // bit 5
63+
uint8_t padding_6_7 : 2; // bits 6-7 (padding for gaps)
64+
uint8_t CELL_TOO_LOW : 1; // bit 8
65+
uint8_t CELL_TOO_HIGH : 1; // bit 9
66+
uint8_t TEMP_TOO_LOW : 1; // bit 10
67+
uint8_t TEMP_TOO_HIGH : 1; // bit 11
68+
uint8_t TEMP_TOO_HIGH_CRG : 1; // bit 12
69+
uint8_t padding_13_15 : 3; // bits 13-15 (padding to complete byte)
70+
uint16_t GLV_VOLTAGE; // bits 16-31
71+
uint32_t CELL_FAULT_INDEX; // bits 32-63
72+
};
73+
74+
struct ACC_SEG_VOLTS_t {
75+
uint8_t VOLTS_CELL0; // bits 0-7
76+
uint8_t VOLTS_CELL1; // bits 8-15
77+
uint8_t VOLTS_CELL2; // bits 16-23
78+
uint8_t VOLTS_CELL3; // bits 24-31
79+
uint8_t VOLTS_CELL4; // byte 32-39
80+
uint8_t VOLTS_CELL5; // byte 40-47
81+
};
82+
83+
struct ACC_POWER_t {
84+
uint16_t PACK_VOLTAGE; // bits 0-15
85+
uint8_t SOC; // bits 16-23
86+
uint16_t CURRENT; // bits 24-39
87+
};
88+
89+
struct ACC_SEG_TEMPS_t {
90+
uint8_t TEMPS_CELL0; // bits 0-7
91+
uint8_t TEMPS_CELL1; // bits 8-15
92+
uint8_t TEMPS_CELL2; // bits 16-23
93+
uint8_t TEMPS_CELL3; // bits 24-31
94+
uint8_t TEMPS_CELL4; // bits 32-39
95+
uint8_t TEMPS_CELL5; // bits 40-47
96+
};
97+
98+
struct ETC_STATUS_t {
99+
uint16_t HE1; // bits 0-15
100+
uint16_t HE2; // bits 16-31
101+
uint16_t BRAKE_SENSE_VOLTAGE; // bits 32-47
102+
uint8_t PEDAL_TRAVEL; // bits 48-55
103+
bool RTD_BUTTON : 1; // bit 56
104+
bool RTDS : 1; // bit 57
105+
bool REVERSE : 1; // bit 58
106+
bool BRAKELIGHT : 1; // bit 59
107+
bool RTD : 1; // bit 60
108+
bool IMPLAUSIBILITY : 1; // bit 61
109+
bool TS_ACTIVE : 1; // bit 62
110+
};
111+
112+
struct PDB_POWER_A_t {
113+
uint16_t GLV_VOLTAGE; // bits 0-15
114+
uint8_t CURRENT_SHUTDOWN; // bits 16-23
115+
uint8_t CURRENT_ACC; // bits 24-31
116+
uint8_t CURRENT_ETC; // bits 32-39
117+
uint8_t CURRENT_BPS; // bits 40-47
118+
uint8_t CURRENT_TRACTIVE; // bits 48-55
119+
uint8_t CURRENT_BSPD; // bits 56-63
120+
};
121+
122+
struct PDB_POWER_B_t {
123+
uint8_t CURRENT_TELEMETRY; // bits 0-7
124+
uint8_t CURRENT_PDB; // bits 8-15
125+
uint8_t CURRENT_DASH; // bits 16-23
126+
uint8_t CURRENT_RTML; // bits 24-31
127+
uint8_t CURRENT_EXTRA_1; // bits 32-39
128+
uint8_t CURRENT_EXTRA_2; // bits 40-47
129+
};
130+
131+
struct SME_THROTTLE_DEMAND_t {
132+
uint16_t TORQUE_DEMAND; // bits 0-15
133+
uint16_t MAX_SPEED; // bits 16-31
134+
uint8_t FORWARD : 1; // bit 32
135+
uint8_t REVERSE : 1; // bit 33
136+
uint8_t padding_34 : 1; // bit 34 (used for alignment)
137+
uint8_t POWER_READY : 1; // bit 35
138+
uint8_t padding2 : 4; // bits 36-39
139+
uint8_t MBB_ALIVE: 1; // bit 40
140+
};
141+
142+
struct SME_TRQSPD_t {
143+
uint16_t SPEED; // bits 0-15
144+
uint16_t TORQUE; // bits 16-31
145+
uint8_t SOC_LOW_TRACTION : 1; // bit 32
146+
uint8_t SOC_LOW_HYDRAULIC : 1; // bit 33
147+
uint8_t REVERSE : 1; // bit 34
148+
uint8_t FORWARD : 1; // bit 35
149+
uint8_t PARK_BRAKE : 1; // bit 36
150+
uint8_t PEDAL_BRAKE : 1; // bit 37
151+
uint8_t CONTROLLER_OVERTEMP : 1; // bit 38
152+
uint8_t KEY_SWITCH_OVERVOLT : 1; // bit 39
153+
uint8_t KEY_SWITCH_UNDERVOLT: 1; // bit 40
154+
uint8_t RUNNING : 1; // bit 41
155+
uint8_t TRACTION : 1; // bit 42
156+
uint8_t HYDRAULIC : 1; // bit 43
157+
uint8_t POWERING_ENABLED : 1; // bit 44
158+
uint8_t POWERING_READY : 1; // bit 45
159+
uint8_t PRECHARGING : 1; // bit 46
160+
uint8_t CONTACTOR_CLOSED : 1; // bit 47
161+
uint16_t MOTOR_FLAGS; // bits 48-63
162+
};
163+
164+
struct SME_TEMP_t {
165+
uint8_t MOTOR_TEMP; // bits 0-7
166+
uint8_t CONTROLLER_TEMP; // bits 8-15
167+
uint16_t DC_BUS_V; // bits 16-31
168+
uint8_t FAULT_CODE; // bits 32-39
169+
uint8_t FAULT_LEVEL; // bits 40-47
170+
uint16_t BUS_CURRENT; // bits 48-63
171+
};
172+
173+
struct SME_MAX_CURRENTS_t {
174+
uint16_t CHARGE_CURRENT; // bits 0-15
175+
uint16_t DISCHARGE_CURRENT; // bits 16-31
176+
};
177+
178+
struct TMAIN_DATA_t {
179+
uint16_t BRAKES_F; // bits 0-15
180+
uint16_t BRAKES_R; // bits 16-31
181+
};
182+
183+
struct TPERIPH_DATA_t {
184+
uint16_t WHEELSPEED; // bits 0-15
185+
uint16_t SUSTRAVEL; // bits 16-31
186+
uint16_t STRAIN; // bits 32-47
187+
uint8_t SIDE_TIRE_TEMP; // bits 48-55
188+
};
189+
190+
struct TPERIPH_TIRETEMP_t {
191+
uint8_t TIRETEMP_1; // bits 0-7
192+
uint8_t TIRETEMP_2; // bits 8-15
193+
uint8_t TIRETEMP_3; // bits 16-23
194+
uint8_t TIRETEMP_4; // bits 24-31
195+
uint8_t TIRETEMP_5; // bits 32-39
196+
uint8_t TIRETEMP_6; // bits 40-47
197+
uint8_t TIRETEMP_7; // bits 48-55
198+
uint8_t TIRETEMP_8; // bits 56-63
199+
200+
};
201+
202+
struct VDM_GPS_LAT_LONG_t {
203+
int32_t LATITUDE; // bits 7-38
204+
int32_t LONGITUDE; // bits 39-50
205+
};
206+
207+
struct VDM_GPS_DATA_t {
208+
int16_t SPEED; // bits 7-22
209+
int16_t ALTITUDE; // bits 23-38
210+
int16_t TRUE_COURSE; // bits 39-54
211+
int8_t SATELLITES_IN_USE; // bits 55-62
212+
int8_t VALID1; // bits 63-70
213+
};
214+
215+
struct VDM_DATE_TIME_t {
216+
int8_t VALID2; // bits 7-14
217+
int8_t UTC_DATE_YEAR; // bits 15-22
218+
int8_t UTC_DATE_MONTH; // bits 23-30
219+
int8_t UTC_DATE_DAY; // bits 31-38
220+
int8_t UTC_TIME_HOURS; // bits 47-54
221+
int8_t UTC_TIME_MINUTES; // bits 55-62
222+
int8_t UTC_TIME_SECONDS; // bits 63-70
223+
};
224+
225+
struct VDM_ACCELERATION_t {
226+
int16_t X; // bits 7-22
227+
int16_t Y; // bits 23-38
228+
int16_t Z; // bits 39-54
229+
};
230+
231+
struct VDM_YAW_RATE_t {
232+
int16_t X; // bits 7-22
233+
int16_t Y; // bits 23-38
234+
int16_t Z; // bits 39-54
235+
};
236+
237+
#endif // CANPROTOCOL_HPP

0 commit comments

Comments
 (0)