动态库说明
头文件libtriton.h
内容如下:
// Max length for 'action' in struct Payload
#define MAX_ACTION_LENGTH 256
// Max length for 'keyValue' in struct Payload
#define MAX_KEYVALUE_PAIRS 5000
// Max length for 'key' in struct KeyValue
#define MAX_KEY_LENGTH 4096
// Max length for 'value' in struct KeyValue
#define MAX_VALUE_LENGTH 4096
#ifndef LIBTRITON_LIBRARY_H
#define LIBTRITON_LIBRARY_H
#ifndef NELEMS
#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
#endif
typedef struct _KeyValue {
char *key;
char *value;
} KeyValue;
typedef struct _Payload {
int size;
char *action;
KeyValue *keyValue;
} Payload;
#ifdef __cplusplus
extern "C" {
#endif
// Send data
// Parameters:
// kvs - array of key value pairs (KeyValue structs) to be sent
// size - length of array (kvs)
// Return values:
// 0 - success
// -1 - error connecting to server
// -2 - error writing to server
// -3 - error reading response from server
// -4 - data error
int Send(KeyValue kvs[], int size);
int Send_Compat(KeyValue kvs[], int size);
// Receive data
// Returns received Payload, use freePayload() to free memory after use
Payload *Receive();
Payload *Receive_Compat();
// MQTT status
// Returns MQTT connection status
// 0 - Not connected
// 1 - Connected
int Status();
int Status_Compat();
// Get device UUID
// Parameters
// buffer: buffer for storing fetched UUID
// Returns fetched UUID length
int GetUUID(char *buffer);
int GetUUID_Compat(char *buffer);
// Helper function for freeing the payload and key values
void freePayload(Payload *payload);
void freeKeyValues(KeyValue *keyValue, int size);
#ifdef __cplusplus
}
#endif
#endif
提示
- 需要发送的数据按结构体
KeyValue
构造,将KeyValue
数组传入发送函数Send()
中 - 带有
_Compat
后缀的函数为兼容模式函数,一般情况下不需使用 Receive
函数必须由调用者定期调用以获取消息- 接收完成后需要调用
freePayload
函数以释放内存 - 发送完成后需要调用
freeKeyvalues
函数以释放内存