24#define _NETSIM_MDEIUM_CODE_
29#pragma comment(lib,"NetworkStack.lib")
30#pragma comment(lib,"Metrics.lib")
31#pragma comment(lib,"PropagationModel.lib")
86 fnNetSimError(
"Device id = %d, device interface = %d is not a valid input for %s,",
105 fplog = fopen(str,
"w");
108 va_start(ls, format);
109 vfprintf(
fplog, format, ls);
121 fnNetSimError(
"Device %d, interface %d is not added to medium before transmission.",
129 fnNetSimErrorandStop(
"Propagation info is NULL between %d:%d-%d:%d\n", t, ti, r, ri);
137 double dFrequency_MHz,
138 double dBandwidth_MHz,
139 double dRxSensitivity_dBm,
140 double dEdThreshold_dBm,
173 fnNetSimError(
"%s is called without adding device %d:%d to medium. use medium_add_device to add the device.\n",
174 __FUNCTION__, d, in);
185 fnNetSimError(
"%s is called without adding device %d:%d to medium. use medium_add_device to add the device.\n",
186 __FUNCTION__, d, in);
197 fnNetSimError(
"%s is called without adding device %d:%d to medium. use medium_add_device to add the device.\n",
198 __FUNCTION__, d, in);
209 fnNetSimError(
"%s is called without adding device %d:%d to medium. use medium_add_device to add the device.\n",
210 __FUNCTION__, d, in);
221 fnNetSimError(
"%s is called without adding device %d:%d to medium. use medium_add_device to add the device.\n",
222 __FUNCTION__, d, in);
234 fnNetSimError(
"%s is called without adding device %d:%d to medium. use medium_add_device to add the device.\n",
235 __FUNCTION__, d, in);
288 write_log(
"New Packet %d,TX=%d-%d,RX=%d-%d,RxPower=%lf,\n",
290 txId, txIf, rxId, rxIf,
318 write_log(
"remove Packet %d,TX=%d-%d,RX=%d-%d,RxPower=%lf,\n",
330#define BOLTZMANN 1.38064852e-23
331#define TEMPERATURE 300
367 double interferencedbm =
MW_TO_DBM(interference);
401 if (dFrequency1 > dFrequency2)
403 if ((dFrequency1 - dFrequency2) >= bandwidth)
410 if ((dFrequency2 - dFrequency1) >= bandwidth)
422 fnNetSimError(
"Device %d, interface %d is not added to medium before transmission.",
430 for (nLoopInterface = 1; nLoopInterface <=
DEVICE(nLoop)->nNumOfInterface; nLoopInterface++)
451 if (nLoop == info->
rxId &&
452 nLoopInterface == info->
rxIf)
continue;
453 if (nLoop == info->
txId &&
454 nLoopInterface == info->
txIf)
continue;
471 fnNetSimError(
"Device %d, interface %d is not added to medium before transmission.",
479 for (nLoopInterface = 1; nLoopInterface <=
DEVICE(nLoop)->nNumOfInterface; nLoopInterface++)
481 if (nLoop == info->
txId &&
482 nLoopInterface == info->
txIf)
504 if (nLoop == info->
rxId &&
505 nLoopInterface == info->
rxIf)
continue;
506 if (nLoop == info->
txId &&
507 nLoopInterface == info->
txIf)
continue;
532 write_log(
"Packet %d errored, BER=%lf, Interference=%lf, RXPower=%lf,\n",
double calculate_FEC_BER(PHY_MODULATION modulation, double codingRate, double dReceivedPower_dBm, double interferencePower_dBm, double dBandwidth_MHz, double dataRate_mbps)
#define _declspec(dllexport)
This function is used to trigger the update.
#define fnNetSimError(x,...)
struct stru_medium * ptrMEDIUM
static void medium_remove_device(NETSIM_ID d, NETSIM_ID ifId)
struct stru_Packet_info PACKETINFO
static ptrDEVICE_IN_MEDIUM medium_find_device(NETSIM_ID devId, NETSIM_ID devIf)
struct stru_medium MEDIUM
static void update_power_due_to_transmission(ptrPACKETINFO info)
static void medium_update_interference(ptrPACKETINFO info)
static void update_power_due_to_transmission_stop(ptrPACKETINFO info)
struct stru_Packet_info * ptrPACKETINFO
static void write_log(char *format,...)
static double GetRXPowerdBm(NETSIM_ID t, NETSIM_ID ti, NETSIM_ID r, NETSIM_ID ri, double time)
static bool isAnypacketIsThereForThisTransmitter(ptrPACKETINFO info)
void medium_update_edthershold(NETSIM_ID d, NETSIM_ID in, double p_dbm)
static double GetRXPowerMW(NETSIM_ID t, NETSIM_ID ti, NETSIM_ID r, NETSIM_ID ri, double time)
static ptrPACKETINFO packetInfo_add(NetSim_PACKET *packet, NETSIM_ID txId, NETSIM_ID txIf, NETSIM_ID rxId, NETSIM_ID rxIf)
static void medium_mark_packet_error(ptrPACKETINFO info)
void medium_update_rxsensitivity(NETSIM_ID d, NETSIM_ID in, double p_dbm)
bool medium_isIdle(NETSIM_ID d, NETSIM_ID in)
struct stru_Device * ptrDEVICE_IN_MEDIUM
static ptrPACKETINFO packetInfo_remove(NetSim_PACKET *packet)
static bool CheckFrequencyInterfrence(double dFrequency1, double dFrequency2, double bandwidth)
void medium_notify_packet_received(NetSim_PACKET *packet)
static double compute_sinr(double p, double i, double bw)
void medium_update_bandwidth(NETSIM_ID d, NETSIM_ID in, double bw_MHz)
void medium_update_datarate(NETSIM_ID d, NETSIM_ID in, double r_mbps)
static void packetInfo_free(ptrPACKETINFO info)
void medium_update_frequency(NETSIM_ID d, NETSIM_ID in, double f_MHz)
struct stru_Device DEVICE_IN_MEDIUM
void medium_update_modulation(NETSIM_ID d, NETSIM_ID in, PHY_MODULATION m, double coderate)
void medium_add_device(NETSIM_ID d, NETSIM_ID ifid, double dFrequency_MHz, double dBandwidth_MHz, double dRxSensitivity_dBm, double dEdThreshold_dBm, void(*medium_change_callback)(NETSIM_ID, NETSIM_ID, bool, NetSim_PACKET *), bool(*isRadioIdle)(NETSIM_ID, NETSIM_ID), bool(*isTransmitterBusy)(NETSIM_ID, NETSIM_ID), void *(*propagationinfo_find)(NETSIM_ID, NETSIM_ID, NETSIM_ID, NETSIM_ID), void(*packetsentnotify)(NETSIM_ID, NETSIM_ID, NetSim_PACKET *))
void medium_notify_packet_send(NetSim_PACKET *packet, NETSIM_ID txId, NETSIM_ID txIf, NETSIM_ID rxId, NETSIM_ID rxIf)
PACKET_STATUS fn_NetSim_Packet_DecideError(double dBER, long double dPacketSize)
double _propagation_get_received_power_dbm(PPROPAGATION_INFO info, double time)
Used to the received power in dBm over time.
double _propagation_calculate_fadingloss(PPROPAGATION_INFO info)
Used to calculate the fading loss. Fading model and parameter must be set in PROPAGATION structure wi...
#define NEGATIVE_INFINITY
EXPORTED char * pszIOLogPath
EXPORTED struct stru_NetSim_Network * NETWORK
enum enum_Modulation PHY_MODULATION
uint f(uint state, uchar key[])
enum enum_PacketStatus PACKET_STATUS
void(* medium_change_callback)(NETSIM_ID, NETSIM_ID, bool, NetSim_PACKET *)
bool(* isTranmitterBusy)(NETSIM_ID, NETSIM_ID)
double dCummulativeReceivedPower_mw
void *(* propagationinfo_find)(NETSIM_ID, NETSIM_ID, NETSIM_ID, NETSIM_ID)
double dCummulativeReceivedPower_dbm
bool(* isRadioIdle)(NETSIM_ID, NETSIM_ID)
double dRxSensitivity_dBm
void(* packetSentNotify)(NETSIM_ID, NETSIM_ID, NetSim_PACKET *)
PHY_MODULATION modulation
PACKET_STATUS nPacketStatus
struct stru_NetSim_Packet_PhyLayer * pstruPhyData
unsigned int nControlDataType
struct stru_Packet_info * next
double dMaxInterference_dbm
PHY_MODULATION modulation
ptrDEVICE_IN_MEDIUM ** devices
ptrPACKETINFO transmissionPacket