Device Message Response


⚠️ Note: This document describes how to use the SDK's API for scanner device operations and provides sample code in C. Please note that the API is synchronous and may block the main thread during use.

⚠️ Note: Before using the API, you need to successfully connect the device yourself.

1. Device Message Response

The Bluetooth service and characteristic UUIDs to be used are as follows:

Bluetooth UUID
Service 0x0000ff0000001000800000805f9b34fb
Characteristic 0x0000ff0100001000800000805f9b34fb

After successfully connecting to the device, you need to register for message notifications to receive messages from the device. You can parse the message notifications using the following method:

const char* result = inateck_scanner_cmd_notify_data_result(data, data_length);

The return result is in JSON format. If the call is successful, result will return:

{
    "notify_type": 0,
    "notify_status": 1,
    "notify_data": [0, 1, 2, 3],
}

If the call fails, result will return:

{
    "notify_type": 0,
    "notify_status": 0,
    "notify_data": [],
}

Explanation of the return result:

2. Sample Code

#include <stdio.h>
#include <string.h>
#include "inateck_scanner_cmd.h"

#define MAX_DATA_LENGTH 1024

unsigned char total_data[MAX_DATA_LENGTH];
int total_data_length = 0;

void notify_data_result(const unsigned char* data, int data_length) {
    // Append the received data to the end of total_data
    if (total_data_length + data_length < MAX_DATA_LENGTH) {
        memcpy(total_data + total_data_length, data, data_length);
        total_data_length += data_length;
    } else {
        printf("Data length exceeds buffer size\n");
        return;
    }

    const char* result = inateck_scanner_cmd_notify_data_result(total_data, total_data_length);
    if (result) {
        // Parse the JSON result, please parse according to the actual situation
        int notify_status = ...; // Parse notify_status
        const unsigned char* notify_data = ...; // Parse notify_data
        int notify_data_length = ...; // Parse the length of notify_data
        int notify_type = ...; // Parse notify_type

        if (notify_status == 0) {
            // Data is incomplete, continue receiving data
            // Assign notify_data to total_data, wait for new data to be received, add it to the existing total_data, and call the inateck_scanner_cmd_notify_data_result method again to parse it
            memcpy(total_data, notify_data, notify_data_length); // Use the length of notify_data
            total_data_length = notify_data_length;
            printf("Data is incomplete, continue receiving data\n");
        } else if (notify_status == 1) {
            // Data reception is complete, data can be parsed
            if (notify_type == 0) {
                // Scan result
                printf("scan result: %s\n", notify_data);
            } else if (notify_type == 1) {
                // Setting command response
                printf("notify result: %s\n", notify_data);
            }
            // Clear data
            total_data_length = 0;
        } else {
            // Data reception error
            printf("notify error\n");
            // Clear data
            total_data_length = 0;
        }

        printf("notify result: %s\n", result);
    }
}

int main() {
    // Bluetooth connect to device
    // Register for message notifications
    // Receive message notifications
    return 0;
}