Skip to content

The Software Development Kit 💼

The Software Development Kit (SDK) 💼 is the fastest and easiest way to start developing with the Cloud Module ☁️. The SDK is a single C header file, which allows for easy integration into your embedded system.

Flow of Development

Even though the C language doesn't support namespaces nor objects, it is still useful to approach certain structures as such. The struct can both be used as an object as well as a namespace. A namespace consists out of a struct which has already be declared as a constant. An object is a struct which contains function pointers, and which have a constructor function defined.

The SDK 💼 revolves around two objects:

  • cloudmodule — A namespace which contains the constructor for the CloudJson object among other things.
  • CloudJson — A set of builder pattern methods to construct a JSON object, and methods to send the object to the cloud.

Due to how C tends to work, you must first declare the cloudmodule namespace before you can use it:

c
/* Include the Cloud Module SDK. */
#include <cloudmodule.h>

/* Make sure the cloudmodule structure is declared. */
CloudModule cloudmodule = CloudModule();

Next, to communicate with the Cloud Module ☁️, you need to declare an instance of the CloudJson object. The constructor can be found under cloudmodule. There are two constructors, depending on the communication interface you want to use:

c
/* Initialise for the CAN interface. */
const CloudJson *json = cloudmodule.InitCan(SendCanOpen);

/* Or */

/* Initialise for the UART interface. */
const CloudJson *json_uart = cloudmodule.InitUart(SendUart);

Both constructors require the need for a Send() function in respect to the interface you have chosen. The InitCan() method expects you to send data over CAN using the SDO protocol. Uart on the other hand you only need to provide a function to send characters:

c
void SendCanOpen(uint16_t index, uint8_t subindex, uint32_t data) {
  /* TODO by you */
}

void SendUart(char symbol) {
  /* TODO by you */
}

WARNING

If you use the CAN communication interface, you should make sure to provide the CAN-ID, which in CANopen is also known as the COB-ID. As you are intended to send SDO requests, you should increment the Cloud Module ID with this allocator:

yaml
identifiers:
  sdo-request: 0x600
  cloud-module: 0x55
  cob: 0x655

CloudJson Object

The CloudJson object provides a set of methods to create a JSON object and to send out said object. The Add() method allows you to add a key-value pair to the JSON object you are building up. The Add() method uses the _Generic macro to provide you an interface which allows for the general primitive types, without the need for different methods:

c
const CloudJson *json = cloudmodule.InitCan(SendCanOpen);
json->Add("integer", -42)
    ->Add("unsigned", 420)
    ->Add("float", 6.9);

Additionally, the CloudJson object provides an extension on the Add() method which allows you to get back the row index of the value added to the Toast 🍞 configuration. This allows you to easily change the value without re-building the whole JSON object. The Change() function is just for that:

c
uint16_t ref = 0;
json->Add("integer", -42, &ref);

/* Change the value from -42 to -43. */
json->Change(ref, -43);

More, the CloudJson object provides the set of commands to set the URL, and to upload the constructed JSON object as the body to said URL. The URL should contain all the verification information to access cloud through a HTTP(s) POST method:

c
json->SetUrl("https://example.dev/items/data?access_token=RoBoT");
json->Upload();

The CloudJson object also provides members to add complex types to the JSON object:

c
json->AddImei()
    ->AddGps()
    ->AddSignal();

Classical C Approach

If you don't like the use of the object approach in your C code, than there is also another approach. Each of the methods in the CloudJson object also has a public function accessible to you.