def analyse_data_payload(self, curr_data_item): data_payload = curr_data_item.data_payload # split the data string into chunks of length 4 index_list = StrManipulator.split_string( data_payload, GlobalConstants.PAYLOAD_INDICES_LEN) if not index_list: return True index_list = StrManipulator.remove_every_other(index_list) index_list = list(map(Calculator.get_int, index_list)) # generate a sequence of numbers according to data buffer length # (number of data chunks) packet_len = Calculator.get_int(curr_data_item.packet_len) BYTES_PER_DATA_CHUNK = 2 data_payload_len = packet_len - GlobalConstants.DATA_PARAMS_LEN num_seq_len = data_payload_len / BYTES_PER_DATA_CHUNK # divide by 2 because of taking into account every other num num_seq_len /= 2 num_seq_len = int(num_seq_len) num_seq = list(range(0, num_seq_len)) if index_list != num_seq: self.add_com_error('UNORDERED DATA CONTENT') return False return True
def extract_data_payload(self): # remove indices if not self.data_payload_value: payload = StrManipulator.split_string( self.data_payload, GlobalConstants.PAYLOAD_INDICES_LEN) payload = StrManipulator.remove_every_other(payload, True) payload = StrManipulator.list_into_str(payload) self.data_payload_value = payload
def analyse_heartbeat(self, data_payload: str): period = StrManipulator.substring( data_payload, GlobalConstants.HEARTBEAT_PERIOD_START, GlobalConstants.HEARTBEAT_PERIOD_END) period = Calculator.get_int(period) self.curr_heartbeat_period = DataStructFunctions.get_key( GlobalConstants.HEARTBEAT_PERIODS, period) id = StrManipulator.substring(data_payload, GlobalConstants.HEARTBEAT_ID_START, GlobalConstants.HEARTBEAT_ID_END) id = Calculator.get_int(id) heartbeat = DataPacketFactory.get_packet('HEARTBEAT_RESPONSE', params={'heartbeat_id': id}) return heartbeat
def extract_packet_length(self, data_header: str): self.packet_len = StrManipulator.substring( data_header, GlobalConstants.PACKET_LEN_START_INDEX, GlobalConstants.PACKET_LEN_END_INDEX) int_len = Calculator.get_int(self.packet_len) # number of hex digits self.len_of_hex = int_len * 2
def extract_message_code(self, data_header: str): msg_code = StrManipulator.substring( data_header, GlobalConstants.MSG_CODE_START_INDEX, GlobalConstants.MSG_CODE_END_INDEX) msg_code = Calculator.get_int(msg_code) self.msg_code = msg_code self.purpose = DataStructFunctions.get_key( GlobalConstants.MESSAGE_CODE_DICT, msg_code)
def __init__(self, complete_data=''): self.time = '' self.complete_data = complete_data self.data_payload = '' self.payload_len = 0 self.packet_len = '' self.checksum = '' self.msg_code = '' self.data_index = 0 self.data_index_hex = '' self.len_of_hex = 0 #number of digits in hexadecimal representation self.purpose = '' self.data_payload_value = '' if self.complete_data: header = StrManipulator.substring( self.complete_data, 0, GlobalConstants.DATA_PAYLOAD_START_INDEX) payload = StrManipulator.substring( self.complete_data, GlobalConstants.DATA_PAYLOAD_START_INDEX, len(self.complete_data)) self.add_header_info(header) self.data_payload = payload
def extract_addresses(self): self.faulty_addresses = self.data[GlobalConstants. MEM_ADDRESSES_START::] self.faulty_addresses = StrManipulator.split_string( self.faulty_addresses, GlobalConstants.MEM_ADDRESSES_LEN)
def check_overflow(self): overflow = StrManipulator.substring(self.data, GlobalConstants.OVERFLOW_START, GlobalConstants.OVERFLOW_END) if overflow != '00': self.overflow = True
def extract_err_cnt(self): cnt = StrManipulator.substring(self.data, GlobalConstants.ERROR_CNT_START, GlobalConstants.ERROR_CNT_END) cnt = Calculator.get_int(cnt) self.error_num = cnt
def extract_mem_error_id(self): id = StrManipulator.substring(self.data, GlobalConstants.MEM_ERROR_INDEX_START, GlobalConstants.MEM_ERROR_INDEX_END) self.mem_error_id = id
def extract_checksum(self, data_header: str): checksum = StrManipulator.substring( data_header, GlobalConstants.CHECKSUM_START_INDEX, GlobalConstants.CHECKSUM_END_INDEX) self.checksum = Calculator.get_int(checksum)
def extract_data_counter(self, data_header: str): data_index = StrManipulator.substring( data_header, GlobalConstants.DATA_COUNTER_START_INDEX, GlobalConstants.DATA_COUNTER_END_INDEX) self.data_index = Calculator.get_int(data_index) self.data_index_hex = data_index