Skip to content

Commit df2a0e6

Browse files
committed
Adding sendCustomCommandWithResponse. Adding flow control. Making functionality public.
1 parent e8ed3d1 commit df2a0e6

3 files changed

+71
-48
lines changed

keywords.txt

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#######################################
88

99
SARA_R5 KEYWORD1
10+
SARA_R5_flow_control_t KEYWORD1
1011
mobile_network_operator_t KEYWORD1
1112
SARA_R5_error_t KEYWORD1
1213
SARA_R5_registration_status_t KEYWORD1
@@ -28,6 +29,7 @@ SARA_R5_http_content_types_t KEYWORD1
2829
SARA_R5_pdp_configuration_parameter_t KEYWORD1
2930
SARA_R5_pdp_protocol_type_t KEYWORD1
3031
SARA_R5_pdp_actions_t KEYWORD1
32+
SARA_R5_functionality_t KEYWORD1
3133
SARA_R5_pdp_type KEYWORD1
3234
SARA_R5_l2p_t KEYWORD1
3335
SARA_R5_gpio_t KEYWORD1
@@ -92,6 +94,7 @@ sendSMS KEYWORD2
9294
getPreferredMessageStorage KEYWORD2
9395
readSMSmessage KEYWORD2
9496
setBaud KEYWORD2
97+
setFlowControl KEYWORD2
9598
setGpioMode KEYWORD2
9699
getGpioMode KEYWORD2
97100
socketOpen KEYWORD2
@@ -135,11 +138,15 @@ gpsEnableSpeed KEYWORD2
135138
gpsGetSpeed KEYWORD2
136139
gpsRequest KEYWORD2
137140
getFileContents KEYWORD2
141+
functionality KEYWORD2
142+
sendCustomCommandWithResponse KEYWORD2
138143

139144
#######################################
140145
# Constants LITERAL1
141146
#######################################
142147

148+
SARA_R5_DISABLE_FLOW_CONTROL LITERAL1
149+
SARA_R5_ENABLE_FLOW_CONTROL LITERAL1
143150
MNO_INVALID LITERAL1
144151
MNO_SW_DEFAULT LITERAL1
145152
MNO_SIM_ICCID LITERAL1
@@ -263,6 +270,14 @@ SARA_R5_PSD_ACTION_STORE LITERAL1
263270
SARA_R5_PSD_ACTION_LOAD LITERAL1
264271
SARA_R5_PSD_ACTION_ACTIVATE LITERAL1
265272
SARA_R5_PSD_ACTION_DEACTIVATE LITERAL1
273+
MINIMUM_FUNCTIONALITY LITERAL1
274+
FULL_FUNCTIONALITY LITERAL1
275+
AIRPLANE_MODE LITERAL1
276+
SIM_TOOLKIT_ENABLE_DEDICATED LITERAL1
277+
SIM_TOOLKIT_DISABLE_DEDICATED LITERAL1
278+
SIM_TOOLKIT_ENABLE_RAW LITERAL1
279+
FAST_SAFE_POWER_OFF LITERAL1
280+
SILENT_RESET_WITH_SIM LITERAL1
266281
PDP_TYPE_INVALID LITERAL1
267282
PDP_TYPE_IP LITERAL1
268283
PDP_TYPE_NONIP LITERAL1

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

+25-31
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,24 @@ SARA_R5_error_t SARA_R5::setBaud(unsigned long baud)
18771877
return err;
18781878
}
18791879

1880+
SARA_R5_error_t SARA_R5::setFlowControl(SARA_R5_flow_control_t value)
1881+
{
1882+
SARA_R5_error_t err;
1883+
char *command;
1884+
1885+
command = sara_r5_calloc_char(strlen(SARA_R5_FLOW_CONTROL) + 3);
1886+
if (command == NULL)
1887+
return SARA_R5_ERROR_OUT_OF_MEMORY;
1888+
sprintf(command, "%s%d", SARA_R5_FLOW_CONTROL, value);
1889+
1890+
err = sendCommandWithResponse(command, SARA_R5_RESPONSE_OK,
1891+
NULL, SARA_R5_STANDARD_RESPONSE_TIMEOUT);
1892+
1893+
free(command);
1894+
1895+
return err;
1896+
}
1897+
18801898
SARA_R5_error_t SARA_R5::setGpioMode(SARA_R5_gpio_t gpio,
18811899
SARA_R5_gpio_mode_t mode)
18821900
{
@@ -3193,37 +3211,6 @@ SARA_R5_error_t SARA_R5::getMNOprofile(mobile_network_operator_t *mno)
31933211
return err;
31943212
}
31953213

