tracer.cxx
7.8 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include <string>
#include <thread>
#include <sys/time.h>
#include "uav_core.h"
#include "uav_logger.h"
#include "uav_upgrade.h"
#include "uav_platform.h"
#include "uav_data_type.h"
#include "uav_sdk_app_info.h"
#include "uav_fc_subscription.h"
#include "uav_low_speed_data_channel.h"
#include "uav_high_speed_data_channel.h"
#include "proto/tracerMessage.pb.h"
void tracerThreadFunc(void);
int main(int argc, char *argv[])
{
T_AUserInfo usrInfo;
logger_init(std::string(argv[1]));
if(false == uav_sdk_app_info_init(&usrInfo)) {
LOG_ERROR("uav_sdk_app_info_init failed");
return -1;
}
UAV_Core_Init(&usrInfo);
UAV_Core_SetAlias("tracerV1");
UAV_Network_Init(LOCALHOST_ETHERNET);
// UAV_Uart_Init("/dev/pts/20",115200);
std::thread tracerThread(tracerThreadFunc);
tracerThread.detach();
return UAV_Core_ApplicationStart();
}
/******************************************************************USR Example Code***********************************************************************/
static void myPositionFusedMsgCB(void *data)
{
T_UAVSubscriptionPositionFused *posSt = (T_UAVSubscriptionPositionFused*)data;
LOG_INFO("longitude:{}, latitude:{}, altitude:{}, visibleSatelliteNumber:{}", posSt->longitude, posSt->latitude, posSt->altitude, posSt->visibleSatelliteNumber);
}
static void myPositionGpsMsgCB(void *data)
{
T_UAVSubscriptionGpsPosition *posSt = (T_UAVSubscriptionGpsPosition*)data;
LOG_INFO("longitude:{}, latitude:{}, altitude:{}, visibleSatelliteNumber:{}", posSt->x, posSt->y, posSt->z);
}
static void myEulerAngularVelocityMsgCB(void *data)
{
T_UAVSubscriptionAngularRateRaw *eulerSt = (T_UAVSubscriptionAngularRateRaw*)data;
LOG_INFO("wroll:{}, wpitch:{}, wyaw:{}", eulerSt->x, eulerSt->y, eulerSt->z);
}
static void myVelocityComponentMsgCB(void *data)
{
T_UAVSubscriptionGpsVelocity *velCompSt = (T_UAVSubscriptionGpsVelocity*)data;
LOG_INFO("vX:{}, vY:{}, vZ:{}", velCompSt->x, velCompSt->y, velCompSt->z);
}
static void myEulerAngularMsgCB(void *data)
{
T_UAVSubscriptionEulerAngular *eulerSt = (T_UAVSubscriptionEulerAngular*)data;
LOG_INFO("roll:{}, pitch:{}, yaw:{}", eulerSt->roll, eulerSt->pitch, eulerSt->yaw);
}
//channel callback
static void myWorkModeControlCallback(int32_t srcChannelID, int data_type, const uint8_t *data, uint32_t len)
{
std::string str;
autel::protocol::TracerWorkModeControlMessage reqMsg;
LOG_INFO("myChannelRecvDataCallback from srcChannelID:{}", int(srcChannelID));
if(!reqMsg.ParseFromArray(data, len)){
LOG_ERROR("parseMsg TracerWorkModeControlMessage failed");
return;
}
LOG_INFO("seq:{}, workMode:{}, dxNum:{}, dxFreq:{}", reqMsg.seq(), reqMsg.workmode(), reqMsg.dxnum(), reqMsg.dxfreq());
//response
autel::protocol::TracerWorkModeControlRspMessage rspMsg;
rspMsg.set_seq(reqMsg.seq());
rspMsg.set_rlt(0);
rspMsg.SerializeToString(&str);
UAV_LowSpeedDataChannel_SendData(srcChannelID, PAYLOAD_TRACER_WORKMODE_CONTROL, (const uint8_t *)str.c_str(), str.size()); //ack
}
static bool getModuleInfo(T_ModuleInfo &info)
{
info.model = "tracer";
info.app_version = "V1.0.0";
info.boot_version = "V1.0.0";
info.hard_version = "V1.0.0";
LOG_INFO("getModuleInfo");
return true;
}
static bool upgradeConditionCheck(void)
{
LOG_INFO("upgradeConditionCheck");
return true;
}
static int upgradeExcute(bool force, const std::string &model, const std::string &filename)
{
LOG_INFO("force: {}, model: {}, filename: {}", force, model.c_str(), filename.c_str());
return 10;
}
static bool upgradeQuery(T_UAVUpgradeStatus &status)
{
status.state = 1;
status.progress = 10;
status.error_code = 0;
status.module = "tracer";
return true;
}
static T_UAVUpgradeHandler g_uavUpgradeHandler = {
.getModuleInfo = getModuleInfo,
.upgradeConditionCheck = upgradeConditionCheck,
.upgradeExcute = upgradeExcute,
.upgradeQuery = upgradeQuery,
};
void tracerThreadFunc(void)
{
std::string str;
T_UAVFileDesc desc;
std::string model("tracer");
//升级初始化
UAV_Upgrade_Init(&g_uavUpgradeHandler);
//创建低速数据通道回调
UAV_LowSpeedDataChannel_Init();
UAV_LowSpeedDataChannel_RegRecvDataCallback(myWorkModeControlCallback);
// UAV_LowSpeedDataChannel_RegRecvDataCallback(myWorkModeControlCallback);
//wait register success
if(false == wait_register_ready(100)){
LOG_ERROR("waitHandShakeRegister failed");
return;
}
LOG_INFO("start tracerThreadFunc");
//升级固件下载
if(true == UAV_Upgrade_Firmware_Download(model, desc))
{
int64_t read_len = 0;
std::vector<uint8_t> data;
int64_t file_size = desc.file_size;
LOG_INFO("file name: {}, size: {}, package size: {}", desc.file_name, desc.file_size, desc.package_size);
while(file_size > 0)
{
UAV_Upgrade_Firmware_Request(read_len, desc.package_size, 200, data);
read_len += data.size();
file_size -= data.size();
LOG_INFO("download data size: {}", data.size());
}
UAV_Upgrade_Firmware_Verify(DIGEST_TYPE_CRC32, "12345678", 50);
UAV_Upgrade_Firmware_Finish("seccuss", 50);
}
//订阅飞机GPS位置信息
UAV_SubscribeTopic(UAV_SUBSCRIPTION_TOPIC_GPS_POSITION, 0, myPositionGpsMsgCB);
//订阅飞机位置信息
UAV_SubscribeTopic(UAV_SUBSCRIPTION_TOPIC_POSITION_FUSED, 0, myPositionFusedMsgCB);
// 订阅飞机欧拉角速度信息
UAV_SubscribeTopic(UAV_SUBSCRIPTION_TOPIC_ANGULAR_RATE_RAW, 0, myEulerAngularVelocityMsgCB);
// 订阅飞机速度分量信息
UAV_SubscribeTopic(UAV_SUBSCRIPTION_TOPIC_GPS_VELOCITY, 0, myVelocityComponentMsgCB);
// 订阅飞机姿态欧拉角信息
UAV_SubscribeTopic(UAV_SUBSCRIPTION_TOPIC_EULER_ANGULAR_INFO, 0, myEulerAngularMsgCB);
while(1){
sleep(1);
//1-发布检测结果
autel::protocol::tracerMeasureInfoMessage tracerMeasureInfoMsg;
tracerMeasureInfoMsg.set_workstatus(1);
tracerMeasureInfoMsg.set_tarnum(3);
for(int i = 0 ; i < 3 ; i ++){
autel::protocol::singleTargetInfo *info = tracerMeasureInfoMsg.add_tarinfo();
info->set_tnum(1);
info->set_tfreq(2);
info->set_tamp(3);
info->set_tmfw(4);
info->set_tmfy(5);
info->set_tffw(6);
info->set_tffy(7);
}
tracerMeasureInfoMsg.SerializeToString(&str);
UAV_LowSpeedDataChannel_SendData(UAV_CHANNEL_ADDRESS_MASTER_RC_APP, PAYLOAD_TRACER_MEASURE_INFO, (const uint8_t *)str.c_str(), str.size());
sleep(1);
//2-发布错频信息
autel::protocol::TracerStaggerFreqMessage TracerStaggerFreqMsg;
TracerStaggerFreqMsg.set_seq(101);
TracerStaggerFreqMsg.set_freqband(102);
TracerStaggerFreqMsg.set_timstamp(103);
TracerStaggerFreqMsg.set_reserv(104);
TracerStaggerFreqMsg.SerializeToString(&str);
UAV_LowSpeedDataChannel_SendData(UAV_CHANNEL_ADDRESS_MASTER_RC_APP, PAYLOAD_TRACER_STAGGER_FREQ, (const uint8_t *)str.c_str(), str.size());
sleep(1);
//3-发布系统状态信息
autel::protocol::TracerSystemInfoMessage TracerSystemInfoMsg;
TracerSystemInfoMsg.set_workstatus(12);
TracerSystemInfoMsg.set_faultstatus(13);
TracerSystemInfoMsg.set_netstatus(14);
TracerSystemInfoMsg.set_ssid("unknow");
TracerSystemInfoMsg.set_ipaddress("192.168.1.111");
TracerSystemInfoMsg.SerializeToString(&str);
UavHighSpeedDataChannel_SendDataStreamData(5, (const uint8_t *)str.c_str(), str.size());
UAV_LowSpeedDataChannel_SendData(UAV_CHANNEL_ADDRESS_MASTER_RC_APP, PAYLOAD_TRACER_SYSTEM_INFO, (const uint8_t *)str.c_str(), str.size());
}
}