This article describes the system-related API operations that need to be defined when you port Link SDK for C.
Link SDK for C supports different operating systems or hardware platforms. Link SDK for C encapsulates system-related API operations to interact with operating systems or hardware platforms. When you develop a product, you must call the API operations in the SDK to implement business logic. You must also write code to define system-related API operations.
Description of system-related API operations
System-related API operations decouple Link SDK for C from operating systems. You can call the operations to interact with different operating systems.
The aiot_sysdep_portfile_t g_aiot_sysdep_portfile global variable is defined to include all system-related API operations.
The common operations and mutex-related operations are easy to use. This article does not describe how to call these operations. When you port the SDK, you must define all system-related API operations. You cannot specify NULL when you define the operations. Otherwise, errors occur.
List of system-related API operations
Applies for memory.
Obtains the current timestamp. Link SDK is used to calculate the deviation.
Specifies a sleep time, in milliseconds.
Generates a random number.
Creates a session.
Sets parameters for a session.
Establishes a session. MQTT or HTTP connections are based on sessions.
Reads data from a specified session.
Sends data by using a specified session.
Destroys a session.
Creates a mutex.
Applies for a mutex.
Releases a mutex.
Destroys a mutex.
Set the network parameters
When you port Link SDK for C, you must set the following parameters of the core_sysdep_network_setopt operation.
Set the network connection type. You can create a TCP or UDP socket for connection.
The TCP client. To establish MQTT, HTTP, HTTP2, or WebSocket connections, you must specify this parameter.
The UDP client. To establish CoAP connections, you must specify this parameter.
Save the following parameters for subsequent use.
The type of the socket to be created.
The domain name or IP address that is used to establish the connection. The memory is shared by the upper-layer modules.
The backup IP address that is used if the DNS resolution fails. You do not need to specify this parameter.
The port number that is used to establish the connection.
The timeout period to establish a connection, in milliseconds.
This parameter is not used. You do not need to specify this parameter.
Link SDK for C provides sample code in the
portfile/aiot_port/posix_port.c file. Code are ported based on the POSIX standard.