JL_700N_COLORSCREEN,获取Android手机系统时间

绪论:主要有两种获取方式,第一种是走SDK内部本身已有的传统HFP获取,但是这种获取方式在获取安卓系统时间时会出现兼容性问题,表现为:十台手机可能有八台无法正常获取,其二,走MAP配置文件可以同时获取安卓和IOS的系统时间。

第一步,先注册声明一个profile

第二步,声明及定义相关枚举

第三步,定义相关库函数

#if USER_SUPPORT_PROFILE_MAP
char *strtok(char *str, const char *delim) {
    static char *last;
    if (str == NULL)
        str = last;
    if (str == NULL)
        return NULL;
    char *p = str;
    while (*p != '\0' && strchr(delim, *p) == NULL)
        p++;
    if (*p == '\0') {
        last = NULL;
        return NULL;
    }
    *p = '\0';
    last = p + 1;
    return str;
}
void ios_ascill_to_data(u8 *data)
{
    u8 *year = strtok(data,"/");
    u8 *month = strtok(NULL,"/");
    u8 *day = strtok(NULL,",");
    u8 *hour = strtok(NULL,":");
    u8 *min = strtok(NULL,":");
    u8 *second = strtok(NULL,"\"");
    memset(&phone_time,0,sizeof(phone_time));
    printf("ios_ascill_to_data %s %s %s %s %s %s \n",year,month, day, hour, min, second);
    phone_time.years = 2000+10*(year[0]-'0')+(year[1]-'0');
    phone_time.months = 10*(month[0]-'0')+(month[1]-'0');
    phone_time.days = 10*(day[0]-'0')+(day[1]-'0');
    phone_time.hours = 10*(hour[1]-'0')+(hour[2]-'0');
    phone_time.min = 10*(min[0]-'0')+(min[1]-'0');
    phone_time.second = 10*(second[0]-'0')+(second[1]-'0');
    printf("ios_ascill_to_data %d %d %d %d %d %d \n",phone_time.years,phone_time.months, phone_time.days, phone_time.hours, phone_time.min, phone_time.second);
    //custom_time_sync(phone_time);
}
void android_ascill_to_data(u8 *data)
{
    memset(&phone_time,0,sizeof(phone_time));
    phone_time.years = 1000*(data[0]-'0')+100*(data[1]-'0')+10*(data[2]-'0')+(data[3]-'0');
    phone_time.months = 10*(data[4]-'0')+(data[5]-'0');
    phone_time.days = 10*(data[6]-'0')+(data[7]-'0');
    phone_time.hours = 10*(data[9]-'0')+(data[10]-'0');
    phone_time.min = 10*(data[11]-'0')+(data[12]-'0');
    phone_time.second = 10*(data[13]-'0')+(data[14]-'0');
    printf("android_ascill_to_data %d %d %d %d %d %d \n",phone_time.years,phone_time.months, phone_time.days, phone_time.hours, phone_time.min, phone_time.second);
    // custom_time_sync(phone_time);
    u8 offset = 0;
    u8 temp_year = (u8)phone_time.years - 2000;
    rcsp_log_debug("temp_year : %d",temp_year);

    if(phone_time.years != 0){

    memcpy(&time_info.time[offset++],&temp_year,__get_size(u8));
    memcpy(&time_info.time[offset++],&phone_time.months,__get_size(u8));
    memcpy(&time_info.time[offset++],&phone_time.days,__get_size(u8));
    memcpy(&time_info.time[offset++],&phone_time.hours,__get_size(u8));
    memcpy(&time_info.time[offset++],&phone_time.min,__get_size(u8));
    memcpy(&time_info.time[offset++],&phone_time.second,__get_size(u8));
    }

    offset %= __get_size(time_info.time);
    time_info.time_len = 0x6;

    for (u8 i = 0; i < 6; i++)
    {
        rcsp_log_debug("loki data : %d",time_info.time[i]);
    }
}
#define PROFILE_CMD_TRY_AGAIN_LATER    -1004

以及相关结构体

struct user_time {
    u16 years;
    u8 months;
    u8 days;
    u8 hours;
    u8 min;
    u8 second;
};

第四步,在BT建立连接时发送获取消息

最后,需要注意的是,2023/10月份之后的库都是支持获取的,如果库文件版本过低需要更换相关库文件才能够正常获取。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值