Skip to content

Commit

Permalink
Add BRK board to Debian SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
neerajdantu committed Mar 3, 2022
1 parent 78cb872 commit 3bea536
Show file tree
Hide file tree
Showing 15 changed files with 543 additions and 77 deletions.
74 changes: 49 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ATF_VERSION=arm-trusted-firmware-2.4
UBOOT_VERSION = u-boot-2020.10
KERNEL_VERSION=linux-5.10
GCNANO_VERSION=6.4.3
GCNANO_SUBVERSION=20200902

FSBL_DIR ?= $(realpath bootloader/$(ATF_VERSION))
SSBL_DIR ?= $(realpath bootloader/$(UBOOT_VERSION))
Expand All @@ -16,15 +17,18 @@ MULTISTRAP_DIR ?= $(realpath multistrap)
ROOTFS_DIR ?= $(MULTISTRAP_DIR)/multistrap-debian-bullseye
GCNANO_DIR ?= $(realpath gcnano-$(GCNANO_VERSION).binaries)
GCNANO_DRV_DIR ?= $(GCNANO_DIR)/gcnano-driver-$(GCNANO_VERSION)
GCNANO_USR_DIR ?= $(GCNANO_DIR)/gcnano-userland-multi-$(GCNANO_VERSION)-*
GCNANO_USR_DIR ?= $(GCNANO_DIR)/gcnano-userland-multi-$(GCNANO_VERSION)-$(GCNANO_SUBVERSION)
M4PROJECTS_DIR ?= $(realpath STM32CubeMP1)
DEPLOY_DIR ?= $(PWD)/deploy
BUILDTOOLS_DIR ?= $(realpath build-tools)

MODE ?= trusted
#MODE ?= basic
BOARD_NAME := stm32mp157c-osd32mp1-red
KDEFCONFIG ?= multi_v7_defconfig
BOOT_EMMC = 1
BOOT_SD = 1
BOARD_RED = stm32mp157c-osd32mp1-red
BOARD_BRK = stm32mp157c-osd32mp1-brk

ARCH ?= arm
CROSS_COMPILE ?= arm-linux-gnueabihf-
Expand Down Expand Up @@ -78,12 +82,18 @@ setup:
patch --ignore-whitespace $(DEPLOY_DIR)/create_sdcard_from_flashlayout.sh $(BUILDTOOLS_DIR)/files/flash-tools/sdcard-script.patch

# First stage bootloader
# Add to if statement for custom board
fsbl: setup patch_fsbl
cp $(BUILDTOOLS_DIR)/files/fsbl/Makefile.sdk $(FSBL_DIR)
PWD=$(FSBL_DIR) $(MAKE) $(FLAGS) -C $(FSBL_DIR) -f Makefile.sdk stm32
cp $(FSBL_DIR)/deploy/tf-a-$(BOARD_NAME)-sdcard.stm32 $(DEPLOY_DIR)
cp $(FSBL_DIR)/deploy/tf-a-$(BOARD_NAME)-emmc.stm32 $(DEPLOY_DIR)
cp $(FSBL_DIR)/deploy/tf-a-$(BOARD_NAME)-usb.stm32 $(DEPLOY_DIR)
if [ "$(BOOT_SD)" -eq "1" ]; then \
cp $(FSBL_DIR)/deploy/tf-a-$(BOARD_NAME)-sdcard.stm32 $(DEPLOY_DIR); \
fi
if [ "$(BOOT_EMMC)" -eq "1" ]; then \
cp $(FSBL_DIR)/deploy/tf-a-$(BOARD_NAME)-emmc.stm32 $(DEPLOY_DIR); \
fi


