// ---------------------------------------------------------------------- bool ExtIfaceProcessor::process_message( const shawn::ConstMessageHandle& mh ) throw() { const shawn::SimulationEnvironment& se = owner().world().simulation_controller().environment(); const ExtIfaceWiselibMessage* message = dynamic_cast<const ExtIfaceWiselibMessage*> ( mh.get() ); if ( message != NULL ) { if ( message->source().id()!=owner().id() && (message->destination() == owner().id() || message->destination() == BROADCAST_ADDRESS) ) { for ( ReceiverListIterator it = delegates_.begin(); it != delegates_.end(); ++it ) { (*it)( message->source().id(), message->payload_size(), message->payload() ); } if (!ext_delegates_.empty() ) { node_id_t const from=message->source().id(); double const ux=owner().real_position().x(); double const uy=owner().real_position().y(); double const uz=owner().real_position().z(); double const vx=owner().world().find_node_by_id(from)->real_position().x(); double const vy=owner().world().find_node_by_id(from)->real_position().y(); double const vz=owner().world().find_node_by_id(from)->real_position().z(); double const dist=std::sqrt((vx-ux)*(vx-ux)+(vy-uy)*(vy-uy)+(vz-uz)*(vz-uz)); ExtendedData ex; double vrange = owner().world().find_node_by_id(from)->transmission_range(); double urange = owner().transmission_range(); double g_range = owner().world().communication_model().communication_upper_bound(); double rssi_up = se.required_double_param( "rssi_up"); double rssi_low = rssi_up - se.required_double_param( "rssi_low"); double lqi_up = se.required_double_param( "lqi_limit_up_ratio"); double lqi_low = se.required_double_param( "lqi_limit_low_ratio"); double byte_var = se.required_double_param( "byte_var" ); int len = message->payload_size(); int max_len = message->max_len(); double max_dist = g_range*vrange; ex.set_link_metric( rssi(dist, max_dist, rssi_up, rssi_low, byte_var, len, max_len ) ); ex.set_rssi( rssi(dist, max_dist, rssi_up, rssi_low, byte_var, len, max_len ) ); ex.set_lqi( lqi(dist, max_dist, rssi_up, rssi_low, lqi_up, lqi_low, byte_var, len, max_len ) ); for ( ExtendedReceiverListIterator it = ext_delegates_.begin(); it != ext_delegates_.end(); ++it ) { (*it)(from, message->payload_size(), message->payload(), ex); } } } return true; } return shawn::Processor::process_message( mh ); }
// ---------------------------------------------------------------------- int ExtIfaceProcessor:: lqi( double dist, double max_dist, double rssi_up, double rssi_low, double lqi_up, double lqi_low, double byte_var, int len, int max_len ) { double dist_offset_low = max_dist * ( lqi_up / 100 ); double dist_offset_up = max_dist - max_dist * ( lqi_low / 100 ); int lqi = rssi( dist, max_dist, rssi_up, rssi_low, byte_var, len, max_len ); if ( ( dist_offset_low != 0 ) && ( ( dist < dist_offset_low ) || ( dist == 0 ) ) ) { return rssi( dist_offset_low, max_dist, rssi_up, rssi_low, byte_var, len, max_len ); } else if ( ( dist_offset_up != 0 ) && ( ( dist > dist_offset_up ) || ( dist > max_dist ) ) ) { return rssi( dist_offset_up, max_dist, rssi_up, rssi_low, byte_var, len, max_len ); } return lqi; };
static void usage(void) { const char *msg = "\ Usage: radartool [cmd]\n\ firpwr X set firpwr (thresh to check radar sig is gone) to X (int32)\n\ rrssi X set radar rssi (start det) to X dB (u_int32)\n\ height X set threshold for pulse height to X dB (u_int32)\n\ prssi set threshold to checkif pulse is gone to X dB (u_int32)\n\ inband X set threshold to check if pulse is inband to X (0.5 dB) (u_int32)\n\ dfstime X set dfs test time to X secs\n\ en_relpwr_check X enable/disable radar relative power check (AR5413 only)\n\ relpwr X set threshold to check the relative power of radar (AR5413 only)\n\ usefir128 X en/dis using in-band pwr measurement over 128 cycles(AR5413 only)\n\ en_block_check X en/dis to block OFDM weak sig as radar det(AR5413 only)\n\ en_max_rrssi X en/dis to use max rssi instead of last rssi (AR5413 only)\n\ en_relstep X en/dis to check pulse relative step (AR5413 only)\n\ relstep X set threshold to check relative step for pulse det(AR5413 only)\n\ maxlen X set max length of radar signal(in 0.8us step) (AR5413 only)\n\ numdetects get number of radar detects\n\ getnol get NOL channel information\n\ setnol set NOL channel information\n"; fprintf(stderr, "%s", msg); }
void Server::run() { Packet * pPacket = NULL, * pNewPacket = NULL; unsigned char * pNewMessage; int iNewMessageLength = 0; in_addr_t ipTX; std::map<in_addr_t, in_addr_t> mapNewCars; struct timeval tWait = MakeTime(SERVER_WAIT_SECS, SERVER_WAIT_USECS); std::map<in_addr_t, std::vector<Packet *> >::iterator iterPackets; std::map<in_addr_t, Buffer>::iterator iterBuffer; std::map<in_addr_t, CarModel *> * pCarRegistry; std::map<in_addr_t, InfrastructureNodeModel *> * pNodeRegistry; std::map<in_addr_t, CarModel *>::iterator iterCarReceiver; std::map<in_addr_t, InfrastructureNodeModel *>::iterator iterNode; struct timeval tRX; char iRSSI, iSNR; fd_set rfds; std::list<ReadBuffer> listRead; std::list<ReadBuffer>::iterator iterRead; while (!m_bCancelled) { // get any waiting messages m_mutexConnections.lock(); if (FillFDs(&rfds) && Select(&rfds, tWait)) { Read(&rfds, listRead); for (iterRead = listRead.begin(); iterRead != listRead.end(); ++iterRead) { ipTX = ntohl(iterRead->sFrom.sin_addr.s_addr); // if new message is not null, add it to the current buffer if (iterRead->pData != NULL) m_mapBuffers[ipTX] += Buffer(iterRead->pData, iterRead->iLength); } listRead.clear(); } m_mutexConnections.unlock(); // process non-empty buffers into messages for (iterBuffer = m_mapBuffers.begin(); iterBuffer != m_mapBuffers.end(); ++iterBuffer) { if (iterBuffer->second.m_iLength > 0) { //printf("processing buffer..........\n"); //fflush(stdout); unsigned char * pNew = NULL; pCarRegistry = g_pCarRegistry->acquireLock(); pNodeRegistry = g_pInfrastructureNodeRegistry->acquireLock(); m_mutexBuffers.lock(); pNewMessage = iterBuffer->second.m_pData; iNewMessageLength = (signed)iterBuffer->second.m_iLength; tRX = GetCurrentTime(); iRSSI = rssi(); iSNR = snr(); while (iNewMessageLength >= (signed)PACKET_MINIMUM_LENGTH && (pPacket = CreatePacket(*(const PacketType *)pNewMessage)) != NULL) { //printf("got packet...\n"); if (!pPacket->FromBytes(pNewMessage, iNewMessageLength)) { //printf("failed...\n"); DestroyPacket(pPacket); iNewMessageLength = 0; break; } //if(((SafetyPacket*)pPacket)->m_ePacketType == ptSafety) // printf("data: %s\n", ((SafetyPacket*)pPacket)->m_pData); //if(((Packet*)pPacket)->m_ePacketType == ptGeneric) // printf("long: %ld\n", ((Packet*)pPacket)->m_ptTXPosition.m_iLong); // add it to the proper message buffer pPacket->m_tRX = tRX; pPacket->m_iRSSI = iRSSI; pPacket->m_iSNR = iSNR; pNewPacket = pPacket->clone(); for (iterCarReceiver = pCarRegistry->begin(); iterCarReceiver != pCarRegistry->end(); ++iterCarReceiver) { if (iterCarReceiver->second != NULL && iterCarReceiver->second->GetOwnerIPAddress() == CARMODEL_IPOWNER_LOCAL && iterCarReceiver->first != pPacket->m_ipTX) { pNewPacket->m_ipRX = iterCarReceiver->first; iterCarReceiver->second->ReceivePacket(pNewPacket); } } for (iterNode = pNodeRegistry->begin(); iterNode != pNodeRegistry->end(); ++iterNode) { if (iterNode->second != NULL && iterNode->first != pPacket->m_ipTX) { pNewPacket->m_ipRX = iterNode->first; iterNode->second->ReceivePacket(pNewPacket); } } DestroyPacket(pNewPacket); iterCarReceiver = pCarRegistry->find(pPacket->m_ID.srcID.ipCar); iterNode = pNodeRegistry->find(pPacket->m_ID.srcID.ipCar); if ((iterCarReceiver == pCarRegistry->end() || iterCarReceiver->second == NULL || iterCarReceiver->second->GetOwnerIPAddress() != CARMODEL_IPOWNER_LOCAL) && (iterNode == pNodeRegistry->end() || iterNode->second == NULL)) { //printf("processing..................................\n"); mapNewCars[pPacket->m_ID.srcID.ipCar] = iterBuffer->first; iterPackets = m_mapPackets.find(pPacket->m_ID.srcID.ipCar); if (iterPackets == m_mapPackets.end()) iterPackets = m_mapPackets.insert(std::pair<in_addr_t, std::vector<Packet *> >(pPacket->m_ID.srcID.ipCar, std::vector<Packet *>())).first; iterPackets->second.push_back(pPacket); push_heap(iterPackets->second.begin(), iterPackets->second.end(), ComparePacketPtrs); } else DestroyPacket(pPacket); } m_mutexBuffers.unlock(); g_pInfrastructureNodeRegistry->releaseLock(); g_pCarRegistry->releaseLock(); if (iNewMessageLength > 0) pNew = (unsigned char *)memcpy(malloc(iNewMessageLength), pNewMessage, iNewMessageLength); iterBuffer->second = Buffer(pNew, iNewMessageLength); } } //add new network car to list if (!mapNewCars.empty()) { g_pSimulator->m_ModelMgr.AddNetworkCars(mapNewCars); mapNewCars.clear(); } //sleep(1); } }