Skip to content

Commit fa110de

Browse files
Merge pull request #2 from MasterYuan418/dev
Complement files [1.0.7]
2 parents de11579 + b65b37d commit fa110de

File tree

6 files changed

+583
-0
lines changed

6 files changed

+583
-0
lines changed

depends/test_build.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <iostream>
2+
#include <windows>
3+
#include <string>
4+
5+
using namespace std;
6+
7+
int main()
8+
{
9+
string projectPath;
10+
cout << "Input project path(.vsxproj where)"
11+
cin >> projectPath;
12+
string head = "msbuild ";
13+
string foot = " /p:Configuration=""release""";
14+
c.append(head);
15+
c.append(projectPath);
16+
c.append(foot);
17+
system(c);
18+
}

proto.h

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#ifndef _PROTO_H__
2+
#define _PROTO_H__
3+
4+
5+
#define PACKED __attribute__((__packed__))
6+
#define AWLINK_MAGIC 0xFA
7+
8+
#define AWLINK_IDSRC_MASTER 0
9+
#define AWLINK_IDSRC_CLIENT 1
10+
11+
#define AWLINK_PARSE_STEP_MAGIC 1
12+
#define AWLINK_PARSE_STEP_LENGTH 2
13+
#define AWLINK_PARSE_STEP_ID_SRC 3
14+
#define AWLINK_PARSE_STEP_I_ID 4
15+
#define AWLINK_PARSE_STEP_SI_ID 5
16+
#define AWLINK_PARSE_STEP_DATA 6
17+
#define AWLINK_PARSE_STEP_CHECKSUM1 7
18+
#define AWLINK_PARSE_STEP_CHECKSUM2 8
19+
#define AWLINK_PARSE_STEP_OK 9
20+
#define AWLINK_PARSE_STEP_FAIL 10
21+
22+
#define AWLINK_ITEM_SYSTEM 0
23+
#define AWLINK_ITEM_STATUS 1
24+
#define AWLINK_ITEM_CONTROL 2
25+
#define AWLINK_ITEM_MISSION 3
26+
#define AWLINK_ITEM_PARAM 4
27+
#define AWLINK_ITEM_LOG 5
28+
#define AWLINK_ITEM_FILE 6
29+
30+
#define AWLINK_ITEM_SYSTEM_ACK 0
31+
#define AWLINK_ITEM_SYSTEM_AWLINK_VER 1
32+
#define AWLINK_ITEM_SYSTEM_AWPILOT_VER 2
33+
#define AWLINK_ITEM_SYSTEM_HEART 3
34+
#define AWLINK_ITEM_SYSTEM_MSG 4
35+
36+
37+
#define AWLINK_ITEM_STATUS_BASIC_INFO 0
38+
#define AWLINK_ITEM_STATUS_MISSION_INFO 1
39+
#define AWLINK_ITEM_STATUS_GPS_INFO 2
40+
#define AWLINK_ITEM_STATUS_SENSOR_INFO 3
41+
#define AWLINK_ITEM_STATUS_SENSOR_CALIB_INFO 4
42+
#define AWLINK_ITEM_STATUS_USER1_INFO 5
43+
44+
45+
#define AWLINK_ITEM_CONTROL_JOYSTICK 0
46+
#define AWLINK_ITEM_CONTROL_STATUS_RATE 1
47+
#define AWLINK_ITEM_CONTROL_CALIBRATE 2
48+
#define AWLINK_ITEM_CONTROL_MODE 3
49+
#define AWLINK_ITEM_CONTROL_ARUCO_DIST 11
50+
51+
typedef struct {
52+
uint8_t heart;
53+
}awlink_system_heart_s;
54+
55+
56+
typedef struct {
57+
uint8_t ack;
58+
uint8_t item_id;
59+
uint8_t subitem_id;
60+
}awlink_system_ack_s;
61+
62+
typedef struct{
63+
float att[3];
64+
float vel_ned[3];
65+
float pos_ned[3];
66+
uint8_t status;
67+
uint8_t mode;
68+
uint8_t capacity;
69+
uint8_t voltage;
70+
bool charge;
71+
bool headfree;
72+
bool armed;
73+
}awlink_status_base_info_s;
74+
75+
76+
typedef struct {
77+
uint8_t magic;
78+
uint8_t length;
79+
uint8_t id_src;
80+
uint8_t item_id;
81+
uint8_t subitem_id;
82+
uint8_t *data;
83+
uint16_t checksum;
84+
85+
}awlink_msg_s;
86+
87+
typedef struct {
88+
uint8_t type;
89+
uint16_t awlink_parse_error;
90+
uint8_t awlink_parse_step;
91+
uint8_t awlink_parse_data_count;
92+
uint16_t awlink_parse_checksum;
93+
awlink_msg_s awlink_package;
94+
95+
}awlink_decode_s;
96+
97+
enum cmd {
98+
CMD_SAFE_MODE = 83,
99+
CMD_WING_PROTECTION,
100+
CMD_CONTROL_YAW,
101+
CMD_CONTROL_ALT,
102+
CMD_IMG_LOAD,
103+
CMD_TOF_ALTHOLD,//88
104+
CMD_TAKEOFF_ALT,
105+
CMD_INFRARED_SHOOTING,
106+
};
107+
108+
enum action_cmd {
109+
CMD_ACC = 0, //校准
110+
CMD_TAKEOFF, //起飞
111+
CMD_LAND, //降落
112+
CMD_FORWARD_TURN, //前翻
113+
CMD_BACK_TURN, //后翻
114+
CMD_LEFT_TURN, //左翻
115+
CMD_RIGHT_TURN, //右翻
116+
CMD_UP, //上升
117+
CMD_DOWN, //下降
118+
CMD_LEFT, //向左
119+
CMD_RIGHT, //向右
120+
CMD_FORWARD, //向前
121+
CMD_BACK, //向后
122+
CMD_LEFT_YAW, //左旋
123+
CMD_RIGHT_YAW, //右旋
124+
CMD_TAKE_PHOTO, //拍照
125+
CMD_TOF_ALT, //定高
126+
CMD_TAKEOFF_ALTH, //起飞高度
127+
CMD_MODE_CHANGE, //模式切换
128+
CMD_SHOOT, //射击
129+
CMD_ARUCO,
130+
};
131+
132+
133+
134+
void recv_udp(int fd);
135+
uint8_t batt_get_cap();
136+
137+
#endif

