@@ -10,15 +10,20 @@ void sendCAN();
10
10
CAN* can;
11
11
12
12
uint32_t max_voltage_mV = 0 ;
13
- uint16_t max_dc_current_mA = 0 ;
13
+ uint16_t max_dc_current_cA = 0 ; // in centiamps (0.01 amps)
14
14
uint8_t max_ac_current_A = 0 ;
15
15
16
+ uint16_t pack_voltage = 0 ;
17
+ uint16_t soc = 0 ;
18
+
16
19
bool enable = false ;
17
20
18
21
19
22
AnalogIn control_pilot (PIN_CONTROL_PILOT);
20
23
AnalogIn proximity_pilot (PIN_PROXIMITY_PILOT);
21
24
25
+ EventQueue queue = EventQueue(EVENTS_EVENT_SIZE * 32 );
26
+
22
27
23
28
int main ()
24
29
{
@@ -41,15 +46,18 @@ int main()
41
46
42
47
while (can->read (msg)) {
43
48
switch (msg.id ) {
44
- case 0x80 : // sync
45
- sendCAN ();
46
- break ;
47
- case 0x188 : // ACC_TPDO_STATUS
48
- prechargeDone = msg.data [0 ] & 0b00001000 ;
49
- fault = msg.data [0 ] & 0b00000011 ;
50
- shutdown_closed = msg.data [0 ] & 0b00000100 ;
51
- cell_temps_fine = !(msg.data [1 ] & 0b00010000 );
52
- break ;
49
+ case 0x188 : // ACC_TPDO_STATUS
50
+ prechargeDone = msg.data [0 ] & 0b00001000 ;
51
+ fault = msg.data [0 ] & 0b00000011 ;
52
+ shutdown_closed = msg.data [0 ] & 0b00000100 ;
53
+ cell_temps_fine = !(msg.data [1 ] & 0b00010000 );
54
+ break ;
55
+ case 0x288 : // ACC_TPDO_POWER
56
+ pack_voltage = msg.data [0 ] + (msg.data [1 ] << 8 );
57
+ soc = msg.data [2 ];
58
+ break ;
59
+ default :
60
+ break ;
53
61
}
54
62
}
55
63
@@ -77,11 +85,18 @@ int main()
77
85
78
86
79
87
max_voltage_mV = VOLTAGE_TARGET_MV;
80
- max_dc_current_mA = CURRENT_MAX_MA;
81
88
82
- printf (" pp_ready: %x, precharge done: %x, fault: %x, sh closed: %x, cell temps fine: %x\n " , proximity_pilot_ready, prechargeDone, fault, shutdown_closed, cell_temps_fine);
89
+ // printf("pp_ready: %x, precharge done: %x, fault: %x, sh closed: %x, cell temps fine: %x\n", proximity_pilot_ready, prechargeDone, fault, shutdown_closed, cell_temps_fine);
83
90
enable = proximity_pilot_ready && prechargeDone && !fault && shutdown_closed && cell_temps_fine;
84
- printf (" enable: %x\n " , enable);
91
+ printf (" Enable: %x\n Voltage: %f\n SOC: %d\n\n " , enable, pack_voltage / 100.0 , soc);
92
+
93
+ if (enable) {
94
+ max_dc_current_cA = CURRENT_MAX_CA;
95
+ } else {
96
+ max_dc_current_cA = 0 ;
97
+ }
98
+
99
+ queue.dispatch_once ();
85
100
}
86
101
87
102
// main() is expected to loop forever.
@@ -92,24 +107,28 @@ int main()
92
107
void initIO () {
93
108
printf (" initIO()\n " );
94
109
can = new CAN (PIN_CAN1_RD, PIN_CAN1_TD, CAN_FREQUENCY);
110
+ can->filter (0x088 , 0x00FF , CANAny); // accept any TPDOs from ACC (0x188, 0x288)
95
111
96
112
// LSS assign charger
97
113
initChargerCAN ();
114
+
115
+ this_thread::sleep_for (100ms);
116
+ queue.call_every (100ms, &sendCAN);
98
117
}
99
118
100
119
void initChargerCAN () {
101
120
printf (" initChargerCAN()\n " );
102
121
103
122
ThisThread::sleep_for (2500ms);
104
123
105
- // Switch state global protocal , switch to LSS configuration state
124
+ // Switch state global protocol , switch to LSS configuration state
106
125
uint8_t lss0_data[8 ] = {0x04 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
107
126
CANMessage lss0_msg (0x7E5 , lss0_data);
108
127
can->write (lss0_msg);
109
128
110
129
ThisThread::sleep_for (500ms);
111
130
112
- // Configurate node ID protocal , set node ID to 0x10
131
+ // Configurate node ID protocol , set node ID to 0x10
113
132
uint8_t lss1_data[8 ] = {0x11 , 0x10 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
114
133
CANMessage lss1_msg (0x7E5 , lss1_data);
115
134
can->write (lss1_msg);
@@ -127,8 +146,8 @@ void sendCAN() {
127
146
static_cast <uint8_t >(max_voltage_mV >> 8 ),
128
147
static_cast <uint8_t >(max_voltage_mV >> 16 ),
129
148
static_cast <uint8_t >(max_voltage_mV >> 24 ),
130
- static_cast <uint8_t >(max_dc_current_mA ),
131
- static_cast <uint8_t >(max_dc_current_mA >> 8 ),
149
+ static_cast <uint8_t >(max_dc_current_cA ),
150
+ static_cast <uint8_t >(max_dc_current_cA >> 8 ),
132
151
max_ac_current_A
133
152
};
134
153
CANMessage charge_limits_msg (0x306 , charge_limits_data);
0 commit comments