Explorar o código

Pi logic updated to GET BATTERY MEASUREMENT for Cycle number and Cycle state

namrota ghosh hai 7 meses
pai
achega
f8c841b385
Modificáronse 2 ficheiros con 15 adicións e 11 borrados
  1. 11 9
      src/pi/i2c_pi_target.c
  2. 4 2
      src/pi/i2c_pi_target.h

+ 11 - 9
src/pi/i2c_pi_target.c

@@ -64,7 +64,7 @@ void pi_i2c_mcu(){
     }
     //bitmasked GET command:
     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
         uint8_t requestedSlot = (receivedCommand & 0xF0)>>4;
         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
         BatteryInfo *battery = &battery_data[requestedSlot];
-        battery_measure.slot_id= battery->slot_id;
         battery_measure.voltage= battery->battery_measurement.voltage;
         battery_measure.current= battery->battery_measurement.current;
         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));
         printf("Battery Measurement Sent. \n");
         DL_I2C_flushTargetTXFIFO(I2C_0_INST);
 
     }
 
-    else if(receivedCommand== CMD_SET_BATTERY_LIMIT){
+    else if((receivedCommand & 0x0F)== 0x03){
 
         //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)
         * max_voltage: 4200 (68 10)
@@ -97,10 +99,10 @@ void pi_i2c_mcu(){
         * charge fraction: 25 (19)
         */
         uint8_t rx_index= 0;
-
+        uint8_t requestedSlot= (receivedCommand & 0xF0)>>4;
         while(rx_index < (sizeof(BatteryLimitMsg))){
             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]);
                 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:
         if(rx_index== (sizeof(BatteryLimitMsg))){
             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->max_voltage = battery_limit_received.max_voltage;
                 battery->cut_off_current = battery_limit_received.cut_off_current;

+ 4 - 2
src/pi/i2c_pi_target.h

@@ -3,6 +3,7 @@
 
 #include <stdbool.h>
 #include <stdint.h>
+#include "src/battery_data/battery.h"
 
 // I2C command codes
 #define CMD_GET_BATTERY_STATUS        0x01       // Request battery state
@@ -10,19 +11,20 @@
 #define CMD_SET_BATTERY_LIMIT         0x03       // SET min/max voltage, cutoff current limits
 
 typedef struct __attribute__((packed)){
-    uint8_t slot_id;
     uint16_t voltage;
     int16_t current;
     uint16_t temperature;
+    uint8_t cycle_number;
+    BatteryChargingState cycle_state;
 } BatteryData;
 
 typedef struct __attribute__((packed)){
-    uint8_t slot_id;
     uint16_t min_voltage;
     uint16_t max_voltage;
     uint8_t cut_off_current;
     uint16_t capacitance;
     uint8_t charge_fraction;
+    //uint8_t previous_cycle_number;
 } BatteryLimitMsg;