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

New Frontend #159

Merged
merged 126 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
ab2ed56
Initial setup
Jun 17, 2019
5cd9316
Some styling done still using mock data
Jun 18, 2019
351ebfd
Alert added temporarily
Jun 18, 2019
fe03518
Minor adjustments
Jun 19, 2019
2fd5041
Cleaner
Jun 19, 2019
3a3d2f1
Reactive components are tough
Jun 19, 2019
afe66f3
Barebones asthetics
Jun 21, 2019
32a4675
Slight improvements
Jun 21, 2019
be14ce9
Data visualization components working
Jun 25, 2019
e402ff2
ToDo added
Jun 25, 2019
48cfcf0
Small changes
Jun 25, 2019
9bfea1d
AHHH I BROKE MY BACK(END) (To make it better ofc)
Jun 25, 2019
b206c1d
Fun stuff
Jun 27, 2019
33ede2a
Added dev stuff
Jul 2, 2019
3c54c52
Dev commands can be sent
Jul 3, 2019
1dfae1b
Buttons working
Jul 3, 2019
3918be3
Oh boy cool stuff! Auto updating and dev working
Jul 5, 2019
ea6f6ec
More stats added
Jul 6, 2019
7d8aaa7
Added stat trackers
Jul 6, 2019
7ac2ed0
Coloring works for stats
Jul 7, 2019
dceb783
Buttons working
Jul 8, 2019
dfc5d8a
Readme changes
Jul 8, 2019
703f9b6
Merge remote-tracking branch 'origin/pod4' into New-Frontend
Jul 9, 2019
5626140
Server startup script + tcp starts when frontend
Jul 9, 2019
9d08ae3
Merge branch 'Evan's-Edits' into New-Frontend
Jul 9, 2019
b83a0e8
Python3 not 2
Jul 9, 2019
e44572e
chmod added
Jul 9, 2019
2b3280f
Merge branch 'New-Frontend' of https://github.com/IlliniHyperloopComp…
Jul 9, 2019
99d8f4c
All can data added
Jul 9, 2019
cb9e201
Its working :)
Jul 12, 2019
126e5d5
Merge remote-tracking branch 'origin/pod4' into New-Frontend
Jul 12, 2019
092d194
Fixes for buttons
Jul 13, 2019
3ea4c58
More fixes
Jul 13, 2019
e9699b9
Fixes to I2C I hope plus frontend fixes
Jul 13, 2019
74acd10
AGH segfault fix maybe
Jul 13, 2019
daf4a08
I think I got it this time
Jul 13, 2019
89df625
Fixed I2C issue with off by one bug
Jul 13, 2019
daa4833
Merge remote-tracking branch 'origin/pod4' into New-Frontend
Jul 13, 2019
de90216
Fixes and such (BaseStation i2c support)
Jul 13, 2019
c674774
Fix to weird NUM_ACCEL error
Jul 13, 2019
d37172a
Fixes and such
Jul 13, 2019
819f1e6
fixed severed connection
Jul 13, 2019
f9b12cb
Fixed(??) the udp server. Didn't really do much, though
rgw3d Jul 13, 2019
4669e2f
Reducing the UDP heartbeat timeout
rgw3d Jul 13, 2019
f8cb93b
god damn udp. When in doubt, beej
rgw3d Jul 14, 2019
2dbbc99
adding printouts to demonstrate how UDP now works
rgw3d Jul 14, 2019
cf56e34
Slight fixes to udpserver
Jul 14, 2019
75df10d
Trying a slightly different socket configuration... this time it shou…
rgw3d Jul 14, 2019
91ccadb
still mucking around with udpserver.py
rgw3d Jul 14, 2019
eb56293
Merge branch 'New-Frontend' of github.com:IlliniHyperloopComputing/Po…
rgw3d Jul 14, 2019
a8aaa47
Oops, there was a broken loop that wouldn't have worked anyway
rgw3d Jul 14, 2019
8f7c4bf
Removing unecessary printout from UDPserver.py
rgw3d Jul 14, 2019
ba23164
Added UDP ping error
anshulshah957 Jul 15, 2019
6ab9363
New UDP Error
anshulshah957 Jul 15, 2019
6d43378
Auto stash before merge of "New-Frontend" and "origin/New-Frontend"
Jul 15, 2019
6877e92
ADC added
Jul 15, 2019
bee6d05
made acceleration mean of ADC data
anshulshah957 Jul 15, 2019
e5f954f
ADC fix
Jul 15, 2019
2dcd0c5
Bug fix
Jul 15, 2019
c7f1479
Removed motor encoder usage
anshulshah957 Jul 15, 2019
53327ae
Merged pull
anshulshah957 Jul 15, 2019
c21c9f7
Commands work and renamed ADC data
Jul 15, 2019
dee396d
Merge remote-tracking branch 'origin/pod4' into New-Frontend
Jul 16, 2019
5af99bb
Auto stash before merge of "New-Frontend" and "origin/pod4"
Jul 16, 2019
4a097e0
Added frontend enable_motor
Jul 16, 2019
7184b93
Fixes for frontend enable_motor
Jul 16, 2019
1c4f79e
Fixed sentinel and UDP errors
anshulshah957 Jul 16, 2019
7ab8292
Added abort for UDP
anshulshah957 Jul 16, 2019
587d5f3
Changed chars to ints
Jul 17, 2019
4d22113
Merge branch 'New-Frontend' of https://github.com/IlliniHyperloopComp…
Jul 17, 2019
cb52f0c
Potential Fix
Jul 17, 2019
0afc805
Finally got Relay working
Jul 17, 2019
86c70ad
UDP and TCP codes
Jul 17, 2019
38af290
Made code a uint8
Jul 17, 2019
4822bbd
Merge remote-tracking branch 'origin/pod4' into New-Frontend
Jul 17, 2019
de6c678
Moved cast to u32, abort is now 13
anshulshah957 Jul 17, 2019
9d575e6
Merge branch 'New-Frontend' of https://github.com/IlliniHyperloopComp…
anshulshah957 Jul 17, 2019
57651f6
back to u8
anshulshah957 Jul 17, 2019
5261f8d
Fixed tcpserver issues
Jul 18, 2019
61d4bf9
Fixed motion stuff
Jul 18, 2019
fdb92f3
Merge remote-tracking branch 'origin/pod4' into New-Frontend
Jul 18, 2019
6ce9b27
Added transition to abort on UDP error
anshulshah957 Jul 18, 2019
f0b2beb
Fixes to PRU and debug stuff added
Jul 18, 2019
78e97a6
Added error color framework
Jul 18, 2019
61bf1c1
Merge remote-tracking branch 'origin/New-Frontend' into New-Frontend
Jul 18, 2019
0c550fe
PRU resets at start now
anshulshah957 Jul 19, 2019
5a4f731
Switched PRU to GPIO reads
anshulshah957 Jul 19, 2019
9624c7d
Changed some GPIO pin numbers
anshulshah957 Jul 19, 2019
ef9c168
We can supprt bms now
Jul 19, 2019
112a82b
Merge branch 'New-Frontend' of https://github.com/IlliniHyperloopComp…
Jul 19, 2019
e581773
Min and max
Jul 19, 2019
6f3087b
Temp stage
Jul 19, 2019
765bc23
Debugged PRU implementation
anshulshah957 Jul 19, 2019
33289bd
Merge branch 'New-Frontend' of https://github.com/IlliniHyperloopComp…
anshulshah957 Jul 19, 2019
5835047
Changed CAN val
anshulshah957 Jul 19, 2019
a4b409d
ITS POD DAY MY DUDES AGHHHHH
Jul 20, 2019
539e439
Merge branch 'New-Frontend' of https://github.com/IlliniHyperloopComp…
Jul 20, 2019
fbc3607
Some stuff
Jul 20, 2019
e5cb67b
Fixed frontend
Jul 20, 2019
0cef470
Fixes to stuff and what not
Jul 20, 2019
d8c7442
Merge remote-tracking branch 'origin/pod4' into New-Frontend
Jul 20, 2019
59edb4c
GIT REBASE -f now
Jul 20, 2019
2698c50
BMS readout fix
Jul 20, 2019
71cc6d9
input added
Jul 20, 2019
5512acd
BMS readout and TCP status
Jul 20, 2019
c4ab73b
fix my studpi fuckup
rgw3d Jul 20, 2019
e89bd33
Fix PRU
rgw3d Jul 20, 2019
51d8826
Correct PRU shit now
rgw3d Jul 20, 2019
bd0df0d
FUCK
rgw3d Jul 20, 2019
837b17c
Changed Ranges according to pod health and config files. Added '?' to…
rishiwadhwa0 Jul 20, 2019
f22760f
help debug unknown frame
rgw3d Jul 20, 2019
4f80af5
Big fix energy
Jul 20, 2019
b699c02
Merge branch 'New-Frontend' of https://github.com/IlliniHyperloopComp…
Jul 20, 2019
122a9f6
add ADC printout
rgw3d Jul 20, 2019
6cde12f
Remove unecessary printout
rgw3d Jul 20, 2019
53a43aa
Remove I2C erros
rgw3d Jul 20, 2019
24ba5c1
Fixed merge conflicts.
rishiwadhwa0 Jul 20, 2019
581c069
Fuckk
rgw3d Jul 20, 2019
e27e6a6
Merge branch 'New-Frontend' of github.com:IlliniHyperloopComputing/Po…
rgw3d Jul 20, 2019
f2ecce4
fuckk2
rgw3d Jul 20, 2019
e4ba1c6
AGH WHY ME
Jul 20, 2019
7503d33
Merge
Jul 20, 2019
84bcf5e
Plz work thermisters
Jul 20, 2019
44b6c8f
why
rgw3d Jul 20, 2019
122dfa5
Merge branch 'New-Frontend' of github.com:IlliniHyperloopComputing/Po…
rgw3d Jul 20, 2019
d93ee86
Fuck me endian
rgw3d Jul 20, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ cross-test
# Other
.depend
*.swp
BaseStation/Backend/db.sqlite3
56 changes: 27 additions & 29 deletions BBBSetup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ This folder contains all of the setup information for the BBB. Device tree overl

