@janpom unfortunately I have no response :C
For telemetry I have something like this:
bool VescUartUnity::processReadPacket(uint8_t * message) {
COMM_PACKET_ID packetId;
int32_t ind = 0;
packetId = (COMM_PACKET_ID)message[0];
message++; // Removes the packetId from the actual message (payload)
switch (packetId){
case COMM_GET_VALUES: // Structure defined here: https://github.com/vedderb/bldc/blob/43c3bbaf91f5052a35b75c2ff17b5fe99fad94d1/commands.c#L164
ind = 0;
data.filteredFetTemp0 = buffer_get_float16(message, 10.0, &ind);
data.filteredFetTemp1 = buffer_get_float16(message, 10.0, &ind);
data.filteredMotorTemp0 = buffer_get_float16(message, 10.0, &ind);
data.filteredMotorTemp1 = buffer_get_float16(message, 10.0, &ind);
data.avgMotorCurrent0 = buffer_get_float32(message, 100.0, &ind);
data.avgMotorCurrent1 = buffer_get_float32(message, 100.0, &ind);
data.avgInputCurrent = buffer_get_float32(message, 100.0, &ind);
ind += 16;
// buffer_append_float32(send_buffer, mc_interface_read_reset_avg_id(), 1e2, &ind);
// buffer_append_float32(send_buffer, mc_interface_read_reset_avg_id2(), 1e2, &ind);
// buffer_append_float32(send_buffer, mc_interface_read_reset_avg_iq(), 1e2, &ind);
// buffer_append_float32(send_buffer, mc_interface_read_reset_avg_iq2(), 1e2, &ind);
data.dutyCycleNow0 = buffer_get_float16(message, 1000.0, &ind);
data.dutyCycleNow1 = buffer_get_float16(message, 1000.0, &ind);
data.rpm = buffer_get_int32(message, &ind);
ind += 4;
// buffer_append_float32(send_buffer, mc_interface_get_rpm2(), 1e0, &ind);
data.inpVoltage = buffer_get_float16(message, 10.0, &ind);
data.ampHours = buffer_get_float32(message, 10000.0, &ind);
data.ampHoursCharged = buffer_get_float32(message, 10000.0, &ind);
ind += 8;
// buffer_append_float32(send_buffer, mc_interface_get_watt_hours(false), 1e4, &ind);
// buffer_append_float32(send_buffer, mc_interface_get_watt_hours_charged(false), 1e4, &ind);
data.tachometer = buffer_get_int32(message, &ind);
ind += 8;
// buffer_append_int32(send_buffer, mc_interface_get_tachometer_value2(false), &ind);
data.tachometerAbs = buffer_get_int32(message, &ind);
ind += 8;
// buffer_append_int32(send_buffer, mc_interface_get_tachometer_abs_value2(false), &ind);
return true;
break;
default:
return false;
break;
}
}
And I’m not sure how should look like code for BMS values. I tried something like that:
bool VescUartUnity::processReadPacket(uint8_t * message) {
send_buffer[ind++] = COMM_GET_VALUES;
buffer_append_int32(send_buffer, (int32_t) ADC_convertedResults[batteryVoltage], &ind); // packVoltage
buffer_append_int32(send_buffer, (int32_t) ADC_convertedResults[chargeCurrent], &ind); // packCurrent
send_buffer[ind++] = 50; // FIXME: SoC
uint16_t cell_high = highestCell(nonVolPars.chgParas.packCellCount);
uint16_t cell_low = lowestCell(nonVolPars.chgParas.packCellCount);
buffer_append_int32(send_buffer, cell_high, &ind); // cellVoltageHigh
buffer_append_int32(send_buffer, (cell_high + cell_low) / 2, &ind); // cellVoltageAverage (very rough approximation)
buffer_append_int32(send_buffer, cell_low, &ind); // cellVoltageLow
buffer_append_int32(send_buffer, cell_high - cell_low, &ind); // cellVoltageMisMatch
buffer_append_float16(send_buffer, 0.0, 1e2, &ind); // loCurrentLoadVoltage
buffer_append_float16(send_buffer, 0.0, 1e2, &ind); // loCurrentLoadCurrent
buffer_append_float16(send_buffer, 0.0, 1e2, &ind); // hiCurrentLoadVoltage
buffer_append_float16(send_buffer, 0.0, 1e2, &ind); // hiCurrentLoadCurrent
buffer_append_float16(send_buffer, 0.0, 1e2, &ind); // auxVoltage
buffer_append_float16(send_buffer, 0.0, 1e2, &ind); // auxCurrent
buffer_append_int16(send_buffer, (int16_t) (ADC_convertedResults[externalTemp] * 1e1 - CELSIUS_TO_KELVIN_1E1), &ind); // tempBatteryHigh
buffer_append_int16(send_buffer, (int16_t) (ADC_convertedResults[externalTemp] * 1e1 - CELSIUS_TO_KELVIN_1E1), &ind); // tempBatteryAverage
uint16_t mcu_temp = ADC_convertedResults[mcuInternalTemp];
uint16_t ltc_temp = LTC6803_getTemperature();
uint16_t bms_temp_high = (mcu_temp > ltc_temp) ? mcu_temp : ltc_temp;
uint16_t bms_temp_avg = (mcu_temp + ltc_temp) / 2;
buffer_append_int16(send_buffer, (int16_t) (bms_temp_high * 1e1 - CELSIUS_TO_KELVIN_1E1), &ind); // tempBMSHigh
buffer_append_int16(send_buffer, (int16_t) (bms_temp_avg * 1e1 - CELSIUS_TO_KELVIN_1E1), &ind); // tempBMSAverage
// TODO: use runtimePars.chargingState and runtimePars.charging
send_buffer[ind++] = (uint8_t) OP_STATE_INIT; // FIXME: operationalState
send_buffer[ind++] = 0; // FIXME: chargeBalanceActive (Indicator for charging)
send_buffer[ind++] = 0; // Future faultstate
send_buffer[ind++] = nonVolPars.genParas.canID;
commands_send_packet(from, send_buffer, ind);
break;
}
And values from code above are written in array.