def handleJSON(self, json_obj): # do whatever with the incoming data... if not srv.DELIV_NAV in json_obj: return deliv_nav = json_obj[srv.DELIV_NAV] # update rover status if srv.STATUS and srv.MESSAGE in deliv_nav: text = srv.INFO_DB_STORE_ATT + " Data being stored: " + json.dumps( json_obj) text = re.sub('\"', '', text) msg = status.StatusMsg(self.name, "STORE", "COLOR", text) self.sendToStatusThread(msg) text = srv.store( json.loads('{ "DELIV_NAV.STATUS": { "$exists": true } }'), json_obj, self.col) text = re.sub('\"', '', text) msg = status.StatusMsg(self.name, "SUCCESS", "STATUS", text) self.sendToStatusThread(msg) # update position elif srv.X and srv.Y in deliv_nav: text = srv.INFO_DB_STORE_ATT + " Data being stored: " + json.dumps( json_obj) text = re.sub('\"', '', text) msg = status.StatusMsg(self.name, "STORE", "COLOR", text) self.sendToStatusThread(msg) text = srv.store( json.loads('{ "DELIV_NAV.X": { "$exists": true } }'), json_obj, self.col) text = re.sub('\"', '', text) msg = status.StatusMsg(self.name, "SUCCESS", "LOC", text) self.sendToStatusThread(msg) # update spped and direction elif srv.RIGHT_DIR and srv.LEFT_DIR and srv.RIGHT_SPEED and srv.LEFT_SPEED in deliv_nav: text = srv.INFO_DB_STORE_ATT + " Data being stored: " + json.dumps( json_obj) text = re.sub('\"', '', text) msg = status.StatusMsg(self.name, "STORE", "COLOR", text) self.sendToStatusThread(msg) text = srv.store( json.loads('{ "DELIV_NAV.RIGHT_DIR": { "$exists": true } }'), json_obj, self.col) text = re.sub('\"', '', text) msg = status.StatusMsg(self.name, "SUCCESS", "SPEED", text) self.sendToStatusThread(msg) if srv.STATUS in deliv_nav: if deliv_nav[srv.STATUS] is 0: # send message for next action (FWD, BACKWARD, etc) #deliv_nav_rtrn_msg = srv.retrieve(self.seq_num, self.col) srv.send_msg(self.client, srv.DELIV_NAV_DEFAULT_ACTION) self.seq_num += 1 return
def handleJSON(self, json_obj): # handle scanner rover sensing message calls if srv.SCAN_SENSE in json_obj: scan_sense = json_obj[srv.SCAN_SENSE] # update quota status if srv.ZONE in scan_sense: if scan_sense[srv.ZONE] is 0: self.client.send(('{ "SEQ": 0, "ZONE": 1, "ACTION": 1 }').encode()) if srv.RED and srv.GREEN and srv.BLUE in scan_sense: text = srv.INFO_DB_STORE_ATT + " Data being stored: " + json.dumps(json_obj) text = re.sub('\"','',text) msg = status.StatusMsg(self.name, "STORE", "COLOR", text) self.sendToStatusThread(msg) text = srv.store(json.loads('{ "SCAN_SENSE.ZONE": ' + str(scan_sense[srv.ZONE]) + ' }'), json_obj, self.col) # text = re.sub('\"','',text) msg = status.StatusMsg(self.name, "SUCCESS", "COLOR", text) self.sendToStatusThread(msg) if json_obj[srv.SEQ_FIELD] <= 100 and json_obj[srv.SEQ_FIELD] >= 0: self.client.send(str('{ "SEQ": 0, "ZONE": ' + str(1) + ' , "ACTION": 1 }').encode()) elif json_obj[srv.SEQ_FIELD] <= 200 and json_obj[srv.SEQ_FIELD] > 100: self.client.send(str('{ "SEQ": 0, "ZONE": ' + str(2) + ' , "ACTION": 1 }').encode()) elif json_obj[srv.SEQ_FIELD] <= 300 and json_obj[srv.SEQ_FIELD] > 200: self.client.send(str('{ "SEQ": 0, "ZONE": ' + str(3) + ' , "ACTION": 1 }').encode()) elif json_obj[srv.SEQ_FIELD] >= 301: self.client.send(str('{ "SEQ": 0, "ZONE": 1 , "ACTION": 1 }').encode())
# Begin to handle messages scan_sense_rtrn_msg = "" scan_nav_rtrn_msg = "" deliv_sense_rtrn_msg = "" deliv_nav_rtrn_msg = "" # update sequence number seq_num = srv.handle_seq(seq_num) # handle scanner rover sensing message calls if SCAN_SENSE in json_obj: scan_sense = json_obj[SCAN_SENSE] # update quota status if ZONE in scan_sense: if RED and GREEN and BLUE in scan_sense: srv.store(json.loads('{ "SCAN_SENSE.ZONE": ' + str(scan_sense[ZONE]) + ' }'), json_obj, scan_snsg_col) else: srv.print_msg(FORMAT_ERR, "RED, GREEN, or BLUE fields do not exist!") else: srv.print_msg(FORMAT_ERR, "ZONE field does not exist!") srv.print_msg(FORMAT_ERR, "ZONE field does not exist!") srv.print_msg(FORMAT_ERR, "ZONE field does not exist!") # send message back of current action (STOP or CONTINUE) #scan_sense_rtrn_msg = srv.retrieve(seq_num, scan_snsg_col) #temp_send = input("Send? ") #zone = input("Zone: ") #if temp_send is 'y': #print("Message sent: ", '{ "SEQ": ' + str(seq_num) + ', "ZONE": ' + zone + ' , "ACTION": 1 }!') #sys.stdout.flush()