智能对讲

核心应用app组成:
App kill 远程屏蔽
App Long work单独工作模式
App menu 界面菜单
App Power 电源管理
App moni 监听
App Battery 电源管理
App Scan 扫描信道
App Vox Sql 信号相关
架构职责链:
传递单位 包
typedef struct
{
messageOrigin_tsource;
appId_ttargetAppId;
appId_tsenderAppId;
INT32U op_code; /* 操作码 */
INT32Ubutton_code; /* 按键 物理值 */
INT32Ustate; /*状态码 */
void * msg_ptr; /* 消息内容指针 */
BOOLinputConsumed; /* the status of the input message */
} applicationInputData_t;
接口
void RAM_SendMsgToApp (appId_ttargetAppId,//目的APP
appId_tsenderAppId,
BOOLactivateTarget,//是否激活目的APP
appOpcode_tmsgOpcode,//消息ID
INT8U*msgDataPtr); //消息参数

/*
**The basic idea is to have one ADT table for each model or product, which
**is indexed by the App ID and contains various information about each
**application.
*/
const adtRow_t AppAdt[] =
{
{/******************** INVALID APP *************************/
/* application */NULL,
/* Priority */APP_PRIORITY_BASE,
},

{ /***********APP_POWERUP0x01*************/
/* Application*/App_PowerUp,
/* Priority */APP_PRIORITY_NORMOL,
},

{ /***********APP_POWERDOWN0x02*************/
/* Application*/App_PowerDown,
/* Priority */APP_PRIORITY_NORMOL,
},

{ /***********APP_ANALOGVOICE0x03*************/
/* Application*/App_AnalogVoice,
/* Priority */APP_PRIORITY_ANALOGVOICE,
},

{ /***********APP_DIGITALVOICE0x04*************/
/* Application*/App_DigitalVoice,
/* Priority */APP_PRIORITY_NORMOL,
},

{ /***********APP_CHANNELCHANGE0x05*************/
/* Application*/App_ChannelChange,
/* Priority */APP_PRIORITY_NORMOL,
},

{ /***********APP_RXINDICATOR0x06*************/
/* Application*/App_RxIndicator,
/* Priority */APP_PRIORITY_NORMOL,
},


{/***********APP_READWRITEPRG0x07*************/
/* Application*/App_ReadWritePrg,
/* Priority */APP_PRIORITY_NORMOL,
},

{/***********APP_AUDIOADJUST0x08*************/
/* Application*/App_AudioAdjust,
/* Priority */APP_PRIORITY_NORMOL
},

{/***********APP_KEYLOCK0x09*************/
/* Application*/App_KeyLock,
/* Priority */APP_PRIORITY_KEYLOCK,
},

{/***********APP_BATTERY0x0A*************/
/* Application*/App_Battery,
/* Priority */APP_PRIORITY_NORMOL,
},

{ /***********APP_KEYSQL0x0B*************/
/* Application*/App_KeySql,
/* Priority */APP_PRIORITY_KEYSQL,
},

{/***********APP_SQLEVEL0x0C*************/
/* Application*/App_SqLevel,
/* Priority */APP_PRIORITY_NORMOL,
},

{/***********APP_POWERLEVEL0x0D*************/
/* Application*/App_PowerLevel,
/* Priority */APP_PRIORITY_NORMOL,
},


{/***********APP_TALKAROUND0x0E*************/
/* Application*/App_TalkAround,
/* Priority */APP_PRIORITY_NORMOL,
},


{/***********APP_SCAN0x0F*************/
/* Application*/App_Scan,
/* Priority */APP_PRIORITY_SCAN,
},

{/***********APP_EMERGENCY0x10*************/
/* Application*/App_Emergency,
/* Priority */APP_PRIORITY_NORMOL,
},
{/***********APP_KILL0x11*************/
/* Application*/App_Kill,
/* Priority */APP_PRIORITY_NORMOL,
},
{/***********APP_DATATX0x12*************/
/* Application*/App_DataTx,
/* Priority */APP_PRIORITY_NORMOL,
},

{/***********APP_SMARTCALL0x13*************/
/* Application*/App_SmartCall,
/* Priority */APP_PRIORITY_NORMOL,
},

{/***********APP_REMOTOMONI0x14*************/
/* Application*/App_RemotoMoniVoice,
/* Priority */APP_PRIORITY_NORMOL,
},
{/***********APP_LONEWORKER0x15*************/
/* Application*/App_LoneWorker,
/* Priority */APP_PRIORITY_NORMOL,
},
{/***********APP_SAVEBATTERY0x16*************/
/* Application*/App_SaveBattery,
/* Priority */APP_PRIORITY_NORMOL,
},

{/***********APP_VOX0x17*************/
/* Application*/App_Vox,
/* Priority */APP_PRIORITY_VOX,
},

{/***********APP_ALARM0x18*************/
/* Application*/App_Alarm,
/* Priority */APP_PRIORITY_ALARM,
},


{/***********APP_REMINDER0x19*************/
/* Application*/App_Reminder,
/* Priority */APP_PRIORITY_NORMOL,
},

{/***********APP_MENU0x1A*************/
/* Application*/App_Menu,
/* Priority */APP_PRIORITY_MENU,
},

{/***********APP_DATARX0x1B*************/
/* Application*/App_DataRx,
/* Priority */APP_PRIORITY_NORMOL,
},
{/***********reserved0x1C*************/
/* Application*/NULL,
/* Priority */APP_PRIORITY_NORMOL,
},

{/***********reserved0x1D*************/
/* Application*/NULL,
/* Priority */APP_PRIORITY_NORMOL,
},
{/***********reserved0x1E*************/
/* Application*/NULL,
/* Priority */APP_PRIORITY_NORMOL,
},

{/***********reserved0x1F*************/
/* Application*/NULL,
/* Priority */APP_PRIORITY_NORMOL,
},

};
/*-------------------------- HEADER FILE INCLUDES ----------------------------*/
#include "RAM_def.h"
#include "RAM_queue.h"
#include "RAM_AppManager.h"
#include "API_Timer.h"
/*---------------------------- LOCAL CONSTANTS -------------------------------*/
/*--------------------------- LOCAL ENUMERATIONS -----------------------------*/
/*----------------------------- LOCAL DATA TYPES -----------------------------*/
//RAM对象?
typedef struct
{
AppLaunchInfo_t AppInfo[RAM_ADT_SIZE]; // 属性?
BOOL* pMsgConsumedFlag; // 属性?
applicationInputData_t (*InputMessageHandle)(void* pMsg); // 行为1?
AppLaunchInfo_t (*MsgFilter)(void* pMsg); // 行为2?
void (*FreeMsgBuffer)(messageOrigin_t source,void* pMsg); // 行为3?

}AppManager_t;
/*------------------------------- GLOBALDATA -------------------------------*/
AppManager_t AppManagerObj;
/*------------------------ LOCAL FUNCTION PROTOTYPES -------------------------*/
static void RAM_FreeMsgBuffer(messageOrigin_t source,void* pMsgData);
static applicationInputData_t Input_KeyMessageHandle(void* pMsg);
static applicationInputData_t Input_MenuMessageHandle(void* pMsg);
static applicationInputData_t Input_PSMessageHandle(void* pMsg);
static applicationInputData_t Input_LLMessageHandle(void* pMsg);
static applicationInputData_t Input_TimerMessageHandle(void* pMsg);
static applicationInputData_t Input_AppMessageHandle(void* pMsg);
static AppLaunchInfo_t RAM_AppMsgFilter(void* pInputData);
AppLaunchInfo_t RAM_TimerMsgFilter(void* pInputData);
static AppManager_t *GetAppManagerInstance( void );
static void AppManagerInit(messageOrigin_t source);
void RAM_AppManager(messageOrigin_t source,void* pMsgData);
void RAM_SetMsgConsumedFlag(void);
BOOL RAM_IsAppActive(appId_t appId);
/*******************************************************************************/
/*Program*/
/*******************************************************************************/

