Skip to content

Commit 8ec31ea

Browse files
committed
Merge pull request #132 from mazgch/master
Detection of modem when using serial port, CDMA version of linkmonitor
2 parents 1eec522 + 6b9f207 commit 8ec31ea

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed

libraries/net/cellular/CellularModem/link/LinkMonitor.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,24 @@ using std::sscanf;
3333

3434
LinkMonitor::LinkMonitor(ATCommandsInterface* pIf) : m_pIf(pIf), m_rssi(0), m_registrationState(REGISTRATION_STATE_UNKNOWN), m_bearer(BEARER_UNKNOWN)
3535
{
36-
36+
m_gsm = true;
3737
}
3838

39-
int LinkMonitor::init()
39+
int LinkMonitor::init(bool gsm)
4040
{
41-
// we need to make sure that we setup the operator selection to be in 'numeric' format.
42-
// i.e. it is made up of a network and country code when returned by the modem e.g. Operator = 23415. This allows easy logic parsing for
43-
// setting up other network parameters in future.
44-
DBG("LinkMonitor::init() being called. This should only happen once: executinging AT+COPS=0,2");
45-
int ret = m_pIf->executeSimple("AT+COPS=0,2", NULL, DEFAULT_TIMEOUT); //Configure to set the operator string to Country Code and mobile network code
46-
if(ret != OK)
41+
m_gsm = gsm;
42+
if (m_gsm)
4743
{
48-
WARN(" NET_PROTOCOL error from sending the AT+COPS command to the modem. ");
49-
return NET_PROTOCOL;
44+
// we need to make sure that we setup the operator selection to be in 'numeric' format.
45+
// i.e. it is made up of a network and country code when returned by the modem e.g. Operator = 23415. This allows easy logic parsing for
46+
// setting up other network parameters in future.
47+
DBG("LinkMonitor::init() being called. This should only happen once: executinging AT+COPS=0,2");
48+
int ret = m_pIf->executeSimple("AT+COPS=0,2", NULL, DEFAULT_TIMEOUT); //Configure to set the operator string to Country Code and mobile network code
49+
if(ret != OK)
50+
{
51+
WARN(" NET_PROTOCOL error from sending the AT+COPS command to the modem. ");
52+
return NET_PROTOCOL;
53+
}
5054
}
5155
return OK;
5256
}
@@ -136,7 +140,7 @@ int LinkMonitor::getState(int* pRssi, REGISTRATION_STATE* pRegistrationState, BE
136140
m_rssi = 0;
137141
m_registrationState = REGISTRATION_STATE_UNKNOWN;
138142
m_bearer = BEARER_UNKNOWN;
139-
int ret = m_pIf->execute("AT+CREG?;+COPS?;+CSQ", this, NULL, DEFAULT_TIMEOUT); //Configure to get registration info & get it; get signal quality
143+
int ret = m_pIf->execute(m_gsm ? "AT+CREG?;+COPS?;+CSQ" : "AT+CREG?;+CSQ", this, NULL, DEFAULT_TIMEOUT); //Configure to get registration info & get it; get signal quality
140144
if(ret != OK)
141145
{
142146
return NET_PROTOCOL;

libraries/net/cellular/CellularModem/link/LinkMonitor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class LinkMonitor : protected IATCommandsProcessor
3939

4040
/** Initialize monitor
4141
*/
42-
int init();
42+
int init(bool gsm = true);
4343

4444
/** Registration State
4545
*/
@@ -82,6 +82,7 @@ class LinkMonitor : protected IATCommandsProcessor
8282
ATCommandsInterface* m_pIf;
8383

8484
int m_rssi;
85+
bool m_gsm;
8586
REGISTRATION_STATE m_registrationState;
8687
BEARER m_bearer;
8788

libraries/net/cellular/UbloxUSBModem/UbloxModem.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,36 @@ UbloxModem::UbloxModem(IOStream* atStream, IOStream* pppStream) :
4545
{
4646
}
4747

48+
49+
class AtiProcessor : public IATCommandsProcessor
50+
{
51+
public:
52+
AtiProcessor()
53+
{
54+
i = 0;
55+
str[0] = '\0';
56+
}
57+
const char* getInfo(void) { return str; }
58+
private:
59+
virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line)
60+
{
61+
int l = strlen(line);
62+
if (i + l + 2 > sizeof(str))
63+
return NET_OVERFLOW;
64+
if (i) str[i++] = ',';
65+
strcat(&str[i], line);
66+
i += l;
67+
return OK;
68+
}
69+
virtual int onNewEntryPrompt(ATCommandsInterface* pInst)
70+
{
71+
return OK;
72+
}
73+
protected:
74+
char str[256];
75+
int i;
76+
};
77+
4878
class CREGProcessor : public IATCommandsProcessor
4979
{
5080
public:
@@ -309,6 +339,22 @@ int UbloxModem::init()
309339
}
310340

311341
ATCommandsInterface::ATResult result;
342+
AtiProcessor atiProcessor;
343+
do
344+
{
345+
ret = m_at.execute("ATI", &atiProcessor, &result);
346+
}
347+
while (ret != OK);
348+
{
349+
const char* info = atiProcessor.getInfo();
350+
DBG("Modem Identification [%s]", info);
351+
if (strstr(info, "LISA-C200"))
352+
{
353+
m_gsm = false; // it is CDMA modem
354+
m_onePort = true; // force use of only one port
355+
}
356+
}
357+
312358
CREGProcessor cregProcessor(m_gsm);
313359
//Wait for network registration
314360
do
@@ -393,6 +439,7 @@ int UbloxModem::getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegis
393439
if(!m_linkMonitorInit)
394440
{
395441
ret = m_linkMonitor.init();
442+
ret = m_linkMonitor.init(m_gsm);
396443
if(ret)
397444
{
398445
return ret;

0 commit comments

Comments
 (0)