Control method and device, and storage medium
By introducing a service layer and a ring storage space, the application layer and driver layer are decoupled, solving the problem of high development difficulty caused by sensor driver programs and realizing efficient sensor data control and publishing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING XIAOMI MOBILE SOFTWARE CO LTD
- Filing Date
- 2021-09-13
- Publication Date
- 2026-07-24
AI Technical Summary
Because different sensors require their own unique drivers, application development is difficult and time-consuming. In existing RTOS systems, sensor control and software algorithm development models are mixed together, which increases the difficulty of application development and the risk of program errors.
A service layer is introduced to interact with the application layer, broadcast the topic information of the sensor data, respond to the subscription requests of the application layer, and control the driver layer to read the target sensor data from the sensor. A circular storage space and a general driver sub-layer are adopted to reduce redundant code and decouple the application layer and the driver layer.
It reduces the difficulty of application development, decreases the risk of program errors, improves development efficiency, and enables efficient control and data dissemination of sensor devices.
Smart Images

Figure CN113971045B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of embedded systems technology, and in particular to a control method, apparatus and storage medium. Background Technology
[0002] Sensors are an important part of the Internet of Things (IoT) field. They are the eyes of devices that perceive everything in the world. They transform everything and its environmental changes into digital information, which is then forwarded and processed by the IoT, making people's lives more intelligent and efficient.
[0003] With the development of the Internet of Things (IoT), the types of sensors are increasing. While this increases the choices available to developers, it also increases the difficulty of application development. Because different sensors require their own unique drivers to function, applications need to be adapted for different sensors, resulting in higher development difficulty and longer development cycles. Summary of the Invention
[0004] This disclosure provides a control method, apparatus, and storage medium.
[0005] According to a first aspect of the present disclosure, a control method is provided, applied to a control system, the control system comprising: an application layer, a service layer, and multiple driver layers, the method comprising:
[0006] The service layer broadcasts the topic information of the sensor data to the application layer, where different sensor data are generated by different sensors;
[0007] In response to the application layer's subscription request for at least one topic information, the service layer controls the driver layer corresponding to at least one of the topic information to read target sensing data from the sensor;
[0008] The service layer publishes the target sensing data to the application layer.
[0009] Optionally, the driving layer includes:
[0010] The first sublayer, wherein different first sublayers contain drivers for different sensors for interacting with the sensors;
[0011] The second sublayer is a common driving sublayer shared by different sensors. It provides storage space for writing sensor data by interacting with the first sublayer.
[0012] Optionally, the storage space is a ring-shaped storage space;
[0013] After the second storage address of the ring-shaped storage space is occupied, the target sensing data is written to the first storage address of the ring-shaped storage space, wherein the first storage address is the starting storage address of the storage area corresponding to the ring-shaped storage space; and the second storage address is the ending storage address of the storage area corresponding to the ring-shaped storage space.
[0014] Optionally, the service layer controls at least one driving layer corresponding to the topic information to read target sensing data from the sensor, including:
[0015] The service layer sends a control command to the first sub-layer; the control command is used to trigger the first sub-layer to read target sensing data from the connected sensor and write the target sensing data into the storage space of the second sub-layer;
[0016] After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer.
[0017] Optionally, the service layer controls at least one driving layer corresponding to the topic information to read target sensing data from the sensor, including:
[0018] The service layer sends a parameter adjustment instruction to the first sub-layer; the parameter adjustment instruction is used to trigger the first sub-layer to adjust the acquisition parameters, read the target sensing data from the connected sensor based on the adjusted acquisition parameters, and write the target sensing data into the storage space of the second sub-layer;
[0019] After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer.
[0020] Optionally, the acquisition parameters include:
[0021] The frequency of sensor data acquisition;
[0022] And / or, the sensor data acquisition mode, wherein different acquisition modes correspond to different preset lengths and / or different reading methods for the sensor data read from the ring storage space by the service layer.
[0023] Optionally, after the service layer detects an update to the data stored in the storage space of the second sub-layer, it retrieves the target sensing data from the storage space of the second sub-layer, including:
[0024] After detecting an update to the data stored in the storage space of the second sub-layer, the service layer sequentially reads the sensor data of a preset length from the data reading position indicated by the read pointer of the storage space.
[0025] Then move the read pointer to the next position after the current read position.
[0026] Optionally, the service layer broadcasts topic information of the sensor data to the application layer, including:
[0027] The service layer obtains the type information of the first type of registered sensors within the control system;
[0028] Based on the type information of the first type of sensor, the subject information of the sensing data sensed by the first type of sensor is determined; wherein, the first type of sensor is a sensor that only has a preset function;
[0029] The service layer broadcasts the topic information of the sensing data sensed by the first type of sensor to the application layer.
[0030] Optionally, the method further includes:
[0031] The application layer sends control commands to the registered second-type sensors in the control system through a preset operation function interface;
[0032] The control command is used to trigger the driver layer of the second type of sensor to call the operation function corresponding to the operation function interface, execute the control command, and transmit the execution result to the application layer through the operation function interface.
[0033] According to a second aspect of the present disclosure, a control device is provided for use in a control system, the control system comprising: an application layer, a service layer, and a plurality of driver layers, including:
[0034] The broadcast module is used by the service layer to broadcast the topic information of sensor data to the application layer, where different sensor data are generated by different sensors.
[0035] The first acquisition module is used to respond to the application layer's subscription request for at least one topic information, and the service layer controls the driver layer corresponding to at least one of the topic information to read target sensing data from the sensor;
[0036] The publishing module is used by the service layer to publish the target sensing data to the application layer.
[0037] Optionally, the driving layer includes:
[0038] The first sublayer, wherein different first sublayers contain drivers for different sensors for interacting with the sensors;
[0039] The second sublayer is a common driving sublayer shared by different sensors. It provides storage space for writing sensor data by interacting with the first sublayer.
[0040] Optionally, the storage space is a ring-shaped storage space;
[0041] After the second storage address of the ring-shaped storage space is occupied, the target sensing data is written to the first storage address of the ring-shaped storage space, wherein the first storage address is the starting storage address of the storage area corresponding to the ring-shaped storage space; and the second storage address is the ending storage address of the storage area corresponding to the ring-shaped storage space.
[0042] Optionally, the first acquisition module is configured to:
[0043] The service layer sends a control command to the first sub-layer; the control command is used to trigger the first sub-layer to read target sensing data from the connected sensor and write the target sensing data into the storage space of the second sub-layer;
[0044] After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer.
[0045] Optionally, the first acquisition module is configured to:
[0046] The service layer sends a parameter adjustment instruction to the first sub-layer; the parameter adjustment instruction is used to trigger the first sub-layer to adjust the acquisition parameters, read the target sensing data from the connected sensor based on the adjusted acquisition parameters, and write the target sensing data into the storage space of the second sub-layer;
[0047] After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer.
[0048] Optionally, the acquisition parameters include:
[0049] The frequency of sensor data acquisition;
[0050] And / or, the sensor data acquisition mode, wherein different acquisition modes correspond to different preset lengths and / or different reading methods for the sensor data read from the ring storage space by the service layer.
[0051] Optionally, the first acquisition module is further configured to:
[0052] After detecting an update to the data stored in the storage space of the second sub-layer, the service layer sequentially reads the sensor data of a preset length from the data reading position indicated by the read pointer of the storage space.
[0053] Then move the read pointer to the next position after the current read position.
[0054] Optionally, the broadcast module is used for:
[0055] The service layer obtains the type information of the first type of registered sensors within the control system;
[0056] Based on the type information of the first type of sensor, the subject information of the sensing data sensed by the first type of sensor is determined; wherein, the first type of sensor is a sensor that only has a preset function;
[0057] The service layer broadcasts the topic information of the sensing data sensed by the first type of sensor to the application layer.
[0058] Optionally, the apparatus further includes: a second acquisition module, configured to:
[0059] The application layer sends control commands to the registered second-type sensors in the control system through a preset operation function interface;
[0060] The control command is used to trigger the driver layer of the second type of sensor to call the operation function corresponding to the operation function interface, execute the control command, and transmit the execution result to the application layer through the operation function interface.
[0061] According to a third aspect of the present disclosure, a control device is provided, comprising:
[0062] processor;
[0063] Memory used to store executable instructions;
[0064] The processor is configured to, when executing executable instructions stored in the memory, implement the steps of the control method described in the first aspect of the present disclosure.
[0065] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium is provided, wherein when instructions in the storage medium are executed by a processor of a control device, the control device is enabled to perform steps in the control method as described in the first aspect of the present disclosure.
[0066] The technical solutions provided by the embodiments of this disclosure may include the following beneficial effects:
[0067] This embodiment of the disclosure broadcasts the topic information of sensor data to the application layer through a service layer, and in response to the application layer's subscription request for the topic information, controls the driver layer corresponding to the topic information to read target sensor data from the sensor; and the service layer publishes the target sensor data to the application layer; thus, by introducing a service layer and interacting with the application layer, the development process of the application does not require attention to the sensor driver, reducing the development difficulty of the application; through the interaction between the service layer and the sensor driver layer, the sensor device is controlled and the sensor data collected by the sensor is published according to the subscription status of the topic information of the sensor data, so that the application layer and the driver layer are completely decoupled.
[0068] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0069] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0070] Figure 1 This is a schematic diagram of the framework of an RTOS system according to an exemplary embodiment.
[0071] Figure 2 This is a schematic diagram of a sensor driving framework for an RT-Thread system according to an exemplary embodiment. Figure 1 .
[0072] Figure 3 This is a schematic diagram of a sensor driving framework for an RT-Thread system according to an exemplary embodiment. Figure 2 .
[0073] Figure 4 This is a flowchart illustrating a control method according to an exemplary embodiment. Figure 1 .
[0074] Figure 5 This is a flowchart illustrating a control method according to an exemplary embodiment. Figure 2 .
[0075] Figure 6 This is a schematic diagram of the software framework of a control system according to an exemplary embodiment.
[0076] Figure 7 This is a schematic diagram of a sensor driver layer framework according to an exemplary embodiment.
[0077] Figure 8 This is a schematic diagram illustrating a driving model of different sensor modules according to an exemplary embodiment.
[0078] Figure 9 This is a flowchart illustrating a control method according to an exemplary embodiment. Figure 3 .
[0079] Figure 10 This is a schematic diagram illustrating an application development framework according to an exemplary embodiment.
[0080] Figure 11 This is a schematic diagram of the structure of a control device according to an exemplary embodiment.
[0081] Figure 12 This is a block diagram illustrating a control device according to an exemplary embodiment. Detailed Implementation
[0082] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses consistent with some aspects of this disclosure as detailed in the appended claims.
[0083] For embedded or IoT devices, since their random access memory (RAM) or read-only memory (ROM) is generally in the KB or MB range, it is difficult to achieve storage of GB or more for low-power and resource-constrained sensors. Therefore, in embedded or IoT platforms, when the functions and usage scenarios are more complex, the ROTS system is usually chosen for function scheduling between sensors.
[0084] Currently, commonly used RTOS systems include FreeRTOS, uc / OS-II, Zypher, and RT-Thread, but most of these RTOS systems only implement driver programs for sensor control, such as... Figure 1 As shown, Figure 1 This is a schematic diagram illustrating the framework of an RTOS system according to an exemplary embodiment. By registering sensors as character devices, applications can perform differential control of the sensors through character device nodes to meet the functional requirements of embedded platforms or Internet of Things (IoT) platforms.
[0085] The following section uses the RT-Thread system as an example to briefly introduce RTOS systems; Figure 2 , Figure 3 As shown, Figure 2This is a schematic diagram of a sensor driving framework for an RT-Thread system according to an exemplary embodiment. Figure 1 ; Figure 3 This is a schematic diagram of a sensor driving framework for an RT-Thread system according to an exemplary embodiment. Figure 2 In the RT-Thread system, the sensor driver layer provides driver interfaces (e.g., open, close, read, or control) to the application layer, enabling the application to open the corresponding sensor character device node and access the sensor's driver layer. The sensor driver layer also provides operation command interfaces (fetch_data or control) to the underlying drivers, which interface with the underlying drivers of the specific sensor hardware to control the sensor.
[0086] In RTOS systems, the development model of software algorithms is integrated with the underlying driver, resulting in the data processing code at the driver level and the code within the software algorithm being intertwined. When multiple applications simultaneously read the sensing data from a single sensor, complex mutual exclusion code and downsampling code to meet different sampling rates need to be implemented in the driver. This increases the difficulty and development cycle of application development and also makes program errors more likely to occur.
[0087] In response, this disclosure provides a control method. Figure 4 This is a flowchart illustrating a control method according to an exemplary embodiment. Figure 1 ,like Figure 4 As shown, the method includes:
[0088] Step S101: The service layer broadcasts the topic information of the sensor data to the application layer, wherein different sensor data are generated by different sensors.
[0089] Step S102: In response to the application layer's subscription request for at least one topic information, the service layer controls the driving layer corresponding to at least one of the topic information to read target sensing data from the sensor.
[0090] Step S103: The service layer publishes the target sensing data to the application layer.
[0091] The control method provided in this disclosure is applied to a control system, which includes an application layer, a service layer, and multiple driver layers.
[0092] In step S101, the topic information may include: topic name, content of sensor data, and type of sensor data, etc. For example, the topic information may be accelerometer data, audio data, Bluetooth WiFi status, or any intermediate quantity generated by the system.
[0093] It should be noted that different topic information has a unique name. Different topic information can also correspond to different structures. The structure contains descriptive information about the topic status. For example, the name of the topic information could be "accelerometer data," and its corresponding structure could contain x, y, and z-axis acceleration vectors and timestamp messages.
[0094] The service layer can obtain sensing data from different sensors within the control system, determine the topic information based on the sensing data, and broadcast the topic information to the application layer through a preset interface.
[0095] In some embodiments, the preset interface may be a Micro Object RequestBroker (uORB) interface, through which topic information is broadcast.
[0096] It should be noted that the uORB interface is an application programming interface (API) for asynchronous publish-subscribe messaging between threads / processes. As an asynchronous communication mechanism, the uORB interface does not guarantee that all data published by the publisher will be received by the subscriber; it only guarantees that the subscriber will receive the latest data when it wants to receive it. In other words, during communication, the publisher is only responsible for publishing data and does not care who receives the data or whether the subscriber receives all the data. Similarly, the subscriber does not care who published the data or whether it receives all the data during the reception process.
[0097] For example, the service layer can use uORB interfaces such as orb_advertise or orb_advertise_multi to broadcast the topic information of the sensor data. When an application in the application layer subscribes to the topic information of a certain sensor data using interfaces such as orb_subscribe or orb_subscribe_multi, the service layer will receive a notification.
[0098] In step S102, each application in the application layer subscribes to the topic information of the sensing data it needs based on the topic information broadcast by the service layer. After receiving the subscription request from the application layer, the service layer controls the driver layer corresponding to the topic information to read the target sensing data from the sensor.
[0099] It should be noted that different sensors correspond to different driving layers. The service layer can determine the sensing data required by the application layer based on the topic information targeted by the subscription request, and thus control the corresponding driving layer to read the target sensing data from the connected sensor.
[0100] The subscription request may be a request from one application in the application layer to obtain one or more topic information, or it may be a subscription request from multiple applications in the application layer for one or more topic information. This disclosure does not limit this.
[0101] In step S103, after the driver layer reads the target sensing data from the sensor, the service layer obtains the target sensing data from the driver layer and publishes the target sensing data to the application in the application layer that has subscribed to the topic information of the target sensing data through a preset interface, so that the application can obtain the target sensing data.
[0102] In some embodiments, the preset interface may be a uORB interface;
[0103] For example, after the service layer obtains the target sensing data from the driver layer, it can publish the target sensing data using a uORB interface (such as orb_publish). All applications that have subscribed to the topic information of the target sensing data will be notified, and the applications can use the uORB interface (such as orb_copy) to obtain the target sensing data.
[0104] When multiple applications in the application layer subscribe to the same topic information of sensor data, since the uORB interface is based on shared memory between multiple processes for data transmission, the uORB interface can distribute sensor data to multiple applications through shared memory, thereby reducing mutual exclusion problems between applications.
[0105] This disclosure introduces a service layer that interacts with the application layer, thereby eliminating the need to focus on sensor drivers during application development and reducing the difficulty of application development. By interacting with the sensor driver layer through the service layer, the sensor device is controlled and the sensor data collected by the sensor is published based on the subscription of the topic information of the sensor data, thus completely decoupling the application layer and the driver layer.
[0106] Optionally, the driving layer includes:
[0107] The first sublayer, wherein different first sublayers contain drivers for different sensors for interacting with the sensors;
[0108] The second sublayer is a common driving sublayer shared by different sensors. It provides storage space for writing sensor data by interacting with the first sublayer.
[0109] In this embodiment of the disclosure, the driving layer may include: a first sub-layer and a second sub-layer; the first sub-layer contains a driver program for a sensor corresponding to the driving layer, and access to the sensor can be achieved by calling the corresponding operation function from the first sub-layer.
[0110] It is understandable that, since different sensors require their own unique drivers to function, the first sub-layer needs to contain the drivers for the connected sensors in order to enable the first sub-layer to interact directly with them; since different first sub-layers connect to different sensors, different first sub-layers contain drivers for different sensors.
[0111] The second sublayer is a general driver sublayer shared by different sensors. This second sublayer does not interact with the sensors and is used to provide general functions for the sensors, such as registering character device nodes, batch mode management, or reference counting.
[0112] It should be noted that, since different sensors have different drivers, when there are many sensors in the control system, the amount of driver code contained in the driver layer of the sensors is large. In order to reduce redundant code and increase reusability, the driver layer of the sensors in this embodiment can be divided into a first sub-layer and a second sub-layer. The second sub-layer contains the same parts of the drivers of multiple sensors (i.e., the drivers of the general functions of the sensors), so that a copy of the code of the second sub-layer can be retained during code implementation. By calling the code of the second sub-layer, the general functions of the sensors can be realized.
[0113] The service layer can acquire target sensing data from the sensor by controlling the first sub-layer. The second sub-layer interacts with the first sub-layer to write the target sensing data acquired from the first sub-layer into the storage space of the second sub-layer, so that the service layer can read the target sensing data from the storage space of the second sub-layer.
[0114] It should be noted that different sensors have different driving layers, and the storage spaces in the second sub-layer of different sensors are independent of each other and will not affect each other. For example, they are all in the memory or flash memory of a smartphone. However, the memory or flash memory is divided into different storage areas as needed to separate them, so they will not affect each other.
[0115] Optionally, the storage space is a ring-shaped storage space;
[0116] After the second storage address of the ring-shaped storage space is occupied, the target sensing data is written to the first storage address of the ring-shaped storage space, wherein the first storage address is the starting storage address of the storage area corresponding to the ring-shaped storage space; and the second storage address is the ending storage address of the storage area corresponding to the ring-shaped storage space.
[0117] In this embodiment of the disclosure, the storage space of the second sub-layer can be a circular storage space. It should be noted that the circular storage space is a data structure used to represent a storage area of fixed length that is connected end to end. The circular storage space usually has a read pointer and a write pointer. The read pointer points to the storage location of readable data in the circular storage space, and the write pointer points to the storage location of writable data in the circular storage space. By moving the read pointer and the write pointer, data reading and writing in the circular storage space can be realized.
[0118] After the first sub-layer acquires target sensing data from the sensor, it transmits the target sensing data to the second sub-layer. The second sub-layer determines whether the circular buffer space is full by judging whether the second storage address in the circular storage space is occupied. If the second storage address in the circular storage space is not occupied, that is, the circular storage space is not full, the target sensing data can be written to the storage address corresponding to the write pointer of the circular storage space.
[0119] If the second storage address of the ring storage space is occupied, that is, the ring storage space is full, the write pointer of the ring storage space can be moved to the first storage address of the ring storage space, so as to write the target sensing data to the first storage address and overwrite the data originally stored at the first storage address.
[0120] It should be noted that since the circular storage space is a first-in-first-out circular storage space, when the circular storage space is full and new data needs to be stored, the new data can be directly stored in the starting storage address of the storage area corresponding to the circular storage space, and the oldest historical data stored in the starting storage address can be discarded, thus avoiding the need for frequent memory allocation.
[0121] Optionally, in step S102, the service layer controls at least one driving layer corresponding to the topic information to read target sensing data from the sensor, including:
[0122] The service layer sends a control command to the first sub-layer; the control command is used to trigger the first sub-layer to read target sensing data from the connected sensor and write the target sensing data into the storage space of the second sub-layer;
[0123] After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer.
[0124] In this embodiment of the disclosure, the service layer sends a control command to the first sub-layer. Since the first sub-layer contains a driver program for the sensor, the service layer can call the operation function corresponding to the control command from the first sub-layer to control the sensor to perform the corresponding operation and write the acquired target sensing data into the storage space of the second sub-layer. After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it can directly obtain the target sensing data from the storage space to control the sensor.
[0125] In some embodiments, if the service layer does not detect the subscription request of the application layer within a preset time period, the service layer sends a shutdown command to the first sub-layer. The shutdown command is used to trigger the first sub-layer to control the connected sensor to switch to a shutdown state.
[0126] It should be noted that if no subscription request is detected in the application layer within the preset time period, it means that the application layer does not need the sensor data at this time. Therefore, the service layer can control the sensor to switch to the off state to reduce power consumption.
[0127] In other embodiments, if the service layer receives a subscription cancellation request from the application layer, and the topic information of the sensor data indicated by the subscription cancellation request has not been subscribed to by other applications of the application layer, the service layer issues a shutdown command to the first sub-layer corresponding to the topic information.
[0128] In this embodiment of the disclosure, if an application in the application layer unsubscribes from the topic information of the sensor data, the service layer will receive an unsubscribe notification; if all applications that have subscribed to the topic information of a certain sensor data unsubscribe from the topic information, the service layer can control the sensor corresponding to the topic information to switch to a relationship state, thereby achieving the effect of reducing power consumption.
[0129] Optionally, in step S102, the service layer controls at least one driving layer corresponding to the topic information to read target sensing data from the sensor, including:
[0130] The service layer sends a parameter adjustment instruction to the first sub-layer; the parameter adjustment instruction is used to trigger the first sub-layer to adjust the acquisition parameters, read the target sensing data from the connected sensor based on the adjusted acquisition parameters, and write the target sensing data into the storage space of the second sub-layer;
[0131] After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer.
[0132] In this embodiment of the disclosure, if the application layer sends parameter setting information to the service layer through a preset interface, the service layer can issue a parameter adjustment instruction to the first sub-layer according to the parameter setting information, so that the first sub-layer can obtain target sensing data from the connected sensor according to the acquisition parameters indicated by the parameter adjustment instruction; and write the target sensing data into the storage space of the second sub-layer.
[0133] Here, the preset interface can be a uORB interface. For example, the application can set the sensor's sampling rate by using the uORB interface (such as orb_set_interval).
[0134] In some embodiments, the method further includes:
[0135] In response to the parameter setting information of the application layer used to indicate multiple sampling frequencies, the service layer determines the maximum sampling frequency;
[0136] Based on the maximum sampling frequency, a parameter control command is sent to the first sub-layer. The parameter control command is used to trigger the first sub-layer to acquire target sensing data from the connected sensor based on the maximum sampling frequency, and write the target sensing data into the storage space of the second sub-layer.
[0137] After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer, performs downsampling processing on the target sensing data, and obtains multiple target sensing data that meet multiple sampling frequencies.
[0138] Here, the parameter setting information may include: settings indicating the sensor's acquisition parameters and / or the sensor's operating parameters. For example, the parameter setting information may be the sensor's acquisition frequency and / or acquisition mode, etc. The sensor's operating parameters include, but are not limited to: the sensor's operating time period parameters, the sensor's operating mode parameters, and / or the sensor's power parameters, etc.
[0139] In this embodiment of the disclosure, the parameter setting information refers to different acquisition frequencies of the same sensor indicated by multiple applications in the application layer.
[0140] In this embodiment of the disclosure, if multiple applications in the application layer subscribe to the same topic information, and the sampling frequencies of the sensor data subscribed to by different applications are different, the service layer can determine the maximum sampling frequency based on the sampling frequencies in the multiple subscription requests; based on the maximum sampling frequency, it sends a parameter adjustment instruction to the first sub-layer; the first sub-layer acquires target sensor data from the sensor according to the maximum sampling frequency indicated by the parameter adjustment instruction, and writes the acquired target sensor data into the storage space of the second sub-layer; after the service layer acquires the target sensor data from the storage space, it performs downsampling processing on the target sensor data to obtain target sensor data with different sampling frequencies, thereby publishing the target sensor data with different sampling frequencies to the application layer.
[0141] Optionally, the acquisition parameters include:
[0142] The frequency of sensor data acquisition;
[0143] And / or, the sensor data acquisition mode, wherein different acquisition modes correspond to different preset lengths and / or different reading methods for the sensor data read from the ring storage space by the service layer.
[0144] In this embodiment of the disclosure, if the acquisition parameter can be the acquisition frequency of the sensing data, the service layer can send a parameter adjustment instruction to the first sub-layer according to the sampling frequency indicated by the subscription request; the first sub-layer reads the target sensing data from the connected sensor according to the acquisition frequency indicated by the parameter adjustment instruction, and writes the acquired target sensing data into the storage space of the second sub-layer, so that the service layer can read the target sensing data from the storage space and publish the target sensing data to the application in the application layer that has subscribed to the topic information of the sensing data.
[0145] The sensor data acquisition modes may include: interrupt control mode, polling mode, and first-in-first-out (FIFO) mode;
[0146] It should be noted that if the sensor data reading mode is interrupt control mode, when the service layer receives the subscription request, it sends a control command to the first sub-layer to trigger the generation of an interrupt signal. After the first sub-layer detects the interrupt signal, it reads the target sensor data from the sensor and writes the target sensor data into the storage space of the second sub-layer so that the service layer can read the target sensor data.
[0147] If the sensor data reading mode is polling mode, the first sub-layer periodically acquires target sensor data from the sensor; the target sensor data is written into the storage space of the second sub-layer so that when the service layer receives a subscription request, it can directly read the target sensor data from the storage space.
[0148] The FIFO mode requires sensor hardware support. When the sensor data reading mode is FIFO mode, the service layer sends a control command to the first sub-layer to control the first sub-layer to read a preset length of target sensor data. The first sub-layer can read the target sensor data from the sensor and store the read target sensor data in the hardware FIFO. After the hardware FIFO has stored a preset length of target sensor data, the preset length of target sensor data is written into the storage space of the second sub-layer. It does not need to wait for the service layer to generate an interrupt signal every time to read a target sensor data, thereby saving CPU resources and making it suitable for low-power mode.
[0149] If the acquisition parameters are the reading mode of the sensor data, the service layer can send a parameter adjustment instruction to the first sub-layer according to the reading mode indicated by the subscription request. The first sub-layer reads the target sensor data of a preset length from the connected sensor according to the reading mode indicated by the parameter adjustment instruction and the reading method corresponding to the reading mode. The read target sensor data is written into the storage space of the second sub-layer so that the service layer can read the target sensor data from the storage space of the second sub-layer and publish the target sensor data to the application in the application layer that has subscribed to the topic information of the sensor data.
[0150] Optionally, after the service layer detects an update to the data stored in the storage space of the second sub-layer, it retrieves the target sensing data from the storage space of the second sub-layer, including:
[0151] After detecting an update to the data stored in the storage space of the second sub-layer, the service layer sequentially reads the sensor data of a preset length from the data reading position indicated by the read pointer of the storage space.
[0152] Then move the read pointer to the next position after the current read position.
[0153] In this embodiment of the disclosure, since the storage space of the second sub-layer is a circular storage space, after the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it can sequentially read the target sensing data of a preset length stored in the circular storage space, starting from the data reading position indicated by the read pointer of the circular storage space. After the data reading is completed, the read pointer of the circular storage space is moved to the next position after the current reading position to facilitate the reading of subsequent sensing data and reduce the problem of repeatedly reading the same sensing data.
[0154] It should be noted that the preset lengths for different reading modes are different. For example, in interrupt control mode, the sensor data is read once every time an interrupt signal is received, so the preset length for interrupt control mode can be the length of the sensor data. In contrast, in FIFO mode, multiple sensor data are read from the sensor after receiving a control command, so the preset length for FIFO mode can be the length of multiple sensor data.
[0155] Optionally, in step S101, the service layer broadcasts the topic information of the sensor data to the application layer, including:
[0156] The service layer obtains the type information of the first type of registered sensors within the control system;
[0157] Based on the type information of the first type of sensor, the subject information of the sensing data sensed by the first type of sensor is determined; wherein, the first type of sensor is a sensor that only has a preset function;
[0158] The service layer broadcasts the topic information of the sensing data sensed by the first type of sensor to the application layer.
[0159] In this embodiment of the disclosure, the first type of sensor may be a sensor of a preset type, which only has preset functions; here, the preset type can be set according to the actual situation. For example, the first type of sensor includes 25 known types of sensors such as accelerometers, gyroscopes or magnetometers.
[0160] The service layer obtains the type information of the first type of sensor by scanning the character device nodes of the first type of sensor registered in the control system; based on the type information of the first type of sensor, it generates topic information of the sensing data sensed by the first type of sensor, and broadcasts the topic information of the sensing data to the application layer through a preset interface, so that the application in the application layer can subscribe to the sensing data it needs based on the topic information.
[0161] It should be noted that, in this embodiment of the disclosure, all first-type sensors within the control system are managed and controlled uniformly through a service layer. The service layer actively obtains the type information of the first-type sensors to determine the topic information of the sensing data sensed by the first-type sensors. The service layer then broadcasts the topic information of the sensing data to the application layer so that each application in the application layer can subscribe to the sensing data it needs based on the topic information.
[0162] Optionally, the method further includes:
[0163] The application layer sends control commands to the registered second-type sensors in the control system through a preset operation function interface;
[0164] The control command is used to trigger the driver layer of the second type of sensor to call the operation function corresponding to the operation function interface, execute the control command, and transmit the execution result to the application layer through the operation function interface.
[0165] In this embodiment of the disclosure, the second type of sensor may be a sensor that does not have a preset function or has both a preset function and other complex functions; the second type of sensor is not uniformly managed by the service layer, but needs to be directly controlled and managed by the application layer.
[0166] The application layer can directly open the character device node of the second type of sensor through a preset operation function interface, thereby accessing the driver layer of the second type of sensor to issue control commands to the second type of sensor; the driver layer of the second type of sensor controls the second type of sensor to execute the control commands by calling the operation function corresponding to the operation function interface, and obtains sensing data from the second type of sensor, and transmits the sensing data to the application layer through the operation function interface.
[0167] Here, the preset operation function interface can be a functional interface predefined during the application layer development process to adapt to the driver program of the second type of sensor. For example, open, close, read, or control interfaces.
[0168] It should be noted that, since the operation of the second type of sensor is not universal and the type of sensor it senses is uncertain, the service layer cannot directly control the second type of sensor. Therefore, in order to facilitate the control of the second type of sensor, the application layer application needs to be adapted to the driver of the second type of sensor. Based on the driver of the second type of sensor, the operation function interface of the second type of sensor is predefined, so that the application layer application can directly access the character device node of the second type of sensor through the operation function interface, thereby controlling the second type of sensor.
[0169] In some embodiments, to facilitate data interaction between sensors within the control system and the service layer or application layer, the sensors need to be registered within the control system; therefore, the method further includes:
[0170] Based on the sensor driver program within the first sub-layer, the second sub-layer determines the type information of the sensor;
[0171] The second sub-layer registers the character device corresponding to the sensor based on the sensor type information.
[0172] In this embodiment of the disclosure, since character devices can use the same file operation commands as ordinary files to operate on character device files, after a physical connection is established with the sensor, a character device file needs to be created for the sensor in order to operate on the data collected by the sensor.
[0173] It is understandable that sensors can be divided into first-class sensors and second-class sensors. The functions of first-class sensors and second-class sensors may be different. First-class sensors only have preset functions and can be uniformly managed by the service layer. Second-class sensors need to be controlled and managed by the application layer. Therefore, when registering the sensors, it is necessary to distinguish between first-class sensors and second-class sensors according to the sensor type information and register first-class sensors and second-class sensors separately.
[0174] If the sensor is a first type of sensor, the second sub-layer can determine the identification information of the character device corresponding to the first type of sensor based on the type information of the first type of sensor, and register the character device corresponding to the first type of sensor;
[0175] If the sensor is a second type of sensor, based on the driver program for the second type of sensor in the first sub-layer, the second sub-layer determines the storage space address, storage capacity, and identification information of the second type of sensor; based on the storage space address, the storage capacity, and the identification information, it registers the character device corresponding to the second type of sensor.
[0176] Here, the identification information may be the name and / or ID number of the character device; the character device can be uniquely identified through the identification information.
[0177] The service layer can identify the character devices of the first type of sensor and the topic information of the sensing data sensed by the first type of sensor by obtaining the identification information of all character devices within the control system, and then broadcast the topic information to the application layer. The application layer obtains the sensing data sensed by the first type of sensor by subscribing to the topic information.
[0178] If the application layer needs to obtain the sensing data of the second type of sensor, it needs to predefine the operation function interface according to the driver of the second type of sensor so that in the subsequent processing, the application layer can directly access the character device of the second type of sensor through the operation function interface to obtain the sensing data sensed by the second type of sensor.
[0179] This disclosure also provides the following embodiments:
[0180] Figure 5 This is a flowchart illustrating a control method according to an exemplary embodiment. Figure 2 The method includes:
[0181] Step S201: The service layer obtains the type information of the first type of sensor registered in the control system; based on the type information of the first type of sensor, it determines the topic information of the sensing data sensed by the first type of sensor; the service layer broadcasts the topic information of the sensing data sensed by the first type of sensor to the application layer.
[0182] In this example, the control method is applied in a control system, which includes an application layer, a service layer, and multiple driver layers. Figure 6 As shown, Figure 6 This is a schematic diagram of the software framework of a control system according to an exemplary embodiment. The software framework of the control system mainly includes: an application layer, a sensor service layer, and a sensor driver layer.
[0183] Here, the service layer can be a sensor service layer, which provides the ability to publish sensor data and perform automatic control. The driver layer can be a sensor driver layer; the sensor driver layer provides the ability to interact with sensor devices.
[0184] The driving layer includes:
[0185] The first sublayer, wherein different first sublayers contain drivers for different sensors for interacting with the sensors;
[0186] The second sublayer is a common driving sublayer shared by different sensors. It provides storage space for writing sensor data by interacting with the first sublayer.
[0187] In this example, the first sub-layer can be the lower layer, and the second sub-layer can be the upper layer. The upper layer does not interact with the actual sensor device; it provides general functions for the sensor driver layer, such as registering device nodes, binding syscall callback sets, multi-user access, providing a circular buffer, batch mode management, and sensor control. The lower layer is the actual driver, responsible for interacting with the sensor device, including activation, sampling rate setting, batch processing, etc., and transferring the sensor data collected from the sensor device to the upper layer's storage space.
[0188] It should be noted that in a control system, each sensor device corresponds to a sensor driver layer. To reduce redundant code and improve reusability, the sensor driver layer can be divided into an upper layer and a lower layer. The upper layer of each sensor device is the same, providing common functions for the sensor device. Therefore, in the code implementation, only one set of upper layer driver code needs to be written; each sensor driver can call this upper layer code. The lower layer is the actual driver program, and the code for the lower layer is different for each sensor device.
[0189] This can be achieved by extracting the common parts of the drivers for all sensor devices in the control system as the upper layer, and the remaining drivers as the lower layer; for example... Figure 7 As shown, Figure 7 This is a schematic diagram of a sensor driver layer framework according to an exemplary embodiment. The data structure `struct lowerhalf_s` acts as a bridge connecting the upper and lower layers. Upward, it expresses the sensor type, ring storage size, sensor data calibration flag, and control set for sensor behavior of the lower layer; downward, it transmits event push notifications, event push interfaces, and pointers to the upper layer.
[0190] Understandably, in this example, the driver layer only focuses on physical sensor types. Virtual sensor types are integrated from upper-layer applications and are not considered here. `struct lowerhalf_s` represents a specific physical sensor type, such as an accelerometer.
[0191] In some embodiments, depending on the type of sensor module, it can be divided into: single-chip single sensor, such as IAM20381, which only contains a three-axis accelerometer; and single-chip multi-sensor, such as ICM20948, a nine-axis IMU, which contains an accelerometer, a gyroscope and a magnetometer.
[0192] Understandably, different types of sensor modules require different driver models. For a sensor module integrating multiple sensors, multiple `struct lowerhalf_s` bridges need to be built to generate multiple character device nodes. For example... Figure 8 As shown, Figure 8 This is a schematic diagram illustrating a driving model of different sensor modules according to an exemplary embodiment.
[0193] In this example, the application layer and the sensor service layer interact through the uORB interface.
[0194] It's important to note that the uORB interface is a crucial module in the open-source flight controller PX4, primarily responsible for data transmission between various modules within the system. It acts as a message publish-subscribe middleware, and the uORB interface operates entirely independently of threads and work queues, mainly ensuring the initialization of some global data. Its communication is implemented based on shared memory between multiple processes.
[0195] The uORB interface is an asynchronous communication mechanism with two roles: a publisher, which publishes generated data as topics through the uORB interface; and a subscriber, which subscribes to information it is interested in as topics through the uORB interface. Because the publisher and subscriber use completely separate storage spaces, they do not affect or wait for each other.
[0196] The uORB interface boasts optimal code size and provides low-latency data exchange. Its implementation is based on system calls such as open, read, write, close, and ioctl. Porting uORB is also very simple; it only requires the system's lib C++ library to participate in the compilation process and resolve some compilation errors to achieve successful porting.
[0197] The topic can be specific sensor data, such as accelerometer data; or it can be any intermediate quantity generated by the system. Each topic will have a specific and unique name and a corresponding structure, which contains a description of the topic's state. For example, the structure corresponding to the accelerometer contains x, y, and z-axis acceleration vectors and timestamp messages.
[0198] The sensor service layer can use uORB interfaces such as orb_advertise and orb_advertise_multi to broadcast topics for all sensors in the system. When an application in the application layer subscribes to a specified sensor topic using orb_subscribe or orb_subscribe_multi, the sensor service layer will be notified and will interact with the driver layer to enable the sensor hardware.
[0199] In this example, the control system includes: a first type of sensor and a second type of sensor; wherein, the first type of sensor is a sensor that only has a preset function.
[0200] The first type of sensor is managed uniformly by the sensor service layer, while the second type of sensor is a custom type of sensor that is controlled and managed by the upper layer application. Unconventional operations can be performed on the second type of sensor to achieve complex function control.
[0201] It should be noted that the sensor driver layer registers itself as a character device node with the user. The application layer or sensor service layer controls the sensor corresponding to the character device node by performing operations such as opening and reading the character device node.
[0202] For the first type of sensor, a character device node can be registered using the instance lowerhalf pointer and the device number;
[0203] int sensor_register(structsensor_lowerhalf_s*dev, int devno);
[0204] void sensor_unregister(structsensor_lowerhalf_s*dev, int devno);
[0205] In this system, the upper layer of the first type of sensor device determines the name and ID of the character device node based on the sensor type. The first type of sensor can be any of 25 preset sensor types.
[0206] For the second type of sensor, the character device node of the second type of sensor can be registered by instantiating the lowerhalf pointer and device node address and the custom sensorevent buffer size.
[0207] int sensor_custom_redister(structsensor_lowerhalf_s*lower, const char*path, uint8_tesize);
[0208] void sensor_custom_unregister(FAR structsensor_lowerhalf_s*lower, const char*path);
[0209] Understandably, since the second type of sensor not only has preset functions but also other functions, it is necessary to customize the interface for the other functions of the second type of sensor.
[0210] In this example, for the first type of sensor, the application layer (APP) can obtain sensor data by subscribing to the topic information of the sensor data published by the sensor service layer through the UORB interface instead of directly accessing the character device node to control and acquire sensor data.
[0211] During the control system startup process, the sensor service layer scans all registered Type I sensors in the control system, determines the topic information of the sensing data sensed by the Type I sensors based on the type of the Type I sensors, and broadcasts the topic information of the sensing data to the application layer through the uORB interface, so that the application layer can determine whether it needs to subscribe to the sensing data based on the topic information.
[0212] In some embodiments, if the service layer does not detect a subscription request for the topic information from the application layer, the sensor service layer can turn off the sensor to save power.
[0213] In step S202, in response to the application layer's subscription request for at least one topic information, the service layer sends a control instruction to the first sub-layer of the driver layer; the control instruction is used to trigger the first sub-layer to read target sensing data from the connected sensor and write the target sensing data into the storage space of the second sub-layer of the driver layer.
[0214] In this example, the application layer determines the sensor data it needs based on the topic information of the sensor data broadcast by the sensor service layer, and subscribes to the topic information corresponding to the sensor data. When the sensor service layer detects that the application layer has subscribed to at least one topic information, the sensor service layer controls the lower layer of the sensor driver layer to enable the sensor interrupt, obtain the sensor data, and reports the sensor data to the upper layer for storage in the upper layer's storage space.
[0215] In some embodiments, the method further includes:
[0216] The service layer sends a parameter adjustment instruction to the first sub-layer; the parameter adjustment instruction is used to trigger the first sub-layer to adjust the acquisition parameters, read the target sensing data from the connected sensor based on the adjusted acquisition parameters, and write the target sensing data into the storage space of the second sub-layer;
[0217] In this example, the application layer can control the sensors in the control system according to its own needs. The application layer can send parameter setting information to the sensor service layer by calling the uORB interface. The sensor service layer issues parameter adjustment instructions to the lower layer according to the parameter setting information. After receiving the parameter adjustment instructions, the first sub-layer reads the target sensing data from the connected sensor according to the acquisition parameters indicated by the parameter adjustment instructions, and writes the read target sensing data into the storage space of the upper layer.
[0218] The collected parameters include:
[0219] The frequency of sensor data acquisition;
[0220] And / or, the sensor data acquisition mode, wherein different acquisition modes correspond to different preset lengths and / or different reading methods for the sensor data read from the ring storage space by the service layer.
[0221] In this example, the application layer can set the sensor's sampling frequency by calling the uORB interface orb_set_interval. When multiple applications set different sampling frequencies, the sensor service layer determines the maximum sampling frequency and generates parameter adjustment instructions based on the maximum sampling frequency to send to the lower layer. After the sensor service layer obtains the sensor data collected based on the maximum sampling frequency, uORB internally performs downsampling processing on the sensor data at the maximum sampling frequency to obtain sensor data at different sampling frequencies, which are then sent to different applications.
[0222] The sensor data acquisition modes may include: FIFO mode, polling mode, and interrupt control mode; different acquisition modes correspond to different preset lengths and / or different reading methods for the service layer to read sensor data from the ring storage space.
[0223] Step S203: After detecting that the data stored in the storage space of the second sub-layer has been updated, the service layer starts from the data reading position indicated by the read pointer of the storage space and sequentially reads the sensor data of a preset length in the storage space; and moves the read pointer to the next position after the current reading position.
[0224] In this example, the storage space is a ring-shaped storage space;
[0225] After the second storage address of the ring-shaped storage space is occupied, the target sensing data is written to the first storage address of the ring-shaped storage space, wherein the first storage address is the starting storage address of the storage area corresponding to the ring-shaped storage space; and the second storage address is the ending storage address of the storage area corresponding to the ring-shaped storage space.
[0226] After the lower layer acquires sensing data from the sensor and transmits it to the upper layer, the upper layer determines whether the second storage address of the ring-shaped storage space is occupied, and whether the ring-shaped storage space is full. If the second storage address of the ring-shaped storage space is not occupied, that is, the ring-shaped storage space is not full, the target sensing data can be stored after the storage location of the data already stored in the ring-shaped storage space. If the second storage address of the ring-shaped storage space is occupied, that is, the ring-shaped storage space is full, the target sensing data can be stored in the first storage address of the ring-shaped storage space, that is, the data stored in the first storage address of the first ring-shaped storage space is overwritten.
[0227] Understandably, by setting the upper layer's storage space as a circular storage space, frequent memory allocation is not required, and overflow can be effectively avoided; this also compensates for data loss caused by application lag, delay, or failure to read data in a timely manner.
[0228] In this example, the preset length of the target sensor data to be read can be determined based on the sensor data reading pattern. When the sensor service layer detects that the data stored in the upper layer's storage space has been updated, the sensor service layer starts from the data reading position indicated by the read pointer of the storage space, reads the preset length of sensor data in sequence, and moves the read pointer to the next position after the current reading position to facilitate the next reading.
[0229] Step S204: The service layer publishes the target sensing data to the application layer;
[0230] In this example, after the service layer obtains the target sensing data, it publishes the target sensing data through the uORB interface. The application in the application layer that subscribes to the topic information of the target sensing data receives the target sensing data through the uORB interface.
[0231] In step S205, the application layer sends a control command to the second type of sensor registered in the control system through a preset operation function interface; the control command is used to trigger the driver layer of the second type of sensor to call the operation function corresponding to the operation function interface, execute the control command, and transmit the execution result to the application layer through the operation function interface.
[0232] In this example, because the operation of the second type of sensor is not universal and the event type is uncertain, it cannot be uniformly managed by the sensor service layer. When the application layer application needs to use system calls to directly access the character device node of the second type of sensor in order to control the second type of sensor.
[0233] It should be noted that for standard type sensors, when the control of the sensor service layer cannot meet the product requirements, that is, in addition to activation, acquisition rate setting and batch processing, additional control of the sensor is required. This can be achieved by setting control commands separately through the control interface and assigning them to the character device node, thereby transmitting the control commands to the sensor's driver layer so that the driver layer can respond to the control commands.
[0234] For example, such as Figure 9 As shown, Figure 9 This is a flowchart illustrating a control method according to an exemplary embodiment. Figure 3 .
[0235] Step S301: Start the control system;
[0236] Step S302: The service layer scans and opens the character device files of all first-class sensors in the control system to obtain file handles;
[0237] Step S303: The service layer broadcasts the topic information of the sensing data of the first type of sensor to the application layer to obtain the advertising handle;
[0238] Step S304: Add all file handles and ad handles to the epoll queue for monitoring;
[0239] Step S305: Determine the handle type. If the handle is an advertising handle, proceed to step S306; if the handle is a file handle, proceed to step S307.
[0240] Step S306: Based on the advertising handle, the service layer controls the activation state, sampling rate, and batch processing mode of the corresponding sensor.
[0241] Step S305: Based on the file handle, the service layer controls the corresponding driver layer to acquire the sensor data.
[0242] In this example, the service layer manages and controls all first-type sensors within the system. However, for second-type sensors, due to their non-universal operation and uncertain sensor data types, they cannot be managed uniformly by the service layer. Therefore, the application needs to use system calls to access the character devices of the second-type sensors.
[0243] Because this example introduces a service layer that completely decouples the application layer and the sensor driver layer, the sensor driver does not need to be considered during application development. Below, this example also provides a model for software algorithm development, such as... Figure 10 As shown, Figure 10 This is a schematic diagram illustrating an application development framework according to an exemplary embodiment.
[0244] When uncalibrated sensor data is read by the service layer through the character device node and published via the uORB interface, the calibration algorithm application can obtain uncalibrated sensor data by subscribing to the topic information of the uncalibrated sensor data, and publish the calibrated sensor data after completing the calibration process of the uncalibrated sensor data; the motion algorithm application can obtain calibrated sensor data and uncalibrated sensor data by subscribing to the topic information of both calibrated and uncalibrated sensor data.
[0245] In this way, by introducing a service layer to completely decouple the application layer from the sensor driver layer, when the underlying sensor hardware is replaced, there is no need to change the upper-layer algorithm logic and any intermediate variables, reducing workload and improving application development efficiency.
[0246] This disclosure also provides a control device. Figure 11 This is a schematic diagram of the structure of a control device according to an exemplary embodiment, such as... Figure 11 As shown, the control system includes an application layer, a service layer, and multiple driver layers. The control device 100 includes:
[0247] The broadcast module 101 is used by the service layer to broadcast the topic information of the sensor data to the application layer, wherein different sensor data are generated by different sensors.
[0248] The first acquisition module 102 is used to respond to the application layer's subscription request for at least one topic information, and the service layer controls the driving layer corresponding to at least one of the topic information to read target sensing data from the sensor;
[0249] The publishing module 103 is used by the service layer to publish the target sensing data to the application layer.
[0250] Optionally, the driving layer includes:
[0251] The first sublayer, wherein different first sublayers contain drivers for different sensors for interacting with the sensors;
[0252] The second sublayer is a common driving sublayer shared by different sensors. It provides storage space for writing sensor data by interacting with the first sublayer.
[0253] Optionally, the storage space is a ring-shaped storage space;
[0254] After the second storage address of the ring-shaped storage space is occupied, the target sensing data is written to the first storage address of the ring-shaped storage space, wherein the first storage address is the starting storage address of the storage area corresponding to the ring-shaped storage space; and the second storage address is the ending storage address of the storage area corresponding to the ring-shaped storage space.
[0255] Optionally, the first acquisition module 102 is configured to:
[0256] The service layer sends a control command to the first sub-layer; the control command is used to trigger the first sub-layer to read target sensing data from the connected sensor and write the target sensing data into the storage space of the second sub-layer; after the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer.
[0257] Optionally, the first acquisition module 102 is configured to:
[0258] The service layer sends a parameter adjustment instruction to the first sub-layer; the parameter adjustment instruction is used to trigger the first sub-layer to adjust the acquisition parameters, read the target sensing data from the connected sensor based on the adjusted acquisition parameters, and write the target sensing data into the storage space of the second sub-layer;
[0259] After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer.
[0260] Optionally, the acquisition parameters include:
[0261] The frequency of sensor data acquisition;
[0262] And / or, the sensor data acquisition mode, wherein different acquisition modes correspond to different preset lengths and / or different reading methods for the sensor data read from the ring storage space by the service layer.
[0263] Optionally, the first acquisition module 102 is further configured to:
[0264] After detecting an update to the data stored in the storage space of the second sub-layer, the service layer sequentially reads the sensor data of a preset length from the data reading position indicated by the read pointer of the storage space.
[0265] Then move the read pointer to the next position after the current read position.
[0266] Optionally, the broadcast module 101 is used for:
[0267] The service layer obtains the type information of the first type of registered sensors within the control system;
[0268] Based on the type information of the first type of sensor, the subject information of the sensing data sensed by the first type of sensor is determined; wherein, the first type of sensor is a sensor that only has a preset function;
[0269] The service layer broadcasts the topic information of the sensing data sensed by the first type of sensor to the application layer.
[0270] Optionally, the apparatus further includes: a second acquisition module, configured to:
[0271] The application layer sends control commands to the registered second-type sensors in the control system through a preset operation function interface;
[0272] The control command is used to trigger the driver layer of the second type of sensor to call the operation function corresponding to the operation function interface, execute the control command, and transmit the execution result to the application layer through the operation function interface.
[0273] Figure 12 This is a block diagram illustrating a control device according to an exemplary embodiment. For example, device 800 may be a mobile phone, mobile computer, etc.
[0274] Reference Figure 12 The device 800 may include one or more of the following components: a processing component 802, a memory 804, a power supply component 806, a multimedia component 808, an audio component 810, an input / output (I / O) interface 812, a sensor component 814, and a communication component 816.
[0275] Processing component 802 typically controls the overall operation of device 800, such as operations associated with display, telephone calls, data communication, camera operation, and recording. Processing component 802 may include one or more processors 820 to execute instructions to perform all or part of the steps of the methods described above. Furthermore, processing component 802 may include one or more modules to facilitate interaction between processing component 802 and other components. For example, processing component 802 may include a multimedia module to facilitate interaction between multimedia component 808 and processing component 802.
[0276] Memory 804 is configured to store various types of data to support the operation of device 800. Examples of this data include instructions for any application or method operating on device 800, contact data, phonebook data, messages, pictures, videos, etc. Memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0277] Power supply component 806 provides power to various components of device 800. Power supply component 806 may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power to device 800.
[0278] Multimedia component 808 includes a screen that provides an output interface between the device 800 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 808 includes a front-facing camera and / or a rear-facing camera. When the device 800 is in an operating mode, such as a shooting mode or a video mode, the front-facing camera and / or the rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
[0279] Audio component 810 is configured to output and / or input audio signals. For example, audio component 810 includes a microphone (MIC) configured to receive external audio signals when device 800 is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals may be further stored in memory 804 or transmitted via communication component 816. In some embodiments, audio component 810 also includes a speaker for outputting audio signals.
[0280] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.
[0281] Sensor assembly 814 includes one or more sensors for providing status assessments of various aspects of device 800. For example, sensor assembly 814 may detect the on / off state of device 800, the relative positioning of components such as the display and keypad of device 800, changes in the position of device 800 or a component of device 800, the presence or absence of user contact with device 800, the orientation or acceleration / deceleration of device 800, and temperature changes of device 800. Sensor assembly 814 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 814 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 814 may also include an accelerometer, a gyroscope, a magnetometer, a pressure sensor, or a temperature sensor.
[0282] Communication component 816 is configured to facilitate wired or wireless communication between device 800 and other devices. Device 800 can access wireless networks based on communication standards, such as Wi-Fi, 2G, or 3G, or combinations thereof. In one exemplary embodiment, communication component 816 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 816 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0283] In an exemplary embodiment, the apparatus 800 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the methods described above.
[0284] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 804 including instructions, which can be executed by a processor 820 of the device 800 to perform the above-described method. For example, the non-transitory computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0285] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0286] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A control method, characterized in that, The method is applied to a control system, which includes an application layer, a service layer, and multiple driver layers, and includes: The service layer broadcasts the topic information of the sensor data to the application layer, where different sensor data are generated by different sensors; In response to the application layer's subscription request for at least one topic information, the service layer controls the driver layer corresponding to at least one of the topic information to read target sensing data from the sensor; The service layer publishes the target sensing data to the application layer; The driving layer includes a first sub-layer and a second sub-layer. The first sub-layer includes a driver program for at least one sensor, used to interact with the at least one sensor. The second sub-layer is a general driving sub-layer shared by different sensors. The second sub-layer includes a storage space, which is used for the first sub-layer to write target sensing data obtained from the sensor, and for the service layer to read the target sensing data. In response to an application layer subscription request for at least one topic information, the service layer controls the driver layer corresponding to at least one of the topic information to read target sensing data from the sensor, including: In response to multiple subscription requests for the same topic information from multiple applications in the application layer, the service layer determines a maximum sampling frequency based on multiple sampling frequencies corresponding to the multiple subscription requests; wherein the multiple sampling frequencies corresponding to the multiple subscription requests are different. Based on the maximum sampling frequency, the service layer sends a parameter adjustment instruction to the first sub-layer; the parameter adjustment instruction is used to trigger the first sub-layer to read target sensing data from the connected sensor based on the maximum sampling frequency, and write the target sensing data into the storage space of the second sub-layer; After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it obtains the target sensing data from the storage space of the second sub-layer, performs downsampling processing on the target sensing data, and obtains multiple target sensing data that meet the multiple sampling frequencies.
2. The method according to claim 1, characterized in that, The storage space is a ring-shaped storage space; After the second storage address of the ring-shaped storage space is occupied, the target sensing data is written to the first storage address of the ring-shaped storage space, wherein the first storage address is the starting storage address of the storage area corresponding to the ring-shaped storage space; and the second storage address is the ending storage address of the storage area corresponding to the ring-shaped storage space.
3. The method according to claim 2, characterized in that, The service layer controls at least one driver layer corresponding to the topic information to read target sensing data from the sensor, including: The service layer sends a control command to the first sub-layer; the control command is used to trigger the first sub-layer to read target sensing data from the connected sensor and write the target sensing data into the storage space of the second sub-layer; After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer.
4. The method according to claim 2, characterized in that, In response to an application layer subscription request for at least one topic information, the service layer controls the driver layer corresponding to at least one of the topic information to read target sensing data from the sensor, including: In response to the sensor data reading mode indicated by the subscription request, the service layer sends a parameter adjustment instruction to the first sub-layer. The parameter adjustment instruction is used to trigger the first sub-layer to adjust the sensor data acquisition mode, read a preset length of target sensor data from the connected sensor based on the adjusted acquisition mode, and write the target sensor data into the storage space of the second sub-layer. Different acquisition modes correspond to different preset lengths of sensor data read from the storage space by the service layer and / or different reading methods. After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer.
5. The method according to claim 3 or 4, characterized in that, After the service layer detects an update to the data stored in the storage space of the second sublayer, it retrieves the target sensing data from the storage space of the second sublayer, including: After detecting an update to the data stored in the storage space of the second sub-layer, the service layer sequentially reads the sensor data of a preset length from the data reading position indicated by the read pointer of the storage space. Then move the read pointer to the next position after the current read position.
6. The method according to claim 1, characterized in that, The service layer broadcasts the subject information of the sensor data to the application layer, including: The service layer obtains the type information of the first type of registered sensors within the control system; Based on the type information of the first type of sensor, the subject information of the sensing data sensed by the first type of sensor is determined; wherein, the first type of sensor is a sensor that only has a preset function; The service layer broadcasts the topic information of the sensing data sensed by the first type of sensor to the application layer.
7. The method according to claim 6, characterized in that, The method further includes: The application layer sends control commands to the registered second-type sensors in the control system through a preset operation function interface; The control command is used to trigger the driver layer of the second type of sensor to call the operation function corresponding to the operation function interface, execute the control command, and transmit the execution result to the application layer through the operation function interface.
8. A control device, characterized in that, This is applied to a control system, which includes: an application layer, a service layer, and multiple driver layers, including: The broadcast module is used by the service layer to broadcast the topic information of sensor data to the application layer, where different sensor data are generated by different sensors. The first acquisition module is used to respond to the application layer's subscription request for at least one topic information, and the service layer controls the driver layer corresponding to at least one of the topic information to read target sensing data from the sensor; The publishing module is used by the service layer to publish the target sensing data to the application layer; The driving layer includes: a first sub-layer and a second sub-layer; the first sub-layer includes a driver for at least one sensor for interacting with the at least one sensor; the second sub-layer is a general driving sub-layer shared by different sensors, and the second sub-layer includes a storage space for the first sub-layer to write target sensing data acquired from the sensor, and for the service layer to read the target sensing data; The first acquisition module is configured to respond to multiple subscription requests for the same topic information from multiple applications in the application layer. The service layer determines a maximum sampling frequency based on multiple sampling frequencies corresponding to the multiple subscription requests, wherein the multiple sampling frequencies corresponding to the multiple subscription requests are different. Based on the maximum sampling frequency, the service layer sends a parameter adjustment instruction to the first sub-layer. The parameter adjustment instruction is used to trigger the first sub-layer to read target sensing data from connected sensors based on the maximum sampling frequency and write the target sensing data into the storage space of the second sub-layer. After the service layer detects that the data stored in the storage space of the second sub-layer has been updated, it retrieves the target sensing data from the storage space of the second sub-layer, performs downsampling processing on the target sensing data, and obtains multiple target sensing data that satisfy the multiple sampling frequencies.
9. A control device, characterized in that, include: processor; Memory used to store executable instructions; The processor is configured to implement the control method according to any one of claims 1 to 7 when executing executable instructions stored in the memory.
10. A non-transitory computer-readable storage medium, wherein when instructions in the storage medium are executed by a processor of a control device, the control device is enabled to perform the control method of any one of claims 1 to 7.