@@ -15,51 +15,51 @@ void i2cSend(void* i2c, unsigned char* data, unsigned int length) {}
1515void i2cReceive (void * i2c , unsigned char * data , unsigned int length ) {}
1616void i2cClearSCD (void * i2c ) {}
1717
18- obc_error_code_t i2cWriteReg (uint8_t sAddr , uint8_t reg , uint8_t * data , uint16_t numBytes ) {
19- // Simulate a successful write
20- return OBC_ERR_CODE_SUCCESS ;
18+ obc_error_code_t i2cWriteReg (uint8_t sAddr , uint8_t reg , uint8_t * data , uint16_t numBytes ) {
19+ // Simulate a successful write
20+ return OBC_ERR_CODE_SUCCESS ;
2121}
2222
23-
24- obc_error_code_t i2cReadReg (uint8_t sAddr , uint8_t reg , uint8_t * data , uint16_t numBytes , TickType_t transferTimeoutTicks ) {
25- if ((sAddr == 0b1000000U || sAddr == 0b1000001U ) && numBytes == 2 ) {
26- // 0x01 - shunt voltage
27- // 0x02 - bus voltage
28- // 0x03 - power
29- // 0x04 - current
30- if (reg == 0x01 || reg == 0x02 || reg == 0x03 || reg == 0x04 ) { // Bus voltage register
31- data [0 ] = mockData [0 ]; // High byte
32- data [1 ] = mockData [1 ]; // Low byte
33- }
34- return OBC_ERR_CODE_SUCCESS ;
23+ obc_error_code_t i2cReadReg (uint8_t sAddr , uint8_t reg , uint8_t * data , uint16_t numBytes ,
24+ TickType_t transferTimeoutTicks ) {
25+ if ((sAddr == 0b1000000U || sAddr == 0b1000001U ) && numBytes == 2 ) {
26+ // 0x01 - shunt voltage
27+ // 0x02 - bus voltage
28+ // 0x03 - power
29+ // 0x04 - current
30+ if (reg == 0x01 || reg == 0x02 || reg == 0x03 || reg == 0x04 ) { // Bus voltage register
31+ data [0 ] = mockData [0 ]; // High byte
32+ data [1 ] = mockData [1 ]; // Low byte
3533 }
36- // Default mock behavior
3734 return OBC_ERR_CODE_SUCCESS ;
35+ }
36+ // Default mock behavior
37+ return OBC_ERR_CODE_SUCCESS ;
3838}
3939
4040void setMockBusVoltageValue (float expectedVoltage ) {
41- uint16_t expectedVal = (uint16_t )((expectedVoltage / 0.00125f ) + 0.5f );
42- mockData [0 ] = (0xFF00 & expectedVal ) >> 8 ; // High byte
43- mockData [1 ] = 0xFF & expectedVal ; // Low bytes
41+ uint16_t expectedVal = (uint16_t )((expectedVoltage / 0.00125f ) + 0.5f );
42+ mockData [0 ] = (0xFF00 & expectedVal ) >> 8 ; // High byte
43+ mockData [1 ] = 0xFF & expectedVal ; // Low bytes
4444}
4545
4646void setMockCurrentValue (float expectedCurrent ) {
47- uint16_t expectedVal = expectedCurrent / 0.001f ;
48- mockData [0 ] = (0xFF00 & expectedVal ) >> 8 ; // High byte
49- mockData [1 ] = 0xFF & expectedVal ; // Low bytes
47+ uint16_t expectedVal = expectedCurrent / 0.001f ;
48+ mockData [0 ] = (0xFF00 & expectedVal ) >> 8 ; // High byte
49+ mockData [1 ] = 0xFF & expectedVal ; // Low bytes
5050}
5151
5252void setMockPowerValue (float expectedPower ) {
53- // add 0.5 to round to the nearest integer (ensures that .5-.9 rounds up instead of truncating the decimal)
54- uint16_t expectedVal = (uint16_t )((expectedPower / 0.025f ) + 0.5f );
55- mockData [0 ] = (0xFF00 & expectedVal ) >> 8 ; // High byte
56- mockData [1 ] = 0xFF & expectedVal ; // Low bytes
53+ // add 0.5 to round to the nearest integer (ensures that .5-.9 rounds up instead of truncating the decimal)
54+ uint16_t expectedVal = (uint16_t )((expectedPower / 0.025f ) + 0.5f );
55+ mockData [0 ] = (0xFF00 & expectedVal ) >> 8 ; // High byte
56+ mockData [1 ] = 0xFF & expectedVal ; // Low bytes
5757}
5858
5959void setMockShuntVoltageValue (float expectedShuntVoltage ) {
60- // if expected value is positive, add 0.5; if negative, subtract 0.5
61- int32_t raw = (int32_t )((expectedShuntVoltage / 0.0000025f ) + (expectedShuntVoltage >= 0 ? 0.5f : -0.5f ));
62- uint16_t expectedVal = (uint16_t )raw ; // two's complement encoding for negative values
63- mockData [0 ] = (expectedVal >> 8 ) & 0xFF ; // High byte
64- mockData [1 ] = expectedVal & 0xFF ; // Low byte
65- }
60+ // if expected value is positive, add 0.5; if negative, subtract 0.5
61+ int32_t raw = (int32_t )((expectedShuntVoltage / 0.0000025f ) + (expectedShuntVoltage >= 0 ? 0.5f : -0.5f ));
62+ uint16_t expectedVal = (uint16_t )raw ; // two's complement encoding for negative values
63+ mockData [0 ] = (expectedVal >> 8 ) & 0xFF ; // High byte
64+ mockData [1 ] = expectedVal & 0xFF ; // Low byte
65+ }
0 commit comments