Log output method, IOT device and storage medium
By configured the UART tube foot to the GPIO input function when the IoT device is powered on, and the connection state is judged according to the level status, the IoT device storage space is limited and the UART output log increases power consumption. Output.
Patent Information
- Application Number
- CN202411337933.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-24
- Publication Date
- 2025-01-21
AI Technical Summary
Due to the high storage cost, the storage space of Internet of Things (IOT) devices is limited and cannot save logs in real time. When outputting logs through UART, the UART port needs to be configured to be normally open, which increases device power consumption.
When the IOT device is powered on, configure the UART receiving and transmitting pins as GPIO input functions, obtain the level status to determine whether the UART is connected, and if connected, configure the UART receiving and transmitting functions to output log information.
By configuring the pin to the GPIO function, the power consumption of the IOT device is reduced, the log output function is realized, and the high power consumption when continuously configured as the UART function is avoided.
Smart Images

Figure CN119342048A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a log output method, an IOT device, and a storage medium. Background Art
[0002] At present, due to the high storage cost, the storage space of most Internet of Things (IOT) devices is very limited, and the storage of IOT devices cannot save logs in real time. The logs of current IOT devices are output through universal asynchronous receiver / transmitter (UART). When using UART to output logs, the port used to output logs in UART needs to be configured to be normally open. However, configuring the port used to output logs in UART to be normally open will increase the power consumption of IOT devices. Summary of the invention
[0003] The embodiments of the present application provide a method for outputting logs, an IOT device, and a storage medium, which can reduce the power consumption of the IOT device while ensuring the output of logs.
[0004] A first aspect of an embodiment of the present application provides a method for outputting a log, including:
[0005] When the IoT device is powered on, the receiving pin and the transmitting pin of the universal asynchronous receiver / transmitter (UART) of the IoT device are configured as general purpose input / output (GPIO) input functions;
[0006] Obtaining the level status of the receiving pin and the transmitting pin of the UART, and determining whether the UART is in a connected state according to the level status;
[0007] When the UART is in a connected state, the receiving pin of the UART is configured as a UART receiving function, the sending pin of the UART is configured as a UART sending function, and the log information of the IOT device is output through the sending pin of the UART.
[0008] In the embodiment of the present application, when the IOT device is powered on, the receiving pin and the transmitting pin of the UART of the IOT device are configured as GPIO input functions. When the receiving pin and the transmitting pin of the UART are GPIO input functions, the level status of the receiving pin and the transmitting pin of the UART can be obtained, and whether the UART is in a connected state can be determined according to the level status of the receiving pin and the transmitting pin of the UART. If the UART is in a connected state, the receiving pin of the UART is configured as the UART receiving function, and the transmitting pin of the UART is configured as the UART transmitting function, and the log information of the IOT device is output through the transmitting pin of the UART, thereby realizing the function of log output. Since the power consumption of the pin configured as GPIO is lower than that of the pin configured as the UART function, compared with continuously configuring the pin as the UART function, the power consumption of the IOT device can be reduced while ensuring the output of the log.
[0009] Optionally, determining whether the URAT is in a connected state according to the level state includes:
[0010] When both the receiving pin and the transmitting pin of the UART are at high level, determining that the UART is in a connected state;
[0011] When the receiving pin and the transmitting pin of the UART are both at low levels, it is determined that the UART is in a disconnected state.
[0012] Optionally, the method further includes:
[0013] When the UART is in a disconnected state, a receiving pin and a transmitting pin of the UART are configured as a GPIO input interrupt function.
[0014] In the embodiment of the present application, when the receiving pin and the transmitting pin of the UART are GPIO input functions, if it is detected that the receiving pin and the transmitting pin of the UART are both low level, it is determined that the UART is in a disconnected state, and the receiving pin and the transmitting pin of the UART are configured as GPIO input interrupt functions. When the UART is in a disconnected state, there is no need to output logs. Configuring the receiving pin and the transmitting pin of the UART as GPIO input interrupt functions can reduce the power consumption of the pins compared to continuously configuring the pins as UART functions, thereby reducing the power consumption of the IOT device.
[0015] Optionally, the method further includes:
[0016] When the UART is in a disconnected state, a receiving pin and a transmitting pin of the UART are configured to be at a low level.
[0017] In the embodiment of the present application, when the UART is in a disconnected state, the receiving pin and the transmitting pin of the UART are configured to be low level to prevent the receiving pin and the transmitting pin of the UART from being interrupted by error due to fluctuations in the levels.
[0018] Optionally, after configuring the receiving pin and the transmitting pin of the UART to have a GPIO input interrupt function, the method further includes:
[0019] When both the receiving pin and the transmitting pin of the UART generate interrupts and the receiving pin and the transmitting pin of the UART are both at high levels, it is determined that the UART is in a connected state, and the steps of configuring the receiving pin of the UART to be a UART receiving function, configuring the transmitting pin of the UART to be a UART transmitting function, and outputting the log information of the IOT device through the transmitting pin of the UART are executed.
[0020] In the embodiment of the present application, when both the receiving pin and the transmitting pin of the UART generate an interrupt, and the receiving pin and the transmitting pin of the UART are both at a high level, it is determined that the UART is in a connected state, and the receiving pin of the UART can be configured as a UART receiving function, and the transmitting pin of the UART can be configured as a UART transmitting function, and the log information of the IOT device is output through the transmitting pin of the UART, thereby realizing the function of log output. When the receiving pin and the transmitting pin of the UART are configured as GPIO input interrupt functions, the interrupt can accurately determine whether the UART is in a connected state. When the UART is in a connected state, the receiving pin of the UART is configured as a UART receiving function, and the transmitting pin of the UART is configured as a UART transmitting function, and the log information of the IOT device is output through the transmitting pin of the UART, thereby realizing the function of log output.
[0021] Optionally, after configuring the receiving pin of the UART to a UART receiving function, configuring the transmitting pin of the UART to a UART transmitting function, and outputting the log information of the IOT device through the transmitting pin of the UART, the method further includes:
[0022] When the receiving pin of the UART receives an interrupt signal, and the interrupt signal includes a command to close the log output, the sending function of the sending pin of the UART is closed, and the receiving pin and the sending pin of the UART are configured as GPIO input functions.
[0023] In an embodiment of the present application, after configuring the receiving pin of the UART to the UART receiving function and configuring the transmitting pin of the UART to the UART transmitting function, if the receiving pin of the UART receives an interrupt signal and the interrupt signal includes a command to turn off the log output, the transmitting function of the transmitting pin of the UART is turned off, the log output is stopped, and the receiving pin and the transmitting pin of the UART are configured to the GPIO input function, thereby reducing the power consumption of the pins and further reducing the power consumption of the IOT device.
[0024] Optionally, after configuring the receiving pin and the transmitting pin of the UART as GPIO input functions, the method further includes:
[0025] Obtain the levels of the receiving pin and the transmitting pin of the UART;
[0026] When both the receiving pin and the transmitting pin of the UART are at a low level, the step of configuring the receiving pin and the transmitting pin of the UART to be a GPIO input interrupt function is performed.
[0027] In an embodiment of the present application, after configuring the receive pin and transmit pin of the UART as the GPIO input function, if the receive pin and transmit pin of the UART are both at a low level, it indicates that the UART is in a disconnected state. At this time, the receive pin and transmit pin of the UART are configured as the GPIO input interrupt function, thereby reducing the power consumption of the pins and further reducing the power consumption of the IOT device.
[0028] Optionally, after configuring the receiving pin and the transmitting pin of the UART as GPIO input functions, the method further includes:
[0029] When both the receiving pin and the transmitting pin of the UART are at a high level, the step of obtaining the levels of the receiving pin and the transmitting pin of the UART is performed.
[0030] In the embodiment of the present application, after configuring the receiving pin and the transmitting pin of the UART as the GPIO input function, if the receiving pin and the transmitting pin of the UART are both high, it indicates that the UART is in a connected state, and at this time, the receiving pin and the transmitting pin of the UART continue to be obtained until the receiving pin and the transmitting pin of the UART are both low (UART is in a disconnected state). Configuring the receiving pin and the transmitting pin of the UART as the GPIO input interrupt function can reduce the power consumption of the pins, thereby reducing the power consumption of the IOT device.
[0031] A second aspect of an embodiment of the present application provides a device for outputting a log, including:
[0032] A configuration unit is used to configure a receiving pin and a transmitting pin of a universal asynchronous receiver / transmitter (UART) of the IoT device to a general purpose input / output (GPIO) input function when the IoT device is powered on;
[0033] An acquisition unit, used to acquire the level status of the receiving pin and the sending pin of the UART;
[0034] a determining unit, configured to determine whether the URAT is in a connected state according to the level state;
[0035] The configuration unit is further used to configure the receiving pin of the UART to the UART receiving function and configure the sending pin of the UART to the UART sending function when the UART is in a connected state;
[0036] The output unit is used to output the log information of the IOT device through the sending pin of the UART.
[0037] A third aspect of an embodiment of the present application provides an IOT device, comprising a processor and a memory, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the step instructions in the first aspect of the embodiment of the present application.
[0038] The fourth aspect of the embodiments of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for electronic data exchange, wherein the computer program enables a computer to execute part or all of the steps described in the first aspect of the embodiments of the present application.
[0039] A fifth aspect of the embodiments of the present application provides a computer program product, wherein the computer program product includes a computer program, and the computer program is operable to cause an application processor to perform some or all of the steps described in the first aspect of the embodiments of the present application. The computer program product may be a software installation package.
[0040] In the embodiment of the present application, when the IOT device is powered on, the receiving pin and the transmitting pin of the UART of the IOT device are configured as GPIO input functions. When the receiving pin and the transmitting pin of the UART are GPIO input functions, the level status of the receiving pin and the transmitting pin of the UART can be obtained, and whether the UART is in a connected state can be determined according to the level status of the receiving pin and the transmitting pin of the UART. If the UART is in a connected state, the receiving pin of the UART is configured as the UART receiving function, and the transmitting pin of the UART is configured as the UART transmitting function, and the log information of the IOT device is output through the transmitting pin of the UART, thereby realizing the function of log output. Since the power consumption of the pin configured as GPIO is lower than that of the pin configured as the UART function, compared with continuously configuring the pin as the UART function, the power consumption of the IOT device can be reduced while ensuring the output of the log. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0042] Figure 1 It is a schematic diagram of a hardware architecture provided by an embodiment of the present application;
[0043] Figure 2 It is a flowchart of a method for outputting logs provided in an embodiment of the present application;
[0044] Figure 3 It is a flowchart of another method for outputting logs provided in an embodiment of the present application;
[0045] Figure 4 This is a specific flow chart of a method for outputting logs provided in an embodiment of the present application;
[0046] Figure 5 It is a schematic diagram comparing the wake-up time of turning on the UART sending function and turning off the UART sending function of a UART sending pin provided by an embodiment of the present application;
[0047] Figure 6 A schematic diagram of the structure of a device for outputting logs provided in an embodiment of the present application;
[0048] Figure 7 It is a structural diagram of an IOT device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0049] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0050] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices.
[0051] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments.
[0052] The embodiments of the present application provide a method for outputting logs, an IOT device, and a storage medium, which can reduce the power consumption of the IOT device while ensuring the output of logs.
[0053] See also Figure 1 , Figure 1 This is a schematic diagram of a hardware architecture provided by an embodiment of the present application. Figure 1 As shown, the hardware architecture includes an IOT device and a host computer. The IOT device may include a processor and a UART, the UART includes a receiving pin RX1 and a transmitting pin TX1; the host computer may include an interface module, the interface module includes a receiving pin RX2 and a transmitting pin TX2.
[0054] The interface module may be a transistor-transistor logic (TTL) interface module, or the interface module may be a universal serial bus (USB) to TTL interface module. The USB to TTL interface module may be used when the host computer does not support TTL, and the USB to TTL interface module may be used to connect the USB interface of the host computer to realize the function of the TTL interface module.
[0055] In an embodiment of the present application, whether the UART is in a connected state or a disconnected state is determined by judging the levels of a receiving pin RX1 and a transmitting pin TX1 of the UART. When the levels of the receiving pin RX1 and the transmitting pin TX1 of the UART are both high, it is determined that the UART is in a connected state (the receiving pin RX1 of the UART is connected to the transmitting pin TX2 of the interface module, and the transmitting pin TX1 of the UART is connected to the receiving pin RX2 of the interface module). When the levels of the receiving pin RX1 and the transmitting pin TX1 of the UART are both low, it is determined that the UART is in a disconnected state (the receiving pin RX1 of the UART is disconnected from the transmitting pin TX2 of the interface module, and the transmitting pin TX1 of the UART is disconnected from the receiving pin RX2 of the interface module).
[0056] The receiving pin RX1 and the transmitting pin TX1 of the UART of the embodiment of the present application can be multiplexed as a general-purpose input / output (GPIO) function, and interrupts are supported. When UART is in a connected state, the processor can control the transmitting pin TX1 of UART to output a log (Log), and the receiving pin RX1 of UART interacts with the interface module of the host computer for debugging, and the processor can receive and execute the debugging command sent by the host computer. When the log is not needed to be output, the transmitting pin TX2 of the interface module of the host computer sends a command to close the log output to the receiving pin RX1 of UART, and the processor will close the sending function of the transmitting pin TX1 of UART after receiving the command to close the log output, stop outputting the log, and at the same time, the processor determines whether UART is in a disconnected state by obtaining the level of the receiving pin RX1 and the transmitting pin TX1 of UART. After UART is in a disconnected state, it will re-detect whether UART is in a connected state, and after UART is in a connected state, the processor can control the transmitting pin TX1 of UART to output a log. In this way, adaptive log output is achieved, that is, the calendar is output when the UART is connected, and the log output is stopped when the UART is disconnected.
[0057] like Figure 1 As shown in the figure, since the receiving pin RX2 and the transmitting pin TX2 of the interface module have pull-up signals, the receiving pin RX2 and the transmitting pin TX2 of the interface module are high level by default. When the UART is in the connected state, the receiving pin RX1 and the transmitting pin TX1 of the UART are both pulled to a high level; when the UART is in the disconnected state, the receiving pin RX1 and the transmitting pin TX1 of the UART are both suspended and become low level.
[0058] IOT devices can be low-power devices such as point of sales (POS) machines, two-wheeled bicycles, umbrellas, sensors, etc.
[0059] The host computer can be a personal computer (PC), a tablet computer, a mobile phone, etc.
[0060] See also Figure 2 , Figure 2 Schematic diagram of a method for outputting logs provided in an embodiment of the present application. Figure 2 As shown, the method for outputting logs may include the following steps.
[0061] 201. When the Internet of Things (IoT) device is powered on, the IoT device configures a receiving pin and a transmitting pin of a universal asynchronous receiver / transmitter (UART) of the IoT device as a general purpose input / output (GPIO) input function.
[0062] The process of powering on an IoT device refers to the process of the processor and UART in the IoT device starting to be powered from no power. After the IoT device is powered on, the processor in the IoT device can configure the receiving pin and sending pin of the UART as GPIO input functions. The GPIO input function refers to the function that supports GPIO input.
[0063] In the embodiment of the present application, the receiving pin and the transmitting pin of the UART can be multiplexed as GPIO functions and support interrupts. Since the power consumption of the pin configured as GPIO is lower than that of the UART function, the receiving pin and the transmitting pin of the UART of the IOT device are configured as GPIO input functions after the IOT device is powered on, which can reduce the power consumption of the pin, thereby reducing the power consumption of the IOT device.
[0064] After executing step 201 , step 202 may be executed.
[0065] 202, the IOT device obtains the level status of the receiving pin and the sending pin of the UART, and determines whether the UART is in a connection state according to the level status.
[0066] In the embodiment of the present application, the processor of the IOT device can obtain the level status of the receiving pin and the sending pin of the UART, and can determine whether the UART is in a connected state according to the level status of the receiving pin and the sending pin of the UART.
[0067] Optionally, in step 202, the IOT device determines whether the URAT is in a connected state according to the level state, which may include:
[0068] (11) When both the receiving pin and the transmitting pin of the UART are at high levels, the IOT device determines that the UART is in a connected state;
[0069] (12) When the receiving pin and the transmitting pin of the UART are both at low levels, the IOT device determines that the UART is in a disconnected state.
[0070] When both the receiving pin and the transmitting pin of the UART are at high level, it is determined that the UART is in a connected state. Exemplarily, if the level of the receiving pin of the UART is 1, it means that the receiving pin of the UART is at a high level; if the level of the transmitting pin of the UART is 1, it means that the transmitting pin of the UART is at a high level.
[0071] When both the receiving pin and the transmitting pin of the UART are at low level, it is determined that the UART is in a disconnected state. Exemplarily, if the level of the receiving pin of the UART is 0, it means that the receiving pin of the UART is at a low level; if the level of the transmitting pin of the UART is 0, it means that the transmitting pin of the UART is at a low level.
[0072] When both the receiving pin and the sending pin of the UART are high, it indicates that the interface module of the UART and the host computer are connected. At this time, the UART has the hardware conditions to output log information to the host computer.
[0073] 203, when the UART is in a connected state, the IOT device configures the receiving pin of the UART as the UART receiving function, configures the sending pin of the UART as the UART sending function, and outputs the log information of the IOT device through the sending pin of the UART.
[0074] The log information of an IoT device may include: information recorded by the system or application of the IoT device during startup and operation.
[0075] In the embodiment of the present application, when the UART is in a connected state, the receiving pin of the UART is configured as the UART receiving function, and the receiving pin of the UART can receive the signal sent by the host computer through the UART method. The sending pin of the UART is configured as the UART sending function, and the sending pin of the UART can output log information to the host computer through the UART method. The receiving pin and the sending pin of the UART restore the UART function, thereby realizing the function of outputting logs.
[0076] In the embodiment of the present application, when the IOT device is powered on, the receiving pin and the transmitting pin of the UART of the IOT device are configured as GPIO input functions. When the receiving pin and the transmitting pin of the UART are GPIO input functions, the level status of the receiving pin and the transmitting pin of the UART can be obtained, and whether the UART is in a connected state can be determined according to the level status of the receiving pin and the transmitting pin of the UART. If the UART is in a connected state, the receiving pin of the UART is configured as the UART receiving function, and the transmitting pin of the UART is configured as the UART transmitting function, and the log information of the IOT device is output through the transmitting pin of the UART, thereby realizing the function of log output. Since the power consumption of the pin configured as GPIO is lower than that of the pin configured as the UART function, compared with continuously configuring the pin as the UART function, the power consumption of the IOT device can be reduced while ensuring the output of the log.
[0077] See also Figure 3 , Figure 3 FIG. 1 is a flow chart of another method for outputting logs provided in an embodiment of the present application. Figure 3 As shown, the method for outputting logs may include the following steps.
[0078] 301. When the Internet of Things (IoT) device is powered on, the IoT device configures a receiving pin and a transmitting pin of a universal asynchronous receiver / transmitter (UART) of the IoT device as a general purpose input / output (GPIO) input function.
[0079] After executing step 301 , step 302 or step 304 may be executed.
[0080] 302, when the receiving pin and the transmitting pin of the UART are both at high levels, the IOT device determines that the UART is in a connected state.
[0081] 303, when the UART is in a connected state, the IOT device configures the receiving pin of the UART as the UART receiving function, configures the sending pin of the UART as the UART sending function, outputs the log information of the IOT device through the sending pin of the UART, and enables the receiving pin of the UART to have an interrupt function.
[0082] Enable the UART receiving pin to have the interrupt function, that is, make the UART receiving pin have the function of receiving UART interrupt.
[0083] Optionally, in executing step 303, the receiving pin of the UART may be enabled to have an interrupt function, so that the receiving pin of the UART has the function of receiving UART interrupts.
[0084] The specific implementation of steps 301 to 303 may refer to the above steps 201 to 203, which will not be repeated here.
[0085] After executing step 303 , step 307 may be executed.
[0086] 304, when the receiving pin and the transmitting pin of the UART are both at low levels, the IOT device determines that the UART is in a disconnected state.
[0087] In the embodiment of the present application, the processor of the IOT device can obtain the levels of the receiving pin and the transmitting pin of the UART, and determine that the UART is in a disconnected state when both the receiving pin and the transmitting pin of the UART are at a low level. Exemplarily, if the level of the receiving pin of the UART is 0, it means that the receiving pin of the UART is at a low level; if the level of the transmitting pin of the UART is 0, it means that the transmitting pin of the UART is at a low level.
[0088] After executing step 304 , step 305 may be executed.
[0089] 305, when the UART is in a disconnected state, the IOT device configures the receiving pin and the sending pin of the UART as the GPIO input interrupt function, and configures the receiving pin and the sending pin of the UART to a low level.
[0090] In the embodiment of the present application, when the receiving pin and the transmitting pin of the UART are GPIO input functions, if it is detected that the receiving pin and the transmitting pin of the UART are both low level, it is determined that the UART is in a disconnected state, and the receiving pin and the transmitting pin of the UART are configured as GPIO input interrupt functions. When the UART is in a disconnected state, there is no need to output logs. Configuring the receiving pin and the transmitting pin of the UART as GPIO input interrupt functions can reduce the power consumption of the pins compared to continuously configuring the pins as UART functions, thereby reducing the power consumption of the IOT device.
[0091] Exemplarily, the IOT device configures the receiving pin and the transmitting pin of the UART to be low level, which can be: the IOT device turns on the pull-down circuit connected to the receiving pin and the transmitting pin of the UART, thereby configuring the receiving pin and the transmitting pin of the UART to be low level. The pull-down circuit can be a pull-down circuit inside the IOT device, and the pull-down circuit can be composed of a pull-down resistor and a switch in series, one end of the pull-down resistor is connected to one end of the switch, the other end of the switch is connected to the receiving pin and the transmitting pin of the UART, and the other end of the pull-down resistor is grounded. The IOT device controls the switch to turn on, thereby configuring the receiving pin and the transmitting pin of the UART to be low level.
[0092] In the embodiment of the present application, when the UART is in a disconnected state, the receiving pin and the transmitting pin of the UART are configured to be low level to prevent the receiving pin and the transmitting pin of the UART from being interrupted by error due to fluctuations in the levels.
[0093] The GPIO input interrupt function refers to the function of supporting GPIO input and GPIO interrupt.
[0094] The condition for the UART receive pin to trigger a GPIO interrupt is: the level of the UART receive pin changes. The condition for the UART transmit pin to trigger a GPIO interrupt is: the level of the UART transmit pin changes.
[0095] After executing step 305 , step 306 may be executed.
[0096] 306, when both the receiving pin and the transmitting pin of the UART generate interrupts and both the receiving pin and the transmitting pin of the UART are at high levels, the IOT device determines that the UART is in a connected state.
[0097] The interrupts generated by the receiving pin and the transmitting pin of the UART are GPIO interrupts. Exemplarily, when the level of the receiving pin of the UART changes from a low level to a high level, the receiving pin of the UART generates a GPIO interrupt; when the level of the transmitting pin of the UART changes from a low level to a high level, the transmitting pin of the UART generates a GPIO interrupt.
[0098] When both the receiving pin and the transmitting pin of the UART generate GPIO interrupts, the processor in the IOT device can obtain the levels of the receiving pin and the transmitting pin of the UART, and determine that the UART is in a connected state when both the receiving pin and the transmitting pin of the UART are high.
[0099] After executing step 306 , step 303 may be executed.
[0100] In the embodiment of the present application, when both the receiving pin and the transmitting pin of the UART generate an interrupt, and the receiving pin and the transmitting pin of the UART are both at a high level, it is determined that the UART is in a connected state, and the receiving pin of the UART can be configured as a UART receiving function, and the transmitting pin of the UART can be configured as a UART transmitting function, and the log information of the IOT device is output through the transmitting pin of the UART, thereby realizing the function of log output. When the receiving pin and the transmitting pin of the UART are configured as GPIO input interrupt functions, the interrupt can accurately determine whether the UART is in a connected state. When the UART is in a connected state, the receiving pin of the UART is configured as a UART receiving function, and the transmitting pin of the UART is configured as a UART transmitting function, and the log information of the IOT device is output through the transmitting pin of the UART, thereby realizing the function of log output.
[0101] 307, when the receiving pin of the UART receives an interrupt signal, and the interrupt signal includes a command to close the log output, the IOT device closes the sending function of the sending pin of the UART, and configures the receiving pin and the sending pin of the UART as GPIO input functions.
[0102] In the embodiment of the present application, after configuring the receiving pin of the UART as the UART receiving function and configuring the transmitting pin of the UART as the UART transmitting function, the receiving pin of the UART can be enabled to have an interrupt function. If the receiving pin of the UART receives an interrupt signal, and the interrupt signal includes a command to turn off the log output, the sending function of the transmitting pin of the UART is turned off, the output log is stopped, and the receiving pin and the transmitting pin of the UART are configured as the GPIO input function, thereby reducing the power consumption of the pins, and then reducing the power consumption of the IOT device.
[0103] The receiving pin of the UART receives an interrupt signal, indicating that the receiving pin of the UART generates a UART interrupt. When the receiving pin of the UART receives data, the receiving pin of the UART generates a UART interrupt.
[0104] The interrupt signal may come from the host computer, and the command to close the log output may be one or more fields in the interrupt signal.
[0105] The processor of the IoT device can turn off the sending function of the UART sending pin, so that the UART sending pin no longer outputs logs, thereby stopping the output of logs.
[0106] After executing step 307 , execute step 308 .
[0107] 308, obtaining the levels of the receiving pin and the transmitting pin of the UART.
[0108] In an embodiment of the present application, after configuring the receive pin and transmit pin of the UART as the GPIO input function, if the receive pin and transmit pin of the UART are both at a low level, it indicates that the UART is in a disconnected state. At this time, the receive pin and transmit pin of the UART are configured as the GPIO input interrupt function, thereby reducing the power consumption of the pins and further reducing the power consumption of the IOT device.
[0109] After executing step 308 , step 304 may also be executed.
[0110] After executing step 308, if both the receiving pin and the transmitting pin of the UART are high level, step 308 can be continued, or step 308 can be continued after setting the time length. The set time length can be set in advance. Exemplarily, the set time length can be set to 1 second.
[0111] In the embodiment of the present application, after configuring the receiving pin and the transmitting pin of the UART as the GPIO input function, if the receiving pin and the transmitting pin of the UART are both high, it indicates that the UART is in a connected state, and at this time, the receiving pin and the transmitting pin of the UART continue to be obtained until the receiving pin and the transmitting pin of the UART are both low (UART is in a disconnected state). Configuring the receiving pin and the transmitting pin of the UART as the GPIO input interrupt function can reduce the power consumption of the pins, thereby reducing the power consumption of the IOT device.
[0112] See also Figure 4 , Figure 4 This is a specific flow chart of a method for outputting logs provided in an embodiment of the present application. Figure 4 As shown, the method for outputting logs may include the following steps.
[0113] 401, IoT device is powered on.
[0114] After executing step 401 , step 402 may be executed.
[0115] 402, configure the receiving pin and the sending pin of the UART as GPIO input functions, and obtain the levels of the receiving pin and the sending pin of the UART.
[0116] After the IoT device is powered on, it is initialized and configured, and the receiving and sending pins of the UART are configured as GPIO input functions, and the levels of the receiving and sending pins of the UART are read. If the receiving and sending pins of the UART are both high, it is determined that the UART is in a connected state; if the receiving and sending pins of the UART are both high, it is determined that the UART is in a disconnected state.
[0117] After executing step 402 , step 403 may be executed.
[0118] 403, determine whether the receiving pin and the transmitting pin of the UART are both at high level. If yes, execute step 404; if no, execute step 407.
[0119] 404, determine that the UART is in a connected state, configure the receiving pin of the UART to the UART receiving function, configure the sending pin of the UART to the UART sending function, output the log information of the IOT device through the sending pin of the UART, and enable the receiving pin of the UART to have an interrupt function.
[0120] When UART is in the connected state, configure the receiving pin of UART as the UART receiving function, configure the sending pin of UART as the UART sending function, output the log information of IOT device through the sending pin of UART, and the log information will be output to the host computer through the sending pin of UART. The receiving pin of UART will enable the receiving interrupt to process the interrupt signal sent by the host computer.
[0121] Enable the UART receiving pin to have the interrupt function, that is, make the UART receiving pin have the function of receiving UART interrupt.
[0122] After executing step 404 , step 405 may be executed.
[0123] 405, if the receiving pin of the UART receives an interrupt signal, and the interrupt signal includes a command to close the log output, the sending function of the sending pin of the UART is closed, and the receiving pin and the sending pin of the UART are configured as GPIO input functions.
[0124] If the receiving pin of the UART receives an interrupt signal, the received interrupt signal is parsed. If the interrupt signal includes a command to turn off log output (for example, a command to turn off Log), the sending function of the sending pin of the UART is turned off, and the receiving pin and the sending pin of the UART are configured as GPIO input functions. The levels of the receiving pin and the sending pin of the UART are periodically obtained. If both the receiving pin and the sending pin of the UART become low levels, it indicates that the UART is in a disconnected state.
[0125] After executing step 405 , step 406 may be executed.
[0126] 406, obtaining the levels of the receiving pin and the transmitting pin of the UART, and determining whether the receiving pin and the transmitting pin of the UART are both at low levels. If yes, executing step 407; if no, executing step 406.
[0127] If the receiving pin and the sending pin of the UART are both low, the UART is in a disconnected state, and step 407 is continued. If the receiving pin and the sending pin of the ART are not both low, step 406 is continued, or step 406 is continued after the set time. The set time can be set in advance. Exemplarily, the set time can be set to 1 second.
[0128] 407, determine that the UART is in a disconnected state, configure the receiving pin and the transmitting pin of the UART to be a GPIO input interrupt function, and configure the receiving pin and the transmitting pin of the UART to be internally pulled down.
[0129] When the UART is in a disconnected state, the receiving pin and the transmitting pin of the UART are configured as GPIO input interrupt functions, and the receiving pin and the transmitting pin of the UART are configured to be pulled down internally, so as to monitor whether the receiving pin and the transmitting pin of the UART generate an interrupt. When both the receiving pin and the transmitting pin of the UART generate an interrupt, and both the receiving pin and the transmitting pin of the UART are at a high level, it indicates that the UART is in a connected state, and step 404 is executed.
[0130] Configure the receiving pin and sending pin of UART to be internally pulled down, that is, configure the receiving pin and sending pin of UART to be low level.
[0131] 408, when both the receiving pin and the transmitting pin of the UART generate interrupts and both the receiving pin and the transmitting pin of the UART are at high levels, it is determined that the UART is in a connected state.
[0132] After executing step 408 , step 404 may be executed.
[0133] In the embodiment of the present application, when the UART is in a connected state, the log information of the IOT device is output through the UART sending pin. When the UART is in a disconnected state, the receiving pin and the sending pin of the UART are configured as the GPIO input interrupt function, which can reduce the power consumption of the pins and reduce the processor overhead. By configuring the receiving pin of the UART as the UART receiving function and the sending pin of the UART as the UART sending function, the output log function of the sending pin of the UART is turned on, making the output log information more convenient and quick, and providing convenience for quickly locating problems.
[0134] When an IOT device crashes (for example, a boot dump), if the factory settings of the IOT device use USB to output logs by default, when the IOT device crashes, the USB enumeration has not yet been completed, resulting in the inability to capture logs, resulting in the loss of logs related to the IOT device crash. Figure 4 After using the method, connect the UART of the IOT device to the host computer (for example, a computer) when the IOT device is turned on. The IOT device will automatically use the UART to output log information when it is turned on, and the log will not be lost.
[0135] When the IoT device is in sleep mode, if the UART transmit pin is always configured as the UART transmit function, the power consumption will be high. If the UART transmit function of the UART transmit pin is turned off, the log information cannot be obtained in time. It is very inconvenient to analyze the problem by capturing the log.
[0136] See also Figure 5 , Figure 51 is a schematic diagram of the comparison of the wake-up time of turning on the UART send function and turning off the UART send function of a UART send pin provided by an embodiment of the present application. Figure 5 As shown in the figure above, after the IoT device is awakened, the wake-up time (i.e., the time for the IoT device to interact with the base station) lasts for 34.1 milliseconds (ms). When in sleep mode, if the UART transmit function of the UART transmit pin is turned off, such as Figure 5 As shown in the figure below, the wake-up time lasts for 14ms. Figure 5 Compared with the figure below, when the UART transmission pin of the IOT device is in sleep mode, the wake-up time of turning on the UART transmission function is 20.1ms longer than that of turning off the UART transmission function, which will increase the power consumption of the IOT device. Figure 5 ), when there is no need to output logs, turning off the sending function of the UART sending pin can reduce the power consumption of the IOT device. For IOT devices that are sensitive to power consumption, it will greatly increase the battery life of the IOT device. The solution of the embodiment of the present application not only meets the power consumption requirements of the IOT device, but also does not affect the host computer to capture logs, and timely analyze problems based on the logs.
[0137] The above mainly introduces the scheme of the embodiment of the present application from the perspective of the execution process on the method side. It is understandable that in order to realize the above functions, the IOT device includes a hardware structure and / or software module corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments provided in this document, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0138] The embodiment of the present application can divide the functional units of the IOT device according to the above method example. For example, each functional unit can be divided according to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units. It should be noted that the division of units in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0139] See also Figure 6 , Figure 6A schematic diagram of a structure of a device for outputting a log provided in an embodiment of the present application, wherein the device 600 for outputting a log is applied to an IOT device, and the device 600 for outputting a log may include a configuration unit 601, a determination unit 603, and an output unit 604, wherein:
[0140] The configuration unit 601 is used to configure the receiving pin and the transmitting pin of the universal asynchronous receiver / transmitter UART of the IoT device to be a general purpose input / output (GPIO) input function when the IoT device is powered on;
[0141] An acquisition unit 602 is used to acquire the level status of the receiving pin and the sending pin of the UART;
[0142] A determining unit 603, configured to determine whether the URAT is in a connected state according to the level state;
[0143] The configuration unit 601 is further configured to configure the receiving pin of the UART to a UART receiving function and configure the transmitting pin of the UART to a UART transmitting function when the UART is in a connected state;
[0144] The output unit 604 is used to output the log information of the IOT device through the sending pin of the UART.
[0145] Optionally, the determining unit 603 determines whether the URAT is in a connected state according to the level state, including:
[0146] When both the receiving pin and the transmitting pin of the UART are at high level, determining that the UART is in a connected state;
[0147] When the receiving pin and the transmitting pin of the UART are both at low levels, it is determined that the UART is in a disconnected state.
[0148] Optional,
[0149] The configuration unit 601 is further configured to configure the receiving pin and the transmitting pin of the UART to a GPIO input interrupt function when the UART is in a disconnected state.
[0150] Optionally, the configuration unit 601 is further configured to configure the receiving pin and the transmitting pin of the UART to a low level when the UART is in a disconnected state.
[0151] Optionally, the determining unit 603 is further configured to determine that the UART is in a connected state when both a receiving pin and a transmitting pin of the UART generate an interrupt and both the receiving pin and the transmitting pin of the UART are at a high level;
[0152] The configuration unit 601 is further used to configure the receiving pin of the UART to the UART receiving function, configure the sending pin of the UART to the UART sending function, and output the log information of the IOT device through the sending pin of the UART.
[0153] Optionally, the log output device 600 may include a closing unit 605 .
[0154] A closing unit 605 is used to close the sending function of the sending pin of the UART when the receiving pin of the UART receives an interrupt signal and the interrupt signal includes a command to close the log output;
[0155] The configuration unit 601 is also used to configure the receiving pin and the transmitting pin of the UART to have GPIO input functions.
[0156] Optional,
[0157] The acquisition unit 602 is further used to acquire the levels of the receiving pin and the transmitting pin of the UART;
[0158] The configuration unit 601 is further configured to configure the receiving pin and the sending pin of the UART to a GPIO input interrupt function when both the receiving pin and the sending pin of the UART are at a low level.
[0159] Optionally, the acquisition unit 602 is further configured to acquire the levels of the receiving pin and the sending pin of the UART when both the receiving pin and the sending pin of the UART are at high levels.
[0160] The configuration unit 601, the determination unit 603, the closing unit 605, and the acquisition unit 602 in the embodiment of the present application may be processors in an IOT device. The output unit 604 may be a communication module (eg, UART) in an IOT device.
[0161] In the embodiment of the present application, when the IOT device is powered on, the receiving pin and the transmitting pin of the UART of the IOT device are configured as GPIO input functions. When the receiving pin and the transmitting pin of the UART are GPIO input functions, the level status of the receiving pin and the transmitting pin of the UART can be obtained, and whether the UART is in a connected state can be determined according to the level status of the receiving pin and the transmitting pin of the UART. If the UART is in a connected state, the receiving pin of the UART is configured as the UART receiving function, and the transmitting pin of the UART is configured as the UART transmitting function, and the log information of the IOT device is output through the transmitting pin of the UART, thereby realizing the function of log output. Since the power consumption of the pin configured as GPIO is lower than that of the pin configured as the UART function, compared with continuously configuring the pin as the UART function, the power consumption of the IOT device can be reduced while ensuring the output of the log.
[0162] See also Figure 7 , Figure 7 is a schematic diagram of the structure of an IOT device provided in an embodiment of the present application, such as Figure 7 As shown, the IOT device 700 includes a processor 701 and a memory 702, and the processor 701 and the memory 702 can be connected to each other via a communication bus 703. The communication bus 703 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The communication bus 703 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 7 The memory 702 is used to store computer programs, which include program instructions. The processor 701 is configured to call the program instructions. The program includes instructions for executing Figures 2 to 4 Some or all of the steps in the method shown.
[0163] The processor 701 may be a general purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the above program.
[0164] The memory 702 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a bus. The memory may also be integrated with the processor.
[0165] The IOT device 700 may further include a communication module 704 (eg, UART).
[0166] In addition, the IOT device 700 may also include common components such as a communication interface, a radio frequency module (eg, a power amplifier), an antenna, etc., which will not be described in detail here.
[0167] In the embodiment of the present application, when the IOT device is powered on, the receiving pin and the transmitting pin of the UART of the IOT device are configured as GPIO input functions. When the receiving pin and the transmitting pin of the UART are GPIO input functions, the level status of the receiving pin and the transmitting pin of the UART can be obtained, and whether the UART is in a connected state can be determined according to the level status of the receiving pin and the transmitting pin of the UART. If the UART is in a connected state, the receiving pin of the UART is configured as the UART receiving function, and the transmitting pin of the UART is configured as the UART transmitting function, and the log information of the IOT device is output through the transmitting pin of the UART, thereby realizing the function of log output. Since the power consumption of the pin configured as GPIO is lower than that of the pin configured as the UART function, compared with continuously configuring the pin as the UART function, the power consumption of the IOT device can be reduced while ensuring the output of the log.
[0168] An embodiment of the present application also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program for electronic data exchange, and the computer program enables a computer to execute part or all of the steps of any method for implementing a key function as recorded in the above method embodiments.
[0169] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0170] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0171] In the several embodiments provided in the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of the units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be electrical or other forms.
[0172] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0173] In addition, the functional units in the various embodiments of the application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated units may be implemented in the form of hardware or in the form of software program modules.
[0174] If the integrated unit is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a memory, including a number of instructions to enable a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned memory includes: U disk, read-only memory (ROM), random access memory (RAM), mobile hard disk, disk or optical disk and other media that can store program codes.
[0175] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable memory, which can include: a flash drive, a read-only memory, a random access memory, a magnetic disk or an optical disk, etc.
[0176] The embodiments of the present application are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application. At the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for outputting a log, characterized in that: include: When the IoT device is powered on, the receiving pin and the transmitting pin of the universal asynchronous receiver / transmitter (UART) of the IoT device are configured as general purpose input / output (GPIO) input functions; Obtaining the level status of the receiving pin and the sending pin of the UART, and determining whether the UART is in a connected state according to the level status; When the UART is in a connected state, the receiving pin of the UART is configured as a UART receiving function, the sending pin of the UART is configured as a UART sending function, and the log information of the IOT device is output through the sending pin of the UART.
2. The method according to claim 1, characterized in that The determining whether the URAT is in a connected state according to the level state includes: When both the receiving pin and the transmitting pin of the UART are at high level, determining that the UART is in a connected state; When the receiving pin and the transmitting pin of the UART are both at low levels, it is determined that the UART is in a disconnected state.
3. The method according to claim 1 or 2, characterized in that: The method further comprises: When the UART is in a disconnected state, a receiving pin and a transmitting pin of the UART are configured as a GPIO input interrupt function.
4. The method according to claim 3, characterized in that The method further comprises: When the UART is in a disconnected state, a receiving pin and a transmitting pin of the UART are configured to be at a low level.
5. The method according to claim 3, characterized in that: After configuring the receiving pin and the transmitting pin of the UART as the GPIO input interrupt function, the method further includes: When both the receiving pin and the transmitting pin of the UART generate interrupts and the receiving pin and the transmitting pin of the UART are both at high levels, it is determined that the UART is in a connected state, and the steps of configuring the receiving pin of the UART to be a UART receiving function, configuring the transmitting pin of the UART to be a UART transmitting function, and outputting the log information of the IOT device through the transmitting pin of the UART are executed.
6. The method according to any one of claims 3 to 5, characterized in that: After configuring the receiving pin of the UART to the UART receiving function, configuring the transmitting pin of the UART to the UART transmitting function, and outputting the log information of the IOT device through the transmitting pin of the UART, the method further includes: When the receiving pin of the UART receives an interrupt signal, and the interrupt signal includes a command to close the log output, the sending function of the sending pin of the UART is closed, and the receiving pin and the sending pin of the UART are configured as GPIO input functions.
7. The method according to claim 6, characterized in that: After configuring the receiving pin and the transmitting pin of the UART as GPIO input functions, the method further includes: Obtain the levels of the receiving pin and the transmitting pin of the UART; When both the receiving pin and the transmitting pin of the UART are at a low level, the step of configuring the receiving pin and the transmitting pin of the UART to be a GPIO input interrupt function is performed.
8. The method according to claim 7, characterized in that: After configuring the receiving pin and the transmitting pin of the UART as GPIO input functions, the method further includes: When both the receiving pin and the transmitting pin of the UART are at a high level, the step of obtaining the levels of the receiving pin and the transmitting pin of the UART is performed.
9. An IOT device, characterized in that: The method comprises a processor and a memory, wherein the memory is used to store a computer program, the computer program comprises program instructions, and the processor is configured to call the program instructions to execute the method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by an application processor, the application processor executes the method according to any one of claims 1 to 8.