# BBB OS Setup
* Using this [Debian 9.4 image](http://debian.beagleboard.org/images/bone-debian-9.4-iot-armhf-2018-06-17-4gb.img.xz), follow the SD card installation steps at the bottom of this README.
* This guide is specific to just this version of Debian, with the 4.14 kernel. There have been big, breaking changes from previous kernel versions. uEnv.txt is differnt. Device overlays are different.
* This guide is specific to just this version of Debian, with the 4.14 kernel. There have been big, breaking changes from previous kernel versions. uEnv.txt is different. Device overlays are different.
* To connect when plugged directly into your personal computer, I like having a static ethernet port. SSHing over USB is slower, and sometimes drops
* Setup network by editing `/etc/network/interfaces` and adding:
```
Expand Down Expand Up @@ -67,42 +67,42 @@ uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-14-TI-00A0.dtbo
* The above was setup following instructions in the reference guide.
* PRU usage for Optical inputs, device tree overlay setup
* The main challenge with the PRU is that many of the guides were written several years ago (when the BBB came out) and since there have been updates to the kernel. (now on 4.14)
* Use this --> [TI's walk through guide](http://processors.wiki.ti.com/index.php/PRU_Training:_Hands-on_Labs).
* Use this --> [TI's walk through guide](http://processors.wiki.ti.com/index.php/PRU_Training:_Hands-on_Labs).
* TI's [main page on the PRU-ICSS](http://processors.wiki.ti.com/index.php/PRU-ICSS).
* This is [pretty good guide too](http://processors.wiki.ti.com/index.php/RPMsg_Quick_Start_Guide#Booting_the_Board_and_Testing_RPMsg)
* [elinux guide](https://elinux.org/EBC_Exercise_30_PRU_via_remoteproc_and_RPMsg) Look at the BeagleScope example for how someone else has done it.
* [Best reference](https://elinux.org/images/d/da/Am335xPruReferenceGuide.pdf) I could find explaining all of the register level details of the PRU.
* [Best reference](https://elinux.org/images/d/da/Am335xPruReferenceGuide.pdf) I could find explaining all of the register level details of the PRU.
* The PRU Header files necessary for development with their IDE are included in this repo. They were found [here](http://www.ti.com/tool/PROCESSOR-SDK-AM335X). Pretty confusing, but it was in the "PROCESSOR\_SDK\_LINUX\_AM335X", once installed it was in some example files for the PRU.
* _OLD_ An alternative method for [loading modules](https://groups.google.com/forum/#!topic/beagleboard-gsoc/amMNLt4EoHM), which links to this [gist](https://gist.github.com/alexanderhiam/2c4187c710b2c409d8dde8c4015fe007).
* _OLD_ [Another developer blog with links](https://ianrrees.github.io/2016/11/20/getting-started-with-beaglebone-pru-programming-the-new-way.html)
* _OLD_ guide on setting the PRUSS -- Programmable Real-time Unit Sub System. [Derek Molloy's site](http://exploringbeaglebone.com/chapter13/)
* GPIO output device tree overlay setup
* [Derek Molloy's site](http://derekmolloy.ie/gpios-on-the-beaglebone-black-using-device-tree-overlays/). Goes through how to install the device tree, and most importently how to initialize the GPIO once it has been setup in the device tree.
* Check `/sys/class/gpio/`
* 'export' a GPIO by: `echo <num> /sys/class/gpio/export`, where you replae `<num>` with the appropriate "GPIO No." fouund in the P8 and P9 HeaderTable.pdf
* Check `/sys/class/gpio/`
* 'export' a GPIO by: `echo <num> /sys/class/gpio/export`, where you replae `<num>` with the appropriate "GPIO No." fouund in the P8 and P9 HeaderTable.pdf
* Change to output or input with `echo "out" > /sys/class/gpio/gpio<num>/output`
* Set pin value with `echo 1 > /sys/class/gpio/gpio<num>/value`, or read the file if an input
* [Device-Tree Overlay Generator](http://www.kilobaser.com/blog/2014-07-28-beaglebone-black-devicetreeoverlay-generator).
* [Device-Tree Overlay Generator](http://www.kilobaser.com/blog/2014-07-28-beaglebone-black-devicetreeoverlay-generator).
* One-Wire communication protocol for DS18B20 temperature sensor device tree overlay
* [Reference here](http://www.bonebrews.com/temperature-monitoring-with-the-ds18b20-on-a-beaglebone-black/).
* Check the comments, there are syntax errors. There is a missing `;` on line 37.
* Run `cat /sys/bus/w1/devices/28-*/w1_slave` to get the temperature, multiplied by 1000.
* I2C is already enabled by default by the kernel. On I2C2 bus.
* View all device trees on BBB: `dtc -f -I fs /proc/device-tree | less `
* [Device-Tree Overlay Generator](http://www.kilobaser.com/blog/2014-07-28-beaglebone-black-devicetreeoverlay-generator).
* [Device-Tree Overlay Generator](http://www.kilobaser.com/blog/2014-07-28-beaglebone-black-devicetreeoverlay-generator).


# Pin reference
* The two PDFs in this directory contain detailed information about each header.
* CAN Bus
* The two PDFs in this directory contain detailed information about each header.
* CAN Bus
* P9-24 (CAN RX) and P9-26 (CAN TX).
* ADC
* ADC
* P9-33 through P9-40
* PWM
* P9-14 (EHRPWM1A) or P9-16 (EHRPWM1B)
* GPIO input for PRU, Optical sensors
* P8-27 through P8-29, and P8-39 through P8-46
* GPIO output
* GPIO output
* P8-7 through P8-10
* DS18B20 temperature sensors
* P8-11 (and optionally P8-12)
Expand All @@ -113,60 +113,58 @@ uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-14-TI-00A0.dtbo

# BBB SD Card installation

This guide covers how to setup a BeagleBone Black Rev.c with all necessary software
This guide covers how to setup a BeagleBone Black Rev.c with all necessary software

* Download the appropriate image as specified earlier in this document. Although it is dated, I have found [this](http://derekmolloy.ie/write-a-new-image-to-the-beaglebone-black/) to generally be a good guide, but is slightly outdated (as explained below)
* The old guide assumes that the image will automatically begin writing itself to the onboard storage. As described on the [beagleboard.org](https://beagleboard.org/latest-images) site, you will need to modify the `/boot/uEnv.txt` file
* The correct modifications are made later in this guide

* Copy the `.img` file on to a microSD card
* Windows
* Windows
* Extract the `.img` using WinRAR
* Copy onto the uSD card using Win32 Disk imager
* Linux
* Linux
* Extract the `.img` using `xz -d bone-*.img.xz`
* Use `lsblk` to find the name of the microSD card
* Make sure the microSD card is unmounted (not ejected)
* Copy onto the uSD card using `sudo dd if=./bone-*.img of=/dev/NAME status=progress`
* Mac
* Extract the `.img` using `gunzip bone-*.img.xz`
* Mac
* Extract the `.img` using `gunzip bone-*.img.xz`
* Use `diskutil list` to find the name of the microSD card
* Make sure the microSD card is unmounted (not ejected) using `diskutil unmountDisk /dev/disk#`
* Copy onto the uSD card using `sudo dd bs=1m if=./bone-*.img of=/dev/rdisk# conv=sync status=progress`. If this fails, try `/dev/disk#` instead of `/dev/rdisk#`

* Insert the microSD card into the BBB, with the power off

* Hold down the boot button (near the SD card), and plug in power.
* I used USB power from my computer, such that I can SSH into the BBB
* Hold down the boot button (near the SD card), and plug in power.
* I used USB power from my computer, such that I can SSH into the BBB

* Hold the boot button until the LEDs flash

* Wait for the BBB to turn on. It has now booted onto the image on the SD card.
* Wait for the BBB to turn on. It has now booted onto the image on the SD card.

* SSH into the BBB (I found the default username/password [here](http://elinux.org/BeagleBoardDebian))
* The BBB has default drivers that setup a network connection over USB at IPs `192.168.7.2` and `192.168.6.2`.
* The BBB has default drivers that setup a network connection over USB at IPs `192.168.7.2` and `192.168.6.2`.
* Windows
* Wait until the BBB file dialog opens, then you will be able to SSH in.
* Use PuTTY or other appropriate terminal: `ssh [email protected]` with the password `temppwd`.
* Wait until the BBB file dialog opens, then you will be able to SSH in.
* Use PuTTY or other appropriate terminal: `ssh [email protected]` with the password `temppwd`.
* Linux (Ubuntu)
* Check network connections with `ifconfig`
* Use `ssh [email protected]` with the password `temppwd`

* Once logged in
* Edit `/boot/uEnv.txt` use: `sudo vim /boot/uEnv.txt` or `sudo nano /boot/uEnv.txt`
* Go to the bottom of the file, and remove the ‘#’ in front of `cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh` to uncomment it.
* Edit `/boot/uEnv.txt` use: `sudo vim /boot/uEnv.txt` or `sudo nano /boot/uEnv.txt`
* Go to the bottom of the file, and remove the ‘#’ in front of `cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh` to uncomment it.

* Reboot the BBB with `sudo shutdown -r now`
* Begin to hold the boot button
* Hold the boot button until the BBB powercycles, and the LEDs turn back on (just as above)
* After a few moments of booting up and LEDs flashing, the installation will start. The LEDs will flash in a Cyclon/ Knight Rider patter.
* After a few moments of booting up and LEDs flashing, the installation will start. The LEDs will flash in a Cyclon/ Knight Rider patter.
* Wait until the LEDs stop flashing,
* The BBB should power off, but I have found that sometimes it finishes with all LEDs on.
* The BBB should power off, but I have found that sometimes it finishes with all LEDs on.
* Unplug the SD card, otherwise the image will re-install!
* Power back on the BBB! The newest image should be installed and ready to go
* SSH as described above
* Create a new user, named `abc`, with password `hyperloop`. Use: `sudo adduser abc`.
* Add the new user to all of the groups that the user `debian` is a part of. This may not be strictly necessary, but I didn't want to spend the time to figure it out. List all the groups (while logged in as `debian`) with `groups`.
* Add the new user to all of the groups that the user `debian` is a part of. This may not be strictly necessary, but I didn't want to spend the time to figure it out. List all the groups (while logged in as `debian`) with `groups`.
* Add the new user to each group with: `sudo usermod -aG <group_name> <user_name>`. At a minimum, add the user to the `sudo` group.


16 changes: 13 additions & 3 deletions BBBSetup/initGPIO
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#!/bin/bash
echo 66 > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio66/direction
echo 26 > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio26/direction
echo 46 > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio46/direction
echo 65 > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio65/direction
echo 61 > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio61/direction
echo 45 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio45/direction
echo 68 > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio68/direction
echo 69 > /sys/class/gpio/export
echo "out" > /sys/class/gpio69/direction
echo 13 > /sys/class/gpio/export
echo "out" > /sys/class/gpio13/direction
echo "out" > /sys/class/gpio/gpio69/direction
1 change: 1 addition & 0 deletions BBBSetup/initPRU
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ echo 'am335x_pru1_fw' > /sys/class/remoteproc/remoteproc2/firmware
echo 'start' > /sys/class/remoteproc/remoteproc2/state
pru2Stat=$?
echo "pru core 1 is now loaded"
chmod 777 /dev/rpmsg_pru31

if [ $pru1Stat -eq 0 ] && [ $pru2Stat -eq 0 ]
then
Expand Down
Binary file modified BaseStation/Backend/db.sqlite3
Binary file not shown.
137 changes: 137 additions & 0 deletions BaseStation/Backend/podconnect/actions_logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from . import tcpserver, udpserver, models
import json
from django.http import HttpResponse, HttpRequest, JsonResponse

TCPUp = False
UDPUp = False

def buttonPressed(request):
state_data = models.State.objects.latest("date_time")
if request.method == "POST":
message = request.body.decode()
mess = json.loads(message)
if mess["button"] == "ready":
if state_data.state == 0:
print("Transitioning to Test Outside")
tcpserver.addToCommandQueue([1])
elif state_data.state == 1:
print("Transitioning to Loading")
tcpserver.addToCommandQueue([2])
elif state_data.state == 2:
print("Transitioning to Test Inside")
tcpserver.addToCommandQueue([3])
elif state_data.state == 3:
print("Transitioning to Launch Ready")
tcpserver.addToCommandQueue([4])
elif state_data.state == 4:
print("Transitioning to Ready")
tcpserver.addToCommandQueue([5])
else:
print("State out of left button range")
else:
print("AGGHHHH STOP FAST")
tcpserver.addToCommandQueue([13])
udpserver.addToCommandQueue([13])
return HttpResponse(state_data.state)

def devCommand(request):
if request.method == "POST":
message = request.body.decode()
mess = json.loads(message)
command = int(mess["command"])
if command == -1:
return HttpResponse()
print("Command " + str(command))
if command == 0: # TRANS_SAFE_MODE = 0,
tcpserver.addToCommandQueue([0])
elif command == 1: # TRANS_FUNCTIONAL_TEST_OUTSIDE = 1,
tcpserver.addToCommandQueue([1])
elif command == 2: # TRANS_LOADING = 2,
tcpserver.addToCommandQueue([2])
elif command == 3: # TRANS_FUNCTIONAL_TEST_INSIDE = 3,
tcpserver.addToCommandQueue([3])
elif command == 4: # TRANS_LAUNCH_READY = 4,
tcpserver.addToCommandQueue([4])
elif command == 5: # TRANS_FLIGHT_ACCEL = 5,
tcpserver.addToCommandQueue([5])
elif command == 6: # ENABLE_MOTOR = 6,
tcpserver.addToCommandQueue([6])
elif command == 7: # DISABLE_MOTOR = 7,
tcpserver.addToCommandQueue([7])
elif command == 8: # SET_MOTOR_SPEED = 8,
value = int(mess["value"])
tcpserver.addToCommandQueue([8, value])
elif command == 9: # ENABLE_BRAKE = 9,
tcpserver.addToCommandQueue([9])
elif command == 10: # DISABLE_BRAKE = 10,
tcpserver.addToCommandQueue([10])
elif command == 11: # TRANS_FLIGHT_COAST = 11,
tcpserver.addToCommandQueue([11])
elif command == 12: # TRANS_FLIGHT_BRAKE = 12,
tcpserver.addToCommandQueue([12])
elif command == 13: # TRANS_ABORT = 13,
tcpserver.addToCommandQueue([13])
elif command == 14: # SET_ADC_ERROR = 14,
value = int(mess["value"])
tcpserver.addToCommandQueue([14, value])
elif command == 15: # SET_CAN_ERROR = 15,
value = int(mess["value"])
tcpserver.addToCommandQueue([15, value])
elif command == 16: # SET_I2C_ERROR = 16,
value = int(mess["value"])
tcpserver.addToCommandQueue([16, value])
elif command == 17: # SET_PRU_ERROR = 17,
value = int(mess["value"])
tcpserver.addToCommandQueue([17, value])
elif command == 18: # SET_NETWORK_ERROR = 18,
value = int(mess["value"])
tcpserver.addToCommandQueue([18, value])
elif command == 19: # SET_OTHER_ERROR = 19,
value = int(mess["value"])
tcpserver.addToCommandQueue([19, value])
elif command == 20: # CLR_ADC_ERROR = 20,
tcpserver.addToCommandQueue([20])
elif command == 21: # CLR_CAN_ERROR = 21,
tcpserver.addToCommandQueue([21])
elif command == 22: # CLR_I2C_ERROR = 22,
tcpserver.addToCommandQueue([22])
elif command == 23: # CLR_PRU_ERROR = 23,
tcpserver.addToCommandQueue([23])
elif command == 24: # CLR_NETWORK_ERROR = 24,
tcpserver.addToCommandQueue([24])
elif command == 25: # CLR_OTHER_ERROR = 25,
tcpserver.addToCommandQueue([25])
elif command == 26: # SET_HV_RELAY_HV_POLE = 26,
print(mess)
value = int(mess["value"])
if value != 0 and value != 1:
return HttpResponse("Value out of range")
tcpserver.addToCommandQueue([26, value])
elif command == 27: # SET_HV_RELAY_LV_POLE = 27,
print(mess)
value = int(mess["value"])
if value != 0 and value != 1:
return HttpResponse("Value out of range")
tcpserver.addToCommandQueue([27, value])
elif command == 28: # SET_HV_RELAY_PRE_CHARGE = 28,
print(mess)
value = int(mess["value"])
if value != 0 and value != 1:
return HttpResponse("Value out of range")
tcpserver.addToCommandQueue([28, value])
elif command == 29: # CALC_ACCEL_ZERO_G = 29,
tcpserver.addToCommandQueue([29])

return HttpResponse()
return HttpResponse()

def startupServers(request):
global TCPUp, UDPUp
if request.method == "POST":
if not TCPUp:
tcpserver.start()
TCPUp = True
if not UDPUp:
udpserver.start()
UDPUp = True
return HttpResponse()
44 changes: 44 additions & 0 deletions BaseStation/Backend/podconnect/data_logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django.shortcuts import render
from . import models, tcpserver, udpserver, stats_helper
from django.http import HttpResponse, HttpRequest, JsonResponse
from django.core.serializers import serialize
import pickle
import struct

from threading import Lock
import json

def state(request):
state_data = models.State.objects.latest("date_time")
toReturn = state_data.state
return HttpResponse(toReturn)

def stats(request):
toReturn = stats_helper.getStats()
return JsonResponse(toReturn, safe=False)

def battery(request):
can_data = models.CANData.objects.latest("date_time")
toReturn = {
"value": can_data.pack_soc
}
print(can_data.pack_soc)
return JsonResponse(toReturn)

def position(request):
motion_data = models.MotionData.objects.latest("date_time")
toReturn = {
"currentDistance":motion_data.position,
"totalDistance":1200
}
return JsonResponse(toReturn)

def stopPressed(request):
if request.method == "POST":
print("STOPPING")
return HttpResponse()

def readyPressed(request):
if request.method == "POST":
print("Ready!")
return HttpResponse()
Loading