Skip to content

Commit d0d4476

Browse files
committed
adding support for serial port
1 parent a3a16b3 commit d0d4476

15 files changed

+1021
-58
lines changed

libraries/net/cellular/CellularModem/at/ATCommandsInterface.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,33 @@ int ATCommandsInterface::open()
6363
}
6464

6565
//Initialize AT link & start events processing
66-
int ATCommandsInterface::init()
66+
int ATCommandsInterface::init(bool reset /* = true*/)
6767
{
68-
DBG("Sending ATZ E1 V1");
6968

7069
//Lock transaction mutex
7170
m_transactionMtx.lock();
7271

73-
//Should we flush m_pStream at this point ???
74-
int err;
75-
int tries = 5;
76-
do
72+
if (reset)
7773
{
78-
err = executeInternal("ATZ E1 V1", this, NULL, 3000); //Enable echo and verbosity
79-
if(err && tries)
74+
DBG("Sending ATZ E1 V1");
75+
//Should we flush m_pStream at this point ???
76+
int err;
77+
int tries = 5;
78+
do
79+
{
80+
err = executeInternal("ATZ E1 V1", this, NULL, 3000); //Enable echo and verbosity
81+
if(err && tries)
82+
{
83+
WARN("No response, trying again");
84+
Thread::wait(1000); //Give dongle time to recover
85+
}
86+
} while(err && tries--);
87+
if( err )
8088
{
81-
WARN("No response, trying again");
82-
Thread::wait(1000); //Give dongle time to recover
89+
ERR("Sending ATZ E1 V1 returned with err code %d", err);
90+
m_transactionMtx.unlock();
91+
return err;
8392
}
84-
} while(err && tries--);
85-
if( err )
86-
{
87-
ERR("Sending ATZ E1 V1 returned with err code %d", err);
88-
m_transactionMtx.unlock();
89-
return err;
9093
}
9194

9295
//Enable events handling and execute events enabling commands

libraries/net/cellular/CellularModem/at/ATCommandsInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class ATCommandsInterface : protected IATCommandsProcessor
7777
int open();
7878

7979
//Initialize AT link
80-
int init();
80+
int init(bool reset = true);
8181

8282
//Close connection
8383
int close();

libraries/net/cellular/CellularModem/ip/PPPIPInterface.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,15 @@ extern "C" {
5050
#include "netif/ppp/ppp.h"
5151
}
5252

53-
PPPIPInterface::PPPIPInterface(IOStream* pStream, const char* msisdn) : LwIPInterface(), m_linkStatusSphre(1), m_pppErrCode(0), m_pStream(pStream), m_streamAvail(true), m_pppd(-1)
53+
PPPIPInterface::PPPIPInterface(IOStream* pStream) : LwIPInterface(), m_linkStatusSphre(1), m_pppErrCode(0), m_pStream(pStream), m_streamAvail(true), m_pppd(-1)
5454
{
55-
m_connectCmd = new char[strlen(CONNECT_CMD_PREFIX) + strlen(msisdn) + strlen(CONNECT_CMD_SUFFIX) + 1];
56-
sprintf(m_connectCmd, "%s%s%s", CONNECT_CMD_PREFIX, msisdn, CONNECT_CMD_SUFFIX);
57-
m_expectedResp = new char[strlen(m_connectCmd) + strlen(EXPECTED_RESP_SUFFIX) + 1];
58-
sprintf(m_expectedResp, "%s%s", m_connectCmd, EXPECTED_RESP_SUFFIX);
59-
m_expectedRespDatarate = new char[strlen(m_connectCmd) + strlen(EXPECTED_RESP_DATARATE_SUFFIX) + 1];
60-
sprintf(m_expectedRespDatarate, "%s%s", m_connectCmd, EXPECTED_RESP_DATARATE_SUFFIX);
6155
m_linkStatusSphre.wait();
6256
}
6357

58+
59+
6460
/*virtual*/ PPPIPInterface::~PPPIPInterface()
6561
{
66-
delete m_connectCmd;
67-
delete m_expectedResp;
68-
delete m_expectedRespDatarate;
6962
}
7063

7164
/*virtual*/ int PPPIPInterface::init() //Init PPP-specific stuff, create the right bindings, etc
@@ -78,33 +71,34 @@ PPPIPInterface::PPPIPInterface(IOStream* pStream, const char* msisdn) : LwIPInte
7871
return OK;
7972
}
8073

