def send_GN_registration_request(self): # This event is set by sensor_controller after it stores the sensors' info in config file logger.debug("Waiting for sensors info." + "\n\n") # Waits till sensor_plugin object finishes writing to the config file # so that race conditions don't occur sensors_info_saved_event.wait() config = ConfigObj(config_file_name) temp_config = {} temp_config["Systems Info"] = config["Systems Info"] temp_config["Sensors Info"] = config["Sensors Info"] reg_payload = RegistrationPayload() reg_payload.sys_info = dict(temp_config) reg_payload.instance_id = get_instance_id() self.send_to_buffer_mngr(registration_type, no_reply, [reg_payload])
def send_data_msg(self, item): data_payload = DataPayload() data_payload.sens_id = item.msg[0] data_payload.read_tm = item.msg[1] data_payload.inst_id = get_instance_id() ret = True for reading_name, reading_type, reading_value, reading_unit, reading_note in\ zip(item.msg[2], item.msg[3], item.msg[4], item.msg[5], item.msg[6]): ret = (ret and data_payload.add_item(reading_name, reading_type, \ reading_value, reading_unit, reading_note)) if not ret: logger.critical("Error in packing data....................................") logger.debug("DATA PAYLOAD:" + str(data_payload) + "\n\n") self.send_to_buffer_mngr(data_type, item.reply_id, [data_payload]) logger.debug("Data msg sent to bufr mngr to send to NC." + "\n\n")
def gen_msg(self, item): try: header = MessageHeader() header.instance_id = get_instance_id() header.message_type = item.msg_type # saves the session_id + new subseq_no which is called: highest_nc_subseq_no header.sequence_id = self.gen_gn_seq_no() # To indicate the last subseq_no of GN till which all ACKs ie replies from NC have been received # NOTE: Its important to increment the highest_gn_subseq_no first # (which is done in above function call: gen_gn_seq_no) and then call gen_gn_ackd_subseq_no header.user_field1 = self.gen_gn_ackd_subseq_no(item.msg_type) header.reply_to_id = item.reply_id msg = Message() msg.header = header for each_msg in item.msg: msg.append(each_msg) try: msg = msg.encode() except Exception as inst: logger.critical("ERROR: Exception while encoding msg: " + str(inst) ) return msg except Exception as inst: logger.critical("ERROR: Exception in gen_msg: " + str(inst))