Near field communication integrated control system, method, electronic device and storage medium
Patent Information
- Application Number
- CN202610844207.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-11
- Publication Date
- 2026-08-18
AI Technical Summary
[0003]提供一种近场通信集成控制系统、方法、电子设备及存储介质,旨在解决安卓主板与MCU之间进行数据交换时需要通过Socket通信,存在通信延迟高、稳定性差的问题
[0015]This application discloses a near-field communication integrated control system, method, electronic device, and storage medium. The system includes: a motherboard running an Android operating system; a microcontroller connected to the motherboard via a serial port; and a first near-field communication controller integrated on the microcontroller. The motherboard is configured to provide an operation interface to upper-layer applications via a Java native interface, the operation interface being used to directly control the first near-field communication controller via the serial port. By integrating the first near-field communication controller into the microcontroller and connecting the microcontroller to the motherboard via a serial port, this application allows the motherboard to directly provide an operation interface to upper-layer applications via JNI, without needing to use Socket communication, thus reducing communication latency and improving the stability of near-field communication control.
Smart Images

Figure CN122602127A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of near-field communication technology, specifically to a near-field communication integrated control system, method, electronic device, and storage medium. Background Technology
[0002] Near Field Communication (NFC) technology is increasingly widely used in mobile terminals, especially in scenarios such as transportation, access control, and mobile payments. In practical applications, Android devices may need to connect an external NFC controller (such as an external NFC card reader module connected via serial port) to expand the device's NFC capabilities. A common approach to integrating an external NFC controller into the Android system is to configure a separate microcontroller unit (MCU) running a Linux operating system for the external NFC controller. This MCU runs a complete NFC protocol stack and control program, and the Android motherboard exchanges data with this MCU via socket communication. Upper-layer applications establish a socket connection with the MCU through the Android system and send commands to control the external NFC to perform operations such as card reading and writing. However, because data exchange between the Android motherboard and the MCU requires socket communication, it suffers from high communication latency and poor stability. Summary of the Invention
[0003] This invention provides a near-field communication integrated control system, method, electronic device, and storage medium, aiming to solve the problems of high communication latency and poor stability that occur when data exchange is performed between an Android motherboard and an MCU via Socket communication.
[0004] In a first aspect, a near-field communication integrated control system is provided, the system comprising: a motherboard running an Android operating system; a microcontroller connected to the motherboard via a serial port; and a first near-field communication controller integrated on the microcontroller; wherein the motherboard is configured to provide an operation interface to an upper-layer application via a Java native interface, the operation interface being used to directly control the first near-field communication controller via the serial port.
[0005] In some embodiments, the underlying control driver of the first near-field communication controller is ported to the Native layer of the Android operating system to provide the operation interface for controlling the serial port in the Native layer, and the operation interface is encapsulated as a Java callable method function so that the upper-layer application can directly control the first near-field communication controller by calling the method function.
[0006] In some embodiments, the method functions exist as a shared library suitable for the Android operating system.
[0007] In some embodiments, the operation interface includes at least one of the following: an initialization interface, a card reader interface, a card writer interface, and a shutdown interface.
[0008] In some embodiments, the system further includes: a second near-field communication controller connected to the motherboard via a standard interface; wherein the second near-field communication controller is controlled by the native near-field communication framework of the Android operating system; the first near-field communication controller and the second near-field communication controller perform near-field communication operations in parallel.
[0009] In some embodiments, the standard interface includes at least one of the following: an integrated circuit bus interface and a serial peripheral interface.
[0010] In some embodiments, the second near-field communication controller is adapted to the native near-field communication framework through the hardware abstraction layer of the Android operating system; the native near-field communication framework carries at least one of the following functions: card reading function, card writing function, and card emulation function.
[0011] In a second aspect, a near-field communication integrated control method is provided, the method being applied to the near-field communication integrated control system described in any one of the first aspects; the method includes: an upper-layer application responding to a first operation by a user, calling a method function through a Java native interface, and sending a first control command to the first near-field communication controller via the serial port, so that the first near-field communication controller performs a near-field communication operation.
[0012] In some embodiments, the method further includes: in response to a second operation by the user, the upper-layer application sends a second control command to a second near-field communication controller via the native near-field communication framework of the Android operating system, so that the second near-field communication controller and the first near-field communication controller execute the near-field communication operation in parallel.
[0013] Thirdly, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program or instructions, which, when executed by the processor, cause the processor to perform the steps of the near-field communication integrated control method according to any one of the second aspects.
[0014] Fourthly, a computer-readable storage medium is provided having a computer program or instructions stored thereon, which, when executed by a processor, implement the steps of the near-field communication integrated control method as described in any of the second aspects.
[0015] This application discloses a near-field communication integrated control system, method, electronic device, and storage medium. The system includes: a motherboard running an Android operating system; a microcontroller connected to the motherboard via a serial port; and a first near-field communication controller integrated on the microcontroller. The motherboard is configured to provide an operation interface to upper-layer applications via a Java native interface, the operation interface being used to directly control the first near-field communication controller via the serial port. By integrating the first near-field communication controller into the microcontroller and connecting the microcontroller to the motherboard via a serial port, this application allows the motherboard to directly provide an operation interface to upper-layer applications via JNI, without needing to use Socket communication, thus reducing communication latency and improving the stability of near-field communication control.
[0016] In this embodiment, the upper-layer application directly calls the operation interface via JNI, eliminating the need for the native Android NFC framework and cross-system Socket communication, thus reducing communication latency. Furthermore, in this embodiment, the upper-layer application directly controls the first near-field communication controller via a serial port, avoiding potential connection interruptions and data packet loss that can occur with cross-system Socket communication, resulting in a more reliable control link and a higher success rate for NFC operations. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 A structural block diagram of a near-field communication integrated control system provided in an embodiment of this application; Figure 2 A schematic diagram of the architecture of a first near-field communication controller provided for an embodiment of this application; Figure 3 A structural block diagram of another near-field communication integrated control system provided in an embodiment of this application; Figure 4 A schematic diagram of the architecture of a second near-field communication controller provided in an embodiment of this application; Figure 5 A flowchart illustrating a near-field communication integrated control method provided in an embodiment of this application; Figure 6 A flowchart illustrating another near-field communication integrated control method provided in an embodiment of this application; Figure 7 This is a schematic diagram of the structure of an electronic device provided in some embodiments of this application.
[0019] Explanation of reference numerals in the attached figures: 100. Near-field communication integrated control system; 110. Motherboard; 120. Microcontroller; 130. First near-field communication controller; 140. Second near-field communication controller. Detailed Implementation
[0020] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] In the following description, specific embodiments of the invention will be illustrated with reference to steps and symbols performed by one or more computers, unless otherwise stated. Therefore, these steps and operations will be referred to several times as being performed by a computer, and computer execution as referred to herein includes operations by a computer processing unit representing electronic signals of data in a structured format. This operation transforms the data or maintains it at a location in the computer's memory system, which can be reconfigured or otherwise alter the operation of the computer in a manner well known to those skilled in the art. The data structure maintained by the data is the physical location of the memory, which has specific characteristics defined by the data format. However, the principles of the invention described above are not intended to be limiting, and those skilled in the art will understand that many of the steps and operations described below can also be implemented in hardware.
[0022] The terms "module" or "unit" as used herein can be considered as software objects executing on the computing system. The various components, modules, engines, and services described herein can be considered as implementations on the computing system. While the apparatus and methods described herein are preferably implemented in software, they can also be implemented in hardware, both of which are within the scope of this invention.
[0023] Those skilled in the art will understand that, unless specifically stated otherwise, the singular forms “a,” “an,” “the,” and “the” used herein may also include the plural forms. It should be further understood that the term “comprising” as used in this specification means the presence of the stated features, integers, steps, operations, elements, and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. It should be understood that when an element is “connected” or “coupled” to another element, it may be directly connected or coupled to the other element, or there may be intermediate elements. Furthermore, “connected” or “coupled” as used herein may include wireless connections or wireless coupling. The term “and / or” as used herein includes all or any units and all combinations of one or more associated listed items.
[0024] With the widespread application of NFC technology in mobile terminals, users' demands for multi-tasking concurrency of NFC functions on devices are constantly increasing in scenarios such as transportation, access control, and mobile payment. For example, in transportation, users hope that devices can simulate multiple transit cards simultaneously and improve the success rate of card swiping; in daily life scenarios, users expect access control and payment functions to be used in parallel, achieving "one device for multiple uses" without interference.
[0025] To meet these requirements, some devices have begun exploring dual NFC architectures. The relevant technologies mainly employ the following two implementation methods: Method 1: Single NFC chip with software simulation. The device uses only one NFC chip, and a second NFC controller is simulated using software. In this method, the two NFC controllers essentially share the same hardware resources, making true physical isolation impossible. Therefore, it cannot support true concurrent operations, limiting application scenarios and failing to meet high-concurrency business requirements.
[0026] Method 2: Dual Systems Controlling Dual NFC. The device's mainboard 110 runs an Android system and controls one NFC controller, while an external MCU board running a Linux operating system controls the other NFC controller. The two systems exchange data via Socket communication to coordinate the operation of the dual NFC. This method requires maintaining two independent operating systems (Android and Linux), resulting in a complex system architecture and high development and maintenance costs. Furthermore, data exchange relies on cross-system Socket communication, leading to significant communication latency and poor real-time performance. The cross-system communication link is also susceptible to factors such as system load and network conditions, making stability difficult to guarantee. In addition, this solution is difficult to implement and costly.
[0027] Therefore, to overcome the limitations of single NFC virtualization solutions in supporting high-concurrency business scenarios, and to improve the problems of high data latency, system instability, maintenance difficulties, and high implementation complexity caused by cross-system socket communication in conventional dual NFC hardware solutions, this application provides a near-field communication integrated control system, which aims to at least partially solve the above-mentioned technical problems.
[0028] Figure 1 This is a structural block diagram of a near-field communication integrated control system provided in an embodiment of this application. Please refer to... Figure 1 The near-field communication integrated control system 100 may include: a motherboard 110, a microcontroller 120, and a first near-field communication controller 130.
[0029] The motherboard 110 runs an Android operating system; the microcontroller 120 is connected to the motherboard 110 via a serial port; the first near-field communication controller 130 is integrated on the microcontroller 120; the motherboard 110 is configured to provide an operation interface to the upper-layer application through a Java native interface, and the operation interface is used to directly control the first near-field communication controller 130 via the serial port.
[0030] The Android operating system can be Android 10 or later, featuring a standard system framework, Hardware Abstraction Layer (HAL), and kernel driver management capabilities. The microcontroller 120 can be an MCU with a Universal Asynchronous Receiver / Transmitter (UART) (i.e., serial port). The first near-field communication controller 130 and the microcontroller 120 can be packaged in the same circuit module. The microcontroller 120 is responsible for receiving control commands from the motherboard 110 and driving the first near-field communication controller 130 to perform corresponding RF operations (such as card reading, card writing, card emulation, etc.).
[0031] Upper-layer applications (such as user-developed, custom Android applications) can call this operation interface through the Java Native Interface (JNI) to send control commands (such as initialization, card reading, card writing, and closing) to the microcontroller 120 via serial port. After parsing the commands, the microcontroller 120 drives the first near-field communication controller 130 to execute the corresponding near-field communication operations, such as activating the radio frequency field and polling the card. Since this operation interface is directly exposed to the upper-layer application through JNI, without going through the Android system's native NFC framework, the upper-layer application can bypass the system-level NFC service stack and control the external first near-field communication controller 130 with minimal latency and the simplest path.
[0032] The near-field communication integrated control system 100 provided in this application embodiment integrates a first near-field communication controller 130 into a microcontroller 120, and connects the microcontroller 120 to an Android motherboard 110 via a serial port. This allows the motherboard 110 to directly provide an operation interface to upper-layer applications via JNI, without requiring Socket communication. The near-field communication integrated control system 100 provided in this application embodiment has the following beneficial effects: First, it reduces communication latency: upper-layer applications do not need to go through the Android native NFC framework and cross-system Socket communication, but directly call the operation interface through JNI. The control command path is short and the real-time performance is high, which is especially suitable for NFC interaction scenarios that are sensitive to response speed (such as access control card swiping and fast payment).
[0033] Second, the system architecture is simplified: the embodiments of this application do not require running a separate Linux operating system for the external NFC controller, nor do they require maintaining a cross-system communication protocol stack. Only a single-chip microcomputer 120 is needed to perform simple instruction parsing and driver tasks, which reduces system complexity and development and maintenance costs.
[0034] Third, improve the stability of NFC control: The embodiments of this application avoid unstable factors such as connection interruption and data packet loss that may occur in cross-system Socket communication, making the control link more reliable and the success rate of NFC operation higher.
[0035] Fourth, it supports flexible expansion: upper-layer applications can fully and independently control the external NFC controller, without being limited by the Android native NFC framework, which makes it easy for developers to customize NFC functions according to actual business needs (such as specific card read / write algorithms, custom polling strategies, etc.).
[0036] Fifth, reduce hardware costs: Compared with plug-in solutions that require running a complete Linux system, the embodiments of this application only require a low-cost microcontroller 120, without the need for large-capacity memory and flash memory, effectively reducing material costs.
[0037] In some embodiments, the underlying control driver of the first near-field communication controller 130 is ported to the Native layer of the Android operating system to provide an operation interface for controlling the serial port in the Native layer, and the operation interface is encapsulated into Java callable method functions so that the upper-layer application can directly control the first near-field communication controller 130 by calling the method functions.
[0038] The original manufacturer of an external NFC controller (such as the PN5190 chip) typically provides a set of Linux development documentation and a low-level driver based on the Linux system. This driver contains the implementation code for core functions of the NFC chip, such as initialization, reading, writing, and closing, and is usually written in C / C++. In this embodiment, the developers extract this Linux low-level driver code from the original Linux environment and port it to the Native layer (i.e., the C / C++ layer of the Android system, located below the Java Framework layer) of the Android motherboard 110's Android operating system kernel. For example, the specific porting process may include: removing dependencies strongly bound to the Linux system from the original low-level control driver, adapting to the Android operating system's lib libraries and system call interfaces, and adapting the serial port operations in the driver to serial port operation functions available in the Android operating system's Native layer.
[0039] After the porting was completed, four core operation interfaces were extracted from the original driver code: initialization interface (init), card reading interface (read), card writing interface (write), and close interface (close), and these were encapsulated as independent modules while removing redundant dependencies. These interfaces provide basic operational capabilities for controlling the serial port at the Native layer. In some embodiments, the operation interfaces include at least one of the following: initialization interface, card reading interface, card writing interface, and close interface.
[0040] Using JNI technology, the four core operation interfaces of the Native layer are encapsulated into Java-callable methods, enabling bidirectional calls between the Java and Native layers. In some embodiments, these methods exist as a shared library suitable for the Android operating system. For example, the Native layer code can be compiled into a shared library suitable for the Android operating system architecture using the CMake toolchain. For example, a .so file can be generated.
[0041] Create a custom Android application (i.e., the upper-layer application) and integrate the generated .so shared library into that application project. Upper-layer application developers can call methods such as open(), read(), write(), and close() just like regular Java methods, without needing to concern themselves with the underlying serial port communication details.
[0042] This application's embodiment ports the existing Linux-based NFC driver to the Android Native layer, eliminating the need to write driver code from scratch, shortening the development cycle, and ensuring driver stability and maturity. After JNI encapsulation, upper-layer applications call Java methods, while the underlying layer directly operates the serial port hardware, with only Native layer conversion in between. This avoids the overhead of traditional solutions involving multiple layers of forwarding through system services, Binder, and Socket, achieving a low-latency direct path from the Java layer to the hardware. Upper-layer application developers still use the Java language and conventional JNI calling methods, without needing to learn complex cross-system communication technologies, maintaining compatibility with Android standard development patterns, and lowering the development threshold.
[0043] The PN5190 chip is used as a specific example of the first near-field communication controller 130. Figure 2 This is a schematic diagram of the architecture of a first near-field communication controller provided in an embodiment of this application. Figure 2 As shown, the architecture of the first near-field communication controller 130 includes a hardware layer, a kernel driver layer, a board support package (BSP) layer, a JNI bridging layer, a framework layer, and an application layer.
[0044] The hardware layer includes the PN5190 chip, which serves as the NFC chip for the first near-field communication controller 130. The kernel driver layer includes components such as the SPI device driver ( / dev / pn5190), General Purpose Input / Output (GPIO) control, power management, buffer management, and data transmission, communicating with the NFC chip via the SPI bus. The BSP layer is a C function library, including components such as pn5190_open (device open), pn5190_read_card (card read), pn5190_write_card (card write), and pn5190_close (device close), corresponding to the specific operation interfaces init, read, write, and close. The JNI bridging layer corresponds to the pn5190_jni dynamic library, JNI_OnLoad initialization, function mapping table (bidirectional mapping between Java and Native), data type conversion, and exception handling, used to expose Native functions to Java. The Framework layer encapsulates JNI calls and loads native libraries, including components such as PN5190Manager (high-level API encapsulation), PN5190Native (JNI method declaration), and System.loadLibrary (loading native libraries). The Application layer is used to develop custom NFC applications, using JAR packages to directly call JNI interfaces.
[0045] Figure 3 This is a structural block diagram of another near-field communication integrated control system provided in an embodiment of this application. Figure 3 As shown, in some embodiments, the near-field communication integrated control system 100 further includes: a second near-field communication controller 140, which is connected to the motherboard 110 via a standard interface; wherein the second near-field communication controller 140 is controlled by the native near-field communication framework of the Android operating system; the first near-field communication controller 130 and the second near-field communication controller 140 perform near-field communication operations in parallel.
[0046] The second near-field communication controller 140 can be an NFC chip (such as a PN7220 chip) integrated on the motherboard 110, connected to the processor of the motherboard 110 through a standard hardware interface. In some embodiments, the standard interface includes at least one of the following: an integrated circuit bus interface and a serial peripheral interface. The I2C interface is suitable for connecting multiple slave devices and occupies few pins, and is often used in low-speed NFC chips. The SPI interface has a higher transmission rate and is suitable for NFC application scenarios that require high-speed data exchange (such as high-capacity card reading and writing). The specific interface used depends on the specifications of the selected NFC chip and the hardware design of the motherboard 110. Both the I2C and SPI interfaces are standard buses between the Android motherboard 110 and the NFC chip, featuring low power consumption, high reliability, and complete driver support.
[0047] At the software level, the native NFC framework built into the Android operating system manages the second near-field communication controller 140. Upper-layer applications (such as the "NFC" switch in system settings, third-party payment applications, etc.) can use the second near-field communication controller 140 to perform operations such as card reading, card writing, and card emulation by calling the Android standard NFC application programming interface. In some embodiments, the second near-field communication controller 140 is adapted to the native near-field communication framework through the hardware abstraction layer of the Android operating system; the functions carried by the native near-field communication framework include at least one of the following: card reading function, card writing function, and card emulation function.
[0048] The first near-field communication controller 130 and the second near-field communication controller 140 can perform near-field communication operations in parallel. The first near-field communication controller 130 is directly controlled by the upper-layer application via JNI through the serial port, while the second near-field communication controller 140 is controlled by the Android native NFC framework through the HAL layer. The two control paths are completely independent and do not interfere with each other. For example, a user can simultaneously use the first near-field communication controller 130 to read an external tag and simultaneously use the second near-field communication controller 140 to simulate an access card and interact with the card reader. At the software level, the multi-task scheduling capability of the Android system ensures that the two control tasks can run concurrently; at the hardware level, the two NFC controllers each have independent physical connections and radio frequency antennas, and there will be no resource conflicts.
[0049] The technical solution provided in this application embodiment enables physically independent control of two NFC controllers, allowing them to simultaneously execute different near-field communication operations and meet the needs of complex business scenarios (such as simultaneous card payment and access control verification). The second near-field communication controller 140 reuses the native Android framework, ensuring full compatibility with the existing NFC application ecosystem; the first near-field communication controller 130 provides flexible expansion capabilities through a custom direct control path. Developers can add new NFC channels without modifying the system framework. Users do not need to manually switch NFC controllers; the system can automatically or in parallel use the two NFC channels according to the application scenario. For example, the primary NFC can be used for payment on the top area of the phone, while the secondary NFC can be used to read tags on the back area, improving the convenience of interaction.
[0050] The PN7220 chip is used as a specific example of the second near-field communication controller 140. Figure 4 This is a schematic diagram of the architecture of a second near-field communication controller provided in an embodiment of this application. Figure 4 As shown, the architecture of the second near-field communication controller 140 includes a hardware layer, a kernel driver layer, a hardware abstraction layer (HAL) layer, a framework layer, and an application layer.
[0051] The hardware layer includes the PN7220 chip, which serves as the NFC chip for the second near-field communication controller 140. The kernel driver layer includes components such as the character device driver ( / dev / pn7220), bus communication (I2C / SPI interface), and interrupt handling (Direct Memory Access (DMA) transfer). As a kernel-level driver, the kernel driver layer communicates with the NFC chip via the I2C / SPI bus. The HAL layer includes components such as the NFC HAL interface (e.g., hardware / nfc.h), the NFC Controller Interface (NCI) protocol stack implementation (e.g., libnfc.nci), and the device abstraction layer (e.g., NfcTransport), implementing the NCI protocol and interacting with the kernel driver. The Framework layer, as the native Android NFC framework, communicates via Binder and includes components such as NfcManager (for obtaining the NFC adapter), NfcAdapter (the main operation interface), and system services (BinderIPC communication). The application layer provides Android NFC applications, using the standard Application Programming Interface (API).
[0052] The second near-field communication (NFC) controller 140 fully reuses the native Android NFC framework. Its application layer uses standard APIs, eliminating the need for custom interface development. Its control path is: Application Layer - Framework Layer - HAL Layer - Kernel Driver Layer - Hardware Layer. The first NFC controller 130 bypasses the native Android NFC framework, directly calling the Native layer via JNI. Its control path is: Application Layer - JNI Layer - BSP Layer - Kernel Driver Layer - Hardware Layer. The control chain of the first NFC controller 130 is completely independent of the native Android NFC framework. Direct calls between the Java layer and the Native layer are achieved through JNI, and the BSP layer encapsulates core operation interfaces such as open, read, write, and close. The first NFC controller 130 and the second NFC controller 140 together form a dual-NFC parallel architecture.
[0053] This application discloses a near-field communication integrated control system 100, including: a motherboard 110 running an Android operating system; a microcontroller 120 connected to the motherboard 110 via a serial port; and a first near-field communication controller 130 integrated on the microcontroller 120. The motherboard 110 is configured to provide an operation interface to upper-layer applications via a Java native interface, the operation interface being used to directly control the first near-field communication controller 130 via the serial port. By integrating the first near-field communication controller 130 into the microcontroller 120 and connecting the microcontroller 120 to the motherboard 110 via a serial port, this application allows the motherboard 110 to directly provide an operation interface to upper-layer applications via JNI, without needing to use Socket communication, thus reducing communication latency and improving the stability of near-field communication control. The technical solution provided in this application embodiment allows both NFC controllers to run on a single Android system on the motherboard 110 side, eliminating the need to maintain two independent operating systems, thus reducing development difficulty and maintenance costs; eliminating the need for cross-system communication between the two systems, resulting in a short data interaction path and low complexity; low latency in control command transmission, stable and reliable card swiping control, and a significantly improved user experience; and support for physically independent parallel operation of the two NFC controllers, offering strong scalability and applicability to more practical business scenarios.
[0054] To facilitate better implementation of the near-field communication integrated control system provided in the embodiments of this application, the embodiments of this application also provide a near-field communication integrated control method based on the above-described near-field communication integrated control system. The meanings of the terms used are the same as in the above-described near-field communication integrated control system, and specific implementation details can be found in the descriptions in the system embodiments.
[0055] Figure 5 This is a flowchart illustrating a near-field communication integrated control method provided in an embodiment of this application. Please refer to... Figure 5The near-field communication integrated control method is applied to the aforementioned near-field communication integrated control system. The near-field communication integrated control method mainly includes the following steps: Step S501: In response to the user's first operation, the upper-layer application calls a method function through the Java native interface and sends a first control command to the first near-field communication controller via the serial port, so that the first near-field communication controller performs near-field communication operation.
[0056] For example, the upper-layer application can be a custom Android application. The user opens a custom app specifically designed to read a particular type of tag, clicks the "Read" button on the interface (i.e., the first operation), and the app internally sends a card reading command to the serial port by calling the write() method through the previously loaded JNI shared library. After receiving the command, the microcontroller 120 drives the first near-field communication controller 130 (i.e., auxiliary NFC) to activate the radio frequency field and read the card data. Then, the read data is returned through the serial port, and the app then obtains the data through the JNI read() method and displays it on the UI interface.
[0057] The first control command goes from the upper-layer application to the hardware via the serial port, without going through the Android native NFC framework, system services, Binder and other intermediate links, thus achieving microsecond-level response latency. It is especially suitable for scenarios that require fast polling or high real-time requirements (such as industrial barcode scanning and fast access control).
[0058] like Figure 5 As shown, in some embodiments, the above-described near-field communication integrated control method may further include the following steps: Step S502: In response to the user's second operation, the upper-layer application sends a second control command to the second near-field communication controller through the native near-field communication framework of the Android operating system, so that the second near-field communication controller and the first near-field communication controller can perform near-field communication operations in parallel.
[0059] For example, the same custom app can also provide a "Start Payment Mode" button (second operation). After clicking, a second control command is sent to the second near-field communication controller 140 (i.e., the main NFC) via the Android standard NFC API, causing it to simulate a bank card or access card. This process fully reuses the system's native capabilities and requires no additional development of underlying logic.
[0060] Because the two control links are physically independent and their software stacks are independent, Android's multi-task scheduling mechanism can handle two NFC tasks simultaneously. For example, a user can use the first near-field communication controller 130 to poll and read external tags (directly controlled via JNI) while using the second near-field communication controller 140 to simulate a card in the background and wait for a POS machine to swipe the card. The two do not block each other, truly achieving concurrent NFC operations.
[0061] The near-field communication integrated control method provided in this application provides an extremely low-latency direct control path for upper-layer applications, bypassing the system framework, through the aforementioned step S501, which is significantly superior to traditional cross-system socket solutions. Simultaneously, through the aforementioned step S502, it provides upper-layer applications with the NFC functionality of the second near-field communication controller 140, which reuses the native NFC framework of the Android system. The technical solution provided in this application provides complete dual-NFC parallel capability, simultaneously supporting native framework control of the primary NFC and direct control of the secondary NFC, meeting the needs of complex businesses for multiple NFC channels. Custom applications can flexibly choose to directly control the secondary NFC via JNI, or control the primary NFC via standard API, or even use both simultaneously, according to business needs. Users do not need to perceive underlying differences and can trigger different NFC functions through simple UI operations. For scenarios requiring extended special NFC functions, external NFC can be easily integrated without affecting the stability of the original system. For scenarios only requiring the use of the system's native NFC capabilities, NFC functions can be directly implemented based on the native NFC framework, exhibiting good compatibility and scalability.
[0062] As a concrete example, Figure 6 This is a flowchart illustrating another near-field communication integrated control method provided in an embodiment of this application. Figure 6 As shown, the method includes the following steps: Step S600: Adaptation and verification of the main NFC (i.e., the second near-field communication controller 140) function. It should be noted that this step is an optional prerequisite. For scenarios where the native NFC capability of the motherboard 110 needs to be retained, firstly, the driver for the main NFC integrated on the motherboard 110 is ported to the Android kernel, and HAL layer adaptation is completed. This ensures that the native NFC framework of the Android operating system can normally perform card reading, card writing, and card emulation operations, serving as the main channel in the dual-NFC architecture, ensuring that the system's original NFC capability is not affected.
[0063] Step S601: Determine whether the verification is successful; if the verification fails, return to step S600; if the verification is successful, proceed to step S602.
[0064] Step S602: Auxiliary NFC (i.e., the first near-field communication controller 130) communication is established. The MCU board (i.e., the microcontroller 120) is connected to the Android motherboard 110 via the UART serial port to verify that the physical layer communication is normal and to ensure the reliability of subsequent data transmission.
[0065] Step S603: Determine if communication is normal; if communication is abnormal, return to step S602; if communication is normal, proceed to step S604.
[0066] Step S604: Port and extract the Linux NFC underlying program; based on the Linux development documentation provided by the NFC chip solution provider for the MCU, port the original C / C++ underlying control program to the Android Native environment. Extract four core operation interfaces from the code: open (init), read (read), write (write), and close (close), and encapsulate them into independent modules, while removing redundant dependencies. These interfaces constitute the basic set of operations for controlling the serial port at the Native layer.
[0067] Step S605: Determine if the interface is complete; if the interface is incomplete, return to step S604; if the interface is complete, proceed to step S606.
[0068] Step S606: Write the JNI wrapper layer and compile the dynamic library; based on the four operation interfaces extracted in step S604, write JNI code to implement bidirectional calls between the Java layer and the Native layer. Use the CMake toolchain to compile the above Native code into a shared library (such as a .so file) suitable for the Android architecture.
[0069] Step S607: Determine if compilation was successful; if compilation failed, return to step S606; if compilation was successful, proceed to step S608.
[0070] Step S608: Develop a custom NFC application and integrate the JNI library; create a custom Android application as the upper-layer application, and integrate the shared .so library generated in step S606 into the project. Write Java interface classes at the application layer to call the four core functions encapsulated at the lower layer via JNI, providing a concise API to the upper layer.
[0071] Step S609: Implement UI interaction call: In the user interface (UI) of the custom application, respond to the user's operation (such as clicking the card reader button), and implement the call to the card reading, card writing and other functions of the auxiliary NFC through the Java interface provided in step S607, and return the operation result to the upper layer application through the serial port, and finally display it on the UI interface.
[0072] Step S610: Determine if the function is normal; if the function is abnormal, return to step S609; if the function is normal, the process ends. At this point, the auxiliary NFC, as an independent application function, runs in parallel with the main NFC on the same Android system.
[0073] This application discloses a near-field communication integrated control system, method, electronic device, and storage medium. The system includes: a motherboard 110 running an Android operating system; a microcontroller 120 connected to the motherboard 110 via a serial port; and a first near-field communication controller 130 integrated on the microcontroller 120. The motherboard 110 is configured to provide an operation interface to upper-layer applications via a Java native interface, the operation interface being used to directly control the first near-field communication controller 130 via the serial port. By integrating the first near-field communication controller 130 into the microcontroller 120 and connecting the microcontroller 120 to the motherboard 110 via a serial port, this application allows the motherboard 110 to directly provide an operation interface to upper-layer applications via JNI, without needing to use Socket communication, thus reducing communication latency and improving the stability of near-field communication control.
[0074] Figure 7 This is a schematic diagram of the structure of an electronic device provided in some embodiments of this application. Figure 7 The dashed line in the text indicates that the unit or module is optional. Figure 7 The electronic device 700 can be used to implement the methods described in the above method embodiments. The electronic device 700 can be a chip, a terminal device, or a first server.
[0075] Electronic device 700 may include one or more processors 710. The processor 710 can support the electronic device 700 in implementing the methods described in the preceding method embodiments. The processor 710 can be a general-purpose processor or a special-purpose processor. For example, the processor can be a Central Processing Unit (CPU). Alternatively, the processor can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0076] The electronic device 700 may also include one or more memories 720. Computer programs are stored on the memories 720. The memories 720 may be independent of the processor 710 or integrated into the processor 710.
[0077] The electronic device 700 may also include a transceiver 730. The processor 710 can communicate with other devices or chips via the transceiver 730. For example, the processor 710 can send and receive data with other devices or chips via the transceiver 730.
[0078] The computer program in memory 720 can be executed by processor 710, causing processor 710 to perform the steps in any of the above near-field communication integrated control methods.
[0079] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0080] Therefore, embodiments of this application provide a computer-readable storage medium storing a computer program thereon, which is loaded by a processor to execute the steps described in the above-described method embodiments of this application. For example, the computer program loaded by the processor can execute the steps in any of the above-described near-field communication integrated control methods.
[0081] For details on the implementation of each of the above operations / steps, please refer to the previous examples, which will not be repeated here.
[0082] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0083] Since the computer program stored in the computer-readable storage medium can execute the steps in any of the above method embodiments provided in the embodiments of this application, the beneficial effects that the methods described in any of the above method embodiments can achieve can be realized, as detailed in the preceding embodiments, and will not be repeated here.
[0084] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the electronic device to perform the methods provided in the various optional implementations of the above embodiments.
[0085] The above provides a detailed description of a near-field communication integrated control system, method, electronic device, and storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A near-field communication integrated control system, characterized in that, The system includes: The motherboard runs the Android operating system. The microcontroller is connected to the motherboard via a serial port. The first near-field communication controller is integrated on the microcontroller; The motherboard is configured to provide an operation interface to the upper-layer application via a Java native interface, the operation interface being used to directly control the first near-field communication controller via the serial port.
2. The system according to claim 1, characterized in that, The underlying control driver of the first near-field communication controller is ported to the Native layer of the Android operating system to provide the operation interface for controlling the serial port in the Native layer, and the operation interface is encapsulated into Java callable method functions so that the upper-layer application can directly control the first near-field communication controller by calling the method functions.
3. The system according to claim 2, characterized in that, The method functions exist as a shared library suitable for the Android operating system.
4. The system according to any one of claims 1 to 3, characterized in that, The operation interface includes at least one of the following: Initialize the interface, read the card interface, write the card interface, and close the interface.
5. The system according to claim 1, characterized in that, The system also includes: The second near-field communication controller is connected to the motherboard via a standard interface; The second near-field communication controller is controlled by the native near-field communication framework of the Android operating system; the first near-field communication controller and the second near-field communication controller perform near-field communication operations in parallel.
6. The system according to claim 5, characterized in that, The standard interface includes at least one of the following: Integrated circuit bus interface, serial peripheral interface.
7. The system according to claim 5, characterized in that, The second near-field communication controller is adapted to the native near-field communication framework through the hardware abstraction layer of the Android operating system; the native near-field communication framework carries at least one of the following functions: Card reading function, card writing function, and card simulation function.
8. A near-field communication integrated control method, characterized in that, The method is applied to the near-field communication integrated control system as described in any one of claims 1 to 7; the method includes: In response to the user's first operation, the upper-layer application calls a method function through the Java native interface and sends a first control command to the first near-field communication controller via the serial port, so that the first near-field communication controller performs near-field communication operations.
9. The method according to claim 8, characterized in that, The method further includes: In response to the user's second operation, the upper-layer application sends a second control command to the second near-field communication controller through the native near-field communication framework of the Android operating system, so that the second near-field communication controller and the first near-field communication controller execute the near-field communication operation in parallel.
10. An electronic device, characterized in that, It includes a memory and a processor, wherein the memory stores a computer program or instructions, which, when executed by the processor, cause the processor to perform the steps in the near-field communication integrated control method as described in claim 8 or 9.
11. A computer-readable storage medium, characterized in that, It stores computer programs or instructions that, when executed by a processor, implement the steps of the near-field communication integrated control method as described in claim 8 or 9.