Skip to content

Commit

Permalink
Merge branch 'master' into frontend-team
Browse files Browse the repository at this point in the history
  • Loading branch information
daisycrego committed Apr 26, 2020
2 parents dc0bbb4 + f795cc8 commit ab38224
Show file tree
Hide file tree
Showing 34 changed files with 778 additions and 614 deletions.
29 changes: 29 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ignore everything
*

# except the hardware directory
!hardware

# things we want to ignore in the file directory
**/__pycache__
**/*.pyc
**/*.pyo
**/*.pyd
**/.Python
**/.env
**/pip-log.txt
**/pip-delete-this-directory.txt
**/.tox
**/.coverage
**/.coveragerc
**/.coverage.*
**/.cache
**/nosetests.xml
**/coverage.xml
**/*,cover
**/*.log

# things we want to specifically include
!pi_requirements.txt
!Dockerfile

3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ max-line-length = 119
exclude =
.git,
__pycache__,
venv
venv,
pi_venv
**/migrations
27 changes: 27 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Title
_Give a self-explanatory title_

## Description
_If this fixes a bug or resolves an issue, provide a link to that issue. Give a detailed description that answers:_
- _what is the purpose of this PR?_
- _what is the original vs the new behaviour?_
- _what bug does this PR attempt to fix?_
- _what is documented in the new documentation?_

## Types of Changes
_Put an `x` in the boxes that apply_

- [ ] Feature (non-breaking change which adds functionality)
- [ ] Bug Fix (non-breaking change that fixes an issue)
- [ ] Breaking Change (feature/fix that causes existing features to not work as expected)
- [ ] Documentation

## Checklist

- [ ] I have read the [contribute]contributing<link> doc
- [ ] Classes, scripts, and environment variables follow existing naming convention
- [ ] Lint and Unit tests pass locally
- [ ] New features on hardware have been tested on a local Raspberry Pi
- [ ] Mention new programs/binaries if any must be installed along with this change
- [ ] Mention new environment variables if any have been added to hardware/env file
- [ ] Test coverage should not drop more than 3%
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ jobs:
services:
- docker

before_script:
install:
- docker pull nyumotorsportstelemetryorg/mercury || true

script:
# prepare qemu for arm emulation on x64 hardware
- docker run --rm --privileged multiarch/qemu-user-static:register --reset
# build image
# - docker build -t gcivil-nyu-org/spring2020-cs-gy-9223-class .
- docker build --pull --cache-from nyumotorsportstelemetryorg/mercury --tag nyumotorsportstelemetryorg/mercury .
# basic help world test to see if it's working
- docker run nyumotorsportstelemetryorg/mercury grep -q "Hello, Docker!" hello.txt
# - black --check --exclude "migrations/" hardware
- docker run -d --name test_pi nyumotorsportstelemetryorg/mercury

script:
# insure that the server started up as expected
- docker ps -a
- docker ps | grep -q test_pi

after_script:
- docker images
Expand Down
20 changes: 17 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
FROM raspbian/stretch

ENV PYTHONUNBUFFERED 1

# install common build dependencies and clean up afterwards
RUN apt-get update && apt-get install -y --no-install-recommends \
raspi-config \
python3-pip \
python3-sense-emu \
sense-emu-tools \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir ~/Downloads
RUN mkdir hardware

# copy setup scripts
COPY ./hardware .
COPY ./hardware/setup/raspberrypi-common.sh .

# run setup
RUN bash ./setup/raspberrypi-common.sh
RUN bash ./raspberrypi-common.sh

COPY ./hardware/pi_requirements.txt .
RUN sudo python3 -m pip install pip --upgrade --force
RUN sudo pip3 install -r pi_requirements.txt

COPY ./hardware hardware/

RUN echo "Hello, Docker!" > hello.txt
CMD [ "python3", "-m", "hardware.main" ]
13 changes: 10 additions & 3 deletions hardware/CommunicationsPi/comm_pi.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import os
from http.server import BaseHTTPRequestHandler
from hardware.CommunicationsPi.radio_transceiver import Transceiver

transceiver = Transceiver()


class CommPi(BaseHTTPRequestHandler):
def __init__(self, *args, **kwargs):
self.transceiver = Transceiver()
super().__init__(*args, **kwargs)

def _set_response(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
Expand All @@ -23,5 +26,9 @@ def do_POST(self):
self.wfile.write("POST request for {}".format(self.path).encode("utf-8"))

def send_data(self, payload):
transceiver.send(payload)
if os.environ.get("ENABLE_INTERNET_TRANSMISSION"):
print("transmit via internet")
if os.environ.get("ENABLE_RADIO_TRANSMISSION"):
print("transmit via radio")
self.transceiver.send(payload)
return
143 changes: 0 additions & 143 deletions hardware/CommunicationsPi/find_port.py

This file was deleted.

17 changes: 8 additions & 9 deletions hardware/CommunicationsPi/lan_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
from http.server import BaseHTTPRequestHandler, HTTPServer
from hardware.Utils.utils import get_logger

log = get_logger("LAN_SERVER_LOG_FILE")


class Server(BaseHTTPRequestHandler):
def __init__(self, *args, **kwargs):
self.log = get_logger("LAN_SERVER_LOG_FILE")
super().__init__(*args, **kwargs)

def _set_response(self):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.end_headers()

def do_GET(self):
global log

log.info(
self.log.info(
"GET request,\nPath: %s\nHeaders:\n%s\n"
+ str(self.path)
+ str(self.headers)
Expand All @@ -24,19 +25,18 @@ def do_GET(self):
self.wfile.write("GET request for {}".format(self.path).encode("utf-8"))

def do_POST(self):
global log

content_length = int(
self.headers["Content-Length"]
) # <--- Gets the size of data
post_data = self.rfile.read(content_length) # <--- Gets the data itself
log.info(
self.log.info(
"POST request,\nPath: %s\nHeaders:\n%s\n\nBody:\n%s\n"
+ str(self.path)
+ str(self.headers)
+ post_data.decode("utf-8")
)
log.info("data: " + str(post_data))
self.log.info("data: " + str(post_data))

self._set_response()
self.wfile.write("POST request for {}".format(self.path).encode("utf-8"))
Expand All @@ -45,11 +45,10 @@ def do_POST(self):
def runServer(
server_class=HTTPServer, handler_class=Server, log_file_name=None, port=None
):
global log
log = (
get_logger("LAN_SERVER_LOG_FILE")
if log_file_name is None
else get_logger(log_file_name, log_file_name)
else get_logger(log_file_name)
)

port = int(os.environ["LAN_PORT"]) if port is None else port
Expand Down

0 comments on commit ab38224

Please sign in to comment.