⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updateprogram.c

📁 通过车载终端采集GPS数据
💻 C
字号:
#include "typedef.h"
#include "updateprogram.h"
#include "global.h"
#include "nvram.h"
#include "mcuInit.h"
#include "common_function.h"
UPDATE_PROGTIME g_updatetime;
Uchar g_timecount = 2;
Uchar g_startReset = 0;
/***********************************
*pTime:需要更新的时间,这里采用压缩BCD进行编码,
************************************/
void write_updatetime(Uchar *pTime)
{
    g_updatetime.valid = UPDATE_VALID;
    g_updatetime.year = bcd2bin(pTime[0]);
    g_updatetime.mon = bcd2bin(pTime[1]);
    g_updatetime.day = bcd2bin(pTime[2]);
    g_updatetime.hour = bcd2bin(pTime[3]);
    g_updatetime.min = bcd2bin(pTime[4]);
    g_updatetime.sec = bcd2bin(pTime[5]);
    nvram_write(NVRAM_UPDATE_TIME, &g_updatetime);
}

/********************************
*初始化更新时间,在主机启动后初始化调用
**********************************/
void init_updatetime()
{
    nvram_read(NVRAM_UPDATE_TIME, &g_updatetime);
}

extern xdata SYSTEM_INFO systemInfo;
void start_updatehost()
{
    g_updatetime.valid = UPDATE_INVALID;
    nvram_write(NVRAM_UPDATE_TIME, &g_updatetime);
    //生成通知包
 //   encapsulate_hostreset();
    g_startReset = 1;
}
/********************************
*判断是否需要更新的进程,目前准备3秒测试一次
********************************/
void process_updateprog()
{
    if (g_startReset > 0)
    {
        switch_ld_ap();
    }
    if (UPDATE_VALID == g_updatetime.valid)
    {
        if (0 == g_timecount)
        {
            g_timecount = 2;
            if (systemInfo.year > g_updatetime.year)
            {
                //开始更新
                start_updatehost();
            }
            else if (systemInfo.year == g_updatetime.year)
            {
                if (systemInfo.mon > g_updatetime.mon)
                {
                    start_updatehost();
                }
                else if (systemInfo.mon == g_updatetime.mon)
                {
                    if (systemInfo.day > g_updatetime.day)
                    {
                        start_updatehost();
                    }
                    else if (systemInfo.day == g_updatetime.day)
                    {
                        if (systemInfo.hour > g_updatetime.hour)
                        {
                            start_updatehost();
                        }
                        else if (systemInfo.hour == g_updatetime.hour)  
                        {
                            if (systemInfo.min > g_updatetime.min)
                            {
                                start_updatehost();
                            }
                            else if (systemInfo.min == g_updatetime.min)
                            {
                                if (systemInfo.sec >= g_updatetime.sec)
                                    start_updatehost();
                            }
                        }
                    }
                }
            }
        }
        else
            g_timecount--;
    }
    else
        g_startReset = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -