|
|
# STA5 SmartLink command guidance
|
|
|
|
|
|
## Requirement
|
|
|
- Platform: STA5
|
|
|
|
|
|
- The version can be found in sml_def.h, please follow the latest version.
|
|
|
|
|
|
- Please import below files to your project, they’re under SmartLink build folder:
|
|
|
<pre>
|
|
|
export
|
|
|
├── include
|
|
|
│ ├── libunixsocket.h
|
|
|
│ ├── sml_def.h
|
|
|
│ └── sml_data_format.h
|
|
|
└── libsocket.so
|
|
|
</pre>
|
|
|
|
|
|
## APIs
|
|
|
- To connect:
|
|
|
<pre>
|
|
|
ret = sfd = create_unix_stream_socket(TMP_SOCKET_SML, 0);
|
|
|
if (ret < 0) {
|
|
|
perror(0);
|
|
|
exit(1);
|
|
|
}
|
|
|
</pre>
|
|
|
- Send message:
|
|
|
<pre>
|
|
|
ret = write(sfd, &send_data, sizeof(send_data));
|
|
|
if (ret < 0) {
|
|
|
perror(0);
|
|
|
goto ERR_EXIT;
|
|
|
}
|
|
|
</pre>
|
|
|
- Receive message:
|
|
|
<pre>
|
|
|
ret = bytes = read(sfd, buf, MAX_MESSAGE_READ);
|
|
|
if (ret < 0) {
|
|
|
perror(0);
|
|
|
exit(1);
|
|
|
}
|
|
|
</pre>
|
|
|
|
|
|
## SmartLink data format
|
|
|
| Data member | Date type | Data length | Description |
|
|
|
| ----------- | ------------------ | ----------- | --------------------------------------- |
|
|
|
| version | unsigned char | 1 byte | Set to SML_MAJOR_VERSION. |
|
|
|
| mode | unsigned char | 1 byte | Refer to type REQ_MODE. |
|
|
|
| AppType | unsigned char | 1 byte | Refer to type APP_TYPE. |
|
|
|
| state | unsigned char | 1 byte | Refer to type SML_STATE_CODE. |
|
|
|
| AppClientID | unsigned int | 4 bytes | Client ID. |
|
|
|
| srcAppName | unsigned char[128] | 128 bytes | Source application name in string. |
|
|
|
| dstAppName | unsigned char[128] | 128 bytes | Destination application name in string. |
|
|
|
| cmd | unsigned int | 4 bytes | Refer to type SML_COMMAND. |
|
|
|
| len | unsigned int | 4 bytes | Total length of message in bytes. | |