# Second stage bootloader
ssbl: setup fsbl patch_ssbl
Expand Down Expand Up @@ -142,7 +152,7 @@ rootfs: kernel gcnano m4_demo
mkdir -p $(ROOTFS_DIR)/lib/firmware/brcm/
cp $(BUILDTOOLS_DIR)/files/firmwares/CYW43430A1.1DX.hcd $(ROOTFS_DIR)/lib/firmware/brcm/BCM43430A1.hcd
cp $(BUILDTOOLS_DIR)/files/firmwares/LICENCE.cypress $(ROOTFS_DIR)/lib/firmware/LICENCE.cypress_bcm4343
cp $(BUILDTOOLS_DIR)/files/firmwares/brcmfmac43430-sdio.txt $(ROOTFS_DIR)/lib/firmware/brcm/
cp $(BUILDTOOLS_DIR)/files/firmwares/brcmfmac43430-sdio.txt $(ROOTFS_DIR)/lib/firmware/brcm/brcmfmac43430-sdio.octavo,stm32mp157c-osd32mp1-red.txt
cp $(BUILDTOOLS_DIR)/files/firmwares/brcmfmac43430-sdio.bin $(ROOTFS_DIR)/lib/firmware/brcm/
cp $(BUILDTOOLS_DIR)/files/firmwares/brcmfmac43430-sdio.1DX.clm_blob $(ROOTFS_DIR)/lib/firmware/brcm/brcmfmac43430-sdio.clm_blob

Expand All @@ -157,25 +167,36 @@ rootfs: kernel gcnano m4_demo
sed -i -e "s:@userfs_mount_point@:${STM32MP_USERFS_MOUNTPOINT_IMAGE}:" $(ROOTFS_DIR)/sbin/st-m4firmware-load-default.sh
cp $(M4PROJECTS_DIR)/st-m4firmware-load.service $(ROOTFS_DIR)/lib/systemd/system/

# Install demo files
cp $(BUILDTOOLS_DIR)/files/demo_camera.sh $(ROOTFS_DIR)/home/debian
cp $(BUILDTOOLS_DIR)/files/demo_video.sh $(ROOTFS_DIR)/home/debian
cp $(BUILDTOOLS_DIR)/files/OSD32MP1_RED_intro_360p.mp4 $(ROOTFS_DIR)/home/debian
# Install demo files for OSD32MP1-RED
ifeq ($(BOARD_NAME), $(BOARD_RED))
cp $(BUILDTOOLS_DIR)/files/demo_red/demo_camera.sh $(ROOTFS_DIR)/home/debian; \
cp $(BUILDTOOLS_DIR)/files/demo_red/demo_video.sh $(ROOTFS_DIR)/home/debian; \
cp $(BUILDTOOLS_DIR)/files/demo_red/OSD32MP1_RED_intro_360p.mp4 $(ROOTFS_DIR)/home/debian;
endif

# Instll demo files for OSD32MP1-BRK
ifeq ($(BOARD_NAME), $(BOARD_BRK))
mkdir -p $(ROOTFS_DIR)/usr/local/demo/; \
cp -R $(BUILDTOOLS_DIR)/files/demo_brk/LEDWebDemo/ $(ROOTFS_DIR)/usr/local/demo/;
endif

# Install M4 demo firmware
cp -R $(M4PROJECTS_DIR)/deploy/STM32MP157C-DK2 $(ROOTFS_DIR)/usr/local/bin/

# Install fstab for emmc
cp $(BUILDTOOLS_DIR)/files/rootfs/fstab_emmc $(ROOTFS_DIR)/etc/fstab
if [ $(BOOT_EMMC) -eq 1 ]; then \
cp $(BUILDTOOLS_DIR)/files/rootfs/fstab_emmc_$(BOARD_NAME) $(ROOTFS_DIR)/etc/fstab; \
tar -cf $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-emmc-$(BOARD_NAME).tar -C $(ROOTFS_DIR) .; \
virt-make-fs --type=ext4 --size=+$(ROOTFS_EXTRA_SPACE)M $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-emmc-$(BOARD_NAME).tar $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-emmc-$(BOARD_NAME).ext4; \
fi

if [ $(BOOT_SD) -eq 1 ]; then \
cp $(BUILDTOOLS_DIR)/files/rootfs/fstab_sdcard_$(BOARD_NAME) $(ROOTFS_DIR)/etc/fstab; \
tar -cf $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-sdcard-$(BOARD_NAME).tar -C $(ROOTFS_DIR) .; \
virt-make-fs --type=ext4 --size=+$(ROOTFS_EXTRA_SPACE)M $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-sdcard-$(BOARD_NAME).tar $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-sdcard-$(BOARD_NAME).ext4; \
fi

