|
|
@@ -17,7 +17,8 @@ bool controller_SetCommandRequest(uint8_t const TARGET_ADDRESS, uint8_t command,
|
|
|
}
|
|
|
}
|
|
|
tx_packet.txLen = data_len + 1; // +1 for command
|
|
|
- return i2c_hal.write(TARGET_ADDRESS);
|
|
|
+ //return i2c_hal.write(TARGET_ADDRESS);
|
|
|
+ return i2c_mock_interface.write(TARGET_ADDRESS);
|
|
|
}
|
|
|
|
|
|
//Generic Function to send data to the target controller using I2C:
|
|
|
@@ -25,7 +26,7 @@ bool controller_SetCommandRequest(uint8_t const TARGET_ADDRESS, uint8_t command,
|
|
|
bool controller_GetCommandRequest(uint8_t const TARGET_ADDRESS, uint8_t command, uint8_t slot_id, uint8_t *data, uint8_t data_len){
|
|
|
//Set the command in the tx buffer in bit masked format to the target
|
|
|
tx_packet.txBuffer[0] = command| (slot_id<<4); //shift slot_id to the left by 4 bits
|
|
|
- printf("Bitmasked Command:: 0x%02X\n", tx_packet.txBuffer[0]);
|
|
|
+ printf("[MCU] Bitmasked Command:: 0x%02X\n", tx_packet.txBuffer[0]);
|
|
|
//Conditional check to check if the data is not null and data length is greater than 0
|
|
|
if(data != NULL && data_len > 0){
|
|
|
//when data is sent along with the command, copying the data to the tx buffer
|
|
|
@@ -35,10 +36,10 @@ bool controller_GetCommandRequest(uint8_t const TARGET_ADDRESS, uint8_t command,
|
|
|
else{
|
|
|
tx_packet.txLen = 1; // Only command
|
|
|
}
|
|
|
- if(!i2c_hal.write(TARGET_ADDRESS)){
|
|
|
+ /*if(!i2c_hal.read(TARGET_ADDRESS)){
|
|
|
return false;
|
|
|
- }
|
|
|
- bool result= i2c_hal.read(TARGET_ADDRESS);
|
|
|
+ }*/
|
|
|
+ bool result= i2c_mock_interface.read(TARGET_ADDRESS);
|
|
|
if(result){
|
|
|
printf("[I2C] Successfully read %d bytes from target 0x%02X\n", data_len, TARGET_ADDRESS);
|
|
|
return true;
|
|
|
@@ -49,10 +50,11 @@ bool controller_GetCommandRequest(uint8_t const TARGET_ADDRESS, uint8_t command,
|
|
|
}
|
|
|
|
|
|
//Send command to set charge and discharge current to the target
|
|
|
-void controller_SetCurrent(uint8_t const TARGET_ADDRESS, uint8_t slot_id, uint8_t current_mA){
|
|
|
- uint8_t data[2];
|
|
|
+void controller_SetCurrent(uint8_t const TARGET_ADDRESS, uint8_t slot_id, int16_t current_mA){
|
|
|
+ uint8_t data[3];
|
|
|
data[0] = slot_id;
|
|
|
- data[1] = current_mA;
|
|
|
+ data[1] = current_mA & 0xFF; //Current LSB
|
|
|
+ data[2] = (current_mA >> 8) & 0xFF; //Current MSB
|
|
|
controller_SetCommandRequest(TARGET_ADDRESS, CMD_SET_CURRENT, data, sizeof(data));
|
|
|
}
|
|
|
|
|
|
@@ -62,7 +64,11 @@ bool controller_GetBatteryMeasurement(uint8_t const TARGET_ADDRESS, uint8_t slot
|
|
|
if(controller_GetCommandRequest(TARGET_ADDRESS, CMD_GET_MEASUREMENT, slot_id, (uint8_t *)measurement, sizeof(BatteryMeasurement))){
|
|
|
measurement->voltage = rx_packet.rxBuffer[0] | (rx_packet.rxBuffer[1] << 8);
|
|
|
measurement->current = rx_packet.rxBuffer[2] | (rx_packet.rxBuffer[3] << 8);
|
|
|
- measurement->temperature = rx_packet.rxBuffer[4] | (rx_packet.rxBuffer[5] << 8);
|
|
|
+ measurement->temperature = rx_packet.rxBuffer[4] | (rx_packet.rxBuffer[5] << 8);
|
|
|
+
|
|
|
+ printf("Voltage:0x%02X\n", rx_packet.rxBuffer[0] | (rx_packet.rxBuffer[1] << 8));
|
|
|
+ printf("Current:0x%02X\n", rx_packet.rxBuffer[2] | (rx_packet.rxBuffer[3] << 8));
|
|
|
+ printf("Temperature:0x%02X\n", rx_packet.rxBuffer[4] | (rx_packet.rxBuffer[5] << 8));
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|