static AppManager_t *GetAppManagerInstance( void )
{
return &AppManagerObj;
}

static void AppManagerInit(messageOrigin_t source)
{
AppManager_t * pAppManager = GetAppManagerInstance(); //指向全局变量。
pAppManager->FreeMsgBuffer = RAM_FreeMsgBuffer; //此函数用于释放动态分配的内存。
switch(source)
{
case KEY_INPUT:
pAppManager->InputMessageHandle = Input_KeyMessageHandle;
pAppManager->MsgFilter = RAM_KeyMsgFilter;
break;
case MENU_INPUT:
pAppManager->InputMessageHandle = Input_MenuMessageHandle;
pAppManager->MsgFilter = RAM_MenuMsgFilter;
break;
case CCL_INPUT:
pAppManager->InputMessageHandle = Input_PSMessageHandle;
pAppManager->MsgFilter = RAM_PSMsgFilter;
break;
case LL_INPUT:
pAppManager->InputMessageHandle = Input_LLMessageHandle;
pAppManager->MsgFilter = RAM_LLMsgFilter;
break;
case APP_INPUT:
pAppManager->InputMessageHandle = Input_AppMessageHandle;
pAppManager->MsgFilter = RAM_AppMsgFilter;
break;
case TIMER_INPUT:
pAppManager->InputMessageHandle = Input_TimerMessageHandle;
pAppManager->MsgFilter = RAM_TimerMsgFilter;
break;

default:
break;
}
}
void RAM_AppManager(messageOrigin_t source,void* pMsgData)
{
INT8U i;
AppManager_t* pAppManager;
ActAppQueue_t* pAppQueue;
applicationInputData_t InputData;
AppLaunchInfo_t result;
INT8U LengthTemp;
appId_t appId;
ActApp_t ActAppArrayTemp[RAM_ADT_SIZE];

BOOL AppProFlag[RAM_ADT_SIZE];
for(i=0; iAppProFlag[i] = FALSE;

pAppManager = GetAppManagerInstance(); //指向一个全局变量。
AppManagerInit(source); //source的两个方法和一个释放内存的操作。
pAppQueue = GetActAppQueueInstance(); //初始化活动链表。每个app的状态都为ACT_DONE。
InputData = https://www.it610.com/article/pAppManager->InputMessageHandle(pMsgData); //得到数据。
pAppManager->pMsgConsumedFlag = &(InputData.inputConsumed); //pMsgConsumedFlag = False.

/* 分阶段将其投入APP中处理,filter,launch*/

/*filter阶段处理*/
if(source == KEY_INPUT ||source == MENU_INPUT )
{
memcpy(ActAppArrayTemp,pAppQueue->ActAppArray ,RAM_ADT_SIZE*sizeof(ActApp_t));
LengthTemp = pAppQueue->Len; //初始化的时候Len等于0;
for( i=0; i{
appId = ActAppArrayTemp[i].appId;
AppProFlag[appId] = TRUE;
/* 检测APP是否Active */
if(AppAdt[appId].appAddress(AM_APP_INPUTS,&InputData,ActAppArrayTemp[i].pAdb) == APP_DONE)
{
pAppQueue->del(appId);
}
/* 检测消息是否被消费 */
if(*(pAppManager->pMsgConsumedFlag)== TRUE)
{
break;
}
}
}
/*launch阶段处理*/

result= pAppManager->MsgFilter(pMsgData);
if(result.appId != 0 && AppProFlag[result.appId]==FALSE && (*(pAppManager->pMsgConsumedFlag) != TRUE))
{
if(pAppQueue->AppState[result.appId] == APP_DONE && result.appLaunchFlag == TRUE)/* 检测是否需要激活 */
{
/* 检测要激活的APP与已激活的APP的交互状态 */
memcpy(ActAppArrayTemp,pAppQueue->ActAppArray ,RAM_ADT_SIZE*sizeof(ActApp_t));
LengthTemp = pAppQueue->Len;
for( i=0; i{
appId = ActAppArrayTemp[i].appId;
if(Interaction_Table[result.appId-1][appId-1] == n_INTERACTION_BLOCK)
{
pAppManager->FreeMsgBuffer(source,pMsgData);
return;
}
}
/* 检测是否需要ShutDown已激活APP */
for( i=0; i{
appId = ActAppArrayTemp[i].appId;
if(Interaction_Table[result.appId-1][appId-1] == n_INTERACTION_SHUTDOWN)
{
AppAdt[appId].appAddress(AM_SHUTDOWN,NULL,ActAppArrayTemp[i].pAdb);
pAppQueue->del(appId);
}
}

pAppQueue->add(result.appId); //
if(AppAdt[result.appId].appAddress(AM_LAUNCH_REQUEST,&InputData,pAppQueue->ActAppArray[pAppQueue->Len-1].pAdb) == APP_DONE)// app在此被调用滴。
{
pAppQueue->del(result.appId);
}
}
else if(pAppQueue->AppState[result.appId] == APP_ACTIVE)// AppState数组在AppManagerInit中的RAM_KeyMsgFilter类似函数中被调用滴。
{
if(AppAdt[result.appId].appAddress(AM_APP_INPUTS,&InputData,pAppQueue->ActAppArray[pAppQueue->Len-1].pAdb) == APP_DONE)
{
pAppQueue->del(result.appId);
}
}
}
pAppManager->FreeMsgBuffer(source,pMsgData);

}

static void RAM_FreeMsgBuffer(messageOrigin_t source,void* pMsg)
{
switch(source)
{
case LL_INPUT:
case CCL_INPUT:
case MENU_INPUT:
{
stMSG* pData = https://www.it610.com/article/(stMSG*)pMsg;
if(pData->PtrMsgSt != NULL)
ROS_FreeMem(pData->PtrMsgSt);
}
break;

case KEY_INPUT:
{
Keymsg_t* pKeyData = https://www.it610.com/article/(Keymsg_t*)pMsg;
if(pKeyData->pPayload != NULL)
ROS_FreeMem(pKeyData->pPayload);
}
break;
case APP_INPUT:
{
AppToAppData_t* pAppData = https://www.it610.com/article/(AppToAppData_t*)pMsg;
if(pAppData->msgDataPtr != NULL)
ROS_FreeMem(pAppData->msgDataPtr);
}
break;
default:
break;
}
ROS_FreeMem(pMsg);
}
static applicationInputData_t Input_KeyMessageHandle(void* pMsg)
{
applicationInputData_t DataRet;
Keymsg_t* pData = https://www.it610.com/article/(Keymsg_t*)pMsg;
DataRet.source = KEY_INPUT;
DataRet.op_code = pData->op_code;
DataRet.button_code = pData->button_code;
DataRet.msg_ptr = pData->pPayload;
DataRet.inputConsumed = FALSE;
return DataRet;
}

static applicationInputData_t Input_MenuMessageHandle(void* pMsg)
{
applicationInputData_t DataRet;
stMSG* pData = https://www.it610.com/article/(stMSG*)pMsg;
DataRet.source = MENU_INPUT;
DataRet.op_code = pData->MsgID;
DataRet.msg_ptr = pData->PtrMsgSt;
DataRet.inputConsumed = FALSE;
return DataRet;

}

static applicationInputData_t Input_PSMessageHandle(void* pMsg)
{
applicationInputData_t DataRet;
stMSG* pData = https://www.it610.com/article/(stMSG*)pMsg;
DataRet.source = CCL_INPUT;
DataRet.op_code = pData->MsgID;
DataRet.msg_ptr = pData->PtrMsgSt;
DataRet.inputConsumed = FALSE;
return DataRet;


}
static applicationInputData_t Input_LLMessageHandle(void* pMsg)
{
applicationInputData_t DataRet;
stMSG* pData = https://www.it610.com/article/(stMSG*)pMsg;
DataRet.source = LL_INPUT;
DataRet.op_code = pData->MsgID;
DataRet.msg_ptr = pData->PtrMsgSt;
DataRet.inputConsumed = FALSE;
return DataRet;

}
static applicationInputData_t Input_TimerMessageHandle(void* pMsg)
{
applicationInputData_t DataRet;
DataRet.source = TIMER_INPUT;
DataRet.msg_ptr = pMsg;
DataRet.inputConsumed = FALSE;
return DataRet;
}
static applicationInputData_t Input_AppMessageHandle(void* pMsg)
{
applicationInputData_t DataRet;
AppToAppData_t* pData = https://www.it610.com/article/(AppToAppData_t*)pMsg;
DataRet.source = APP_INPUT;
DataRet.targetAppId = pData->targetAppId;
DataRet.senderAppId= pData->senderAppId;
DataRet.op_code= pData->msgOpcode;
DataRet.msg_ptr = pData->msgDataPtr;
DataRet.inputConsumed = FALSE;
return DataRet;
}

static AppLaunchInfo_t RAM_AppMsgFilter(void* pMsg)
{
AppLaunchInfo_t ret;
AppToAppData_t* pData = https://www.it610.com/article/(AppToAppData_t*)pMsg;
ret.appId = pData->targetAppId;
ret.appLaunchFlag = pData->activateTarget;
return ret;

}
AppLaunchInfo_t RAM_TimerMsgFilter(void* pMsg)
{
AppLaunchInfo_t ret;
API_timer_t* pData = https://www.it610.com/article/(API_timer_t*)pMsg;
ret.appId = pData->user_id;
ret.appLaunchFlag = FALSE;
return ret;
}
void RAM_SetMsgConsumedFlag(void)
{
AppManager_t*pMgr = GetAppManagerInstance();
*(pMgr->pMsgConsumedFlag) = TRUE;
}
BOOL RAM_IsAppActive(appId_t appId)
{
ActAppQueue_t* pAppQueue = GetActAppQueueInstance();
if(pAppQueue->AppState[appId] == APP_ACTIVE)
return TRUE;
else
return FALSE;
}
【智能对讲】

    推荐阅读