protoserver.commander module#

protoserver.commander.generate_command_message(subtype)[source]#

Generate a CommandMessage with common fields and payload based on subtype from user input.

Parameters:

subtype (int) – The subtype of the command message corresponding to enum commandMessageSubType

Returns:

The generated CommandMessage.

Return type:

tmcvp_command_message_pb2.CommandMessage

For Future Changes

This function creates and sets common fields of command message such as message_id, correlation_id, vehicle_id, type, priority, provisioning_state, version, time_stamp, and packet_status to hard code values. If any of these fields change, the code needs to be modified. However, it is agnostic to changes commandPayload.

Example:

command_message = generate_command_message(1)
print(command_message)
protoserver.commander.decode_response(rcvdMsg)[source]#

Decode and print the received MQTT message.

Parameters:

rcvdMsg (bytes) – The received MQTT message in bytes.

For Future Changes

This function assumes that the fields message_id, correlation_id, vehicle_id, type, subtype, priority, provisioning_state, version, time_stamp, packet_status and return_code are present in future proto versions of CommandResponseMessage as in version TMCVP 6.3. If any of these fields change, the code needs to be modified. However, it is agnostic to changes commandResponsePayload.

Example:

rcvd_message = b'\n$ebc4a199-67d7-4bea-9fed-d05db21e7744\x12$b82a63a2-6619-496a-8b92-be7a763db448\x1a\x11ACCDEV14012078186 \x01(\x112\x0108\x02B\x056.2.0J\t\x08\x9f\x93\xd6\xae\x06\x10\x8a\x02PLb\x05\x9a\x01\x02\x08\x01'
decode_response(rcvd_message)
protoserver.commander.start_mqtt(client)[source]#

Configures callbacks and start the MQTT client for communication. Blocks until connection is established.

Parameters:

client (paho.mqtt.client) – MQTT client object

protoserver.commander.mqtt_subscribe(vin_no='+')[source]#

Subscribe to a MQTT topic for a given VIN number else uses wild card (+)

Hint

This function uses paho.mqtt.subscribe instead of subcribing with same client. Reason: I was facing issues when publishing and subcribing with the same client object.

Parameters:

vin_no (str) – VIN number for MQTT topic subscription