How to send different messages via VehicleIOPlugin in driveworks9.0?

Hello,

I have developed a vehicleio-plugin for vehicleio to send and receive can-messages.

Receive and parse can-messages from the car perform good.

But I found some problems in sending different can-messages with different cycle-time.

In driveworks9.0, the api for send-command through vehicleio-plugin is:

dwStatus _dwVehicleIODriver_sendCommand(const dwVehicleIOCommand* cmd, dwSensorHandle_t sensor)

And that would cause a problem if I want to transform cmd into several different can_message, especailly when I have to send them with different cycle-time.

for example, the implements of send in sample:
dwStatus _dwVehicleIODriver_sendCommand(const dwVehicleIOCommand* cmd,
dwSensorHandle_t sensor)
{
dwCANMessage msgCAN{};
dwStatus status;
dwStatus result = DW_SUCCESS;

status = dwCANInterpreter_createMessageFromName(&msgCAN, GENERIC_MSG_STEERING_CMD, gIntp);
checkError(result, status, "create steering message failed");

status = encodeSteering(msgCAN, cmd);
checkError(result, status, "encode steering failed");

status = dwSensorCAN_sendMessage(&msgCAN, 1000000, sensor);
checkError(result, status, "send steering failed");

return result;

}
if I want to transform the dwVehicleIOCommand into several messages, is there any recommended way?

I noticed in dw10.0, the apis have been different, which goes as following:
typedef dwStatus(* dwSensorCANPlugin_send) (const dwCANMessage *msg, dwTime_t timeout_us, dwSensorPluginSensorHandle_t sensor)
this makes it easier to send different messages,give our developers more control ability.

but I wouldn’t like to upgrade the system.

Dear wenwu.deng,
Are you asking how to generate multiple msgCAN from a single cmd in _dwVehicleIODriver_sendCommand() function in the code snippet?

I know how to generate several messages from a single command, I want to know how to send them if they have different cycle-time?

Dear wenwu.deng,
we are checking on this internally and update you.

Dear @wenwu.deng,
sending different messages with different frequencies or separated by a delta time is possible. Note that VehicleIO module does not impose any policy regarding implementation, so the application is free to implement the strategy. There are a few strategies I can suggest:

  1. Inside _dwVehicleIODriver_sendCommand implementation, the code may check current time and whether specific CAN message needs to be sent, for example:
    indent preformatted text by 4 spaces
dwTime_t steeringSentTime{};
dwTime_t throttleSentTime{};

... _dwVehicleIODriver_sendCommand(...)
{
    ...
    dwTime_t now{};
    dwContext_getCurrentTime(&now, ctx);

    if (now - steeringSentTime > steeringCycleTime)
    {
    

status = encodeSteering(steeringMsg, cmd);

checkError(...);


status = dwSensorCAN_sendMessage(steeringMsg, 1000000, sensor);

checkError(...);

steeringSentTime = now; 
} 
if (now - throttleSentTime > throttleCycleTime) {

status = encodeThrottle(throttleMsg, cmd);
checkError(...);
status = dwSensorCAN_sendMessage(throttleMsg, 1000000, sensor);
checkError(...);
throttleSentTime = now; 
} 
... 
}
  1. Alternatively, inside your VehicleIO plugin, you may want to create and manage a thread and a queue of commands (or a mailbox if only the most recent command is important), while _dwVehicleIODriver_sendCommand() would simply add commands to the queue/mailbox.

It is recommended to keep the amount of threads minimal, so the first option would be preferred.

I noticed in dw10.0, the apis have been different, which goes as following:
typedef dwStatus(* dwSensorCANPlugin_send) (const dwCANMessage *msg, dwTime_t timeout_us, dwSensorPluginSensorHandle_t sensor)

Note that the cited API corresponds to CAN Plugin, not VehicleIO plugin. Nothing major changed between DW9 and DW10 in VehicleIO.

Dear @wenwu.deng,
Can we close this topic?

ok, thanks a lot.