81-
int PPPIPInterface::setup(const char* user, const char* pw)
74+
int PPPIPInterface::setup(const char* user, const char* pw, const char* msisdn)
8275
{
8376
DBG("Configuring PPP authentication method");
8477
pppSetAuth(PPPAUTHTYPE_ANY, user, pw);
78+
m_msisdn = msisdn;
8579
DBG("Done");
8680
return OK;
8781
}
8882

8983
/*virtual*/ int PPPIPInterface::connect()
9084
{
9185
int ret;
86+
char cmd[32];
87+
int cmdLen;
9288
char buf[32];
9389
size_t len;
9490
DBG("Trying to connect with PPP");
9591

9692
cleanupLink();
9793

98-
DBG("Sending %s", m_connectCmd);
99-
100-
ret = m_pStream->write((uint8_t*)m_connectCmd, strlen(m_connectCmd), osWaitForever);
94+
cmdLen = sprintf(cmd, "%s%s%s", CONNECT_CMD_PREFIX, m_msisdn, CONNECT_CMD_SUFFIX);
95+
DBG("Sending %s", cmd);
96+
ret = m_pStream->write((uint8_t*)cmd, cmdLen, osWaitForever);
10197
if( ret != OK )
10298
{
10399
return NET_UNKNOWN;
104100
}
105101

106-
DBG("Expect %s", m_expectedResp);
107-
108102
len = 0;
109103
size_t readLen;
110104
ret = m_pStream->read((uint8_t*)buf + len, &readLen, EXPECTED_RESP_MIN_LEN, 10000);
@@ -128,16 +122,21 @@ int PPPIPInterface::setup(const char* user, const char* pw)
128122
DBG("Got %s[len %d]", buf, len);
129123

130124
int datarate = 0;
131-
if( (sscanf(buf, m_expectedRespDatarate, &datarate ) != 1) && (strcmp(m_expectedResp, buf) != 0) )
125+
strcpy(&cmd[cmdLen], EXPECTED_RESP_DATARATE_SUFFIX);
126+
if( (sscanf(buf, cmd, &datarate ) != 1))
132127
{
133-
//Discard buffer
134-
do //Clear buf
128+
strcpy(&cmd[cmdLen], EXPECTED_RESP_SUFFIX);
129+
if (strcmp(cmd, buf) != 0)
135130
{
136-
ret = m_pStream->read((uint8_t*)buf, &len, 32, 0);
137-
} while( (ret == OK) && (len > 0) );
138-
return NET_CONN;
139-
}
140-
131+
//Discard buffer
132+
do //Clear buf
133+
{
134+
ret = m_pStream->read((uint8_t*)buf, &len, 32, 0);
135+
} while( (ret == OK) && (len > 0) );
136+
return NET_CONN;
137+
}
138+
}
139+
141140
DBG("Transport link open");
142141
if(datarate != 0)
143142
{

libraries/net/cellular/CellularModem/ip/PPPIPInterface.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ using namespace rtos;
4040
class PPPIPInterface : public LwIPInterface
4141
{
4242
public:
43-
PPPIPInterface(IOStream* pStream, const char* msisdn);
43+
PPPIPInterface(IOStream* pStream);
4444
virtual ~PPPIPInterface();
4545

4646
int init(); //Init PPP-specific stuff, create the right bindings, etc
47-
int setup(const char* user, const char* pw); //Setup authentication
47+
int setup(const char* user, const char* pw, const char* msisdn); //Setup authentication
4848
virtual int connect();
4949
virtual int disconnect();
5050

@@ -57,16 +57,13 @@ class PPPIPInterface : public LwIPInterface
5757

5858
IOStream* m_pStream; //Serial stream
5959
bool m_streamAvail;
60+
const char* m_msisdn;
6061

6162
int m_pppd;
6263

6364
friend u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len);
6465
friend u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len);
6566
friend void sio_read_abort(sio_fd_t fd);
66-
67-
char* m_connectCmd;
68-
char* m_expectedResp;
69-
char* m_expectedRespDatarate;
7067
};
7168

7269
#endif /* PPPIPINTERFACE_H_ */

0 commit comments

Comments
 (0)