示例#1
0
 def send_reg_msg_to_cloud(self, inst_id):
     try:
         reg_payload = RegistrationPayload()
         config = ConfigObj(config_file_name)
         l=lambda:defaultdict(l)
         reg_dict = l()
         if config["Registered"] == 'NO':
             reg_dict["Systems Info"] = config["Systems Info"]
         for node in config["GN Info"]:
             if config["GN Info"][node]["Registered"] == 'NO':
                 # append this GN's info to the registration dict
                 reg_dict["GN Info"][node]["Systems Info"] = config["GN Info"][node]["Systems Info"]
                 reg_dict["GN Info"][node]["Sensors Info"] = config["GN Info"][node]["Sensors Info"]
         reg_payload.sys_info = reg_dict
         reg_payload.instance_id = get_instance_id()
         buff_msg = buffered_msg(registration_type, None, no_reply, [reg_payload], inst_id)
         # Sends registration msg by sending to buffer_mngr
         add_to_thread_buffer(self.buffer_mngr.outgoing_ncMsgBfr[inst_id], buff_msg, 'buffer_mngr')
         logger.debug("Registration msg sent to bufr mngr to send to cloud.")
     except Exception as inst:
         logger.critical("Exception in send_reg_msg_to_cloud:" + str(inst))
示例#2
0
 def gen_msg(self, item):
     try:
         header = MessageHeader()
         header.message_type = item.msg_type
         header.instance_id = get_instance_id()
         # saves the session_id + new subseq_no which is called: highest_nc_subseq_no
         header.sequence_id = self.gen_nc_seq_no(item.sock_or_gn_id)
         # To indicate the last subseq_no of NC till which all ACKs ie replies from this GN have been received
         # NOTE: Its important to increment the highest_nc_subseq_no first
         # (which is done in above function call: gen_nc_seq_no) and then call gen_nc_ackd_subseq_no
         header.user_field1 = self.gen_nc_ackd_subseq_no(item.sock_or_gn_id, 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("Exception while encoding msg: " + str(inst) )
         logger.debug("Msg Encoded.")
         return msg
     except Exception as inst:
         logger.critical("Exception in gen_msg: " + str(inst))