Open Trion opened 3 months ago
Test Code
/*
HANDLE mainTaskHandle = NULL; HANDLE otherTaskHandle = NULL; uint16_t chargerState ; uint16_t chargeLevel ; uint16_t batteryState ; uint16_t batteryVoltage;
void LoopTask(VOID pData)
{
uint64_t count = 0;
while(1)
{
++count;
if(count == 3000)
{
count = 0;
Trace(1,"Test Test");
OS_Sleep(1000);
Trace(1,"Test Test2");
}
}
}
void EventDispatch(API_Event_t pEvent)
{
switch(pEvent->id)
{
case API_EVENT_ID_POWER_ON:
break;
case API_EVENT_ID_NO_SIMCARD:
break;
case API_EVENT_ID_NETWORK_REGISTERED_HOME:
case API_EVENT_ID_NETWORK_REGISTERED_ROAMING:
break;
case API_EVENT_ID_POWER_INFO:
chargerState = (pEvent->param1 >> 16) & 0xFFFF;
chargeLevel = pEvent->param1 & 0xFFFF;
batteryState = (pEvent->param2 >> 16) & 0xFFFF;
batteryVoltage = pEvent->param2 & 0xFFFF;
Trace(1,"Charger State: %d",chargerState);
Trace(1,"Charger Level: %d",chargeLevel);
Trace(1,"battery State: %d",batteryState);
Trace(1,"battery Voltage: %d",batteryVoltage);
switch(chargerState){
case PM_CHARGER_STATE_DISCONNECTED:
Trace(1,"Charger is disconnected");
break;
case PM_CHARGER_STATE_CONNECTED:
Trace(1,"Charger is connected");
break;
case PM_CHARGER_STATE_CHRGING:
Trace(1,"Charging is progress");
break;
case PM_CHARGER_STATE_FINISHED:
Trace(1,"Battery is fully charged");
break;
}
default:
break;
}
}
void AppMainTask(VOID pData)
{
API_Event_t event=NULL;
otherTaskHandle = OS_CreateTask(LoopTask ,
NULL, NULL, AppMain_TASK_STACK_SIZE, AppMain_TASK_PRIORITY, 0, 0, "ohter Task");
while(1)
{
if(OS_WaitEvent(mainTaskHandle, &event, OS_TIME_OUT_WAIT_FOREVER))
{
EventDispatch(event);
OS_Free(event->pParam1);
OS_Free(event->pParam2);
OS_Free(event);
}
}
}
void app_Main(void)
{
mainTaskHandle = OS_CreateTask(AppMainTask ,
NULL, NULL, AppMain_TASK_STACK_SIZE, AppMain_TASK_PRIORITY, 0, 0, "init Task");
OS_SetUserMainHandle(&mainTaskHandle);
}
SDK Version : Latest File location : api_event.h & api_inc_pm.h
typedef enum{ PM_CHARGER_STATE_DISCONNECTED = 0, PM_CHARGER_STATE_CONNECTED = 1, PM_CHARGER_STATE_CHRGING = 2, PM_CHARGER_STATE_FINISHED = 3, PM_CHARGER_STATE_ERROR_TEMPERATURE = 4, PM_CHARGER_STATE_ERROR_VOLTAGE = 5, PM_CHARGER_STATE_ERROR_UNKNOWN = 9, PM_CHARGER_STATE_MAX }PM_Charger_State_t;
api_event.h API_EVENT_ID_POWER_INFO (PM_Charger_State_t<<16|charge_level(%)) , param2: (PM_Battery_State_t<<16|battery_voltage(mV)) (log output result in traccer:
Battery_AsyncEventProcess nBatteryChargeState = 3,nBatteryChargeLevel = 98,nBatteryState = 0,nBatteryVoltage = 4187 )
To handle API_EVENT_ID_POWER_INFO and extract the charger state in the GPRS C SDK, you need to interpret the parameters param1 and param2 correctly. These parameters are bit-packed to provide multiple pieces of information. Here’s how you can extract the charger state from param1.
Breakdown of Parameters
PM_Charger_State_t
(upper 16 bits)PM_Battery_State_t
(upper 16 bits)Here is an example of how you can extract the charger state from param1:
Explanation
Extract Charger State: uint16_t chargerState = (pEvent->param1 >> 16) & 0xFFFF;
Extract Charge Level: uint16_t chargeLevel = pEvent->param1 & 0xFFFF;
Extract Battery State: uint16_t batteryState = (pEvent->param2 >> 16) & 0xFFFF;
Extract Battery Voltage: uint16_t batteryVoltage = pEvent->param2 & 0xFFFF;
By correctly interpreting these bit-packed parameters, you can extract and handle the necessary power information in your application. Make sure to adapt the PM_Charger_State_t enum and the handling logic as per your SDK documentation.