1 /*
2 * Copyright 1996, 1997, 1998, 1999 by Daniel B. Suthers,
3 * Pleasanton Ca. 94588 USA
4 * E-MAIL dbs@tanj.com
5 *
6 */
7
8 /*
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 *
22 */
23
24 /* This module has some functions unique to the CM11A interface.
25 *
26 */
27
28 #include <stdio.h>
29 #include "x10.h"
30
31 extern unsigned char cm11map[];
32 extern unsigned char map2cm11[];
33
34
35 /* This function will transform a 16 bit bitmap of devices in X10 format,
36 * IE bit 6 is device 1 to a human readable map where bit 0 is device 1.
37 * The map is bigendian, IE bit 0 is at the far right.
38 * Unit 1 example:starting with 040 (1000000b) will return 1 (0001b)
39 * Unit 4 example:starting with 0400 (10000000000b) will return 8 (1000b)
40 */
x2unitmap(xmap)41 unsigned int x2unitmap(xmap)
42 int xmap;
43 {
44 unsigned int ret_map;
45 int cntr;
46
47 cntr = ret_map = 0;
48 while( cntr < 16)
49 {
50 if( (xmap & ( 0x01 << cntr)) != 0 )
51 ret_map |= (0x1 << (map2cm11[cntr] - 1));
52 /* Note: The ret_map is 0 relative and the map2cm11 array
53 * is 1 relative, so we must adjust by one.
54 */
55 cntr++;
56 }
57
58 return(ret_map);
59 }
60
61
62 /* b2s converts a 16 bit int to a 16 byte binary ascii string, msb on the left
63 * It's used for visualizing the bits as they are displayed.
64 * (Good for debugging)
65 */
b2s(bin)66 char *b2s(bin)
67 unsigned int bin;
68 {
69 static char bite[17];
70 int i, ii;
71
72 i = 16;
73 ii = 0;
74 while( i > 0 )
75 {
76 bite[--i] = ((bin & (0x01 << ii++)) != 0 ) +'0' ;
77 }
78 bite[16] = '\0';
79
80 return(bite);
81 }
82