# Create eMMC image
tar -cf $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-emmc-$(BOARD_NAME).tar -C $(ROOTFS_DIR) .
virt-make-fs --type=ext4 --size=+$(ROOTFS_EXTRA_SPACE)M $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-emmc-$(BOARD_NAME).tar $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-emmc-$(BOARD_NAME).ext4

# Install fstab for sd card
cp $(BUILDTOOLS_DIR)/files/rootfs/fstab_sdcard $(ROOTFS_DIR)/etc/fstab

# Create SD card image
tar -cf $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-sdcard-$(BOARD_NAME).tar -C $(ROOTFS_DIR) .
virt-make-fs --type=ext4 --size=+$(ROOTFS_EXTRA_SPACE)M $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-sdcard-$(BOARD_NAME).tar $(DEPLOY_DIR)/octavo-rootfs-debian-lxqt-sdcard-$(BOARD_NAME).ext4


vendorfs: setup gcnano
Expand All @@ -195,11 +216,14 @@ m4_demo: setup
cd $(M4PROJECTS_DIR) ; ./build_m4projects.sh; \
fi

image:
rm -rf $(DEPLOY_DIR)/FlashLayout_sdcard_$(BOARD_NAME)-$(MODE).raw
$(DEPLOY_DIR)/generate_tsv.sh -b $(BOARD_NAME) -m $(MODE) -d 0
$(DEPLOY_DIR)/generate_tsv.sh -b $(BOARD_NAME) -m $(MODE) -d 1
$(DEPLOY_DIR)/create_sdcard_from_flashlayout.sh $(DEPLOY_DIR)/FlashLayout_sdcard_$(BOARD_NAME)-$(MODE).tsv $(SDCARD_SIZE_GB)
image: fsbl ssbl bootfs rootfs vendorfs
if [ $(BOOT_SD) -eq 1 ]; then \
$(DEPLOY_DIR)/generate_tsv.sh -b $(BOARD_NAME) -m $(MODE) -d 0; \
$(DEPLOY_DIR)/create_sdcard_from_flashlayout.sh $(DEPLOY_DIR)/FlashLayout_sdcard_$(BOARD_NAME)-$(MODE).tsv $(SDCARD_SIZE_GB); \
fi
if [ $(BOOT_EMMC) -eq 1 ]; then \
$(DEPLOY_DIR)/generate_tsv.sh -b $(BOARD_NAME) -m $(MODE) -d 1; \
fi

all: ssbl fsbl bootfs rootfs vendorfs image

Expand All @@ -224,8 +248,8 @@ kernel_clean:
clean: ssbl_clean fsbl_clean kernel_clean
$(MAKE) $(FLAGS) -C $(MULTISTRAP_DIR) clean
@rm -rf $(GCNANO_DRV_DIR)
@rm -rf $(GCNANO_USR_DIR)
@rm -rf $(GCNANO_DRV_DIR)/galcore.ko
@rm -rf $(DEPLOY_DIR)
@rm -rf $(ROOTFS_DIR)
@rm -rf $(GCNANO_USR_DIR)

54 changes: 28 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# OSD32MP1 Debian SDK: OSD32MP1-build-tools
This repository contains the build tools used for OSD32MP1 Debian SDK
# OSD32MP1 Debian SDK v3.0
This repository contains the list of repositories used for OSD32MP1 Debian SDK v3.0

## Introduction
OSD32MP1 Debian SDK can be used to develop Debian Linux images for OSD32MP1 based platforms. The SDK runs on host desktop preferably runnning Ubuntu. Docker is used to containerize the build environment. Souce code from ST (OpenSTLinux) is used, for TF-A, U-Boot, Linux kernel, GCNano and STM32CubeMP1. So, the SDK is compatible with software from ST. Binary images for both SD card or eMMC can be generated. Cube Programmer can be used to flash the eMMC via USB.
OSD32MP1 Debian SDK can be used to develop Debian Linux images for OSD32MP1 based platforms. The SDK runs on host desktop preferably runnning Ubuntu. Docker is used to containerize the build environment. Souce code from ST (OpenSTLinux) is used, for TF-A, U-Boot, Linux kernel, GCNano and STM32CubeMP1. So, the SDK is compatible with software from ST. Binary images for both SD card and eMMC can be generated. Cube Programmer can be used to flash the eMMC via USB.

