From c13c9806f957ebc675462737f4b328d3ab89e028 Mon Sep 17 00:00:00 2001 From: guowenxue <guowenxue@gmail.com> Date: Mon, 10 Jul 2023 17:29:22 +0800 Subject: [PATCH] update gpsd.c --- gpsd/booster/atcmd.h | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 87 insertions(+), 0 deletions(-) diff --git a/gpsd/booster/atcmd.h b/gpsd/booster/atcmd.h new file mode 100644 index 0000000..a84d564 --- /dev/null +++ b/gpsd/booster/atcmd.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2022 Guo Wenxue + * Author: Guo Wenxue <guowenxue@gmail.com> + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GPL license. + */ + +#ifndef _ATCMD_H_ +#define _ATCMD_H_ + +#include "comport.h" + +/* AT command common reply message max length */ +#define ATCMD_REPLY_LEN 1024 /* Max AT command reply message length */ +#define ATCMD_LEN 256 /* Max AT command length */ + +/* AT command reply message got expect or error string */ +#define AT_OKSTR "\r\nOK\r\n" /* expect string always be OK */ +#define AT_ERRSTR "\r\nERROR\r\n" /* error string always be ERROR */ + +/* AT command should be end by $AT_SUFFIX */ +#define AT_SUFFIX "\r\n" + +/* send_atcmd)( return value status */ +enum +{ + ATRES_ERROR, /* AT command reply got error string, such as "ERROR\r\n" */ + ATRES_EXPECT, /* AT command reply got expect string, such as "OK\r\n" */ + ATRES_TIMEOUT, /* AT command not get error/expect string, receive util timeout */ +}; + +/* Description: this function used to send an AT command from serial port and wait for reply message from + * the communication module, and it will return once get expet/error string or timeout. + * + * Arugments: + * $comport: the serial port which connected to GPRS/3G/4G/NB-IoT/WiFi/BLE/Zigbee/LoRa... + * $at: the AT command need to be sent, without "\r\n" + * $timeout: wait for module reply for AT command timeout value, unit micro seconds(ms) + * $exepct: the expect string reply from communication module + * $error: the error string reply from communication module + * $reply: the module reply message output buffer + * $size: the output buffer ($reply) size + * + * Return value: <0: Function error 0: Got error string 1: Got expect string 2: Receive util timeout + * + */ +int send_atcmd(comport_t *comport, char *at, unsigned long timeout, char *expect, char *error, char *reply, int size); + + +/* + * Description: Send AT command which will only reply by "OK" or "ERROR", such as AT: + * Reply: \r\nOK\r\n + * + * Return Value: 0: OK -X: ERROR + */ +int send_atcmd_check_ok(comport_t *comport, char *at, unsigned long timeout); + + +/* + * Description: Send AT command which will reply by a value directly in a single line, such as AT+CGMM: + * Reply: \r\nEC20F\r\nOK\r\n + * + * Return Value: 0: OK -X: ERROR + */ +int send_atcmd_check_value(comport_t *comport, char *at, unsigned long timeout, char *reply, int size); + +/* + * Description: Parser the $value from $key like "xxx: " line, such as AT+CSQ: + * Reply: \r\n+CSQ: 26,99\r\nOK\r\n + * + * Return Value: 0: OK -X: Failure + */ +int parser_request_value(char *buf, char *key, char *value, int size); + + +/* + * Description: Send AT command which will reply by the value with a prefix "+CMD: " line, such as AT+CSQ: + * Reply: \r\n+CSQ: 26,99\r\nOK\r\n + * + * Return Value: 0: OK -X: ERROR + */ +int send_atcmd_check_request(comport_t *comport, char *at, unsigned long timeout, char *repy, int size); + + +#endif /* ----- #ifndef _ATCMD_H_ ----- */ + -- Gitblit v1.9.1