Skip to content

Commit 3be31f2

Browse files
committed
feat: added testing scripts (wip)
1 parent c883c17 commit 3be31f2

18 files changed

Lines changed: 698 additions & 0 deletions

testing/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# TODO
2+
3+
Try the different testing scripts and integrate them into an end-to-end testing setup.

testing/bin/ads1015-setup.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
# vim: nowrap ts=4
3+
4+
# Sysfs setup for ADS1015 ADC
5+
6+
ADC_PATH=/sys/bus/i2c/devices/5-0049/iio:device1
7+
8+
function ads1015_init () {
9+
# Tell the kernel where our ADC is
10+
echo ads1015 0x49 | sudo tee /sys/bus/i2c/devices/i2c-5/new_device > /dev/null
11+
12+
# To remove the driver from the kernel, echo the address to delete_device
13+
# echo 0x49 | sudo tee /sys/bus/i2c/devices/i2c-5/delete_device > /dev/null
14+
15+
# The ADC can now be found under the Industrial I/O (iio) at the following path,
16+
# look there for all the options (sampling_frequency_available, scale_available, input configurations)
17+
# The lowest sample freq gives the best accuracy, but is slower. That doesn't matter here because we don't read continously.
18+
# scale_available: 0.125000000 0.250000000 0.500000000 1.000000000 2.000000000 3.000000000
19+
# sampling_frequency_available=128 250 490 920 1600 2400 3300 3300
20+
# ADC_PATH=/sys/bus/i2c/devices/5-0049/iio:device1
21+
22+
# Setup the ADC.
23+
# The internal reference voltage is 2.048V, and the resolution is 12-bit for differential inputs,
24+
# but we're using them in single-ended mode (one input is ground) so we'll get 11-bit resolution.
25+
# By selecting a scale of 2, the input range is 4.096V but the actual voltage may not exceed 3.3V, the ADC's supply voltage.
26+
#
27+
# CH0 is the potentiometer next to the telemetry module
28+
# CH0 range: 0 .. 3.3V
29+
# CH1 is the potentiometer next to the I2C connectors
30+
# CH2 is the battery voltage divided by 10
31+
# CH3 is the external voltage on the white connector between the potentiometers
32+
#
33+
# In the end, the raw ADC values are available in in_voltage{0.3}_raw. These have to be calculated to voltages, see below.
34+
35+
36+
# Set scale for potentiometers, CH0 and CH1
37+
echo 2 | sudo tee $ADC_PATH/in_voltage0_scale > /dev/null
38+
echo 2 | sudo tee $ADC_PATH/in_voltage1_scale > /dev/null
39+
40+
# Set scale for VBat/10 (2.048V range is ok here), CH2
41+
echo 1 | sudo tee $ADC_PATH/in_voltage2_scale > /dev/null
42+
43+
# Set scale for Vext, CH3 (set to scale 2 since we expect the input to be 0 .. 3.3V)
44+
echo 2 | sudo tee $ADC_PATH/in_voltage3_scale > /dev/null
45+
46+
# Optionally set the sample frequency
47+
echo 1600 | sudo tee $ADC_PATH/in_voltage0_sampling_frequency > /dev/null
48+
echo 1600 | sudo tee $ADC_PATH/in_voltage1_sampling_frequency > /dev/null
49+
echo 1600 | sudo tee $ADC_PATH/in_voltage2_sampling_frequency > /dev/null
50+
echo 1600 | sudo tee $ADC_PATH/in_voltage3_sampling_frequency > /dev/null
51+
52+
# Apparently the ADC or the kernel needs some time to set itself up.
53+
sleep 1
54+
}
55+
56+
function ads1015_delete () {
57+
echo 0x49 | sudo tee /sys/bus/i2c/devices/i2c-5/delete_device > /dev/null
58+
}
59+
60+
function ads1015_get_settings () {
61+
# Read back the settings for verification
62+
raw0=$(cat $ADC_PATH/in_voltage0_raw)
63+
raw1=$(cat $ADC_PATH/in_voltage1_raw)
64+
raw2=$(cat $ADC_PATH/in_voltage2_raw)
65+
raw3=$(cat $ADC_PATH/in_voltage3_raw)
66+
echo "CH0: scale=$(cat $ADC_PATH/in_voltage0_scale), sampling_frequency=$(cat $ADC_PATH/in_voltage0_sampling_frequency), raw=$raw0"
67+
echo "CH1: scale=$(cat $ADC_PATH/in_voltage1_scale), sampling_frequency=$(cat $ADC_PATH/in_voltage1_sampling_frequency), raw=$raw1"
68+
echo "CH2: scale=$(cat $ADC_PATH/in_voltage2_scale), sampling_frequency=$(cat $ADC_PATH/in_voltage2_sampling_frequency), raw=$raw2"
69+
echo "CH3: scale=$(cat $ADC_PATH/in_voltage3_scale), sampling_frequency=$(cat $ADC_PATH/in_voltage3_sampling_frequency), raw=$raw3"
70+
}
71+
72+
function ads1015_get_voltages () {
73+
# To calculate the voltages from the raw value, use the following formula:
74+
# Vchn = raw * Vref/2^(12-1) * scale
75+
76+
# In bash, using bc as our calculator this would look like this: (scale=3 is bc's precision and not our ADC scale).
77+
raw0=$(cat $ADC_PATH/in_voltage0_raw)
78+
raw1=$(cat $ADC_PATH/in_voltage1_raw)
79+
raw2=$(cat $ADC_PATH/in_voltage2_raw)
80+
raw3=$(cat $ADC_PATH/in_voltage3_raw)
81+
read volt0 <<< "$(bc <<< "scale=3; $raw0 * 2.048/(2^(12-1)) * 2")"
82+
read volt1 <<< "$(bc <<< "scale=3; $raw1 * 2.048/(2^(12-1)) * 2")"
83+
read volt2 <<< "$(bc <<< "scale=3; $raw2 * 2.048/(2^(12-1)) * 1 * 10")" # note ADC scale=1 and x10 for Vbat
84+
read volt3 <<< "$(bc <<< "scale=3; $raw3 * 2.048/(2^(12-1)) * 2")"
85+
read percent0 <<< "$(bc <<< "scale=1; 4096/3300 * $raw0 / 2048 * 100")"
86+
read percent1 <<< "$(bc <<< "scale=1; 4096/3300 * $raw1 / 2048 * 100")"
87+
88+
echo "CH0_volt="$(printf "%1.3f" $volt0)", CH0_percent=$percent0"
89+
echo "CH1_volt="$(printf "%1.3f" $volt1)", CH1_percent=$percent1"
90+
echo "CH2_volt=$volt2"
91+
echo "CH3_volt=$volt3"
92+
}
93+
94+
# MAIN
95+
if [ "$1" == "init" ]; then
96+
ads1015_init
97+
ads1015_get_settings
98+
exit 0
99+
elif [ "$1" == "delete" ]; then
100+
ads1015_delete
101+
exit 0
102+
elif [ "$1" == "getsettings" ]; then
103+
ads1015_get_settings
104+
exit 0
105+
elif [ "$1" == "getvoltages" ]; then
106+
ads1015_get_voltages
107+
exit 0
108+
else
109+
echo "Usage: $0 init|delete|getsettings|getvoltages"
110+
exit 1
111+
fi
112+

