Index: scripts/globals.sh =================================================================== diff -u -r0f372ddc9cdcc26e136818f03e9249a8347a144e -rc8ccc2c34a91572cf00b6f79bb8af6f0d4bd56c6 --- scripts/globals.sh (.../globals.sh) (revision 0f372ddc9cdcc26e136818f03e9249a8347a144e) +++ scripts/globals.sh (.../globals.sh) (revision c8ccc2c34a91572cf00b6f79bb8af6f0d4bd56c6) @@ -59,6 +59,7 @@ SRC_PATH_SCRIPTS="scripts" SRC_PATH_CONFIG="settings" SRC_PATH_CLOUDSYNC="cloudsync" +SRC_PATH_DRYDEMO="dry-demo" SRC_PATH_FONTS="fonts" DST_IP="" @@ -67,6 +68,7 @@ DST_PATH_HOME="/home/$DST_USER" DST_PATH_SCRIPTS="/home/$DST_USER/scripts" DST_PATH_CLOUDSYNC="/home/$DST_USER/cloudsync" +DST_PATH_DRYDEMO="/home/$DST_USER/dry-demo" DST_PATH_FONTS="/usr/share/fonts/truetype" POSTLOG=/tmp/post.log @@ -82,7 +84,6 @@ POSTMSG_BLUETOOTH="Bluetooth" POSTMSG_SHASUM="App shasum" POSTMSG_CLOUDSYNC="CloudSync" -POSTMSG_CLOUDSYNC_RUNNING="CloudSync app IS running" POSTMSG_SETTINGSCRC="SettingsCRC" TDCTL_NTP_USED=$FALSE @@ -107,27 +108,50 @@ SETUP_ENABLE_MANUFACTURING_MODE="ManufacturingMode" SETUP_ENABLE_UpdatingING_MODE="UpdatingMode" -APPLICATION_PARAMS="&" +APPLICATION_PARAMS="" +APPLICATION_PARAMS_DEFAULT="-xyz" # log x: long name, y: upload, z: compressed -CloudSync_DRT_SERVER_IP=172.31.99.117 +CloudSync_DRT_SERVER_IP="" CloudSync_DRT_SERVER_PORT=80 CLOUD_USER=cloud CLOUD_HOME=/home/$CLOUD_USER DENALI_USER=denali DENALI_HOME=/home/$DENALI_USER +DEMO_USER=root +DEMO_HOME=/home/$DEMO_USER -SETTING_CONF_FOLDER_PATH=/var/configurations +SETTING_CONF_FOLDER_PATH=/var/configurations SETTINGS_CRC_FILE_PATH=$DENALI_HOME/settings.crc +DEMO_MODE=0 +P_CANBUS=can0 +V_CANBUS=can1 +D_CANBUS=$P_CANBUS + +function checkDemoMode() { + if [ -d "$DEMO_HOME/$SRC_PATH_DRYDEMO" ]; then + DEMO_MODE=1 + fi +} + +# *** this function should be used without brackets in the if to be effective. +function isDemoMode() { + if [ $DEMO_MODE -eq 1 ]; then + echo $TRUE + else + echo $FALSE + fi +} + function user_input() { read -p "$1? $2" -n 1 -r if [ "$CONTINUE" == "y" ]; then echo "" return $TRUE else echo "" - return $FALSE + return $FALSE fi } @@ -245,7 +269,7 @@ function post_out () { echo "$1" >> $POSTOUT; } function post_out_dash () { echo "$COMMENT_DASH$1" >> $POSTOUT; } -function debug () { +function debug () { echo_dash_comment echo_dash_message "$1" echo_dash_comment @@ -278,35 +302,66 @@ killall $DENALI_BIN } +function queryOSVersion() { + #get the OS version ----------------------- OS Version + post_log_dash " OS Version " + post_log "$(cat /etc/os-release)" +} + function setupEthernet() { #setting up ethernet----------------------- Ethernet post_log_dash " Ethernet " ieth=eth0 udhcpc --timeout=5 --retries=2 -n -i $ieth - post_log "$(ip addr show $ieth)" # -details -statistics + post_log "$(ip addr show $ieth)" # -details -statistics } -function setupCANBus() { +function setupPCAN() { #setting up can interface ----------------- CANBus post_log_dash " 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 + #$ ip -details -statistics link show $P_CANBUS + ip link set $P_CANBUS up type can bitrate 250000 restart-ms 100 + ifconfig $P_CANBUS txqueuelen 4000 +} + +function setupVCAN() { + modprobe vcan + ip link add dev $V_CANBUS type vcan + ip link set $V_CANBUS up +} + +function checkCANBus() { + candump $D_CANBUS -T1 # check if candump can successfully use the port. will terminate in 1ms if [ $? -eq 0 ]; then post_log_pass "$POSTMSG_CANBUS$POSTMSG_POSTFIX_PASSED" - post_log "$(ip link show can0)" # -details -statistics + post_log "$(ip link show $D_CANBUS)" # -details -statistics else post_log_fail "$POSTMSG_CANBUS$POSTMSG_POSTFIX_FAILED" fi } +function setupCANBus() { + if [ "$1" == "setup" ];then + D_CANBUS=$P_CANBUS # it is the default but kept to be consistent. + setupPCAN + else + if [ $(isDemoMode) -eq $TRUE ]; then + D_CANBUS=$V_CANBUS + setupVCAN + else + D_CANBUS=$P_CANBUS # it is the default but kept to be consistent. + setupPCAN + fi + fi + checkCANBus +} + function setupSDCard() { #mounting sdcard -------------------------- SD-CARD post_log_dash " SD-CARD " mkdir -p $SDCARD_MNT - mount $SDCARD_PRT $SDCARD_MNT + mount -o noexec,nodev,nosuid $SDCARD_PRT $SDCARD_MNT SDCTEST="$(mount | grep "$SDCARD_PRT on $SDCARD_MNT type $SDCARD_TYP_NAME (rw,")" if ! [ -z "$SDCTEST" ]; then SDINFO="$(df -h | grep -i $SDCARD_MNT)" @@ -412,7 +467,6 @@ fi } - function testApplicationShasum_setup() { # ----------------------------------------- Sha256Sum post_log_dash " Sha256Sum " @@ -426,7 +480,6 @@ fi } - function testApplicationShasum_local() { # ----------------------------------------- Sha256Sum post_log_dash " Sha256Sum " @@ -440,15 +493,13 @@ fi } - function testCloudSystem() { # ----------------------------------------- CloudSystem post_log_dash " CloudSystem " post_log "$(ip addr show $iwlan)" # -details -statistics post_log "$(ping www.diality.staging.kebormed.com -I $iwlan -c 3 -4)" } - function startCloudSync_setup() { # ----------------------------------------- CloudSync post_log_dash " CloudSync " @@ -463,9 +514,8 @@ echo "Executing the CloudSync" cd $CLOUDSYNC_PATH ./cs.py start debug & - sleep 2 - CLOUDSYNC_STATUS="$(./cs.py status)" - if [ "$CLOUDSYNC_STATUS" == "$POSTMSG_CLOUDSYNC_RUNNING" ]; then + CLOUDSYNC_STATUS="$(ps ax | grep -e cs.py -e cloud_sync.py | grep -v grep)" + if [ -n "$CLOUDSYNC_STATUS" ]; then post_log_pass "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_PASSED" else post_log_fail "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED" @@ -502,7 +552,6 @@ echo "" } - function startCloudSync_local() { # ----------------------------------------- CloudSync post_log_dash " CloudSync " @@ -522,9 +571,8 @@ echo "Executing the CloudSync" cd $CLOUDSYNC_PATH sudo -u $CLOUD_USER ./cs.py start - sleep 2 - CLOUDSYNC_STATUS="$(sudo -u $CLOUD_USER ./cs.py status)" - if [ "$CLOUDSYNC_STATUS" == "$POSTMSG_CLOUDSYNC_RUNNING" ]; then + CLOUDSYNC_STATUS="$(ps ax | grep -e cs.py -e cloud_sync.py | grep -v grep)" + if [ -n "$CLOUDSYNC_STATUS" ]; then post_log_pass "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_PASSED" else post_log_fail "$POSTMSG_CLOUDSYNC$POSTMSG_POSTFIX_FAILED" @@ -536,25 +584,45 @@ fi } - function startApplication_local() { # ----------------------------------------- Denali post_log_dash " Denali " #launching denali application DENALI_VERSION="$($DENALI_HOME/$DENALI_BIN -v)" if [ -n "$DENALI_VERSION" ]; then post_log_pass "$DENALI_VERSION" # log UI Software version - sudo -u $DENALI_USER $DENALI_HOME/$DENALI_BIN $APPLICATION_PARAMS 1>> /tmp/denali.out 2>> /tmp/denali.out & + if [ $(isDemoMode) -eq $TRUE ]; then + APPLICATION_PARAMS="$APPLICATION_PARAMS"" -q -D -A $D_CANBUS" + fi + sudo -u $DENALI_USER $DENALI_HOME/$DENALI_BIN $APPLICATION_PARAMS_DEFAULT $APPLICATION_PARAMS 1>> /tmp/denali.out 2>> /tmp/denali.out & else post_log_fail "Unknown Applicaion Version for $DENALI_HOME/$DENALI_BIN" fi } +function startDemoMode_local() { + # *** eliminated brackets are intentional. *** + if [ $(isDemoMode) -eq $TRUE ]; then + # ----------------------------------------- Demo Mode + post_log_dash " Demo Mode " + local DRYDEMO_PATH=$DEMO_HOME/$SRC_PATH_DRYDEMO + cd $DRYDEMO_PATH + ./run.py > $DRYDEMO_PATH.log & # create the log file at same level and name of the folder. + post_log "Dry-Demo Started" + fi +} function timerStart() { time_start=$(date +%s) } + +#TODO later improvement +# function checkLogBackups() { +# find +# filename="$SDCARD_MNT/log/" && filename2="${filename%.*}"".u."${filename##*.} && mv "$filename" "$filename2" && gzip $filename2 && ls log +# } + function timerEndLog() { # ----------------------------------------- END # tag the end time in the POST log file @@ -567,8 +635,10 @@ function applicationPOST() { setupConsoleout disableRootSSH - cleanupPOSTLogs - setupCANBus + cleanupPOSTLogs + checkDemoMode + queryOSVersion + setupCANBus $1 setupResolved killApplication setupEthernet