summaryrefslogtreecommitdiff
path: root/src/MTS_IO_CellularRadio.cpp
blob: 8eb35d5a7a544192d84bcbf8db8290d59e1aa7b3 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
/*
 * Copyright (C) 2015 by Multi-Tech Systems
 *
 * This file is part of libmts-io.
 *
 * libmts-io is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * libmts-io is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with libmts-io.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*! 
 \file MTS_IO_CellularRadio.cpp
 \brief A brief description 
 \date Nov 5, 2014
 \author sgodinez

 A more elaborate description
*/

/*!
 \file MTS_CELL_CellularRadio.cpp
 \brief A brief description
 \date Nov 4, 2014
 \author sgodinez

 A more elaborate description
*/

#include <mts/MTS_IO_CellularRadio.h>
#include <mts/MTS_IO_MccMncTable.h>
#include <mts/MTS_Thread.h>
#include <mts/MTS_Timer.h>
#include <mts/MTS_Logger.h>
#include <mts/MTS_Text.h>
#include <map>
#include <cstring>
#include <sstream>
#include <sys/file.h>
#include <errno.h>
#include <unistd.h>


using namespace MTS::IO;

const char CellularRadio::ETX    = 0x03;  //Ends socket connection
const char CellularRadio::DLE    = 0x10;  //Escapes ETX and DLE within Payload
const char CellularRadio::CR     = 0x0D;
const char CellularRadio::NL     = 0x0A;
const char CellularRadio::CTRL_Z = 0x1A;

const std::string CellularRadio::RSP_ERROR("ERROR");
const std::string CellularRadio::RSP_OK("OK");


const std::string CellularRadio::DEFAULT_RADIO_PORT("/dev/modem_at1");
const std::string CellularRadio::DEFAULT_RADIO_DIR("/var/run/radio/");
const std::string CellularRadio::VALUE_UNKNOWN("Unknown");
const std::string CellularRadio::VALUE_UNAVAILABLE("Unavailable");
const std::string CellularRadio::VALUE_NOT_SUPPORTED("Not Supported");

const std::string CellularRadio::VALUE_NOT_REGISTERED("NOT REGISTERED");
const std::string CellularRadio::VALUE_REGISTERED("REGISTERED");
const std::string CellularRadio::VALUE_SEARCHING("SEARCHING");
const std::string CellularRadio::VALUE_DENIED("DENIED");
const std::string CellularRadio::VALUE_ROAMING("ROAMING");

//Static Data
const std::string CellularRadio::KEY_TYPE("type");                  //!< GSM or CDMA
const std::string CellularRadio::KEY_CODE("code");                  //!< Product Code : H5, H6, C2, EV3, G3
const std::string CellularRadio::KEY_MODEL("model");                //!< Model : HE910, LE910, CE910, DE910, GE910
const std::string CellularRadio::KEY_MANUFACTURER("manufacturer");  //!< Manufacturer: Telit
const std::string CellularRadio::KEY_HARDWARE("hardware");          //!< Radio Hardware Version
const std::string CellularRadio::KEY_FIRMWARE("firmware");          //!< Radio Firmware Version

const std::string CellularRadio::KEY_CARRIER("carrier");   //!< Cellular Service Provider (Home Network)
const std::string CellularRadio::VALUE_CARRIER_VERIZON("Verizon");
const std::string CellularRadio::VALUE_CARRIER_AERIS("Aeris");
const std::string CellularRadio::VALUE_CARRIER_SPRINT("Sprint");
const std::string CellularRadio::VALUE_CARRIER_ATT("AT&T");
const std::string CellularRadio::VALUE_CARRIER_TMOBILE("T-Mobile");

const std::string CellularRadio::KEY_IMEI("imei");          //!< International Mobile Station Equipment Identity
const std::string CellularRadio::KEY_MEID("meid");          //!< Mobile Equipment Identifier
const std::string CellularRadio::KEY_IMSI("imsi");          //!< International Mobile Subscriber Identity
const std::string CellularRadio::KEY_MSID("msid");          //!< Mobil Station ID / Mobile Identification Number (MSID/MIN) (CDMA-Only)
const std::string CellularRadio::KEY_MDN("mdn");            //!< Mobile Directory Number : Actual phone number dialed to reach radio
const std::string CellularRadio::KEY_ICCID("iccid");        //!< Integrated Circuit Card Identifier
const std::string CellularRadio::KEY_MSL("msl");            //!< Master Subsidy Lock

//Dynamic Data
const std::string CellularRadio::KEY_ROAMING("roaming");    //!< Indicates whether or not using Home Network
const std::string CellularRadio::KEY_DATETIME("datetime");  //!< Date and Time from tower
const std::string CellularRadio::KEY_SERVICE("service");    //!< Service Connection Type [GPRS, EGPRS, WCDMA, HSDPA, 1xRTT, EVDO]
const std::string CellularRadio::KEY_NETWORK("network");    //!< Cellular Service Provider
const std::string CellularRadio::KEY_CID("cid");            //!< Cellular ID (Tower) in HEX
const std::string CellularRadio::KEY_LAC("lac");            //!< Location Area Code in HEX
const std::string CellularRadio::KEY_RAC("rac");            //!< Routing Area Code in HEX
const std::string CellularRadio::KEY_RSSI("rssi");          //!< Signal Strength
const std::string CellularRadio::KEY_RSSIDBM("rssidBm");    //!< Signal Strength in dBm
const std::string CellularRadio::KEY_MCC("mcc");            //!< Country Code
const std::string CellularRadio::KEY_MNC("mnc");            //!< Operator Code
const std::string CellularRadio::KEY_CHANNEL("channel");    //!< ARFCN or UARFCN Assigned Radio Channel
const std::string CellularRadio::KEY_TXPWR("txpwr");        //!< Transmit Power
const std::string CellularRadio::KEY_PSC("psc");            //!< Active Primary Synchronization Code (PSC)
const std::string CellularRadio::KEY_ECIO("ecio");          //!< Active Ec/Io (chip energy per total wideband power in dBm)
const std::string CellularRadio::KEY_RSCP("rscp");          //!< Active RSCP (Received Signal Code Power in dBm)
const std::string CellularRadio::KEY_DRX("drx");            //!< Discontinuous reception cycle length (ms)
const std::string CellularRadio::KEY_MM("mm");              //!< Mobility Management State
const std::string CellularRadio::KEY_RR("rr");              //!< Radio Resource State
const std::string CellularRadio::KEY_NOM("nom");            //!< Network Operator Mode
const std::string CellularRadio::KEY_ABND("abnd");          //!< Active Band
const std::string CellularRadio::KEY_BLER("bler");          //!< Block Error Rate (percentage)
const std::string CellularRadio::KEY_SD("sd");              //!< Service Domain
const std::string CellularRadio::KEY_DEBUG("debug");        //!< Debug Information

const std::string CellularRadio::KEY_MIP("mipProfile");                      //!< Mobile IP Information
const std::string CellularRadio::KEY_MIP_ID("id");                           //!< Mobile IP ID
const std::string CellularRadio::KEY_MIP_ENABLED("enabled");                 //!< Mobile IP Enabled/Disabled
const std::string CellularRadio::KEY_MIP_NAI("nai");                         //!< Network Access Identifier
const std::string CellularRadio::KEY_MIP_HOMEADDRESS("homeAddress");         //!< Home Address
const std::string CellularRadio::KEY_MIP_PRIMARYHA("primaryAddress");        //!< Primary Home Agent
const std::string CellularRadio::KEY_MIP_SECONDARYHA("secondaryAddress");    //!< Secondary Home Agent
const std::string CellularRadio::KEY_MIP_MNAAASPI("mnAaaSpi");               //!< Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index
const std::string CellularRadio::KEY_MIP_MNHASPI("mnHaSpi");                 //!< Mobile Node Home Agent Security Server Parameter Index
const std::string CellularRadio::KEY_MIP_REVTUN("revTun");                   //!< Reverse Tunneling Enabled
const std::string CellularRadio::KEY_MIP_MNAAASS("mnAaaSs");                 //!< Mobile Node Authentication, Authorization, and Accounting Server Shared Secret
const std::string CellularRadio::KEY_MIP_MNHASS("mnHaSs");                   //!< Mobile Node Home Agent Shared Secret

