|
@@ -64,7 +64,7 @@ void pi_i2c_mcu(){
|
|
|
}
|
|
}
|
|
|
//bitmasked GET command:
|
|
//bitmasked GET command:
|
|
|
else if((receivedCommand & 0x0F)== 0x02){
|
|
else if((receivedCommand & 0x0F)== 0x02){
|
|
|
- //I2Ctools command: i2cget -y 1 0x20 0xn2 i 7
|
|
|
|
|
|
|
+ //I2Ctools command: i2cget -y 1 0x20 0xn2 i 8
|
|
|
//Get Battery Measurement data for slot_id: Voltage, Current, Temperture
|
|
//Get Battery Measurement data for slot_id: Voltage, Current, Temperture
|
|
|
uint8_t requestedSlot = (receivedCommand & 0xF0)>>4;
|
|
uint8_t requestedSlot = (receivedCommand & 0xF0)>>4;
|
|
|
printf("Requested slot:%d\n", requestedSlot);
|
|
printf("Requested slot:%d\n", requestedSlot);
|
|
@@ -75,20 +75,22 @@ void pi_i2c_mcu(){
|
|
|
}
|
|
}
|
|
|
//Check for the requested slot and get the battery measurement data
|
|
//Check for the requested slot and get the battery measurement data
|
|
|
BatteryInfo *battery = &battery_data[requestedSlot];
|
|
BatteryInfo *battery = &battery_data[requestedSlot];
|
|
|
- battery_measure.slot_id= battery->slot_id;
|
|
|
|
|
battery_measure.voltage= battery->battery_measurement.voltage;
|
|
battery_measure.voltage= battery->battery_measurement.voltage;
|
|
|
battery_measure.current= battery->battery_measurement.current;
|
|
battery_measure.current= battery->battery_measurement.current;
|
|
|
battery_measure.temperature= battery->battery_measurement.temperature;
|
|
battery_measure.temperature= battery->battery_measurement.temperature;
|
|
|
|
|
+ battery_measure.cycle_number= battery->cycle_number;
|
|
|
|
|
+ battery_measure.cycle_state= battery->battery_charging_state;
|
|
|
|
|
+
|
|
|
DL_I2C_fillTargetTXFIFO(I2C_0_INST, (uint8_t *)&battery_measure, sizeof(BatteryData));
|
|
DL_I2C_fillTargetTXFIFO(I2C_0_INST, (uint8_t *)&battery_measure, sizeof(BatteryData));
|
|
|
printf("Battery Measurement Sent. \n");
|
|
printf("Battery Measurement Sent. \n");
|
|
|
DL_I2C_flushTargetTXFIFO(I2C_0_INST);
|
|
DL_I2C_flushTargetTXFIFO(I2C_0_INST);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- else if(receivedCommand== CMD_SET_BATTERY_LIMIT){
|
|
|
|
|
|
|
+ else if((receivedCommand & 0x0F)== 0x03){
|
|
|
|
|
|
|
|
//slot_id is another element
|
|
//slot_id is another element
|
|
|
- //Example i2ctools: i2cset -y 1 0x20 0x03 0x00 0x2C 0x01 0x68 0x10 0xFA 0xD0 0x07 0x19 i
|
|
|
|
|
|
|
+ //Example i2ctools: i2cset -y 1 0x20 0x03 0x2C 0x01 0x68 0x10 0xFA 0xD0 0x07 0x19 i
|
|
|
/*
|
|
/*
|
|
|
* min_voltage: 300 (2C 01)
|
|
* min_voltage: 300 (2C 01)
|
|
|
* max_voltage: 4200 (68 10)
|
|
* max_voltage: 4200 (68 10)
|
|
@@ -97,10 +99,10 @@ void pi_i2c_mcu(){
|
|
|
* charge fraction: 25 (19)
|
|
* charge fraction: 25 (19)
|
|
|
*/
|
|
*/
|
|
|
uint8_t rx_index= 0;
|
|
uint8_t rx_index= 0;
|
|
|
-
|
|
|
|
|
|
|
+ uint8_t requestedSlot= (receivedCommand & 0xF0)>>4;
|
|
|
while(rx_index < (sizeof(BatteryLimitMsg))){
|
|
while(rx_index < (sizeof(BatteryLimitMsg))){
|
|
|
if(!DL_I2C_isTargetRXFIFOEmpty(I2C_0_INST)){
|
|
if(!DL_I2C_isTargetRXFIFOEmpty(I2C_0_INST)){
|
|
|
- rx_packet.rxBuffer[rx_index] = DL_I2C_receiveTargetData(I2C_0_INST);
|
|
|
|
|
|
|
+ rxPacket.rxBuffer[rx_index] = DL_I2C_receiveTargetData(I2C_0_INST);
|
|
|
//printf("Received Bytes[%d]: 0x%02X\n", rx_index, rx_packet.rxBuffer[rx_index]);
|
|
//printf("Received Bytes[%d]: 0x%02X\n", rx_index, rx_packet.rxBuffer[rx_index]);
|
|
|
rx_index++;
|
|
rx_index++;
|
|
|
}
|
|
}
|
|
@@ -109,9 +111,9 @@ void pi_i2c_mcu(){
|
|
|
//Check if all the data is received then store the battery limits in BatteryInfo struct:
|
|
//Check if all the data is received then store the battery limits in BatteryInfo struct:
|
|
|
if(rx_index== (sizeof(BatteryLimitMsg))){
|
|
if(rx_index== (sizeof(BatteryLimitMsg))){
|
|
|
BatteryLimitMsg battery_limit_received;
|
|
BatteryLimitMsg battery_limit_received;
|
|
|
- memcpy(&battery_limit_received, (const uint8_t*)rx_packet.rxBuffer, sizeof(BatteryLimitMsg));
|
|
|
|
|
- if(battery_limit_received.slot_id < NUM_SLOTS){
|
|
|
|
|
- BatteryInfo *battery = &battery_data[battery_limit_received.slot_id];
|
|
|
|
|
|
|
+ memcpy(&battery_limit_received, (const uint8_t*)rxPacket.rxBuffer, sizeof(BatteryLimitMsg));
|
|
|
|
|
+ if(requestedSlot < NUM_SLOTS){
|
|
|
|
|
+ BatteryInfo *battery = &battery_data[requestedSlot];
|
|
|
battery->min_voltage = battery_limit_received.min_voltage;
|
|
battery->min_voltage = battery_limit_received.min_voltage;
|
|
|
battery->max_voltage = battery_limit_received.max_voltage;
|
|
battery->max_voltage = battery_limit_received.max_voltage;
|
|
|
battery->cut_off_current = battery_limit_received.cut_off_current;
|
|
battery->cut_off_current = battery_limit_received.cut_off_current;
|