Prefix and Suffix Configuration¶
⚠️ Note: This document describes how to use the SDK's API to operate the scanning device 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. Set Prefix¶
1.1 Write Command¶
To set the prefix of the scanning device, use the following Bluetooth service and characteristic UUIDs for 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_set_prefix(prefix, prefix_length);
Input parameters are as follows:
prefix
: Prefix string, maximum length of 32 bytes, the last byte must be0xFF
. For character range, please refer to Custom Encoding Table. For example, if the prefix isABC
, thenprefix
should be0x41 0x42 0x43 0xFF
.prefix_length
: Length of the prefix, maximum of 32 bytes.
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:
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
.
1.3 Sample Code¶
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include "inateck_scanner_ble.h"
int main() {
const char prefix[] = {0x41, 0x42, 0x43, 0xFF};
const char* result = inateck_scanner_cmd_set_prefix(prefix, sizeof(prefix));
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 prefix success\n");
} else {
printf("Set prefix failed\n");
}
}
return 0;
}
2. Get Prefix¶
2.1 Write Command¶
To get the prefix of the scanning device, use the following Bluetooth service and characteristic UUIDs for 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_prefix();
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:
const char* result = inateck_scanner_cmd_get_affix_result(data, data_length);
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": [],
}
Return parameters are as follows:
data
: Prefix byte array. For byte parsing, please refer to Custom Encoding Table.
2.3 Sample Code¶
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include "inateck_scanner_ble.h"
int main() {
const char* result = inateck_scanner_ble_get_prefix(device_id);
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
const char* result = inateck_scanner_cmd_get_affix_result(data, data_length);
if (result) {
printf("Get prefix success\n");
} else {
printf("Get prefix failed\n");
}
}
return 0;
}
3. Set Suffix¶
3.1 Write Command¶
To set the suffix of the scanning device, use the following Bluetooth service and characteristic UUIDs for 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_set_suffix(suffix, suffix_length);
Input parameters are as follows:
suffix
: Suffix string, maximum length of 32 bytes, the last byte must be0xFF
. For character range, please refer to Custom Encoding Table. For example, if the suffix isXYZ
, thensuffix
should be0x58 0x59 0x5A 0xFF
.suffix_length
: Length of the suffix, maximum of 32 bytes.
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": [],
}
3.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
.
3.3 Sample Code¶
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include "inateck_scanner_ble.h"
int main() {
const char suffix[] = {0x41, 0x42, 0x43, 0xFF};
const char* result = inateck_scanner_cmd_set_suffix(suffix, sizeof(suffix));
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 suffix success\n");
} else {
printf("Set suffix failed\n");
}
}
return 0;
}
4. Get Suffix¶
4.1 Write Command¶
To get the suffix of the scanning device, use the following Bluetooth service and characteristic UUIDs for 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_suffix();
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": [],
}
4.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_affix_result(data, data_length);
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": [],
}
Return parameters are as follows:
* data
: Suffix byte array. For byte parsing, please refer to Custom Encoding Table.
4.3 Sample Code¶
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
#include "inateck_scanner_ble.h"
int main() {
const char* result = inateck_scanner_ble_get_suffix(device_id);
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
const char* result = inateck_scanner_cmd_get_affix_result(data, data_length);
if (result) {
printf("Get suffix success\n");
} else {
printf("Get suffix failed\n");
}
}
return 0;
}