[Hilo] How to decode PLMN in the result of KCELL?


#1

Answer: In the response of <AT+KCELL=0>, the PLMN format is the one defined in the 3GPP.
It is coded as following:
With 2 digits MNC: PLMN = MCC[2] MCC[1] F MCC[3] MNC[2] MNC[1]
With 3 digits MNC: PLMN = MCC[2] MCC[1] MNC[3] MCC[3] MNC[2] MNC[1]

For example PLMN = 0 2 F 8 0 2 , with MCC = 208 and MNC = 20, we have:
MNC[2] = 0 MNC[1] = 2
MCC[3] = 8 MCC[2] = 0 MCC[1] = 2

For example PLMN = 1 3 0 0 7 1, with MCC = 310 and MNC = 170, we have:
MNC[3] = 0 MNC[2] = 7 MNC[1] = 1
MCC[3] = 0 MCC[2] = 1 MCC[1] = 3


#2

Here is a bash script for decoding:

[code]KCELL="$(echo -e “AT+KCELL=0\r” | /bin/busybox microcom -t 2000 /dev/ttyACM5)"
echo “$KCELL”

MCC=“0”
MNC=“0”
LAC=“0”
CI=“0”
if [[ $KCELL =~ +KCELL:\ [0-9]+,(0,[0-9]+|2),[0-9]+,([0-9])([0-9])([0-9])([0-9])([0-9])([0-9]),([0-9a-f]+),([0-9a-f]+) ]]; then
echo “Match (MNC has 3 digits)”
MCC="${BASH_REMATCH[3]}${BASH_REMATCH[2]}${BASH_REMATCH[5]}"
MNC="${BASH_REMATCH[7]}${BASH_REMATCH[6]}${BASH_REMATCH[4]}"
LAC="$((0x${BASH_REMATCH[8]}))"
CI="$((0x${BASH_REMATCH[9]}))"
elif [[ $KCELL =~ +KCELL:\ [0-9]+,(0,[0-9]+|2),[0-9]+,([0-9])([0-9])(f)([0-9])([0-9])([0-9]),([0-9a-f]+),([0-9a-f]+) ]]; then
echo “Match (MNC has 2 digits)”
MCC="${BASH_REMATCH[3]}${BASH_REMATCH[2]}${BASH_REMATCH[5]}"
MNC="${BASH_REMATCH[7]}${BASH_REMATCH[6]}"
LAC="$((0x${BASH_REMATCH[8]}))"
CI="$((0x${BASH_REMATCH[9]}))"
else
echo “Warning: No match found”
fi
echo “MCC:$MCC MNC:$MNC LAC:$LAC CI:$CI”[/code]