-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheml_structs_templates.py
127 lines (95 loc) · 2.77 KB
/
eml_structs_templates.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
## This file is part of conftron.
##
## Copyright (C) 2011 Matt Peddie <[email protected]>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
############ LCM ###############
eml_lcm_send_template = """\
function %(classname)s_lcm_send_%(type)s( %(type)s_in_ ) %%#eml
%(type)s_ = %(classname)s_%(type)s( %(type)s_in_, [1,1] );
eml.ceval('emlc_lcm_send_%(type)s', eml.rref(%(type)s_));
end
"""
eml_lcm_send_dummy_template = """\
function %(classname)s_lcm_send_%(type)s( %(type)s_in_ ) %%#eml
%% dummy file to keep simulink from choking
end
"""
############# STRUCTS #################
eml_constructor_template = ["""\
function %(type)s_out_ = %(classname)s_%(type)s(%(type)s_in_, n) %%#eml
%% constructor:
""",
"""
if nargin == 0
return;
end
%% safecopy:
if nargin == 1
n = [1,1];
end
assert(isequal(size(%(type)s_in_), n));
%(type)s_out_full_ = repmat( %(type)s_out_, n );
for k=1:prod(n)
""",
"""\
end
end\
"""]
################# ENUMS ####################
eml_enum_constructor_template = """\
function val_out = %(classname)s_%(type)s(val_in, n) %%#eml
if nargin == 0
val_out = int32(0);
return;
end
%% arrays of enums not yet supported
if nargin == 2
assert(n == [1,1]);
end
if ischar(val_in)
val_out = encode_%(classname)s_%(type)s(val_in);
else
assert(isinteger(val_in));
assert(isscalar(val_in));
val_out = int32(val_in);
end
end
"""
eml_enum_encoder_template_0 = """\
function int32_out = encode_%(classname)s_%(type)s(string_in); %%#eml
assert(ischar(string_in));
switch string_in
"""
eml_enum_encoder_template_1 = """\
otherwise
error_string = sprintf(\'unrecognized enum string value \'\'%%s\'\' in encode_%(classname)s_%(type)s\\n\', string_in);
error(error_string);
end
end\
"""
eml_enum_decoder_template_0 = """\
function string_out = decode_%(classname)s_%(type)s(int_in); %%#eml
assert(isnumeric(int_in));
switch int32(int_in)
"""
eml_enum_decoder_template_1 = """\
otherwise
error_string = sprintf(\'unrecognized enum integer value \'\'%%d\'\' in decode_%(classname)s_%(type)s\\n\', int_in);
error(error_string);
end
end\
"""