summaryrefslogtreecommitdiff
path: root/prod-scripts/MTCDT-0.1/cdteep.sh
blob: c0e1e1412814c3ab4d142d0d25564edd7c71d7ba (plain)
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
#!/bin/sh
# This scripts follows old school option rules, and all
# options must come before parameters.  Four parameters
# are required.  Options requiring parameters must be
# followed by their parameter, with or without a space.
# Options not requiring parameters can be ganged, and may
# precede a single option requiring a parameter.
# 
MYNAME=cdteep.sh
out="/sys/bus/i2c/devices/0-0056/eeprom"
vendor_id="Multi-Tech Systems"
hw_version="MTCDT-0.1"


# Set the MTCDT EEPROM
function usage {
  echo "${MYNAME}"' -d -g -b "bt_mac_addr" -w "wifi_mac_addr" -i "imei number" -l "product-id" "device-id" "uuid" "eth_mac_addr"' >&2
  cat <<!EOF >&2
  assumptions:
    All options are optional and must come first.
    -b and -w require a following mac address
    -d displays the PROM, do not write.  Ignores other parameters.
    -g GPS capability.
    -l lora capability.
    -i requires a following imei number
    
    Example
    cdteep.sh -lb 01:12:AB:C3:23:FE MTCDT-210L 3489235379 125-6356-2283-9792 12:34:AB:CD:8F:34
    To add wifimac and remove lora:
    ${MYNAME} -b 01:12:AB:C3:23:FE -w 04:16:3C:C3:45:75 MTCDT-210L 3489235379 125-6356-2283-9792 12:34:AB:CD:8F:34
        
    product-id, device-id, uuid and eth_mac_addr are required.
    
    -d          display EEPROM
    -g          capa-GPS
    -l          capa-Lora
    The following fields are fixed:
    out-file    ${out}
    vendor-id   ${vendor_id}
    hw-version  ${hw_version}
!EOF
  exit 1
}

((display=0))

while getopts b:dgw:i:l opt ; do
echo looking at opt $opt
  case $opt in
  b)
    bt_mac_addr="$OPTARG"
    barg="--mac-bluetooth ${OPTARG} --capa-bluetooth"
    ;;
  w)
    wifi_mac_addr="$OPTARG"
    warg="--mac-wifi ${OPTARG} --capa-wifi"
    ;;
  i)
    imei="$OPTARG"
    if ((${#imei} == 0)) ; then
	echo "i option requires an imei number." >&2
	usage
    fi
    iarg="--imei ${OPTARG}"
    ;;
  l)
    larg="--capa-lora"
    ;;
  d)
    echo -e "\n\nEEPROM contents"
    echo    "-----------------"
    mts-id-eeprom --in-file $out
    exit
    ;;
  g)
    gps="--capa-gps"
    ;;
 \?)
    usage
    ;;
 :)
    echo "Option -$OPTARG requires an argument." >&2
    usage
    ;;
  esac
done


shift $((OPTIND-1))

if (($# != 4)) ; then
  echo Need 4 parameters beyond the options. >&2
  echo "You specified $#." >&2
  usage
  exit 1
fi
product_id=$1
device_id=$2
uuid=$3
mac=$4

mts-id-eeprom --out-file $out --out-format bin --vendor-id "$vendor_id" \
  --product-id "$product_id" --device-id "$device_id" \
  --hw-version "$hw_version" --mac-addr $mac \
  ${warg} ${barg} \
  ${iarg} ${larg} ${gps} --uuid "$uuid"

echo -e "\n\nNew contents"
echo    "-----------------"
mts-id-eeprom --in-file $out