testing/bin/ase2024-bootlogo.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
PATH=/home/debix/bin:$PATH
4+
5+
oled-logo-set logo_clear
6+
sleep 1
7+
for i in logo_vukip logo_nxp logo_debix logo_duckcover logo_ase
8+
do
9+
oled-logo-set $i
10+
sleep 1
11+
done

testing/bin/ase_shutdown.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# This script runs right before the system shuts down (reboot, poweroff, halt, kexec) if it's put into /usr/lib/systemd/system-shutdown
4+
# It's called with one argument: "halt", "poweroff", "reboot" or "kexec"
5+
6+
PATH="/home/debix/bin:$PATH"
7+
8+
if [ "$1" == "halt" ]; then
9+
oled-logo-set logo_noise
10+
oled-logo-set logo_powered_off
11+
fi
12+
13+
if [ "$1" == "poweroff" ]; then
14+
oled-logo-set logo_noise
15+
oled-logo-set logo_powered_off
16+
fi
17+
18+
if [ "$1" == "reboot" ]; then
19+
oled-logo-set logo_noise
20+
oled-logo-set logo_reboot
21+
fi
22+
23+
if [ "$1" == "kexec" ]; then
24+
oled-logo-set logo_noise
25+
oled-logo-set logo_reboot
26+
fi
27+

