#!/bin/sh ########################################################################### # # Copyright (c) 2019-2022 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # @file run.sh # # @author (last) Behrouz NematiPour # @date (last) 28-Sep-2022 # @author (original) Behrouz NematiPour # @date (original) 28-Oct-2019 # ############################################################################ function currDate() { echo $(date +"%d%m%Y%H%M%S") } #DO NOT MODIFY VARIABLES #unless the denali applicaiton is updated as well to match. HOME=/home/root SDCARD_DEV=/dev/mmcblk1p1 SDCARD_MNT=/media/sd-card SDCARD_TYP=ext4 USB_DEV=/dev/sda1 USB_MNT=/media/usb CLOUDSYNC_FOLDER=cloudsync # both for log and application POSTLOG=$HOME/post.log POSTERR=$HOME/post.err POSTOUT=$HOME/post.out POSTMSG_POSTFIX_PASSED=" passed" POSTMSG_POSTFIX_FAILED=" failed" POSTMSG_CANBUS="CANBus" POSTMSG_SDCARD="SD-CARD" POSTMSG_TOUCH="Touch" POSTMSG_RTC="RTC" POSTMSG_WIFI="WiFi" POSTMSG_BLUETOOTH="Bluetooth" POSTMSG_SHASUM="App shasum" POSTMSG_CLOUDSYNC="CloudSync" POSTMSG_CLOUDSYNC_RUNNING="CloudSync app IS running" # cleanup the POST log file echo "Start: $(currDate)" > $POSTLOG echo "" > $POSTERR echo "" > $POSTOUT #create folders for sd-card and usb if not exist mkdir -p $SDCARD_MNT mkdir -p $USB_MNT # ---------------------------------------- STOP denali in case running (sys not rebooted) killall denali # ---------------------------------------- UPDATE #mounting usb mount $USB_DEV $USB_MNT USBTEST="$(mount | grep "$USB_MNT")" if ! [ -z "$USBTEST" ]; then echo ":: USB drive found and mounted on $USB_MNT" #A simple none secure update if [ -e $USB_MNT/denali ]; then mv $HOME/denali $HOME/denali.$(currDate) cp $USB_MNT/denali $HOME/denali # check if update where successful if [ $? -eq 0 ]; then sync;sync;sync; echo ":: Denali application has been updated with the one on the USB drive" mv $USB_MNT/denali $USB_MNT/denali.updated sync;sync;sync; fi fi fi # ---------------------------------------- SETUP & POST #Here only passed is logged and if nothing added to the post.log means it failed. #setting up can interface ----------------- CANBus #current settings can be retrieved by the command below #$ ip -details -statistics link show can0 ip link set can0 up type can bitrate 250000 restart-ms 100 ifconfig can0 txqueuelen 4000 candump can0 -T1 # check if candump can successfully use the port. will terminate in 1ms if [ $? -eq 0 ]; then echo $POSTMSG_CANBUS$POSTMSG_POSTFIX_PASSED >> $POSTLOG else echo $POSTMSG_CANBUS$POSTMSG_POSTFIX_FAILED >> $POSTLOG fi #mounting sdcard -------------------------- SD-CARD mount $SDCARD_DEV $SDCARD_MNT SDCTEST="$(mount | grep "$SDCARD_DEV on $SDCARD_MNT type $SDCARD_TYP (rw,")" if ! [ -z "$SDCTEST" ]; then SDINFO="$(df -h | grep -i $SDCARD_MNT)" echo $POSTMSG_SDCARD$POSTMSG_POSTFIX_PASSED >> $POSTLOG echo $SDCTEST >> $POSTLOG echo $SDINFO >> $POSTLOG else echo $POSTMSG_SDCARD$POSTMSG_POSTFIX_FAILED >> $POSTLOG fi #test the touch screen -------------------- Touch #if loaded successful it has a long description with "Touch" keyword, 'T' capital. #if fails has a one line error with "touch" keyword, 't' non-capital. #if there is other issues can even be empty. TSTEST="$(dmesg | grep Touch)" if [ $? -eq 0 ]; then echo $POSTMSG_TOUCH$POSTMSG_POSTFIX_PASSED >> $POSTLOG else echo $POSTMSG_TOUCH$POSTMSG_POSTFIX_FAILED >> $POSTLOG fi #test the RTC ----------------------------- RTC #may not be an accurate test but sufficient for now #and could not find a way to get the rtc clock with the higher resolusion #it should not be confused with date command which is system date/time and not hwclock hwclock -r # if there is any issue with rtc hwclock will show errors if [ $? -eq 0 ]; then RTC1=$(cat /sys/class/rtc/rtc0/since_epoch) sleep 1 RTC2=$(cat /sys/class/rtc/rtc0/since_epoch) if [ $(($RTC2 - $RTC1)) -eq 1 ]; then echo $POSTMSG_RTC$POSTMSG_POSTFIX_PASSED >> $POSTLOG else echo $POSTMSG_RTC$POSTMSG_POSTFIX_FAILED >> $POSTLOG fi fi # ---------------------------------------- Connections # stop the connection manager daemon killall connmand # ---------------------------------------- Bluetooth /usr/share/silex-uart/silex-uart.sh start 1>> $POSTOUT 2>> $POSTERR sleep 5 hciconfig hci0 up if [ $? -eq 0 ]; then echo $POSTMSG_BLUETOOTH$POSTMSG_POSTFIX_PASSED >> $POSTLOG else echo $POSTMSG_BLUETOOTH$POSTMSG_POSTFIX_FAILED >> $POSTLOG fi # ---------------------------------------- WiFi killall wpa_supplicant 1>> $POSTOUT 2>> $POSTERR if [[ ! -z $(dmesg | grep "wlan: driver loaded") ]]; then echo $POSTMSG_WIFI$POSTMSG_POSTFIX_PASSED >> $POSTLOG else echo $POSTMSG_WIFI$POSTMSG_POSTFIX_FAILED >> $POSTLOG fi # ---------------------------------------- Sha256Sum #check the denali applicatoin checksum SHA_ACT=$(tail -c 83 $HOME/denali | cut -c19-82) SHA_EXP=$(head -c -83 $HOME/denali | sha256sum -b --tag | cut -c14-77) if [ "$SHA_ACT" == "$SHA_EXP" ]; then echo $POSTMSG_SHASUM$POSTMSG_POSTFIX_PASSED >> $POSTLOG else echo $POSTMSG_SHASUM$POSTMSG_POSTFIX_FAILED >> $POSTLOG fi # ---------------------------------------- CloudSync if [ -d $CLOUDSYNC_FOLDER ]; then # moving/ backing up the previous treatment logs so the new buff starts with fresh sequence echo "Backing up CloudSync I/O buff" CLOUDSYNC_PATH="$SDCARD_MNT"/"$CLOUDSYNC_FOLDER" CLOUDSYNC_BACKUP="$CLOUDSYNC_PATH"_backup/$(currDate)/ mkdir -p $CLOUDSYNC_BACKUP mv $CLOUDSYNC_PATH/* $CLOUDSYNC_BACKUP rm $HOME/$CLOUDSYNC_FOLDER/data/* echo "Starting CloudSync" >> $POSTLOG cd $HOME/$CLOUDSYNC_FOLDER/ python3 ./cs.py start & sleep 2 CLOUDSYNC_STATUS="$(python3 ./cs.py status)" if $CLOUDSYNC_STATUS == $POSTMSG_CLOUDSYNC_RUNNING; then echo $POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_PASSED >> $POSTLOG else echo $POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED >> $POSTLOG fi cd else echo $POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED >> $POSTLOG fi # ---------------------------------------- Denali #launching denali application $HOME/denali -u -C & # -C to disable cloudsync for now sync it blocks the system and no cloudsync has been installed. # ---------------------------------------- END # tag the end time in the POST log file echo "End: $(date +"%d%m%Y%H%M%S")" >> $POSTLOG # ---------------------------------------- Ethernet # setup ethernet # note: At this time the application is running and also the ehternet connection is not necessary # so the sleep here is not hurtung any part of the applicaion progress. sleep 10 udhcpc eth0 &