const std::string CellularRadio::VALUE_TYPE_GSM("GSM");
const std::string CellularRadio::VALUE_TYPE_LTE("LTE");
const std::string CellularRadio::VALUE_TYPE_CDMA("CDMA");

const std::string CellularRadio::VALUE_SD_NO_SERVICE("NO SERVICE");
const std::string CellularRadio::VALUE_SD_CS_ONLY("CS ONLY");
const std::string CellularRadio::VALUE_SD_PS_ONLY("PS ONLY");
const std::string CellularRadio::VALUE_SD_CSPS("CS+PS");

const std::string CellularRadio::VALUE_ABND_GSM_850("GSM 850");
const std::string CellularRadio::VALUE_ABND_GSM_900("GSM 900");
const std::string CellularRadio::VALUE_ABND_DCS_1800("DCS 1800");
const std::string CellularRadio::VALUE_ABND_PCS_1900("PCS 1900");

const std::vector<std::string> CellularRadio::DEFAULT_BAIL_STRINGS = { CellularRadio::RSP_OK, CellularRadio::RSP_ERROR };

CellularRadio::CellularRadio(const std::string& sName, const std::string& sRadioPort)
: m_sName(sName)
, m_sRadioPort(sRadioPort)
, m_bEchoEnabled(false)
, m_bEnableEchoOnClose(false)
{
    m_apIo.reset(new MTS::IO::SerialConnection(
                             MTS::IO::SerialConnection::Builder(m_sRadioPort)
                                .baudRate(115200)
                                .useLockFile()
                                .build()));
}


CellularRadio::~CellularRadio() {
    shutdown();
    m_apIo.reset();
}

