一般常用于状态交互
/* file name : status_machine.c
author : zhongjun
description : status_machine demo
data : 20150630
time : AM 10:06
key(study) : 预处理器 & enum & typedef & struct & malloc & memset
*/
#include <stdio.h>
#define DEBUG_STATUS
#ifdef DEBUG_STATUS
#define DEBUG(x) {printf x;}
#define STATUS_DEBUG(x) DEBUG(x)
#else
#define STATUS_DEBUG(x)
#endif
typedef enum {
HF_INITIALISING,
HF_READY,
HF_DISCONNECTING,
HF_CONNECTING,
HF_CONNECTED,
HF_INCOMING_CALL_ESTABLISH,
HF_OUTGOING_CALL_ESTABLISH,
HF_ACTIVE_CALL,
HF_3WAY_CALL_WAITING,
HF_3WAY_MULTICALL,
HF_3WAY_CALL_ON_HOLD,
HF_INCOMING_CALL_ON_HOLD
} AnwHfStateType;
typedef struct
{
AnwHfStateType hfpstate ;
unsigned char SCO_Link_connect :8;
unsigned char answerButton_ChangeTo_Transfer :8;
}AnwDeviceManager;
AnwDeviceManager *devicemanager ;
void SetHfpState ( AnwHfStateType state );
AnwDeviceManager* GetDeviceManager(void);
int main()
{
devicemanager = (AnwDeviceManager*)malloc(sizeof(AnwDeviceManager));
memset(devicemanager, 0, sizeof(AnwDeviceManager));
devicemanager->hfpstate = HF_READY;
SetHfpState(HF_CONNECTED);
return 0;
}
void SetHfpState (AnwHfStateType state)
{
devicemanager->hfpstate = state;
STATUS_DEBUG(("Set HfpState (%d)\n", state));
}
AnwDeviceManager* GetDeviceManager(void)
{
return devicemanager;
}