-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbarcodeinterpret
executable file
·68 lines (59 loc) · 2.15 KB
/
barcodeinterpret
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
#!/bin/bash
# interpret Interleaved 2/5 barcode 58 byte barcode values used by the ProBell tape management system
SCRIPTDIR=$(dirname "${0}")
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ;};
_cleanup(){
_log -a "Process aborted"
exit 1
}
trap _cleanup SIGHUP SIGINT SIGTERM
_log -b
if test "${#}" != 1 ; then
echo "You must supply one argument, a scanned interleaved 2/5 barcode value"; exit
fi
BARCODE="${1}"
translatebyte()
{
VAL=$(echo $1 | echo $(cut -c $2-$3) + 32 | bc)
if [ "${VAL}" = 131 ] ; then
echo 9 | awk '{printf "%c", $1}'
else
echo "${VAL}" | awk '{printf "%c", $1}'
fi
}
_addcolons()
{
echo $(echo "${1}" | cut -c 1-2):$(echo "${1}" | cut -c 3-4):$(echo "${1}" | cut -c 5-6):$(echo "${1}" | cut -c 7-8)
}
_get_ids()
{
BARCODE=$1
c00=$(translatebyte "${BARCODE}" 2 3)
c01=$(translatebyte "${BARCODE}" 4 5)
c02=$(translatebyte "${BARCODE}" 6 7)
c03=$(translatebyte "${BARCODE}" 8 9)
c04=$(translatebyte "${BARCODE}" 10 11)
c05=$(translatebyte "${BARCODE}" 12 13)
c06=$(translatebyte "${BARCODE}" 14 15)
c07=$(translatebyte "${BARCODE}" 16 17)
c08=$(translatebyte "${BARCODE}" 18 19)
c09=$(translatebyte "${BARCODE}" 20 21)
c10=$(translatebyte "${BARCODE}" 22 23)
c11=$(translatebyte "${BARCODE}" 24 25)
c12=$(translatebyte "${BARCODE}" 26 27)
c13=$(translatebyte "${BARCODE}" 28 29)
c14=$(translatebyte "${BARCODE}" 30 31)
c15=$(translatebyte "${BARCODE}" 32 33)
c16=$(translatebyte "${BARCODE}" 34 35)
c17=$(translatebyte "${BARCODE}" 36 37)
c18=$(translatebyte "${BARCODE}" 38 39)
c19=$(translatebyte "${BARCODE}" 40 41)
echo "$c00$c01$c02$c03$c04$c05$c06$c07$c08$c09$c10$c11$c12$c13$c14$c15$c16$c17$c18$c19"
}
IDS=$(_get_ids "${BARCODE}")
MATERIALID=$(echo "${IDS}" | cut -c 10- | sed 's/ //g')
if [[ $(echo "${MATERIALID}" | tail -c +9 | head -c 1) == "H" ]] ; then
MATERIALID="${MATERIALID}D"
fi
echo DEVICEID,$(echo "${IDS}" | cut -c 1-8),MATERIALID,${MATERIALID},SOM,$(_addcolons $(echo "${BARCODE}" | cut -c 42-49)),duration,$(_addcolons $(echo "${BARCODE}" | cut -c 50-57))
_log -e