核心应用app组成:
App kill 远程屏蔽
App Long work 单独工作模式
App menu 界面菜单
App Power 电源管理
App moni 监听
App Battery 电源管理
App Scan 扫描信道
App Vox Sql 信号相关
架构职责链:
传递单位 包
typedef struct
{
messageOrigin_t source;
appId_t targetAppId;
appId_t senderAppId;
INT32U op_code; /* 操作码 */
INT32U button_code; /* 按键 物理值 */
INT32U state; /*状态码 */
void * msg_ptr; /* 消息内容指针 */
BOOL inputConsumed; /* the status of the input message */
} applicationInputData_t;
接口
void RAM_SendMsgToApp (appId_t targetAppId, //目的APP
appId_t senderAppId,
BOOL activateTarget,//是否激活目的APP
appOpcode_t msgOpcode,//消息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_POWERUP 0x01 *************/
/* Application */ App_PowerUp,
/* Priority */ APP_PRIORITY_NORMOL,
},
{ /*********** APP_POWERDOWN 0x02 *************/
/* Application */ App_PowerDown,
/* Priority */ APP_PRIORITY_NORMOL,
},
{ /*********** APP_ANALOGVOICE 0x03 *************/
/* Application */ App_AnalogVoice,
/* Priority */ APP_PRIORITY_ANALOGVOICE,
},
{ /*********** APP_DIGITALVOICE 0x04 *************/
/* Application */ App_DigitalVoice,
/* Priority */ APP_PRIORITY_NORMOL,
},
{ /*********** APP_CHANNELCHANGE 0x05 *************/
/* Application */ App_ChannelChange,
/* Priority */ APP_PRIORITY_NORMOL,
},
{ /*********** APP_RXINDICATOR 0x06 *************/
/* Application */ App_RxIndicator,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_READWRITEPRG 0x07 *************/
/* Application */ App_ReadWritePrg,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_AUDIOADJUST 0x08 *************/
/* Application */App_AudioAdjust,
/* Priority */ APP_PRIORITY_NORMOL
},
{/*********** APP_KEYLOCK 0x09 *************/
/* Application */App_KeyLock,
/* Priority */ APP_PRIORITY_KEYLOCK,
},
{/*********** APP_BATTERY 0x0A *************/
/* Application */App_Battery,
/* Priority */ APP_PRIORITY_NORMOL,
},
{ /*********** APP_KEYSQL 0x0B *************/
/* Application */ App_KeySql,
/* Priority */ APP_PRIORITY_KEYSQL,
},
{/*********** APP_SQLEVEL 0x0C *************/
/* Application */App_SqLevel,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_POWERLEVEL 0x0D *************/
/* Application */App_PowerLevel,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_TALKAROUND 0x0E *************/
/* Application */App_TalkAround,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_SCAN 0x0F *************/
/* Application */App_Scan,
/* Priority */ APP_PRIORITY_SCAN,
},
{/*********** APP_EMERGENCY 0x10 *************/
/* Application */App_Emergency,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_KILL 0x11 *************/
/* Application */App_Kill,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_DATATX 0x12 *************/
/* Application */App_DataTx,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_SMARTCALL 0x13 *************/
/* Application */App_SmartCall,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_REMOTOMONI 0x14 *************/
/* Application */App_RemotoMoniVoice,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_LONEWORKER 0x15 *************/
/* Application */App_LoneWorker,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_SAVEBATTERY 0x16 *************/
/* Application */App_SaveBattery,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_VOX 0x17 *************/
/* Application */App_Vox,
/* Priority */ APP_PRIORITY_VOX,
},
{/*********** APP_ALARM 0x18 *************/
/* Application */App_Alarm,
/* Priority */ APP_PRIORITY_ALARM,
},
{/*********** APP_REMINDER 0x19 *************/
/* Application */App_Reminder,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** APP_MENU 0x1A *************/
/* Application */App_Menu,
/* Priority */ APP_PRIORITY_MENU,
},
{/*********** APP_DATARX 0x1B *************/
/* Application */App_DataRx,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** reserved 0x1C *************/
/* Application */NULL,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** reserved 0x1D *************/
/* Application */NULL,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** reserved 0x1E *************/
/* Application */NULL,
/* Priority */ APP_PRIORITY_NORMOL,
},
{/*********** reserved 0x1F *************/
/* 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;
/*------------------------------- GLOBAL DATA -------------------------------*/
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;i
pAppManager = GetAppManagerInstance(); //指向一个全局变量。
AppManagerInit(source); //source的两个方法和一个释放内存的操作。
pAppQueue = GetActAppQueueInstance(); //初始化活动链表。每个app的状态都为ACT_DONE。
InputData = 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 = (stMSG*)pMsg;
if(pData->PtrMsgSt != NULL)
ROS_FreeMem(pData->PtrMsgSt);
}
break;
case KEY_INPUT:
{
Keymsg_t* pKeyData = (Keymsg_t*)pMsg;
if(pKeyData->pPayload != NULL)
ROS_FreeMem(pKeyData->pPayload);
}
break;
case APP_INPUT:
{
AppToAppData_t* pAppData = (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 = (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 = (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 = (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 = (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 = (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 = (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 = (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;
}