210 lines
5.6 KiB
C
210 lines
5.6 KiB
C
|
|
#ifndef SIMPLEBLE_H
|
|||
|
|
#define SIMPLEBLE_H
|
|||
|
|
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
extern "C"
|
|||
|
|
{
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------------
|
|||
|
|
//--------------------------------------------------------------------------------
|
|||
|
|
|
|||
|
|
//#define RELEASE_VER //<2F><><EFBFBD><EFBFBD><EFBFBD>汾<EFBFBD><E6B1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
//------------------------------------------------------------------------------
|
|||
|
|
//--------------------------------------------------------------------------------
|
|||
|
|
#define NPI_TIMEOUT_EVT 0x0008
|
|||
|
|
|
|||
|
|
|
|||
|
|
#define VERSION "v1.3"
|
|||
|
|
|
|||
|
|
|
|||
|
|
// How often to perform periodic event
|
|||
|
|
#define SBP_PERIODIC_EVT_PERIOD 100//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>100ms
|
|||
|
|
|
|||
|
|
#define MAX_PERIPHERAL_MAC_ADDR 5//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>Ĵӻ<C4B4><D3BB><EFBFBD>ַ
|
|||
|
|
|
|||
|
|
#define MAC_ADDR_CHAR_LEN 12//mac<61><63>ַ<EFBFBD><D6B7><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD> (һ<><D2BB><EFBFBD>ֽڵ<D6BD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>)
|
|||
|
|
|
|||
|
|
|
|||
|
|
typedef enum
|
|||
|
|
{
|
|||
|
|
PARA_ALL_FACTORY = 0, //ȫ<><C8AB><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
PARA_PARI_FACTORY = 1, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D>൱<EFBFBD><E0B5B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
|
}PARA_SET_FACTORY;
|
|||
|
|
|
|||
|
|
typedef enum
|
|||
|
|
{
|
|||
|
|
BLE_ROLE_PERIPHERAL = 0, //<2F>ӻ<EFBFBD><D3BB><EFBFBD>ɫ
|
|||
|
|
BLE_ROLE_CENTRAL = 1, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|||
|
|
}BLE_ROLE;
|
|||
|
|
|
|||
|
|
// Application states
|
|||
|
|
enum
|
|||
|
|
{
|
|||
|
|
BLE_STATE_IDLE, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD>״̬
|
|||
|
|
BLE_STATE_CONNECTING, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...
|
|||
|
|
BLE_STATE_CONNECTED, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
BLE_STATE_DISCONNECTING, //<2F>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
BLE_STATE_ADVERTISING //<2F>ӻ<EFBFBD><D3BB>㲥<EFBFBD><E3B2A5>
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
enum
|
|||
|
|
{
|
|||
|
|
BLE_MODE_SERIAL, // <20><><EFBFBD><EFBFBD><EFBFBD><CDB8>ģʽ <20><>Ĭ<EFBFBD>ϡ<EFBFBD>
|
|||
|
|
BLE_MODE_DRIVER, // ֱ<><D6B1>ģʽ
|
|||
|
|
BLE_MODE_iBeacon, // iBeacon <20>㲥ģʽ
|
|||
|
|
BLE_MODE_MAX,
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
typedef struct
|
|||
|
|
{
|
|||
|
|
/*
|
|||
|
|
0---------9600
|
|||
|
|
1---------19200
|
|||
|
|
2---------38400
|
|||
|
|
3---------57600
|
|||
|
|
4---------115200
|
|||
|
|
*/
|
|||
|
|
uint8 baudrate; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
uint8 parity; //У<><D0A3>λ
|
|||
|
|
uint8 stopbit; //ֹͣλ
|
|||
|
|
uint8 mode; //<2F><><EFBFBD><EFBFBD>ģʽ 0:<><CDB8> <20><> 1: ֱ<><D6B1> , 2: iBeacon
|
|||
|
|
uint8 name[12]; //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
BLE_ROLE role; //<2F><><EFBFBD><EFBFBD>ģʽ 0: <20>ӻ<EFBFBD> 1: <20><><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
uint8 pass[7]; //<2F><><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
Para: 0 ~ 1
|
|||
|
|
0: <EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
1: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
*/
|
|||
|
|
uint8 type; //<2F><>Ȩģʽ
|
|||
|
|
|
|||
|
|
|
|||
|
|
uint8 mac_addr[13]; //<2F><><EFBFBD><EFBFBD>mac<61><63>ַ
|
|||
|
|
|
|||
|
|
uint8 connl_status; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>ε<EFBFBD>״̬
|
|||
|
|
uint8 connect_mac_status; //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>״̬
|
|||
|
|
uint8 connect_mac_addr[13]; //ָ<><D6B8>ȥ<EFBFBD><C8A5><EFBFBD>ӵ<EFBFBD>mac<61><63>ַ
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9>Ĵӻ<C4B4><D3BB><EFBFBD>ַ
|
|||
|
|
uint8 ever_connect_mac_status[MAX_PERIPHERAL_MAC_ADDR][13];
|
|||
|
|
|
|||
|
|
uint8 verion[5]; //<2F>汾<EFBFBD><E6B1BE>Ϣ v1.0 ~ v9.9
|
|||
|
|
|
|||
|
|
/*
|
|||
|
|
Para: 000000<EFBFBD><EFBFBD>009999
|
|||
|
|
000000 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Եĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
Default:001000
|
|||
|
|
*/
|
|||
|
|
uint16 try_connect_time_ms; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
int8 rssi; // RSSI <20>ź<EFBFBD>ֵ
|
|||
|
|
uint8 rxGain; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF>
|
|||
|
|
uint8 txPower; // <20><><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>ǿ<EFBFBD><C7BF>
|
|||
|
|
uint16 ibeacon_adver_time_ms; // <20>㲥<EFBFBD><E3B2A5><EFBFBD><EFBFBD>
|
|||
|
|
uint8 workMode; // ģ<>鹤<EFBFBD><E9B9A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1: <20>ȴ<EFBFBD>AT+CON <20><> AT+CONNL <20><><EFBFBD><EFBFBD>
|
|||
|
|
}SYS_CONFIG;
|
|||
|
|
extern SYS_CONFIG sys_config;
|
|||
|
|
|
|||
|
|
|
|||
|
|
extern void Serial_Delay(int times);
|
|||
|
|
|
|||
|
|
//flag: PARA_ALL_FACTORY: ȫ<><C8AB><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
//flag: PARA_PARI_FACTORY: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
|
extern void simpleBLE_SetAllParaDefault(PARA_SET_FACTORY flag);
|
|||
|
|
extern void simpleBLE_SaveAllDataToFlash();
|
|||
|
|
|
|||
|
|
extern void PrintAllPara(void);
|
|||
|
|
extern bool simpleBLE_AT_CMD_Handle(uint8 *pBuffer, uint16 length);
|
|||
|
|
|
|||
|
|
extern void simpleBLE_NPI_init(void);
|
|||
|
|
|
|||
|
|
extern void UpdateRxGain(void);
|
|||
|
|
extern void UpdateTxPower(void);
|
|||
|
|
|
|||
|
|
extern void LedSetState(uint8 onoff);
|
|||
|
|
extern void simpleBle_SetRssi(int8 rssi);
|
|||
|
|
|
|||
|
|
|
|||
|
|
extern BLE_ROLE GetBleRole();
|
|||
|
|
|
|||
|
|
extern uint32 str2Num(uint8* numStr, uint8 iLength);
|
|||
|
|
|
|||
|
|
extern void simpleBle_PrintPassword();
|
|||
|
|
|
|||
|
|
extern uint8* GetAttDeviceName();
|
|||
|
|
extern void performPeriodicTask( void );
|
|||
|
|
|
|||
|
|
extern char *bdAddr2Str ( uint8 *pAddr );
|
|||
|
|
extern void CheckKeyForSetAllParaDefault(void);
|
|||
|
|
|
|||
|
|
extern bool CheckIfUse_iBeacon();
|
|||
|
|
extern bool simpleBle_GetIfNeedPassword();
|
|||
|
|
|
|||
|
|
extern void simpleBLE_SetToConnectFlag(bool bToConnect);
|
|||
|
|
extern bool simpleBLE_GetToConnectFlag(uint8 *Addr);
|
|||
|
|
|
|||
|
|
|
|||
|
|
extern uint32 Get_iBeaconAdvertisingInterral();
|
|||
|
|
extern void simpleBLE_SetPeripheralMacAddr(uint8 *pAddr);
|
|||
|
|
extern bool simpleBLE_GetPeripheralMacAddr(uint8 *pAddr);
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
extern uint8 simpleBLEState;
|
|||
|
|
extern uint16 simpleBLECharHdl;
|
|||
|
|
extern uint16 simpleBLECharHd6;
|
|||
|
|
extern bool simpleBLEChar6DoWrite;
|
|||
|
|
extern bool simpleBLEChar6DoWrite2;
|
|||
|
|
|
|||
|
|
|
|||
|
|
#if defined (RELEASE_VER)
|
|||
|
|
#define LCD_WRITE_STRING(str, option)
|
|||
|
|
#define LCD_WRITE_SCREEN(line1, line2)
|
|||
|
|
#define LCD_WRITE_STRING_VALUE(title, value, format, line)
|
|||
|
|
|
|||
|
|
#if defined (HAL_LCD)
|
|||
|
|
#undef HAL_LCD
|
|||
|
|
#define HAL_LCD FALSE
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
#else
|
|||
|
|
// LCD macros
|
|||
|
|
#if HAL_LCD == TRUE
|
|||
|
|
#define LCD_WRITE_STRING(str, option) HalLcdWriteString( (str), (option))
|
|||
|
|
#define LCD_WRITE_SCREEN(line1, line2) HalLcdWriteScreen( (line1), (line2) )
|
|||
|
|
#define LCD_WRITE_STRING_VALUE(title, value, format, line) HalLcdWriteStringValue( (title), (value), (format), (line) )
|
|||
|
|
#else
|
|||
|
|
#define LCD_WRITE_STRING(str, option)
|
|||
|
|
#define LCD_WRITE_SCREEN(line1, line2)
|
|||
|
|
#define LCD_WRITE_STRING_VALUE(title, value, format, line)
|
|||
|
|
#endif
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
extern uint8 simpleBLETaskId; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
extern uint8 simpleBLEState;
|
|||
|
|
extern uint16 simpleBLECharHdl;
|
|||
|
|
extern uint16 simpleBLECharHd6;
|
|||
|
|
extern bool simpleBLECentralCanSend;
|
|||
|
|
extern bool simpleBLEChar6DoWrite;
|
|||
|
|
extern uint8 simpleBLEPeripheral_TaskID; // <20>ӻ<EFBFBD><D3BB><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
#ifdef __cplusplus
|
|||
|
|
}
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
#endif /* SIMPLEBLE_H */
|