3 * @author Simon Han (simonhan@ee.ucla.edu)
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.
15 node_loc_t node_loc
= {
17 .unit
= NODE_LOC_UNIT
,
41 #ifndef NODE_GPS_X_DIR
42 #define NODE_GPS_X_DIR WEST
44 #ifndef NODE_GPS_X_DEG
45 #define NODE_GPS_X_DEG 0
47 #ifndef NODE_GPS_X_MIN
48 #define NODE_GPS_X_MIN 0
50 #ifndef NODE_GPS_X_SEC
51 #define NODE_GPS_X_SEC 0
53 #ifndef NODE_GPS_Y_DIR
54 #define NODE_GPS_Y_DIR NORTH
56 #ifndef NODE_GPS_Y_DEG
57 #define NODE_GPS_Y_DEG 0
59 #ifndef NODE_GPS_Y_MIN
60 #define NODE_GPS_Y_MIN 0
62 #ifndef NODE_GPS_Y_SEC
63 #define NODE_GPS_Y_SEC 0
65 #ifndef NODE_GPS_Z_UNIT
66 #define NODE_GPS_Z_UNIT UNIT_FEET
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
,
79 uint16_t node_address
= NODE_ADDR
;
81 uint16_t node_address
= 1;
87 uint8_t node_group_id
= NODE_GROUP_ID
;
89 uint8_t node_group_id
= 1;
94 uint8_t hw_type
= HW_TYPE
;
96 uint8_t hw_type
= UNKNOWEN
;
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
;
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
135 #define MAX(a,b) ( ((a) > (b)) ? (a) : (b) )
139 #define MIN(a,b) ( ((a) < (b)) ? (a) : (b) )
142 if (loc1
->unit
!= loc2
->unit
)
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
);
157 return dx2
+ dy2
+ dz2
;
160 uint16_t ker_uart_id()
162 return (uint16_t)UART_ADDRESS
;
167 return (uint8_t)I2C_ADDRESS
;
170 uint8_t ker_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
; }