File: cm11a.c

package info (click to toggle)
heyu 1.28-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 360 kB
  • ctags: 278
  • sloc: ansic: 3,318; makefile: 134; sh: 72
file content (127 lines) | stat: -rw-r--r-- 2,878 bytes parent folder | download
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
/*
 * Copyright 1996, 1997, 1998, 1999 by Daniel B. Suthers,
 * Pleasanton Ca. 94588 USA
 * E-MAIL dbs@tanj.com
 *
 * You may freely copy, use, and distribute this software,
 * in whole or in part, subject to the following restrictions:
 *
 *  1)  You may not charge money for it.
 *  2)  You may not remove or alter this copyright notice.
 *  3)  You may not claim you wrote it.
 *  4)  If you make improvements (or other changes), you are requested
 *      to send them to me, so there's a focal point for distributing
 *      improved versions.
 *
 */

/* This module has some functions unique to the CM11A interface.
 *
 */
 
#include <stdio.h>
#include "x10.h"

extern unsigned char cm11map[];
extern unsigned char map2cm11[];

char *funcmap[] = {
        "All Off",
	"All On",
	"On",
	"Off",
	"Dim",
	"Bright",
	"All Lights Off",
	"Extended Code",
	"Hail Request",
	"Hail Acknowledge",
	"Pre Set Dim %5",
	"Pre Set Dim %75",
	"Extended Data Transfer",
	"Status is On",
	"Status is Off",
	"Status Request" } ;


/* This function returns an integer between 1 and 16.
 * It expects hex_unit to be the hex number coresponding to a
 * unit number.
 * Return -1 upon failure to find a match.
 */

int unit2int(hex_unit)
int hex_unit;
{

  char RCSID[]= "@(#) $Id: cm11a.c,v 1.7 1999/12/13 19:30:26 dbs Exp dbs $\n";

  int unhexed;
  display(RCSID);

  /* Unit numbers may be 1 to 16.  Enforce this restriction */
  hex_unit &= 0x0F;

  /* search through the external array 'cm11map'
   * Return the index that matches the value
   */

  unhexed = 0;
  while ( unhexed < 16 )
  {
      if( hex_unit == cm11map[unhexed++] )
          break;
  }
  if( unhexed == 16  && hex_unit != cm11map[15]  )
      unhexed = -1;

  return(unhexed);
}

/* This function will transform a 16 bit bitmap of devices in X10 format,
 * IE bit 6 is device 1 to a human readable map where bit 0 is device 1.
 * The map is bigendian, IE bit 0 is at the far right.
 * Unit 1 example:starting with 040 (1000000b)  will return 1 (0001b)
 * Unit 4 example:starting with 0400 (10000000000b)  will return 8 (1000b)
 */
unsigned int x2unitmap(xmap)
int xmap;
{
    unsigned int ret_map;
    int cntr;

    cntr = ret_map = 0;
    while( cntr < 16)
    {
        if( (xmap & ( 0x01 << cntr)) != 0 )
	    ret_map  |= (0x1 << (map2cm11[cntr] - 1));
		/* Note:  The ret_map is 0 relative and the map2cm11 array 
		 *        is 1 relative, so we must adjust by one.
		 */
	cntr++;
    }
    
return(ret_map);
}


/* b2s converts a 16 bit int to a 16 byte binary ascii string, msb on the left
 * It's used for visualizing the bits as they are displayed.
 * (Good for debugging)
 */
char *b2s(bin)
unsigned int bin;
{
    static char bite[17];
    int i, ii;

    i = 16;
    ii = 0;
    while( i > 0  )
    {
        bite[--i] = ((bin & (0x01 << ii++)) != 0 ) +'0' ;
    }
    bite[16] = '\0';

    return(bite);
}