testing/bin/ase_startup.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# vim: ts=4
3+
4+
PATH="/home/debix/bin:$PATH"
5+
6+
function gpioset () {
7+
n="$1"
8+
dir="$2"
9+
val="$3"
10+
echo $n | sudo tee /sys/class/gpio/export > /dev/null
11+
echo $dir | sudo tee /sys/class/gpio/gpio$n/direction > /dev/null
12+
if [ ! -z "$val" ]; then
13+
echo $val | sudo tee /sys/class/gpio/gpio$n/value > /dev/null
14+
fi
15+
}
16+
17+
18+
# Configure CAN1/CAN2 pins for GPIO
19+
n=86
20+
echo $n > /sys/class/gpio/export
21+
echo out > /sys/class/gpio/gpio$n/direction
22+
echo 0 > /sys/class/gpio/gpio$n/value
23+
24+
n=87
25+
echo $n > /sys/class/gpio/export
26+
echo out > /sys/class/gpio/gpio$n/direction
27+
echo 0 > /sys/class/gpio/gpio$n/value
28+
29+
n=88
30+
echo $n > /sys/class/gpio/export
31+
echo out > /sys/class/gpio/gpio$n/direction
32+
echo 0 > /sys/class/gpio/gpio$n/value
33+
34+
n=89
35+
echo $n > /sys/class/gpio/export
36+
echo out > /sys/class/gpio/gpio$n/direction
37+
echo 0 > /sys/class/gpio/gpio$n/value
38+
39+
# Configure HC12 SET pin
40+
#hc12-setup.sh
41+
n=85
42+
echo $n > /sys/class/gpio/export
43+
echo out > /sys/class/gpio/gpio$n/direction
44+
echo 1 > /sys/class/gpio/gpio$n/value
45+
stty -F /dev/ttymxc2 speed 9600 raw
46+
47+
# Switches and LEDs on GPIO
48+
n=3 # Blue LED
49+
echo $n > /sys/class/gpio/export
50+
echo out > /sys/class/gpio/gpio$n/direction
51+
echo 0 > /sys/class/gpio/gpio$n/value
52+
53+
n=4 # Yellow LED
54+
echo $n > /sys/class/gpio/export
55+
echo out > /sys/class/gpio/gpio$n/direction
56+
echo 0 > /sys/class/gpio/gpio$n/value
57+
58+
n=12 # Toggle switch
59+
echo $n > /sys/class/gpio/export
60+
echo in > /sys/class/gpio/gpio$n/direction
61+
62+
n=13 # Pushbutton
63+
echo $n > /sys/class/gpio/export
64+
echo in > /sys/class/gpio/gpio$n/direction
65+
####
66+
#### # Switches and LEDs on MCP23017
67+
#### echo mcp23017 0x21 | sudo tee /sys/bus/i2c/devices/i2c-5/new_device > /dev/null
68+
#### #### # No exports yet here, gpiod (gpioset / gpioget) work fine
69+
pca9555_init.sh
70+
i2cset -y 5 0x21 0x02 0x01; sleep 0.05; i2cset -y 5 0x21 0x02 0x00
71+
i2cset -y 5 0x21 0x03 0xf0; sleep 1; i2cset -y 5 0x21 0x03 0x00

