From e56084a2934d8b9884ad72c2057e731800a5a6d7 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 29 May 2020 00:39:24 -0700 Subject: [PATCH] Add code listings. --- Makefile | 7 ++++-- default.nix | 2 +- listings.tex | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 listings.tex diff --git a/Makefile b/Makefile index fc8ddde..8a3aae1 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,14 @@ archive.pdf: intro.pdf requirements.pdf design-doc.pdf \ binary/techreview-ryan.pdf techreview-daniel.pdf binary/techreview-matt.pdf \ binary/blog-ryan.pdf blog-daniel.pdf binary/blog-matt.pdf \ - readme.pdf resources.pdf reflection.pdf review.pdf + readme.pdf resources.pdf reflection.pdf listings.pdf review.pdf pdfjam --no-tidy --outfile archive.pdf -- intro.pdf requirements.pdf design-doc.pdf \ binary/techreview-ryan.pdf techreview-daniel.pdf binary/techreview-matt.pdf \ binary/blog-ryan.pdf blog-daniel.pdf binary/blog-matt.pdf \ - readme.pdf resources.pdf reflection.pdf review.pdf + readme.pdf resources.pdf reflection.pdf listings.pdf review.pdf + +listings.pdf: listings.tex + pdflatex listings.tex resources.pdf: resources.tex pdflatex resources.tex diff --git a/default.nix b/default.nix index cc1be78..f5ec924 100644 --- a/default.nix +++ b/default.nix @@ -4,7 +4,7 @@ mkShell { buildInputs = [ pandoc (python38.withPackages (ps: with ps; [ pip virtualenv ])) - (texlive.combine { inherit (texlive) framed booktabs pdfjam pdfpages pdflscape scheme-basic IEEEtran collection-fontsrecommended todonotes caption pgfgantt setspace; }) + (texlive.combine { inherit (texlive) listings framed booktabs pdfjam pdfpages pdflscape scheme-basic IEEEtran collection-fontsrecommended todonotes caption pgfgantt setspace; }) ]; } diff --git a/listings.tex b/listings.tex new file mode 100644 index 0000000..664f192 --- /dev/null +++ b/listings.tex @@ -0,0 +1,68 @@ +\documentclass[10pt, draftclsnofoot,onecolumn, compsoc]{IEEEtran} + +\def\changemargin#1#2{\list{}{\rightmargin#2\leftmargin#1}\item[]} +\let\endchangemargin=\endlist + +\usepackage{setspace} +\usepackage{listings} +\linespread{1} + +\title{Appendix 1: Essential Code Listings} + +\begin{document} +\maketitle + +\section*{Android Application} +\subsection*{Login Request} +This class holds information and functionality for building an HTTP request that will be sent to the API servers /login endpoint. +\lstinputlisting[firstline=17, lastline=32]{external/app/app/src/main/java/com/danilafe/fencelessgrazing/requests/LoginRequest.kt} + +\subsection*{Grazing Boundary Editor} +This code allows editing of the current collar's grazing boundary, and achieves this editing through opening BoundaryEditorActivity. +\lstinputlisting[firstline=208, lastline=216]{external/app/app/src/main/java/com/danilafe/fencelessgrazing/ui/activities/CollarDetailActivity.kt} + +\pagebreak +\subsection*{Custom Polygon Class} +This class implements a custom polygon and displays it on the map with certain visual settings for showing the current valid grazing area. +\lstinputlisting[firstline=10, lastline=18]{external/app/app/src/main/java/com/danilafe/fencelessgrazing/ui/components/GrazingPolygon.kt} + +\section*{Server} +\subsection*{Authentication} +This code snipped implements authentication for the API routes. This function is called for each route in the API, and forces authorization using JSON web tokens. If a user has not authenticated themselves, and does not provide a valid JSON web token, an unauthorized error code is presented. +\lstinputlisting[language=Python, firstline=16, lastline=41]{external/server/fgs/jwt.py} + +\pagebreak +\subsection*{Login Route} +This is the code for one of the API routes. This function implements the /login route and allows the user to receive a JSON web token if the correct login information was provided. +\lstinputlisting[language=Python, firstline=18, lastline=35]{external/server/fgs/views.py} + +\pagebreak +\subsection*{User Model Definition} +This code snippet defines the User class, which holds all of the necessary information and functionality for a user including getting, setting, and checking their password. +\lstinputlisting[language=Python, firstline=110, lastline=142]{external/server/fgs/model.py} + +\section*{Gateway Software} +\subsection*{Boundary Pushing} +This function is called every ten seconds and queries the database to see if any new boundaries were added. If so, these boundaries will be queued to be sent to all end-devices. +\lstinputlisting[language=Python, firstline=71, lastline=78]{external/gateway/main.py} + +\pagebreak +\subsection*{Coordinate Storage} +Called each time a message is received from one of the end-devices, this function handles parsing the data received and saving the converted protobuf data to the database with a call to \texttt{store\_collar\_data}. +\lstinputlisting[language=Python, firstline=94, lastline=106]{external/gateway/main.py} + +\section*{Collar Firmware} +\subsection*{Pinout} +This structure provides pin mappings. This information will need to changed based on the hardware implementation and connections. That is, you can rewire / adjust these pin mappings to account for your test-bed. +\lstinputlisting[language=C++, firstline=35, lastline=40]{external/collar/collar.cpp} + +\subsection*{Polygon Boundary Checking} +This function provides all of the boundary checking. A set of coordinates which defines the valid grazing area is sent as input to this function, and a basic math function is run to determine whether or not the current position is within the bounds (defined as a polygon) or outside of the bounds. Essentially just provides bounds checking on a n vertex polygon. +\lstinputlisting[language=C++, firstline=68, lastline=78]{external/collar/collar.cpp} + +\pagebreak +\subsection*{Event Loop} +This is the main Arduino event loop. Code flashed onto the Arduino is expecting to see an event loop that will be called over and over until the hardware is shut down. This event loop checks states and calls the corresponding functions depending on the current state we are in. +\lstinputlisting[language=C++, firstline=246, lastline=268]{external/collar/collar.cpp} + +\end{document}