Cleaned up whitespace

This commit is contained in:
Mark Qvist 2020-05-27 16:17:40 +02:00
parent a683e2df4d
commit 02525cee55
2 changed files with 449 additions and 449 deletions

View File

@ -7,13 +7,15 @@ from RNode import RNodeInterface
# We'll also define which serial port the # We'll also define which serial port the
# RNode is attached to. # RNode is attached to.
serialPort = "/dev/ttyUSB0" serialPort = "/dev/ttyUSB0"
# TODO: Remove
serialPort = "/dev/tty.usbserial-DN03E0FQ"
# This function gets called every time a # This function gets called every time a
# packet is received # packet is received
def gotPacket(data, rnode): def gotPacket(data, rnode):
print "Received a packet: "+data print("Received a packet: "+data)
print "RSSI: "+str(rnode.r_stat_rssi)+" dBm" print("RSSI: "+str(rnode.r_stat_rssi)+" dBm")
print "SNR: "+str(rnode.r_stat_snr)+" dB" print("SNR: "+str(rnode.r_stat_snr)+" dB")
# Create an RNode instance. This configures # Create an RNode instance. This configures
# and powers up the radio. # and powers up the radio.
@ -30,10 +32,10 @@ rnode = RNodeInterface(
# Enter a loop waiting for user input. # Enter a loop waiting for user input.
try: try:
print "Waiting for packets, hit enter to send a packet, Ctrl-C to exit" print("Waiting for packets, hit enter to send a packet, Ctrl-C to exit")
while True: while True:
raw_input() input()
rnode.send("Hello World!") rnode.send("Hello World!")
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
print "" print("")
exit() exit()

View File

@ -1,4 +1,3 @@
from __future__ import print_function
from time import sleep from time import sleep
import sys import sys
import serial import serial
@ -7,48 +6,47 @@ import time
import math import math
class KISS(): class KISS():
FEND = chr(0xC0) FEND = 0xC0
FESC = chr(0xDB) FESC = 0xDB
TFEND = chr(0xDC) TFEND = 0xDC
TFESC = chr(0xDD) TFESC = 0xDD
CMD_UNKNOWN = 0xFE
CMD_DATA = 0x00
CMD_FREQUENCY = 0x01
CMD_BANDWIDTH = 0x02
CMD_TXPOWER = 0x03
CMD_SF = 0x04
CMD_CR = 0x05
CMD_RADIO_STATE = 0x06
CMD_RADIO_LOCK = 0x07
CMD_DETECT = 0x08
CMD_PROMISC = 0x0E
CMD_READY = 0x0F
CMD_STAT_RX = 0x21
CMD_STAT_TX = 0x22
CMD_STAT_RSSI = 0x23
CMD_STAT_SNR = 0x24
CMD_BLINK = 0x30
CMD_RANDOM = 0x40
CMD_FW_VERSION = 0x50
CMD_ROM_READ = 0x51
CMD_UNKNOWN = chr(0xFE) DETECT_REQ = 0x73
CMD_DATA = chr(0x00) DETECT_RESP = 0x46
CMD_FREQUENCY = chr(0x01)
CMD_BANDWIDTH = chr(0x02)
CMD_TXPOWER = chr(0x03)
CMD_SF = chr(0x04)
CMD_CR = chr(0x05)
CMD_RADIO_STATE = chr(0x06)
CMD_RADIO_LOCK = chr(0x07)
CMD_DETECT = chr(0x08)
CMD_PROMISC = chr(0x0E)
CMD_READY = chr(0x0F)
CMD_STAT_RX = chr(0x21)
CMD_STAT_TX = chr(0x22)
CMD_STAT_RSSI = chr(0x23)
CMD_STAT_SNR = chr(0x24)
CMD_BLINK = chr(0x30)
CMD_RANDOM = chr(0x40)
CMD_FW_VERSION = chr(0x50)
CMD_ROM_READ = chr(0x51)
DETECT_REQ = chr(0x73) RADIO_STATE_OFF = 0x00
DETECT_RESP = chr(0x46) RADIO_STATE_ON = 0x01
RADIO_STATE_ASK = 0xFF
RADIO_STATE_OFF = chr(0x00) CMD_ERROR = chr0x90
RADIO_STATE_ON = chr(0x01) ERROR_INITRADIO = chr0x01
RADIO_STATE_ASK = chr(0xFF) ERROR_TXFAILED = chr0x02
ERROR_EEPROM_LOCKED = chr0x03
CMD_ERROR = chr(0x90)
ERROR_INITRADIO = chr(0x01)
ERROR_TXFAILED = chr(0x02)
ERROR_EEPROM_LOCKED = chr(0x03)
@staticmethod @staticmethod
def escape(data): def escape(data):
data = data.replace(chr(0xdb), chr(0xdb)+chr(0xdd)) data = data.replace(bytes([0xdb]), bytes([0xdb, 0xdd]))
data = data.replace(chr(0xc0), chr(0xdb)+chr(0xdc)) data = data.replace(bytes([0xc0]), bytes([0xdb, 0xdc]))
return data return data