The following repositories make up OSD32MP1 Debian SDK::

Expand All @@ -13,7 +13,7 @@ The following repositories make up OSD32MP1 Debian SDK::
| Linux kernel Source code | https://github.com/STMicroelectronics/linux.git |
| GCNano Binaries | https://github.com/STMicroelectronics/gcnano-binaries.git |
| STM32Cube MP1 Package | https://github.com/STMicroelectronics/STM32CubeMP1.git |
| Debian multistrap Source code | https://github.com/octavosystems/osd32mp1-multistrap-buster.git |
| Debian multistrap Source code | https://github.com/octavosystems/osd32mp1-multistrap.git |
| Docker image Source code | https://github.com/octavosystems/osd32mp1-debian-docker.git |
| Build tools source code | https://github.com/octavosystems/osd32mp1-build-tools.git |

Expand All @@ -23,7 +23,7 @@ The following repositories make up OSD32MP1 Debian SDK::
| OSD32MP1-RED | https://octavosystems.com/octavo_products/osd32mp1-red/ |

## Requirements
Tested on Ubuntu 18.04 LTS
Tested on Ubuntu 20.04 LTS

The following packges are recommended:

Expand All @@ -33,8 +33,8 @@ The following packges are recommended:
| git | 2.17 or higher|
| Python | 3.x |
| Docker | 19.x |
| qemu-user-static | v5.4-stm32mp |
| STM32MP1 Cube Programmer | 2.5 or higher|
| qemu-user-static | 1:4.2-3ubuntu6.19 |
| STM32MP1 Cube Programmer | 2.9 or higher|


## OSD32MP1 Target binary versions:
Expand All @@ -43,19 +43,20 @@ The following version of the image are supported in release:

| Package | Version | Source URL |
| ------- | ------- | ---------- |
| TF-A | v2.0-stm32mp-r1.5 | https://github.com/STMicroelectronics/arm-trusted-firmware.git |
| U-Boot | v2018.11-stm32mp-r3 | https://github.com/STMicroelectronics/u-boot.git |
| Linux Kernel | v4.19-stm32mp-r3 | https://github.com/STMicroelectronics/linux.git |
| GCNano(binaries) | gcnano-6.2.4_p4-binaries | https://github.com/STMicroelectronics/gcnano-binaries.git |
| STM32CubeMP1 | 1.2 | https://github.com/STMicroelectronics/STM32CubeMP1.git |
| TF-A | v2.4-stm32mp-r1 | https://github.com/STMicroelectronics/arm-trusted-firmware.git |
| U-Boot | 2020.10-stm32mp-r1 | https://github.com/STMicroelectronics/u-boot.git |
| Linux Kernel | v5.10-stm32mp-r1 | https://github.com/STMicroelectronics/linux.git |
| GCNano(binaries) | gcnano-6.4.3-binaries | https://github.com/STMicroelectronics/gcnano-binaries.git |
| STM32CubeMP1 | 1.4 | https://github.com/STMicroelectronics/STM32CubeMP1.git |

## How to use the SDK
### Setup Host computer
1. ```sudo apt-get update```
2. ```sudo apt-get upgrade```
3. ```sudo apt-get install git docker.io repo qemu-user-static```
3. ```sudo apt-get install git docker.io qemu-user-static```
4. ```sudo systemctl enable docker```
5. ```sudo systemctl start docker```
6. Install repo: https://stackoverflow.com/questions/4350344/how-to-install-androids-repo-on-my-ubuntu-system

Install Cube Programmer from here: https://www.st.com/en/development-tools/stm32cubeprog.html
Please see https://wiki.st.com/stm32mpu/wiki/STM32CubeProgrammer for Cube Programmer installation instructions and setup.
Expand All @@ -80,20 +81,21 @@ The following outputs are generated in ~/osd32mp1-workspace/deploy :

