ATSystem.h 2.77 KB
/*
 * 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_ */