tcp_client.cpp

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#include "tcp_client.h"
2+
#include "ftp_client.h"
3+
#include "cJSON.h"
4+
#include "proto.h"
5+
SOCKET sclient;
6+
7+
int tcp_client_init()
8+
{
9+
10+
WORD socketVersion = MAKEWORD(2,2);
11+
WSADATA wsaData;
12+
if(WSAStartup(socketVersion, &wsaData) != 0)
13+
{
14+
return 0;
15+
}
16+
17+
sockaddr_in serAddr;
18+
serAddr.sin_family = AF_INET;
19+
serAddr.sin_port = htons(4646);
20+
inet_pton(AF_INET, "192.168.100.1", &serAddr.sin_addr);
21+
22+
// serAddr.sin_addr.s_addr=inet_addr("192.168.100.1");
23+
cout<<"等待无线连接...."<<endl;
24+
sclient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
25+
if (sclient == INVALID_SOCKET){
26+
printf("invalid socket!");
27+
return 0;
28+
}
29+
30+
if (connect(sclient, (sockaddr *)&serAddr, sizeof(serAddr)) == SOCKET_ERROR)
31+
{ //连接失败
32+
printf("无线未连接 !\n");
33+
closesocket(sclient);
34+
return 0;
35+
}
36+
cout<<"无线连接成功"<<endl;
37+
ftp_init();
38+
return 0;
39+
}
40+
41+
int tcp_send(int cmd,int val)
42+
{
43+
char *out=NULL;
44+
int ret;
45+
cJSON *root = NULL;
46+
cJSON *param=NULL;
47+
cJSON *item = NULL;
48+
cJSON *found = NULL;
49+
cJSON *vel=NULL;
50+
switch(cmd)
51+
{
52+
case CMD_IMG_LOAD:
53+
root = cJSON_CreateObject();
54+
cJSON_AddNumberToObject(root, "CMD", CMD_IMG_LOAD);
55+
cJSON_AddItemToObject(root, "PARAM", param = cJSON_CreateObject());
56+
cJSON_AddNumberToObject(param,"num",1);
57+
cJSON_AddNumberToObject(param,"delay",0);
58+
out = cJSON_Print(root);
59+
//char *p="{\"CMD\":87,\"PARAM\":{\"num\":1,\"delay\":0}}";
60+
// printf("out:%s\n",out);
61+
cJSON_Delete(root);
62+
break;
63+
case CMD_SAFE_MODE:
64+
root = cJSON_CreateObject();
65+
cJSON_AddNumberToObject(root, "CMD", CMD_SAFE_MODE);
66+
cJSON_AddNumberToObject(root, "PARAM", 1);
67+
out = cJSON_Print(root);
68+
cJSON_Delete(root);
69+
break;
70+
case CMD_TAKEOFF_ALT:
71+
root = cJSON_CreateObject();
72+
cJSON_AddNumberToObject(root, "CMD", CMD_TAKEOFF_ALT);
73+
cJSON_AddNumberToObject(root, "PARAM", val);
74+
out = cJSON_Print(root);
75+
cJSON_Delete(root);
76+
break;
77+
case CMD_INFRARED_SHOOTING:
78+
root = cJSON_CreateObject();
79+
cJSON_AddNumberToObject(root, "CMD", CMD_INFRARED_SHOOTING);
80+
cJSON_AddNumberToObject(root, "PARAM", 0);
81+
out = cJSON_Print(root);
82+
cJSON_Delete(root);
83+
break;
84+
default:
85+
cout<<"命令错误"<<endl;
86+
}
87+
ret=send(sclient, out, strlen(out), 0);
88+
if(ret < 0){
89+
cout<<"命令发送失败"<<endl;
90+
return -1;
91+
}
92+
char recData[255];
93+
ret = recv(sclient, recData, 255, 0);
94+
if (ret > 0) {
95+
recData[ret] = 0x00;
96+
switch(cmd)
97+
{
98+
case CMD_IMG_LOAD:
99+
item =cJSON_Parse(recData);
100+
found=cJSON_GetObjectItem(item, "PARAM");
101+
vel=cJSON_GetObjectItem(found,"photo");
102+
ftp_main(vel->valuestring);
103+
cJSON_Delete(item);
104+
break;
105+
}
106+
}
107+
cout<<"设置完成"<<endl;
108+
return 0;
109+
110+
}
111+
void tcp_quit()
112+
{
113+
closesocket(sclient);
114+
ftp_quit();
115+
WSACleanup();
116+
}
117+
118+
119+

tcp_client.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef _TCP_H__
2+
#define _TCP_H__
3+
4+
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#include <winsock2.h>
8+
#include <string.h>
9+
//#include <unistd.h>
10+
#include <iostream>
11+
#include <pthread.h>
12+
#include "crc.h"
13+
#include "cJSON.h"
14+
#include "ftp_client.h"
15+
#include <ws2tcpip.h>
16+
#include<iostream>
17+
#include<cstring>
18+
19+
#pragma comment(lib,"ws2_32.lib")
20+
using namespace std;
21+
22+
int tcp_client_init();
23+
void tcp_quit();
24+
int tcp_send(int cmd,int vel);
25+
#endif

udp.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef _UDP_H__
2+
#define _UDP_H__
3+
4+
//int main_control();
5+
int action_cmd(int id, int val=0,int time=0);
6+
void aruco_cmd(int action, int id, int roll=0, int pitch=0, int yaw=0);
7+
bool get_control_mode();
8+
void set_control_mode();
9+
bool get_aruco_ok();
10+
void set_aruco_ok();
11+
#endif
12+

0 commit comments

Comments
 (0)