SAIC-iSmart-API / saic-python-client

MIT License
12 stars 5 forks source link

Error while decoding a/c enable response #8

Closed nanomad closed 1 year ago

nanomad commented 1 year ago

I've tried the enable ac command with temp_idx=7, here's the response after the second poll:

The first response message got processed correctly as it had no application data

2023-07-24 06:48:13,679 Error while processing MQTT message: MPDispatcherBody.uid: out of data (At bit offset: 189)
Traceback (most recent call last):
  File "/usr/src/app/mqtt_publisher.py", line 66, in __on_message
    self.__on_message_real(client, userdata, msg)
  File "/usr/src/app/mqtt_publisher.py", line 87, in __on_message_real
    self.on_mqtt_command_received(vin, msg)
  File "/usr/src/app/./mqtt_gateway.py", line 315, in __on_mqtt_command_received
    vehicle_handler.handle_mqtt_command(msg)
  File "/usr/src/app/./mqtt_gateway.py", line 180, in handle_mqtt_command
    self.saic_api.start_ac(self.vin_info, temperature_idx=self.vehicle_state.get_ac_temperature_idx())
  File "/usr/local/lib/python3.10/site-packages/saic_ismart_client/saic_api.py", line 277, in start_ac
    return self.control_climate(vin_info, fan_speed=2, ac_on=None, temperature_idx=temperature_idx)
  File "/usr/local/lib/python3.10/site-packages/saic_ismart_client/saic_api.py", line 352, in control_climate
    return self.send_vehicle_ctrl_cmd_with_retry(vin_info, b'\x06', rcv_params, True)
  File "/usr/local/lib/python3.10/site-packages/saic_ismart_client/saic_api.py", line 439, in send_vehicle_ctrl_cmd_with_retry
    return self.handle_retry(
  File "/usr/local/lib/python3.10/site-packages/saic_ismart_client/saic_api.py", line 458, in handle_retry
    return self.__handle_retry_with_app_data(func, vin_info=vin_info, max_retries=max_retries)
  File "/usr/local/lib/python3.10/site-packages/saic_ismart_client/saic_api.py", line 510, in __handle_retry_with_app_data
    rsp_msg = func(vin_info, rsp_msg.body.event_id)
  File "/usr/local/lib/python3.10/site-packages/saic_ismart_client/saic_api.py", line 539, in __send_vehicle_control_command
    self.message_V2_1_coder.decode_response(vehicle_control_cmd_rsp_msg_hex, vehicle_control_cmd_rsp_msg)
  File "/usr/local/lib/python3.10/site-packages/saic_ismart_client/ota_v2_1/Message.py", line 12, in decode_response
    return super().decode_response(message, decoded_message)
  File "/usr/local/lib/python3.10/site-packages/saic_ismart_client/common_model.py", line 482, in decode_response
    message_body_dict = self.asn1_tool_uper.decode('MPDispatcherBody', dispatcher_message_bytes)
  File "/usr/local/lib/python3.10/site-packages/asn1tools/compiler.py", line 167, in decode
    decoded = type_.decode(data)
  File "/usr/local/lib/python3.10/site-packages/asn1tools/codecs/uper.py", line 500, in decode
    raise e
  File "/usr/local/lib/python3.10/site-packages/asn1tools/codecs/uper.py", line 496, in decode
    return self._type.decode(decoder)
  File "/usr/local/lib/python3.10/site-packages/asn1tools/codecs/per.py", line 830, in decode
    decoded = self.decode_root(decoder)
  File "/usr/local/lib/python3.10/site-packages/asn1tools/codecs/per.py", line 848, in decode_root
    raise e
  File "/usr/local/lib/python3.10/site-packages/asn1tools/codecs/per.py", line 844, in decode_root
    value = member.decode(decoder)
  File "/usr/local/lib/python3.10/site-packages/asn1tools/codecs/uper.py", line 107, in decode
    value = decoder.read_non_negative_binary_integer(self.bits_per_character)
  File "/usr/local/lib/python3.10/site-packages/asn1tools/codecs/per.py", line 449, in read_non_negative_binary_integer
    raise OutOfDataError(self.number_of_read_bits())
asn1tools.codecs.OutOfDataError: MPDispatcherBody.uid: out of data (At bit offset: 189)
nanomad commented 1 year ago

Hex message:

1012E211B0035333434333437313336323530363732FFFD83060C183060C183060C183060C183060C183060C183060C183060C183060C18B060C183060C183768DDBB768C5BB76CC59325AD5830CAB5A37C8E16E1CCE582D738DC30CB8F13870D5BB462DD9346AC584CA72ABC868C1CB1A13983460E5A3703C97C3D5B90320FC400000004000000003280A00104F2630903A3AB09030BD34B7B7329061D4103A3937B8383790333932B8BAB2B73A3297102832B91036309039B4B1BAB932BD3D30903232B6103B32B4B1B7B63796103ABA34B634BD3D30B9329036309031B434B0BB32903334B9B4B1B0903832B91030BB3B34B0B9329034B6103B32B4B1B7B6379032903934B83937BB30B932903237B8379030BB32B91039B832B73A379034B61036B7BA37B93297141B98948

tosate commented 1 year ago

Finally, I found out what is going on here. According to the header, the dispatcher message length is 27, but this is not true. It seems like the API provides a wrong length value. In fact, the message is much longer. However, I found out how to calculate the dispatcher message length.