3196-
/*SARA_R5_error_t SARA_R5::sendCommandWithResponseAndTimeout(const char * command,
3197-
char * expectedResponse, uint16_t commandTimeout, boolean at)
3198-
{
3199-
unsigned long timeIn = millis();
3200-
char * response;
3201-
3202-
sendCommand(command, at);
3203-
3204-
// Wait until we've receved the requested number of characters
3205-
while (hwAvailable() < strlen(expectedResponse))
3206-
{
3207-
if (millis() > timeIn + commandTimeout)
3208-
{
3209-
return SARA_R5_ERROR_TIMEOUT;
3210-
}
3211-
}
3212-
response = sara_r5_calloc_char(hwAvailable() + 1);
3213-
if (response == NULL)
3214-
{
3215-
return SARA_R5_ERROR_OUT_OF_MEMORY;
3216-
}
3217-
readAvailable(response);
3218-
3219-
// Check for expected response
3220-
if (strcmp(response, expectedResponse) == 0)
3221-
{
3222-
return SARA_R5_ERROR_SUCCESS;
3223-
}
3224-
return SARA_R5_ERROR_UNEXPECTED_RESPONSE;
3225-
}*/
3226-
32273214
SARA_R5_error_t SARA_R5::waitForResponse(const char *expectedResponse, const char *expectedError, uint16_t timeout)
32283215
{
32293216
unsigned long timeIn;
@@ -3343,6 +3330,13 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
33433330
}
33443331
}
33453332

3333+
// Send a custom command with an expected (potentially partial) response, store entire response
3334+
SARA_R5_error_t SARA_R5::sendCustomCommandWithResponse(const char *command, const char *expectedResponse,
3335+
char *responseDest, unsigned long commandTimeout, boolean at)
3336+
{
3337+
return sendCommandWithResponse(command, expectedResponse, responseDest, commandTimeout, at);
3338+
}
3339+
33463340
int SARA_R5::sendCommand(const char *command, boolean at)
33473341
{
33483342
int backlogIndex = strlen(saraResponseBacklog);

src/SparkFun_u-blox_SARA-R5_Arduino_Library.h

+31-17
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const char SARA_R5_NEW_MESSAGE_IND[] = "+CNMI"; // New [SMS] message indication
9898
const char SARA_R5_PREF_MESSAGE_STORE[] = "+CPMS"; // Preferred message storage
9999
const char SARA_R5_READ_TEXT_MESSAGE[] = "+CMGR"; // Read message
100100
// V24 control and V25ter (UART interface)
101+
const char SARA_R5_FLOW_CONTROL[] = "&K"; // Flow control
101102
const char SARA_R5_COMMAND_BAUD[] = "+IPR"; // Baud rate
102103
// ### Packet switched data services
103104
const char SARA_R5_MESSAGE_PDP_DEF[] = "+CGDCONT"; // Packet switched Data Profile context definition
@@ -162,6 +163,13 @@ const unsigned long SARA_R5_SUPPORTED_BAUD[NUM_SUPPORTED_BAUD] =
162163
230400};
163164
#define SARA_R5_DEFAULT_BAUD_RATE 115200
164165

166+
// Flow control definitions for AT&K
167+
// Note: SW (XON/XOFF) flow control is not supported on the SARA_R5
168+
typedef enum
169+
{
170+
SARA_R5_DISABLE_FLOW_CONTROL = 0,
171+
SARA_R5_ENABLE_FLOW_CONTROL = 3
172+
} SARA_R5_flow_control_t;
165173

