Mostly minor fixes up until version 0.8.10.
[irreco.git] / irtrans / irserver / src / common / flash.h
blob880904824a45bf594c618b39ede9d7ff361f57d4
1 /*
2 * Copyright (c) 2007, IRTrans GmbH
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of IRTrans GmbH nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY IRTrans GmbH ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL IRTrans GmbH BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #define REMOTE_CNT 11
33 #define F_ENABLEGROUP 0
34 #define F_COMMAND 1
35 #define F_VOLUMEMACRO 2
36 #define F_VOLUMEMACROD 3
37 #define F_CONFIG 4
38 #define F_REMOTE 5
39 #define F_SEND 6
40 #define F_PREKEY 7
41 #define IRDB_REM 8
42 #define IRDB_TYPEHEADER 9
43 #define IRDB_TYPEACTION 10
44 #define IRDB_TYPEACTION_1 11
45 #define IRDB_TYPEACTION_2 12
47 #define F_TOGGLE 70
48 #define F_ERROR 99
49 #define F_MACRO 100
51 #define F_MAGIC 0x3542
53 #define COMPARE_LEN 128
55 #define PC_MASK 3
56 #define PC_RECV 1
57 #define PC_TRANS 2
58 #define PC_OFF 3
60 #ifdef DETOMA
62 #define TRANSM_MASK 124
64 #define TRANSM_EXT1 4
65 #define TRANSM_EXT2 8
66 #define TRANSM_EXT3 16
67 #define TRANSM_EXT4 32
68 #define TRANSM_INTERN 64
70 #define TRANSM_ALL TRANSM_MASK
72 #else
75 #define SBUS_MASK 12
76 #define SBUS_RECV 4
77 #define SBUS_TRANS 8
78 #define SBUS_OFF 12
80 #define TRANSM_MASK 48
81 #define TRANSM_INTERN 16
82 #define TRANSM_EXTERN 32
83 #define TRANSM_BOTH TRANSM_MASK
85 #endif
87 #define ACC_WAIT 0xf0
88 #define ACC_REPEAT 0xf
90 #ifndef AVR
91 #pragma pack(1)
92 #endif
94 #define MACRO_TIMEOUT 500
97 // Remote = 0: Globale Informationen
99 typedef struct {
100 word dir_cnt;
101 word data_pnt;
102 word end_pnt;
103 word magic;
104 word checksum;
106 byte trans_setup[REMOTE_CNT];
107 byte rcv_len;
108 word target_mask[REMOTE_CNT];
109 word source_mask[REMOTE_CNT];
110 uint32_t group_flags[REMOTE_CNT];
111 } FLASH_CONTENT;
113 typedef struct {
114 FLASH_CONTENT f_content;
115 word last_flashcommand;
116 word command_repeat;
117 uint32_t last_command_time;
118 uint32_t prekey_timeout;
119 byte pre_key;
120 byte toggle_pos[REMOTE_CNT];
121 } FLASH_CONTENT_MEMORY;
124 extern byte flash_mode;
126 #define FLASH_MODE_TRANSLATOR 1
127 #define FLASH_MODE_IRDB 2
128 #define FLASH_MODE_IRDBAUX 4
129 #define FLASH_MODE_LAN_DB 8
130 #define FLASH_MODE_LANRELAIS 16
133 /* Struktur IRDB:
135 Alle Adressen relativ auf Nr. des Eintrags ??
137 0: IRDB_TABLE
138 4: IRDB_HEADER
140 hi: HASH_ENTRY für jedes IR Command -> PNT auf IRDB_IRCOMMAND
141 hc: HASH_ENTRY für jedes Command -> PNT auf IRDB_COMMAND
142 hr: HASH_ENTRY für jede Remote -> PNT auf IRDB_REMOTE
143 c: IRDB_COMMAND für jedes Command -> PNT auf IRDB_REMOTE + IRDB_TIMING + IRDB_IRCOMMAND
144 i: IRDB_IRCOMMAND für jedes Command -> PNT auf IRDB_COMMAND
145 r: IRDB_REMOTE
146 t: IRDB_TIMING
147 a: IRDB_ACTION
151 typedef struct {
152 byte mode;
153 byte hysteresis;
154 byte low_value;
155 byte high_value;
156 word low_remote;
157 word high_remote;
158 word low_mask;
159 word high_mask;
160 byte low_ledsel;
161 byte high_ledsel;
162 byte low_commands[50];
163 byte high_commands[50];
164 } ADC_ENTRY;
166 typedef struct {
167 word remote_cnt;
168 word remote_adr;
169 word remote_hash_adr;
170 word command_cnt;
171 word ircommand_adr;
172 word ircommand_hash_adr;
173 byte return_stat_ok[21];
174 byte return_stat_err[21];
175 byte default_action[100];
176 } IRDB_TABLE_SHORT;
178 typedef struct {
179 word remote_cnt;
180 word remote_adr;
181 word remote_hash_adr;
182 word command_cnt;
183 word ircommand_adr;
184 word ircommand_hash_adr;
185 byte return_stat_ok[21];
186 byte return_stat_err[21];
187 byte default_action[100];
188 ADC_ENTRY adc[4];
189 } IRDB_TABLE;
191 typedef struct {
192 word crc;
193 word type;
194 word len;
195 IRDB_TABLE_SHORT table;
196 } IRDB_HEADER_SHORT;
198 typedef struct {
199 word crc;
200 word type;
201 word len;
202 IRDB_TABLE table;
203 } IRDB_HEADER;
205 typedef struct {
206 word crc;
207 word type;
208 word len;
209 } IRDB_HEADER_ONLY;
211 typedef union {
212 FLASH_CONTENT_MEMORY translation_mem;
213 IRDB_TABLE_SHORT irdb_mem;
214 } FLASH_COMMON_HEADER_SHORT;
216 typedef union {
217 FLASH_CONTENT_MEMORY translation_mem;
218 IRDB_TABLE irdb_mem;
219 } FLASH_COMMON_HEADER;
221 #ifdef ADC_INPUT
222 extern FLASH_COMMON_HEADER f_common;
223 #else
224 extern FLASH_COMMON_HEADER_SHORT f_common;
225 #endif
227 typedef struct {
228 byte name[80];
229 word command_cnt;
230 word command_hash;
231 word command_adr;
232 } IRDB_REMOTE;
234 typedef struct {
235 word command_cnt;
236 word command_hash;
237 word command_adr;
238 byte namelen;
239 byte name[80];
240 } IRDB_REMOTE_COMPACT;
243 typedef struct {
244 word command_cnt;
245 word command_hash;
246 word command_adr;
247 byte namelen;
248 byte defactlen;
249 uint32_t ip;
250 word port;
251 byte modeflags;
252 byte name[130];
253 } IRDB_REMOTE_EX;
256 typedef struct {
257 byte name[20];
258 word timing_adr;
259 word remote_adr;
260 word ird_adr;
261 word action_adr;
262 } IRDB_COMMAND_1;
265 typedef struct {
266 byte name[20];
267 word timing_adr;
268 word remote_adr;
269 word ird_adr;
270 word action_adr;
271 byte toggle_seq;
272 byte dummy;
273 } IRDB_COMMAND;
275 typedef struct {
276 word timing_adr;
277 word remote_adr;
278 word ird_adr;
279 word action_adr;
280 byte toggle_seq;
281 byte namelen;
282 byte name[20];
283 } IRDB_COMMAND_COMPACT;
285 typedef struct {
286 byte ir_length;
287 byte transmit_freq;
288 byte mode;
289 word pause_len[TIME_LEN];
290 word pulse_len[TIME_LEN];
291 byte time_cnt;
292 byte ir_repeat;
293 byte repeat_pause;
294 } IRDB_TIMING;
296 typedef struct {
297 byte action_len;
298 byte action_type;
299 byte relais;
300 byte action[1];
301 } IRDB_ACTION;
303 // Type Flags
305 #define ACTION_BINARY 1
306 #define ACTION_UDP_DEFAULT 2
307 #define ACTION_UDP_UDP 4
308 #define ACTION_UDP_AUX 8
309 #define ACTION_IP 16
310 #define ACTION_PORT 32
312 typedef struct {
313 byte relais;
314 byte action_len[3];
315 byte action_type[3];
316 byte align;
317 byte action[1];
318 } IRDB_ACTION_EX;
320 typedef struct {
321 word command_adr;
322 byte ir_length;
323 byte ir_data[1];
324 } IRDB_IRCOMMAND;
327 #define IRDB_REMOTE_LEN ((sizeof (IRDB_REMOTE) + 1) / 2)
328 #define IRDB_REMOTE_LEN_COMPACT (sizeof (IRDB_REMOTE_COMPACT) - 79)
329 #define IRDB_REMOTE_LEN_EX (sizeof (IRDB_REMOTE_EX) - 129)
330 #define IRDB_COMMAND_LEN ((sizeof (IRDB_COMMAND) + 1) / 2)
331 #define IRDB_COMMAND_LEN_COMPACT (sizeof (IRDB_COMMAND_COMPACT) - 19)
332 #define IRDB_COMMAND_LEN_1 ((sizeof (IRDB_COMMAND_1) + 1) / 2)
333 #define IRDB_HEADER_LEN ((sizeof (IRDB_HEADER) + 1) / 2)
334 #define IRDB_TIMING_LEN ((sizeof (IRDB_TIMING) + 1) / 2)
337 #define CONTENT_LEN ((sizeof (FLASH_CONTENT) + 1) / 2)
338 #define HASH_LEN ((sizeof (HASH_ENTRY) + 1) / 2)
341 typedef struct {
342 byte type;
343 byte len;
344 byte remote;
345 byte group;
346 word flash_adr;
347 word source_mask;
348 byte accelerator_timeout;
349 byte accelerator_repeat;
350 byte trans_setup;
351 byte pre_key;
352 byte name_len;
353 byte data[1];
354 } FLASH_ENTRY;
356 typedef struct {
357 byte type;
358 byte len;
359 byte remote;
360 byte group;
361 word flash_adr;
362 word source_mask;
363 byte accelerator_timeout;
364 byte accelerator_repeat;
365 byte trans_setup;
366 byte pre_key;
367 byte data[1];
368 } FLASH_ENTRY_2;
370 typedef struct {
371 byte type;
372 byte len;
373 byte remote;
374 byte group;
375 word flash_adr;
376 word source_mask;
377 byte accelerator_timeout;
378 byte accelerator_repeat;
379 byte trans_setup;
380 byte cdata[1];
381 } FLASH_ENTRY_ORG;
383 typedef struct {
384 word hashcode;
385 word adr;
386 } HASH_ENTRY;
388 #ifdef AVR
390 typedef union {
391 uint32_t Whole;
392 struct
394 byte Data;
395 word Remainder;
396 byte Head;
397 } Part;
398 } CRC_BUFFER;
400 void PutCRC(byte b,CRC_BUFFER *crcb);
401 void CRCStart (CRC_BUFFER *crcb,byte init);
402 void CRCSet (CRC_BUFFER *crcb,byte *Data, word Length);
403 word CRC (CRC_BUFFER *crcb);
405 #endif
407 void flash_lan (void);
408 void init_irdb (void);
409 void flash_init (void);
410 void flash_ioinit (void);
411 void read_flash_directory (void);
412 byte flash_exec (byte adr,byte data[],byte len,byte md);
413 void load_flashcommand (word adr,IRDATA *ird);
414 void send_flashcommand (FLASH_ENTRY *fentry,byte num,byte md);
415 word find_flashentry (byte data[],byte len,word hpnt,FLASH_ENTRY *fentry);
416 byte compare_code (byte data[],byte len,word adr,FLASH_ENTRY *fentry);
417 word get_hashcode (byte data[],byte len);
418 void read_flashdata (byte *pnt,word adr,word cnt);
419 void write_flashdata (byte *pnt,word adr,word cnt);
420 void set_flashadr (word adr);
421 void read_nextflashdata (byte *pnt,word cnt);
422 void signal_error (void);
423 void set_commanddata (int pos,IRDATA *irpnt);
424 void switch_relay (byte val);
425 byte irdb_findircommand (byte ircommand[],byte irlen,byte adr,byte *data);
426 byte irdb_send_string (byte *str,byte len);
427 byte irdb_send (byte remote[],byte command[],byte led,word mask,byte stat);
428 byte irdb_receive (byte ircommand[],byte len,IRRECEIVE *ir);
429 byte irdb_format_receive (byte ircommand[],byte len,IRRECEIVE *ir,word adr);
430 byte udp_format_data (IRRECEIVE *ir,UDP_ASCII_RECEIVE *data,byte num);
431 void ReadIRDataFlash (word iadr,word tadr);
432 word _atoi (byte pnt[]);
433 byte irdb_findcommand (byte com[],IRDB_REMOTE_EX *irdb_rem,IRDB_COMMAND_COMPACT *irdb_com);
434 void irdb_relais (IRRECEIVE *ir);