Skip to content

Commit 8fee7e3

Browse files
committed
Remove redundant code from poll
1 parent 01487c3 commit 8fee7e3

File tree

2 files changed

+11
-260
lines changed

2 files changed

+11
-260
lines changed

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

Lines changed: 0 additions & 260 deletions
Original file line numberDiff line numberDiff line change
@@ -448,266 +448,6 @@ bool SARA_R5::poll(void)
448448
// Now search for all supported URC's
449449
handled = processURCEvent(saraRXBuffer);
450450

451-
/*
452-
{
453-
int socket, length;
454-
if (sscanf(saraRXBuffer, "+UUSORD: %d,%d", &socket, &length) == 2)
455-
{
456-
parseSocketReadIndication(socket, length);
457-
handled = true;
458-
}
459-
}
460-
{
461-
int socket, length;
462-
int ret = sscanf(saraRXBuffer, "+UUSORF: %d,%d", &socket, &length);
463-
if (ret == 2)
464-
{
465-
parseSocketReadIndicationUDP(socket, length);
466-
handled = true;
467-
}
468-
}
469-
{
470-
int socket = 0;
471-
int listenSocket = 0;
472-
unsigned int port = 0;
473-
unsigned int listenPort = 0;
474-
IPAddress remoteIP = {0,0,0,0};
475-
IPAddress localIP = {0,0,0,0};
476-
int remoteIPstore[4] = {0,0,0,0};
477-
int localIPstore[4] = {0,0,0,0};
478-
479-
int ret = sscanf(saraRXBuffer,
480-
"+UUSOLI: %d,\"%d.%d.%d.%d\",%u,%d,\"%d.%d.%d.%d\",%u",
481-
&socket,
482-
&remoteIPstore[0], &remoteIPstore[1], &remoteIPstore[2], &remoteIPstore[3],
483-
&port, &listenSocket,
484-
&localIPstore[0], &localIPstore[1], &localIPstore[2], &localIPstore[3],
485-
&listenPort);
486-
for (int i = 0; i <= 3; i++)
487-
{
488-
remoteIP[i] = (uint8_t)remoteIPstore[i];
489-
localIP[i] = (uint8_t)localIPstore[i];
490-
}
491-
if (ret > 4)
492-
{
493-
parseSocketListenIndication(listenSocket, localIP, listenPort, socket, remoteIP, port);
494-
handled = true;
495-
}
496-
}
497-
{
498-
int socket;
499-
500-
if (sscanf(saraRXBuffer,
501-
"+UUSOCL: %d", &socket) == 1)
502-
{
503-
if ((socket >= 0) && (socket <= 6))
504-
{
505-
if (_socketCloseCallback != NULL)
506-
{
507-
_socketCloseCallback(socket);
508-
}
509-
}
510-
handled = true;
511-
}
512-
}
513-
{
514-
ClockData clck;
515-
PositionData gps;
516-
SpeedData spd;
517-
unsigned long uncertainty;
518-
int scanNum;
519-
int latH, lonH, alt;
520-
unsigned int speedU, cogU;
521-
char latL[10], lonL[10];
522-
523-
// Maybe we should also scan for +UUGIND and extract the activated gnss system?
524-
525-
if (strstr(saraRXBuffer, "+UULOC"))
526-
{
527-
// Found a Location string!
528-
if (_printDebug == true)
529-
{
530-
_debugPort->print(F("poll +UULOC: saraRXBuffer: "));
531-
_debugPort->println(saraRXBuffer);
532-
}
533-
534-
// This assumes the ULOC response type is "0" or "1" - as selected by gpsRequest detailed
535-
int dateStore[5];
536-
scanNum = sscanf(saraRXBuffer,
537-
"+UULOC: %d/%d/%d,%d:%d:%d.%d,%d.%[^,],%d.%[^,],%d,%lu,%u,%u,%*s",
538-
&dateStore[0], &dateStore[1], &clck.date.year,
539-
&dateStore[2], &dateStore[3], &dateStore[4], &clck.time.ms,
540-
&latH, latL, &lonH, lonL, &alt, &uncertainty,
541-
&speedU, &cogU);
542-
clck.date.day = dateStore[0];
543-
clck.date.month = dateStore[1];
544-
clck.time.hour = dateStore[2];
545-
clck.time.minute = dateStore[3];
546-
clck.time.second = dateStore[4];
547-
if (scanNum < 13)
548-
return false; // Break out if we didn't find enough
549-
550-
if (latH >= 0)
551-
gps.lat = (float)latH + ((float)atol(latL) / pow(10, strlen(latL)));
552-
else
553-
gps.lat = (float)latH - ((float)atol(latL) / pow(10, strlen(latL)));
554-
if (lonH >= 0)
555-
gps.lon = (float)lonH + ((float)atol(lonL) / pow(10, strlen(lonL)));
556-
else
557-
gps.lon = (float)lonH - ((float)atol(lonL) / pow(10, strlen(lonL)));
558-
gps.alt = (float)alt;
559-
if (scanNum >= 15) // If detailed response, get speed data
560-
{
561-
spd.speed = (float)speedU;
562-
spd.cog = (float)cogU;
563-
}
564-
565-
if (_printDebug == true)
566-
{
567-
_debugPort->print(F("poll +UULOC: lat: "));
568-
_debugPort->print(gps.lat, 7);
569-
_debugPort->print(F(" lon: "));
570-
_debugPort->print(gps.lon, 7);
571-
_debugPort->print(F(" alt: "));
572-
_debugPort->print(gps.alt, 2);
573-
_debugPort->print(F(" speed: "));
574-
_debugPort->print(spd.speed, 2);
575-
_debugPort->print(F(" cog: "));
576-
_debugPort->println(spd.cog, 2);
577-
}
578-
579-
if (_gpsRequestCallback != NULL)
580-
{
581-
_gpsRequestCallback(clck, gps, spd, uncertainty);
582-
}
583-
584-
handled = true;
585-
}
586-
}
587-
{
588-
SARA_R5_sim_states_t state;
589-
int scanNum;
590-
591-
if (strstr(saraRXBuffer, "+UUSIMSTAT"))
592-
{
593-
int stateStore;
594-
scanNum = sscanf(saraRXBuffer, "+UUSIMSTAT:%d", &stateStore);
595-
state = (SARA_R5_sim_states_t)stateStore;
596-
if (scanNum < 1)
597-
return false; // Break out if we didn't find enough
598-
599-
if (_simStateReportCallback != NULL)
600-
{
601-
_simStateReportCallback(state);
602-
}
603-
604-
handled = true;
605-
}
606-
}
607-
{
608-
int result;
609-
IPAddress remoteIP = {0, 0, 0, 0};
610-
int scanNum;
611-
612-
if (strstr(saraRXBuffer, "+UUPSDA"))
613-
{
614-
int remoteIPstore[4];
615-
scanNum = sscanf(saraRXBuffer, "+UUPSDA: %d,\"%d.%d.%d.%d\"",
616-
&result, &remoteIPstore[0], &remoteIPstore[1], &remoteIPstore[2], &remoteIPstore[3]);
617-
for (int i = 0; i <= 3; i++)
618-
{
619-
remoteIP[i] = (uint8_t)remoteIPstore[i];
620-
}
621-
if (scanNum < 1)
622-
return false; // Break out if we didn't find enough
623-
624-
if (_psdActionRequestCallback != NULL)
625-
{
626-
_psdActionRequestCallback(result, remoteIP);
627-
}
628-
629-
handled = true;
630-
}
631-
}
632-
{
633-
int retry = 0;
634-
int p_size = 0;
635-
int ttl = 0;
636-
String remote_host = "";
637-
IPAddress remoteIP = {0, 0, 0, 0};
638-
long rtt = 0;
639-
int scanNum;
640-
char *searchPtr = saraRXBuffer;
641-
642-
// Find the first/next occurrence of +UUPING:
643-
searchPtr = strstr(searchPtr, "+UUPING: ");
644-
if (searchPtr != NULL)
645-
{
646-
//if (_printDebug == true)
647-
//{
648-
// _debugPort->print(F("poll +UUPING: saraRXBuffer: "));
649-
// _debugPort->println(saraRXBuffer);
650-
//}
651-
652-
// Extract the retries and payload size
653-
scanNum = sscanf(searchPtr, "+UUPING: %d,%d,", &retry, &p_size);
654-
655-
if (scanNum < 2)
656-
return false; // Break out if we didn't find enough
657-
658-
searchPtr = strchr(++searchPtr, '\"'); // Search to the first quote
659-
660-
// Extract the remote host name, stop at the next quote
661-
while ((*(++searchPtr) != '\"') && (*searchPtr != '\0'))
662-
{
663-
remote_host.concat(*(searchPtr));
664-
}
665-
666-
if (*searchPtr == '\0')
667-
return false; // Break out if we didn't find enough
668-
669-
int remoteIPstore[4];
670-
scanNum = sscanf(searchPtr, "\",\"%d.%d.%d.%d\",%d,%ld",
671-
&remoteIPstore[0], &remoteIPstore[1], &remoteIPstore[2], &remoteIPstore[3], &ttl, &rtt);
672-
for (int i = 0; i <= 3; i++)
673-
{
674-
remoteIP[i] = (uint8_t)remoteIPstore[i];
675-
}
676-
677-
if (scanNum < 6)
678-
return false; // Break out if we didn't find enough
679-
680-
if (_pingRequestCallback != NULL)
681-
{
682-
_pingRequestCallback(retry, p_size, remote_host, remoteIP, ttl, rtt);
683-
}
684-
685-
handled = true;
686-
}
687-
}
688-
{
689-
int profile, command, result;
690-
int scanNum;
691-
692-
if (strstr(saraRXBuffer, "+UUHTTPCR"))
693-
{
694-
scanNum = sscanf(saraRXBuffer, "+UUHTTPCR: %d,%d,%d", &profile, &command, &result);
695-
if (scanNum < 3)
696-
return false; // Break out if we didn't find enough
697-
698-
if ((profile >= 0) && (profile < SARA_R5_NUM_HTTP_PROFILES))
699-
{
700-
if (_httpCommandRequestCallback != NULL)
701-
{
702-
_httpCommandRequestCallback(profile, command, result);
703-
}
704-
}
705-
706-
handled = true;
707-
}
708-
}
709-
*/
710-
711451
if ((handled == false) && (strlen(saraRXBuffer) > 2))
712452
{
713453
if (_printDebug == true)

src/SparkFun_u-blox_SARA-R5_Arduino_Library.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,19 @@ class SARA_R5 : public Print
473473
void modulePowerOn(void); // Requires access to the PWR_ON pin
474474

475475
// Loop polling and polling setup
476+
477+
// This function was originally written by Matthew Menze for the LTE Shield (SARA-R4) library
478+
// See: https://github.com/sparkfun/SparkFun_LTE_Shield_Arduino_Library/pull/8
479+
// It does the same job as ::poll but also processed any 'old' data stored in the backlog first
480+
// It also has a built-in timeout - which ::poll does not
476481
bool bufferedPoll(void);
482+
483+
// This is the original poll function.
484+
// It is 'blocking' - it does not return when serial data is available until it receives a `\n`.
485+
// ::bufferedPoll is the new improved version. It processes any data in the backlog and includes a timeout.
477486
bool poll(void);
487+
488+
// Callbacks (called during polling)
478489
void setSocketListenCallback(void (*socketListenCallback)(int, IPAddress, unsigned int, int, IPAddress, unsigned int));
479490
void setSocketReadCallback(void (*socketReadCallback)(int, String));
480491
void setSocketCloseCallback(void (*socketCloseCallback)(int));

0 commit comments

Comments
 (0)