//-------------------------------------------------------------- void Device::set(string id, int nbLEDs, float distLEDs) { if (nbLEDs<2) nbLEDs = 2; m_id = id; m_nbLEDs = nbLEDs; m_distLEDs = distLEDs; m_length = m_distLEDs*(m_nbLEDs-1); // printf("m_length=%.3f\n", m_length); createPackets(m_nbLEDs); }
/** * fullThrottle() Create and send packets as fast as they can be generated. * * Description:\n * Creates noise packets with optional signal(s) injected, then sends\n * LCP and RCP signals.\n */ void fullThrottle() { for (packet = 0; packet < nPackets; ++packet) { *xPkt = *pkt; *yPkt = *pkt; createPackets(genX, genY, *xPkt, *yPkt); sendPackets(*xPkt, *yPkt); } printStatistics(); fout.close(); exit(0); }
//-------------------------------------------------------------- void Device::setNbLeds(int nb) { m_nbLEDs = nb; createPackets(m_nbLEDs); if (m_isSendMessagesOSC == false) return; ofxOscMessage m; m.setAddress( OSC_ADDRESS_SET_DEVICE_PROP ); m.addStringArg(m_id); m.addStringArg("setNbLeds"); m.addIntArg( m_nbLEDs ); m_oscSender.sendMessage(m); }
/** * alarmHandler() Create and send packets at a given interval. * * Description:\n * At each alarm, creates a pair of LCP/RCP gaussian noise packets\n * and sends them to the network or a file.\n */ void alarmHandler(int signal) { if (packet < nPackets) { *xPkt = *pkt; *yPkt = *pkt; createPackets(genX, genY, *xPkt, *yPkt); sendPackets(*xPkt, *yPkt); packet++; } else { printStatistics(); fout.close(); exit(0); } }
//-------------------------------------------------------------- void Device::set(string id, int nbLEDs, float distLEDs) { if (nbLEDs<2) nbLEDs = 2; m_id = id; m_nbLEDs = nbLEDs; m_distLEDs = distLEDs; m_length = m_distLEDs*(m_nbLEDs-1); // printf("m_length=%.3f\n", m_length); createPackets(m_nbLEDs); mp_sampleStandBy = new float[m_nbLEDs]; for (int i=0;i<m_nbLEDs;i++){ mp_sampleStandBy[i]=0.0f; } }
int main(int argc, char **argv) { struct sockaddr_in myaddr; /* our address */ int recvlen; /* # bytes received */ int fd, i; /* our socket */ int msgcnt = 0; /* count # of messages we received */ char buf[BUFSIZE]; /* receive buffer */ /* create a UDP socket */ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("cannot create socket\n"); return 0; } /* bind the socket to any valid IP address and a specific port */ memset((char *)&myaddr, 0, sizeof(myaddr)); myaddr.sin_family = AF_INET; myaddr.sin_addr.s_addr = htonl(INADDR_ANY); myaddr.sin_port = htons(SERVICE_PORT); if (bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) { perror("bind failed"); } printf("waiting on port %d\n", SERVICE_PORT); for (;;) { timer++; printf("timer %d\n", timer); if (timer == timeoutInt ) { if (base==nsn && nsn != NULL) { printf("timeout occured but nothing to resend to client \n"); timerIsOn = 0; }else{ printf("timeout occured resending unacknowledge packets \n"); toResendFunc(fd, remaddr, addrlen); timer = 0; //TODO: Ask Gerard if this should reset } } recvlen = recvfrom(fd, buf, BUFSIZE, 0, (struct sockaddr *)&remaddr, &addrlen); tv.tv_sec = timerIsOn; tv.tv_usec = 0; if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO,&tv,sizeof(tv)) < 0) { perror("Error"); } if (recvlen >= 0) { buf[recvlen] = 0; /* expect a printable string - terminate it */ printf("received message from client: \"%s\"\n", buf); //listen for configurations from client if (strstr(buf, "filename") != NULL) { tokenizeConfig(buf, ",=:"); //get configuration and store createPackets(filename,chunksizeInt);// fragmentation of the file requested by client //initial start sending packets base = head; nsn = head; sendPackets(fd, remaddr, addrlen); } else if(strstr(buf, "ACK") != NULL){ timerIsOn = 1; // timer = 0;//reset timer /*TODO:continue to send packets to maximize window size traverse base based on received acknowledged packet seq of client note: ack seq num is actually the seq number expected by the client to receive n = (ackseqnum - base->startseqnum)/chunksize */ ackNum = tokenizeAck(buf,"-"); if (ackNum < (fileSize+isnInt)) { traverseBase((ackNum - base->startSeqNumber)/chunksizeInt); if (base==nsn) { timerIsOn = 0; }else { timerIsOn = 1; } sendPackets(fd, remaddr, addrlen); }else{ printf("filetransfer complete \n"); printf("nullifying timeout timer, no packets left to send\n"); timerIsOn = 0; sprintf(buf, "complete"); if (sendto(fd, buf, strlen(buf), 0, (struct sockaddr *)&remaddr, addrlen) < 0) perror("sendto"); // close(fd); } } } } // display(); /* never exits */ }
//-------------------------------------------------------------- void Device::setNbLedsOSC(int nb) { m_nbLEDs = nb; createPackets(m_nbLEDs); }
int main(int argc, char **argv) { parseArgs(argc, argv); if (beam) channel = 0; sndX = new MCSend(channel, mcPortX+channel, mcAddr); sndY = new MCSend(channel, mcPortY+channel, mcAddr); /** * initialize the sample generators */ genX.setup(seedX, bandwidth, power); genY.setup(seedY, bandwidth, power); /** * if we're writing to output, open the file */ if (packetFile.length()) openFile(packetFile); if (beam) { pkt = new BeamPacket(source, channel); xPkt = new BeamPacket(source, channel); yPkt = new BeamPacket(source, channel); ATADataPacketHeader hdr = pkt->getHeader(); complex<float> val(1, 1); for (uint32_t i = 0; i < hdr.len; ++i) { pkt->putSample(i, val); xPkt->putSample(i, val); yPkt->putSample(i, val); } /** * send packets with no valid bit to reset Channelizer */ createPackets(genX, genY, *xPkt, *yPkt); sendPackets(*xPkt, *yPkt); } else { pkt = new ChannelPacket(source, channel); xPkt = new ChannelPacket(source, channel); yPkt = new ChannelPacket(source, channel); ATADataPacketHeader hdr = pkt->getHeader(); complex<float> val(1, 1); for (uint32_t i = 0; i < hdr.len; ++i) { pkt->putSample(i, val); xPkt->putSample(i, val); yPkt->putSample(i, val); } } // // set the valid flag for all remaining packets // data_valid = ATADataPacketHeader::DATA_VALID; // // add signals // for (PacketSigList::iterator p = signals.begin(); p != signals.end(); ++p) { PacketSig sig = *p; if (sig.tOff == 0.0) { if (sig.pol == ATADataPacketHeader::XLINEAR || sig.pol == ATADataPacketHeader::BOTH ) genX.addCwSignal(sig.freq, sig.drift, sig.snr); if (sig.pol == ATADataPacketHeader::YLINEAR || sig.pol == ATADataPacketHeader::BOTH ) genY.addCwSignal(sig.freq, sig.drift, sig.snr); } else { if (sig.pol == ATADataPacketHeader::XLINEAR || sig.pol == ATADataPacketHeader::BOTH ) genX.addPulseSignal(sig.freq, sig.drift, sig.snr, sig.tStart, sig.tOn, sig.tOff); if (sig.pol == ATADataPacketHeader::YLINEAR || sig.pol == ATADataPacketHeader::BOTH ) genY.addPulseSignal(sig.freq, sig.drift, sig.snr, sig.tStart, sig.tOn, sig.tOff); } } gettimeofday(&start, NULL); // // now create and send packets at an interval or // continuously // if (alarmInterval) frameAlarm.set(&alarmHandler, alarmInterval, alarmInterval); else fullThrottle(); while (1) ; }