RockBLOCK 9704 C Library
Doxygen documentation for the RockBLOCK 9704 C Library.
rockblock_9704.h
Go to the documentation of this file.
1 #ifndef ROCKBLOCK_9704_H
2 #define ROCKBLOCK_9704_H
3 
10 #if defined(__linux__) || defined(__APPLE__)
11  #include "serial_presets/serial_linux/serial_linux.h"
12 #elif defined(_WIN32)
13  #include "serial_presets/serial_windows/serial_windows.h"
14 #elif defined(ARDUINO) && defined(__cplusplus)
15  #include "serial_presets/serial_arduino/serial_arduino.h"
16 #endif
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include "serial.h"
23 #include "jspr.h"
24 #include <stdio.h>
25 #include <stdint.h>
26 #include <stdbool.h>
27 #include <string.h>
28 #include <stddef.h>
29 
37 typedef enum
38 {
43 
49 
57 typedef struct
58 {
64  void (*messageProvisioning)(const jsprMessageProvisioning_t *messageProvisioning);
65 
73  void (*moMessageComplete)(const uint16_t id, const rbMsgStatus_t status);
74 
82  void (*mtMessageComplete)(const uint16_t id, const rbMsgStatus_t status);
83 
89  void (*constellationState)(const jsprConstellationState_t *state);
90 
96  void (*moMessageStarted)(const uint16_t id);
98 
107 void rbRegisterCallbacks(const rbCallbacks_t *callbacks);
108 
112 #define BASE64_TEMP_BUFFER 2048U
113 
119 #define RB9704_BAUD 230400U
120 
139 #ifndef SERIAL_CONTEXT_SETUP_FUNC
140  #ifdef __linux__
141  #define SERIAL_CONTEXT_SETUP_FUNC setContextLinux
142  #elif __APPLE__
143  #define SERIAL_CONTEXT_SETUP_FUNC setContextLinux
144  #elif _WIN32
145  #define SERIAL_CONTEXT_SETUP_FUNC setContextWindows
146  #elif ARDUINO
147  #define SERIAL_CONTEXT_SETUP_FUNC setContextArduino
148  #endif
149 #endif
150 
157 typedef enum
158 {
160  RAW_TOPIC = 244,
161 
164 
166  PINK_TOPIC = 314,
167 
169  RED_TOPIC = 315,
170 
173 
175  YELLOW_TOPIC = 317
177 
178 
179 #if defined(ARDUINO) && defined(__cplusplus)
180  } // End extern "C"
181 
194  bool rbBegin(Stream &port);
195 
196  // Redefine extern C
197  extern "C" {
198 #else
211  bool rbBegin(const char * port);
212 #endif
213 
219 bool rbEnd(void);
220 
229 bool rbSendMessage(const char * data, const size_t length, const int timeout);
230 
240 bool rbSendMessageCloudloop(cloudloopTopics_t topic, const char * data, const size_t length, const int timeout);
241 
251 bool rbSendMessageAny(uint16_t topic, const char * data, const size_t length, const int timeout);
252 
263 size_t rbReceiveMessage(char ** buffer);
264 
276 size_t rbReceiveMessageWithTopic(char ** buffer, uint16_t topic);
277 
288 size_t rbReceiveMessageAsync(char ** buffer);
289 
301 
309 void rbReceiveLockAsync(void);
310 
318 void rbReceiveUnlockAsync(void);
319 
327 void rbSendLockAsync(void);
328 
333 void rbSendUnlockAsync(void);
334 
347 bool rbSendMessageAsync(uint16_t topic, const char * data, const size_t length);
348 
361 bool rbCancelMessage(const uint16_t topic, const uint16_t id);
362 
369 void rbPoll(void);
370 
383 int8_t rbGetSignal(void);
384 
390 char * rbGetHwVersion(void);
391 
397 char * rbGetSerialNumber(void);
398 
404 char * rbGetImei(void);
405 
411 int8_t rbGetBoardTemp(void);
412 
420 bool rbGetCardPresent(void);
421 
431 bool rbGetSimConnected(void);
432 
438 char * rbGetIccid(void);
439 
447 char * rbGetFirmwareVersion(void);
448 
465 bool rbResyncServiceConfig(void);
466 
467 #if defined(KERMIT)
477 typedef void(*updateProgressCallback)(void * context, const unsigned long sofar, const unsigned long total);
478 
489 bool rbUpdateFirmware (const char * firmwareFile, updateProgressCallback progress, void * context);
490 #endif
491 
492 #ifdef RB_GPIO
493 #include "gpio.h"
494 
511 bool rbBeginGpio(char * port, const rbGpioTable_t * gpioInfo, const int timeout);
512 
521 bool rbEndGpio(const rbGpioTable_t * gpioInfo);
522 #endif
523 
532 static uint16_t calculateCrc(const uint8_t * buffer, const size_t bufferLength, const uint16_t initialCRC);
533 
541 static bool appendCrc(uint8_t * buffer, size_t length);
542 
552 static size_t encodeData(const char * srcBuffer, const size_t srcLength, char * destBuffer, const size_t destLength);
553 
563 static size_t decodeData(const char * srcBuffer, const size_t srcLength, char * destBuffer, const size_t destLength);
564 
569 void clearLeftoverData(void);
570 
576 bool setApi(void);
577 
583 bool setSim(void);
584 
590 bool setState(void);
591 
598 static bool checkProvisioning(uint16_t topic);
599 
606 static bool sendMoFromQueue(const int timeout);
607 
613 static bool listenForMt(void);
614 
622 
630 
636 static bool sendMoFromQueueAsync(void);
637 
643 static bool checkMoQueue(void);
644 
645 
646 #ifdef __cplusplus
647 }
648 #endif
649 
650 #endif
serialContext context
Definition: serial.c:6
jsprSimStatus_t simStatus
Definition: rockblock_9704.c:38
jsprHwInfo_t hwInfo
Definition: rockblock_9704.c:37
size_t rbReceiveMessage(char **buffer)
Listen for a mobile terminated message from the modem.
Definition: rockblock_9704.c:472
static bool sendMoFromQueue(const int timeout)
Send a queued message using mobile originated (MO) transmission.
void clearLeftoverData(void)
Clear any stale data leftover in serial buffers.
Definition: rockblock_9704.c:135
int8_t rbGetSignal(void)
Get the current signal strength from the modem.
Definition: rockblock_9704.c:908
static bool getHwInfo(jsprHwInfo_t *hwInfo)
Retrieve hardware information from the modem.
bool rbSendMessageAny(uint16_t topic, const char *data, const size_t length, const int timeout)
Send a mobile originated message from the modem on any topic.
Definition: rockblock_9704.c:387
bool rbEnd(void)
Uninitialise/close the the serial connection.
Definition: rockblock_9704.c:1139
bool rbGetSimConnected(void)
Check if SIM card is present, communicating properly with, and has presented no errors in SIM transac...
Definition: rockblock_9704.c:1008
static bool getSimStatus(jsprSimStatus_t *simStatus)
Get current SIM card status.
size_t rbReceiveMessageAsync(char **buffer)
Check if a valid message exists, stored at the head of the receiving queue.
Definition: rockblock_9704.c:636
static size_t encodeData(const char *srcBuffer, const size_t srcLength, char *destBuffer, const size_t destLength)
Encode binary data to base64 format.
static bool checkProvisioning(uint16_t topic)
Check if the given topic is provisioned.
bool rbSendMessageAsync(uint16_t topic, const char *data, const size_t length)
Queue a message to be sent.
Definition: rockblock_9704.c:589
char * rbGetFirmwareVersion(void)
Get the Iridium modem firmware version as vX.Y.X with X being the major number, Y being the minor num...
Definition: rockblock_9704.c:1047
void rbSendUnlockAsync(void)
Unlocks the sending queue so that old messages are discarded to make space for incoming ones.
Definition: rockblock_9704.c:676
bool rbEndGpio(const rbGpioTable_t *gpioInfo)
Drives user defined pin (power enable) high and another user defined pin (iridium enable) low to dein...
Definition: rockblock_9704.c:82
bool rbGetCardPresent(void)
Check if SIM presence is currently asserted.
Definition: rockblock_9704.c:998
char * rbGetIccid(void)
Get the iccid.
Definition: rockblock_9704.c:1018
static bool checkMoQueue(void)
Checks if any more messages have been queued, if so, send them.
char * rbGetSerialNumber(void)
Get the serial number.
Definition: rockblock_9704.c:962
int8_t rbGetBoardTemp(void)
Get the board temperature.
Definition: rockblock_9704.c:972
bool rbBegin(const char *port)
Initialise the the serial connection in the detected context (or user defined), if successful continu...
Definition: rockblock_9704.c:274
static size_t decodeData(const char *srcBuffer, const size_t srcLength, char *destBuffer, const size_t destLength)
Decode base64 data back into binary.
static bool listenForMt(void)
Listen for an incoming mobile terminated (MT) message.
size_t rbReceiveMessageWithTopic(char **buffer, uint16_t topic)
Listen for a mobile terminated message from the modem.
Definition: rockblock_9704.c:494
static uint16_t calculateCrc(const uint8_t *buffer, const size_t bufferLength, const uint16_t initialCRC)
Calculate CRC for a buffer.
char * rbGetHwVersion(void)
Get the hardware version.
Definition: rockblock_9704.c:952
bool setSim(void)
Initialise SIM card configuration.
Definition: rockblock_9704.c:188
static bool appendCrc(uint8_t *buffer, size_t length)
Append CRC to the end of a buffer.
rbMsgStatus_t
Indicates the result of a message operation.
Definition: rockblock_9704.h:38
@ RB_MSG_STATUS_OK
Message was processed successfully.
Definition: rockblock_9704.h:42
@ RB_MSG_STATUS_FAIL
Message failed to be processed.
Definition: rockblock_9704.h:47
void rbPoll(void)
Polling function that handles all incoming communication from the modem.
Definition: rockblock_9704.c:704
bool rbSendMessage(const char *data, const size_t length, const int timeout)
Send a mobile originated message from the modem on the default topic (244).
Definition: rockblock_9704.c:343
void rbReceiveUnlockAsync(void)
Unlocks the receiving queue so that old messages are discarded to make space for incoming ones.
Definition: rockblock_9704.c:666
bool setState(void)
Set operational state for the modem.
Definition: rockblock_9704.c:226
char * rbGetImei(void)
Get the imei.
Definition: rockblock_9704.c:942
cloudloopTopics_t
Predefined Cloudloop topic identifiers for RockBLOCK 9704.
Definition: rockblock_9704.h:158
@ RAW_TOPIC
Definition: rockblock_9704.h:160
@ PURPLE_TOPIC
Definition: rockblock_9704.h:163
@ PINK_TOPIC
Definition: rockblock_9704.h:166
@ ORANGE_TOPIC
Definition: rockblock_9704.h:172
@ RED_TOPIC
Definition: rockblock_9704.h:169
@ YELLOW_TOPIC
Definition: rockblock_9704.h:175
bool rbBeginGpio(char *port, const rbGpioTable_t *gpioInfo, const int timeout)
Drives user defined pin (power enable) low and user defined pin (iridium enable) high to initialise t...
Definition: rockblock_9704.c:62
void rbSendLockAsync(void)
Locks the sending queue so that old messages aren't discarded when incoming ones arrive.
Definition: rockblock_9704.c:671
bool rbUpdateFirmware(const char *firmwareFile, updateProgressCallback progress, void *context)
Update 9704 firmware. This is a blocking call and will take approximately 10 minutes to upgrade,...
Definition: rockblock_9704.c:1216
static bool sendMoFromQueueAsync(void)
Send a the modem a request to queue a message.
bool rbResyncServiceConfig(void)
Requests a resynchronisation of the service configuration.
Definition: rockblock_9704.c:1064
bool rbSendMessageCloudloop(cloudloopTopics_t topic, const char *data, const size_t length, const int timeout)
Send a mobile originated message from the modem on a cloudloop topic of choice.
Definition: rockblock_9704.c:365
bool setApi(void)
Set the modem API version.
Definition: rockblock_9704.c:153
void(* updateProgressCallback)(void *context, const unsigned long sofar, const unsigned long total)
A callback definition for the kermit transfer.
Definition: rockblock_9704.h:477
void rbRegisterCallbacks(const rbCallbacks_t *callbacks)
Registers a set of user-defined callbacks with the library.
Definition: rockblock_9704.c:53
void rbReceiveLockAsync(void)
Locks the receiving queue so that old messages aren't discarded when incoming ones arrive.
Definition: rockblock_9704.c:661
bool rbCancelMessage(const uint16_t topic, const uint16_t id)
Cancel a message.
Definition: rockblock_9704.c:619
bool rbAcknowledgeReceiveHeadAsync(void)
Acknowledge the head of the receiving queue by discarding it.
Definition: rockblock_9704.c:681
Definition: jspr.h:202
Definition: jspr.h:276
Definition: jspr.h:269
Definition: jspr.h:284
Struct containing user defined callback functions for asynchronous operations.
Definition: rockblock_9704.h:58
void(* messageProvisioning)(const jsprMessageProvisioning_t *messageProvisioning)
Callback for message provisioning info once its been obtained.
Definition: rockblock_9704.h:64
Definition: gpio.h:26