Skip to content

Commit

Permalink
add function to download PDF version of release note
Browse files Browse the repository at this point in the history
Signed-off-by: Clark Wang <[email protected]>
  • Loading branch information
wangxiaoningnxp committed Jul 16, 2020
1 parent c5a09f3 commit a7565ba
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
31 changes: 20 additions & 11 deletions bcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,37 @@ int compareVersion(const char *v1, const char *v2)
return 0;
}

static void upgrade_bcu()
static void upgrade_bcu(struct options_setting* setting)
{
printf("now version %s\n", GIT_VERSION);

char version[15];
struct latest_git_info bcu_download_info;
strcpy(bcu_download_info.download_url_base, "https://github.com/NXPmicro/bcu/releases/download/");
strcpy(bcu_download_info.download_name, "bcu");
#ifdef linux
strcpy(bcu_download_info.extension_name, "");
#else
strcpy(bcu_download_info.extension_name, ".exe");
#endif

if (https_get_by_url("https://api.github.com/repos/NXPmicro/bcu/releases", &bcu_download_info))
{
printf("Fail to get the latest BCU!\n");
return;
}
https_response_parse(&bcu_download_info);

strncpy(version, GIT_VERSION, 11);
if (setting->download_doc)
{
strcpy(bcu_download_info.download_name, "BCU");
strcpy(bcu_download_info.extension_name, ".pdf");
https_download(&bcu_download_info);
return;
}

strcpy(bcu_download_info.download_name, "bcu");
#ifdef linux
strcpy(bcu_download_info.extension_name, "");
#else
strcpy(bcu_download_info.extension_name, ".exe");
#endif

strncpy(version, GIT_VERSION, 11);
if (compareVersion(&bcu_download_info.tag_name[4], &GIT_VERSION[4]) > 0)
{
printf("\nRelease Note for %s:\n%s\n\n", bcu_download_info.tag_name, bcu_download_info.release_note);
Expand Down Expand Up @@ -208,8 +217,8 @@ static void print_help(char* cmd)
printf(" %s%-50s%s%s\n", g_vt_default, "lsbootmode [-board=]", g_vt_green, "show a list of available boot mode of a board");
printf(" %s%-50s%s%s\n", g_vt_default, "lsgpio [-board=]", g_vt_green, "show a list of available gpio pin of a board");
printf("\n");
printf(" %s%-50s%s%s%s\n", g_vt_default, "version", g_vt_green, "print version number", g_vt_default);
printf(" %s%-50s%s%s%s\n", g_vt_default, "upgrade", g_vt_green, "get the latest BCU release", g_vt_default);
printf(" %s%-50s%s%s\n", g_vt_default, "version", g_vt_green, "print version number");
printf(" %s%-50s%s%s\n", g_vt_default, "upgrade [-doc]", g_vt_green, "get the latest BCU release");
printf(" %s%-50s%s%s%s\n", g_vt_default, "help", g_vt_green, "show command details", g_vt_default);
// printf(" %s%-50s%s%s%s\n", g_vt_default, "help [COMMAND_NAME]", g_vt_green, "show details and options of COMMAND_NAME", g_vt_default);

Expand Down Expand Up @@ -2253,7 +2262,7 @@ int main(int argc, char** argv)
}
else if (strcmp(cmd, "upgrade") == 0)
{
upgrade_bcu();
upgrade_bcu(&setting);
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions bcu_https.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,16 @@ void https_response_parse(struct latest_git_info* get_info)
str_replace(get_info->release_note, "\\r\\n", "\r\n");
str_replace(get_info->release_note, "\\t", "\t");

}

void https_download(struct latest_git_info* get_info)
{
strcpy(get_info->download_url, get_info->download_url_base);
strcat(get_info->download_url, get_info->tag_name);
strcat(get_info->download_url, "/");
strcat(get_info->download_url, get_info->download_name);
strcat(get_info->download_url, get_info->extension_name);

}

void https_download(struct latest_git_info* get_info)
{
printf("Downloading %s%s from %s\n", get_info->tag_name,
get_info->extension_name, get_info->download_url);
if(_download(get_info->download_url, get_info->tag_name, get_info->extension_name))
Expand Down
5 changes: 5 additions & 0 deletions bcu_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ void set_options_default(struct options_setting* setting)
setting->rangefixed = 0;
setting->use_hwfilter = 0;
setting->use_bipolar = 1;
setting->download_doc = 0;
}


Expand Down Expand Up @@ -417,6 +418,10 @@ int parse_options(int argc, char** argv, struct options_setting* setting)
{
setting->use_bipolar = 0;
}
else if (strcmp(argv[i], "-doc") == 0)
{
setting->download_doc = 1;
}
else if (strncmp(argv[i], "-board=", 7) == 0 && strlen(argv[i]) > 7)
{
//do nothing
Expand Down
1 change: 1 addition & 0 deletions bcu_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct options_setting {
int rangefixed;
int use_hwfilter;
int use_bipolar;
int download_doc;
char groups[MAX_NUMBER_OF_POWER * MAX_MAPPING_NAME_LENGTH];
};

Expand Down

0 comments on commit a7565ba

Please sign in to comment.