1 /* Simple radio simulation
2 Copyright (C) 2005-2008, Jonathan Bachrach, Jacob Beal, and contributors
3 listed in the AUTHORS file in the MIT Proto distribution's top directory.
5 This file is part of MIT Proto, and is distributed under the terms of
6 the GNU General Public License, with a linking exception, as described
7 in the file LICENSE in the MIT Proto distribution's top directory. */
9 #ifndef __UNITDISCRADIO__
10 #define __UNITDISCRADIO__
12 #include "spatialcomputer.h"
14 class UnitDiscRadio
: public Layer
, public HardwarePatch
{
17 float tx_error
; // probability of failure on transmit
18 float rx_error
; // probability of failure before reception
19 float range
, r_sqr
; // radius of transmission (in meters) [and sq]
21 BOOL is_show_connectivity
, is_show_logical_nbrs
;
22 BOOL is_show_radio
, is_show_backoff
;
23 int connect_display_mode
; // fuzzy=0, locally sharp=1, or sharp=2
24 BOOL is_debug_radio
; // turn on radio debugging
25 BOOL is_fast_prune_hood
; // prune the VM neighborhood on movement?
28 UnitDiscRadio(Args
* args
, SpatialComputer
* parent
, int n
);
30 BOOL
handle_key(KeyEvent
* key
);
31 void add_device(Device
* d
);
32 void device_moved(Device
* d
);
35 NUM_VAL
read_radio_range (VOID
);
36 int radio_send_export (uint8_t version
, uint8_t timeout
, uint8_t n
,
37 uint8_t len
, COM_DATA
*buf
);
38 int radio_send_script_pkt (uint8_t version
, uint16_t n
,
39 uint8_t pkt_num
, uint8_t *script
);
40 int radio_send_digest (uint8_t version
, uint16_t script_len
,
43 friend class UnitDiscDevice
;
45 // storage: gridded in range-size squares to cover screen
46 // an additional layer of cells coats the edges, covering all outside area
47 // it performs badly when devices are not well dispersed in the screen area
48 Population
** cells
; // collections of Device pointers
49 int cell_rows
, cell_cols
, cell_lvls
, num_cells
, lvl_size
;
50 METERS cell_left
, cell_bottom
, cell_floor
;
51 int device_cell(Device
* d
); // which cell is a device in?
52 void connect_to_cell(Device
* d
,int cell_id
); // handle connections
53 void connect_device2(Device
* d
, int base
); // iterate connection over 9 cells
54 void connect_device(Device
*d
); // create all connections
55 void disconnect_device(Device
*d
); // delete all connections
58 class UnitDiscDevice
: public DeviceLayer
{
60 UnitDiscRadio
* parent
;
61 // these values are actually managed by the UnitDiscRadio
62 Population neighbors
; // collection of NbrRecord* (internal definition)
63 int cell_id
; // which cell the device was last in (before motion)
64 int cell_loc
; // where is the device in its cell's list
66 UnitDiscDevice(UnitDiscRadio
* parent
, Device
* container
);
69 void copy_state(DeviceLayer
* src
) {} // to be called during cloning
72 #endif // __UNITDISCRADIO__