| Output | Filename | Comment |
| ------ | -------- | ------- |
| 1 | tf-a-osd32mp1-red.stm32 | Binary for OSD32M1 arm-trusted-firmware |
| 2 | tf-a-osd32mp1-red-trusted.stm32 | Binary for OSD32MP1 arm-trsuted-firmware |
| 3 | u-boot-osd32mp1-red-trusted.stm32 | Binary for OSD32MP1 U-Boot |
| 4 | FlashLayout_sdcard_osd32mp1-red-trusted.tsv | Flash layout file for OSD32MP1-RED trusted - SD card |
| 5 | FlashLayout_sdcard_osd32mp1-red-trusted.raw | Binary image for OSD32MP1-RED trusted - SD card |
| 6 | FlashLayout_emmc_osd32mp1-red-trusted.tsv | Flash layout file for OSD32MP1-RED trsudted - eMMC |
| 7 | octavo-bootfs-debian-lxqt-osd32mp1-red.ext4 | BOOTFS binary for OSD32MP1-RED |
| 8 | octavo-rootfs-debian-lxqt-emmc-osd32mp1-red.ext4 | ROOTFS binary for OSD32MP1-RED - eMMC |
| 9 | octavo-rootfs-debian-lxqt-sdcard-osd32mp1-red.ext4 | ROOTFS binary for OSD32MP1-RED - SD card |
| 10 | octavo-vendorfs-debian-lxqt-osd32mp1-red.ext4 | VENDORFS binary for OSD32MP1-RED |
| 1 | tf-a-stm32mp157c-osd32mp1-red-emmc.stm32 | Binary for OSD32M1 arm-trusted-firmware eMMC |
| 2 | tf-a-stm32mp157c-osd32mp1-red-sdcard.stm32 | Binary for OSD32MP1 arm-trsuted-firmware SD card |
| 3 | tf-a-stm32mp157c-osd32mp1-red-usb.stm32 | Binary for OSD32MP1 arm-trsuted-firmware SD card USB boot |
| 4 | fip-stm32mp157c-osd32mp1-red-trusted.bin | FiP Binary for OSD32MP1 U-Boot |
| 4 | FlashLayout_sdcard_stm32mp157c-osd32mp1-red-trusted.tsv | Flash layout file for OSD32MP1-RED trusted - SD card |
| 5 | FlashLayout_sdcard_stm32mp157c-osd32mp1-red-trusted.raw | Binary image for OSD32MP1-RED trusted - SD card |
| 6 | FlashLayout_emmc_stm32mp157c-osd32mp1-red-trusted.tsv | Flash layout file for OSD32MP1-RED trsudted - eMMC |
| 7 | octavo-bootfs-debian-lxqt-stm32mp157c-osd32mp1-red.ext4 | BOOTFS binary for OSD32MP1-RED |
| 8 | octavo-rootfs-debian-lxqt-emmc-stm32mp157c-osd32mp1-red.ext4 | ROOTFS binary for OSD32MP1-RED - eMMC |
| 9 | octavo-rootfs-debian-lxqt-sdcard-stm32mp157c-osd32mp1-red.ext4 | ROOTFS binary for OSD32MP1-RED - SD card |
| 10 | octavo-vendorfs-debian-lxqt-stm32mp157c-osd32mp1-red.ext4 | VENDORFS binary for OSD32MP1-RED |

### Deploy on SD card (where sdX is the device assignment for SD card)
1. ```cd ~/osd32mp1-workspace/deploy/```
2. ```sudo dd if=FlashLayout_sdcard_osd32mp1-red-trusted.raw of=/dev/sdX bs=1M conv=fdatasync status=progress```
2. ```sudo dd if=FlashLayout_sdcard_stm32mp157c-osd32mp1-red-trusted.raw of=/dev/sdX bs=1M conv=fdatasync status=progress```

### Flash eMMC
STM32MP1 Cube Programmer is required for this procedure
Expand All @@ -105,7 +107,7 @@ To determine device numnber for the board connected:

3. ```STM32_Programmer_CLI -l USB```
<pre><font color="#34E2E2"><b> -------------------------------------------------------------------</b></font>
<font color="#34E2E2"><b> STM32CubeProgrammer v2.5.0 </b></font>
<font color="#34E2E2"><b> STM32CubeProgrammer v2.9.0 </b></font>
<font color="#34E2E2"><b> -------------------------------------------------------------------</b></font>

