/*
 * at_command.h
 *
 *  Created on: 2019Äê1ÔÂ6ÈÕ
 *      Author: JinXi
 */

#ifndef AT_COMMAND_H_
#define AT_COMMAND_H_

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include "myType.h"

#define CMD_BUFFER_SIZE 	256

typedef const char* ptr_const;
typedef char* ptr;
//static ptr parseUartData( ptr src, ptr e );
struct uartCmdProcess_t{
	bool	continual;
	const ptr_const		cmdString;
	void 	(*processer)( ptr s, char len );
	};

typedef struct uartCmdProcess_t uartCmdProcess;


extern void at_command_buf_clean(void);
extern SHORT at_command_process(CHAR* strBuf, USHORT len);
extern bool Uart_frame_over(UCHAR*buf, USHORT len);


typedef struct
{
	/* acc data:x,y,z */
	SHORT Acc_x;
	SHORT Acc_y;
	SHORT Acc_z;
	/* gro data:x,y,z */
	SHORT Gro_x;
	SHORT Gro_y;
	SHORT Gro_z;
	/* mag data:x,y,z */
	SHORT Mag_x;
	SHORT Mag_y;
	SHORT Mag_z;
}Ciss_data_motion_struct;

typedef struct
{
	/* temprature data *10 */
	SHORT temp;
	/* humid data */
	USHORT humid;
	/* pressure data *100 */
	UINT pressure;
	/* noise data */
	SHORT noise;
	/* light data */
	UINT light;
	USHORT reserve;
}Ciss_data_evr_struct;

typedef struct
{
	/* mac address of ciss*/
	UCHAR dev_sn[20];
	/* mode, 1:sensor&evirment, 2:sensor, 3:evirment */
	USHORT	dev_mod;
	/* reserve for ble state */
	USHORT dev_state;
	/* send time stamp */
	LLONG  send_tim;
	/* motison data struct */
	Ciss_data_motion_struct motion_data;
	/* evirment data struct */
	Ciss_data_evr_struct evr_data;
}Ciss_data_struct;

typedef enum
{
	/* without connection */
	STATE_IDLE = 0,
	/* ciss connected */
	STATE_CONNECTED,
	/* data chanel on motion data */
	STATE_CH_IT_OPEN,
	/* data chanel on evirment data */
	STATE_CH_ET_OPEN,
	/* sample working */
	STATE_SAMPLE,
	/* ciss disconnected */
	STATE_DISCONNECT
};

typedef enum
{
	/* event ciss connect success */
	EVT_CONNECT_SUCCESS = 0,
	/* event ciss connect fail */
	EVT_CONNECT_FAIL,
	/* event open ciss's motion data chanel success */
	EVT_OPEN_IT_CH,
	/* event open ciss's evirment data chanel success */
	EVT_OPEN_ET_CH,
	/* event start sample success */
	EVT_START_SAMPLE,
	/* event close sample success */
	EVT_STOP_SAMPLE,
	/* event disconnect */
	EVT_DISCONNECT,
	/* event reset ble module */
	EVT_RESET,
	/* event command error */
	EVT_CMD_ERROR,
}AT_CMD_EVT_ENUM;

typedef enum
{
	/* MSG type is motion data */
	POST_DATA_MOTION = 0,
	/* MSG type is enviroment data */
	POST_DATA_EVIRMENT,
}POST_DATA_TYPE_ENUM;

extern void ciss_connect_dev(UCHAR* mac);
extern void ciss_disconnect_dev(UCHAR* mac);
extern void ciss_enable_IT_dev(UCHAR* mac, bool on);
extern void ciss_enable_ET_dev(UCHAR* mac, bool on);
extern void ciss_enable_sample_dev(UCHAR* mac, USHORT frq, UCHAR mod);
extern void ciss_enable_RESET_Module(void);

#endif /* AT_COMMAND_H_ */
