On this page Handle a vehicle commandReport the resultReport battery and mileageReport a vehicle faultCheck the integration
SDK / FreeRTOS

Controls & vehicle data

Handle commands and report battery, mileage and faults.

Connect two paths: APP commands to the vehicle controller, and vehicle data back to the APP. First complete Bluetooth and enable the features in the device model’s console settings.

Handle a vehicle command

User taps Unlock → SDK emits VEHICLE_COMMAND
→ Your driver operates the vehicle → Controller confirms → SDK replies to the APP

For MOTO_EVENT_VEHICLE_COMMAND, use these fields to choose the operation:

Field Meaning
e.message Command type
e.target Object to control
e.value Operation or setting value

Use the command definitions in the delivered headers. Copy the whole event to your CAN, UART or other vehicle driver; you will need it to report the result.

Report the result

After the controller confirms completion, call:

moto_result rc = moto_terminal_complete(
    terminal, &saved_event, MOTO_SUCCEEDED, 0);

saved_event is the event saved when this command arrived. Choose the result based on the actual outcome:

Result Example
MOTO_SUCCEEDED Controller confirms the vehicle is unlocked
MOTO_FAILED Controller explicitly rejected the command; pass its error code as the final argument
MOTO_UNKNOWN Command was sent, but a timeout leaves the lock state uncertain

MOTO_OK means the SDK accepted the report. MOTO_FULL means it did not: retain the report and retry. Retry the report, not the vehicle operation.

Before executing a queued command, check deadline_ms (execution deadline; 0 means none) and confirm it still belongs to the current connection and session. Cancel pending old commands when disconnected.

Report battery and mileage

Read the vehicle and submit its complete current state. Replace the two variables below with your measured values:

moto_vehicle_state state = {0};
state.present = MOTO_CAP(MOTO_BATTERY) | MOTO_CAP(MOTO_MILEAGE);
state.values[MOTO_BATTERY] = actual_soc_percent;   // percent
state.values[MOTO_MILEAGE] = actual_total_metres;  // metres
moto_result rc = moto_terminal_report_state(terminal, &state);
  • present: fields included in this report.
  • values: values for those fields.
  • unknown: included fields whose readings are unavailable; these must also be in present.

For an unavailable battery reading, mark it unknown instead of reporting 0, which means empty. The SDK maintains the state revision automatically.

Report a vehicle fault

Call moto_terminal_report_fault(t, id, active, module, code, severity):

Argument Value
id Nonzero fault ID; keep the same ID when retrying the same fault
active true when raised, false when cleared
module / code Module name and manufacturer fault code, such as a battery fault
severity Severity level, from 0 to 3

Check the integration

Try locking, unlocking and sounding the horn from the APP. Confirm that the physical action and reported result agree. Disconnect the vehicle controller: the APP should receive a failed or unknown result. Reconnect it and check battery and mileage.

For completion, state and fault reports, retain and retry the data on MOTO_FULL. See API reference for all return values.