166174
// The standard Europe profile should be used as the basis for all other MNOs in Europe outside of Vodafone
167175
// and Deutsche Telekom. However, there may be changes that need to be applied to the module for proper
@@ -394,6 +402,21 @@ typedef enum
394402
SARA_R5_PSD_ACTION_DEACTIVATE
395403
} SARA_R5_pdp_actions_t;
396404

405+
typedef enum
406+
{
407+
MINIMUM_FUNCTIONALITY = 0, // (disable both transmit and receive RF circuits by deactivating both CS and PS services)
408+
FULL_FUNCTIONALITY = 1,
409+
AIRPLANE_MODE = 4,
410+
SIM_TOOLKIT_ENABLE_DEDICATED = 6,
411+
SIM_TOOLKIT_DISABLE_DEDICATED = 7,
412+
SIM_TOOLKIT_ENABLE_RAW = 9,
413+
FAST_SAFE_POWER_OFF = 10,
414+
//SILENT_RESET_WITHOUT_SIM = 15, // Not supported on SARA-R5
415+
SILENT_RESET_WITH_SIM = 16
416+
//MINIMUM_FUNCTIONALITY = 19, // Not supported on SARA-R5
417+
//DEEP_LOW_POWER_STATE = 127 // Not supported on SARA-R5
418+
} SARA_R5_functionality_t;
419+
397420
class SARA_R5 : public Print
398421
{
399422
public:
@@ -514,6 +537,7 @@ class SARA_R5 : public Print
514537

515538
// V24 Control and V25ter (UART interface) AT commands
516539
SARA_R5_error_t setBaud(unsigned long baud);
540+
SARA_R5_error_t setFlowControl(SARA_R5_flow_control_t value = SARA_R5_ENABLE_FLOW_CONTROL);
517541

518542
// GPIO
519543
// GPIO pin map
@@ -649,6 +673,13 @@ class SARA_R5 : public Print
649673
// File system
650674
SARA_R5_error_t getFileContents(String filename, String *contents);
651675

676+
// Functionality
677+
SARA_R5_error_t functionality(SARA_R5_functionality_t function = FULL_FUNCTIONALITY);
678+
679+
// Send a custom command with an expected (potentially partial) response, store entire response
680+
SARA_R5_error_t sendCustomCommandWithResponse(const char *command, const char *expectedResponse,
681+
char *responseDest, unsigned long commandTimeout = SARA_R5_STANDARD_RESPONSE_TIMEOUT, boolean at = true);
682+
652683
private:
653684
HardwareSerial *_hardSerial;
654685
#ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED
@@ -683,29 +714,12 @@ class SARA_R5 : public Print
683714
SARA_R5_INIT_RESET
684715
} SARA_R5_init_type_t;
685716

686-
typedef enum
687-
{
688-
MINIMUM_FUNCTIONALITY = 0, // (disable both transmit and receive RF circuits by deactivating both CS and PS services)
689-
FULL_FUNCTIONALITY = 1,
690-
AIRPLANE_MODE = 4,
691-
SIM_TOOLKIT_ENABLE_DEDICATED = 6,
692-
SIM_TOOLKIT_DISABLE_DEDICATED = 7,
693-
SIM_TOOLKIT_ENABLE_RAW = 9,
694-
FAST_SAFE_POWER_OFF = 10,
695-
//SILENT_RESET_WITHOUT_SIM = 15, // Not supported on SARA-R5
696-
SILENT_RESET_WITH_SIM = 16
697-
//MINIMUM_FUNCTIONALITY = 19, // Not supported on SARA-R5
698-
//DEEP_LOW_POWER_STATE = 127 // Not supported on SARA-R5
699-
} SARA_R5_functionality_t;
700-
701717
SARA_R5_error_t init(unsigned long baud, SARA_R5_init_type_t initType = SARA_R5_INIT_STANDARD);
702718

703719
void powerOn(void);
704720

705721
void hwReset(void);
706722

707-
SARA_R5_error_t functionality(SARA_R5_functionality_t function = FULL_FUNCTIONALITY);
708-
709723
SARA_R5_error_t setMNOprofile(mobile_network_operator_t mno, boolean autoReset = false, boolean urcNotification = false);
710724
SARA_R5_error_t getMNOprofile(mobile_network_operator_t *mno);
711725

0 commit comments

Comments
 (0)