README_channel_and_modem_if.md
1## Channels and modems
2
3To be able to emulate the system performance in different environments, with
4different modems and analog components, and with different tradeoffs of
5simulation speed and accuracy, this Phy allows to use exchangable channel
6and modem models.
7How a user selects then is described in
8[this page](https://babblesim.github.io/2G4_select_ch_mo.html)
9
10All a channel needs to do for this Phy to be able to load and use it is to
11implement the interface described in [channel_if.h](../src/channel_if.h)
12
13Similarly modems models would need to implement the interface described in
14[modem_if.h](../src/modem_if.h)
15
README_design.md
1## Overall internal design
2
3In short this Phy is composed of the following main components:
4
5* A list of current (and future) transmissions in the air
6* For each device interface: A state machine where transitions/operations
7 can either be done immediately or be scheduled for a future time
8* A list of (timed) events (function queue)
9
10### The pending transmissions list
11
12The pending list of transmissions (Tx list,
13[pending_tx_list.c](../src/p2G4_pending_tx_list.c)/
14[h](../src/p2G4_pending_tx_rx_list.h))
15is an array with one entry per device (`tx_l_c_t`).
16Where each element keeps a current or future transmission parameters,
17as well as an indication of the transmission being currently active.<br>
18An interface is provided to modify (register) and entry, set it to active,
19and clear it.<br>
20
21### Functions queue
22
23The list of events/function queue,
24([func_queue.h](../src/p2G4_func_queue.h),
25[funcqueue.c](../src/p2G4_func_queue.c))
26is used by each of the device interfaces to schedule future operations.
27This queue has one entry per interface, which consists just of a function to be
28called and the simulated time when the call should be done.<br>
29
30This queue provides functions to modify (add) an entry, to remove it,
31as well as to get the time of the next event.<br>
32Each time a new event is queued the list finds which is the next event
33which needs to be executed. The queue is ordered first by time, and then by
34event type (`f_index_t`).<br>
35You can see more details in [p2G4_func_queue.h](../src/p2G4_func_queue.h).
36
37### Device interface state machine
38
39Each device interface implements the same state machine, which in short works
40as follows:
41
421. The next operation is requested from the device.
43 Depending on what the operation is, either one of the substatemachines events
44 is started (Rx, Tx, Wait, RSSI, CCA), or the device interface is disabled
45 (DISCONNECT), or the whole simulation is ended (TERMINATE)
462. The substate machine transitions over time (using the function queue)
47 until it eventually comes back to 1.
48
49You can find more details about each substate machine in
50[README_device_interface.md](README_device_interface.md)
51
52## Overall workings
53
54The Phy starts by parsing the command line parameters, intializing all its
55components, and loading and initializing the channel and modem libraries.
56
57Then it will block until receiving the next request from each device.
58
59Note that this is the basic way of working of the Phy:
60It cannot let time pass until it knows what is it that all devices want to do.
61It cannot know if a reception will be succesfull until it knows what all others
62devices will be doing during that reception time.
63
64Once it knows what it is that all devices want to do, it can let time pass
65until it handles the first (earliest) device needs, and then it must wait until
66that device requests what it wants next.
67
68It will then repeat this process again and again, until the simulation end time
69has been reached, or all devices have disconnected.
70
README_dumps.md
1## BLE Phy activity dumps
2
3The Physical layer (Phy) can dump all radio activity to files.
4These files will contain all transmissions, receptions and RSSI measurements
5from each device.
6
7The files are stored in `results/<sim_id>/d_2G4_<dev_number>.{Rx|Tx|RSSI}.csv`
8
9These files are formated as comma separated files (csv) with one line heading,
10and, after, one line for each transaction.
11
12This dumps can be converted to other formats other tools can process.
13Check the `dump_post_process/` folder for more info.
14
15The Phy can also be run in "check" mode. In this mode it will compare the
16content of already existing files (for ex. from a previous run) with what it
17would have generated otherwise, and warn when differences are found.
18Run the Phy with `--help` to get more info about this option.
19
20### Tx (v1) format
21
22For each device transmission, these are the columns:
23
24* start_time : microsecond when the first bit of the packet in air starts (1st bit of the preamble)
25* end_time: microsecond when the last bit of the packet ends (last bit of the CRC). Note that a packet may have been aborted before reaching this point.
26* center_freq: As an offset from 2400MHz, in MHz, carrier frequency. Note that frequencies below 0 and above 80 are valid for interferers.
27* phy_address : Physical address / sync word of the packet
28* modulation: Modulation type. One of P2G4_MOD_* : 0x10 = BLE 1 Mbps, 0x20 = BLE 2Mbps
29* power_level: In dBm, transmitted power level (accounting for the device antenna gain)
30* abort_time: When was the packet transmission aborted, or TIME_NEVER (2^64-1) if not aborted.
31* recheck_time: (internal info) When did the device request to reevaluate the possibility to abort the packet last time
32* packet_size: Size of the packet in bytes (not counting preamble or syncword, but counting header, payload, MIC and CRC)
33* packet: Actual packet data (packet_size bytes)
34
35### Rx (v1)
36
37For each device reception attempt, these are the columns:
38
39* start_time: When (in air time) was the receiver opened
40* scan_duration: For how long was the receiver opened attempting to have a physical address match
41* phy_address: Physical address / sync word which was searched for
42* modulation: Type of modulation the receiver is configured to receive. One of P2G4_MOD_*
43* center_freq: As an offset from 2400MHz, in MHz, carrier frequency.
44* antenna_gain: Receiver antenna gain in dB
45* sync_threshold: Reception tolerance: How many errors do we accept before considering the preamble + address sync lost
46* header_threshold: How many errors do we accept in the header before giving a header error (automatically in the phy).
47* pream_and_addr_duration: Duration of the preamble and syncword (for 1Mbps BLE, 40 micros)
48* header_duration: Duration of the packet header (for 1Mbps BLE, 16 micros)
49* bps : Phy bitrate in bits per second (for 1Mbps 1e6)
50* abort_time: When was the packet reception aborted, or TIME_NEVER (2^64-1) if not aborted.
51* recheck_time: (internal info) When did the device request to reevaluate the possibility to abort the reception last time
52* tx_nbr: Which simulated device number was synchronized to (-1 if none)
53* biterrors: How many bit errors there was during the packet reception
54* sync_end: Last micros (included) in which the address ended (only if there was a sync)
55* header_end: Last micros (included) in which the packet header ended (only if there was a sync)
56* payload_end: Last micros (included) in which the packet (CRC) ended (only if there was a sync)
57* rx_time_stamp: Reception time stamp (last microsecond of the sync word/address)
58* status: Reception status. One of P2G4_RXSTATUS*: 1:Ok, 2: CRC error, 3: Header Error, 4: No sync
59* RSSI: Measured RSSI (Received signal strenght indication) value in dBm
60* packet_size: Size of the packet in bytes (not counting preamble or syncword, but counting header, payload, MIC and CRC)
61* packet: Actual packet data (packet_size bytes), note that this is the actual transmitted packet, without possible bit errors
62
63### RSSI:
64
65For each RSSI measurement (excluding the ones performed automatically in Rx measurements)
66
67* meas_time: microsecond in which the mesaurement was performed
68* modulation: Type of modulation the receiver is configured for during the measurement. One of P2G4_MOD_*
69* center_freq: As an offset from 2400MHz, in MHz.
70* antenna_gain: Receiver antenna gain in dB
71* RSSI: Measured RSSI (Received signal strenght indication) value in dBm
72
73### Tx (v2) format
74
75For each device transmission, these are the columns:
76
77* start_tx_time: microsecond when the transmitter starts emitting
78* end_tx_time: microsecond when the transmitter stopped emitting (note that it may have been aborted)
79* start_packet_time: microsecond when the first bit of the packet in air would start (assuming it is not truncated) (1st bit of the preamble)
80* end_packet_time: microsecond when the last bit of the packet ends (for ex. last bit of the CRC). Note that a packet may have been aborted.
81* center_freq: As an offset from 2400MHz, in MHz, carrier frequency. Note that frequencies below 0 and above 80 are valid for interferers.
82* phy_address : Physical address / sync word of the packet
83* modulation: Modulation type. One of P2G4_MOD_* : 0x10 = BLE 1 Mbps, 0x20 = BLE 2Mbps
84* power_level: In dBm, transmitted power level (accounting for the device antenna gain)
85* abort_time: When was the packet transmission aborted, or TIME_NEVER (2^64-1) if not aborted.
86* recheck_time: (internal info) When did the device request to reevaluate the possibility to abort the packet last time
87* packet_size: Size of the packet in bytes (not counting preamble or syncword, but counting header, payload, MIC and CRC)
88* packet: Actual packet data (packet_size bytes)
89
90### Rx (v2)
91
92For each device reception attempt, these are the columns:
93
94* start_time: When (in air time) was the receiver opened
95* scan_duration: For how long was the receiver opened attempting to have a physical address match
96* n_addr: How many addresses is the receiver trying to search for simultaneously
97* phy_address[]: Array of physical addresses / sync wordes which were searched for
98* modulation: Type of modulation the receiver is configured to receive. One of P2G4_MOD_*
99* center_freq: As an offset from 2400MHz, in MHz, carrier frequency.
100* antenna_gain: Receiver antenna gain in dB
101* acceptable_pre_truncation: Up to how many µs of the preamble may have been missed by the receiver
102* sync_threshold: Reception tolerance: How many errors do we accept before considering the preamble + address sync lost
103* header_threshold: How many errors do we accept in the header before giving a header error (automatically in the phy).
104* pream_and_addr_duration: Duration of the preamble and syncword (for 1Mbps BLE, 40 micros)
105* header_duration: Duration of the packet header (for 1Mbps BLE, 16 micros)
106* error_calc_rate : Error calculation rate in bits per second (for ex. for 1Mbps 1e6)
107* resp_type: Type of response the receiver wants at the reception end (0 only supported so far)
108* abort_time: When was the packet reception aborted, or TIME_NEVER (2^64-1) if not aborted.
109* recheck_time: (internal info) When did the device request to reevaluate the possibility to abort the reception last time
110* tx_nbr: Which simulated device number was synchronized to (-1 if none)
111* matched_addr: Which phy address was actually matched
112* biterrors: How many bit errors there was during the packet reception
113* sync_end: Last micros (included) in which the address ended (only if there was a sync)
114* header_end: Last micros (included) in which the packet header ended (only if there was a sync)
115* payload_end: Last micros (included) in which the packet (CRC) ended (only if there was a sync)
116* rx_time_stamp: Reception time stamp (last microsecond of the sync word/address)
117* status: Reception status. One of P2G4_RXSTATUS*: 1:Ok, 2: CRC/Payload error, 3: Header Error, 4: No sync
118* RSSI: Measured RSSI (Received signal strenght indication) value in dBm
119* packet_size: Size of the packet in bytes (not counting preamble or syncword, but counting header, payload, MIC and CRC)
120* packet: Actual packet data (packet_size bytes), note that this is the actual transmitted packet, without possible bit errors
121
122### CCA
123
124For each device CCA request attempt, these are the columns:
125
126* start_time: When (in air time) was the measurement started
127* scan_duration: For how long, in µs, is the measurement performed
128* scan_period: How often will the phy re-measure/check
129* modulation: Which modulation is being search for, and which modulation is the receiver opened with for the RSSI measurements
130* center_freq: Center frequency for the search
131* antenna_gain: Receiver antenna gain in dB
132* threshold_mod: Power threshold at which the search may stop, while it detects the expected modulation
133* threshold_rssi: Power threshold at which the search may stop, when it does not detect the expected modulation
134* stop_when_found: Stop when detecting the modulation (and the rx power > threshold_mod) (1), stop when not detecting the modulation (and the rx power > threshold_rssi) (2), or both (3), or neither (0)
135* abort_time: When was the measurement aborted, or TIME_NEVER (2^64-1) if not aborted.
136* recheck_time: (internal info) When did the device request to reevaluate the possibility to abort last time
137* end_time: When did the measurement actually end
138* RSSI_ave: Average measured RSSI value (in dBm)
139* RSSI_max: Maximum measured RSSI value (in dBm)
140* mod_rx_power: Maximum measured power/RSSI when a compatible modulation was heard
141* mod_found: Was a compatible modulation heard over its threshold power or not
142* rssi_overthreshold: Was the rssi value over its threshold power or not