Introduction

HUAWEI OneHop is a core part of Huawei's device distributed technology. Based on the traditional NFC technology, HUAWEI OneHop integrates more short-distance technologies to enable a more efficient interaction and collaboration between a smartphone and other devices with a simple tap.

What You Will Learn

In this CodeLab, you are supposed to create a demo project and integrate the HUAWEI OneHop SDK into the demo to allow the OneHop Kit service work on Linux compatible devices.

Hardware Requirements

Software Requirements

Required Knowledge

Development Procedures

(1) Creating a project

The specific procedure depends on the actual development environment. The directory structure for the project is shown as follows:

Upload the project to the Linux compilation environment.

(2) Project compilation

In the Linux compilation environment, run the compilation commands to compile the project. For details, see the README file in the sample code package. The generated onehopkit_demo file is shown as follows:

(3) Configuring environment variables

Configure variables for the Linux environment where the demo program runs. For details about how to configure environment variables, please refer to the README file in the sample code package. After the configuration, you can run the demo program. The following figure shows the commands for configuring environment variables and running the demo program.

Service Process

The following figure shows the overall process.

For details on the API definitions, refer to the API Description.

The following shows how OneHop demo program invokes APIs for OneHop printing.
onehop_demo.c

int main() { signal(SIGINT, p_exit); InitCallback(); InitDriverAdapt(); /* Service Initialization APIs*/ if (InitOneHop(NULL) != 0) { printf("*****Init OneHop failed!*****\n"); return -1; } /* OneHop service is running * Press Ctrl and C keys to terminate the service */ while (g_running) { if (g_serviceEndFlag == SERVICE_STOPPED) { g_serviceEndFlag = SERVICE_STARTED; printf("#####Start onehop service#####\n"); if (StartOneHopService(&g_callBack) != 0) { printf("*****Start onehop service failed!*****\n"); if (StopOneHopService() != 0) { printf("*****Stop onehop service failed!*****\n"); UninitOneHop(); return -1; } g_serviceEndFlag = SERVICE_STOPPED; } } sleep(1); } /* Invoke the end OneHop service API */ printf("#####Stop onehop service#####\n"); if (StopOneHopService() != 0) { printf("*****Stop onehop service failed!*****\n"); UninitOneHop(); return -1; } /* Invoke the deinitialization OneHop service API */ printf("#####Uninit onehop kit#####\n"); UninitOneHop(); return 0; }

You have successfully completed this CodeLab and learned:

For more information about HUAWEI OneHop, click the following links:
HUAWEI OneHop Introduction

Downloading Source Code

Code copied