[go: up one dir, main page]

CN106658688B - System and method for realizing GSM module control in single chip microcomputer - Google Patents

System and method for realizing GSM module control in single chip microcomputer Download PDF

Info

Publication number
CN106658688B
CN106658688B CN201710020080.0A CN201710020080A CN106658688B CN 106658688 B CN106658688 B CN 106658688B CN 201710020080 A CN201710020080 A CN 201710020080A CN 106658688 B CN106658688 B CN 106658688B
Authority
CN
China
Prior art keywords
task
function
gsm
reply
layer
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710020080.0A
Other languages
Chinese (zh)
Other versions
CN106658688A (en
Inventor
颜昊霖
牟荣增
王宏飞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Kunshan Microelectronics Technology Research Institute
Original Assignee
Institute of Microelectronics of CAS
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Institute of Microelectronics of CAS filed Critical Institute of Microelectronics of CAS
Priority to CN201710020080.0A priority Critical patent/CN106658688B/en
Publication of CN106658688A publication Critical patent/CN106658688A/en
Application granted granted Critical
Publication of CN106658688B publication Critical patent/CN106658688B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W52/00Power management, e.g. Transmission Power Control [TPC] or power classes
    • H04W52/02Power saving arrangements
    • H04W52/0209Power saving arrangements in terminal devices
    • H04W52/0225Power saving arrangements in terminal devices using monitoring of external events, e.g. the presence of a signal
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

本发明公开了一种在单片机中实现GSM模块控制的系统,包括GSM任务调度层、任务处理与撤销层、任务执行层、功能封装层、底层驱动层、以及全局变量层,其中,所述GSM任务调度层、所述任务处理与撤销层、所述任务执行层、所述功能封装层和所述底层驱动层依次连接,并均与所述全局变量层连接。本发明通过五层划分加一套全局变量层的软件架构,将GSM的任务划分成GSM模块的功能序列,每次调用任务执行函数,执行一个功能封装函数,该功能封装函数通过异步控制,对于短时间内有回复的AT命令,通过同步方式检测其回复,可以较迅速地做出响应,而对于回复时间较长的AT命令,通过异步方式检测其回复,减少了回复的等待时间,降低了系统功耗。

Figure 201710020080

The invention discloses a system for realizing GSM module control in a single-chip microcomputer, comprising a GSM task scheduling layer, a task processing and cancellation layer, a task execution layer, a function encapsulation layer, a bottom driver layer, and a global variable layer, wherein the GSM The task scheduling layer, the task processing and cancellation layer, the task execution layer, the function encapsulation layer and the underlying driver layer are connected in sequence, and are all connected with the global variable layer. The invention divides the GSM task into the function sequence of the GSM module through the software architecture of five-layer division and a set of global variable layers, and calls the task execution function each time to execute a function encapsulation function, and the function encapsulation function is controlled asynchronously. For AT commands that have a reply in a short time, the reply can be detected synchronously, and the response can be made more quickly. For AT commands with a long reply time, the reply is detected in an asynchronous way, which reduces the waiting time for the reply and reduces the system power consumption.

Figure 201710020080

Description

一种在单片机中实现GSM模块控制的系统及方法A system and method for realizing GSM module control in single chip microcomputer

技术领域technical field

本发明涉及无线通信领域,尤其涉及在单片机上实现GSM无线通信模块的低功耗控制的嵌入式系统及其工作方法,更具体地,涉及以嵌入式软件架构实现GSM模块的低功耗控制。The invention relates to the field of wireless communication, in particular to an embedded system for realizing low power consumption control of a GSM wireless communication module on a single chip microcomputer and a working method thereof, and more particularly, to an embedded software framework for realizing low power consumption control of a GSM module.

背景技术Background technique

全球移动通信系统GSM(Global System for Mobile Communication)技术广为大众所熟知,其中的核心模块是GSM无线通信模块,其指的是符合GSM规范的,具有发送短信、语音通话、GPRS数据传输等基于GSM网络的所有基本功能的软件模块,又简称为GSM模块。The GSM (Global System for Mobile Communication) technology is widely known to the public, and the core module is the GSM wireless communication module, which refers to the GSM standard, which has the functions of sending short messages, voice calls, GPRS data transmission, etc. A software module for all basic functions of a GSM network, also referred to as a GSM module.

市面上大部分智能硬件产品都附带有通信模块,根据其需求,可能选择WIFI模块、蓝牙模块、GSM模块。其中,GSM模块网络覆盖面广,应用限制小,是智能硬件上最受欢迎的通信方案之一。一般的智能硬件开发,都是通过一个单片机来控制一个通信模块以及其余相关外设,其中,通信模块是最为复杂的部分,其控制逻辑是否完善直接影响着单片机的稳定性、功耗、功能性,进而影响到最终的智能硬件产品的价值。Most smart hardware products on the market are equipped with communication modules. According to their needs, WIFI modules, Bluetooth modules, and GSM modules may be selected. Among them, the GSM module has a wide network coverage and small application restrictions, and is one of the most popular communication solutions on intelligent hardware. In general intelligent hardware development, a single-chip microcomputer controls a communication module and other related peripherals. Among them, the communication module is the most complex part, and whether its control logic is perfect directly affects the stability, power consumption, and functionality of the single-chip microcomputer. , which in turn affects the value of the final smart hardware product.

现有的通过单片机控制通信模块的软件架构(以下简称软件架构),大致有两种:There are roughly two types of software architectures (hereinafter referred to as software architectures) for controlling communication modules through single-chip microcomputers:

(1)数据透传型:将GSM模块配置成“数据透传模式”,在整个系统的运行周期中,GSM模块都处于开启状态。这一方式编程简单,无需进行复杂的软件设计,但是能够使用的GSM模块功能局限于GPRS数据传输。同时GSM模块保持开启,导致电路功耗较大,不适合于对功耗有严格要求的产品。(1) Data transparent transmission type: The GSM module is configured as "data transparent transmission mode", and the GSM module is in the open state during the operation cycle of the entire system. This method is simple to program and does not require complicated software design, but the functions of the GSM module that can be used are limited to GPRS data transmission. At the same time, the GSM module is kept on, resulting in high power consumption of the circuit, which is not suitable for products with strict requirements on power consumption.

(2)同步控制型:使用AT指令对GSM模块进行控制,发出一条AT指令后,程序阻塞,直到GSM模块返回结果。为了防止程序锁死,一般设置超时时间,返回时间若超过超时时间,则认为命令失败。这一方式编程比较简单,但是存在一定缺陷:耗时较长的AT指令其返回时间不固定,如果超时时间设置过短,则命令失败率高,如果设置过长,则系统阻塞时间过长,影响系统处理速度。此外,无论如何设置超时时间,系统都存在一定阻塞,导致用户体验下降。(2) Synchronous control type: use the AT command to control the GSM module, after issuing an AT command, the program blocks until the GSM module returns the result. In order to prevent the program from locking up, a timeout period is generally set. If the return time exceeds the timeout period, the command is considered to have failed. This method is relatively simple to program, but has certain defects: the return time of AT commands that take a long time is not fixed. If the timeout time is set too short, the command failure rate will be high. Affect the system processing speed. In addition, no matter how the timeout period is set, the system will be blocked to a certain extent, which will degrade the user experience.

这些现有技术中存在如下缺点。在数据透传型架构中,GSM模块开启时间过长,因而功耗较高,此外,由于GSM模块持续开启,因而无法使用除GPRS数据传输以外的功能。在同步控制型架构中,对长命令的超时时间难以进行合适的设置,过高则系统长时间阻塞,过低则命令成功率低,而且系统阻塞的存在必定导致用户体验的下降,进一步地,在同步控制逻辑中,主程序代码和GSM模块控制代码耦合程度较高,这导致一旦更换GSM模块,主程序代码必须相应修改,大大提高了开发人员的工作量。The following disadvantages exist in these prior art. In the data transparent transmission type architecture, the GSM module is turned on for a long time, so the power consumption is high. In addition, because the GSM module is continuously turned on, functions other than GPRS data transmission cannot be used. In the synchronous control architecture, it is difficult to properly set the timeout time of long commands. If it is too high, the system will be blocked for a long time. If it is too low, the success rate of the command will be low. Moreover, the existence of system blocking will inevitably lead to the decline of user experience. Further, In the synchronous control logic, the main program code and the GSM module control code are highly coupled, which results in that once the GSM module is replaced, the main program code must be modified accordingly, which greatly increases the workload of developers.

发明内容SUMMARY OF THE INVENTION

本发明旨在解决上述现有技术中存在的问题,本发明的目的是通过以下技术方案实现的。The purpose of the present invention is to solve the problems existing in the above-mentioned prior art, and the purpose of the present invention is achieved through the following technical solutions.

本发明提供一种在单片机中实现GSM模块控制的方法,其特征在于,所述方法包括:The invention provides a method for realizing GSM module control in a single-chip microcomputer, which is characterized in that the method comprises:

步骤S1:检测是否接收到模块启用命令,如果未接收到,则返回到其余业务逻辑,继续等待,如果接收到,则判断要执行的任务是否是GSM任务,如果不是,则关闭GSM模块,如果是,则进入步骤S2;Step S1: Detect whether the module enable command is received, if not, return to the rest of the business logic, continue to wait, if received, determine whether the task to be executed is a GSM task, if not, close the GSM module, if If yes, then go to step S2;

步骤S2:执行GSM任务调度;Step S2: perform GSM task scheduling;

步骤S3:GSM任务调度结束后,返回其余业务逻辑,继续等待新的命令。Step S3: After the GSM task scheduling is completed, return to the rest of the business logic, and continue to wait for new commands.

进一步地,步骤S2中GSM任务调度的执行方法包括:Further, the execution method of GSM task scheduling in step S2 includes:

步骤S201:由依据本发明的系统的GSM任务调度层判断任务是否在进行中,如果任务正在进行中,则进入任务执行处理环节,如果任务不在进行中,则从任务队列中取出一条任务,并进入任务执行处理环节;Step S201: the GSM task scheduling layer of the system according to the present invention judges whether the task is in progress, if the task is in progress, enter the task execution processing link, if the task is not in progress, then take out a task from the task queue, and Enter the task execution processing link;

步骤S202:在任务执行处理环节,判断模块是否出错,如果没有出错,则表示执行成功,退出当前任务;如果出错,则将错误计数器中的数值加1,并进入步骤S203;Step S202: in the task execution processing link, determine whether the module has an error, if there is no error, it means that the execution is successful, and exit the current task; if there is an error, add 1 to the value in the error counter, and enter step S203;

步骤S203:判断错误计数器的数值是否超过预先设定的阈值,如果没有超过,则对GSM状态机进行校正,并退出当前任务;如果超过阈值,则执行任务撤销操作S204;Step S203: judging whether the value of the error counter exceeds a preset threshold, if not, correcting the GSM state machine and exiting the current task; if exceeding the threshold, executing the task cancellation operation S204;

步骤S204:执行模块检测,如果检测不通过,则停用该模块,并退出当前任务;如果检测通过,则清空该错误计数器的值,并退出当前任务。Step S204: Execute module detection, if the detection fails, disable the module and exit the current task; if the detection passes, clear the value of the error counter and exit the current task.

进一步地,所述任务执行处理环节包括:Further, the task execution processing link includes:

步骤S201-1:根据异步等待标志位,判断是否正在等待异步回复,如果不是,则进入步骤S201-2,如果是,则进入步骤S201-3;Step S201-1: According to the asynchronous wait flag, determine whether the asynchronous reply is being waited for, if not, go to step S201-2, if yes, go to step S201-3;

步骤S201-2:判断当前正在执行哪项任务,根据任务编号调用任务执行函数,如果任务执行函数出错,则设置GSM状态变量中的模块错误位,并退出任务执行处理环节;如果任务执行函数没有出错,则在执行完毕后退出任务执行处理环节;Step S201-2: Determine which task is currently being executed, and call the task execution function according to the task number. If the task execution function fails, set the module error bit in the GSM state variable, and exit the task execution processing link; if the task execution function does not If an error occurs, exit the task execution processing link after the execution is completed;

步骤S201-3:检测是否接收到异步回复,如果异步回复超时或失败,则设置GSM状态变量中的模块错误位,并退出任务执行处理环节;如果没有检测到异步回复超时或失败,则继续进行异步回复成功检测,如果该异步回复成功,则重置所述异步等待标志位,并退出任务执行处理环节;如果仍然没有检测到异步回复成功,则直接退出任务执行处理环节。Step S201-3: Detect whether an asynchronous reply is received, if the asynchronous reply times out or fails, set the module error bit in the GSM state variable, and exit the task execution processing link; if no asynchronous reply time-out or failure is detected, continue the process The asynchronous reply is successfully detected. If the asynchronous reply is successful, the asynchronous wait flag is reset, and the task execution processing link is exited; if the asynchronous response success is still not detected, the task execution processing link is directly exited.

进一步地,任务执行函数的运行方法包括:Further, the running method of the task execution function includes:

步骤S201-2-a:根据任务内容判断当前模块的状态,确定需要执行哪项功能封装函数;Step S201-2-a: judge the state of the current module according to the task content, and determine which function encapsulation function needs to be executed;

步骤S201-2-b:根据所确定的功能封装函数编号,调用相应功能封装函数;Step S201-2-b: calling the corresponding function packaging function according to the determined function packaging function number;

步骤S201-2-c:判断功能封装函数是否出错,如果出错,则返回“错误”,否则返回“正常”。Step S201-2-c: Determine whether the function encapsulation function is in error, if there is an error, return "error", otherwise return "normal".

进一步地,其中所述功能封装函数将一条或多条AT命令组合,进行连续执行,对于短时间内有回复的AT命令,以同步方式执行;Further, wherein the function encapsulation function combines one or more AT commands for continuous execution, and executes in a synchronous manner for the AT commands that have a reply in a short time;

对于回复时间长的AT命令,将该AT命令放在功能封装函数的最后,并且设置等待长回复标志位。For an AT command with a long reply time, place the AT command at the end of the function encapsulation function, and set the waiting long reply flag.

进一步地,功能封装函数的执行方法包括:Further, the execution method of the function encapsulation function includes:

步骤ss1:执行短时间内有回复的AT命令,并判断是否执行成功,如果不成功,返回“失败”;如果执行成功,则设置GSM状态变量中的GSM模块状态机,并继续执行后续AT命令;Step ss1: Execute the AT command that has a reply in a short time, and judge whether the execution is successful, if not, return "failure"; if the execution is successful, set the GSM module state machine in the GSM state variable, and continue to execute subsequent AT commands ;

步骤ss2:执行长时间回复的AT命令,设置等待长回复标志位,并设置GSM状态变量中的GSM模块状态机;Step ss2: Execute the AT command of the long-time reply, set the waiting long-reply flag bit, and set the GSM module state machine in the GSM state variable;

步骤ss3:AT命令均执行完成后,返回“成功”。Step ss3: After all AT commands are executed, "success" is returned.

进一步地,将特定命令保存在长时间AT命令列表中,系统在处理待执行AT命令时,查询该长时间AT命令列表,如果待执行AT命令包括在该列表中,则该待执行AT命令属于长时间回复的AT命令,如果不包括在该列表中,则属于短时间内有回复的AT命令。Further, the specific command is stored in the long-term AT command list, and the system queries the long-term AT command list when processing the AT command to be executed. If the AT command to be executed is included in the list, the AT command to be executed belongs to If the AT commands that are replied to for a long time are not included in the list, they belong to the AT commands that are replied in a short time.

本发明还提供一种在单片机中实现GSM模块控制的系统,该系统包括:The present invention also provides a system for realizing GSM module control in the single-chip microcomputer, and the system includes:

GSM任务调度层,用于进行GSM任务切换,并调用任务处理函数和任务撤销函数,如果检测到模块错误,则进行GSM状态机校正;The GSM task scheduling layer is used to switch the GSM task, and call the task processing function and the task cancellation function. If a module error is detected, the GSM state machine will be corrected;

任务处理与撤销层,用于根据当前任务调用相应的任务处理函数;当需要撤销任务时,调用相应的任务撤销函数,根据当前任务进行相应的撤销工作;The task processing and cancellation layer is used to call the corresponding task processing function according to the current task; when the task needs to be cancelled, the corresponding task cancellation function is called, and the corresponding cancellation work is performed according to the current task;

任务执行层,包括至少一个任务执行函数,每一个GSM任务对应于一个任务执行函数,用于根据具体的业务逻辑与模块当前的状态,调用相应的功能函数;The task execution layer includes at least one task execution function, and each GSM task corresponds to a task execution function, which is used to call the corresponding function function according to the specific business logic and the current state of the module;

功能封装层,用于将一条或多条AT指令打包,控制GSM模块实现特定功能;The function encapsulation layer is used to package one or more AT commands to control the GSM module to achieve specific functions;

底层驱动层,用于执行AT命令的发送以及回复的接收和检测;The underlying driver layer is used to send AT commands and receive and detect replies;

所述系统还包括全局变量层,其包括GSM状态变量,用于在所述GSM任务调度层、所述任务处理与撤销层、所述任务执行层、所述功能封装层和所述底层驱动层之间交换信息;The system also includes a global variable layer, which includes GSM state variables, which are used in the GSM task scheduling layer, the task processing and cancellation layer, the task execution layer, the function encapsulation layer, and the underlying driver layer. exchange of information;

其中,所述GSM任务调度层、所述任务处理与撤销层、所述任务执行层、所述功能封装层和所述底层驱动层依次连接,并均与所述全局变量层连接。Wherein, the GSM task scheduling layer, the task processing and cancellation layer, the task execution layer, the function encapsulation layer and the underlying driver layer are connected in sequence, and are all connected with the global variable layer.

进一步地,所述GSM状态变量中保存有:GSM模块状态机、GSM任务队列、当前执行的任务、当前执行的功能函数、接收缓存和发送缓存、模块错误位,在每条功能封装执行成功后,需设置GSM模块状态机。Further, the GSM state variable is stored with: GSM module state machine, GSM task queue, currently executed task, currently executed functional function, receiving buffer and sending buffer, module error bit, after each function encapsulation is executed successfully. , the GSM module state machine needs to be set.

进一步地,其中底层驱动层包括三个底层驱动函数:命令发送函数、回复接收函数和回复检测函数,其配置用于:首先,所述命令发送函数清空接收缓存,然后将发送缓存里的内容通过串口发送到GSM模块;其次,在串口中断里调用回复接收函数,将串口回复的字符串存入到接收缓存中;并且,所述回复检测函数扫描接收缓存来判断是否有回复以及回复内容。Further, the underlying driver layer includes three underlying driver functions: a command sending function, a reply receiving function, and a reply detecting function, which are configured to: first, the command sending function clears the receiving buffer, and then sends the content in the sending buffer through the The serial port is sent to the GSM module; secondly, the reply receiving function is called in the serial port interrupt, and the string replied by the serial port is stored in the receiving buffer; and the reply detection function scans the receiving buffer to determine whether there is a reply and the content of the reply.

本发明基于独创的在单片机上控制GSM模块的软件架构,具有以下特点:1、本发明的软件架构具有较低功耗,尤其适用于便携式智能硬件产品。2、本发明将同步控制与异步控制结合,把阻塞环节的耗时减少到最小。3、本发明由于GSM模块的灵活性,对于收发的GPRS数据没有任何限制。4、本发明能够支持短信收发、GPRS数据传输这两项GSM基础功能。5、本发明能够实现对GSM功能的封装以及与主程序代码的解耦,减少GSM模块更换时需要重写的代码量。通过本发明的改进,能够在单片机上实现GSM模块的低功耗、高效率、高兼容性的控制。The present invention is based on an original software architecture for controlling the GSM module on a single-chip microcomputer, and has the following features: 1. The software architecture of the present invention has low power consumption, and is especially suitable for portable intelligent hardware products. 2. The present invention combines synchronous control with asynchronous control to minimize the time consuming of blocking links. 3. Due to the flexibility of the GSM module, the present invention does not have any restrictions on the GPRS data sent and received. 4. The present invention can support two basic GSM functions of sending and receiving short messages and GPRS data transmission. 5. The present invention can realize the encapsulation of the GSM function and the decoupling from the main program code, thereby reducing the amount of code that needs to be rewritten when the GSM module is replaced. Through the improvement of the invention, the low power consumption, high efficiency and high compatibility control of the GSM module can be realized on the single chip microcomputer.

与现有方法相比,本发明通过五层划分加一套全局变量的软件架构,将GSM的任务划分成GSM模块的功能序列,每次调用任务执行函数,执行一个功能封装函数,该功能封装函数通过异步控制,对于短时间内有回复的AT命令,通过同步方式检测其回复,可以较迅速地做出响应,而对于回复时间较长的AT命令,通过异步方式检测其回复,大大减少了回复的等待时间。Compared with the existing method, the present invention divides the GSM task into the function sequence of the GSM module through a software architecture of five-layer division and a set of global variables, calls the task execution function each time, and executes a function encapsulation function, which encapsulates the function. The function is controlled asynchronously. For AT commands that have a reply in a short time, the reply can be detected in a synchronous way, and the response can be made more quickly. For AT commands with a long reply time, the reply is detected in an asynchronous way, which greatly reduces the number of responses. The wait time for a reply.

综上所述,本发明的优点在于:与数据透传型架构相比,本发明在空闲时关闭GSM模块,有任务时开启,可以降低功耗,并且GSM模块无需一直保持在GPRS连接状态(仅在需要时开启),因此可以使用短信功能;与同步控制型架构相比,本发明将耗时长的AT命令以异步方式检测回复,相比同步方式,可以设置更大的超时时间,因此稳定性更高,而且不会影响用户体验,此外,对需要实现的程序代码进行了明确的封装和分装,其中与GSM模块直接相关的只有功能封装层,因此减少了模块发生变动时需要修改的代码数量。To sum up, the advantages of the present invention are: compared with the data transparent transmission type architecture, the present invention turns off the GSM module when it is idle, and turns it on when there is a task, which can reduce power consumption, and the GSM module does not need to be kept in the GPRS connection state ( It is only turned on when needed), so the short message function can be used; compared with the synchronous control structure, the present invention detects and replies the AT commands that take a long time in an asynchronous way, and can set a larger timeout period than the synchronous way, so it is stable It is more flexible and will not affect the user experience. In addition, the program code that needs to be implemented is clearly packaged and subpackaged. Only the functional package layer is directly related to the GSM module, thus reducing the need for modification when the module changes. number of codes.

附图说明Description of drawings

通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are for the purpose of illustrating preferred embodiments only and are not to be considered limiting of the invention. Also, the same components are denoted by the same reference numerals throughout the drawings. In the attached image:

附图1示出了根据本发明实施方式的在单片机中实现GSM模块控制的系统框架图。FIG. 1 shows a system frame diagram of implementing GSM module control in a single-chip microcomputer according to an embodiment of the present invention.

附图2示出了根据本发明实施方式系统中的主程序执行流程图。FIG. 2 shows a flow chart of the execution of the main program in the system according to the embodiment of the present invention.

附图3示出了根据本发明实施方式的GSM任务调度的具体执行方法流程图。FIG. 3 shows a flowchart of a specific execution method of GSM task scheduling according to an embodiment of the present invention.

附图4示出了根据本发明实施方式的任务处理与撤销层的具体工作方法流程图。FIG. 4 shows a flowchart of a specific working method of the task processing and cancellation layer according to an embodiment of the present invention.

附图5示出了根据本发明实施方式的任务执行函数的运行方法流程图。FIG. 5 shows a flowchart of a method for running a task execution function according to an embodiment of the present invention.

附图6示出了根据本发明实施方式的功能封装函数的执行方法流程图。FIG. 6 shows a flowchart of a method for executing a function encapsulation function according to an embodiment of the present invention.

具体实施方式Detailed ways

下面将参照附图更详细地描述本公开的示例性实施方式。虽然附图中显示了本公开的示例性实施方式,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施方式所限制。相反,提供这些实施方式是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided so that the present disclosure will be more thoroughly understood, and will fully convey the scope of the present disclosure to those skilled in the art.

根据本发明的实施方式,本发明在硬件方面至少包括8位单片机;1KB以上RAM,其中512B作为接收缓存,512B作为发送缓存;GSM模块;GSM模块和单片机间的串口连接,例如连接TX和RX线。该单片机通过串口中断方式接收GSM模块回复。According to the embodiment of the present invention, the present invention includes at least an 8-bit single-chip microcomputer in terms of hardware; a RAM of more than 1KB, of which 512B is used as a receiving buffer and 512B is used as a sending buffer; a GSM module; a serial port connection between the GSM module and the single-chip microcomputer, such as connecting TX and RX Wire. The microcontroller receives the reply from the GSM module through serial port interruption.

在软件方面,本发明的在单片机中实现GSM模块控制的系统包括五层结构,图1示出了本发明软件系统的构成框图,包括五层结构,依次为:GSM任务调度层、任务处理与撤销层、任务执行层、功能封装层、底层驱动层。五层之间使用一套全局变量(GSM状态变量)来交换信息,其中各层的构成原理按照在程序调用树中的层级来排布。In terms of software, the system for realizing GSM module control in a single-chip microcomputer of the present invention includes a five-layer structure. Cancellation layer, task execution layer, function encapsulation layer, underlying driver layer. A set of global variables (GSM state variables) are used to exchange information among the five layers, wherein the composition principle of each layer is arranged according to the level in the program call tree.

具体而言,GSM状态变量中保存有:GSM模块状态机、GSM任务队列、当前执行的任务、当前执行的功能函数、接收缓存和发送缓存、模块错误位等,用于在各层之间进行衔接和控制。GSM任务调度层用于进行GSM任务切换,并调用任务处理函数和任务撤销函数,如果检测到模块错误,则进行状态机校正。任务处理与撤销层根据当前任务调用相应的任务处理函数;当需要撤销任务时,调用相应的任务撤销函数,根据当前任务进行相应的撤销工作。任务执行层包括至少一个任务执行函数,其根据具体的业务逻辑与模块当前的状态,调用相应的功能函数。每一个GSM任务都有一个对应的任务执行函数。功能封装层将一条或多条AT指令打包,控制GSM模块实现某个功能。在每条功能封装执行成功后,需设置GSM模块的状态机。底层驱动层用于执行AT命令的发送以及回复的接收和检测。Specifically, the GSM state variables store: GSM module state machine, GSM task queue, currently executed tasks, currently executed functional functions, receive buffers and send buffers, module error bits, etc. articulation and control. The GSM task scheduling layer is used to switch the GSM task, and call the task processing function and the task cancellation function. If a module error is detected, the state machine will be corrected. The task processing and cancellation layer calls the corresponding task processing function according to the current task; when the task needs to be cancelled, the corresponding task cancellation function is called, and the corresponding cancellation work is performed according to the current task. The task execution layer includes at least one task execution function, which calls the corresponding function function according to the specific business logic and the current state of the module. Each GSM task has a corresponding task execution function. The function encapsulation layer packs one or more AT commands to control the GSM module to achieve a certain function. After each function package is successfully executed, the state machine of the GSM module needs to be set. The underlying driver layer is used to perform the sending of AT commands and the receiving and detection of replies.

图2示出了基于本发明的系统的主程序执行流程。本发明的在单片机中实现GSM模块控制的方法,首先对装置中的模块进行检测,如果检测不通过,则停用该模块,并进入其余业务逻辑,如果检测通过,则直接进入其余业务逻辑,并执行以下步骤:Fig. 2 shows the main program execution flow of the system based on the present invention. In the method for realizing GSM module control in a single-chip microcomputer of the present invention, firstly, the module in the device is detected. If the detection fails, the module is deactivated, and the remaining business logic is entered. If the detection is passed, the remaining business logic is directly entered. and perform the following steps:

步骤S1:检测是否接收到模块启用命令,如果未接收到,则返回其余业务逻辑,继续等待,如果接收到,则判断要执行的任务是否是GSM任务,如果不是,则关闭GSM模块,如果是,则进入步骤S2;Step S1: Detect whether the module enabling command is received, if not, return to the rest of the business logic, continue to wait, if received, determine whether the task to be executed is a GSM task, if not, close the GSM module, if yes , then enter step S2;

步骤S2:执行GSM任务调度;Step S2: perform GSM task scheduling;

步骤S3:GSM任务调度结束后,返回其余业务逻辑,继续等待新的命令。Step S3: After the GSM task scheduling is completed, return to the rest of the business logic, and continue to wait for new commands.

其中,步骤S2中GSM任务调度的具体执行方法流程如图3所示,包括:Wherein, the specific execution method flow of GSM task scheduling in step S2 is shown in Figure 3, including:

步骤S201:由依据本发明的系统的GSM任务调度层判断任务是否在进行中,如果任务正在进行中,则进入任务执行处理环节,如果任务不在进行中,则从任务队列中取出一条任务,并进入任务执行处理环节;所述从任务队列中取出一条任务,优选为选择优先级最高的任务;Step S201: the GSM task scheduling layer of the system according to the present invention judges whether the task is in progress, if the task is in progress, enter the task execution processing link, if the task is not in progress, then take out a task from the task queue, and Enter the task execution processing link; the task of taking out a task from the task queue is preferably the task with the highest priority;

步骤S202:在任务执行处理环节,判断模块是否出错,如果没有出错,则表示执行成功,退出当前任务;如果出错,则将错误计数器中的数值加1,并进入步骤S203;Step S202: in the task execution processing link, determine whether the module has an error, if there is no error, it means that the execution is successful, and exit the current task; if there is an error, add 1 to the value in the error counter, and enter step S203;

步骤S203:判断错误计数器的数值是否超过预先设定的阈值,如果没有超过,则对GSM状态机进行校正,并退出当前任务;如果超过阈值,则执行任务撤销操作S204;Step S203: judging whether the value of the error counter exceeds a preset threshold, if not, correcting the GSM state machine and exiting the current task; if exceeding the threshold, executing the task cancellation operation S204;

步骤S204:执行模块检测,如果检测不通过,则停用该模块,并退出当前任务;如果检测通过,则清空该错误计数器的值,并退出当前任务。Step S204: Execute module detection, if the detection fails, disable the module and exit the current task; if the detection passes, clear the value of the error counter and exit the current task.

需要注意的是,本发明中GSM任务调度的具体执行过程并不仅仅由系统中的GSM任务调度层完成。在执行过程中,需要调用任务处理与撤销层的任务处理模块、任务撤销模块,以进行任务执行处理和任务撤销操作,该任务处理模块和任务撤销模块分别包括任务执行函数和任务撤销函数。此外,上述步骤S202和S203中的判断步骤可以由任务处理模块执行,也可以由GSM任务调度层来执行。It should be noted that the specific execution process of the GSM task scheduling in the present invention is not only completed by the GSM task scheduling layer in the system. During the execution process, the task processing module and the task cancellation module of the task processing and cancellation layer need to be called to perform task execution processing and task cancellation operations. The task processing module and the task cancellation module respectively include a task execution function and a task cancellation function. In addition, the judging steps in the above steps S202 and S203 may be performed by the task processing module, or may be performed by the GSM task scheduling layer.

所述任务处理与撤销层的具体工作方法如图4所示,所述任务执行处理的方法具体包括:The specific working method of the task processing and cancellation layer is shown in Figure 4, and the task execution processing method specifically includes:

步骤S201-1:根据异步等待标志位,判断是否正在等待异步回复,如果不是,则进入步骤S201-2,如果是,则进入步骤S201-3;Step S201-1: According to the asynchronous wait flag, determine whether the asynchronous reply is being waited for, if not, go to step S201-2, if yes, go to step S201-3;

步骤S201-2:判断当前正在执行哪项任务,根据任务编号调用任务执行函数,例如调用任务1执行函数、任务2执行函数、任务3执行函数等,如果任务执行函数出错,则设置GSM状态变量中的模块错误位,并退出任务执行处理环节;如果任务执行函数没有出错,则在执行完毕后退出任务执行处理环节;Step S201-2: Determine which task is currently being executed, and call the task execution function according to the task number, such as calling the task 1 execution function, the task 2 execution function, the task 3 execution function, etc. If the task execution function is wrong, set the GSM state variable module error bit in , and exit the task execution processing link; if there is no error in the task execution function, exit the task execution processing link after the execution is completed;

步骤S201-3:检测是否接收到异步回复,如果异步回复超时或失败,则设置GSM状态变量中的模块错误位,并退出任务执行处理环节;如果没有检测到异步回复超时或失败,则再进行异步回复成功检测,从而反复确定该异步回复的正确性,提高系统运行的准确度。如果该异步回复成功,则重置所述异步等待标志位,并退出任务执行处理环节;如果仍然没有检测到异步回复成功,则直接退出任务执行处理环节。Step S201-3: Detect whether an asynchronous reply is received, if the asynchronous reply times out or fails, set the module error bit in the GSM state variable, and exit the task execution processing link; if the asynchronous reply time-out or failure is not detected, proceed again The asynchronous reply is successfully detected, so that the correctness of the asynchronous reply is repeatedly determined, and the accuracy of the system operation is improved. If the asynchronous reply is successful, the asynchronous wait flag is reset, and the task execution processing link is exited; if it is still not detected that the asynchronous response is successful, the task execution processing link is directly exited.

上述任务执行函数包括在系统的任务执行层中,其包括根据任务而定的业务逻辑。任务执行函数在被调用时,通过实际任务内容来判断需要执行的功能封装函数,并且根据功能封装函数的执行结果来返回错误/正确,参考图5。任务执行函数的运行方法包括:The above task execution function is included in the task execution layer of the system, which includes business logic determined according to the task. When the task execution function is called, it judges the function encapsulation function to be executed according to the actual task content, and returns an error/correct according to the execution result of the function encapsulation function, referring to FIG. 5 . The running methods of the task execution function include:

步骤S201-2-a:根据任务内容判断当前模块的状态,确定需要执行哪项功能封装函数;Step S201-2-a: judge the state of the current module according to the task content, and determine which function encapsulation function needs to be executed;

步骤S201-2-b:根据所确定的结果,调用相应功能封装函数,例如功能1封装函数、功能2封装函数、功能3封装函数;Step S201-2-b: according to the determined result, call the corresponding function encapsulation function, for example, the function 1 encapsulation function, the function 2 encapsulation function, and the function 3 encapsulation function;

步骤S201-2-c:判断功能封装函数是否出错,如果出错,则返回“错误”,否则返回“正常”。Step S201-2-c: Determine whether the function encapsulation function is in error, if there is an error, return "error", otherwise return "normal".

所述功能封装函数包含在本发明系统的功能封装层中,其将一条或多条AT命令组合在一起进行连续执行。具体而言,对于短时间内有回复的AT命令,以同步方式进行;而如果功能封装函数中需要执行长时间AT命令,则该命令必须放在功能封装函数的最后,并且要设置长回复等待位。如果功能封装函数执行成功,需要相应设置GSM状态变量中的GSM模块状态。本发明功能封装函数的执行方法的一个示例流程图如图6所示,包括:The function encapsulation function is included in the function encapsulation layer of the system of the present invention, which combines one or more AT commands for continuous execution. Specifically, for the AT command that has a reply in a short time, it is carried out in a synchronous manner; and if a long time AT command needs to be executed in the function encapsulation function, the command must be placed at the end of the function encapsulation function, and a long reply wait must be set. bit. If the function encapsulation function is executed successfully, the GSM module state in the GSM state variable needs to be set accordingly. An example flow chart of the execution method of the function encapsulation function of the present invention is shown in FIG. 6 , including:

步骤I:首先执行短时间内有回复的AT命令1,并判断是否执行成功,如果不成功,返回“失败”;如果执行成功,则设置GSM状态变量中的GSM模块状态机,并继续执行后续AT命令;Step 1: First execute the AT command 1 that has a reply in a short time, and judge whether the execution is successful, if not, return "failure"; if the execution is successful, set the GSM module state machine in the GSM state variable, and continue to execute the follow-up AT command;

步骤II:执行短时间内有回复的AT命令2,并判断是否执行成功,如果不成功,返回“失败”;如果执行成功,则再次设置GSM状态变量中的GSM模块状态机,并继续执行后续AT命令;Step II: Execute the AT command 2 that has a reply in a short time, and judge whether the execution is successful, if not, return "failure"; if the execution is successful, set the GSM module state machine in the GSM state variable again, and continue to execute the follow-up AT command;

步骤III:执行长时间回复的AT命令1,设置等待长回复标志位,并设置GSM状态变量中的GSM模块状态机。所述等待长回复标志位用于指示系统正在等待该长时间回复的AT命令1的回复。Step III: Execute the AT command 1 of the long reply, set the waiting long reply flag, and set the GSM module state machine in the GSM state variable. The waiting long reply flag bit is used to indicate that the system is waiting for the reply of the long reply AT command 1.

步骤IV:AT命令均执行完成后,返回“成功”。Step IV: After all AT commands are executed, "success" is returned.

在上述方法中,短时间内有回复的AT命令数目不限,图6中以2个AT命令作为示意,仅仅是为了使得示例清楚易懂,实际系统中,AT命令的数目可以是1个或大于2个,则步骤I的重复次数则相应地改变。但是需要注意的是,如果AT命令数量过多,执行时间过长,则系统每个主循环的最大延时会增加,这将不利于系统的运行。In the above method, the number of AT commands that can be replied in a short time is not limited. In FIG. 6, 2 AT commands are used as an illustration, just to make the example clear and easy to understand. In an actual system, the number of AT commands can be one or more. If more than 2, the number of repetitions of step I is changed accordingly. However, it should be noted that if the number of AT commands is too large and the execution time is too long, the maximum delay of each main loop of the system will increase, which will be detrimental to the operation of the system.

此外,长时间回复的AT命令1相对应的流程在图6中以虚线框表示,因为其为可选项,如果存在长时间回复的AT命令,则执行步骤III,如果不存在,则步骤III可以忽略。同样地,此处仅仅以1个AT命令作为示意,实际系统中可以不限于1个。In addition, the process corresponding to the AT command 1 with a long-term reply is represented by a dashed box in FIG. 6, because it is an optional option. If there is an AT command with a long-time reply, step III is performed. If there is no AT command, then step III can be used. neglect. Likewise, only one AT command is used here as an illustration, and the actual system may not be limited to one.

进一步地,所述短时间内有回复的AT命令、长时间回复的AT命令的区分标准可以由开发人员预先设定。例如,可以将特定命令设置为长时间回复的AT命令,其余命令均属于短时间内有回复的AT命令。具体而言,可以将特定命令保存在长时间AT命令列表中,系统在分辨待执行AT命令的种类时,查询该长时间AT命令列表,如果待执行AT命令包括在该列表中,则该待执行AT命令属于长时间回复的AT命令,如果不包括在该列表中,则属于短时间内有回复的AT命令。Further, the distinguishing standard of the AT command that has a reply in a short time and the AT command that has a reply for a long time can be preset by the developer. For example, a specific command can be set to be an AT command with a long reply, and the rest of the commands are AT commands with a reply in a short time. Specifically, the specific command can be saved in the long-term AT command list, and the system queries the long-term AT command list when distinguishing the type of the AT command to be executed. If the AT command to be executed is included in the list, the Executing an AT command is an AT command with a long-term reply, and if it is not included in the list, it is an AT command with a reply in a short time.

所述区分标准还可以由系统进行训练,例如,设置时间阈值t,当同一条AT命令的回复时间超过t的次数达到预定限值时,将该条AT命令记为长时间回复的AT命令,否则记为短时间内有回复的AT命令。系统训练的好处在于,能够根据该系统的实际情况,灵活调节AT命令的分类,从而使得AT命令的执行过程能够更好地适应当前平台。The distinguishing criteria can also be trained by the system, for example, a time threshold t is set, and when the number of times the reply time of the same AT command exceeds t reaches a predetermined limit, the AT command is recorded as a long-time reply AT command, Otherwise, it is recorded as an AT command that has a reply in a short time. The advantage of system training is that the classification of AT commands can be flexibly adjusted according to the actual situation of the system, so that the execution process of AT commands can better adapt to the current platform.

底层驱动层包括三个底层驱动函数:命令发送函数、回复接收函数和回复检测函数。具体执行时,首先,所述命令发送函数清空接收缓存,然后将发送缓存里的内容通过串口发送到GSM模块;其次,在串口中断里调用回复接收函数,将串口回复的字符串存入到接收缓存中;此外,回复检测函数扫描接收缓存来判断是否有回复以及回复内容。The bottom driver layer includes three bottom driver functions: command sending function, reply receiving function and reply detection function. During specific execution, first, the command sending function clears the receiving buffer, and then sends the content in the sending buffer to the GSM module through the serial port; secondly, the reply receiving function is called in the serial port interrupt, and the string replied by the serial port is stored in the receiving In the cache; in addition, the reply detection function scans the receiving cache to determine whether there is a reply and the content of the reply.

本发明的在单片机中实现GSM模块控制的系统还包括两个错误处理函数:GSM状态机校正函数和模块检测函数。其中,GSM状态机校正函数用于在程序发生错误时,发送相关的AT命令来确认GSM模块当前的状态,并相应设置GSM模块状态机,该GSM状态机校正函数例如可用于执行GSM状态机校正。模块检测函数用于发送相关AT命令来检测模块功能是否正常,可用于执行模块检测。The system for realizing GSM module control in the single-chip microcomputer of the present invention further includes two error handling functions: a GSM state machine correction function and a module detection function. Among them, the GSM state machine correction function is used to send relevant AT commands to confirm the current state of the GSM module when an error occurs in the program, and set the GSM module state machine accordingly, the GSM state machine correction function can be used to perform GSM state machine correction, for example . The module detection function is used to send relevant AT commands to detect whether the module function is normal, and can be used to perform module detection.

以上所述,仅为本发明较佳的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到的变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以所述权利要求的保护范围为准。The above description is only a preferred embodiment of the present invention, but the protection scope of the present invention is not limited to this. Substitutions should be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims (8)

1.一种在单片机中实现GSM模块控制的方法,其特征在于,所述方法包括:1. a method for realizing GSM module control in single-chip microcomputer, is characterized in that, described method comprises: 步骤S1:检测是否接收到模块启用命令,如果未接收到,则返回到其余业务逻辑,继续等待,如果接收到,则判断要执行的任务是否是GSM任务,如果不是,则关闭GSM模块,如果是,则进入步骤S2;Step S1: Detect whether the module enable command is received, if not, return to the rest of the business logic, continue to wait, if received, determine whether the task to be executed is a GSM task, if not, close the GSM module, if If yes, then go to step S2; 步骤S2:执行GSM任务调度;Step S2: perform GSM task scheduling; 步骤S3:GSM任务调度结束后,返回其余业务逻辑,继续等待新的命令,其中步骤S2中GSM任务调度的执行方法包括:Step S3: After the GSM task scheduling is completed, return to the rest of the business logic, and continue to wait for new commands, wherein the execution method of the GSM task scheduling in step S2 includes: 步骤S201:由GSM任务调度层判断任务是否在进行中,如果任务正在进行中,则进入任务执行处理环节,如果任务不在进行中,则从任务队列中取出一条任务,并进入任务执行处理环节;Step S201: determine whether the task is in progress by the GSM task scheduling layer, if the task is in progress, then enter the task execution processing link, if the task is not in progress, then take out a task from the task queue, and enter the task execution processing link; 步骤S202:在任务执行处理环节,判断模块是否出错,如果没有出错,则表示执行成功,退出当前任务;如果出错,则将错误计数器中的数值加1,并进入步骤S203;Step S202: in the task execution processing link, determine whether the module has an error, if there is no error, it means that the execution is successful, and exit the current task; if there is an error, add 1 to the value in the error counter, and enter step S203; 步骤S203:判断错误计数器的数值是否超过预先设定的阈值,如果没有超过,则对GSM状态机进行校正,并退出当前任务;如果超过阈值,则执行任务撤销操作S204;Step S203: judging whether the value of the error counter exceeds a preset threshold, if not, correcting the GSM state machine and exiting the current task; if exceeding the threshold, executing the task cancellation operation S204; 步骤S204:执行模块检测,如果检测不通过,则停用该模块,并退出当前任务;如果检测通过,则清空该错误计数器的值,并退出当前任务,其中步骤201、步骤202中所述任务执行处理环节包括:Step S204: Execute module detection, if the detection fails, disable the module and exit the current task; if the detection passes, clear the value of the error counter and exit the current task, wherein the tasks described in steps 201 and 202 The execution process includes: 步骤S201-1:根据异步等待标志位,判断是否正在等待异步回复,如果不是,则进入步骤S201-2,如果是,则进入步骤S201-3;Step S201-1: According to the asynchronous wait flag, determine whether the asynchronous reply is being waited for, if not, go to step S201-2, if yes, go to step S201-3; 步骤S201-2:判断当前正在执行哪项任务,根据任务编号调用任务执行函数,如果任务执行函数出错,则设置GSM状态变量中的模块错误位,并退出任务执行处理环节;如果任务执行函数没有出错,则在执行完毕后退出任务执行处理环节;Step S201-2: Determine which task is currently being executed, and call the task execution function according to the task number. If the task execution function fails, set the module error bit in the GSM state variable, and exit the task execution processing link; if the task execution function does not If an error occurs, exit the task execution processing link after the execution is completed; 步骤S201-3:检测是否接收到异步回复,如果异步回复超时或失败,则设置GSM状态变量中的模块错误位,并退出任务执行处理环节;如果没有检测到异步回复超时或失败,则继续进行异步回复成功检测,如果该异步回复成功,则重置所述异步等待标志位,并退出任务执行处理环节;如果仍然没有检测到异步回复成功,则直接退出任务执行处理环节。Step S201-3: Detect whether an asynchronous reply is received, if the asynchronous reply times out or fails, set the module error bit in the GSM state variable, and exit the task execution processing link; if no asynchronous reply time-out or failure is detected, continue the process The asynchronous reply is successfully detected. If the asynchronous reply is successful, the asynchronous wait flag is reset, and the task execution processing link is exited; if the asynchronous response success is still not detected, the task execution processing link is directly exited. 2.如权利要求1所述的方法,其中任务执行函数的运行方法包括:2. The method according to claim 1, wherein the running method of the task execution function comprises: 步骤S201-2-a:根据任务内容判断当前模块的状态,确定需要执行哪项功能封装函数;Step S201-2-a: judge the state of the current module according to the task content, and determine which function encapsulation function needs to be executed; 步骤S201-2-b:根据所确定的功能封装函数编号,调用相应功能封装函数;Step S201-2-b: calling the corresponding function packaging function according to the determined function packaging function number; 步骤S201-2-c:判断功能封装函数是否出错,如果出错,则返回“错误”,否则返回“正常”。Step S201-2-c: Determine whether the function encapsulation function is in error, if there is an error, return "error", otherwise return "normal". 3.如权利要求2所述的方法,其中所述功能封装函数将一条或多条AT命令组合,进行连续执行,对于短时间内有回复的AT命令,以同步方式执行;3. The method according to claim 2, wherein the function encapsulation function combines one or more AT commands for continuous execution, and for the AT commands that reply in a short time, executes in a synchronous manner; 对于回复时间长的AT命令,将该AT命令放在功能封装函数的最后,并且设置等待长回复标志位。For an AT command with a long reply time, place the AT command at the end of the function encapsulation function, and set the waiting long reply flag. 4.如权利要求3所述的方法,其中功能封装函数的执行方法包括:4. The method of claim 3, wherein the execution method of the function encapsulation function comprises: 步骤ss1:执行短时间内有回复的AT命令,并判断是否执行成功,如果不成功,返回“失败”;如果执行成功,则设置GSM状态变量中的GSM模块状态机,并继续执行后续AT命令;Step ss1: Execute the AT command that has a reply in a short time, and judge whether the execution is successful, if not, return "failure"; if the execution is successful, set the GSM module state machine in the GSM state variable, and continue to execute subsequent AT commands ; 步骤ss2:执行长时间回复的AT命令,设置等待长回复标志位,并设置GSM状态变量中的GSM模块状态机;Step ss2: Execute the AT command of the long-time reply, set the waiting long-reply flag bit, and set the GSM module state machine in the GSM state variable; 步骤ss3:AT命令均执行完成后,返回“成功”。Step ss3: After all AT commands are executed, "success" is returned. 5.如权利要求4所述的方法,其中将特定命令保存在长时间AT命令列表中,系统在处理待执行AT命令时,查询该长时间AT命令列表,如果待执行AT命令包括在该列表中,则该待执行AT命令属于长时间回复的AT命令,如果不包括在该列表中,则属于短时间内有回复的AT命令。5. The method of claim 4, wherein the specific command is stored in a long-term AT command list, and the system queries the long-term AT command list when processing the AT command to be executed, and if the AT command to be executed is included in the list , the AT command to be executed belongs to an AT command that has been replied for a long time, and if it is not included in the list, it is an AT command that has a reply in a short time. 6.一种在单片机中实现GSM模块控制的系统,用于执行权利要求1-5中任一项所述的方法,其特征在于,该系统包括:6. A system for realizing GSM module control in a single-chip microcomputer, for carrying out the method described in any one of claims 1-5, is characterized in that, this system comprises: GSM任务调度层,用于进行GSM任务切换,并调用任务处理函数和任务撤销函数,如果检测到模块错误,则进行GSM状态机校正;The GSM task scheduling layer is used to switch the GSM task, and call the task processing function and the task cancellation function. If a module error is detected, the GSM state machine will be corrected; 任务处理与撤销层,用于根据当前任务调用相应的任务处理函数;当需要撤销任务时,调用相应的任务撤销函数,根据当前任务进行相应的撤销工作;The task processing and cancellation layer is used to call the corresponding task processing function according to the current task; when the task needs to be cancelled, the corresponding task cancellation function is called, and the corresponding cancellation work is performed according to the current task; 任务执行层,包括至少一个任务执行函数,每一个GSM任务对应于一个任务执行函数,用于根据具体的业务逻辑与模块当前的状态,调用相应的功能函数;The task execution layer includes at least one task execution function, and each GSM task corresponds to a task execution function, which is used to call the corresponding function function according to the specific business logic and the current state of the module; 功能封装层,用于将一条或多条AT指令打包,控制GSM模块实现特定功能;The function encapsulation layer is used to package one or more AT commands to control the GSM module to achieve specific functions; 底层驱动层,用于执行AT命令的发送以及回复的接收和检测;The underlying driver layer is used to send AT commands and receive and detect replies; 所述系统还包括全局变量层,其包括GSM状态变量,用于在所述GSM任务调度层、所述任务处理与撤销层、所述任务执行层、所述功能封装层和所述底层驱动层之间交换信息;The system also includes a global variable layer, which includes GSM state variables, which are used in the GSM task scheduling layer, the task processing and cancellation layer, the task execution layer, the function encapsulation layer, and the underlying driver layer. exchange of information; 其中,所述GSM任务调度层、所述任务处理与撤销层、所述任务执行层、所述功能封装层和所述底层驱动层依次连接,并均与所述全局变量层连接。Wherein, the GSM task scheduling layer, the task processing and cancellation layer, the task execution layer, the function encapsulation layer and the underlying driver layer are connected in sequence, and are all connected with the global variable layer. 7.如权利要求6所述的系统,其中,所述GSM状态变量中保存有:GSM模块状态机、GSM任务队列、当前执行的任务、当前执行的功能函数、接收缓存和发送缓存、模块错误位,在每条功能封装执行成功后,需设置GSM模块状态机。7. system as claimed in claim 6, wherein, in described GSM state variable, keep: GSM module state machine, GSM task queue, the task of current execution, the function function of current execution, receive buffer and send buffer, module error bit, after each function package is successfully executed, the GSM module state machine needs to be set. 8.如权利要求7所述的系统,其中底层驱动层包括三个底层驱动函数:命令发送函数、回复接收函数和回复检测函数,其配置用于:8. The system of claim 7, wherein the underlying driver layer comprises three underlying driver functions: a command sending function, a reply receiving function and a reply detecting function, which are configured to: 首先,所述命令发送函数清空接收缓存,然后将发送缓存里的内容通过串口发送到GSM模块;First, the command sending function clears the receiving buffer, and then sends the content in the sending buffer to the GSM module through the serial port; 其次,在串口中断里调用回复接收函数,将串口回复的字符串存入到接收缓存中;Secondly, call the reply receiving function in the serial port interrupt, and store the string replied by the serial port into the receiving buffer; 并且,所述回复检测函数扫描接收缓存来判断是否有回复以及回复内容。In addition, the reply detection function scans the receiving buffer to determine whether there is a reply and the content of the reply.
CN201710020080.0A 2017-01-11 2017-01-11 System and method for realizing GSM module control in single chip microcomputer Active CN106658688B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710020080.0A CN106658688B (en) 2017-01-11 2017-01-11 System and method for realizing GSM module control in single chip microcomputer

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710020080.0A CN106658688B (en) 2017-01-11 2017-01-11 System and method for realizing GSM module control in single chip microcomputer

Publications (2)

Publication Number Publication Date
CN106658688A CN106658688A (en) 2017-05-10
CN106658688B true CN106658688B (en) 2020-01-10

Family

ID=58842732

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710020080.0A Active CN106658688B (en) 2017-01-11 2017-01-11 System and method for realizing GSM module control in single chip microcomputer

Country Status (1)

Country Link
CN (1) CN106658688B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111615099B (en) * 2020-04-28 2023-07-04 深圳市有方科技股份有限公司 eSIM card interaction control method and related equipment
CN113179227B (en) * 2021-04-26 2023-05-19 哈尔滨铁路科研所科技有限公司 AT instruction control method based on queue

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101853155A (en) * 2010-04-15 2010-10-06 中兴通讯股份有限公司 Method and device for automatically sending AT command
CN102256239A (en) * 2011-07-05 2011-11-23 华为终端有限公司 Multimode terminal and data processing method for multimode terminal
WO2014002968A1 (en) * 2012-06-25 2014-01-03 京セラ株式会社 Communication terminal and communication control method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101853155A (en) * 2010-04-15 2010-10-06 中兴通讯股份有限公司 Method and device for automatically sending AT command
CN102256239A (en) * 2011-07-05 2011-11-23 华为终端有限公司 Multimode terminal and data processing method for multimode terminal
WO2014002968A1 (en) * 2012-06-25 2014-01-03 京セラ株式会社 Communication terminal and communication control method

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
单片机控制GSM模块实现短信收发的技术及应用;牛丹,等;《仪器仪表与分析监测》;20080831;全文 *

Also Published As

Publication number Publication date
CN106658688A (en) 2017-05-10

Similar Documents

Publication Publication Date Title
US20190086993A1 (en) Methods and apparatus for running and booting an inter-processor communication link between independently operable processors
US8438572B2 (en) Task scheduling method and apparatus
CN109688058B (en) Message processing method and device and network equipment
CN104750510A (en) Chip start method and multi-core processor chip
US20140115603A1 (en) Method, apparatus, and system for scheduling processor core in multiprocessor core system
CN107046508A (en) Message receiving method and network equipment
US12386616B2 (en) Detecting infinite loops in a programmable atomic transaction
CN101609544A (en) A data loading and testing method and device for an image processor
CN111200541B (en) Network data processing method and device
CN106658688B (en) System and method for realizing GSM module control in single chip microcomputer
CN108153536B (en) DSP online upgrading method for dynamically adjusting RAM space
CN104866454A (en) Write message prospect processing method and device facing board-level high-speed bus
CN112235206A (en) Annular buffer queue data receiving mechanism based on single chip microcomputer
CN105939293B (en) A kind of SKB recovery method and device
CN107294865B (en) A load balancing method for a software switch and the software switch
CN109933549A (en) An Interrupt Controller for RISC-V Processors
CN109582379B (en) Programmable logic controller system based on microkernel operating system and control method
CN101604270A (en) ARINC429 communication redundancy method based on vxworks operating system
CN110703897A (en) Control method, device, chip and equipment
EP2592792A1 (en) Instruction processing method of network processor and network processor
CN117544504A (en) Data processing unit thermal updating method, device, communication equipment and storage medium
CN114116583B (en) Serial communication method of double chips and system with double chips
CN110618962A (en) Multi-core network concurrent access method, system and medium of FT-M6678 chip
CN116244254A (en) RSMC chip, chip channel self-adaptive loading method and Beidou communication navigation device
CN114268670A (en) Ethernet asynchronous message processing system and method based on time trigger

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address

Address after: 215347 no.707, complex building, Kunshan Industrial Technology Research Institute, no.1699, Zuchongzhi South Road, Kunshan, Suzhou, Jiangsu Province

Patentee after: Kunshan Microelectronics Technology Research Institute

Address before: 215347 7th floor, IIR complex, 1699 Weicheng South Road, Kunshan City, Suzhou City, Jiangsu Province

Patentee before: KUNSHAN BRANCH, INSTITUTE OF MICROELECTRONICS OF CHINESE ACADEMY OF SCIENCES

CP03 Change of name, title or address