Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added radio_transeiver class #256

Merged
merged 7 commits into from Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion hardware/CommunicationsPi/lan_server.py
Expand Up @@ -42,7 +42,7 @@ def run(server_class=HTTPServer, handler_class=S, port=8080):
logging.basicConfig(level=logging.INFO)
server_address = ("", port)
httpd = server_class(server_address, handler_class)
logging.info("Starting httpd...\n")
log.info("Starting httpd...\n")
try:
httpd.serve_forever()
except KeyboardInterrupt:
Expand Down
46 changes: 46 additions & 0 deletions hardware/CommunicationsPi/radio_transceiver.py
@@ -0,0 +1,46 @@
import os
import serial
import json

from .utils import get_logger, get_serial_stream


class Transceiver:
def __init__(self, log_file_name=None, port=None):
if log_file_name is None:
self.logging = get_logger("TRANSMITTER_LOG_FILE")
else:
self.logging = get_logger(log_file_name)

port = os.environ["RADIO_TRANSMITTER_PORT"] if port is None else port
baudrate = 9600
parity = serial.PARITY_NONE
stopbits = serial.STOPBITS_ONE
bytesize = serial.EIGHTBITS
timeout = 1

self.logging.info("Opening serial")
self.serial = serial.Serial(
port=port,
baudrate=baudrate,
parity=parity,
stopbits=stopbits,
bytesize=bytesize,
timeout=timeout,
)

def send(self, payload):
self.logging.info("sending")
self.serial.write(get_serial_stream(payload))
self.logging.info(payload)

def listen(self):
payload = self.serial.readline().decode("utf-8")
message = "Error: Check logs"
if payload != "":
try:
message = json.loads(payload)
self.logging.info(message)
except json.JSONDecodeError:
self.logging.error(json.JSONDecodeError)
return message
27 changes: 0 additions & 27 deletions hardware/CommunicationsPi/serial_read.py

This file was deleted.

28 changes: 0 additions & 28 deletions hardware/CommunicationsPi/serial_write.py

This file was deleted.