Added SHT11 driver for TMote.
[sos-2x.git] / kernel / sos_info.c
bloba092cfe78bffb41e8f9ff99abb73b8a35a036ee7
1 /**
2 * @brief node id
3 * @author Simon Han (simonhan@ee.ucla.edu)
4 * @version 1.0
5 * This is the interface for modules, kernel can
6 * just use node_address
7 * 9/13/2005 mods made by Nicholas Kottenstette (nkottens@nd.edu)
8 * changed ker_loc to return copy of node_loc, changed node_loc.{x,y,z}
9 * to be int16_t, added gps_loc data, ker_gps interface, and
10 * ker_loc_r2 interface.
12 #include <sos_info.h>
13 #include <sos.h>
15 node_loc_t node_loc = {
16 #ifdef NODE_LOC_UNIT
17 .unit = NODE_LOC_UNIT,
18 #else
19 .unit = UNIT_FEET,
20 #endif
22 #ifdef NODE_X
23 .x = NODE_X,
24 #else
25 .x = 0,
26 #endif
28 #ifdef NODE_Y
29 .y = NODE_Y,
30 #else
31 .y = 0,
32 #endif
34 #ifdef NODE_Z
35 .z = NODE_Z,
36 #else
37 .z = 0,
38 #endif
41 #ifndef NODE_GPS_X_DIR
42 #define NODE_GPS_X_DIR WEST
43 #endif
44 #ifndef NODE_GPS_X_DEG
45 #define NODE_GPS_X_DEG 0
46 #endif
47 #ifndef NODE_GPS_X_MIN
48 #define NODE_GPS_X_MIN 0
49 #endif
50 #ifndef NODE_GPS_X_SEC
51 #define NODE_GPS_X_SEC 0
52 #endif
53 #ifndef NODE_GPS_Y_DIR
54 #define NODE_GPS_Y_DIR NORTH
55 #endif
56 #ifndef NODE_GPS_Y_DEG
57 #define NODE_GPS_Y_DEG 0
58 #endif
59 #ifndef NODE_GPS_Y_MIN
60 #define NODE_GPS_Y_MIN 0
61 #endif
62 #ifndef NODE_GPS_Y_SEC
63 #define NODE_GPS_Y_SEC 0
64 #endif
65 #ifndef NODE_GPS_Z_UNIT
66 #define NODE_GPS_Z_UNIT UNIT_FEET
67 #endif
68 #ifndef NODE_GPS_Z
69 #define NODE_GPS_Z 0
70 #endif
71 gps_t gps_loc = {
72 .x = { NODE_GPS_X_DIR, NODE_GPS_X_DEG, NODE_GPS_X_MIN, NODE_GPS_X_SEC },
73 .y = { NODE_GPS_Y_DIR, NODE_GPS_Y_DEG, NODE_GPS_Y_MIN, NODE_GPS_Y_SEC },
74 .unit = NODE_GPS_Z_UNIT,
75 .z = NODE_GPS_Z,
78 #ifdef NODE_ADDR
79 uint16_t node_address = NODE_ADDR;
80 #else
81 uint16_t node_address = 1;
82 #endif
86 #ifdef NODE_GROUP_ID
87 uint8_t node_group_id = NODE_GROUP_ID;
88 #else
89 uint8_t node_group_id = 1;
90 #endif
93 #ifdef HW_TYPE
94 uint8_t hw_type = HW_TYPE;
95 #else
96 uint8_t hw_type = UNKNOWEN;
97 #endif
99 int8_t id_init()
101 return SOS_OK;
105 //! The following function is used by the 802.15.4 MAC to set the node address after boot-up
106 void ker_set_id(uint16_t alloc_address)
108 node_address = alloc_address;
111 uint16_t ker_id()
113 return node_address;
116 node_loc_t ker_loc()
118 return node_loc;
121 gps_t ker_gps()
123 return gps_loc;
126 uint32_t ker_loc_r2(node_loc_t *loc1, node_loc_t *loc2)
128 int32_t dx=0, dy=0, dz=0;
129 uint32_t dx2=0, dy2=0, dz2=0;
130 #define SQUARED(x) ((x)*(x))
131 #define DXYZ_MAX ((int16_t)1<<14)
132 #define DXYZ_MIN -DXYZ_MAX
134 #ifndef MAX
135 #define MAX(a,b) ( ((a) > (b)) ? (a) : (b) )
136 #endif
138 #ifndef MIN
139 #define MIN(a,b) ( ((a) < (b)) ? (a) : (b) )
140 #endif
142 if (loc1->unit != loc2->unit)
143 return 0xffffffff;
144 /* Limit the largest dimension to +/- 16384 to prevent overflow */
145 dx = loc1->x - loc2->x;
146 dy = loc1->y - loc2->y;
147 dz = loc1->z - loc2->z;
148 dx = MAX(dx,DXYZ_MIN);
149 dy = MAX(dy,DXYZ_MIN);
150 dz = MAX(dz,DXYZ_MIN);
151 dx = MIN(dx,DXYZ_MAX);
152 dy = MIN(dy,DXYZ_MAX);
153 dz = MIN(dz,DXYZ_MAX);
154 dx2 = SQUARED(dx);
155 dy2 = SQUARED(dy);
156 dz2 = SQUARED(dz);
157 return dx2 + dy2 + dz2;
160 uint16_t ker_uart_id()
162 return (uint16_t)UART_ADDRESS;
165 uint8_t ker_i2c_id()
167 return (uint8_t)I2C_ADDRESS;
170 uint8_t ker_hw_type()
172 return hw_type;
175 uint8_t ker_get_group(void) { return node_group_id; }
177 void ker_set_group(uint8_t new_group_id) { node_group_id = new_group_id; }