testing/bin/gpio_test.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
while true; do
4+
# Toggle switch and LED blue
5+
GPIO12=$(cat /sys/class/gpio/gpio12/value)
6+
echo $GPIO12 > /sys/class/gpio/gpio3/value
7+
8+
# Pushbutton switch and LED yellow
9+
GPIO13=$(cat /sys/class/gpio/gpio13/value)
10+
echo $GPIO13 > /sys/class/gpio/gpio4/value
11+
echo
12+
13+
echo SW_Toggle=$GPIO12, SW_PUSH=$GPIO13
14+
sleep 0.25
15+
done

testing/bin/hc12-setup.sh

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
3+
# Serial port
4+
PORT=/dev/ttymxc2
5+
6+
# Channel number. 1..127 but >100 not recommended. Also see HC12 doc for channel spacing (5?)
7+
# So valid channels would be 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76, 81, 86, 91 and 96.
8+
CHANNEL=21
9+
10+
# Communication baudrate
11+
BAUD=115200
12+
13+
hc12_send () {
14+
echo "hc12_send(): $1"
15+
echo -n $1 > $PORT
16+
hc12_receive
17+
}
18+
19+
hc12_receive () {
20+
read -t2 RESP < $PORT
21+
echo -n "hc12_receive(): "
22+
if [ -z "$RESP" ]; then
23+
echo no response
24+
else
25+
echo "$RESP"
26+
fi
27+
}
28+
29+
# Setup GPIO pin for command mode (GPIO3_IO21 (85) according to debix-gpio but the schematic says GPIO1_IO21),
30+
# and enter HC12 command mode by setting the pin to 0
31+
hc12_set () {
32+
if [ ! -d /sys/class/gpio/gpio85 ]; then
33+
echo "hc12_set(): exporting pin 85"
34+
echo 85 > /sys/class/gpio/export
35+
else
36+
echo "hc12_set(): pin 85 already exported"
37+
fi
38+
39+
echo out > /sys/class/gpio/gpio85/direction
40+
echo 0 > /sys/class/gpio/gpio85/value
41+
}
42+
43+
hc12_unset () {
44+
echo 1 > /sys/class/gpio/gpio85/value
45+
echo 85 > /sys/class/gpio/unexport
46+
}
47+
48+
49+
# Enter HC12 command mode
50+
#debix-gpio GPIO3_IO21 out 0
51+
hc12_set
52+
53+
# Set baudrate to 9600 (command mode is always 9600)
54+
stty -F $PORT raw speed 9600 > /dev/null
55+
56+
# Show current settings
57+
hc12_send "AT+V" # Firmware version
58+
hc12_send "AT+RB" # Get baudrate
59+
hc12_send "AT+RC" # Get channel
60+
hc12_send "AT+RF" # Get transmission mode
61+
hc12_send "AT+RP" # Get transmission power level
62+
63+
# Reset to default settings
64+
hc12_send "AT+DEFAULT"
65+
66+
# Set baudrate
67+
hc12_send "AT+B$BAUD"
68+
69+
# Set channel
70+
HC12_CH=`printf "%03i" $CHANNEL` # Format channel number
71+
hc12_send "AT+C$HC12_CH"
72+
73+
# Set transmission mode
74+
hc12_send "AT+FU3"
75+
76+
# Set transmitting power level (8=max, 20dBm)
77+
hc12_send "AT+P8"
78+
79+
# Show new settings
80+
hc12_send "AT+RX"
81+
82+
# Exit HC12 command mode
83+
#debix-gpio GPIO3_IO21 out 1
84+
hc12_unset
85+
86+
# Set baudrate to specified communication speed
87+
stty -F $PORT raw speed $BAUD > /dev/null
88+

testing/bin/iio_event_monitor

74.4 KB
Binary file not shown.

testing/bin/iio_generic_buffer

93.4 KB
Binary file not shown.

testing/bin/lsiio

66.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)