-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
executable file
·105 lines (88 loc) · 2.26 KB
/
main.cpp
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
/**
* @author clark
* @email haixuanwo_clark@hotmail.com
* @date 2020-08-03
*/
#include "common_include.h"
#include "log.h"
#include "mqtt.h"
#include "tinyxml2.h"
#include "json.hpp"
#include "sqlite.h"
#include "Time.h"
#include "random_number.h"
#include <string.h>
int log_test()
{
char buf[] = {"fpx is rabish"};
while(1)
{
CLOG_INFO("cao ni daye [%d]:%s", 2025, buf);
sleep(1);
}
}
int mqtt_test()
{
char buf[] = {"cao l ni ma de ig"};
MqttAttr_S mqttAttr;
strcpy(mqttAttr.IP, "192.168.1.119");
mqttAttr.keepalive = 60;
mqttAttr.port = 1883;
mqttAttr.mid = 0;
mqttAttr.qos = 2;
snprintf(mqttAttr.pub_topic, sizeof(mqttAttr.pub_topic), "test/topic");
snprintf(mqttAttr.sub_topic, sizeof(mqttAttr.pub_topic), "test/topic");
CMqtt mqtt(mqttAttr);
mqtt.init_mqtt();
while(1)
{
mqtt.async_loop();
mqtt.push_data(buf, strlen(buf));
sleep(1);
}
}
void time_test()
{
CTime T;
int year = 0;
int mon = 0;
int day = 0;
int hour = 0;
int min = 0;
int second = 0;
while(1)
{
//CLOG_INFO("T --- now time [%d] secs\n", T.get_UTC_seconds());
//CLOG_INFO("T --- now time [%ld] nanosecs\n", T.get_UTC_nanoseconds()/1000000000);
//CLOG_INFO("T --- now time [%ld] usecs\n", T.get_UTC_useconds());
/*T.get_local_date(year, mon, day, hour, min, second);
CLOG_INFO("T --- local year[%d] mon[%d] day[%d] hour[%d] min[%d] second[%d]\n", year, mon, day, hour, min, second);
struct tm tmp;
memset(&tmp, 0, sizeof(tmp));
tmp.tm_year = year - 1900;
tmp.tm_mon = mon - 1;
tmp.tm_mday = day;
tmp.tm_hour = hour;
tmp.tm_min = min;
tmp.tm_sec = second;
CLOG_INFO("T --- TIME[%d] time[%d]\n", T.get_local_time_frome_date(&tmp), time(nullptr));*/
T.start();
sleep(1);
CLOG_INFO("T --- interval time[%ld]", T.stop());
}
}
void test_random()
{
CRand R;
while(1)
{
//CLOG_INFO("T --- rand num[%ld] RAND_MAX[%d]", R.get_rand_num(), RAND_MAX);
CLOG_INFO("T --- rand num [%d]", R.get_rand_num_from_range(10, 20));
sleep(1);
}
}
int main(int argc, char *argv[])
{
test_random();
return 0;
}