Dusun Gateway Z-wave API
Summary
This document lists the API used for Zwave development.
The SDK related to it can be download from DUSUN website. For detailed information, please refer to the example in the SDK sample code.
1. SDK init function
SDK init function
Function declaration
BOOL SerialAPI_Init(const char* serial_port, const struct SerialAPI_Callbacks* _callbacks )
Parameter
Parameter
Necessity
Type
Input type
Introduction
serial_port
Yes
Yes
char *
Callback function
SerialAPI_Callbacks
input
input
Seen in example
Serial setting etc, /dev/ttyUSB1
Sample
const struct SerialAPI_Callbacks serial_api_callbacks = {
ApplicationCommandHandler,
ApplicationNodeInformation,
ApplicationControllerUpdate,
0,
0,
0,
0,
};
if (!SerialAPI_Init("/dev/ttyUSB1", &serial_api_callbacks))
{
fprintf(stderr, "SerialAPI not initilized\n");
return 1;
}
2. ZW_Version
SDK version query
Function Declaration
BYTE ZW_Version(BYTE *pBuf)
Parameter
None
Sample
char buf[64];
ZW_Version(buf);
printf("Vesion: %s \n", buf );
3. ZW_SoftRest
SDK software reset
Function Declaration
BYTE ZW_SoftReset()
Parameter
None
Sample
ZW_SoftReset();
4. SerialAPI_Poll
SDK event poll
Function Declaration
uint8_t SerialAPI_Poll(void)
Parameter
None
Sample
SerialAPI_Poll();
Notice:
While calling the Poll function, the Z-wave event would return by the registration function in the SerialAPI_Init function.
5. SerialAPI_GetFd
SDK io reuse to get the fd
Function Declaration
int SerialAPI_GetFd()
Parameter
None
Sample
int fd = SerialAPI_GetFd();
6. ZW_AddNodeToNetwork
Add devices to the the network
Function declaration
void ZW_AddNodeToNetwork(BYTE bMode,VOID_CALLBACKFUNC(completedFunc) (auto LEARN_INFO*))
Parameter
Parameter
Necessity
Type
Input type
Introduction
mode
Yes
BYTE
input
REMOVE_NODE_ANY - Remove any node from the network
REMOVE_NODE_CONTROLLER - Remove a controller from the network
REMOVE_NODE_SLAVE - Remove a slaev node from the network
REMOVE_NODE_STOP - Stop learn mode without reporting an error
Yes
Function
completedFunc
input
Remove Node Step Callback
Sample
ZW_AddNodeToNetwork(ADD_NODE_ANY|ADD_NODE_OPTION_NETWORK_WIDE,AddNodeStatusUpdate);
7. ZW_RemoveNodeFromNetwork
Delete devices from the network
Function declaration
void ZW_RemoveNodeFromNetwork(BYTE bMode, VOID_CALLBACKFUNC(completedFunc)(auto LEARN_INFO*))
Parameter
Parameter
Necessity
Type
Input type
Introduction
mode
Yes
BYTE
input
REMOVE_NODE_ANY - Remove any node from the network
REMOVE_NODE_CONTROLLER - Remove a controller from the network
REMOVE_NODE_SLAVE - Remove a slaev node from the network
REMOVE_NODE_STOP - Stop learn mode without reporting an error
Yes
Function
completedFunc
input
Remove Node Step Callback
Sample
ZW_RemoveNodeFromNetwork(REMOVE_NODE_ANY,RemoveNodeStatusUpdate);;
8. ZW_SendData
Send data to the device
Function declaration
BYTE ZW_SendData( BYTE nodeID, BYTE *pData, BYTE dataLength, BYTE txOptions, VOID_CALLBACKFUNC(completedFunc)(BYTE, TX_STATUS_TYPE*))
Parameter
Parameter
Necessity
Type
Input type
Introduction
nodeID
Yes
BYTE
input
Destination node ID (0xFF == broadcast)
Yes
BYTE *
pData
input
Data buffer pointer
Yes
BYTE
dataLength
input
Data buffer length
Yes
BYTE
txOptions
input
Transmit option flags
Yes
function
completedFunc
input
Transmit completed call back function
Yes
BYTE
nodeID
input
Destination node ID (0xFF == broadcast)
Sample
int zwave_class_cmd(unsigned char nid, unsigned char class, unsigned char cmd, char *data, int len, void (*completed)(BYTE x, TX_STATUS_TYPE *status))
{
char buf[256] = {0};
buf[0] = class & 0xff;
buf[1] = cmd & 0xff;
if (len > 0)
{
memcpy(buf + 2, data, len);
}
unsigned char options = 0x25;
void (*f)(BYTE, TX_STATUS_TYPE *) = NULL;
if (completed == NULL)
{
f = zwave_class_cmd_completed;
}
else
{
f = completed;
}
if (ZW_SendData((BYTE)nid, (BYTE *)buf, 2 + len, options, f) == FALSE)
{
{
printf("full tx queue!\n");
return -1;
}
return 0;
}
Ask for More IoT Resources
Talk to our experts in IoT.
Speed up the process in your IoT projects.