3 Copyright (C
) 2005-2007 Martin Koegler
<mkoegler@auto.tuwien.ac.at
>
5 This program is free software
; you can redistribute it and
/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation
; either version
2 of the License
, or
8 (at your option
) any later version.
10 In addition to the permissions in the GNU General Public License
,
11 you may link the compiled version of this file into combinations
12 with other programs
, and distribute those combinations without any
13 restriction coming from the use of this file.
(The General Public
14 License restrictions do apply in other respects
; for example
, they
15 cover modification of the file
, and distribution when not linked into
16 a combine executable.
)
18 This program is distributed in the hope that it will be useful
,
19 but WITHOUT ANY WARRANTY
; without even the implied warranty of
20 MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program
; if not
, write to the Free Software
25 Foundation
, Inc.
, 59 Temple Place
, Suite
330, Boston
, MA
02111-1307 USA
28 #define
EIBC_LICENSE(text
)
30 #define
BYTE2INT(val
) (((int
)(val
))&0xff)
31 #define
SHORT2INT(h
,l
) ((BYTE2INT(h
)<<8)|
(BYTE2INT(l
)))
33 #define
EIBTYPE (SHORT2INT(data
[0],data
[1]))
35 #define EIBC_GETREQUEST \
37 if (_EIB_GetRequest()== -1) \
40 #define
EIBC_RETURNERROR(msg
, error
) \
47 #define
EIBC_RETURNERROR_UINT16(offset
, error
) \
48 if (SHORT2INT (data
[offset
], data
[offset
+1]) == 0) \
54 #define
EIBC_RETURNERROR_SIZE(Length
, error
) \
55 if (data.length
<= Length
) \
61 #define
EIBC_CHECKRESULT(msg
, msgsize
) \
62 if (EIBTYPE
!= msg || data.length
< msgsize
) \
68 #define
EIBC_RETURN_BUF(offset
) \
69 i
= data.length
- offset
; \
70 buf.data
= new byte
[i
]; \
71 System.
arraycopy (data
, offset
, buf.data
, 0, i
); \
74 #define EIBC_RETURN_OK \
77 #define EIBC_RETURN_LEN \
80 #define
EIBC_RETURN_UINT8(offset
) \
81 return
BYTE2INT (data
[offset
]);
83 #define
EIBC_RETURN_UINT16(offset
) \
84 return
SHORT2INT (data
[offset
], data
[offset
+1]);
86 #define
EIBC_RETURN_PTR1(offset
) \
88 ptr1.data
= (short
)SHORT2INT (data
[offset
],data
[offset
+1]);
90 #define
EIBC_RETURN_PTR2(offset
) \
92 ptr2.data
= data
[offset
];
94 #define
EIBC_RETURN_PTR3(offset
) \
96 ptr3.data
= data
[offset
];
98 #define
EIBC_RETURN_PTR4(offset
) \
100 ptr4.data
= (short
)SHORT2INT (data
[offset
],data
[offset
+1]);
102 #define
EIBC_RETURN_PTR5(offset
) \
104 ptr5.addr
= (short
)SHORT2INT (data
[offset
], data
[offset
+1]);
106 #define
EIBC_RETURN_PTR6(offset
) \
108 ptr6.addr
= (short
)SHORT2INT (data
[offset
], data
[offset
+1]);
110 #define
EIBC_COMPLETE(name
, body
) \
111 private class name##_complete implements _complete
{ \
112 public int
complete () throws IOException
{ \
117 #define
EIBC_INIT_COMPLETE(name
) \
118 complete
= new name ##
_complete (); \
121 #define
EIBC_INIT_SEND(length
) \
122 byte head
[] = new byte
[length
]; \
125 #define
EIBC_SEND_BUF(name
) EIBC_SEND_BUF_LEN (name
, 0)
127 #define
EIBC_SEND_BUF_LEN(name
, Length
) \
128 if (name.length
< Length
) \
129 throw new
ArrayIndexOutOfBoundsException ("data to short"); \
130 ibuf
= new byte
[head.length
+ data.length
]; \
131 System.
arraycopy (head
, 0, ibuf
, 0, head.length
); \
132 System.
arraycopy (name
, 0, ibuf
, head.length
, data.length
);
134 #define
EIBC_SEND_LEN(name
) (name.length
)
136 #define
EIBC_SEND(msg
) \
137 ibuf
[0] = (byte
)((msg
>>8)&0xff); \
138 ibuf
[1] = (byte
)((msg
)&0xff); \
139 if (_EIB_SendRequest (ibuf
) == -1) \
142 #define
EIBC_READ_BUF(buffer
) \
145 #define
EIBC_READ_LEN(name
) (name ## _len
)
147 #define
EIBC_PTR1(name
) \
150 #define
EIBC_PTR2(name
) \
153 #define
EIBC_PTR3(name
) \
156 #define
EIBC_PTR4(name
) \
159 #define
EIBC_PTR5(name
) \
162 #define
EIBC_PTR6(name
) \
165 #define
EIBC_SETADDR(name
, offset
) \
166 ibuf
[offset
] = (byte
)((name
>>8)&0xff); \
167 ibuf
[offset
+1] = (byte
)((name
)&0xff);
169 #define
EIBC_SETUINT8(name
, offset
) \
170 ibuf
[offset
] = (byte
)((name
)&0xff);
172 #define
EIBC_SETUINT16(name
, offset
) \
173 ibuf
[offset
] = (byte
)((name
>>8)&0xff); \
174 ibuf
[offset
+1] = (byte
)((name
)&0xff);
176 #define
EIBC_SETBOOL(value
, offset
) \
177 ibuf
[offset
] = (byte
)((value
) ?
0xff : 0);
179 #define
EIBC_SETKEY(value
, offset
) \
180 if (value.length
!= 4) \
181 throw new
ArrayIndexOutOfBoundsException ("key is not 4 bytes long"); \
182 System.
arraycopy (value
, 0, ibuf
, offset
, 4);
184 #define
EIBC_ASYNC(name
, args
, body
) \
185 public int name ##
_async ( AG ## args
) throws IOException
{ \
189 public int
name ( AG ## args
) throws IOException
{ \
190 if (name ##
_async (AL##args
) == -1) \
192 return
EIBComplete (); \
195 #define
EIBC_SYNC(name
, args
, body
) \
196 public int
name ( AG ## args
) throws IOException
{ \