421 lines
13 KiB
Bash
Executable File
421 lines
13 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
DIALOG_CANCEL=1
|
|
DIALOG_ESC=255
|
|
HEIGHT=-1
|
|
WIDTH=-1
|
|
|
|
# Choices
|
|
PLATTFORM=esp32_devkitc_wroom
|
|
CONNECTIVITY=
|
|
INTERFACES=
|
|
PROTOCOLS=
|
|
SENSORS=
|
|
ACTUATORS=
|
|
|
|
display_result() {
|
|
dialog --title "$1" \
|
|
--backtitle "Configure Zephyr RTOS" \
|
|
--no-collapse \
|
|
--msgbox "$2" -1 -1
|
|
}
|
|
|
|
main_dialog() {
|
|
selection=$(dialog --stdout \
|
|
--backtitle "Configure Zephyr RTOS" \
|
|
--title "Menu" \
|
|
--no-cancel \
|
|
--menu "Please select:" $HEIGHT $WIDTH 4 \
|
|
"1" "Init Zephyr workspace" \
|
|
"2" "Create empty project" \
|
|
"3" "Add additional functionalities" \
|
|
"4" "Build project" \
|
|
"5" "Flash project" \
|
|
"6" "Clean build directory" \
|
|
"7" "Get Shell" \
|
|
"8" "Exit")
|
|
|
|
case $selection in
|
|
1 )
|
|
init_workspace
|
|
;;
|
|
2 )
|
|
init_project
|
|
;;
|
|
3 )
|
|
settings_dialog
|
|
;;
|
|
4 )
|
|
build_project
|
|
;;
|
|
5 )
|
|
flash_project
|
|
;;
|
|
6 )
|
|
clean_build_dir
|
|
;;
|
|
7 )
|
|
clear
|
|
/bin/bash
|
|
;;
|
|
8 )
|
|
clear
|
|
exit
|
|
;;
|
|
esac
|
|
}
|
|
|
|
settings_dialog() {
|
|
selection=$(dialog --stdout \
|
|
--backtitle "Configure Zephyr RTOS" \
|
|
--title "Menu" \
|
|
--cancel-label "Exit" \
|
|
--menu "Please select:" $HEIGHT $WIDTH 4 \
|
|
"1" "Connectivity" \
|
|
"2" "Protocols" \
|
|
"3" "Interfaces" \
|
|
"4" "Sensors" \
|
|
"5" "Actuators" )
|
|
|
|
case $selection in
|
|
1 )
|
|
connectivity_dialog
|
|
;;
|
|
2 )
|
|
protocols_dialog
|
|
;;
|
|
3 )
|
|
interfaces_dialog
|
|
;;
|
|
4 )
|
|
sensors_dialog
|
|
;;
|
|
5 )
|
|
actuators_dialog
|
|
;;
|
|
esac
|
|
}
|
|
|
|
plattform_dialog() {
|
|
plattform=$( dialog --stdout \
|
|
--backtitle "Plattform" \
|
|
--default-item "$PLATTFORM" \
|
|
--no-tags \
|
|
--no-cancel \
|
|
--radiolist "Select plattform:" $HEIGHT $WIDTH 4 \
|
|
esp32c3_devkitm "ESP32-C3" $(equals "$PLATTFORM" "esp32c3_devkitm") \
|
|
esp32_devkitc_wroom "ESP32" $(equals "$PLATTFORM" "esp32_devkitc_wroom") \
|
|
nrf5340dk_nrf5340_cpuapp "nRF5340 DK" $(equals "$PLATTFORM" "nrf5340dk_nrf5340_cpuapp") \
|
|
nrf52840dongle_nrf52840 "nRF52840 Dongle" $(equals "$PLATTFORM" "nrf52840dongle_nrf52840") \
|
|
thingy91_nrf9160_ns "Thingy:91 (nRF9160)" $(equals "$PLATTFORM" "thingy91_nrf9160_ns") \
|
|
thingy91_nrf52840 "Thingy:91 (nRF52840)" $(equals "$PLATTFORM" "thingy91_nrf52840") )
|
|
|
|
if [ ! -z "$plattform" ]; then
|
|
PLATTFORM=$plattform
|
|
fi
|
|
}
|
|
|
|
ble_dialog() {
|
|
# TODO
|
|
ble=$( dialog --stdout \
|
|
--backtitle "Connectivity" \
|
|
--menu "Please select:" $HEIGHT $WIDTH 4 \
|
|
1 "WiFi" \
|
|
2 "Bluetooth" \
|
|
3 "BLE" \
|
|
4 "LoRaWAN" \
|
|
5 "NB-IoT")
|
|
|
|
case $connectivity in
|
|
1 ) # WiFi
|
|
# TODO
|
|
;;
|
|
2 ) # Bluetooth
|
|
sed -i '/int main(void)/e cat /opt/snippets/ble_gatt/code1.txt' /workdir/app/src/main.c
|
|
|
|
code2=$(cat /opt/snippets/ble_gatt/code2.txt)
|
|
echo "$code2" >> /workdir/app/src/peripheral_gatt_write.c
|
|
|
|
code3=$(cat /opt/snippets/ble_gatt/code3.txt)
|
|
echo "$code3" >> /workdir/app/src/gatt_write_common.c
|
|
|
|
config=$(cat /opt/snippets/ble_gatt/config.txt)
|
|
echo "$config" >> /workdir/app/prj.conf
|
|
|
|
display_result 'Added functionality' "Added functionality successfully at the end of main.c.\nYou have to call the function like in the example manually."
|
|
;;
|
|
3 ) # BLE
|
|
;;
|
|
4 ) # LoRaWAN
|
|
# TODO
|
|
;;
|
|
5 ) # NB-IoT
|
|
# TODO
|
|
;;
|
|
esac
|
|
}
|
|
|
|
connectivity_dialog() {
|
|
# TODO
|
|
connectivity=$( dialog --stdout \
|
|
--backtitle "Connectivity" \
|
|
--menu "Please select:" $HEIGHT $WIDTH 4 \
|
|
1 "WiFi" \
|
|
2 "Bluetooth" \
|
|
3 "BLE" \
|
|
4 "LoRaWAN" \
|
|
5 "NB-IoT")
|
|
|
|
case $connectivity in
|
|
1 ) # WiFi
|
|
# TODO
|
|
;;
|
|
2 ) # Bluetooth
|
|
sed -i '/int main(void)/e cat /opt/snippets/ble_gatt/code1.txt' /workdir/app/src/main.c
|
|
|
|
code2=$(cat /opt/snippets/ble_gatt/code2.txt)
|
|
echo "$code2" >> /workdir/app/src/peripheral_gatt_write.c
|
|
|
|
code3=$(cat /opt/snippets/ble_gatt/code3.txt)
|
|
echo "$code3" >> /workdir/app/src/gatt_write_common.c
|
|
|
|
config=$(cat /opt/snippets/ble_gatt/config.txt)
|
|
echo "$config" >> /workdir/app/prj.conf
|
|
|
|
display_result 'Added functionality' "Added functionality successfully at the end of main.c.\nYou have to call the function like in the example manually."
|
|
;;
|
|
3 ) # BLE
|
|
features=$(dialog --stdout \
|
|
--backtitle "BLE features" \
|
|
--checklist "Select BLE features:" $HEIGHT $WIDTH 4 \
|
|
2 "LED" ON \
|
|
3 "Button" ON )
|
|
|
|
# Base
|
|
sed -i '/int main(void)/e cat /opt/snippets/bluetooth/base/code1.txt' /workdir/app/src/main.c
|
|
|
|
config=$(cat /opt/snippets/bluetooth/base/config.txt)
|
|
echo "$config" >> /workdir/app/prj.conf
|
|
|
|
# Button
|
|
if [[ "$features" == *"3"* ]]; then
|
|
sed -i '/#include <zephyr\/bluetooth\/gatt.h>/a#include "button_svc.h"' /workdir/app/src/main.c
|
|
sed -i '/LOG_MODULE_REGISTER(main);/astatic uint16_t but_val;' /workdir/app/src/main.c
|
|
sed -i '/static struct bt_uuid_128 st_service_uuid = BT_UUID_INIT_128(BT_UUID_128_ENCODE(0x0000fe40, 0xcc7a, 0x482a, 0x984a, 0x7f2ed5b3e58f));/astatic struct bt_uuid_128 but_notif_uuid = BT_UUID_INIT_128(BT_UUID_128_ENCODE(0x0000fe42, 0x8e22, 0x4541, 0x9d4c, 0x21edae82ed19));' /workdir/app/src/main.c
|
|
sed -i '/BT_GATT_PRIMARY_SERVICE(&st_service_uuid),/aBT_GATT_CHARACTERISTIC(&but_notif_uuid.uuid, BT_GATT_CHRC_NOTIFY, BT_GATT_PERM_READ, NULL, NULL, &but_val),' /workdir/app/src/main.c
|
|
|
|
sed -i '/static void bt_ready(int err)/e cat /opt/snippets/bluetooth/button/code1.txt' /workdir/app/src/main.c
|
|
|
|
sed -i '/int main(void)/e cat /opt/snippets/bluetooth/button/code2.txt' /workdir/app/src/main.c
|
|
|
|
cp /opt/snippets/bluetooth/button/button_svc.h /workdir/app/src/
|
|
cp /opt/snippets/bluetooth/button/button_svc.c /workdir/app/src/
|
|
fi
|
|
|
|
# LED
|
|
if [[ "$features" == *"2"* ]]; then
|
|
sed -i '/#include <zephyr\/bluetooth\/gatt.h>/a#include "led_svc.h"' /workdir/app/src/main.c
|
|
sed -i '/static struct bt_uuid_128 st_service_uuid = BT_UUID_INIT_128(BT_UUID_128_ENCODE(0x0000fe40, 0xcc7a, 0x482a, 0x984a, 0x7f2ed5b3e58f));/astatic struct bt_uuid_128 led_char_uuid = BT_UUID_INIT_128(BT_UUID_128_ENCODE(0x0000fe41, 0x8e22, 0x4541, 0x9d4c, 0x21edae82ed19));' /workdir/app/src/main.c
|
|
sed -i '/BT_GATT_PRIMARY_SERVICE(&st_service_uuid),/aBT_GATT_CHARACTERISTIC(&led_char_uuid.uuid, BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE_WITHOUT_RESP, BT_GATT_PERM_WRITE, NULL, recv, (void *)1),' /workdir/app/src/main.c
|
|
|
|
sed -i '/static void bt_ready(int err)/e cat /opt/snippets/bluetooth/led/code1.txt' /workdir/app/src/main.c
|
|
|
|
sed -i '/int main(void)/e cat /opt/snippets/bluetooth/led/code2.txt' /workdir/app/src/main.c
|
|
|
|
cp /opt/snippets/bluetooth/led/led_svc.h /workdir/app/src/
|
|
cp /opt/snippets/bluetooth/led/led_svc.c /workdir/app/src/
|
|
fi
|
|
|
|
display_result 'Added functionality' "Added functionality successfully at the end of main.c.\nYou have to call the function like in the example manually."
|
|
;;
|
|
4 ) # LoRaWAN
|
|
# TODO
|
|
;;
|
|
5 ) # NB-IoT
|
|
# TODO
|
|
;;
|
|
esac
|
|
}
|
|
|
|
protocols_dialog() {
|
|
# TODO
|
|
protocols=$( dialog --stdout \
|
|
--backtitle "Protocols" \
|
|
--menu "Please select:" $HEIGHT $WIDTH 4 \
|
|
1 "MQTT" \
|
|
2 "REST" \
|
|
3 "CoAP")
|
|
|
|
case $protocols in
|
|
1 ) # MQTT
|
|
# TODO
|
|
;;
|
|
2 ) # REST
|
|
# TODO
|
|
;;
|
|
3 ) # CoAP
|
|
# TODO
|
|
;;
|
|
esac
|
|
}
|
|
|
|
interfaces_dialog() {
|
|
# TODO
|
|
interfaces=$( dialog --stdout \
|
|
--backtitle "Interfaces" \
|
|
--menu "Please select:" $HEIGHT $WIDTH 4 \
|
|
1 "I2C" \
|
|
2 "SPI" \
|
|
3 "UART")
|
|
|
|
case $interfaces in
|
|
1 ) # I2C
|
|
# TODO
|
|
;;
|
|
2 ) # SPI
|
|
# TODO
|
|
;;
|
|
esac
|
|
}
|
|
|
|
sensors_dialog() {
|
|
# TODO
|
|
sensors=$( dialog --stdout \
|
|
--backtitle "Sensors" \
|
|
--menu "Please select:" $HEIGHT $WIDTH 4 \
|
|
1 "Button" \
|
|
2 "Sensor 2" \
|
|
3 "Sensor 3" \
|
|
4 "Sensor 4" )
|
|
|
|
case $sensors in
|
|
1 ) # Button
|
|
sed -i '/int main(void)/e cat /opt/snippets/button/code.txt' /workdir/app/src/main.c
|
|
|
|
config=$(cat /opt/snippets/button/config.txt)
|
|
echo "$config" >> /workdir/app/prj.conf
|
|
|
|
display_result 'Added functionality' "Added functionality successfully at the end of main.c.\nYou have to call the function like in the example manually."
|
|
;;
|
|
2 )
|
|
# TODO
|
|
;;
|
|
3 )
|
|
# TODO
|
|
;;
|
|
esac
|
|
}
|
|
|
|
actuators_dialog() {
|
|
# TODO
|
|
actuators=$( dialog --stdout \
|
|
--backtitle "Actuators" \
|
|
--menu "Please select:" $HEIGHT $WIDTH 4 \
|
|
1 "LED" \
|
|
2 "Actuators 2" \
|
|
3 "Actuators 3" \
|
|
4 "Actuators 4" )
|
|
|
|
case $actuators in
|
|
1 ) # LED
|
|
sed -i '/int main(void)/e cat /opt/snippets/led/code.txt' /workdir/app/src/main.c
|
|
|
|
config=$(cat /opt/snippets/led/config.txt)
|
|
echo "$config" >> /workdir/app/prj.conf
|
|
|
|
display_result 'Added functionality' "Added functionality successfully at the end of main.c.\nYou have to call the function like in the example manually."
|
|
;;
|
|
2 )
|
|
# TODO
|
|
;;
|
|
3 )
|
|
# TODO
|
|
;;
|
|
4 )
|
|
# TODO
|
|
;;
|
|
esac
|
|
}
|
|
|
|
init_workspace() {
|
|
cd /workdir
|
|
{ west init; west update; west zephyr-export; echo "Created workspace successfully"; } 2>&1 | dialog --programbox -1 -1
|
|
}
|
|
|
|
init_project() {
|
|
mkdir /workdir/app
|
|
mkdir /workdir/app/src
|
|
|
|
cp /opt/data/main.c /workdir/app/src/main.c
|
|
cp /opt/data/app.overlay /workdir/app/app.overlay
|
|
cp /opt/data/CMakeLists.txt /workdir/app/CMakeLists.txt
|
|
cp /opt/data/prj.conf /workdir/app/prj.conf
|
|
cp /opt/data/VERSION /workdir/app/VERSION
|
|
|
|
display_result 'Created project' "Project created successfully.\nThe project is located in /workdir.\nYou can edit it by using your favorite IDE."
|
|
}
|
|
|
|
build_project() {
|
|
plattform_dialog
|
|
|
|
clear
|
|
|
|
cd /workdir/app/
|
|
west build -b $PLATTFORM
|
|
|
|
read -p "Press any key to continue... " -n1 -s
|
|
}
|
|
|
|
flash_project() {
|
|
plattform_dialog
|
|
|
|
case "$PLATTFORM" in
|
|
"nrf52840dongle_nrf52840")
|
|
display_result 'Flash project' \
|
|
"Please run those commands in an environment where nrfutil and the compiled hex files are available: \
|
|
\\n\\n\\nnrfutil pkg generate --hw-version 52 --sd-req=0x00 --application build/zephyr/zephyr.hex --application-version 1 mcuboot.zip \
|
|
\\n\\nnrfutil dfu usb-serial -pkg mcuboot.zip -p /dev/ttyACM0" ;;
|
|
"esp32_devkitc_wroom")
|
|
display_result 'Flash project' \
|
|
"Please run those commands in an environment where esptool.py and the compiled bin files are available: \
|
|
\\n\\n\\nesptool.py --chip auto --baud 921600 --before default_reset --after hard_reset write_flash -u --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 app/build/esp-idf/build/bootloader/bootloader.bin 0x8000 app/build/esp-idf/build/partitions_singleapp.bin 0x10000 app/build/zephyr/zephyr.bin"
|
|
|
|
;;
|
|
*)
|
|
display_result "Error" "Board not configured in this tool yet\nSee https://docs.zephyrproject.org/latest/boards/index.html#boards"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
clean_build_dir() {
|
|
rm -rf /workdir/app/build/*
|
|
|
|
display_result "Cleaned build" "Cleaned build directory successfully"
|
|
}
|
|
|
|
in_array() {
|
|
if [[ $1 =~ (^|[[:space:]])"$2"($|[[:space:]]) ]] ; then
|
|
echo on;
|
|
else
|
|
echo off;
|
|
fi
|
|
}
|
|
|
|
equals() {
|
|
if [[ $1 == "$2" ]] ; then
|
|
echo on;
|
|
else
|
|
echo off;
|
|
fi
|
|
}
|
|
|
|
if ! command -v dialog &> /dev/null
|
|
then
|
|
sudo apt update && sudo apt install dialog
|
|
fi
|
|
|
|
cd /workdir
|
|
|
|
while true; do
|
|
main_dialog
|
|
done |