Add missing files
[bcusdk.git] / eibd / client / perl / def.def
blob4d6ec0d5b4854169862d8d059917aaf8d76c6686
2 /*
3 EIBD client library
4 Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 In addition to the permissions in the GNU General Public License,
12 you may link the compiled version of this file into combinations
13 with other programs, and distribute those combinations without any
14 restriction coming from the use of this file. (The General Public
15 License restrictions do apply in other respects; for example, they
16 cover modification of the file, and distribution when not linked into
17 a combine executable.)
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #define EIBC_LICENSE(text)
31 #define BYTE2INT(val) (val)
32 #define SHORT2INT(array, offset) ((vec(array,offset,8) << 8) | (vec(array,offset+1,8)))
33 #define SHORT2LONG(array, offset) ((vec(array,offset,8) << 24) | (vec(array,offset+1,8) << 16)| (vec(array,offset+2,8) << 8)| (vec(array,offset+3,8)))
35 #define EIBTYPE (SHORT2INT($self->{data},0))
37 #define EIBC_GETREQUEST \
38 $self->_EIB_Get_Request()==0 or return undef; \
40 #define EIBC_RETURNERROR(msg, error) \
41 if (EIBTYPE == msg) \
42 { \
43 $! = &Errno::error; \
44 return undef; \
47 #define EIBC_RETURNERROR_UINT16(offset, error) \
48 if (SHORT2INT ($self->{data}, offset) == 0) \
49 { \
50 $! = &Errno::error; \
51 return undef; \
54 #define EIBC_RETURNERROR_SIZE(Length, error) \
55 if (bytes::length($self->{data}) <= Length) \
56 { \
57 $! = &Errno::error; \
58 return undef; \
61 #define EIBC_CHECKRESULT(msg, msgsize) \
62 if (EIBTYPE != msg || bytes::length($self->{data}) < msgsize) \
63 { \
64 $! = &Errno::ECONNRESET; \
65 return undef; \
68 #define EIBC_RETURN_BUF(offset) \
69 ${$self->{buf}} = substr($self->{data}, offset); \
70 return bytes::length(${$self->{buf}});
72 #define EIBC_RETURN_OK \
73 return 0;
75 #define EIBC_RETURN_LEN \
76 return $self->{sendlen};
78 #define EIBC_RETURN_UINT8(offset) \
79 return BYTE2INT ($self->{data}[offset]);
81 #define EIBC_RETURN_UINT16(offset) \
82 return SHORT2INT ($self->{data}, offset);
84 #define EIBC_RETURN_PTR1(offset) \
85 if (defined $self->{ptr1}) \
86 { \
87 ${$self->{ptr1}} = SHORT2INT ($self->{data}, offset); \
90 #define EIBC_RETURN_PTR2(offset) \
91 if (defined $self->{ptr2}) \
92 { \
93 ${$self->{ptr2}} = BYTE2INT ($self->{data}[offset]); \
96 #define EIBC_RETURN_PTR3(offset) \
97 if (defined $self->{ptr3}) \
98 { \
99 ${$self->{ptr3}} = BYTE2INT ($self->{data}[offset]); \
102 #define EIBC_RETURN_PTR4(offset) \
103 if (defined $self->{ptr4}) \
105 ${$self->{ptr4}} = SHORT2INT ($self->{data}, offset); \
108 #define EIBC_RETURN_PTR5(offset) \
109 if (defined $self->{ptr5}) \
111 ${$self->{ptr5}} = SHORT2INT ($self->{data}, offset); \
114 #define EIBC_RETURN_PTR6(offset) \
115 if (defined $self->{ptr6}) \
117 ${$self->{ptr6}} = SHORT2INT ($self->{data}, offset); \
120 #define EIBC_RETURN_PTR7(offset) \
121 if (defined $self->{ptr7}) \
123 ${$self->{ptr7}} = SHORT2LONG ($self->{data}, offset); \
126 #define EIBC_COMPLETE(name, body) \
127 sub name##_complete { \
128 my $self = shift; \
129 $self->{complete} = undef; \
130 my $i; \
131 body \
134 #define EIBC_INIT_COMPLETE(name) \
135 $self->{complete} = #name . "_complete"; \
136 return 0;
138 #define EIBC_INIT_SEND(length) \
139 for ($i = 0; $i<length; $i++) { \
140 $ibuf[$i]=0x00; } \
141 my $headlen = length;
143 #define EIBC_SEND_BUF(name) EIBC_SEND_BUF_LEN (name, 0)
145 #define EIBC_SEND_BUF_LEN(name, Length) \
146 if (bytes::length(SCALAR(name)) < Length) \
148 $! = &Errno::EINVAL; \
149 return undef; \
151 $self->{sendlen} = bytes::length(SCALAR(name)); \
152 for ($i = 0; $i < bytes::length(SCALAR(name)); $i++) { \
153 $ibuf[$headlen + $i] = vec(SCALAR(name),$i,8); }
155 #define EIBC_SEND_LEN(name) (SCALAR(name))
157 #define EIBC_SEND(msg) \
158 $ibuf[0] = (msg>>8)&0xff; \
159 $ibuf[1] = (msg)&0xff; \
160 $self->_EIB_SendRequest (pack("C".@ibuf, @ibuf))==0 or return undef;
162 #define EIBC_READ_BUF(buffer) \
163 $self->{buf} = SCALAR(buffer);
165 #define EIBC_READ_LEN(name) (SCALAR(name ## _len))
167 #define EIBC_PTR1(name) \
168 $self->{ptr1} = SCALAR(name);
170 #define EIBC_PTR2(name) \
171 $self->{ptr2} = SCALAR(name);
173 #define EIBC_PTR3(name) \
174 $self->{ptr3} = SCALAR(name);
176 #define EIBC_PTR4(name) \
177 $self->{ptr4} = SCALAR(name);
179 #define EIBC_PTR5(name) \
180 $self->{ptr5} = SCALAR(name);
182 #define EIBC_PTR6(name) \
183 $self->{ptr6} = SCALAR(name);
185 #define EIBC_PTR7(name) \
186 $self->{ptr7} = SCALAR(name);
188 #define EIBC_SETADDR(name, offset) \
189 $ibuf[offset] = (SCALAR(name)>>8)&0xff; \
190 $ibuf[offset+1] = (SCALAR(name))&0xff;
192 #define EIBC_SETUINT8(name, offset) \
193 $ibuf[offset] = (SCALAR(name))&0xff;
195 #define EIBC_UINT8(name, offset) \
196 $ibuf[offset] = ((name))&0xff;
198 #define EIBC_SETUINT16(name, offset) \
199 $ibuf[offset] = (SCALAR(name)>>8)&0xff; \
200 $ibuf[offset+1] = (SCALAR(name))&0xff;
202 #define EIBC_SETLEN(name, offset) \
203 $ibuf[offset] = ((name)>>8)&0xff; \
204 $ibuf[offset+1] = ((name))&0xff;
206 #define EIBC_SETBOOL(value, offset) \
207 $ibuf[offset] = (SCALAR(value)) ? 0xff : 0;
209 #define EIBC_SETKEY(value, offset) \
210 if (ARRAY(value) != 4) \
212 $! = &Errno::EINVAL; \
213 return undef; \
215 for ($i = 0; $i < 4; $i++) \
217 $ibuf [offset + $i] = vec(SCALAR(value),$i,8); \
220 #define EIBC_ASYNC(name, args, body) \
221 sub name ## _async { \
222 my ($self KAG##args) = @_; \
223 my $i; \
224 my @ibuf = {}; \
225 body \
227 sub name { \
228 my ($self KAG##args) = @_; \
229 $self -> name ## _async ( AL##args )==0 or return undef; \
230 return $self -> EIBComplete(); \
233 #define EIBC_SYNC(name, args, body) \
234 sub name { \
235 my ($self KAG##args) = @_; \
236 my $i; \
237 my @ibuf = {}; \
238 body \