-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
120 lines (89 loc) · 2.59 KB
/
main.cpp
File metadata and controls
120 lines (89 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "include/HttpClient.h"
#include "include/upgrade.h"
#include "unistd.h"
#undef LOG_TAG
#define LOG_NDDBUG 0
#define LOG_TAG "upgrade"
#include <utils/Log.h>
void progress_callback(void *, double download_speed, double remaining_time, double progress_percentage)
{
//qDebug()<<download_speed<<remaining_time<<progress_percentage;
int hours = 0, minutes = 0, seconds = 0;
if (download_speed != 0)
{
hours = remaining_time / 3600;
minutes = (remaining_time - hours * 3600) / 60;
seconds = remaining_time - hours * 3600 - minutes * 60;
}
string unit = "B";
if (download_speed > 1024 * 1024 * 1024)
{
unit = "G";
download_speed /= 1024 * 1024 * 1024;
}
else if (download_speed > 1024 * 1024)
{
unit = "M";
download_speed /= 1024 * 1024;
}
else if (download_speed > 1024)
{
unit = "kB";
download_speed /= 1024;
}
char speedFormat[15] = { 0 };
char timeFormat[10] = { 0 };
char progressFormat[8] = { 0 };
#ifdef _WIN32
sprintf_s(speedFormat, sizeof(speedFormat), "%.2f%s/s", download_speed, unit.c_str());
sprintf_s(timeFormat, sizeof(timeFormat), "%02d:%02d:%02d", hours, minutes, seconds);
sprintf_s(progressFormat, sizeof(progressFormat), "%.2f", progress_percentage);
#else
sprintf(speedFormat, "%.2f%s/s", download_speed, unit.c_str());
sprintf(timeFormat, "%02d:%02d:%02d", hours, minutes, seconds);
sprintf(progressFormat, "%.2f", progress_percentage);
#endif
//AnyClass *eg = static_cast<AnyClass *>(userdata);
//eg->func(speedFormat, timeFormat, progressFormat);
printf("%s %s %s\n", speedFormat, timeFormat, progressFormat);
}
void demo_call_back(int ret)
{
ALOGI("demo upgrade result call back %d", ret);
if (ret == 1)
{
ALOGE("download ok");
upgrade();
}
else if (ret== 0)
{
ALOGE("demo download error ");
// exit(1);
}
// exit(1);
}
int main()
{
const char down_url[] = "http://192.168.1.100/test.zip";
uint32_t time = 0;
int status, flag;
int ret;
ALOGI("start test ");
while(1)
{
ret = upgrade_download((char *)down_url, -1, demo_call_back);
ALOGI("upgrade_download ret %d ", ret);
while(1)
{
upgrade_status_get(&status, &flag);
ALOGI("status %d, flag %d", status, flag );
sleep(3);
// break;
}
upgrade_download_cancel();
sleep(10);
}
while(1);
//upgrade_file((char*)local_uri);
return 0;
}