@@ -100,6 +100,18 @@ void GEMALTO_CINTERION_CellularStack::urc_sisr()
100100 sisr_urc_handler (sock_id, urc_code);
101101}
102102
103+ void GEMALTO_CINTERION_CellularStack::urc_sysstart ()
104+ {
105+ // close sockets if open
106+ _at.lock ();
107+ for (int i = 0 ; i < _device.get_property (AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
108+ _at.clear_error ();
109+ socket_close_impl (i);
110+ }
111+ _at.clear_error ();
112+ _at.unlock ();
113+ }
114+
103115void GEMALTO_CINTERION_CellularStack::sisr_urc_handler (int sock_id, int urc_code)
104116{
105117 CellularSocket *sock = find_socket (sock_id);
@@ -113,6 +125,86 @@ void GEMALTO_CINTERION_CellularStack::sisr_urc_handler(int sock_id, int urc_code
113125 }
114126}
115127
128+ void GEMALTO_CINTERION_CellularStack::urc_gnss () {
129+ char gnss_string[100 ] = {' $' , ' G' };
130+ if (_gnss_cb) {
131+ _at.set_delimiter (' \n ' );
132+ _at.read_string (&gnss_string[2 ], 98 );
133+ _at.set_default_delimiter ();
134+ _gnss_cb (gnss_string);
135+ }
136+ }
137+
138+ void GEMALTO_CINTERION_CellularStack::beginGNSS (mbed::Callback<void (char *)> gnss_cb) {
139+ _at.lock ();
140+ _gnss_cb = gnss_cb;
141+ _at.at_cmd_discard (" ^SGPSC" , " =" , " %s%d" , " Engine/StartMode" , 0 );
142+ _at.at_cmd_discard (" ^SGPSC" , " =" , " %s%d" , " Engine" , 0 );
143+ _at.at_cmd_discard (" ^SGPSC" , " =" , " %s%s" , " Nmea/Urc" , " off" );
144+
145+ // Set up LNA_ENABLE GPIO
146+ _at.at_cmd_discard (" ^SPIO" , " =" , " %d" , 1 );
147+ _at.at_cmd_discard (" ^SCPIN" , " =" , " %d%d%d%d" , 1 , 7 , 1 , 0 );
148+ _at.clear_error ();
149+ _at.unlock ();
150+ }
151+
152+ void GEMALTO_CINTERION_CellularStack::endGNSS () {
153+ _at.lock ();
154+ _at.at_cmd_discard (" ^SSIO" , " =" , " %d%d" , 7 , 0 );
155+ _gnss_cb = nullptr ;
156+ _at.clear_error ();
157+ _at.unlock ();
158+ }
159+
160+ void GEMALTO_CINTERION_CellularStack::enableCmux ()
161+ {
162+ _at.at_cmd_discard (" +CMUX" , " =0" );
163+ }
164+
165+ int GEMALTO_CINTERION_CellularStack::startGNSS () {
166+ _at.lock ();
167+ _engine = false ;
168+ _at.at_cmd_discard (" ^SSIO" , " =" , " %d%d" , 7 , 1 );
169+ _at.cmd_start_stop (" ^SGPSC" , " =" , " %s%d" , " Engine" , 3 );
170+ _at.resp_start (" ^SGPSC: \" Engine\" ," );
171+
172+ char respEng[2 ];
173+ int resp_len = _at.read_string (respEng, sizeof (respEng));
174+ if (strcmp (respEng, " 3" ) != 0 ) {
175+ _engine = false ;
176+ _at.at_cmd_discard (" ^SGPSC" , " =" , " %s%d" , " Engine" , 0 );
177+ _at.at_cmd_discard (" ^SGPSC" , " =" , " %s%s" , " Nmea/Urc" , " off" );
178+ return 0 ;
179+ }
180+ _engine = true ;
181+ _at.at_cmd_discard (" ^SGPSC" , " =" , " %s%s" , " Nmea/Urc" , " on" );
182+ _at.clear_error ();
183+ _at.unlock ();
184+
185+ return 1 ;
186+ }
187+
188+ void GEMALTO_CINTERION_CellularStack::stopGNSS () {
189+ if (_engine) {
190+ _at.lock ();
191+ _at.at_cmd_discard (" ^SGPSC" , " =" , " %s%s" , " Nmea/Urc" , " off" );
192+ _at.at_cmd_discard (" ^SGPSC" , " =" , " %s%d" , " Engine" , 0 );
193+ _at.clear_error ();
194+ _at.unlock ();
195+ _engine = false ;
196+ }
197+ }
198+
199+ void GEMALTO_CINTERION_CellularStack::setGNSS_PSM (bool const enable) {
200+ if (_engine) {
201+ _at.lock ();
202+ _at.at_cmd_discard (" ^SGPSC" , " =" , " %s%d" , " Power/Psm" , enable);
203+ _at.clear_error ();
204+ _at.unlock ();
205+ }
206+ }
207+
116208nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_stack_init ()
117209{
118210 _at.lock ();
@@ -121,6 +213,9 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_stack_init()
121213 _at.set_urc_handler (" ^SIS:" , mbed::Callback<void ()>(this , &GEMALTO_CINTERION_CellularStack::urc_sis));
122214 _at.set_urc_handler (" ^SISW:" , mbed::Callback<void ()>(this , &GEMALTO_CINTERION_CellularStack::urc_sisw));
123215 _at.set_urc_handler (" ^SISR:" , mbed::Callback<void ()>(this , &GEMALTO_CINTERION_CellularStack::urc_sisr));
216+ _at.set_urc_handler (" ^SYSSTART" , mbed::Callback<void ()>(this , &GEMALTO_CINTERION_CellularStack::urc_sysstart));
217+ _at.set_urc_handler (" ^SGPSE" , mbed::Callback<void ()>(this , &GEMALTO_CINTERION_CellularStack::urc_gnss));
218+ _at.set_urc_handler (" $G" , mbed::Callback<void ()>(this , &GEMALTO_CINTERION_CellularStack::urc_gnss));
124219 } else { // recovery cleanup
125220 // close all Internet and connection profiles
126221 for (int i = 0 ; i < _device.get_property (AT_CellularDevice::PROPERTY_SOCKET_COUNT); i++) {
@@ -172,7 +267,7 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::gethostbyname(const char *host, S
172267 _at.resp_start (" ^SISX: \" HostByName\" ," );
173268 char ipAddress[NSAPI_IP_SIZE];
174269 int size = _at.read_string (ipAddress, sizeof (ipAddress));
175- if (size) {
270+ if (size > 0 ) {
176271 // Valid string received
177272 tr_info (" Read %d bytes. Valid string: %s\n " , size, ipAddress);
178273 _at.restore_at_timeout ();
@@ -200,10 +295,6 @@ nsapi_error_t GEMALTO_CINTERION_CellularStack::socket_open_defer(CellularSocket
200295 bool foundSrvType = false ;
201296 bool foundConIdType = false ;
202297
203- if (GEMALTO_CINTERION::get_module () == GEMALTO_CINTERION::ModuleTX62) {
204- _at.cmd_start_stop (" ^SICA" , " =" , " %d%d" , 1 , _cid);
205- }
206-
207298 _at.cmd_start_stop (" ^SISS" , " ?" );
208299 _at.resp_start (" ^SISS:" );
209300 /*
@@ -438,6 +529,7 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
438529 size = UDP_PACKET_SIZE;
439530 }
440531
532+ tr_info (" requesting %d bytes\n " , size);
441533 _at.cmd_start_stop (" ^SISR" , " =" , " %d%d" , socket->id , size);
442534
443535sisr_retry:
@@ -467,26 +559,62 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell
467559 }
468560 if (len == -1 ) {
469561 if (GEMALTO_CINTERION::get_module () == GEMALTO_CINTERION::ModuleTX62 && _at.get_last_read_error () == -2 ) {
562+ _at.process_oob ();
470563 tr_error (" Socket %d recvfrom finished!" , socket->id );
471564 socket->pending_bytes = 0 ;
472565 return NSAPI_ERROR_OK;
473566 }
474567 tr_error (" Socket %d recvfrom failed!" , socket->id );
475568 return NSAPI_ERROR_DEVICE_ERROR;
476569 }
477- socket->pending_bytes = 1 ;
478570 if (len >= (nsapi_size_or_error_t )size) {
479571 len = (nsapi_size_or_error_t )size;
480572 }
481573
482574 // UDP Udp_RemClient
483575 if (socket->proto == NSAPI_UDP && GEMALTO_CINTERION::get_module () != GEMALTO_CINTERION::ModuleBGS2) {
484- char ip_address[NSAPI_IPv6_SIZE + sizeof (" []:12345" ) - 1 + 1 ];
485- int ip_len = _at.read_string (ip_address, sizeof (ip_address));
486- if (ip_len <= 0 ) {
487- tr_error (" Socket %d recvfrom addr (len %d)" , socket->id , ip_len);
488- return NSAPI_ERROR_DEVICE_ERROR;
489- }
576+ size_t ip_address_len = NSAPI_IPv6_SIZE + sizeof (" []:12345" ) - 1 + 1 ;
577+ char ip_address[ip_address_len];
578+
579+ if (GEMALTO_CINTERION::get_module () == GEMALTO_CINTERION::ModuleTX62) {
580+ // Local buffer for parsing Udp_RemClient for TX62
581+ uint8_t at_buf[ip_address_len];
582+ size_t ip_len = 0 ;
583+
584+ // Skip <remainUdpPacketLength>
585+ nsapi_size_or_error_t rem_len = _at.read_int ();
586+
587+ // Wait for full <Udp_RemClient> in the _at buffer
588+ do {
589+ int len = _at.read_bytes (at_buf + ip_len, 1 );
590+ if (len <= 0 ) {
591+ tr_error (" Socket %d recvfrom addr (len %d)" , socket->id , ip_len);
592+ return NSAPI_ERROR_DEVICE_ERROR;
593+ }
594+ ip_len += len;
595+ } while (ip_len < ip_address_len && at_buf[ip_len - 2 ] != ' \r ' && at_buf[ip_len - 1 ] != ' \n ' );
596+
597+ // if (ip_len < sizeof("0.0.0.0:0")) {
598+ if (ip_len < sizeof (" []:0" )) {
599+ tr_error (" Socket %d has no address" , socket->id );
600+ goto sisr_retry;
601+ }
602+
603+ // at_buf contains remote client IP information
604+ // in the format "<ip address>:<port>"\r\n.
605+
606+ // Terminate the C string at the closing quotation mark
607+ at_buf[ip_len - 3 ] = ' \0 ' ;
608+ // Skip the opening quotation mark
609+ memcpy (ip_address, at_buf + 1 , ip_len - 4 );
610+ tr_info (" ip_address %s (%d)" , ip_address, ip_len - 4 );
611+ } else {
612+ int ip_len = _at.read_string (ip_address, sizeof (ip_address));
613+ if (ip_len <= 0 ) {
614+ tr_error (" Socket %d recvfrom addr (len %d)" , socket->id , ip_len);
615+ return NSAPI_ERROR_DEVICE_ERROR;
616+ }
617+ }
490618 if (address) {
491619 char *ip_start = ip_address;
492620 char *ip_stop;
0 commit comments