errcode_t uapi_create_osThread_custom(app_task_definition_t *task_cfg)
{
- if (task_cfg==NULL)
+ if (task_cfg == NULL)
return ERRCODE_FAIL;
- /* Create queues before tasks in case they are used during initialisation. */
- if (task_cfg->create_queue_handle) {
+ /* Create queues before tasks in case they are used during initialisation. */
+ if (task_cfg->create_queue_handle)
+ {
task_cfg->create_queue_handle();
}
/* Create tasks */
- if (task_cfg->use_mem == USE_EXTEND_MEM) {
+ if (task_cfg->use_mem == USE_EXTEND_MEM)
+ {
task_cfg->attr.stack_mem = memalign(16, task_cfg->attr.stack_size); // 16字节对齐
}
task_cfg->task_handle = osThreadNew(task_cfg->func, NULL, &(task_cfg->attr));
- if (task_cfg->task_handle == NULL) {
+ if (task_cfg->task_handle == NULL)
+ {
return ERRCODE_FAIL;
}
return ERRCODE_SUCC;
{
#ifdef SUPPORT_NV
- if( buf_sn == NULL)
+ if (buf_sn == NULL)
return ERRCODE_FAIL;
uint16_t len = 0;
custom_key_sn_t sn = {0};
errcode_t nvRet = uapi_nv_read(NV_ID_CUSTOM_KEY_SERIAL_NUM, sizeof(custom_key_sn_t), &len, &sn);
- if (nvRet != ERRCODE_SUCC) {
- *len_sn = 0;
+ if (nvRet != ERRCODE_SUCC)
+ {
+ *len_sn = 0;
}
- memcpy_s(buf_sn,sizeof(sn.sn),sn.sn,sn.size);
+ memcpy_s(buf_sn, sizeof(sn.sn), sn.sn, sn.size);
*len_sn = sn.size;
- //PRINT("get sn len %d, ret %d , %s\r\n",sn.size,nvRet,sn.sn);
+ // PRINT("get sn len %d, ret %d , %s\r\n",sn.size,nvRet,sn.sn);
#endif
return ERRCODE_SUCC;
}
-
uint32_t zh_set_sn(uint8_t *buf_sn, uint32_t len_sn)
{
- errcode_t nv_ret_value=0;
+ errcode_t nv_ret_value = 0;
#ifdef SUPPORT_NV
- if( buf_sn == NULL || len_sn == 0)
+ if (buf_sn == NULL || len_sn == 0)
return ERRCODE_FAIL;
- uint8_t *test_nv_value; /* 要写入的NV value保存在test_nv_value中 */
+ uint8_t *test_nv_value; /* 要写入的NV value保存在test_nv_value中 */
- uint16_t key_len= sizeof(custom_key_sn_t);
- uint8_t *write_value = malloc(key_len);
- custom_key_sn_t *p_sn = (custom_key_sn_t*)write_value;
+ uint16_t key_len = sizeof(custom_key_sn_t);
+ uint8_t *write_value = malloc(key_len);
+ custom_key_sn_t *p_sn = (custom_key_sn_t *)write_value;
uint16_t len = 0;
if (len_sn > sizeof(p_sn->sn))
{
len = sizeof(p_sn->sn);
- }else{
+ }
+ else
+ {
len = len_sn;
}
p_sn->size = len;
- memcpy_s(p_sn->sn,sizeof(p_sn->sn),buf_sn,len);
- nv_ret_value = uapi_nv_write(NV_ID_CUSTOM_KEY_SERIAL_NUM, write_value, key_len);
- if (nv_ret_value != ERRCODE_SUCC) {
- /* ERROR PROCESS */
- free(write_value);
- return ERRCODE_FAIL;
- }
- /* APP PROCESS */
- free(write_value);
+ memcpy_s(p_sn->sn, sizeof(p_sn->sn), buf_sn, len);
+ nv_ret_value = uapi_nv_write(NV_ID_CUSTOM_KEY_SERIAL_NUM, write_value, key_len);
+ if (nv_ret_value != ERRCODE_SUCC)
+ {
+ /* ERROR PROCESS */
+ free(write_value);
+ return ERRCODE_FAIL;
+ }
+ /* APP PROCESS */
+ free(write_value);
#endif
return nv_ret_value;
-
}
extern uint32_t mcu_os_sys_reset(uint8_t *para, uint32_t para_len);
extern void sync_all_config_to_disk(void);
void uapi_poweroff_device(void)
{
-
+
uapi_sys_shipmode(0);
}
void uapi_reboot_device(void)
{
- mcu_os_sys_reset(NULL,NULL);
+ mcu_os_sys_reset(NULL, NULL);
}
void shutdown_reboot_prejobs_task(void)
{
addressbookTowrite();
-
+
uapi_calendar_store_date();
sync_all_config_to_disk();
}
void shutdown_reboot_prejobs(void)
{
PRINT("shutdown_reboot_prejobs !\r\n");
- app_task_definition_t taskcfg={0};
+ app_task_definition_t taskcfg = {0};
taskcfg.create_queue_handle = NULL;
- taskcfg.attr.name="shutdown_reboot_prejobs";
+ taskcfg.attr.name = "shutdown_reboot_prejobs";
taskcfg.attr.priority = osPriorityNormal;
- taskcfg.attr.stack_size = 0x1000*2;
+ taskcfg.attr.stack_size = 0x1000 * 2;
taskcfg.func = shutdown_reboot_prejobs_task;
taskcfg.use_mem = USE_EXTEND_MEM;
-
- errcode_t ret=uapi_create_osThread_custom(&taskcfg);
- if(ret != ERRCODE_SUCC)
+
+ errcode_t ret = uapi_create_osThread_custom(&taskcfg);
+ if (ret != ERRCODE_SUCC)
{
- PRINT("create shutdown_reboot_prejobs thread failed %d!\r\n",ret);
-
+ PRINT("create shutdown_reboot_prejobs thread failed %d!\r\n", ret);
}
}
void start_shutdown_or_reboot(void)
bool start_custom_ble_service(void)
{
#ifdef SUPPORT_BLE_SERVICE
- openBle();
- PRINT("start custom protocol classic bt ble service !\r\n");
- // bool ret = enable_bt_stack();
-#endif
+ openBle();
+ PRINT("start custom protocol classic bt ble service !\r\n");
+ // bool ret = enable_bt_stack();
+#endif
return true;
}
bool stop_custom_ble_service(void)
{
#ifdef SUPPORT_BLE_SERVICE
- PRINT("start custom protocol classic bt ble service !\r\n");
- // ble_unregist_server();
- closeBle();
- // bool ret = disable_bt_stack();
-#endif
+ PRINT("start custom protocol classic bt ble service !\r\n");
+ // ble_unregist_server();
+ closeBle();
+ // bool ret = disable_bt_stack();
+#endif
return true;
}
PRINT("startup_post_init_task !\r\n");
uapi_calendar_recover_date();
- if(!custom_ble_service_on_flag())
+ if (!custom_ble_service_on_flag())
{
stop_custom_ble_service();
}
LOS_Msleep(5000);
addressbookToRead();
- if ( poweron_cat1_on_bootup_flag() )
+ if (poweron_cat1_on_bootup_flag())
{
PRINT("PowerOn Cat1 !\r\n");
uapi_cat1_power_on(1);
uapi_cat1_reset(0);
- }else{
+ }
+ else
+ {
PRINT("PowerOff Cat1 !\r\n");
uapi_cat1_power_on(0);
uapi_cat1_reset(1);
}
-
}
-
+
void startup_post_init(void)
{
PRINT("startup_post_init !\r\n");
- app_task_definition_t taskcfg={0};
+ app_task_definition_t taskcfg = {0};
taskcfg.create_queue_handle = NULL;
- taskcfg.attr.name="startup_post_init_task";
+ taskcfg.attr.name = "startup_post_init_task";
taskcfg.attr.priority = osPriorityNormal;
taskcfg.attr.stack_size = 0x1000;
taskcfg.func = startup_post_init_task;
taskcfg.use_mem = USE_EXTEND_MEM;
-
- errcode_t ret=uapi_create_osThread_custom(&taskcfg);
- if(ret != ERRCODE_SUCC)
+
+ errcode_t ret = uapi_create_osThread_custom(&taskcfg);
+ if (ret != ERRCODE_SUCC)
{
- PRINT("create shutdown_reboot_prejobs thread failed %d!\r\n",ret);
-
+ PRINT("create shutdown_reboot_prejobs thread failed %d!\r\n", ret);
}
}
{
errcode_t ret;
upg_prepare_info_t t = {0};
- t.package_len = 4 ; //文件升级的前提下,只要package_len 大于0 即可。
+ t.package_len = 4; // 文件升级的前提下,只要package_len 大于0 即可。
ret = uapi_upg_prepare(&t);
- if (ret != ERRCODE_SUCC) {
+ if (ret != ERRCODE_SUCC)
+ {
printf("uapi_upg_prepare error = 0x%x\r\n", ret);
return ret;
- } else {
+ }
+ else
+ {
printf("uapi_upg_prepare OK!!\r\n");
}
ret = uapi_upg_request_upgrade(false);
- if (ret != ERRCODE_SUCC) {
+ if (ret != ERRCODE_SUCC)
+ {
printf("uapi_upg_request_upgrade error = 0x%x\r\n", ret);
- } else {
+ }
+ else
+ {
printf("uapi_upg_request_upgrade OK!!\r\n");
/* app中下载后直接开始升级流程,升级流程结束后重启 */
/* IOT设备重启 */
return ret;
}
-
#include "systick.h"
#include "sys/time.h"
#include "time.h"
errcode_t uapi_get_timestampe_ms(uint64_t *tm)
{
- struct timeval tv = { 0 };
+ struct timeval tv = {0};
- if (gettimeofday(&tv, NULL)) {
+ if (gettimeofday(&tv, NULL))
+ {
return ERRCODE_FAIL;
}
- *tm = (uint64_t)(tv.tv_sec*1000 + tv.tv_usec/1000 );
-
+ *tm = (uint64_t)(tv.tv_sec * 1000 + tv.tv_usec / 1000);
+
return ERRCODE_SUCC;
}
-#define BITS_PER_BYTE 8
-#define HEXADECIMAL 16
-#define DECIMAL 10
-#define TIME_YEAR_OFFSET 123
-#define TIME_ZONE_OFF (8 * 60)
-#define TIME_SECSPERMIN 60 /* second per minute */
-static uint32_t get_sec_time_from_cat1time(char* time , uint32_t *second , uint8_t *zone)
+#define BITS_PER_BYTE 8
+#define HEXADECIMAL 16
+#define DECIMAL 10
+#define TIME_YEAR_OFFSET 123
+#define TIME_ZONE_OFF (8 * 60)
+#define TIME_SECSPERMIN 60 /* second per minute */
+static uint32_t get_sec_time_from_cat1time(char *time, uint32_t *second, uint8_t *zone)
{
- struct tm _tm = { 0 };
- char* ptr = time;
- char* tmp;
+ struct tm _tm = {0};
+ char *ptr = time;
+ char *tmp;
- if (time==NULL || strlen(time) < 12)
+ if (time == NULL || strlen(time) < 12)
{
printf("time==NULL || strlen(time) < 12 , format error, should like (2024, 3, 2, 18, 40, 1, 5, 62),8 ");
return 2;
}
-
+
// 年
tmp = strchr(ptr, '(');
- if (tmp == NULL) { return 1; }
+ if (tmp == NULL)
+ {
+ return 1;
+ }
ptr = tmp + 1;
tmp = strchr(ptr, ',');
- if (tmp == NULL) { return 1; }
+ if (tmp == NULL)
+ {
+ return 1;
+ }
*tmp = '\0';
// 年的计算需要减去1900
_tm.tm_year = strtol(ptr, NULL, DECIMAL) - 1900;
- if (_tm.tm_year < TIME_YEAR_OFFSET) {
+ if (_tm.tm_year < TIME_YEAR_OFFSET)
+ {
printf("ERR!year num must bigger than 2023!");
return 3;
}
ptr = tmp + 1;
-
// 月
- if ( *ptr == ' ') { ptr = ptr + 1; }
+ if (*ptr == ' ')
+ {
+ ptr = ptr + 1;
+ }
tmp = strchr(ptr, ',');
- if (tmp == NULL) { return 1; }
+ if (tmp == NULL)
+ {
+ return 1;
+ }
*tmp = '\0';
// 月的计算需要减1
_tm.tm_mon = strtol(ptr, NULL, DECIMAL) - 1;
ptr = tmp + 1;
// 日
- if ( *ptr == ' ') { ptr = ptr + 1; }
+ if (*ptr == ' ')
+ {
+ ptr = ptr + 1;
+ }
tmp = strchr(ptr, ',');
- if (tmp == NULL) { return 1; }
+ if (tmp == NULL)
+ {
+ return 1;
+ }
*tmp = '\0';
_tm.tm_mday = strtol(ptr, NULL, DECIMAL);
ptr = tmp + 1;
// 时
- if ( *ptr == ' ') { ptr = ptr + 1; }
+ if (*ptr == ' ')
+ {
+ ptr = ptr + 1;
+ }
tmp = strchr(ptr, ',');
- if (tmp == NULL) { return 1; }
+ if (tmp == NULL)
+ {
+ return 1;
+ }
*tmp = '\0';
_tm.tm_hour = strtol(ptr, NULL, DECIMAL);
ptr = tmp + 1;
// 分
- if ( *ptr == ' ') { ptr = ptr + 1; }
+ if (*ptr == ' ')
+ {
+ ptr = ptr + 1;
+ }
tmp = strchr(ptr, ',');
- if (tmp == NULL) { return 1; }
+ if (tmp == NULL)
+ {
+ return 1;
+ }
*tmp = '\0';
_tm.tm_min = strtol(ptr, NULL, DECIMAL);
ptr = tmp + 1;
// 秒
- if ( *ptr == ' ') { ptr = ptr + 1; }
+ if (*ptr == ' ')
+ {
+ ptr = ptr + 1;
+ }
tmp = strchr(ptr, ',');
- if (tmp == NULL) { return 1; }
+ if (tmp == NULL)
+ {
+ return 1;
+ }
*tmp = '\0';
_tm.tm_sec = strtol(ptr, NULL, DECIMAL);
ptr = tmp + 1;
- //毫秒
+ // 毫秒
tmp = strchr(ptr, ',');
- if (tmp == NULL) { return 1; }
+ if (tmp == NULL)
+ {
+ return 1;
+ }
ptr = tmp + 1;
- //微妙
+ // 微妙
tmp = strchr(ptr, ',');
- if (tmp == NULL) { return 1; }
+ if (tmp == NULL)
+ {
+ return 1;
+ }
ptr = tmp + 1;
-
- //时区
- if ( *ptr == ' ') { ptr = ptr + 1; }
+
+ // 时区
+ if (*ptr == ' ')
+ {
+ ptr = ptr + 1;
+ }
*zone = strtol(ptr, NULL, DECIMAL);
*second = (uint32_t)__tm_to_secs(&_tm);
- *second -= *zone * 3600; //cat1获得的时间时当下时间,实际上要减去zone的时间
+ *second -= *zone * 3600; // cat1获得的时间时当下时间,实际上要减去zone的时间
// printf("%04d-%02d-%02d %02d:%02d:%02d %d\n",_tm.tm_year,_tm.tm_mon,_tm.tm_mday,_tm.tm_hour,_tm.tm_min,_tm.tm_sec,*zone);
return 0;
}
-errcode_t uapi_set_time_from_cat1(char* cat1time)
+errcode_t uapi_set_time_from_cat1(char *cat1time)
{
uint8_t zone = 0;
- uint32_t sec = 0;
- uint32_t ret = get_sec_time_from_cat1time(cat1time,&sec,&zone);
-
- if (ret == 0 )
- {
- struct timeval tv = { 0 };
- struct timezone tz = { 0 };
+ uint32_t sec = 0;
+ uint32_t ret = get_sec_time_from_cat1time(cat1time, &sec, &zone);
- tv.tv_sec = sec;
- tv.tv_usec = 0;
- tz.tz_dsttime = 0;
- tz.tz_minuteswest = zone*60;
- settimeofday(&tv, &tz);
-
- }else{
- printf("convert to time failed ret %d!\n",ret);
+ if (ret == 0)
+ {
+ struct timeval tv = {0};
+ struct timezone tz = {0};
+
+ tv.tv_sec = sec;
+ tv.tv_usec = 0;
+ tz.tz_dsttime = 0;
+ tz.tz_minuteswest = zone * 60;
+ settimeofday(&tv, &tz);
+ }
+ else
+ {
+ printf("convert to time failed ret %d!\n", ret);
return ERRCODE_FAIL;
- }
-
-
+ }
+
time_t rawtime;
- struct tm* timeinfo;
+ struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
printf("set time success %04d-%02d-%02d %02d:%02d:%02d %d\n",
- timeinfo->tm_year + 1900,
- timeinfo->tm_mon + 1,
- timeinfo->tm_mday,
- timeinfo->tm_hour,
- timeinfo->tm_min,
- timeinfo->tm_sec,zone);
-
- if (timeinfo->tm_year+1900 < 2024)
+ timeinfo->tm_year + 1900,
+ timeinfo->tm_mon + 1,
+ timeinfo->tm_mday,
+ timeinfo->tm_hour,
+ timeinfo->tm_min,
+ timeinfo->tm_sec, zone);
+
+ if (timeinfo->tm_year + 1900 < 2024)
return ERRCODE_FAIL;
return ERRCODE_SUCC;
-}
+}
/*
* @brief 获取当地[年-月-日]日期
* @return 格式为:[年.月.日]的字符串
-*/
+ */
char *uapi_get_local_yyyymmdd_date(void)
{
time_t rawtime;
- struct tm* timeinfo;
+ struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
- char *buffer = (char*)malloc(80); // 动态分配内存
- if(buffer == NULL)
+ char *buffer = (char *)malloc(80); // 动态分配内存
+ if (buffer == NULL)
{
return NULL; // 内存分配失败
}
// 格式化输出当前时间为 "YYYY-MM-DD HH:MM:SS" 形式
- sprintf(buffer,"%04d.%02d.%02d\n",
- timeinfo->tm_year + 1900,
- timeinfo->tm_mon + 1,
- timeinfo->tm_mday);
-
+ sprintf(buffer, "%04d.%02d.%02d\n",
+ timeinfo->tm_year + 1900,
+ timeinfo->tm_mon + 1,
+ timeinfo->tm_mday);
+
return buffer;
}
/// @brief 获取日期
errcode_t uapi_get_yyyymmddhhmmss_Date(char *date)
{
- if(date != NULL)
+ if (date != NULL)
{
time_t rawtime;
- struct tm* timeinfo;
+ struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
- sprintf(date,"%04d%02d%02d%02d%02d%02d",
- timeinfo->tm_year + 1900,
- timeinfo->tm_mon + 1,
- timeinfo->tm_mday,
- timeinfo->tm_hour,
- timeinfo->tm_min,
- timeinfo->tm_sec);
+ sprintf(date, "%04d%02d%02d%02d%02d%02d",
+ timeinfo->tm_year + 1900,
+ timeinfo->tm_mon + 1,
+ timeinfo->tm_mday,
+ timeinfo->tm_hour,
+ timeinfo->tm_min,
+ timeinfo->tm_sec);
}
return ERRCODE_SUCC;
}
}
/// @brief 控制屏幕是否常亮
-/// @param turnOnFlag 1:常亮屏幕
-/// @param turnOnFlag 0:取消常亮
+/// @param turnOnFlag 1:常亮屏幕
+/// @param turnOnFlag 0:取消常亮
void ScreenAlwaysOnCtr(uint8_t turnOnFlag)
{
const power_display_svr_api_t *display_api = power_display_svr_get_api();
- if(turnOnFlag)
+ if (turnOnFlag)
{
display_api->set_screen_set_keepon_timeout(0);
if (display_api->get_screen_state() != SCREEN_ON)
{
display_api->turn_on_screen();
}
- //当设置的值是-1 的时候,设置屏幕常亮
+ // 当设置的值是-1 的时候,设置屏幕常亮
display_api->set_screen_set_keepon_timeout(-1);
}
else
}
/*
- * @brief 设置某个Slice亮屏时间,超过时间后屏幕息屏,单位ms
-*/
+ * @brief 设置某个Slice亮屏时间,超过时间后屏幕息屏,单位ms
+ */
void uapi_setScreenDuration(int32_t time)
{
const power_display_svr_api_t *display_api = power_display_svr_get_api();
}
/*
- * @brief 获取屏幕状态
-*/
+ * @brief 获取屏幕状态
+ */
int32_t uapi_get_screen_state(void)
{
const power_display_svr_api_t *display_api = power_display_svr_get_api();
void uapi_set_screen_on_api(void)
{
const power_display_svr_api_t *display_api = power_display_svr_get_api();
+ display_api->set_screen_set_keepon_timeout(0);
if (display_api->get_screen_state() != SCREEN_ON)
{
display_api->turn_on_screen();
}
+ // 设置屏幕亮5000
+ display_api->set_screen_set_keepon_timeout(5000);
}
#include "bts_le_gap.h"
-
-
// extern void wstp_spp_cmd_server_create(const char *spp_uuid, const char *name, uint8_t name_len);
// extern void wstp_spp_cmd_server_accept(uint32_t server_id);
// extern errcode_t enable_bt_stack(void);
// extern errcode_t bluetooth_get_local_name(unsigned char *localName, unsigned char *length);
errcode_t uapi_get_btname(uint8_t *buf_btname, uint32_t *len_btname)
{
- if(buf_btname == NULL || len_btname == NULL)
+ if (buf_btname == NULL || len_btname == NULL)
{
printf("ERROR param NULL");
return ERRCODE_FAIL;
unsigned char namelen = 248;
unsigned char name[248] = {0};
errcode_t res = bluetooth_get_local_name(name, &namelen);
- if (res == 0) {
+ if (res == 0)
+ {
char str[256] = "^btname:";
- strcat_s(str, strlen(str) + strlen((char*)name), (char*)name);
+ strcat_s(str, strlen(str) + strlen((char *)name), (char *)name);
printf("%s\r\n", &str[0]);
printf("name: %s, length: %d\n", name, namelen);
- sprintf((char*)buf_btname,"%s",name);
- *len_btname = strlen((const char*)name);
+ sprintf((char *)buf_btname, "%s", name);
+ *len_btname = strlen((const char *)name);
return ERRCODE_SUCC;
- } else {
- printf("bluetooth_get_local_name ret = 0x%X\n",res);
+ }
+ else
+ {
+ printf("bluetooth_get_local_name ret = 0x%X\n", res);
return ERRCODE_FAIL;
}
-
}
errcode_t uapi_get_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr)
{
- if (buf_btaddr == NULL || len_btaddr == NULL) {
+ if (buf_btaddr == NULL || len_btaddr == NULL)
+ {
printf("ERROR param NULL");
return ERRCODE_FAIL;
}
errcode_t res;
- #define BT_MAC_LEN 6
+#define BT_MAC_LEN 6
unsigned int len = BT_MAC_LEN;
unsigned char addr[BT_MAC_LEN] = {0};
srand(time(0));
res = bluetooth_get_local_addr(&addr[0], len);
- if (res == 0) {
+ if (res == 0)
+ {
char str[64] = {0};
- strcat_s(str, strlen(str) + strlen((char*)addr), (char*)addr);
+ strcat_s(str, strlen(str) + strlen((char *)addr), (char *)addr);
printf("%s\r\n", &str[0]);
printf("local_addr : ******%02x%02x%02x\n", addr[3], addr[4], addr[5]);
-
- memset((void*)buf_btaddr,0,*len_btaddr);
- sprintf_s((char*)buf_btaddr, *len_btaddr, "%02X:%02X:%02X:%02X:%02X:%02X",addr[0], addr[1],addr[2],addr[3],addr[4],addr[5]);
+
+ memset((void *)buf_btaddr, 0, *len_btaddr);
+ sprintf_s((char *)buf_btaddr, *len_btaddr, "%02X:%02X:%02X:%02X:%02X:%02X", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
*len_btaddr = strlen(str);
-
- } else {
- printf("bluetooth_get_local_addr err 0x%X\r\n",res);
+ }
+ else
+ {
+ printf("bluetooth_get_local_addr err 0x%X\r\n", res);
return ERRCODE_FAIL;
}
-
return ERRCODE_SUCC;
}
{
#ifdef SUPPORT_NV
- if( buf_btaddr == NULL || len_btaddr == NULL || *len_btaddr == 0)
+ if (buf_btaddr == NULL || len_btaddr == NULL || *len_btaddr == 0)
return ERRCODE_FAIL;
uint16_t len = 0;
btsrv_local_device_info_t btinfo = {0};
errcode_t nvRet = uapi_nv_read(NV_ID_BTSRV_LOCAL_DEV_INFO, sizeof(btsrv_local_device_info_t), &len, &btinfo);
- if (nvRet != ERRCODE_SUCC) {
- *len_btaddr = 0;
- return nvRet;
+ if (nvRet != ERRCODE_SUCC)
+ {
+ *len_btaddr = 0;
+ return nvRet;
}
uint32_t max_input_len = *len_btaddr;
- memcpy_s(buf_btaddr,max_input_len,btinfo.bd_addr,sizeof(btinfo.bd_addr));
+ memcpy_s(buf_btaddr, max_input_len, btinfo.bd_addr, sizeof(btinfo.bd_addr));
*len_btaddr = sizeof(btinfo.bd_addr);
printf("get nv local_addr : ******%02x%02x%02x\n", buf_btaddr[2], buf_btaddr[1], buf_btaddr[0]);
#endif
- return ERRCODE_SUCC;
+ return ERRCODE_SUCC;
}
errcode_t uapi_set_nv_btaddr(uint8_t *buf_btaddr, uint32_t len_btaddr)
{
#ifdef SUPPORT_NV
- if( buf_btaddr == NULL || len_btaddr == 0)
+ if (buf_btaddr == NULL || len_btaddr == 0)
return ERRCODE_FAIL;
btsrv_local_device_info_t btinfo = {0};
uint16_t len = 0;
-
+
/**先读取NV,再修改addr值*/
errcode_t nvRet = uapi_nv_read(NV_ID_BTSRV_LOCAL_DEV_INFO, sizeof(btsrv_local_device_info_t), &len, &btinfo);
- if (nvRet != ERRCODE_SUCC) {
- return nvRet;
+ if (nvRet != ERRCODE_SUCC)
+ {
+ return nvRet;
}
+ uint16_t key_len = sizeof(btinfo.bd_addr);
+ memcpy_s(btinfo.bd_addr, key_len, buf_btaddr, len_btaddr);
+ nvRet = uapi_nv_write(NV_ID_BTSRV_LOCAL_DEV_INFO, &btinfo, sizeof(btsrv_local_device_info_t));
+ if (nvRet != ERRCODE_SUCC)
+ {
+ /* ERROR PROCESS */
- uint16_t key_len= sizeof(btinfo.bd_addr);
- memcpy_s(btinfo.bd_addr,key_len,buf_btaddr,len_btaddr);
- nvRet = uapi_nv_write(NV_ID_BTSRV_LOCAL_DEV_INFO, &btinfo, sizeof(btsrv_local_device_info_t));
- if (nvRet != ERRCODE_SUCC) {
- /* ERROR PROCESS */
-
- return nvRet;
- }
+ return nvRet;
+ }
printf("set nv local_addr : ******%02x%02x%02x\n", buf_btaddr[3], buf_btaddr[4], buf_btaddr[5]);
-
+
#endif
-
+
return ERRCODE_SUCC;
}
-
errcode_t uapi_get_nv_btname(uint8_t *buf_btname, uint32_t *len_btname)
{
#ifdef SUPPORT_NV
- if( buf_btname == NULL || len_btname == NULL || *len_btname == 0)
+ if (buf_btname == NULL || len_btname == NULL || *len_btname == 0)
return ERRCODE_FAIL;
uint16_t len = 0;
btsrv_local_device_info_t btinfo = {0};
errcode_t nvRet = uapi_nv_read(NV_ID_BTSRV_LOCAL_DEV_INFO, sizeof(btsrv_local_device_info_t), &len, &btinfo);
- if (nvRet != ERRCODE_SUCC) {
- *len_btname = 0;
- return nvRet;
+ if (nvRet != ERRCODE_SUCC)
+ {
+ *len_btname = 0;
+ return nvRet;
}
uint32_t max_input_len = *len_btname;
- *len_btname = strlen((char*)btinfo.name);
- memcpy_s(buf_btname,max_input_len,btinfo.name,*len_btname);
+ *len_btname = strlen((char *)btinfo.name);
+ memcpy_s(buf_btname, max_input_len, btinfo.name, *len_btname);
printf("get nv local_name : %s\n", buf_btname);
#endif
- return ERRCODE_SUCC;
+ return ERRCODE_SUCC;
}
-
errcode_t uapi_set_nv_btname(uint8_t *buf_btname, uint32_t len_btname)
{
#ifdef SUPPORT_NV
- if( buf_btname == NULL || len_btname == 0)
+ if (buf_btname == NULL || len_btname == 0)
return ERRCODE_FAIL;
btsrv_local_device_info_t btinfo = {0};
uint16_t len = 0;
-
+
/**先读取NV,再修改addr值*/
errcode_t nvRet = uapi_nv_read(NV_ID_BTSRV_LOCAL_DEV_INFO, sizeof(btsrv_local_device_info_t), &len, &btinfo);
- if (nvRet != ERRCODE_SUCC) {
- return ERRCODE_FAIL;
+ if (nvRet != ERRCODE_SUCC)
+ {
+ return ERRCODE_FAIL;
}
+ uint16_t key_len = sizeof(btinfo.name);
+ memcpy_s(btinfo.name, key_len, buf_btname, len_btname);
+ nvRet = uapi_nv_write(NV_ID_BTSRV_LOCAL_DEV_INFO, &btinfo, sizeof(btsrv_local_device_info_t));
+ if (nvRet != ERRCODE_SUCC)
+ {
+ /* ERROR PROCESS */
- uint16_t key_len=sizeof(btinfo.name);
- memcpy_s(btinfo.name,key_len,buf_btname,len_btname);
- nvRet = uapi_nv_write(NV_ID_BTSRV_LOCAL_DEV_INFO, &btinfo, sizeof(btsrv_local_device_info_t));
- if (nvRet != ERRCODE_SUCC) {
- /* ERROR PROCESS */
-
- return ERRCODE_FAIL;
- }
+ return ERRCODE_FAIL;
+ }
printf("set nv local_name : %s\n", btinfo.name);
-
+
#endif
- return ERRCODE_SUCC;
+ return ERRCODE_SUCC;
}
-
-
-
errcode_t init_btaddr_btname(void)
{
- errcode_t ret ;
- uint8_t bd_addr[BD_ADDR_LEN]={0};
- uint8_t name[BTSDK_DEVNAME_LEN]={0};
- uint32_t addrlen = sizeof(bd_addr);
- ret = uapi_get_nv_btaddr(bd_addr,&addrlen);
- if (ret != ERRCODE_SUCC) {
- /* ERROR PROCESS */
- printf("uapi_get_nv_btaddr failed ret %d , addrlen %d\n",ret,addrlen);
- return ERRCODE_FAIL;
- }
+ errcode_t ret;
+ uint8_t bd_addr[BD_ADDR_LEN] = {0};
+ uint8_t name[BTSDK_DEVNAME_LEN] = {0};
+ uint32_t addrlen = sizeof(bd_addr);
+ ret = uapi_get_nv_btaddr(bd_addr, &addrlen);
+ if (ret != ERRCODE_SUCC)
+ {
+ /* ERROR PROCESS */
+ printf("uapi_get_nv_btaddr failed ret %d , addrlen %d\n", ret, addrlen);
+ return ERRCODE_FAIL;
+ }
- //如果 281106856959
- if ( bd_addr[5] == 0x59 &&
+ // 如果 281106856959
+ if (bd_addr[5] == 0x59 &&
bd_addr[4] == 0x69 &&
bd_addr[3] == 0x85 &&
bd_addr[2] == 0x06 &&
bd_addr[1] == 0x11 &&
- bd_addr[0] == 0x28 )
- {
-
- uint8_t soc_id[20]; // 20 is soc id length
+ bd_addr[0] == 0x28)
+ {
+
+ uint8_t soc_id[20]; // 20 is soc id length
uapi_soc_read_id(soc_id, 20); // 20 is soc id length
uint16_t sum = 0x0;
printf("[soc id:]\r\n");
- for (uint8_t i = 0; i < 20; i += 2) { // 20 is soc id length, 2 means use 16bits
- uint16_t ptmp16= *((uint16_t *)&soc_id[i]);
+ for (uint8_t i = 0; i < 20; i += 2)
+ { // 20 is soc id length, 2 means use 16bits
+ uint16_t ptmp16 = *((uint16_t *)&soc_id[i]);
sum += ptmp16;
printf("0x%04X ", ptmp16);
- if ((i + 2) % 8 == 0) { printf("\r\n"); } // 2&8 will word wrap
+ if ((i + 2) % 8 == 0)
+ {
+ printf("\r\n");
+ } // 2&8 will word wrap
}
- printf("get socid sum 0x%04X\r\n",sum);
+ printf("get socid sum 0x%04X\r\n", sum);
srand(sum);
- //默认是:281106856959
+ // 默认是:281106856959
printf("是默认值,修改地址\n");
- bd_addr[3] = rand() % 0xFF;
+ bd_addr[3] = rand() % 0xFF;
bd_addr[4] = rand() % 0xFF;
bd_addr[5] = rand() % 0xFF;
printf("uapi_set_nv_btaddr : ******%02x%02x%02x\n", bd_addr[3], bd_addr[4], bd_addr[5]);
ret = uapi_set_nv_btaddr(bd_addr, addrlen);
- if (ret != ERRCODE_SUCC) {
- /* ERROR PROCESS */
- printf("uapi_set_nv_btaddr failed ret %d\n",ret);
- return ERRCODE_FAIL;
- }
-
+ if (ret != ERRCODE_SUCC)
+ {
+ /* ERROR PROCESS */
+ printf("uapi_set_nv_btaddr failed ret %d\n", ret);
+ return ERRCODE_FAIL;
+ }
}
-
#if 0
uint32_t namelen = sizeof(name);
ret = uapi_get_nv_btname(name,&namelen);
}
#endif
return ERRCODE_SUCC;
-
}
-
#include "build_version.h"
-#define VER_STR_MAX 128
+#define VER_STR_MAX 128
errcode_t uapi_get_buildversion(uint8_t *para, uint32_t para_len)
{
- if (para == NULL || para_len == 0 )
+ if (para == NULL || para_len == 0)
return ERRCODE_FAIL;
char str[VER_STR_MAX];
-#if !(defined BUILD_TIME)
+#if !(defined BUILD_TIME)
#warning no BUILD_TIME
- (void)sprintf_s(str, VER_STR_MAX, "%s",
+ (void)sprintf_s(str, VER_STR_MAX, "%s",
get_version_string());
#else
#endif
printf(str);
- memset(para,0,para_len);
- memcpy_s(para,para_len,str,strlen(str));
+ memset(para, 0, para_len);
+ memcpy_s(para, para_len, str, strlen(str));
return ERRCODE_SUCC;
}
#include "vibrator.h"
-void vibrator_cyclicity(uint16_t duty , uint16_t cycle_time_ms,uint16_t duration_time_ms)
+void vibrator_cyclicity(uint16_t duty, uint16_t cycle_time_ms, uint16_t duration_time_ms)
{
- g_VibratorFunc(duty,cycle_time_ms,duration_time_ms);
+ g_VibratorFunc(duty, cycle_time_ms, duration_time_ms);
}
-
void uapi_take_to_wake(int cmd)
{
- if(cmd == 1)
- do_cywee_service_check_msg(CYWEE_SERVICE_CMD_OPEN_HAND_UPDOWN,NULL);
- else
- do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CLOSE_HAND_UPDOWN,NULL);
+ if (cmd == 1)
+ do_cywee_service_check_msg(CYWEE_SERVICE_CMD_OPEN_HAND_UPDOWN, NULL);
+ else
+ do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CLOSE_HAND_UPDOWN, NULL);
}
#include "lcd_common.h"
lcd_drv_cfg *lcd_cfg = NULL;
lcd_drv_comm_api = lcd_drv_get_common_api();
- if (lcd_drv_comm_api == NULL) {
+ if (lcd_drv_comm_api == NULL)
+ {
PRINT("lcd_drv_comm_api is null.\r\n");
}
else
{
lcd_cfg = lcd_drv_comm_api->get_lcd_config();
- if (lcd_cfg == NULL) {
+ if (lcd_cfg == NULL)
+ {
PRINT("lcd_cfg is null.\r\n");
- }else
+ }
+ else
{
- PRINT("LCD ID : 0x%x\r\n",(uint32_t)lcd_cfg->lcd_id);
+ PRINT("LCD ID : 0x%x\r\n", (uint32_t)lcd_cfg->lcd_id);
*id = (uint32_t)lcd_cfg->lcd_id;
}
}
#include "ft6x46_ctrl.h"
#include "ft6x46_touch1.h"
-#define FTS_REG_CHIP_ID 0xA3
-#define FTS_REG_CHIP_ID2 0x9F
+#define FTS_REG_CHIP_ID 0xA3
+#define FTS_REG_CHIP_ID2 0x9F
/*Max point numbers of touch trace*/
-#define MAX_POINTS_TOUCH_TRACE 1
+#define MAX_POINTS_TOUCH_TRACE 1
/*Length of touch information*/
-#define MAX_LEN_TOUCH_INFO (MAX_POINTS_TOUCH_TRACE * 6 + 2)
-#define FTS_MAX_POINTS_SUPPORT 10
-
-struct fts_ts_event {
- int x; /*x coordinate */
- int y; /*y coordinate */
- int p; /* pressure */
- int type; /* touch event flag: 0 -- down; 1-- up; 2 -- contact */
- int id; /*touch ID */
- int area; /*touch area*/
-};
+#define MAX_LEN_TOUCH_INFO (MAX_POINTS_TOUCH_TRACE * 6 + 2)
+#define FTS_MAX_POINTS_SUPPORT 10
+struct fts_ts_event
+{
+ int x; /*x coordinate */
+ int y; /*y coordinate */
+ int p; /* pressure */
+ int type; /* touch event flag: 0 -- down; 1-- up; 2 -- contact */
+ int id; /*touch ID */
+ int area; /*touch area*/
+};
-void get_tp_info(int16_t *x,int16_t *y)
+void get_tp_info(int16_t *x, int16_t *y)
{
uint8_t i = 0;
uint8_t base = 0;
uint8_t regaddr = 0x01;
- uint8_t buf[MAX_LEN_TOUCH_INFO];/*A maximum of two points are supported*/
+ uint8_t buf[MAX_LEN_TOUCH_INFO]; /*A maximum of two points are supported*/
- struct fts_ts_event events[FTS_MAX_POINTS_SUPPORT]; /* multi-touch */
+ struct fts_ts_event events[FTS_MAX_POINTS_SUPPORT]; /* multi-touch */
/*read touch information from reg0x01*/
tp_ft6x46_i2c_data_read(regaddr, buf, MAX_LEN_TOUCH_INFO);
memset(events, 0xFF, sizeof(struct fts_ts_event) * FTS_MAX_POINTS_SUPPORT);
- for (i = 0; i < MAX_POINTS_TOUCH_TRACE; i++)
+ for (i = 0; i < MAX_POINTS_TOUCH_TRACE; i++)
{
base = 2 + i * 6;
*x = events[i].x;
*y = events[i].y;
- PRINT("X : %d, y : %d \r\n",*x,*y);
+ PRINT("X : %d, y : %d \r\n", *x, *y);
}
}
-
void touch_getid(uint16_t *id)
{
ext_errno ret;
- uint8_t chip_id[2] = { 0 };
+ uint8_t chip_id[2] = {0};
/*get chip id*/
ret = tp_ft6x46_i2c_data_read(FTS_REG_CHIP_ID, &chip_id[0], 1);
- if (ret != EXT_ERR_SUCCESS) {
+ if (ret != EXT_ERR_SUCCESS)
+ {
PRINT("get ic information error1");
- } else {
+ }
+ else
+ {
ret = tp_ft6x46_i2c_data_read(FTS_REG_CHIP_ID2, &chip_id[1], 1);
- if (ret != EXT_ERR_SUCCESS) {
+ if (ret != EXT_ERR_SUCCESS)
+ {
PRINT("get ic information error2");
- } else
+ }
+ else
{
- PRINT("TOUCH CHIP ID = 0x%02x%02x \r\n", chip_id[0], chip_id[1]);
+ PRINT("TOUCH CHIP ID = 0x%02x%02x \r\n", chip_id[0], chip_id[1]);
*id = (chip_id[0] & 0XFF) << 8 | (chip_id[1] & 0XFF);
- //sprintf(id,"0x%02x%02x", chip_id[0], chip_id[1]);
+ // sprintf(id,"0x%02x%02x", chip_id[0], chip_id[1]);
}
}
}
{
int32_t state;
state = uapi_get_screen_state();
- PRINT("state : %d\r\n",state);
+ PRINT("state : %d\r\n", state);
}
#include "MMC5603.h"
MMC5603_GETID(id);
}
-void mmc5603_getdata(float *fAzimuth,float *fPitch,float *fRoll)
+void mmc5603_getdata(float *fAzimuth, float *fPitch, float *fRoll)
{
mmc5603_check();
*fAzimuth = mag_service_get_fAzimuth();
*fPitch = mag_service_get_fPitch();
*fRoll = mag_service_get_fRoll();
- PRINT("Azimuth : %f, fPitch : %f , fRoll : %f \r\n",*fAzimuth,*fPitch,*fRoll);
+ PRINT("Azimuth : %f, fPitch : %f , fRoll : %f \r\n", *fAzimuth, *fPitch, *fRoll);
}
-
#include "battery_hal.h"
void charge_getstate(void)
{
- if(get_charge_stat())
+ if (get_charge_stat())
PRINT("charging\r\n");
else
PRINT("uncharged\r\n");
battery_get_voltage(voltage);
}
-
#include "flash.h"
void flash_getid(uint32_t *id)
flash_info_t norflash_id;
uapi_flash_get_info(0, &norflash_id);
*id = norflash_id.flash_id;
- PRINT("flash_id : %X \r\n",*id);
+ PRINT("flash_id : %X \r\n", *id);
}
void flash_erase(void)
databuf[4] = (uint8_t)((t.z & 0xFF00) >> 8);
databuf[5] = (uint8_t)(t.z & 0x00FF);
- PRINT("x : %d, y : %d, z : %d \r\n",t.x,t.y,t.z);
- PRINT("GSENSOR: %2X %2X %2X %2X %2X %2X\r\n",databuf[0],databuf[1],databuf[2],databuf[3],databuf[4],databuf[5]);
-
+ PRINT("x : %d, y : %d, z : %d \r\n", t.x, t.y, t.z);
+ PRINT("GSENSOR: %2X %2X %2X %2X %2X %2X\r\n", databuf[0], databuf[1], databuf[2], databuf[3], databuf[4], databuf[5]);
}
void gsensor_get_single_data(gsenson_t *t)
get_gsonsen_xyz(t);
}
-
// 判断是否为闰年
-int isLeapYear(int year) {
+int isLeapYear(int year)
+{
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
// 计算某年某月的天数
-int daysInMonth(int year, int month) {
+int daysInMonth(int year, int month)
+{
const int days[12] = {31, 28 + isLeapYear(year), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
return days[month - 1];
}
// 计算时间距离1970年1月1日00:00:00的秒数
-uint32_t secondsSinceEpoch(int year,int month,int day,int hour,int min,int sec) {
+uint32_t secondsSinceEpoch(int year, int month, int day, int hour, int min, int sec)
+{
const int secondsPerMinute = 60;
const int secondsPerHour = 3600;
const int secondsPerDay = 86400;
long long seconds = 0;
// 计算年份之间的秒数
- for (int i = 1970; i < year; ++i) {
+ for (int i = 1970; i < year; ++i)
+ {
seconds += isLeapYear(i) ? secondsPerYear + secondsPerDay : secondsPerYear;
}
// 计算月份之间的秒数
- for (int i = 1; i < month; ++i) {
+ for (int i = 1; i < month; ++i)
+ {
seconds += daysInMonth(year, i) * secondsPerDay;
}
{
time_t rawtime;
- struct tm* timeinfo;
+ struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
*msc = secondsSinceEpoch(timeinfo->tm_year + 1900,
- timeinfo->tm_mon + 1,
- timeinfo->tm_mday,
- timeinfo->tm_hour,
- timeinfo->tm_min,
- timeinfo->tm_sec);
- PRINT("msc : %d \r\n",*msc);
+ timeinfo->tm_mon + 1,
+ timeinfo->tm_mday,
+ timeinfo->tm_hour,
+ timeinfo->tm_min,
+ timeinfo->tm_sec);
+ PRINT("msc : %d \r\n", *msc);
}
-//#include "lis2doc_reg.h"
+// #include "lis2doc_reg.h"
#include "stdio.h"
/**** 静态全局变量 ****/
-static int width = 200; //LCD X 分辨率
-static int height = 200; //LCD Y 分辨率
-static uint32_t *bmp_buf = NULL; //bmp_buf
-static unsigned long line_length; //LCD 一行的长度(字节为单位)
+static int width = 200; // LCD X 分辨率
+static int height = 200; // LCD Y 分辨率
+static uint32_t *bmp_buf = NULL; // bmp_buf
+static unsigned long line_length; // LCD 一行的长度(字节为单位)
/**** BMP 文件头数据结构 ****/
-typedef struct {
- unsigned char type[2]; //文件类型
- unsigned int size; //文件大小
- unsigned short reserved1; //保留字段 1
- unsigned short reserved2; //保留字段 2
- unsigned int offset; //到位图数据的偏移量
-} __attribute__ ((packed)) bmp_file_header;
+typedef struct
+{
+ unsigned char type[2]; // 文件类型
+ unsigned int size; // 文件大小
+ unsigned short reserved1; // 保留字段 1
+ unsigned short reserved2; // 保留字段 2
+ unsigned int offset; // 到位图数据的偏移量
+} __attribute__((packed)) bmp_file_header;
/**** 位图信息头数据结构 ****/
-typedef struct {
- unsigned int size; //位图信息头大小
- int width; //图像宽度
- int height; //图像高度
- unsigned short planes; //位面数
- unsigned short bpp; //像素深度
- unsigned int compression; //压缩方式
- unsigned int image_size; //图像大小
- int x_pels_per_meter; //像素/米
- int y_pels_per_meter; //像素/米
+typedef struct
+{
+ unsigned int size; // 位图信息头大小
+ int width; // 图像宽度
+ int height; // 图像高度
+ unsigned short planes; // 位面数
+ unsigned short bpp; // 像素深度
+ unsigned int compression; // 压缩方式
+ unsigned int image_size; // 图像大小
+ int x_pels_per_meter; // 像素/米
+ int y_pels_per_meter; // 像素/米
unsigned int clr_used;
unsigned int clr_omportant;
-} __attribute__ ((packed)) bmp_info_header;
+} __attribute__((packed)) bmp_info_header;
int set_bmp(void)
{
- unsigned short *line_buf = NULL; //行缓冲区
- unsigned long line_bytes; //BMP 图像一行的字节的大小
+ unsigned short *line_buf = NULL; // 行缓冲区
+ unsigned long line_bytes; // BMP 图像一行的字节的大小
unsigned int min_h, min_bytes;
const char *path = {"/system/1.bmp"};
/* 打开BMP 文件 */
FILE *fp = fopen(path, "r");
- if (fp == NULL) {
+ if (fp == NULL)
+ {
fclose(fp);
PRINT("file open failed !!!\r\n");
return -1;
}
PRINT("file open succ !!!\r\n");
/* 读取 BMP 文件头 */
- if (sizeof(bmp_file_header) != fread(&file_h, 1, sizeof(bmp_file_header),fp) )
+ if (sizeof(bmp_file_header) != fread(&file_h, 1, sizeof(bmp_file_header), fp))
{
PRINT(" read bmp_file_header failed !!!\r\n");
fclose(fp);
return -1;
}
PRINT("file read succ !!!\r\n");
- if (0 != memcmp(file_h.type, "BM", 2))
+ if (0 != memcmp(file_h.type, "BM", 2))
{
PRINT("it's not a BMP file !!!\r\n");
fclose(fp);
}
/* 读取位图信息头 */
- if (sizeof(bmp_info_header) != fread(&info_h, 1,sizeof(bmp_info_header),fp) )
+ if (sizeof(bmp_info_header) != fread(&info_h, 1, sizeof(bmp_info_header), fp))
{
PRINT("read bmp_info_header error !!!\r\n");
fclose(fp);
}
/* 打印信息 */
PRINT("文件大小: %d\n"
- "位图数据的偏移量: %d\n"
- "位图信息头大小: %d\n"
- "图像分辨率: %d*%d\n"
- "像素深度: %d\n", file_h.size, file_h.offset,
- info_h.size, info_h.width, info_h.height,
- info_h.bpp);
+ "位图数据的偏移量: %d\n"
+ "位图信息头大小: %d\n"
+ "图像分辨率: %d*%d\n"
+ "像素深度: %d\n",
+ file_h.size, file_h.offset,
+ info_h.size, info_h.width, info_h.height,
+ info_h.bpp);
/* 将文件读写位置移动到图像数据开始处 */
- if (-1 == fseek(fp, file_h.offset, SEEK_SET))
+ if (-1 == fseek(fp, file_h.offset, SEEK_SET))
{
PRINT("file lseek error !!!\r\n");
fclose(fp);
line_bytes = info_h.width * info_h.bpp / 8;
line_buf = malloc(line_bytes);
bmp_buf = malloc(file_h.size);
- if (NULL == line_buf)
+ if (NULL == line_buf)
{
fclose(fp);
return -1;
else
PRINT("malloc succ !!!\r\n");
-
if (line_length > line_bytes)
min_bytes = line_bytes;
else
min_bytes = line_length;
- if (0 < info_h.height)
- {//倒向位图
- if (info_h.height > height)
+ if (0 < info_h.height)
+ { // 倒向位图
+ if (info_h.height > height)
{
min_h = height;
fseek(fp, (info_h.height - height) * line_bytes, SEEK_CUR);
- bmp_buf += width * (height - 1); //定位到屏幕左下角位置
+ bmp_buf += width * (height - 1); // 定位到屏幕左下角位置
}
- else
+ else
{
min_h = info_h.height;
- bmp_buf += width * (info_h.height - 1);
+ bmp_buf += width * (info_h.height - 1);
}
- for (j = min_h; j > 0; bmp_buf -= width, j--)
+ for (j = min_h; j > 0; bmp_buf -= width, j--)
{
- fread( line_buf, 1, line_bytes ,fp); //读取出图像数据
- memcpy(bmp_buf, line_buf, min_bytes);//
+ fread(line_buf, 1, line_bytes, fp); // 读取出图像数据
+ memcpy(bmp_buf, line_buf, min_bytes); //
}
}
- else
- { //正向位图
- int temp = 0 - info_h.height; //负数转成正数
+ else
+ { // 正向位图
+ int temp = 0 - info_h.height; // 负数转成正数
if (temp > height)
min_h = height;
else
min_h = temp;
- for (j = 0; j < min_h; j++, bmp_buf += width)
+ for (j = 0; j < min_h; j++, bmp_buf += width)
{
- fread(line_buf, 1 ,line_bytes , fp);
+ fread(line_buf, 1, line_bytes, fp);
memcpy(bmp_buf, line_buf, min_bytes);
}
}
int size = strlen(bmp_buf);
- PRINT("bmp_buf size : %d\r\n",size);
+ PRINT("bmp_buf size : %d\r\n", size);
/* 关闭文件、函数返回 */
fclose(fp);
int enter_recovery(void)
{
- if(set_bmp() == -1)
+ if (set_bmp() == -1)
{
PRINT("set bmp failed !!! \r\n");
return -1;
}
return 1;
- //upg_reboot();
+ // upg_reboot();
}
#include "driver/calendar.h"
calendar_t date;
time_t rawtime;
- struct tm* timeinfo;
+ struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
date.year = timeinfo->tm_year + 1900;
date.sec = timeinfo->tm_sec;
errcode_t ret = uapi_calendar_set_datetime(&date);
- if (ret == ERRCODE_SUCC) {
+ if (ret == ERRCODE_SUCC)
+ {
printf("store datetime success: %d-%d-%d %d:%d:%d\r\n", date.year, date.mon, date.day, date.hour, date.min,
- date.sec);
+ date.sec);
return ERRCODE_SUCC;
}
printf("Set datetime failed, error code = %d \r\n", ret);
calendar_t date;
errcode_t ret = uapi_calendar_get_datetime(&date);
- if (ret == ERRCODE_SUCC) {
+ if (ret == ERRCODE_SUCC)
+ {
printf("Get datetime success: %d-%d-%d %d:%d:%d\r\n", date.year, date.mon, date.day, date.hour, date.min,
- date.sec);
-
- {//设置时间
- struct timeval tv = { 0 };
- struct tm _tm={0};
- _tm.tm_year = date.year -1900;
- _tm.tm_mon = date.mon -1;
+ date.sec);
+
+ { // 设置时间
+ struct timeval tv = {0};
+ struct tm _tm = {0};
+ _tm.tm_year = date.year - 1900;
+ _tm.tm_mon = date.mon - 1;
_tm.tm_mday = date.day;
_tm.tm_hour = date.hour;
_tm.tm_min = date.min;
tv.tv_usec = 0;
settimeofday(&tv, NULL);
}
-
+
return ERRCODE_SUCC;
}
printf("Get datetime failed, error code = %d \r\n", ret);
return ret;
}
-