bool CellularRadio::initialize(uint32_t iTimeoutMillis) {
    if(!m_apIo->open(iTimeoutMillis)) {
        printError("%s| Failed to open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str());
        return false;
    }

    bool bEnabled;
    CODE eCode = getEcho(bEnabled);
    if(eCode == SUCCESS && bEnabled) {
        printDebug("%s| Disabling 'echo'", m_sName.c_str());
        setEcho(false);
        m_bEnableEchoOnClose = true;
    }

    return true;
}

bool CellularRadio::resetRadio(uint32_t iTimeoutMillis) {

    printInfo("%s| Rebooting radio", m_sName.c_str());
    if(sendBasicCommand("AT#REBOOT") == SUCCESS) {
        if(iTimeoutMillis > 5000) {
            MTS::Thread::sleep(5000);
            iTimeoutMillis -= 5000;
        }
        return resetConnection(iTimeoutMillis);
    }

    return false;
}

bool CellularRadio::resetConnection(uint32_t iTimeoutMillis) {
    //Close Current Connection
    if(!m_apIo.isNull()) {
        m_apIo->close();
    }

    m_apIo.reset(new MTS::IO::SerialConnection(
                     MTS::IO::SerialConnection::Builder(m_sRadioPort)
                        .baudRate(115200)
                        .useLockFile()
                        .build()));

    //Try to obtain the device port over the given period of time
    MTS::Timer oTimer;
    oTimer.start();
    uint64_t iCurrentTime = 0;
    while(iCurrentTime < iTimeoutMillis) {

        if(!m_apIo->open(iTimeoutMillis - iCurrentTime)) {
            printWarning("%s| Failed to re-open radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str());
        } else {
            printInfo("%s| Successfully re-opened radio port [%s]", m_sName.c_str(), m_sRadioPort.c_str());
            break;
        }

        ::usleep(500000); //500 millis
        iCurrentTime = oTimer.getMillis();
    }
    oTimer.stop();
    return !m_apIo->isClosed();
}

void CellularRadio::shutdown() {

    if(!m_apIo.isNull()) {
        if(m_bEnableEchoOnClose) {
            printDebug("%s| Enabling 'echo'", m_sName.c_str());
            setEcho(true);
            m_bEnableEchoOnClose = false;
        }
        m_apIo->close();
    }
}

const std::string& CellularRadio::getName() const {
    return m_sName;
}


CellularRadio::CODE CellularRadio::getModel(std::string& sModel) {
    printTrace("%s| Get Model", m_sName.c_str());
    //Always returns SUCCESS because the model should be m_sName
    sModel = m_sName;
    std::string sCmd("ATI4");
    std::string sResult = CellularRadio::sendCommand(m_apIo, sCmd);
    if (sResult.find("OK") == std::string::npos) {
        printWarning("%s| Unable to get model from radio.  Returning [%s]", m_sName.c_str(), m_sName.c_str());
        return SUCCESS;
    } else {
        sModel = CellularRadio::extractModelFromResult(sResult);
        if(sModel.size() == 0) {
            printWarning("%s| Unable to get model from radio.  Returning [%s]", m_sName.c_str(), m_sName.c_str());
            return SUCCESS;
        }
    }

    printDebug("%s| Extracted [%s] from [%s] query", m_sName.c_str(), sModel.c_str(), sCmd.c_str());
    if(sModel != m_sName) {
        printWarning("%s| Model identified [%s] does not match expected [%s]. Returning [%s]",
                     m_sName.c_str(),  sModel.c_str(), m_sName.c_str(), sModel.c_str());
    }

    return SUCCESS;
}

CellularRadio::CODE CellularRadio::convertModelToMtsShortCode(const std::string& sModel, std::string& sCode) {
    CODE eCode = FAILURE;

    if(sModel.find("HE910-D") == 0) {
        sCode = "H5";
        eCode = SUCCESS;
    } else if (sModel.find("HE910-EUD") == 0) {
        sCode = "H6";
        eCode = SUCCESS;
    } else if (sModel.find("LE910-NAG") == 0) {
        sCode = "LAT1";
        eCode = SUCCESS;
    } else if (sModel.find("LE910-SVG") == 0) {
        sCode = "LVW2";
        eCode = SUCCESS;
    } else if (sModel.find("LE910-EUG") == 0) {
        sCode = "LEU1";
        eCode = SUCCESS;
    } else if (sModel.find("GE910") == 0) {
        sCode = "G3";
        eCode = SUCCESS;
    } else if (sModel.find("CE910") == 0) {
        sCode = "C2";
        eCode = SUCCESS;
    } else if (sModel.find("DE910") == 0) {
        sCode = "EV3";
        eCode = SUCCESS;
    } else {
        sCode = VALUE_NOT_SUPPORTED;
        printError("RADIO| Could not identify MTS short code from model. [%s]", sModel.c_str());
        eCode = ERROR;
    }
    return eCode;
}

CellularRadio::CODE CellularRadio::convertServiceDomainToString(SERVICEDOMAIN eSd, std::string& sSd) {
    CODE eCode = FAILURE;
    switch(eSd) {
        case NO_SERVICE: sSd = VALUE_SD_NO_SERVICE; eCode = SUCCESS; break;
        case CS_ONLY: sSd = VALUE_SD_CS_ONLY; eCode = SUCCESS; break;
        case PS_ONLY: sSd = VALUE_SD_PS_ONLY; eCode = SUCCESS; break;
        case CSPS: sSd = VALUE_SD_CSPS; eCode = SUCCESS; break;
        default: sSd = VALUE_UNKNOWN; eCode = FAILURE; break;
    }
    return eCode;
}

CellularRadio::CODE CellularRadio::convertActiveBandToString(ACTIVEBAND eBand, std::string& sBand) {
    CODE eCode = FAILURE;
    switch(eBand) {
        case GSM_850: sBand = VALUE_ABND_GSM_850; eCode = SUCCESS; break;
        case GSM_900: sBand = VALUE_ABND_GSM_900; eCode = SUCCESS; break;
        case DCS_1800: sBand = VALUE_ABND_DCS_1800; eCode = SUCCESS; break;
        case PCS_1900: sBand = VALUE_ABND_PCS_1900; eCode = SUCCESS; break;
        default: sBand = VALUE_UNKNOWN; eCode = FAILURE; break;
    }
    return eCode;
}

CellularRadio::CODE CellularRadio::convertModelToType(const std::string& sModel, std::string& sType) {
    CODE eCode = FAILURE;
    sType = VALUE_NOT_SUPPORTED;

    if(sModel.find("HE910-D") == 0) {
        sType = VALUE_TYPE_GSM;
        eCode = SUCCESS;
    } else if (sModel.find("HE910-EUD") == 0) {
        sType = VALUE_TYPE_GSM;
        eCode = SUCCESS;
    } else if (sModel.find("LE910-NAG") == 0) {
        sType = VALUE_TYPE_LTE;
        eCode = SUCCESS;
    } else if (sModel.find("LE910-SVG") == 0) {
        sType = VALUE_TYPE_LTE;
        eCode = SUCCESS;
    } else if (sModel.find("LE910-EUG") == 0) {
        sType = VALUE_TYPE_LTE;
        eCode = SUCCESS;
    } else if (sModel.find("GE910") == 0) {
        sType = VALUE_TYPE_GSM;
        eCode = SUCCESS;
    } else if (sModel.find("CE910") == 0) {
        sType = VALUE_TYPE_CDMA;
        eCode = SUCCESS;
    } else if (sModel.find("DE910") == 0) {
        sType = VALUE_TYPE_CDMA;
        eCode = SUCCESS;
    } else {
        sType = VALUE_TYPE_GSM;
        eCode = ERROR;
        printError("RADIO| Could not identify type from model. [%s].  Assuming [%s]", sModel.c_str(), sType.c_str());
    }
    return eCode;
}

CellularRadio::CODE CellularRadio::getFirmware(std::string& sFirmware) {
    printTrace("%s| Get Firmware", m_sName.c_str());
    sFirmware = VALUE_NOT_SUPPORTED;
    std::string sCmd("AT+CGMR");
    std::string sResult = CellularRadio::sendCommand(sCmd);
    size_t pos = sResult.find(RSP_OK);
    if (pos == std::string::npos) {
        printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    sFirmware = MTS::Text::trim(sResult.substr(0, pos));
    if(sFirmware.size() == 0) {
        printWarning("%s| Unable to get firmware from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    m_sFirmware = sFirmware;

    return SUCCESS;
}

CellularRadio::CODE CellularRadio::getHardware(std::string& sHardware) {
    printTrace("%s| Get Hardware", m_sName.c_str());
    sHardware = VALUE_NOT_SUPPORTED;

    if(m_sFirmware.size() == 0) {
        getFirmware(m_sFirmware);
    }

    if(getHardwareVersionFromFirmware(m_sFirmware, sHardware)) {
        return SUCCESS;
    }
    return FAILURE;
}

CellularRadio::CODE CellularRadio::getManufacturer(std::string& sManufacturer) {
    printTrace("%s| Get Manufacturer", m_sName.c_str());
    sManufacturer = VALUE_NOT_SUPPORTED;
    std::string sCmd("AT+GMI");
    std::string sResult = CellularRadio::sendCommand(sCmd);
    size_t pos = sResult.find(RSP_OK);
    if (pos == std::string::npos) {
        printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    sManufacturer = MTS::Text::trim(sResult.substr(0, pos));
    if(sManufacturer.size() == 0) {
        printWarning("%s| Unable to get manufacturer from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    return SUCCESS;
}

CellularRadio::CODE CellularRadio::getImei(std::string& sImei) {
    printTrace("%s| Get IMEI", m_sName.c_str());
    sImei = VALUE_NOT_SUPPORTED;
    std::string sCmd("AT+CGSN");
    std::string sResult = CellularRadio::sendCommand(sCmd);
    size_t pos = sResult.find(RSP_OK);
    if (pos == std::string::npos) {
        printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    sImei = MTS::Text::trim(sResult.substr(0, pos));
    if(sImei.size() == 0) {
        printWarning("%s| Unable to get IMEI from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    return SUCCESS;
}

CellularRadio::CODE CellularRadio::getMeid(std::string& sMeid) {
    printTrace("%s| Get MEID", m_sName.c_str());
    return getImei(sMeid);
}

CellularRadio::CODE CellularRadio::getImsi(std::string& sImsi) {
    printTrace("%s| Get IMSI", m_sName.c_str());
    sImsi = VALUE_NOT_SUPPORTED;
    std::string sCmd("AT+CIMI");
    std::string sResult = CellularRadio::sendCommand(sCmd);
    size_t pos = sResult.find(RSP_OK);
    if (pos == std::string::npos) {
        printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    sImsi = MTS::Text::trim(sResult.substr(0, pos));
    if(sImsi.size() == 0) {
        printWarning("%s| Unable to get IMSI from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    return SUCCESS;
}

CellularRadio::CODE CellularRadio::getSimStatus(std::string& sSimStatus) {
    printTrace("%s| Get SIM Status", getName().c_str());
    sSimStatus = VALUE_UNKNOWN;
    return FAILURE;
}

CellularRadio::CODE CellularRadio::getIccid(std::string& sIccid) {
    printTrace("%s| Get ICCID", m_sName.c_str());
    sIccid = VALUE_NOT_SUPPORTED;
    std::string sCmd("AT#CCID");
    std::string sResult = CellularRadio::sendCommand(sCmd);
    size_t end = sResult.find(RSP_OK);
    if (end == std::string::npos) {
        printWarning("%s| Unable to get ICCID from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    size_t start = sResult.find("#CCID:");
    if(start != std::string::npos) {
        start += sizeof("#CCID:");
        sIccid = MTS::Text::trim(sResult.substr(start, end-start));
        if(sIccid.size() == 0) {
            printWarning("%s| Unable to get ICCID from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
            return FAILURE;
        }
    }
    return SUCCESS;
}

CellularRadio::CODE CellularRadio::getService(std::string& sService) {
    printTrace("%s| Get Service", m_sName.c_str());
    sService = VALUE_NOT_SUPPORTED;
    std::string sCmd("AT#PSNT?");
    std::string sResult = CellularRadio::sendCommand(sCmd);
    size_t end = sResult.find(RSP_OK);
    if (end == std::string::npos) {
        printWarning("%s| Unable to get Service from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    size_t start = sResult.find(",");
    if(start != std::string::npos) {
        start += 1; //comma
        std::string sPsnt = MTS::Text::trim(sResult.substr(start, end-start));
        int32_t iService;
        sscanf(sPsnt.c_str(), "%d", &iService);

        switch(iService) {
            case 0: sService = "GPRS"; break;
            case 1: sService = "EGPRS"; break;
            case 2: sService = "WCDMA"; break;
            case 3: sService = "HSDPA"; break;
            case 4: sService = "LTE"; break;
            default: sService = VALUE_UNKNOWN; break;
        }

        printDebug("%s| Service ID: [%d][%s]", m_sName.c_str(), iService, sService.c_str());
    }
    return SUCCESS;
}

CellularRadio::CODE CellularRadio::getLac(std::string& sLac) {
    Json::Value jData;

    printTrace("%s| Get LAC", m_sName.c_str());
    sLac = VALUE_NOT_SUPPORTED;

    if(getNetworkStatus(jData) == SUCCESS) {
        if(jData.isMember(KEY_LAC)) {
            sLac = jData[KEY_LAC].asString();
            return SUCCESS;
        }
    }

    return FAILURE;
}

CellularRadio::CODE CellularRadio::getMdn(std::string& sMdn) {
    printTrace("%s| Get MDN", m_sName.c_str());
    sMdn = VALUE_NOT_SUPPORTED;
    std::string sCmd("AT+CNUM");
    std::string sResult = CellularRadio::sendCommand(sCmd);
    size_t end = sResult.find(RSP_OK);
    if (end == std::string::npos) {
        printWarning("%s| Unable to get MDN from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    size_t start = sResult.find("CNUM:");
    if(start != std::string::npos) {
        start += sizeof("CNUM:");
        std::vector<std::string> vParts = MTS::Text::split(sResult.substr(start, end - start), ',');
        if(vParts.size() < 3) {
            printWarning("%s| Unable to parse MDN from response [%s]", m_sName.c_str(), sResult.c_str());
            return FAILURE;
        }
        sMdn = MTS::Text::strip(vParts[1], '"');
        if(sMdn.size() == 0) {
            printWarning("%s| Unable to get MDN from radio using command [%s].  MDN may not be set.", m_sName.c_str(), sCmd.c_str());
        }
    } else {
        sMdn = "";
        printWarning("%s| Unable to get MDN from radio using command [%s].  MDN may not be set.", m_sName.c_str(), sCmd.c_str());
    }

    return SUCCESS;
}

CellularRadio::CODE CellularRadio::getMsid(std::string& sMsid) {
    printTrace("%s| Get MSID", m_sName.c_str());
    sMsid = "";

    std::string sImsi;
    if(getImsi(sImsi) == SUCCESS) {
        if(sImsi.size() >= 10) {
            sMsid = sImsi.substr(sImsi.size() - 10);
            printTrace("IMSI: [%s] MEID [%s]", sImsi.c_str(), sMsid.c_str());
            return SUCCESS;
        }
    }
    printWarning("%s| Unable to get MSID from radio", m_sName.c_str());
    return FAILURE;
}

CellularRadio::CODE CellularRadio::getType(std::string& sType) {
    printTrace("%s| Get Type", m_sName.c_str());
    sType = VALUE_NOT_SUPPORTED;
    return FAILURE;
}

CellularRadio::CODE CellularRadio::getCarrier(std::string& sCarrier) {
    printTrace("%s| Get Carrier", m_sName.c_str());
    if(m_sCarrier == "") {
        Json::Value jData;
        if(getNetworkStatus(jData) == SUCCESS) {
            if(jData.isMember(KEY_MCC) && jData.isMember(KEY_MNC)) {
                std::string sMcc = jData[KEY_MCC].asString();
                std::string sMnc = jData[KEY_MNC].asString();
                Json::Value jLookup = MccMncTable::getInstance()->lookup(sMcc, sMnc);
                printTrace("%s| MCC-MNC Lookup: [%s][%s][%s]", m_sName.c_str(),
                           sMcc.c_str(), sMnc.c_str(), jLookup.toStyledString().c_str());
                if(jLookup.isMember(KEY_CARRIER)) {
                    m_sCarrier = jLookup[KEY_CARRIER].asString();
                } else {
                    printWarning("%s| MCC-MNC Lookup did not contain carrier", m_sName.c_str());
                    return FAILURE;
                }
            } else {
                printWarning("%s| Network Status did no contain MCC or MNC", m_sName.c_str());
                return FAILURE;
            }
        } else {
            return FAILURE;
        }
    }

    sCarrier = m_sCarrier;
    return SUCCESS;
}

CellularRadio::CODE CellularRadio::getTower(std::string& sTower) {
    Json::Value jData;

    printTrace("%s| Get Tower", m_sName.c_str());
    sTower = VALUE_NOT_SUPPORTED;

    if(getNetworkStatus(jData) == SUCCESS) {
        if(jData.isMember(KEY_CID)) {
            sTower = jData[KEY_CID].asString();
            return SUCCESS;
        }
    }
    return FAILURE;
}

CellularRadio::CODE CellularRadio::getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone) {
    Json::Value jData;

    printTrace("%s| Get Time", m_sName.c_str());
    sDate = "";
    sTime = "";
    sTimeZone = "";

    std::string sCmd("AT+CCLK?");
    std::string sResult = CellularRadio::sendCommand(sCmd);
    size_t end = sResult.find(RSP_OK);
    if (end == std::string::npos) {
        printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    size_t start = sResult.find("CCLK: ");
    if(start != std::string::npos) {
        start += sizeof("CCLK: ");
        std::string sValue = MTS::Text::trim(sResult.substr(start, end - start));
        sValue = MTS::Text::strip(sValue, '"');

        std::vector<std::string> vParts = MTS::Text::split(sValue, ',');
        if(vParts.size() != 2) {
            printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str());
            return FAILURE;
        }


        std::vector<std::string> vDateParts = MTS::Text::split(vParts[0], '/');
        if(vDateParts.size() != 3) {
            printWarning("%s| Unable to parse Date from response [%s]", m_sName.c_str(), sResult.c_str());
            return FAILURE;
        }

        //The Date format is YY/MM/DD -> Change to MM/DD/YY
        sDate = vDateParts[1] + "/" + vDateParts[2] + "/" + vDateParts[0];

        vParts = MTS::Text::split(vParts[1], '-');
        if(vParts.size() != 2) {
            printWarning("%s| Unable to parse Time from response [%s]", m_sName.c_str(), sResult.c_str());
            return FAILURE;
        }
        sTime = vParts[0];

        int32_t iZoneUnits; //the difference, expressed in quarters of an hour, between the local time and GMT
        if(!MTS::Text::parse(iZoneUnits, MTS::Text::strip(vParts[1], '+'))) {
            printWarning("%s| Unable to parse Time Zone from response [%s]", m_sName.c_str(), sResult.c_str());
            return FAILURE;
        }

        int32_t iZone = iZoneUnits/4;  //Divide by 4 to get hours difference
        int32_t iZonePartial = (iZoneUnits % 4) * 15;  //Remainder in minutes
        std::string sPlusSign = "+";
        if(iZonePartial < 0) {
            //Remove negative sign from partial and clear plus sign component
            iZonePartial *= -1;
            sPlusSign = "";
        }
        std::stringstream ss;
        ss << sPlusSign << iZone;
        if(iZonePartial != 0) {
            ss << ":" << iZonePartial;
        }

        sTimeZone = ss.str();
        return SUCCESS;

    } else {
        printWarning("%s| Unable to get Time from radio using command [%s]", m_sName.c_str(), sCmd.c_str());
    }

    return FAILURE;
}

CellularRadio::CODE CellularRadio::getRoaming(bool& bRoaming) {
    Json::Value jData;

    printTrace("%s| Get Roaming", m_sName.c_str());
    bRoaming = false;

    REGISTRATION eReg;
    if(getRegistration(eReg) == SUCCESS) {
        bRoaming = (eReg == ROAMING);
        return SUCCESS;
    }
    return FAILURE;
}

CellularRadio::CODE CellularRadio::getNetwork(std::string& sNetwork) {
    Json::Value jData;

    printTrace("%s| Get Network", m_sName.c_str());
    sNetwork = VALUE_NOT_SUPPORTED;

    if(getNetworkStatus(jData) == SUCCESS) {
        if(jData.isMember(KEY_NETWORK)) {
            sNetwork = jData[KEY_NETWORK].asString();
            return SUCCESS;
        }
    }
    return FAILURE;
}

CellularRadio::CODE CellularRadio::getSignalStrength(int32_t& rssi) {
    printTrace("%s| Get Signal Strength", m_sName.c_str());
    std::string sCmd("AT+CSQ");
    std::string sResult = sendCommand(sCmd);
    if (sResult.find("+CSQ: ") == std::string::npos) {
        printDebug("%s| Signal Strength command returned unexpected response: [%s]", m_sName.c_str(), sResult.c_str());
        return FAILURE;
    }

    size_t start = sResult.find(':');
    size_t stop = sResult.find(',', start);
    if(start == std::string::npos || stop == std::string::npos) {
        printDebug("%s| Signal Strength command returned malformed response: [%s]", m_sName.c_str(), sResult.c_str());
        return FAILURE;
    }
    std::string signal = sResult.substr(start + 2, stop - start - 2);

    sscanf(signal.c_str(), "%d", &rssi);
    printDebug("%s| Signal Strength: [%d]", m_sName.c_str(), rssi);

    return SUCCESS;
}

CellularRadio::CODE CellularRadio::convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& iDbm) {

    //Telit Conversion
    if(iRssi < 0 || iRssi == 99) {
        return FAILURE;
    }

    if(iRssi == 0) {
        iDbm = -113;
    } else if(iRssi == 1) {
        iDbm = -111;
    } else if(iRssi <= 30) {
        //28 steps between 2 and 30
        //54 dbm between 53 and 109
        float stepSize = 54.0 / 28.0;
        iDbm = -109 + (int)(stepSize * (iRssi-2));
    } else {
        iDbm = -51;
    }

    return SUCCESS;
}

CellularRadio::CODE CellularRadio::convertdBmToSignalStrength(const int32_t& iDBm, int32_t& iRssi) {
    //Telit Conversion
    if(iDBm <= -113) {
        iRssi = 0;
    } else if(iDBm <= -111) {
        iRssi = 1;
    } else if(iDBm <= -53) {
        //54 dbm between -109 and -53
        //28 steps between 2 and 30
        float stepSize = 28.0/54.0;
        iRssi = ((iDBm + 109)*stepSize) + 2;
    } else {
        iRssi = 31;
    }

    return SUCCESS;
}

CellularRadio::CODE CellularRadio::getEcho(bool& bEnabled) {
    printTrace("%s| Echo Test", m_sName.c_str());
    std::string sResult = sendCommand("AT");
    if(sResult.size() == 0) {
        return NO_RESPONSE;
    }

    if(sResult.find("AT") != std::string::npos) {
        bEnabled = true;
    } else {
        bEnabled = false;
    }
    m_bEchoEnabled = bEnabled;
    return SUCCESS;
}

CellularRadio::CODE CellularRadio::setEcho(bool bEnabled) {
    CODE eCode = FAILURE;
    if(bEnabled) {
        eCode = sendBasicCommand("ATE1");
        m_bEchoEnabled = (eCode == SUCCESS ) ? true : m_bEchoEnabled;
    } else {
        eCode = sendBasicCommand("ATE0");
        m_bEchoEnabled = (eCode == SUCCESS ) ? false : m_bEchoEnabled;
    }

    return eCode;
}

CellularRadio::CODE CellularRadio::getStaticInformation(Json::Value& jData) {
    printTrace("%s| Get Static Information", m_sName.c_str());

    printTrace("%s| Static Information:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str());

    return FAILURE;
}

/*  AT#RFSTS - NETWORK STATUS

    (GSM network)
    #RFSTS:<PLMN>,<ARFCN>,<RSSI>,<LAC>,<RAC>,<TXPWR>,<MM>,<RR>,<NOM>,<CID>,<IMSI>,<NetNameAsc>,<SD>,<ABND>
    Where:
    <PLMN> - Country code and operator code(MCC, MNC)
    <ARFCN> - GSM Assigned Radio Channel
    <RSSI> - Received Signal Strength Indication
    <LAC> - Localization Area Code
    <RAC> - Routing Area Code
    <TXPWR> - Tx Power
    <MM> - Mobility Management state
    <RR> - Radio Resource state
    <NOM> - Network Operator Mode
    <CID> - Cell ID
    <IMSI> - International Mobile Subscriber Identity
    <NetNameAsc> - Operator name
    <SD> - Service Domain
    0 - No Service
    1 - CS only
    2 - PS only
    3 - CS+PS
    <ABND> - Active Band
    1 - GSM 850
    2 - GSM 900
    3 - DCS 1800
    4 - PCS 1900


    (WCDMA network)
    #RFSTS:
    <PLMN>,<UARFCN>,<PSC>,<Ec/Io>,<RSCP>, RSSI>,<LAC>,<RAC>,<TXPWR>,<DRX>,<MM>,<RRC>,<NOM>,<BLER>,<CID>,<IMSI>,
    <NetNameAsc>,<SD>,<nAST>[,<nUARFCN><nPSC>,<nEc/Io>]
    Where:
    <PLMN> - Country code and operator code(MCC, MNC)
    <UARFCN> - UMTS Assigned Radio Channel
    <PSC> - Active PSC(Primary Synchronization Code)
    <Ec/Io> - Active Ec/Io(chip energy per total wideband power in dBm)
    <RSCP> - Active RSCP (Received Signal Code Power in dBm)
    <RSSI> - Received Signal Strength Indication
    <LAC> - Localization Area Code
    <RAC> - Routing Area Code
    <TXPWR> - Tx Power
    <DRX> - Discontinuous reception cycle Length (cycle length in ms)
    <MM> - Mobility Management state
    <RR> - Radio Resource state
    <NOM> - Network Operator Mode
    <BLER> - Block Error Rate (e.g., 005 means 0.5 %)
    <CID> - Cell ID
    <IMSI> - International Mobile Station ID
    <NetNameAsc> - Operator name
    <SD> - Service Domain (see above)
    <nAST> - Number of Active Set (Maximum 6)
    <nUARFCN> UARFCN of n th active set
    <nPSC> PSC of n th active set
    <nEc/Io > Ec/Io of n th active Set

    (LTE Network)
    #RFSTS:
    <PLMN> -
    <EARFCN> -
    <RSRP> -
    <RSSI> -
    <RSRQ> -
    <TAC> -
    [<TXPWR>] -
    <DRX> -
    <MM> -
    <RRC> -
    <CID> -
    <IMSI> -
    [<NetNameAsc>] -
    <SD> -
    <ABND> -
*/
CellularRadio::CODE CellularRadio::getNetworkStatus(Json::Value& jData) {
    int32_t iValue;
    std::string sValue;
    const uint32_t GSM_NETWORK_FORMAT = 14;
    const uint32_t WCDMA_NETWORK_FORMAT = 19;
    const uint32_t LTE_NETWORK_FORMAT = 16;

    printTrace("%s| Get Network Status", m_sName.c_str());
    std::string sCmd("AT#RFSTS");
    std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 200);
    if (sResult.find("#RFSTS:") == std::string::npos) {
        printDebug("%s| Network Status command returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str());
        return FAILURE;
    }

    size_t start = sResult.find(":") + 1; //Position right after "#RFSTS:"
    std::vector<std::string> vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ",");

    if(vParts.size() >= 3) {
        //Country Code and Operator Code
        std::vector<std::string> vPLMN = MTS::Text::split(vParts[0], ' ');
        if(vPLMN.size() == 2) {
            jData[KEY_MCC] = MTS::Text::strip(vPLMN[0], '"');
            jData[KEY_MNC] = MTS::Text::strip(vPLMN[1], '"');
        }

        jData[KEY_CHANNEL] = vParts[1];
    } else {
        //Unknown Format
        return FAILURE;
    }

    if(vParts.size() == GSM_NETWORK_FORMAT ) {
        //Parse as GSM Network Format
        jData[KEY_RSSIDBM] = vParts[2];
        jData[KEY_LAC] =  vParts[3];
        jData[KEY_RAC] = vParts[4];
        jData[KEY_TXPWR] = vParts[5];
        jData[KEY_MM] = vParts[6];
        jData[KEY_RR] = vParts[7];
        jData[KEY_NOM] = vParts[8];
        jData[KEY_CID] = vParts[9];
        jData[KEY_IMSI] = MTS::Text::strip(vParts[10], '"');
        jData[KEY_NETWORK] = MTS::Text::strip(vParts[11], '"');
        if(MTS::Text::parse(iValue, vParts[12]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) {
            jData[KEY_SD] = sValue;
        }
        if(MTS::Text::parse(iValue, vParts[13]) && convertActiveBandToString((ACTIVEBAND)iValue, sValue) == SUCCESS) {
            jData[KEY_ABND] = sValue;
        }
    } else if(vParts.size() >= WCDMA_NETWORK_FORMAT) {
        Json::Value jDebug;

        //Parse as WCDMA Network Format

        jDebug[KEY_PSC] = vParts[2];
        jDebug[KEY_ECIO] = vParts[3];
        jDebug[KEY_RSCP] = vParts[4];

        jData[KEY_RSSIDBM] = vParts[5];
        jData[KEY_LAC] = vParts[6];
        jData[KEY_RAC] = vParts[7];

        jDebug[KEY_TXPWR] = vParts[8];
        jDebug[KEY_DRX] = vParts[9];
        jDebug[KEY_MM] = vParts[10];
        jDebug[KEY_RR] = vParts[11];
        jDebug[KEY_NOM] = vParts[12];

        if(vParts[13].size() != 0) {
            jDebug[KEY_BLER] = vParts[13];
        } else {
            jDebug[KEY_BLER] = "000";
        }

        jData[KEY_CID] = vParts[14];
        jData[KEY_IMSI] = MTS::Text::strip(vParts[15], '"');
        jData[KEY_NETWORK] = MTS::Text::strip(vParts[16], '"');

        // Get the radio band given the channel (UARFCN)
        RadioBandMap radioBandMap(vParts[1], CellularRadio::VALUE_TYPE_CDMA);
        jData[KEY_ABND] = radioBandMap.getRadioBandName();

        if(MTS::Text::parse(iValue, vParts[17]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) {
            jDebug[KEY_SD] = sValue;
        }
        //Ignoring Active Set Values
        //  <nAST> - Number of Active Set (Maximum 6)
        //  <nUARFCN> - UARFCN of n th active set
        //  <nPSC> - PSC of n th active set
        //  <nEc/Io > - Ec/Io of n th active Set

        jData[KEY_DEBUG] = jDebug;
    } else if(vParts.size() >= LTE_NETWORK_FORMAT) {
        Json::Value jDebug;

        //Parse as LTE Network Format

        jDebug["rsrp"] = vParts[2];
        jDebug[KEY_RSSIDBM] = vParts[3];
        jDebug["rsrq"] = vParts[4];

        jData["tac"] = vParts[5];
        jData[KEY_RAC] = vParts[6];
        jDebug[KEY_TXPWR] = vParts[7];
        //Odd empty index at 7
        jData[KEY_DRX] = vParts[8];

        jDebug[KEY_MM] = vParts[9];
        jDebug["rrc"] = vParts[10];
        jData[KEY_CID] = vParts[11];
        jData[KEY_IMSI] = MTS::Text::strip(vParts[12], '"');
        jData[KEY_NETWORK] = MTS::Text::strip(vParts[13], '"');

        // Get the radio band given the channel (EARFCN)
        RadioBandMap radioBandMap(vParts[1], CellularRadio::VALUE_TYPE_LTE);
        jData[KEY_ABND] = radioBandMap.getRadioBandName();

        // Get the LAC for the LTE radio that's not in the #RFSTS response
        sCmd = "AT+CGREG=2";
        sResult = sendCommand(sCmd);
        if (sResult.find("OK") == std::string::npos) {
            printDebug("%s| AT#CGREG=2 returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str());
        }
        sCmd = "AT+CGREG?";
        sResult = sendCommand(sCmd);
        if (sResult.find("+CGREG:") == std::string::npos) {
            printDebug("%s| AT#CGREG? returned unexpected response: [%s][%s]", m_sName.c_str(), sCmd.c_str(), sResult.c_str());
            jData[KEY_LAC] = CellularRadio::VALUE_UNKNOWN;
        } else {
            size_t start = sResult.find(":") + 1; //Position right after "#RFSTS:"
            std::vector<std::string> vParts = MTS::Text::split(MTS::Text::trim(sResult.substr(start)), ",");
            jData[KEY_LAC] = MTS::Text::strip(vParts[2], '"');
        }

        if(MTS::Text::parse(iValue, vParts[14]) && convertServiceDomainToString((SERVICEDOMAIN)iValue, sValue) == SUCCESS) {
            jDebug[KEY_SD] = sValue;
        }

        jData[KEY_DEBUG] = jDebug;
    }

    getCommonNetworkStats(jData);

    printTrace("%s| Network Status:\n%s\n", m_sName.c_str(), jData.toStyledString().c_str());

    return SUCCESS;
}

void CellularRadio::getCommonNetworkStats(Json::Value& jData) {

    bool bRoaming = false;
    if(getRoaming(bRoaming) == SUCCESS) {
        jData[KEY_ROAMING] = bRoaming;
    }

    int32_t iRssi;
    if(getSignalStrength(iRssi) == SUCCESS) {
        jData[KEY_RSSI] = iRssi;
        int32_t dBm;
        if(!jData.isMember(KEY_RSSIDBM) && convertSignalStrengthTodBm(iRssi, dBm) == SUCCESS) {
            //Add RSSI in dBm format
            jData[KEY_RSSIDBM] = MTS::Text::format(dBm);
        }
    }

    std::string sService;
    if(getService(sService) == SUCCESS) {
        jData[KEY_SERVICE] = sService;
    }
    std::string sDate, sTime, sTimeZone;
    if(getTime(sDate, sTime, sTimeZone) == SUCCESS) {

        jData[KEY_DATETIME] = sDate + " " + sTime + " GMT" + sTimeZone;
    }
}

void CellularRadio::initMipProfile(Json::Value& jData) {
    jData[KEY_MIP_ID] = 0;
    jData[KEY_MIP_ENABLED] = false;
    jData[KEY_MIP_NAI] = VALUE_UNKNOWN;
    jData[KEY_MIP_HOMEADDRESS] = VALUE_UNKNOWN;
    jData[KEY_MIP_PRIMARYHA] = VALUE_UNKNOWN;
    jData[KEY_MIP_SECONDARYHA] = VALUE_UNKNOWN;
    jData[KEY_MIP_MNAAASPI] = VALUE_UNKNOWN;
    jData[KEY_MIP_MNHASPI] = VALUE_UNKNOWN;
    jData[KEY_MIP_MNAAASS] = false;
    jData[KEY_MIP_MNHASS] = false;
}

CellularRadio::CODE CellularRadio::getRegistration(REGISTRATION& eRegistration) {
    std::string sCmd;
    std::string sResp;

    if (m_sName.find("LE910-") != std::string::npos) {
        // use AT+CGREG instead for LE910 models
        sCmd = "AT+CGREG?";
        sResp = "+CGREG: ";
    }
    else {
        sCmd = "AT+CREG?";
        sResp = "+CREG: ";
    }

    std::string sResult = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, 5000);
    if (sResult.find(sResp) == std::string::npos) {
        if(sResult.size() == 0) {
            printDebug("%s| Registration command returned no response: [%s]", m_sName.c_str());
            return NO_RESPONSE;
        }
        printDebug("%s| Registration command returned unexpected response: [%s]", m_sName.c_str(), sResult.c_str());
        return FAILURE;
    }

    size_t start = sResult.find(',');
    size_t stop = sResult.find(' ', start);
    std::string sRegStat = sResult.substr(start + 1, stop - start - 1);
    int32_t value;
    sscanf(sRegStat.c_str(), "%d", &value);
    eRegistration = (REGISTRATION)value;
    return SUCCESS;
}

CellularRadio::CODE CellularRadio::convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration) {

    CODE eCode = FAILURE;
    switch (eRegistration) {
        case NOT_REGISTERED: sRegistration = VALUE_NOT_REGISTERED; eCode = SUCCESS; break;
        case REGISTERED: sRegistration = VALUE_REGISTERED; eCode = SUCCESS; break;
        case SEARCHING: sRegistration = VALUE_SEARCHING; eCode = SUCCESS; break;
        case DENIED: sRegistration = VALUE_DENIED; eCode = SUCCESS; break;
        case UNKNOWN: sRegistration = VALUE_UNKNOWN; eCode = SUCCESS; break;
        case ROAMING: sRegistration = VALUE_ROAMING; eCode = SUCCESS; break;
    }
    return eCode;
}

CellularRadio::CODE CellularRadio::validateMsl(const Json::Value& jArgs) {
    printTrace("%s| Validate MSL", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMdn(const Json::Value& jArgs) {
    printTrace("%s| Set MDN", m_sName.c_str());

    if(!jArgs["mdn"].isString()) {
        return INVALID_ARGS;
    }

    std::string sCmd("AT#SNUM=1,\"");
    sCmd += jArgs["mdn"].asString() + "\"";

    std::string sResult = sendCommand(sCmd);
    size_t end = sResult.find(RSP_OK);
    if (end == std::string::npos) {
        printWarning("%s| Unable to set MDN for radio using command [%s]", m_sName.c_str(), sCmd.c_str());
        return FAILURE;
    }

    return SUCCESS;
}

CellularRadio::CODE CellularRadio::setMsid(const Json::Value& jArgs) {
    printTrace("%s| Set MSID", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::getMipProfile(Json::Value& jMipProfile) {
    printTrace("%s| Get MIP Active Profile", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMipActiveProfile(const Json::Value& jArgs) {
    printTrace("%s| Set MIP Active Profile", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMipNai(const Json::Value& jArgs) {
    printTrace("%s| Set MIP NAI", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMipHomeIp(const Json::Value& jArgs) {
    printTrace("%s| Set MIP Home IP", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMipPrimaryHa(const Json::Value& jArgs) {
    printTrace("%s| Set MIP Primary HA", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMipSecondaryHa(const Json::Value& jArgs) {
    printTrace("%s| Set MIP Secondary HA", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMipMnAaaSpi(const Json::Value& jArgs) {
    printTrace("%s| Set MIP MN-AAA SPI", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMipMnHaSpi(const Json::Value& jArgs) {
    printTrace("%s| Set MIP MN-HA SPI", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMipRevTun(const Json::Value& jArgs) {
    printTrace("%s| Set MIP Rev Tun", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMipMnAaaSs(const Json::Value& jArgs) {
    printTrace("%s| Set MIP MN-AAA SS", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::setMipMnHaSs(const Json::Value& jArgs) {
    printTrace("%s| Set MIP MN-HA SS", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::updateDc(const Json::Value& jArgs, UpdateCb& stepCb) {
    printTrace("%s| Update Device Configuration", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::updatePrl(const Json::Value& jArgs, UpdateCb& stepCb) {
    printTrace("%s| Update Preferred Roaming List", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::updateFumo(const Json::Value& jArgs, UpdateCb& stepCb) {
    printTrace("%s| Update Firmware Update Management Object", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::resetHfa(const Json::Value& jArgs, UpdateCb& stepCb) {
    printTrace("%s| HFA Reset", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::activate(const Json::Value& jArgs, UpdateCb& stepCb) {
    printTrace("%s| Activation", m_sName.c_str());

    return NOT_APPLICABLE;
}

CellularRadio::CODE CellularRadio::sendBasicCommand(const std::string& sCmd, int32_t iTimeoutMillis, const char& ESC) {
    std::string response = sendCommand(sCmd, DEFAULT_BAIL_STRINGS, iTimeoutMillis, ESC);
    if (response.size() == 0) {
        return NO_RESPONSE;
    } else if (response.find(RSP_OK) != std::string::npos) {
        return SUCCESS;
    } else if (response.find(RSP_ERROR) != std::string::npos) {
        return ERROR;
    } else {
        return FAILURE;
    }
}

std::string CellularRadio::sendCommand(const std::string& sCmd, const std::vector<std::string>& vBail, int32_t timeoutMillis, const char& ESC) {
    return sendCommand(m_apIo, sCmd, vBail, timeoutMillis, ESC);
}

std::string CellularRadio::sendCommand(MTS::AutoPtr<MTS::IO::Connection>& apIo, const std::string& sCmd,
                                       const std::vector<std::string>& vBail, int32_t timeoutMillis, const char& ESC) {
    IsNeedMoreData isNeedMoreData = [&vBail](const std::string& iterationData, const std::string& allData)->bool {
        for(size_t i = 0; i < vBail.size(); i++) {
            const std::string& sBail = vBail[i];
            if(sBail.size() > 0) {
                if(allData.find(sBail) != std::string::npos) {
                    //Return when bail string is found
                    printTrace("RADIO| Found bail string [%s]", sBail.c_str());
                    return false;
                }
            }
        }
        return true;
    };

    return sendCommand(apIo, sCmd, isNeedMoreData, timeoutMillis, ESC);
}

std::string CellularRadio::sendCommand(const std::string& sCmd, MTS::IO::CellularRadio::IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) {
    return sendCommand(m_apIo, sCmd, isNeedMoreData, timeoutMillis, ESC);
}

std::string CellularRadio::sendCommand(MTS::AutoPtr<MTS::IO::Connection>& apIo, const std::string& sCmd,
                                       IsNeedMoreData& isNeedMoreData, int32_t timeoutMillis, const char& ESC) {
    if(MTS::Logger::getPrintLevel() >= MTS::Logger::PrintLevel::TRACE_LEVEL) {
        printTrace("RADIO| Sending command [%s]", sCmd.c_str());
    }
    if(apIo.isNull()) {
        printError("RADIO| IO is not set in sendCommand");
        return "";
    }

    int32_t iResult;
    if(ESC == 0x00) {
        iResult = apIo->write(sCmd.data(), sCmd.size());
    } else {
        std::string sNewCmd(sCmd);
        sNewCmd.push_back(ESC);
        iResult = apIo->write(sNewCmd.data(), sNewCmd.size());
    }

    if(iResult == -1) {
        printError("RADIO| Failed to send command to radio");
        return "";
    }

    bool done = false;
    const uint32_t capacity = 1024;
    char buffer[capacity];
    std::string sResult;
    Timer timer;
    timer.start();
    do {
        int32_t iterationTimeout = 100;
        int bytesRead = apIo->read((char*)buffer, capacity, iterationTimeout);
        if(bytesRead == -1) {
            printError("RADIO| Failed to read from radio");
            break;
        }

        std::string sIteration((char*)buffer, bytesRead);
        sResult += sIteration;

        if(isNeedMoreData && !isNeedMoreData(sIteration, sResult)) {
            printTrace("RADIO| No more data needed");
            return sResult;
        }
        if(timeoutMillis >= 0) {
            done = (timer.getMillis() >= (uint64_t)timeoutMillis);
        } else {
            //Do not stop looping until bail string is found
        }
    } while(!done);

    //Timed out
    return sResult;
}

CellularRadio::CODE CellularRadio::test(MTS::AutoPtr<MTS::IO::Connection>& apIo, uint32_t timeoutSeconds) {
    printTrace("RADIO| Basic Test");
    uint32_t count = 0;
    std::string sCmd("AT");
    do {
        std::string sResult = sendCommand(apIo, sCmd);
        if (sResult.find(RSP_OK) == std::string::npos) {
            printTrace("RADIO| Waiting for basic radio communication [%s] ...", sResult.c_str());
        } else {
            break;
        }
        count++;
    } while (count < timeoutSeconds);

    if(count == timeoutSeconds) {
        printWarning("RADIO| Basic radio communication FAILED");
        return NO_RESPONSE;
    }
    return SUCCESS;
}

std::string CellularRadio::extractModelFromResult(const std::string& sResult) {
    std::string sModel(CellularRadio::VALUE_NOT_SUPPORTED);
    if(sResult.find("HE910-D") != std::string::npos) {
        sModel = "HE910-D";
    } else if(sResult.find("HE910-EUD") != std::string::npos) {
        sModel = "HE910-EUD";
    } else if(sResult.find("LE910-NAG") != std::string::npos) {
        sModel = "LE910-NAG";
    } else if(sResult.find("LE910-SVG") != std::string::npos) {
        sModel = "LE910-SVG";
    } else if(sResult.find("LE910-EUG") != std::string::npos) {
        sModel = "LE910-EUG";
    } else if(sResult.find("GE910") != std::string::npos) {
        sModel = "GE910";
    } else if(sResult.find("DE910-DUAL") != std::string::npos) {
        sModel = "DE910-DUAL";
    } else if(sResult.find("CE910") != std::string::npos) {
        sModel = "CE910";
    }
    return sModel;
}

std::string CellularRadio::getCodeAsString(CODE eCode) {
    switch(eCode) {
        case SUCCESS:
            return "SUCCESS";
        case ERROR:
            return "ERROR";
        case FAILURE:
            return "FAILURE";
        case NO_RESPONSE:
            return "NO RESPONSE";
        default:
            return "UNKNOWN";
    }
}

bool CellularRadio::splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey,  Json::ValueType eType) {

    std::vector<std::string> vParts = MTS::Text::split(sLine, ":", 2);

    if(vParts.size() == 2 && vParts[0] == sKey) {
        if(eType == Json::ValueType::stringValue) {
            jParent[sJsonKey] = MTS::Text::trim(vParts[1]);
        } else if (eType == Json::ValueType::intValue || eType == Json::ValueType::uintValue) {
            //TODO:
            printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str());
            return false;
        } else if(eType == Json::ValueType::realValue) {
            //TODO:
            printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str());
            return false;
        } else if(eType == Json::ValueType::booleanValue) {
            //TODO:
            printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str());
            return false;
        } else {
            printWarning("%s| Unable to parse requested type from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str());
            return false;
        }
    } else {
        printWarning("%s| Unable to parse %s from line [%s]", getName().c_str(), sKey.c_str(), sLine.c_str());
        return false;
    }

    return true;
}

bool CellularRadio::getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier) {
    // Telit Radios
    //    H.ab.zyx => 3 Main Components
    //    "H" = Hardware -> 15 = DE910 family, 18 = CE910 family, 12 = HE910 family
    //    "a" = Hardware version
    //    "b" = Software Major Version
    //    "z" = is the product type, i.e. DUAL or SC
    //    "y" = is the carrier variant
    //    "x" = is the firmware version
    //    Telit will do their best to keep the carrier variant as "0" for Sprint, "1" for Aeris, and "2" for Verizon.

    const uint32_t CARRIER_INDEX = 1;   //y in [zyx]

    bool bResult = false;
    std::vector<std::string> vParts = MTS::Text::split(sFirmware, '.');

    if(vParts.size() == 3) {
        //CDMA firmware version notation
        if(vParts[0] == "15" || vParts[0] == "18") {
            //DE910 or CE910 -> Good good
            std::string sID = vParts[2];
            if(sID.size() == 3) {
                char cId = sID[CARRIER_INDEX];

                //Good good
                if(cId == '0') {
                    sCarrier = VALUE_CARRIER_SPRINT;
                    bResult = true;
                }
                if(cId == '1') {
                    sCarrier = VALUE_CARRIER_AERIS;
                    bResult = true;
                }
                if(cId == '2') {
                    sCarrier = VALUE_CARRIER_VERIZON;
                    bResult = true;
                }
            }
        }
    }

    return bResult;
}

bool CellularRadio::getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware) {
    // Telit Radios
    //    H.ab.zyx => 3 Main Components
    //    "H" = Hardware -> 15 = DE910 family, 18 = CE910 family, 12 = HE910 family
    //    "a" = Hardware version
    //    "b" = Software Major Version
    //    "z" = is the product type, i.e. DUAL or SC
    //    "y" = is the carrier variant
    //    "x" = is the firmware version
    //    Telit will do their best to keep the carrier variant as "0" for Sprint, "1" for Aeris, and "2" for Verizon.

    const uint32_t HARDWARE_INDEX = 0;   //a in [ab]

    bool bResult = false;
    std::vector<std::string> vParts = MTS::Text::split(sFirmware, '.');

    if(vParts.size() == 3) {
        //GSM Hardware Version
        if(!(vParts[0] == "15" || vParts[0] == "18")) {
            //Not DE910 or CE910 -> Good good
            std::string sVersion = vParts[1];
            if(sVersion.size() == 2) {
                sHardware = "1.";
                sHardware += sVersion[HARDWARE_INDEX];
                bResult = true;
            }
        }
    }

    return bResult;

}

const char *CellularRadio::RadioBandMap::getLTEBand(const int32_t channel)
{
    for (unsigned int ii = 0; ii < NUM_LTE_BANDS; ii++)
    {
    	if (EULTRAband[ii].low <= channel && EULTRAband[ii].high >= channel)
    	{
    		return EULTRAband[ii].name;
    	}
    }
    return VALUE_UNKNOWN.c_str();
}

const char *CellularRadio::RadioBandMap::getCDMABand(const int channel)
{
    for (unsigned int ii = 0; ii < NUM_WCDMA_BANDS; ii++)
    {
    	if (WCDMAband[ii].low <= channel && WCDMAband[ii].high >= channel)
    	{
    		return WCDMAband[ii].name;
    	}
    }
    return VALUE_UNKNOWN.c_str();
}

const char *CellularRadio::RadioBandMap::getGSMBand(const int channel)
{
    for (unsigned int ii = 0; ii < NUM_GSM_BANDS; ii++)
    {
    	if (GSMband[ii].low <= channel && GSMband[ii].high >= channel)
    	{
    		return GSMband[ii].name;
    	}
    }
    return VALUE_UNKNOWN.c_str();
}

const char *CellularRadio::RadioBandMap::getRadioBandName()
{
    const char *band = CellularRadio::VALUE_UNKNOWN.c_str();

    if (m_sRadioType == CellularRadio::VALUE_TYPE_LTE)
    {
        band = getLTEBand(m_iChannel);
    }
    else if (m_sRadioType == CellularRadio::VALUE_TYPE_CDMA)
    {
        band = getCDMABand(m_iChannel);
    }
    else if (m_sRadioType == CellularRadio::VALUE_TYPE_GSM)
    {
    	band = getGSMBand(m_iChannel);
    }

    return band;
}

const char *CellularRadio::RadioBandMap::getRadioBandName(const std::string &channel, const std::string &radioType)
{
	const char *band = CellularRadio::VALUE_UNKNOWN.c_str();
	int32_t chan = strtol(channel.c_str(), NULL, 10);
    if (radioType == CellularRadio::VALUE_TYPE_LTE)
    {
        band = getLTEBand(chan);
    }
    else if (radioType == CellularRadio::VALUE_TYPE_CDMA)
    {
        band = getCDMABand(chan);
    }
    else if (radioType == CellularRadio::VALUE_TYPE_GSM)
    {
    	band = getGSMBand(chan);
    }

	return band;
}