General Configuration¶
⚠️ Note: This document describes how to use the SDK's API to operate scanning devices and provides sample code in C language. Please note that the API is a synchronous operation and may block the main thread when used.
⚠️ Note: Before using the API, you need to connect the device and register for message notifications to receive messages from the device. For detailed steps, please refer to Message Notification.
1. Get Configuration¶
1.1 Write Command¶
To get the general configuration of the scanning device, use the following Bluetooth service and characteristic UUIDs to perform a write without response operation:
| Bluetooth | UUID |
|---|---|
| Service | 0x0000ff0000001000800000805f9b34fb |
| Characteristic | 0x0000ff0400001000800000805f9b34fb |
Use the following command to get the data to write to the characteristic:
const char* result = inateck_scanner_cmd_get_settings();
The return result is in JSON format. If the call is successful, result will return:
{
"status": 0,
"data": [0, 1, 2, 3],
}
If the call fails, result will return:
{
"status": 1,
"data": [],
}
1.2 Message Parsing¶
After waiting for the device to respond, you can use the following method to parse the data:
const char* result = inateck_scanner_cmd_get_settings_result(device_type, data, data_length);
Input parameters:
device_typeis the device type, the value range is Device Type List.datais the data returned by the device.data_lengthis the length of the data.
The return result is in JSON format. If the call is successful, result will return:
{
"status": 0,
"data": [
{
"name": "volume",
"flag": 1001,
"value": 0,
},
{
"name": "vibration",
"flag": 1002,
"value": 0,
},
]
}
If the call fails, result will return:
{
"status": 1,
"data": [],
}
Return result:
infois the configuration information list, including the name, identifier, and value of the configuration item.nameis the name of the configuration item.flagis the identifier of the configuration item.valueis the value of the configuration item.
1.3 Sample Code¶
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main() {
const char* result = inateck_scanner_cmd_get_settings();
if (result) {
// result is in JSON format, parse the data
const unsigned char* data = (const unsigned char*)result;
int data_length = strlen(result);
// Send data via Bluetooth write without response
// Assume there is a function send_data_via_bluetooth to send data
send_data_via_bluetooth(data, data_length);
// Wait for the device to respond, receive data
// Assume there is a function receive_data_via_bluetooth to receive data
receive_data_via_bluetooth();
const unsigned char* data = get_received_data();
int data_length = get_received_data_length();
int device_type = 12;
// Parse the data
const char* result = inateck_scanner_cmd_get_settings_result(device_type, data, data_length);
if (result) {
printf("Get settings success\n");
}
}
return 0;
}
2. Configuration¶
2.1 Write Command¶
To configure the general settings of the scanning device, use the following Bluetooth service and characteristic UUIDs to perform a write without response operation:
| Bluetooth | UUID |
|---|---|
| Service | 0x0000ff0000001000800000805f9b34fb |
| Characteristic | 0x0000ff0400001000800000805f9b34fb |
First, read the configuration to obtain the data read_data, then use the following command to get the data to write to the characteristic:
const char* result = inateck_scanner_cmd_set_settings(device_type, read_data, read_data_length, cmd);
Input parameters:
device_typeis the device type, the value range is Device Type List.read_datais the data read from the configuration.read_data_lengthis the length of the data read from the configuration.cmdis the configuration command array, including the identifier and value of the configuration item, the value range is Configuration List. Each configuration item is aJSONobject, including the following fields:flagis the identifier of each configuration item, an integer value. For example, theflagofvolumeis1001.valueis the value of the configuration item. For example, thevalueofvolumeis0, which means turning off the sound.
For example, to set the volume of the BCST-21 device to 0 and the vibration to 0, the cmd is [{"flag":1001,"value":0},{"flag":1002,"value":0}], and the device_type is 12.
The return result is in JSON format. If the call is successful, result will return:
{
"status": 0,
"data": [0, 1, 2, 3],
}
If the call fails, result will return:
{
"status": 1,
"data": [],
}
2.2 Message Parsing¶
After waiting for the device to respond, you can use the following method to parse the data:
int result = inateck_scanner_cmd_check_result(data, data_length);
The return result is of type int. If the call is successful, result will return 0. If the call fails, result will return 1.
After the configuration is successful, it is recommended to get the configuration information again to ensure that the configuration has taken effect.
3. Sample Code¶
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
int main() {
const char* result = inateck_scanner_cmd_get_settings();
if (result) {
// result is in JSON format, parse the data
const unsigned char* data = (const unsigned char*)result;
int data_length = strlen(result);
// Send data via Bluetooth write without response
// Assume there is a function send_data_via_bluetooth to send data
send_data_via_bluetooth(data, data_length);
// Wait for the device to respond, receive data
// Assume there is a function receive_data_via_bluetooth to receive data
receive_data_via_bluetooth();
const unsigned char* data = get_received_data();
int data_length = get_received_data_length();
int device_type = 12;
// Parse the data
const char* result = inateck_scanner_cmd_get_settings_result(device_type, data, data_length);
if (result) {
printf("Get settings success\n");
// Parse the data
const unsigned char* read_data = ...;
int read_data_length = ...;
// Set volume to 0, vibration to 0
const char* cmd = "[{\"flag\":1001,\"value\":0},{\"flag\":1002,\"value\":0}]";
const char* result = inateck_scanner_cmd_set_settings(device_type, read_data, read_data_length, cmd);
if (result) {
// result is in JSON format, parse the data
const unsigned char* data = (const unsigned char*)result;
int data_length = strlen(result);
// Send data via Bluetooth write without response
// Assume there is a function send_data_via_bluetooth to send data
send_data_via_bluetooth(data, data_length);
// Wait for the device to respond, receive data
// Assume there is a function receive_data_via_bluetooth to receive data
receive_data_via_bluetooth();
const unsigned char* data = get_received_data();
int data_length = get_received_data_length();
// Parse the data
int result = inateck_scanner_cmd_check_result(data, data_length);
if (result == 0) {
printf("Set settings success\n");
} else {
printf("Set settings failed\n");
}
}
}
}
return 0;
}