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 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
14 #include "serial.h"
15 #include "jspr.h"
16 #include <stdio.h>
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include <string.h>
20 #include <stddef.h>
21 
29 typedef enum
30 {
35 
41 
49 typedef struct
50 {
56  void (*messageProvisioning)(const jsprMessageProvisioning_t *messageProvisioning);
57 
65  void (*moMessageComplete)(const uint16_t id, const rbMsgStatus_t status);
66 
74  void (*mtMessageComplete)(const uint16_t id, const rbMsgStatus_t status);
75 
81  void (*constellationState)(const jsprConstellationState_t *state);
83 
92 void rbRegisterCallbacks(const rbCallbacks_t *callbacks);
93 
97 #define BASE64_TEMP_BUFFER 2048U
98 
104 #define RB9704_BAUD 230400U
105 
124 #ifndef SERIAL_CONTEXT_SETUP_FUNC
125  #ifdef __linux__
126  #define SERIAL_CONTEXT_SETUP_FUNC setContextLinux
127  #elif __APPLE__
128  #define SERIAL_CONTEXT_SETUP_FUNC setContextLinux
129  #elif _WIN32
130  #define SERIAL_CONTEXT_SETUP_FUNC setContextWindows
131  #elif ARDUINO
132  #define SERIAL_CONTEXT_SETUP_FUNC setContextArduino
133  #endif
134 #endif
135 
142 typedef enum
143 {
145  RAW_TOPIC = 244,
146 
149 
151  PINK_TOPIC = 314,
152 
154  RED_TOPIC = 315,
155 
158 
160  YELLOW_TOPIC = 317
162 
163 
172 bool rbBegin(const char * port);
173 
179 bool rbEnd(void);
180 
189 bool rbSendMessage(const char * data, const size_t length, const int timeout);
190 
200 bool rbSendMessageCloudloop(cloudloopTopics_t topic, const char * data, const size_t length, const int timeout);
201 
211 bool rbSendMessageAny(uint16_t topic, const char * data, const size_t length, const int timeout);
212 
223 size_t rbReceiveMessage(char ** buffer);
224 
236 size_t rbReceiveMessageWithTopic(char ** buffer, uint16_t topic);
237 
248 size_t rbReceiveMessageAsync(char ** buffer);
249 
261 
269 void rbReceiveLockAsync(void);
270 
278 void rbReceiveUnlockAsync(void);
279 
292 bool rbSendMessageAsync(uint16_t topic, const char * data, const size_t length);
293 
300 void rbPoll(void);
301 
314 int8_t rbGetSignal(void);
315 
321 char * rbGetHwVersion(void);
322 
328 char * rbGetSerialNumber(void);
329 
335 char * rbGetImei(void);
336 
342 int8_t rbGetBoardTemp(void);
343 
351 bool rbGetCardPresent(void);
352 
362 bool rbGetSimConnected(void);
363 
369 char * rbGetIccid(void);
370 
378 char * rbGetFirmwareVersion(void);
379 
396 bool rbResyncServiceConfig(void);
397 
398 #if defined(KERMIT)
408 typedef void(*updateProgressCallback)(void * context, const unsigned long sofar, const unsigned long total);
409 
420 bool rbUpdateFirmware (const char * firmwareFile, updateProgressCallback progress, void * context);
421 #endif
422 
423 #ifdef RB_GPIO
424 #include "gpio.h"
425 
438 bool rbBeginGpio(char * port, const rbGpioTable_t * gpioInfo, const int timeout);
439 
448 bool rbEndGpio(const rbGpioTable_t * gpioInfo);
449 #endif
450 
459 static uint16_t calculateCrc(const uint8_t * buffer, const size_t bufferLength, const uint16_t initialCRC);
460 
468 static bool appendCrc(uint8_t * buffer, size_t length);
469 
479 static size_t encodeData(const char * srcBuffer, const size_t srcLength, char * destBuffer, const size_t destLength);
480 
490 static size_t decodeData(const char * srcBuffer, const size_t srcLength, char * destBuffer, const size_t destLength);
491 
497 static bool setApi(void);
498 
504 static bool setSim(void);
505 
511 static bool setState(void);
512 
519 static bool checkProvisioning(uint16_t topic);
520 
527 static bool sendMoFromQueue(const int timeout);
528 
534 static bool listenForMt(void);
535 
543 
551 
557 static bool sendMoFromQueueAsync(void);
558 
564 static bool checkMoQueue(void);
565 
566 
567 #ifdef __cplusplus
568 }
569 #endif
570 
571 #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:461
static bool sendMoFromQueue(const int timeout)
Send a queued message using mobile originated (MO) transmission.
int8_t rbGetSignal(void)
Get the current signal strength from the modem.
Definition: rockblock_9704.c:832
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:374
bool rbEnd(void)
Uninitialise/close the the serial connection.
Definition: rockblock_9704.c:1068
bool rbGetSimConnected(void)
Check if SIM card is present, communicating properly with, and has presented no errors in SIM transac...
Definition: rockblock_9704.c:935
static bool getSimStatus(jsprSimStatus_t *simStatus)
Get current SIM card status.
static bool setState(void)
Set operational state for the modem.
size_t rbReceiveMessageAsync(char **buffer)
Check if a valid message exists, stored at the head of the receiving queue.
Definition: rockblock_9704.c:600
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:574
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:975
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:925
static bool setSim(void)
Initialise SIM card configuration.
char * rbGetIccid(void)
Get the iccid.
Definition: rockblock_9704.c:945
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:888
int8_t rbGetBoardTemp(void)
Get the board temperature.
Definition: rockblock_9704.c:898
bool rbBegin(const char *port)
Initialise the the serial connection in the detected context (or user defined), if successful continu...
Definition: rockblock_9704.c:258
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:483
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:878
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:30
@ RB_MSG_STATUS_OK
Message was processed successfully.
Definition: rockblock_9704.h:34
@ RB_MSG_STATUS_FAIL
Message failed to be processed.
Definition: rockblock_9704.h:39
void rbPoll(void)
Polling function that handles all incoming communication from the modem.
Definition: rockblock_9704.c:658
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:328
void rbReceiveUnlockAsync(void)
Unlocks the receiving queue so that old messages are discarded to make space for incoming ones.
Definition: rockblock_9704.c:630
char * rbGetImei(void)
Get the imei.
Definition: rockblock_9704.c:868
cloudloopTopics_t
Predefined Cloudloop topic identifiers for RockBLOCK 9704.
Definition: rockblock_9704.h:143
@ RAW_TOPIC
Definition: rockblock_9704.h:145
@ PURPLE_TOPIC
Definition: rockblock_9704.h:148
@ PINK_TOPIC
Definition: rockblock_9704.h:151
@ ORANGE_TOPIC
Definition: rockblock_9704.h:157
@ RED_TOPIC
Definition: rockblock_9704.h:154
@ YELLOW_TOPIC
Definition: rockblock_9704.h:160
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
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:1146
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:992
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:351
void(* updateProgressCallback)(void *context, const unsigned long sofar, const unsigned long total)
A callback definition for the kermit transfer.
Definition: rockblock_9704.h:408
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:625
static bool setApi(void)
Set the modem API version.
bool rbAcknowledgeReceiveHeadAsync(void)
Acknowledge the head of the receiving queue by discarding it.
Definition: rockblock_9704.c:635
Definition: jspr.h:201
Definition: jspr.h:274
Definition: jspr.h:267
Definition: jspr.h:282
Struct containing user defined callback functions for asynchronous operations.
Definition: rockblock_9704.h:50
void(* messageProvisioning)(const jsprMessageProvisioning_t *messageProvisioning)
Callback for message provisioning info once its been obtained.
Definition: rockblock_9704.h:56
Definition: gpio.h:26