Terminal

>w## Notice > * please include the header file "bwsdk_api.h" when you need to use terminal interface `#include "bwsdk_api.h"` >i## data structure ```/** * @brief System time */ typedef struct { unsigned short year; ///< year 2000 ~ 2049 unsigned short mon; ///< month 1 - 12 unsigned short day; ///< day 1 - 31 unsigned short hour; ///< hour 0 - 23 unsigned short min; ///< minutes 0 - 59 unsigned short sec; ///< second 0 - 59 unsigned short wday; ///< week 0 - 6 (week days, from 0 to 6) } tsSysTime; /** * @brief Sleep Level */ typedef enum { SLEEP_LEVEL_NOSLEEP = 0, ///< No sleep, screen will not auto turn off SLEEP_LEVEL_SYSTEM = 1, ///< Screen auto turn off after timeout, system will enter sleep after screen off. SLEEP_LEVEL_DEEP = 2, ///< Screen auto turn off after timeout, subsystem (eg: WIFI) will enter lowpower mode after deep sleep timeout. SLEEP_LEVEL_UNINITED = 3 ///< Sleep level has not been set. } sleep_level_t; ``` >i## BWSP_Power ### Prototype `void BWSP_Power(int onoff);` ### Function * SP power on/off ### Parameter |Name|Type|description| |-|-|-| |onoff|int|[in] 0: power off, 1: power on| ### Retval |Value|Type|Description| |-|-|-| |none||| >i## GetDSN ### Prototype `int GetDSN(unsigned char *snData, unsigned int len);` ### Function * Get device SN number ### Parameter |Name|Type|description| |-|-|-| |snData|unsigned char *|[out] Serial number data, size fixed 64 bytes| |len|unsigned int|size of snData| ### Retval |Value|Type|Description| |-|-|-| |0|int|success| |-1|int|fail| >i## GetMercuryPlatformVer ### Prototype `unsigned int GetMercuryPlatformVer(void);` ### Function * Get system platform version ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |platform version (Binary code)|unsigned int|example 0x00010901 is V1.9.1| >i## BWSDK_GetSysLibVersion ### Prototype `char* BWSDK_GetSysLibVersion(void);` ### Function * Get the system lib version ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |string of syslib version|char *|no need free| >i## BWSDK_GetVersion ### Prototype `char *BWSDK_GetVersion(unsigned char *maj, unsigned char *mid, unsigned char *min);` ### Function * Get BWSDK version number ### Parameter |Name|Type|description| |-|-|-| |maj|unsigned char *|high part of version number| |mid|unsigned char *|middle part of version number| |min|unsigned char *|low part of version number| ### Retval |Value|Type|Description| |-|-|-| |version number string|char *|no need to free, example 01.00.01| >i## AppLib_GetVersion ### Prototype `char* AppLib_GetVersion(void);` ### Function * get applib version ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |applib version string|char *|no need free| >i## DelayMs ### Prototype `void DelayMs(unsigned int ms);` ### Function * Delay specified ms ### Parameter |Name|Type|description| |-|-|-| |ms|unsigned int|millisecond number| ### Retval |Value|Type|Description| |-|-|-| |none||| >i## GetSysTickCount ### Prototype `unsigned int GetSysTickCount(void);` ### Function * Get system tick count from power on to current ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |tick count|unsigned int|1ms/tick| >i## GetSysLocalTime ### Prototype `int GetSysLocalTime(tsSysTime *time);` ### Function * Get system local time ### Parameter |Name|Type|description| |-|-|-| |time|tsSysTime *|[out] system time got| ### Retval |Value|Type|Description| |-|-|-| |=0|int|success| |<0|int|fail| >i## SetSysLocalTime ### Prototype `int SetSysLocalTime(tsSysTime *time);` ### Function * Setup system local time ### Parameter |Name|Type|description| |-|-|-| |time|tsSysTime *|[int] system time want to set to| ### Retval |Value|Type|Description| |-|-|-| |=0|int|success| |<0|int|fail| >i## IsCharging ### Prototype `int IsCharging(void);` ### Function * Get system charging status ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |0|int|NOT charging| |1|int|charging| >i## IsChargerExist ### Prototype `int IsChargerExist(void);` ### Function * Check if the charger existing ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |0|int|Charger not exist| |1|int|Charger exist| >i## IsBatteryExist ### Prototype `int IsBatteryExist(void);` ### Function * Check if the main battery existing ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |0|int|Battery not exist| |1|int|Battery exist| >i## GetBatteryVoltage ### Prototype `unsigned int GetBatteryVoltage(void);` ### Function * Get main battery voltage in mV ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |The main battery voltage|unsigned int|mV| >i## GetBatteryTemp ### Prototype `int GetBatteryTemp(void);` ### Function * Get main battery tempreature in degrees Celsius ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |The main battery voltage|int|-5 to 50| >i## GetBatteryPercent ### Prototype `unsigned int GetBatteryPercent(void);` ### Function * Get main battery capacity percentage which estimate from voltage ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |The main battery capacity percentage|unsigned int|0 to 100| >i## SetSysSleepLevel ### Prototype `void SetSysSleepLevel(sleep_level_t sleep_level);` ### Function * set system sleep level ### Parameter |Name|Type|description| |-|-|-| |sleep_level|sleep_level_t|see struct sleep_level_t| ### Retval |Value|Type|Description| |-|-|-| |none||| >i## GetSysSleepLevel ### Prototype `sleep_level_t GetSysSleepLevel(void);` ### Function * get device sleep level ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |sleep level|sleep_level_t|see struct sleep_level_t| >i## SetSysSleepTime ### Prototype `void SetSysSleepTime(int tsec);` ### Function * Setup system waiting time, will sleep after a none-operation of user specified second ### Parameter |Name|Type|description| |-|-|-| |tsec|int|seconds, minimum 10 second| ### Retval |Value|Type|Description| |-|-|-| |none||| >i## SetSysDeepSleepTimeout ### Prototype `void SetSysDeepSleepTimeout(int tsec);` ### Function * Set system timeout to deep sleep **Notice:Device enter into deep sleep only when sleep mode is set to level2** ### Parameter |Name|Type|description| |-|-|-| |tsec|int|timeout seconds, allow 5 to 3600 seconds| ### Retval |Value|Type|Description| |-|-|-| |none||| >i## ResetSysSleepTimer ### Prototype `void ResetSysSleepTimer(void);` ### Function * System sleeping timer restart ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |none||| >i## GetSysStatus ### Prototype `int GetSysStatus(void);` ### Function * Get system sleeping status ### Parameter |Name|Type|description| |-|-|-| |none||| ### Retval |Value|Type|Description| |-|-|-| |0|int|system sleeping| |1|int|system NOT sleeping| >i## KbToneNV ### Prototype `void KbToneNV(int onoff);` ### Function * Keyboard sound switch, and store this config to NV ### Parameter |Name|Type|description| |-|-|-| |onoff|int|[in] 0-OFF,1-ON| ### Retval |Value|Type|Description| |-|-|-| |none||| >i## IsKbToneEnable ### Prototype `int IsKbToneEnable(void);` ### Function * Get current keyboard sound switch status ### Parameter |Name|Type|description| |-|-|-| |onoff|int|[in] 0-OFF,1-ON| ### Retval |Value|Type|Description| |-|-|-| |0|int|keyboard sound OFF| |1|int|keyboard sound ON| >i## GetSysInfo ### Prototype `int GetSysInfo(char *info, int flag);` ### Function * Get system information ### Parameter |Name|Type|description| |-|-|-| |info|char *|[out] system information got| |flag|int|[int] 0-ismi, 1-ccid, 2-imei, 3-version (information type)| ### Retval |Value|Type|Description| |-|-|-| |=0|int|success| |<0|int|fail| >s## Example ``` ///< power on SP BWSP_Power(1); ///< get device SN int iRet = 0; unsigned char devSn[64] = {0}; iRet = GetDSN(devSn, sizeof(devSn)); if (iRet < 0) { return iRet; } ///< get Mercury Plat version unsigned int platVer = 0; platVer = GetMercuryPlatformVer(); ///< get system lib version char *pSysLbVer = BWSDK_GetSysLibVersion(); ///< get SDK version unsigned char majVer = 0; unsigned char midVer = 0; unsigned char minVer = 0; char *pSDKVer = BWSDK_GetVersion(&majVer, &midVer, &minVer); ///< get applib version char *pApplibVer = AppLib_GetVersion(); ///< delay 100 ms DelayMs(100); ///< get system tick count unsigned int sysTickCount = GetSysTickCount(); ///< get and set system time int iRet = 0; tsSysTime datime; memset(&datime, 0, sizeof(tsSysTime)); iRet = GetSysLocalTime(&datime); if (!iRet) { datime.year = 2019; iRet = SetSysLocalTime(&datime); } return iRet; ///< battery int flag = 1; if (IsBatteryExist()) { if (GetBatteryVoltage() <= 3400) { if (!IsChargerExist() || !IsCharging()) { flag = 0; } } if (GetBatteryTemp() > 40) { flag = 0; } } if (flag) { return SUCCESS; } return ERROR; ///< system sleep function int iRet = 0; sleep_level_t sleepLevel = SLEEP_LEVEL_UNINITED; iRet = GetSysStatus(); if (iRet) { sleepLevel = GetSysSleepLevel(); if (SLEEP_LEVEL_DEEP != sleepLevel) { SetSysSleepLevel(SLEEP_LEVEL_DEEP ); SetSysSleepTime(30); SetSysDeepSleepTimeout(30); ResetSysSleepTimer(); } } return SUCCESS; ///< turn off keytone if (IsKbToneEnable()) { KbToneNV(0); } ///< get system information char imei[64] = {0}; if (0 == GetSysInfo(imei, 2)) { LOGD("imei = %s\r\n", imei); } ```