-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathfmav_generate_test_c_library.py
132 lines (101 loc) · 3.45 KB
/
fmav_generate_test_c_library.py
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
#!/usr/bin/env python
'''
The fastMavlink library
(c) OlliW, OlliW42, www.olliw.eu
Test Suite
'''
import os
import sys
import shutil
#mavlinkdialect = os.path.join('external','dialects','storm32.xml')
#mavlinkdialect = os.path.join('message_definitions','v1.0','ardupilotmega.xml')
mavlinkdialect = os.path.join('message_definitions','v1.0','all.xml')
'''
Paths and directories and file names
'''
pymavlink_pathtorepository = os.path.join('..','..','mavlink')
pymavlink_outputdirectory = 'pymavlink_c_library_v2'
'''
Helper
'''
xmlfile = os.path.abspath(os.path.join(pymavlink_pathtorepository, mavlinkdialect))
test_outputdirectory = 'test_c_library'
fastmavlink_pathtorepository = os.path.abspath(os.path.join(pymavlink_pathtorepository,'..','fastmavlink'))
fastmavlink_outputdirectory = 'c_library'
'''
Generate Pymavlink-Mavgen C library
'''
def generatePymavlinkCLibrary():
print('----------')
print('Generate pymavlink-mavgen C library')
# import generator
sys.path.insert(0,pymavlink_pathtorepository)
from pymavlink.generator import mavgen
from pymavlink.generator import mavparse
#recreate out directory
print('----------')
print('kill dir', pymavlink_outputdirectory)
try:
shutil.rmtree(pymavlink_outputdirectory)
except:
pass
os.mkdir(pymavlink_outputdirectory)
#generate pymavlink-mavgen C library
print('----------')
opts = mavgen.Opts(pymavlink_outputdirectory,
wire_protocol=mavparse.PROTOCOL_2_0,
language='C',
validate=mavgen.DEFAULT_VALIDATE,
error_limit=5,
strict_units=mavgen.DEFAULT_STRICT_UNITS)
try:
mavgen.mavgen(opts,[xmlfile])
print('Successfully Generated Headers', 'Headers generated successfully.')
except Exception as ex:
exStr = str(ex)
print('Error Generating Headers','{0!s}'.format(exStr))
exit()
print('----------')
'''
Generate fastMavlink C library
'''
def generateFastMavlinkCLibrary():
print('----------')
print('Generate fastmavlink C library')
# import generator
sys.path.insert(0,fastmavlink_pathtorepository)
from generator import fmav_gen as mavgen
from generator.modules import fmav_flags as mavflags
#recreate out directory
print('----------')
print('kill dir', fastmavlink_outputdirectory)
try:
shutil.rmtree(fastmavlink_outputdirectory)
except:
pass
os.mkdir(fastmavlink_outputdirectory)
#generate fastmavlink C library
print('----------')
opts = mavgen.Opts(fastmavlink_outputdirectory, parse_flags=mavflags.PARSE_FLAGS_WARNING_ENUM_VALUE_MISSING)
try:
mavgen.fmavgen(opts,[xmlfile])
print('Successfully Generated Headers', 'Headers generated successfully.')
except Exception as ex:
exStr = str(ex)
print('Error Generating Headers','{0!s}'.format(exStr))
exit()
print('----------')
'''
Generate fastMavlink Test C library
'''
def generateFastMavlinkTestCLibrary():
print('----------')
print('Generate fastMavlink Test C library')
sys.path.insert(0,fastmavlink_pathtorepository)
from tests.generator_tests import fmav_gen_tests as run_tests
print('----------')
run_tests.generate_test_c_library(os.path.abspath(test_outputdirectory), [xmlfile])
print('----------')
generatePymavlinkCLibrary()
generateFastMavlinkCLibrary()
generateFastMavlinkTestCLibrary()