def parse_frame_text(raw_frame: bytes) -> AprsFrame: """ Parses and Extracts the components of a str Frame. """ parsed_frame = aprs.Frame() _path = [] # Source>Destination sd_delim = raw_frame.index(b'>') parsed_frame.set_source(raw_frame[:sd_delim]) # Path:Info pi_delim = raw_frame.index(b':') parsed_path = raw_frame[sd_delim + 1:pi_delim] if b',' in parsed_path: for path in parsed_path.split(b','): _path.append(path) parsed_frame.set_destination(_path.pop(0)) parsed_frame.set_path(_path) else: parsed_frame.set_destination(parsed_path) parsed_frame.set_info(raw_frame[pi_delim + 1:]) return parsed_frame
def _test_write(self): frame = "%s>%s:%s" % (self.random(6), ','.join([ self.random(6), self.random(6), self.random(6) ]), ' '.join([self.random(), 'test_write', self.random()])) aprs_frame = aprs.Frame(frame) kiss_frame = aprs_frame.encode_kiss() ks = kiss.TCPKISS(host=self.random_host, port=self.random_port) a = (self.random_host, self.random_port) entry = MocketEntry(a, kiss_frame) Mocket.register(entry) self._logger.debug(a) self._logger.debug(entry.get_response()) ks.interface = create_connection(a) ks._write_handler = ks.interface.sendall def _pass(): pass ks.stop = _pass ks.write(kiss_frame)
def test_write_and_read(self): """Tests writing-to and reading-from TCP Host.""" frame = "%s>%s:%s" % (self.random(6), ','.join([ self.random(6), self.random(6), self.random(6) ]), ' '.join([self.random(), 'test_write_and_read', self.random()])) aprs_frame = aprs.Frame(frame) kiss_frame = aprs_frame.encode_kiss() ks = kiss.TCPKISS(host=self.random_host, port=self.random_port) a = (self.random_host, self.random_port) entry = MocketEntry(a, [kiss_frame]) entry_1 = MocketEntry(('localhost', 80), True) Mocket.register(entry) ks.interface = create_connection(a) ks._write_handler = ks.interface.sendall def _pass(): pass ks.stop = _pass ks.write(kiss_frame) _read_data = ks.read(len(kiss_frame), readmode=False) self._logger.info('_read_data(%s)="%s"', len(_read_data), _read_data)
def main(): frame = aprs.Frame() # import pdb; pdb.set_trace() frame = aprs.Frame(source='W2GMD-14', destination='PYKISS', info=bytes('>Hello World!', 'ascii')) ki = kiss.TCPKISS(host=HOST, port=PORT) ki.start() import pdb pdb.set_trace() #ki.write(bytes(str(frame),'ascii')) encoded_frame = bytes(str(frame), 'ascii') ki.write(encoded_frame)
def __init__(self, target="localhost", port=7000, source_callsign='SP3SAT', destination_callsign='PWSAT2-0'): self.context = zmq.Context.instance() self.sock = self.context.socket(zmq.PUB) self.sock.connect("tcp://%s:%d" % (target, port)) time.sleep(1) self.aprs_frame = aprs.Frame() self.aprs_frame.source = aprs.Callsign(source_callsign) self.aprs_frame.destination = aprs.Callsign(destination_callsign)
def main(): frame = aprs.Frame() frame.source = aprs.Callsign('W2GMD-14') frame.destination = aprs.Callsign('PYKISS') frame.path = [aprs.Callsign('WIDE1-1')] frame.text = '>Hello World!' ki = kiss.TCPKISS(host='localhost', port=1234) ki.start() ki.write(frame.encode_kiss())
def test_ax25_decode(self): """ Tests AX.25 Encoding a plain-text APRS Frame. """ #frame = 'W2GMD-1>APRY07,WIDE1-1:>test_ax25_decode' frame = 'W2GMD-1>APRY07:>test_ax25_decode' aprs_frame = aprs.Frame.parse(frame) encoded_frame = aprs_frame.encode_ax25() decoded_frame = aprs.Frame(encoded_frame)
def main(): frame = aprs.Frame() frame.source = aprs.Callsign('ZR6AIC-14') frame.destination = aprs.Callsign('ZR6AIC-5') frame.path = [aprs.Callsign('WIDE1-1')] frame.info = '>Hello World!' ki = kiss2.TCPKISS(host='localhost', port=8001) ki.start() ki.write(frame.encode_ax25())
def write(self, info: str): ''' Create a new Frame and sent it ''' if self.kiss_connection is not None: frame = aprs.Frame(self.source, self.destination, info=bytes(info, 'ascii')) encoded_frame = bytes(str(frame), 'ascii') self.kiss_connection.write(encoded_frame)
def main(): frame = aprs.Frame() frame.source = aprs.Callsign('W2GMD-14') frame.destination = aprs.Callsign('PYKISS') frame.path = [aprs.Callsign('WIDE1-1')] frame.text = '>Hello World!' ki = kiss.SerialKISS(port='/dev/cu.AP510-DevB', speed='9600') ki.start() ki.write(frame.encode_kiss())
def __init__(self, redis_conn, channels, frame, interval): threading.Thread.__init__(self) self.redis_conn = redis_conn self.channels = channels self.aprs_frame = aprs.Frame(frame) self.interval = interval self.pubsub = None self.daemon = True self._stop = threading.Event()
def handle_message(self, message): self._logger.debug('Handling message="%s"', message) if message.get('type') == 'message' and message.get('data'): message_data = message['data'] aprs_frame = aprs.Frame(message_data) # Use the ',I' construct for APRS-IS: if self.aprsc.use_i_construct: aprs_frame.path.append('I') self._logger.info('Sending aprs_frame="%s"', aprs_frame) self.aprsc.send(aprs_frame)
def packetize_me(me, you, path, frametype, name, task, run, data=None, now=None): if data == None: data = "" else: data = " " + str(data) if not now: now = time.time() frametxt = "{{%s %s %s %s %.2f%s" % (frametype, name, task, run, now, data) framestr = "%s>%s,%s:%s" % (me, you, path, frametxt) frame = aprs.Frame(framestr) return frame
def test_write(self): ks = kiss.SerialKISS(port=self.random_serial_port, speed='9600') ks.interface = dummyserial.Serial(port=self.random_serial_port) ks._write_handler = ks.interface.write frame = aprs.Frame() frame.source = aprs.Callsign(self.random(6)) frame.destination = aprs.Callsign(self.random(6)) frame.path = [ aprs.Callsign(self.random(6)), aprs.Callsign(self.random(6)) ] frame.text = ' '.join([self.random(), 'test_write', self.random()]) self._logger.debug('frame="%s"', frame) frame_encoded = frame.encode_kiss() self._logger.debug('frame_encoded="%s"', frame_encoded) ks.write(frame_encoded)
def slash(): post_data = json.loads(flask.request.data) if ('location' in post_data and 'vehicle' in post_data and 'id' in post_data['vehicle']): location = post_data['location'] vehicle_id = post_data['vehicle']['id'] else: print 'No location or vehicle data in POST.' print locals() return 'OK' callsign_map = json.load(open(CALLSIGN_MAP)) if vehicle_id in callsign_map: callsign = callsign_map[vehicle_id] else: print 'No valid vehicle_id to callsign mapping found.' print locals() return 'OK' aprs_conn = aprs.TCP(os.environ.get('APRS_LOGIN', 'AUTOMATIC'), os.environ.get('APRS_PORT')) aprs_conn.start() frame = aprs.Frame() frame.destination = 'APYSAU' frame.path = ['TCPIP'] frame.source = callsign frame.text = ( "!%s\\%s7Automatic-to-APRS gateway. http://ampledata.org" % (aprs.dec2dm_lat(location['lat']), aprs.dec2dm_lng(location['lon']))) print frame aprs_result = aprs_conn.send(frame) print aprs_result return 'OK'
def handle_message(self, message): self._logger.debug('Handling message="%s"', message) if message.get('type') == 'message' and message.get('data'): message_data = message['data'] aprs_frame = aprs.Frame(message_data) if aprsgate.reject_frame(aprs_frame): return for channel in self.out_channels: gate_dir, gate_id, gate_tag = channel.split('_') # Don't re-gate my own frames. (anti-loop) for frame_path in aprs_frame.path: if gate_id in str(frame_path): return aprs_frame.path.append(aprs.Callsign(gate_id)) self._logger.debug('Sending to channel=%s frame="%s"', channel, aprs_frame) self.redis_conn.publish(channel, aprs_frame)
def test_write_and_read(self): """Tests writing-to and reading-from a Dummy Serial port.""" frame = aprs.Frame() frame.source = aprs.Callsign(self.random(6)) frame.destination = aprs.Callsign(self.random(6)) frame.path = [ aprs.Callsign(self.random(6)), aprs.Callsign(self.random(6)) ] frame.text = ' '.join( [self.random(), 'test_write_and_read', self.random()]) self._logger.debug('frame="%s"', frame) frame_encoded = frame.encode_kiss() self._logger.debug('frame_encoded="%s"', frame_encoded) frame_escaped = kiss.escape_special_codes(frame_encoded) self._logger.debug('frame_escaped="%s"', frame_escaped) frame_kiss = ''.join( [kiss.FEND, kiss.DATA_FRAME, frame_escaped, kiss.FEND]) self._logger.debug('frame_kiss="%s"', frame_kiss) ks = kiss.SerialKISS(port=self.random_serial_port, speed=self.random_baudrate) ks.interface = dummyserial.Serial( port=self.random_serial_port, baudrate=self.random_baudrate, ds_responses={frame_encoded: frame_kiss}) ks._write_handler = ks.interface.write ks.write(frame_encoded) read_data = ks._read_handler(len(frame_kiss))
def parse_frame_ax25(raw_frame: bytes) -> AprsFrame: """ Parses and Extracts the components of an AX.25-Encoded Frame. """ parsed_frame = aprs.Frame() kiss_call = False _frame = raw_frame.strip(aprs.AX25_FLAG) if (_frame.startswith(aprs.KISS_DATA_FRAME) or _frame.endswith(aprs.KISS_DATA_FRAME)): _frame = _frame.lstrip(aprs.KISS_DATA_FRAME) _frame = _frame.rstrip(aprs.KISS_DATA_FRAME) kiss_call = True # Use these two fields as the address/information delimiter frame_addressing, frame_information = _frame.split(aprs.ADDR_INFO_DELIM) info_field = frame_information.rstrip(b'\xFF\x07') destination = parse_callsign_ax25(frame_addressing, kiss_call) source = parse_callsign_ax25(frame_addressing[7:], kiss_call) paths = frame_addressing[7 + 7:] n_paths = int(len(paths) / 7) n = 0 path = [] while n < n_paths: path.append(parse_callsign_ax25(paths[:7])) paths = paths[7:] n += 1 parsed_frame.set_source(source) parsed_frame.set_destination(destination) parsed_frame.set_path(path) parsed_frame.set_info(info_field) return parsed_frame
def print_frame(cls, frame): print(aprs.Frame(frame))
def print_frame(frame): print((aprs.Frame(frame)))
def print_frame(frame): print(aprs.Frame(frame[1:]))
def print_frame(cls, frame): print('{}'.format(aprs.Frame(frame)))
def handle_message(self, message): for channel in self.channels: aprs_frame = aprs.Frame(message) self._logger.debug('Publishing to channel=%s aprs_frame="%s"', channel, aprs_frame) self.redis_conn.publish(channel, aprs_frame)
def __init__(self, host='localhost', port=8001): self.kiss = UDPKISS(host, port) self.frame = aprs.Frame() self.frame.source = self.frame.destination = aprs.Callsign("PWSAT2-0") self.frame.text = ""