ATSystem.h
2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* ATSystem.h
*
* Created on: Nov 1, 2019
* Author: Hope
*/
#ifndef INC_ATSYSTEM_H_
#define INC_ATSYSTEM_H_
/* Includes ------------------------------------------------------------------*/
#include "usart.h"
/*****************************
* Private Define
*/
#define TRUE 1
#define FALSE 0
/*****************************************
config
****************************************/
/*********************
* compile options
*/
#define AT_FCS_VERIFY FALSE
#define AT_DEBUG_INF_SHOW TRUE
#define AT_CMD_PATTERN_CHECK TRUE
#define AT_UART_BACKSPACE FALSE
#define AT_SHOW_STATE_CHANGE FALSE
/********************************************************
* define UART message sent
*******************************************************/
#define AT_RESP(str, len) HAL_UART_Transmit(&huart2, (uint8_t*)str, len, 1000)
#define AT_OK() AT_RESP("\r\nOK\r\n", sizeof("\r\nOK\r\n")-1)
#define AT_NEXT_LINE() AT_RESP("\r\n", 2)
#define AT_NEW_LINE() AT_RESP("\r\n", 2)
#define AT_ERROR(x) AT_UARTWriteErrMsg(x)
#if AT_DEBUG_INF_SHOW
#define AT_DEBUG(str, len) AT_RESP(str, len)
#else
#define AT_DEBUG(str, len)
#endif
#if AT_CMD_PATTERN_CHECK
#define AT_PARSE_CMD_PATTERN_ERROR(x,y) \
{uint8_t err; \
err = AT_Pattern_Check(x,y); \
if (err != 0) { AT_ERROR(err); return;} }
#else
#define AT_PARSE_CMD_PATTERN_ERROR(x,y)
#endif
#if AT_CMD_PATTERN_CHECK
#define AT_PARSE_SINGLE_CMD_PATTERN_ERROR(x,y) \
{ if (x[0] != y->symbol) {AT_ERROR(AT_INVALID_PARA); return;}}
#else
#define AT_PARSE_CMD_PATTERN_ERROR(x,y)
#endif
/*********************************************************************
* DATA STRUCTURE
*/
typedef struct {
uint8_t symbol;
uint8_t unitLen;
uint8_t* unit;
} AT_CmdUnit;
typedef void (*AT_CmdFn_t)(uint8_t cmd_ptr, uint8_t* msg_ptr);
typedef struct {
char* AT_Cmd_str;
AT_CmdFn_t AT_CmdFn;
char* ATCmdDescription;
} AT_Cmd_t;
/*********************
* error message
*/
#define AT_NO_ERROR 0x00 // Everything OK - Success
#define AT_FATAL_ERROR 0x01 // Fatal Error
#define AT_UNKNOWN_CMD 0x02 // Unknown command
#define AT_LACK_CMD 0x03 // lack command
#define AT_INVALID_PARA 0x04 // Invalid parameter
#define AT_LACK_OPERATOR 0x05
#define AT_LACK_PARA 0x06
/*********************
* command constants
*/
#define AT_CMD_HELP_DESC_OFFSET 17
/*********************************************************************
* GLOBAL VARIABLES
*/
extern void AT_Process(uint8_t ch);
extern void AT_UARTWriteErrMsg(uint8_t errCode);
#endif /* INC_ATSYSTEM_H_ */