Index: scripts/update_package_script/update_package.py =================================================================== diff -u -r4958f2a616031e26b9d0f662b4faca8b28832a53 -r167604cac199c133488d55eb0163e88eadd0e123 --- scripts/update_package_script/update_package.py (.../update_package.py) (revision 4958f2a616031e26b9d0f662b4faca8b28832a53) +++ scripts/update_package_script/update_package.py (.../update_package.py) (revision 167604cac199c133488d55eb0163e88eadd0e123) @@ -61,6 +61,8 @@ """ status = False self._reset_variables() + # Create the CAN listener list from the Leahi messages + self._utilities.clear_can_listener() # TODO how to read from a manifest file. Right now it is passed directly # TODO if stack to update and stack target are not provided, then just read through the manifest files if stack_to_update is not None and destination is not None: @@ -234,15 +236,12 @@ @return none """ - - # Reset firmware - # Wait for the bootloader to come up - # Start updating - list_of_binary_files = self._find_binary_files(packages_dir) if len(list_of_binary_files) == 0: exit(0) # No binary files to process - #self._handle_broadcast_message_thread(start_thread=True) + self._utilities.send_update_available_to_firmware_stacks() + self._handle_broadcast_message_thread(start_thread=True) + time.sleep(1.5) # Wait a while or have a broadcast check for binary_file in list_of_binary_files: # Make sure the file is opened a binary or hex if not binary_file.endswith(".bin") and not binary_file.endswith(".hex"): continue @@ -251,4 +250,4 @@ self._verify_stack_update() # TODO skip if the timeout or another error # Done with update binary files, stop sending the broadcast message - #self._handle_broadcast_message_thread(start_thread=False) + self._handle_broadcast_message_thread(start_thread=False) Index: scripts/update_package_script/utilities.py =================================================================== diff -u -r4958f2a616031e26b9d0f662b4faca8b28832a53 -r167604cac199c133488d55eb0163e88eadd0e123 --- scripts/update_package_script/utilities.py (.../utilities.py) (revision 4958f2a616031e26b9d0f662b4faca8b28832a53) +++ scripts/update_package_script/utilities.py (.../utilities.py) (revision 167604cac199c133488d55eb0163e88eadd0e123) @@ -7,11 +7,32 @@ from can.interfaces.socketcan.socketcan import SocketcanBus class CANMessageListener(can.Listener): + """ + CAN Message Listener + The class is CAN listener + """ def __init__(self): + """ + CANMessageListener class constructor + + """ self.raw_can_messages = list() + def clear_message_list(self): + """ + Publicly accessible method to clear the list of the raw CAN messages. + + @return none + """ + self.raw_can_messages.clear() + def on_message_received(self, msg: can.Message): + """ + Publicly accessible method to receive the raw CAN messages + + @return none + """ self.raw_can_messages.append(msg) @@ -92,11 +113,34 @@ 0xD2DFB272, 0xCC03DD33, 0xEF676CF0, 0xF1BB03B1, 0xA9AE0F76, 0xB7726037, 0x9416D1F4, 0x8ACABEB5, ) + CRC_LIST = ( + 0, 49, 98, 83, 196, 245, 166, 151, 185, 136, 219, 234, 125, 76, 31, 46, + 67, 114, 33, 16, 135, 182, 229, 212, 250, 203, 152, 169, 62, 15, 92, 109, + 134, 183, 228, 213, 66, 115, 32, 17, 63, 14, 93, 108, 251, 202, 153, 168, + 197, 244, 167, 150, 1, 48, 99, 82, 124, 77, 30, 47, 184, 137, 218, 235, + 61, 12, 95, 110, 249, 200, 155, 170, 132, 181, 230, 215, 64, 113, 34, 19, + 126, 79, 28, 45, 186, 139, 216, 233, 199, 246, 165, 148, 3, 50, 97, 80, + 187, 138, 217, 232, 127, 78, 29, 44, 2, 51, 96, 81, 198, 247, 164, 149, + 248, 201, 154, 171, 60, 13, 94, 111, 65, 112, 35, 18, 133, 180, 231, 214, + 122, 75, 24, 41, 190, 143, 220, 237, 195, 242, 161, 144, 7, 54, 101, 84, + 57, 8, 91, 106, 253, 204, 159, 174, 128, 177, 226, 211, 68, 117, 38, 23, + 252, 205, 158, 175, 56, 9, 90, 107, 69, 116, 39, 22, 129, 176, 227, 210, + 191, 142, 221, 236, 123, 74, 25, 40, 6, 55, 100, 85, 194, 243, 160, 145, + 71, 118, 37, 20, 131, 178, 225, 208, 254, 207, 156, 173, 58, 11, 88, 105, + 4, 53, 102, 87, 192, 241, 162, 147, 189, 140, 223, 238, 121, 72, 27, 42, + 193, 240, 163, 146, 5, 52, 103, 86, 120, 73, 26, 43, 188, 141, 222, 239, + 130, 179, 224, 209, 70, 119, 36, 21, 59, 10, 89, 104, 255, 206, 157, 172 + ) + _SEND_CMD_MAIL_BOX = 0x601 _BROADCAST_UPDATE_MAIL_BOX = 0x606 - MSG_ID_FFU_SIGNAL_TD_UPDATE_AVAILABLE = 0xA6 - MSG_ID_FFu_SIGNAL_DD_UPDATE_AVAILABLE = 0xA7 + _LEAHI_START_MESSAGE_BYTE = 0xA5 + _LEAHI_SEQ_1_BYTE = 0x1234 + _LEAHI_SEQ_2_BYTE = 0x34 + _LEAHI_SIGNAL_TD_UPDATE_AVAILABLE = 0x00A6 + _LEAHI_SIGNAL_DD_UPDATE_AVAILABLE = 0x00A7 + _SHIFT_8_BITS_FOR_BYTE_SHIFT = 8 _SHIFT_24_BITS = 24 _SHIFT_BITS_BY_A_NIBBLE = 4 @@ -123,6 +167,7 @@ self._msg_id_count = 0 self._msg_sw_update_index = 0 self._update_mail_boxes = dict() + self._leahi_mail_boxes = dict() self._msg_ack_nack_status = dict() self._total_msg_count = 0 self._stack = 0 @@ -131,7 +176,7 @@ self._msg_ack_nack_status[self.UPDATE_MSG_ACK_STATUS_KEY_NAME] = [CanCommStatus.CAN_COMM_NOT_STARTED.value, 0] self.file_handle = open(os.path.join(os.getcwd(), 'ack_log.log'), 'w') - self._prepare_update_mail_boxes(self._update_mail_boxes) + self._prepare_update_mail_boxes() self._can_listener = CANMessageListener() self._notifier = can.Notifier(self._can_bus, [self._can_listener]) @@ -156,6 +201,14 @@ """ self._msg_ack_nack_status[msg_type][0] = CanCommStatus.CAN_COMM_NOT_STARTED.value + def clear_can_listener(self): + """ + Publicly accessible method to clear the CAN listener. + + @return none + """ + self._can_listener.clear_message_list() + def send_command_msg(self, cmd: int, stack: int, destination: int): """ Publicly accessible method to send a command message to the bootloader @@ -227,7 +280,14 @@ self._get_bootloader_ack_nack_resp(self.UPDATE_MSG_ACK_STATUS_KEY_NAME) def send_update_available_broadcast_message(self, stop_event, interval: int): + """ + Publicly accessible method to send the update available broadcast message. + @param stop_event: the stop event thread flag + @param interval: broadcast interval + + @return none + """ count = 1 while not stop_event.is_set(): count += 1 @@ -237,8 +297,28 @@ crc_32 = self._get_crc32(can_msg_bytes) can_msg_bytes += self._convert_data_to_bytes(' THESE ARE FOR BOOTLOADER + #self._leahi_mail_boxes[UpdateStacks.STACK_DD.name] = {self._STACK_SEND_UPDATE_MAIL_BOX: 0x605, + # self._STACK_RCV_RESP_MAIL_BOX: 0x604} + @staticmethod def _convert_data_to_bytes(conversion: str, data: int): """ @@ -352,7 +459,11 @@ return converted def _get_current_message_count(self): + """ + Privately accessible method to get the current message count. + @return current message count + """ self._msg_id_count = self._msg_id_count + 1 if self._msg_id_count < 0xFFFF else 0 return self._msg_id_count