每次需要开机检查系统的升级固件版本和当前的SD卡中的固件版本是否一致,固件名的开始是固定的字符串加上版本号。
#include <dirent.h>
#include <sys/types.h
static void *update_firmware(void *arg)
{
char acCurVersion[10] = {0};
char *pcFcName = NULL;
DIR *pdSdcard = NULL;
struct dirent *pstdSdcard = NULL;
struct stat stBuf;
while(!pdSdcard)
{
pdSdcard = opendir("/mnt/sdcard/");
if(NULL == pdSdcard)
{
printf("can't open dir:/mnt/sdcard\n");
}
usleep(500000);
}
chdir("/mnt/sdcard/");
while(NULL != (pstdSdcard = readdir(pdSdcard)))
{
if(strstr(pstdSdcard->d_name, "FIRMWARE"))
{
goto det_file;
}
}
printf("the sdcard hasn't the file of firmware\n");
closedir(pdSdcard);
return NULL;
det_file:
printf("detect firmware file:%s\n", pstdSdcard->d_name);
memcpy(acCurVersion, &pstdSdcard->d_name[4], 9);
acCurVersion[9] = '\0';
printf("current fc firmware version:%s\n", acCurVersion);
if(0 > strcmp(gcCurUavFcVersion, acCurVersion))
{
printf("need update firmware\n");
sdcard_update_firmware(pstdSdcard->d_name);
closedir(pdSdcard);
return NULL;
}
closedir(pdSdcard);
printf("current uav version is not need update\n");
return NULL;
}