-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using API_EVENT_ID_POWER_INFO ChatGpt Generate Solution #555
Comments
Test Code /*
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: