def set_software(self, name=UPDATE_INTERVAL, value=None): if(value == None): Error.handle_error('radar software set value error') return False if name == self.UPDATE_INTERVAL: self.update_interval = value return True
def save_hardware_state(self): set_save_message = CanFrame(CONFIG_MESSAGE_ID + self.radar_id * DELTA_ADDRESS, [self.SAVE << 1 | self.W_CONST, 0]) ret = self.can_device.transmit_message(self.channel_id, set_save_message) if not ret: Error.handle_error('radar state save error') return False radar_return_message_id = self.RADAR_RETURN_MESSAGE_ID + self.radar_id * DELTA_ADDRESS ack = self.can_device.get_data_by_id(self.channel_id, radar_return_message_id) if len(ack) == 0: Error.handle_error('radar save ack error') return False ack_data = ack[-1].data if ack_data[0] & RW_MASK != 1: Error.handle_error('radar state save error') return False return True
def set_hardware(self, name=RADAR_ID, value=None): if(value == None): Error.handle_error('radar hardware set value error') return False #radar hardware related dataType_and_RW = name << 1 | self.W_CONST ret = 0 config_message_id = self.CONFIG_MESSAGE_ID + self.radar_id * DELTA_ADDRESS if name == self.RADAR_ID: #radar_id: [dataType:0b1 + R/W:0/1, Value: radar_id] set_radar_id_message = CanFrame(config_message_id, [dataType_and_RW, value]) if not value in range(MAX_DEVICES_IN_CHANNEL): Error.handle_error('radar set radar id value error') return False ret = self.can_device.transmit_message(self.channel_id, set_radar_id_message) elif name == self.OUTPUT_MODE: #output mode: [dataType:0b11 + R/W:0/1, PointOutput: stop:0 / start:1, ClusterOutput: stop:0 / start:1, TraceOutput: stop:0 / start:1, IIRFilterOutput: stop:0 / start:1, Reserve:0] set_output_mode_message = CanFrame(config_message_id, [dataType_and_RW, 0, 0, 0, 0, 0]) output_mode = value if output_mode == self.POINT_MODE: set_output_mode_message.data[1] = 1 elif output_mode == self.CLUSTER_MODE: set_output_mode_message.data[2] = 1 elif output_mode == self.TRACE_MODE: set_output_mode_message.data[3] = 1 elif output_mode == self.IIRFILTER_MODE: set_output_mode_message.data[4] = 1 else: Error.handle_error('radar set output mode value error') return False ret = self.can_device.transmit_message(self.channel_id, set_output_mode_message) elif name == self.OUTPUT_SWITCH: #output switch: [dataType:0b100 + R/W:0/1, Value: stop:0 / start:1] if value != self.STOP and value != self.START: Error.handle_error('radar set output switch value error') return False set_output_switch_message = CanFrame(config_message_id, [dataType_and_RW, value]) ret = self.can_device.transmit_message(self.channel_id, set_output_switch_message) elif name == self.DETECTION_MODE: #detection mode: [dataType:0b101 + R/W:0/1, Radar_Mode: short:1 / middle:2] if value != self.SHORT_MODE and value != self.MIDDLE_MODE: Error.handle_error('radar set detection mode value error') return False set_detection_mode_message = CanFrame(config_message_id, [dataType_and_RW, value]) ret = self.can_device.transmit_message(self.channel_id, set_detection_mode_message) elif name == self.CAN_CONFIG: #can config: [dataType:0b111 + R/W:0/1, Baud: 250k:1 / 500k:2 / 1000k:3, Y/N:0/1, FrameType: standard:1, extend:2, Y/N:0/1] baud = value[self.CAN_BAUD_CONFIG] frame_type = value[self.CAN_FRAME_CONFIG] if baud != self.BAUD_250K and baud != self.BAUD_500K and baud != self.BAUD_1000K: Error.handle_error('radar set can config value error') return False if frame_type != self.STANDARD_FRAME and frame_type != self.EXTEND_FRAME: Error.handle_error('radar set can config value error') return False set_can_config_message = CanFrame(config_message_id, [dataType_and_RW, baud, 1, frame_type, 1]) ret = self.can_device.transmit_message(self.channel_id, set_can_config_message) else: Error.handle_error('radar set name error') return False if not ret: Error.handle_error('radar hardware set error') return False time.sleep(0.5) #wait ack radar_return_message_id = self.RADAR_RETURN_MESSAGE_ID + self.radar_id * DELTA_ADDRESS ack = self.can_device.get_data_by_id(self.channel_id, radar_return_message_id) if len(ack) == 0: Error.handle_error('radar hardware set ack error') return False #type of ack is list canFrame #the length of ack should be 1, if not, choose the last(also leatest) one ack_data = ack[-1].data #ack_data: [dataType:0b110 + success:0/1, radar_id, detection_mode, output switch, point:0/1 + cluster:0/1 + trace:0/1 + iirFilter:0/1 + reserved, can_baud: + can_type] if ack_data[0] & RW_MASK == 1: if name == self.RADAR_ID: self.radar_id = value elif name == self.OUTPUT_MODE: self.output_mode = value elif name == self.OUTPUT_SWITCH: self.output_switch = value elif name == self.DETECTION_MODE: self.detection_mode = value elif name == self.CAN_CONFIG: self.can_baud = value[self.CAN_BAUD_CONFIG] self.frame_type = value[self.CAN_FRAME_CONFIG] else:#never come here return False else: Error.handle_error('radar hardware set error') return False return True