<font color="#4E9A06">===== DFU Interface =====</font>
Expand All @@ -125,7 +127,7 @@ The above device indicates the board is connected as USB1.

Flash the eMMC

4. ```STM32_Programmer_CLI -c port=USB1 -w FlashLayout_emmc_osd32mp1-red-trusted.tsv```
4. ```STM32_Programmer_CLI -c port=USB1 -w FlashLayout_emmc_stm32mp157c-osd32mp1-red-trusted.tsv```


## How to contribute
Expand Down
136 changes: 136 additions & 0 deletions files/demo_brk/LEDWebDemo/LEDWebServer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
"""
--------------------------------------------------------------------------
Octavo Systems - OSD33MP157c-BRK Demo
--------------------------------------------------------------------------
License:
Copyright 2020 - Octavo Systems LLC
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------
This file was modifed from the tutorial found here:
https://www.e-tinkers.com/2018/04/how-to-control-raspberry-pi-gpio-via-http-web-server/
It is a simple webserver used to display a single page and interact with the I/O
--------------------------------------------------------------------------
"""
import os
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse, parse_qs

#the actual hardware interface
import brkLed

host_name = '' # bind to all interfaces
host_port = 8080


class MyServer(BaseHTTPRequestHandler):
""" A special implementation of BaseHTTPRequestHander for reading data from
and control GPIO of the OSD32MP1-BRK
"""

def do_HEAD(self):
""" do_HEAD() can be tested use curl command
'curl -I http://server-ip-address:port'
"""
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()

def _redirect(self, path):
self.send_response(303)
self.send_header('Content-type', 'text/html')
self.send_header('Location', path)
self.end_headers()

def do_GET(self):
""" do_GET() can be tested using curl command
'curl http://server-ip-address:port'
"""
# load the HTML template
html = self.fileToStr('ledTemplate.html')
# get the status of the D1 Green LED
d1g_status = brkLed.ledStatus("d1g")
d1g_disabled = self.setDisabled(d1g_status)

# get the status of the D1 RED LED
d1r_status = brkLed.ledStatus("d1r")
d1r_disabled = self.setDisabled(d1r_status)

# get the status of the D2 Green LED
d2g_status = brkLed.ledStatus("d2g")
d2g_disabled = self.setDisabled(d2g_status)

self.do_HEAD()
#return the completed template
self.wfile.write(html.format(**locals()).encode("utf-8"))

def fileToStr(self, fileName):
"""Return a string containing the contents of the named file."""
fin = open(fileName);
contents = fin.read();
fin.close()
return contents

def setDisabled(self, status):
"""
returns a list to diable the appropriate button based on the status
:param status: that current status
:return: a list with the appropraite strings to disable the correct button given the status
"""
if status =="OFF":
return ["disabled", "", ""]
if status == "ON":
return ["", "disabled", ""]
if status =="FLASHING":
return ["", "", "disabled"]

def do_POST(self):
""" do_POST() can be tested using curl command
'curl -d "submit=On" http://server-ip-address:port'
"""
#get the POST agruments and parse them
content_length = int(self.headers['Content-Length']) # Get the size of data
post_data = self.rfile.read(content_length).decode("utf-8") # Get the data
post_data = parse_qs(post_data)

#pass the appropriate parameters based on which button was pressed
if "d1g" in post_data:
brkLed.ledSET("d1g", post_data["d1g"][0].lower())
elif "d1r" in post_data:
brkLed.ledSET("d1r", post_data["d1r"][0].lower())
elif "d2g" in post_data:
brkLed.ledSET("d2g", post_data["d2g"][0].lower())

self._redirect('/') # Redirect back to the root url'''

if __name__ == '__main__':
#Reset all of the LEDs
brkLed.ledRest()

http_server = HTTPServer((host_name, host_port), MyServer)
print("Server Starts - %s:%s" % (host_name, host_port))

try:
http_server.serve_forever()
except KeyboardInterrupt:
http_server.server_close()

Loading

0 comments on commit 3bea536

Please sign in to comment.