def beacon_thread(): while True: print "Beacon thread: Waiting %s minutes before sending another beacon" % config.get("APRS encoding", "beacon_period") time.sleep( float( config.get("APRS encoding", "beacon_period") )*60 ) aprs_transmit.send_beacon(config)
def process_aprs_message(config, source_callsign, source_ssid, data): #Read list of authorised users #Note: When reading a list from a config file, the key is #made lower case, while the value is kept intact list_of_users = config.options("Authorised users") #All messages containing a message ID needs to be acked ackording to #the spec, APRS101, p71 msg_id_index = data.rfind('{') if(msg_id_index != -1): aprs_transmit.send_packet(config, ":"+(source_callsign+"-"+source_ssid).ljust(9)+":ack"+data[(msg_id_index+1):]) #Now strip the message id data = data[:msg_id_index] #Remove the callsign from the data data = data[11:] #If the message is in the format ":_________:ack#####" it is an ACK #for a message we sent. We can ignore this message for now. #TODO: mark the packet as acked in a queue of unacked sent messages if (data.lower().find("ack") == 0): return if (config.get("Authorisation","enable_auth") == "True"): #If unauthorised, ignore message further. if(source_callsign.lower() in list_of_users): if (config.get("Authorisation","logauth") == "True"): file = open(config.get("Authorisation","authlogfilelocation"), 'a') file.write("AUTHED USER: "******"-"+source_ssid+" MSG: "+data+"\n") file.close() else: if (config.get("Authorisation","logauth") == "True"): file = open(config.get("Authorisation","authlogfilelocation"), 'a') file.write("UNAUTHED USER: "******"-"+source_ssid+" MSG: "+data+"\n") file.close() #Consider the following line very carefully. Do you really want to send messages on the request of any user? #aprs_transmit.send_message(config, ":"+(source_callsign+"-"+source_ssid).ljust(9)+":Invalid user or password") return if (config.get("Authorisation","require_password") == "True"): #TODO: Use the password in the config file to do authentication user_password = config.get("Authorised users",source_callsign.lower()) if (data.find(user_password) != -1): data = data.strip(user_password) data = data.strip() else: aprs_transmit.send_message(config, ":"+(source_callsign+"-"+source_ssid).ljust(9)+":Invalid user or password") return #Make all caps to be case insensitive data = data.upper() if(data == ""): print "Empty message received." return #If the message is "GET","get","G" or "g", send a packet with the current #GPIO states. if(data.find("GET") == 0 or data.find('G') == 0): aprs_transmit.send_current_state(config,source_callsign, source_ssid) #If the message is "SET A1", "S a1", "s A1" or "set a1,b0...", switch the GPIO's and then send #the current state. elif(data.find("SET") == 0 or data.find('S') == 0): data = data.strip("SET") data = data.strip("S") data = data.strip() ports = data.split(",") success = 1 for port in ports: # ERROR codes: # 1=success, 2=invalid gpio, 3=not an output, 4=invalid state, 5=invalid syntax if (len(port)==2): return_code = gpio_management.set_output(config,port[0],port[1]) if(return_code == 1): print "Port successfully set: "+port else: success = return_code print "Port not set: "+port else: success = 5 print "Invalid syntax for a port" if(success == 1): aprs_transmit.send_current_state(config, source_callsign, source_ssid) elif(success == 2): aprs_transmit.send_message(config, ":"+(source_callsign+"-"+source_ssid).ljust(9)+":Invalid GPIO specified") elif(success == 3): aprs_transmit.send_message(config, ":"+(source_callsign+"-"+source_ssid).ljust(9)+":GPIO not an output") elif(success == 4): aprs_transmit.send_message(config, ":"+(source_callsign+"-"+source_ssid).ljust(9)+":Invalid sate specified") elif(success == 5): aprs_transmit.send_message(config, ":"+(source_callsign+"-"+source_ssid).ljust(9)+":Invalid syntax") #If the message is "B","b","BEACON","BeaCon",.. send a beacon now. elif(data.find("BEACON") == 0 or data.find('B') == 0): aprs_transmit.send_beacon(config)