27#include "ErrorModel.h"
28#include "PropagationModel.h"
29#include "IEEE802_11.h"
30#include "IEEE802_11_Phy.h"
32static FILE* fpRMlog = NULL;
34UINT DEVICE_ID_LIST[] = { 0 };
37static bool validate_log(NETSIM_ID nDevID)
39 int count =
sizeof(DEVICE_ID_LIST) /
sizeof(
int);
40 if (count == 1 && DEVICE_ID_LIST[0] == 0)
return true;
43 for (
int i = 0; i < count; i++)
45 if (DEVICE_ID_LIST[i] == DEVICE_CONFIGID(nDevID))
52static void init_radio_measurements_log()
54 if (get_protocol_log_status(
"IEEE_802_11_RADIO_MEASUREMENTS_LOG"))
57 sprintf(s,
"%s\\%s", pszIOLogPath,
"IEEE_802_11_Radio_Measurements_Log.csv");
58 fpRMlog = fopen(s,
"w");
61 fnSystemError(
"Unable to open %s file", s);
66 fprintf(fpRMlog,
"%s,%s,%s,%s,",
67 "Time(ms)",
"Transmitter Name",
"Receiver Name",
"Distance(m)");
69 fprintf(fpRMlog,
"%s,%s,%s,",
70 "Packet ID",
"Packet Type",
"Control Packet Type");
72 fprintf(fpRMlog,
"%s,%s,%s,%s,",
73 "Tx_Power(dBm)",
"Path Loss(dB)",
"Shadowing Loss(dB)",
"Fading Loss(dB)");
76 fprintf(fpRMlog,
"%s,%s,%s,",
77 "Total Loss(dB)",
"Tx Antenna Gain(dB)",
"Rx Antenna Gain(dB)");
79 fprintf(fpRMlog,
"%s,%s,%s,",
80 "Rx_Power(dBm)",
"Interference(dBm)",
"SNR(dB)");
82 fprintf(fpRMlog,
"%s,%s,%s,%s,",
83 "SINR(dB)",
"NSS",
"BER",
"MCS Index");
85 fprintf(fpRMlog,
"\n");
86 if (nDbgFlag) fflush(fpRMlog);
91static void close_radio_measurements_log()
97void IEEE_802_11RadioMeasurements_Init()
99 init_radio_measurements_log();
102void IEEE_802_11RadioMeasurements_Finish()
104 close_radio_measurements_log();
107void IEEE_802_11RadioMeasurements_Log(NetSim_PACKET* packet, NETSIM_ID txid, NETSIM_ID txif, NETSIM_ID rxid, NETSIM_ID rxif)
109 if (fpRMlog == NULL || (!validate_log(txid) && !validate_log(rxid))) {
return; }
112 PPROPAGATION_INFO txinfo = find_propagation_info(txid, txif, rxid, rxif);
113 PIEEE802_11_PHY_VAR txPhy = IEEE802_11_PHY(txid, txif);
114 PIEEE802_11_PHY_VAR rxPhy = IEEE802_11_PHY(rxid, rxif);
116 double rxPowerdBm = _propagation_get_received_power_dbm(txinfo, pstruEventDetails->dEventTime);
117 double interference = medium_get_interference(packet, txid, txif, rxid, rxif);
118 double FadingLoss = propagation_get_Fadingloss(txinfo, pstruEventDetails->dEventTime);
119 rxPowerdBm -= FadingLoss;
121 switch (txPhy->PhyProtocol)
124 if (strcmp(strBERMODEL[txPhy->Ber_Model],
"SINR_BER_PER_TABLE") == 0)
125 ber = calculate_BER_Using_Table(txPhy->PHY_TYPE.dsssPhy.modulation, rxPowerdBm, interference, txPhy->dChannelBandwidth, txPhy->MCS, strWLANProtocol[txPhy->PhyProtocol]);
127 ber = calculate_FEC_BER(txPhy->PHY_TYPE.dsssPhy.modulation, txPhy->PHY_TYPE.dsssPhy.dCodeRate, rxPowerdBm, interference, txPhy->dChannelBandwidth, txPhy->PHY_TYPE.dsssPhy.dDataRate);
132 if (strcmp(strBERMODEL[txPhy->Ber_Model],
"SINR_BER_PER_TABLE") == 0)
133 ber = calculate_BER_Using_Table(txPhy->PHY_TYPE.ofdmPhy.modulation, rxPowerdBm, interference, txPhy->dChannelBandwidth, txPhy->MCS, strWLANProtocol[txPhy->PhyProtocol]);
135 ber = calculate_FEC_BER(txPhy->PHY_TYPE.ofdmPhy.modulation, txPhy->PHY_TYPE.ofdmPhy.dCodingRate, rxPowerdBm, interference, txPhy->dChannelBandwidth, txPhy->PHY_TYPE.ofdmPhy.dDataRate);
138 if (strcmp(strBERMODEL[txPhy->Ber_Model],
"SINR_BER_PER_TABLE") == 0)
139 ber = calculate_BER_Using_Table(txPhy->PHY_TYPE.ofdmPhy_11n.modulation, rxPowerdBm, interference, txPhy->dChannelBandwidth, txPhy->MCS, strWLANProtocol[txPhy->PhyProtocol]);
141 ber = calculate_FEC_BER(txPhy->PHY_TYPE.ofdmPhy_11n.modulation, txPhy->PHY_TYPE.ofdmPhy_11n.dCodingRate, rxPowerdBm, interference, txPhy->dChannelBandwidth, txPhy->PHY_TYPE.ofdmPhy_11n.dDataRate);
144 if (strcmp(strBERMODEL[txPhy->Ber_Model],
"SINR_BER_PER_TABLE") == 0)
145 ber = calculate_BER_Using_Table(txPhy->PHY_TYPE.ofdmPhy_11ac.modulation, rxPowerdBm, interference, txPhy->dChannelBandwidth, txPhy->MCS, strWLANProtocol[txPhy->PhyProtocol]);
147 ber = calculate_FEC_BER(txPhy->PHY_TYPE.ofdmPhy_11ac.modulation, txPhy->PHY_TYPE.ofdmPhy_11ac.dCodingRate, rxPowerdBm, interference, txPhy->dChannelBandwidth, txPhy->PHY_TYPE.ofdmPhy_11ac.dDataRate);
150 if (strcmp(strBERMODEL[txPhy->Ber_Model],
"SINR_BER_PER_TABLE") == 0)
151 ber = calculate_BER_Using_Table(txPhy->PHY_TYPE.ofdmPhy_11ax.modulation, rxPowerdBm, interference, txPhy->dChannelBandwidth, txPhy->MCS, strWLANProtocol[txPhy->PhyProtocol]);
153 ber = calculate_FEC_BER(txPhy->PHY_TYPE.ofdmPhy_11ax.modulation, txPhy->PHY_TYPE.ofdmPhy_11ax.dCodingRate, rxPowerdBm, interference, txPhy->dChannelBandwidth, txPhy->PHY_TYPE.ofdmPhy_11ax.dDataRate);
156 fnNetSimError(
"IEEE802.11--- Unknown protocol %d in %s\n", txPhy->PhyProtocol, __FUNCTION__);
161 fprintf(fpRMlog,
"%lf,%s,%s,%lf,",
162 (ldEventTime/MILLISECOND), DEVICE_NAME(txid),
164 DEVICE_DISTANCE(txid, rxid));
166 fprintf(fpRMlog,
"%lld,%s,%s,",
168 fn_NetSim_Config_GetPacketTypeAsString(packet->nPacketType, ptype),
169 fn_NetSim_Config_GetControlPacketType(packet, type));
171 fprintf(fpRMlog,
"%lf,%lf,%lf,%lf,",
172 MW_TO_DBM(txPhy->nTxPower_mw),
173 propagation_get_Pathloss(txinfo, pstruEventDetails->dEventTime),
174 propagation_get_Shadowloss(txinfo, pstruEventDetails->dEventTime),
178 fprintf(fpRMlog,
"%lf,%lf,%lf,%lf,%lf,",
179 propagation_get_Totalloss(txinfo, pstruEventDetails->dEventTime),
180 txinfo->txInfo.dTxGain,
181 txinfo->txInfo.dRxGain,
186 fprintf(fpRMlog,
"%lf,%lf,%d,%lf,%d,",
187 calculate_sinr(rxPowerdBm, NEGATIVE_DBM, txPhy->dChannelBandwidth),
188 calculate_sinr(rxPowerdBm, interference, txPhy->dChannelBandwidth),
193 fprintf(fpRMlog,
"\n");
194 if (nDbgFlag) fflush(fpRMlog);