commit | author | age
|
d6b4a7
|
1 |
/********************************************************************************* |
G |
2 |
* Copyright: (C) 2023 LingYun IoT System Studio. |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* Filename: atcmd.h |
|
6 |
* Description: This file is lowlevel AT command send and parser API functions |
|
7 |
* |
|
8 |
* Version: 1.0.0(11/08/23) |
|
9 |
* Author: Guo Wenxue <guowenxue@gmail.com> |
|
10 |
* ChangeLog: 1, Release initial version on "11/08/23 16:18:43" |
|
11 |
* |
|
12 |
********************************************************************************/ |
|
13 |
|
|
14 |
|
|
15 |
#ifndef _ATCMD_H_ |
|
16 |
#define _ATCMD_H_ |
|
17 |
|
|
18 |
#include "comport.h" |
|
19 |
|
|
20 |
/* AT command common reply message max length */ |
|
21 |
#define ATCMD_REPLY_LEN 1024 /* Max AT command reply message length */ |
|
22 |
#define ATCMD_LEN 256 /* Max AT command length */ |
|
23 |
|
|
24 |
/* AT command reply message got expect or error string */ |
|
25 |
#define AT_OKSTR "\r\nOK\r\n" /* expect string always be OK */ |
|
26 |
#define AT_ERRSTR "\r\nERROR\r\n" /* error string always be ERROR */ |
|
27 |
|
|
28 |
/* AT command should be end by $AT_SUFFIX */ |
|
29 |
#define AT_SUFFIX "\r\n" |
|
30 |
|
|
31 |
/* send_atcmd)( return value status */ |
|
32 |
enum |
|
33 |
{ |
|
34 |
ATRES_ERROR, /* AT command reply got error string, such as "ERROR\r\n" */ |
|
35 |
ATRES_EXPECT, /* AT command reply got expect string, such as "OK\r\n" */ |
|
36 |
ATRES_TIMEOUT, /* AT command not get error/expect string, receive util timeout */ |
|
37 |
}; |
|
38 |
|
|
39 |
/* Description: this function used to send an AT command from serial port and wait for reply message from |
|
40 |
* the communication module, and it will return once get expet/error string or timeout. |
|
41 |
* |
|
42 |
* Arugments: |
|
43 |
* $comport: the serial port which connected to GPRS/3G/4G/NB-IoT/WiFi/BLE/Zigbee/LoRa... |
|
44 |
* $at: the AT command need to be sent, without "\r\n" |
|
45 |
* $timeout: wait for module reply for AT command timeout value, unit micro seconds(ms) |
|
46 |
* $exepct: the expect string reply from communication module |
|
47 |
* $error: the error string reply from communication module |
|
48 |
* $reply: the module reply message output buffer |
|
49 |
* $size: the output buffer ($reply) size |
|
50 |
* |
|
51 |
* Return value: <0: Function error 0: Got error string 1: Got expect string 2: Receive util timeout |
|
52 |
* |
|
53 |
*/ |
|
54 |
int send_atcmd(comport_t *comport, char *at, unsigned long timeout, char *expect, char *error, char *reply, int size); |
|
55 |
|
|
56 |
|
|
57 |
/* |
|
58 |
* Description: Send AT command which will only reply by "OK" or "ERROR", such as AT: |
|
59 |
* Reply: \r\nOK\r\n |
|
60 |
* |
|
61 |
* Return Value: 0: OK -X: ERROR |
|
62 |
*/ |
|
63 |
int send_atcmd_check_ok(comport_t *comport, char *at, unsigned long timeout); |
|
64 |
|
|
65 |
|
|
66 |
/* |
|
67 |
* Description: Send AT command which will reply by a value directly in a single line, such as AT+CGMM: |
|
68 |
* Reply: \r\nEC20F\r\nOK\r\n |
|
69 |
* |
|
70 |
* Return Value: 0: OK -X: ERROR |
|
71 |
*/ |
|
72 |
int send_atcmd_check_value(comport_t *comport, char *at, unsigned long timeout, char *reply, int size); |
|
73 |
|
|
74 |
/* |
|
75 |
* Description: Parser the $value from $key like "xxx: " line, such as AT+CSQ: |
|
76 |
* Reply: \r\n+CSQ: 26,99\r\nOK\r\n |
|
77 |
* |
|
78 |
* Return Value: 0: OK -X: Failure |
|
79 |
*/ |
|
80 |
int parser_request_value(char *buf, char *key, char *value, int size); |
|
81 |
|
|
82 |
|
|
83 |
/* |
|
84 |
* Description: Send AT command which will reply by the value with a prefix "+CMD: " line, such as AT+CSQ: |
|
85 |
* Reply: \r\n+CSQ: 26,99\r\nOK\r\n |
|
86 |
* |
|
87 |
* Return Value: 0: OK -X: ERROR |
|
88 |
*/ |
|
89 |
int send_atcmd_check_request(comport_t *comport, char *at, unsigned long timeout, char *repy, int size); |
|
90 |
|
|
91 |
|
|
92 |
#endif /* ----- #ifndef _ATCMD_H_ ----- */ |
|
93 |
|