-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathbarcodeinterpret
executable file
·68 lines (59 loc) · 1.98 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", $0);}'
else
echo $val | awk '{printf("%c", $0);}'
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 -d ' ' -f 2)
if [[ $(echo "$materialid" | tail -c +9 | head -c 1) == "H" ]] ; then
materialid="${materialid}D"
fi
echo deviceid,$(echo $ids | cut -d ' ' -f 1),materialid,$materialid,som,`addcolons $(echo $barcode | cut -c 42-49)`,duration,`addcolons $(echo $barcode | cut -c 50-57)`
log -e