-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck_scanner_resolution.sh
More file actions
132 lines (108 loc) · 3.53 KB
/
check_scanner_resolution.sh
File metadata and controls
132 lines (108 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
# shellcheck disable=SC1090
#
# Reads scanner resolutions from
# scanner/apparatus/cameras/resolution-x
# scanner/apparatus/cameras/resolution-y
#
# Reads all camnodes' resolutions from
# scanner/+/camera/resolution-x
# scanner/+/camera/resolution-y
#
# Compares
# each camnode's x value with scanner's x value
# each camnode's y value with scanner's y value
#
# Author: cdeck3r
#
# Params: None
# Exit codes
# 0: at the script's end
# 255: if BAIL_OUT
# this directory is the script directory
SCRIPT_DIR="$(
cd "$(dirname "$0")" || exit
pwd -P
)"
cd "$SCRIPT_DIR" || exit
# shellcheck disable=SC2034
SCRIPT_NAME=$0
# Vars
MQTT_BROKER="" # set empty
[ -f "${SCRIPT_DIR}/common_vars.conf" ] || {
echo "Could find required config file: common_vars.conf"
echo "Abort."
exit 1
}
[ -f "${SCRIPT_DIR}/tap-functions.sh" ] || {
echo "Could find required file: tap-functions.sh"
echo "Abort."
exit 1
}
source "${SCRIPT_DIR}/common_vars.conf"
source "${SCRIPT_DIR}/tap-functions.sh"
#####################################################
# Include Helper functions
#####################################################
[ -f "${SCRIPT_DIR}/funcs.sh" ] || {
echo "Could find required file: funcs.sh"
echo "Abort."
exit 1
}
source "${SCRIPT_DIR}/funcs.sh"
#####################################################
# Main program
#####################################################
# first things first
HR=$(hr) # horizontal line
plan_no_plan
SKIP_CHECK=$(
true
echo $?
)
precheck "${SKIP_CHECK}"
diag "${HR}"
diag "Check scanner resolution on all camnodes"
diag "${HR}"
# shellcheck disable=SC2016
TOPIC='scanner/apparatus/cameras/resolution-x'
RES_X="mosquitto_sub -v -h ${MQTT_BROKER} -t ${TOPIC} -W 2"
SCANNER_RES_X=$(${RES_X} | cut -d' ' -f2)
is $? 0 "Retrieve scanner's resolution width"
TOPIC='scanner/apparatus/cameras/resolution-y'
RES_Y="mosquitto_sub -v -h ${MQTT_BROKER} -t ${TOPIC} -W 2"
SCANNER_RES_Y=$(${RES_Y} | cut -d' ' -f2)
is $? 0 "Retrieve scanner's resolution height"
((SCANNER_RES_X > 0)) && ((SCANNER_RES_X <= 3280)); ok $? "Valid scanner resolution width: ${SCANNER_RES_X}"
((SCANNER_RES_Y > 0)) && ((SCANNER_RES_Y <= 2464)); ok $? "Valid scanner resolution height: ${SCANNER_RES_Y}"
diag "${HR}"
diag "Retrieve resolution of all camnodes"
diag "${HR}"
TOPIC='scanner/+/camera/resolution-x'
RES_X="mosquitto_sub -v -h ${MQTT_BROKER} -t ${TOPIC} -W 2"
CAMNODE_RES_X=$(${RES_X})
is $? 0 "Retrieve camnodes' resolution width"
TOPIC='scanner/+/camera/resolution-y'
RES_Y="mosquitto_sub -v -h ${MQTT_BROKER} -t ${TOPIC} -W 2"
CAMNODE_RES_Y=$(${RES_Y})
is $? 0 "Retrieve camnodes' resolution height"
mapfile -t CAMNODE_RES_X_ARRAY < <(echo "${CAMNODE_RES_X}" | tr " " "_")
mapfile -t CAMNODE_RES_Y_ARRAY < <(echo "${CAMNODE_RES_Y}" | tr " " "_")
res_error_cnt=0
for camnode_res in "${CAMNODE_RES_X_ARRAY[@]}"; do
is "$(echo "${camnode_res}" | cut -d_ -f2)" "${SCANNER_RES_X}" "$(echo "${camnode_res}" | tr '_' ' ')"
if [ $? -ne 0 ]; then
((res_error_cnt = res_error_cnt+1))
fi
done
for camnode_res in "${CAMNODE_RES_Y_ARRAY[@]}"; do
is "$(echo "${camnode_res}" | cut -d_ -f2)" "${SCANNER_RES_Y}" "$(echo "${camnode_res}" | tr '_' ' ')"
if [ $? -ne 0 ]; then
((res_error_cnt = res_error_cnt+1))
fi
done
# Summary
diag "${HR}"
((res_error_cnt > 0)) && { diag "${RED}[FAIL]${NC} - Resolution mismatch between scanner and camnode. Check previous output."; }
((res_error_cnt == 0)) && { diag "${GREEN}[SUCCESS]${NC} - Scanner resolution matches all camnodes."; }
diag "${HR}"