void Tx433_Nexa::Device_Off(int dev) { if (dev >= 3) { sendPackets(GrpOn, Unit[1], Off); } else sendPackets(GrpOff, Unit[dev], Off); }
void QueueController::sendData(std::string chatpayload, uint32_t destinationIP) { //Split the input into multiple strings // Create result and temp vectors/strings. Push contents of chatpayload in temp and pushback temp onto result whenever size of temp is MTU. std::vector<std::string> result; std::string temp; unsigned int index = 0; while (index < strlen(chatpayload.c_str())) { // subtract the header size of 20 bytes if (temp.size() == settings->getMTU() - 20) { result.push_back(temp); temp = ""; } temp = temp + chatpayload[index]; index++; } //Also send the last few bits of data from chatpayload result.push_back(temp); //Create packets from the strings std::vector<PIA> PIAPackets; int i; for (i = 0; i < result.size(); i++) { PIA newPIAPacket(settings->getLocalIP(), destinationIP, 100 + i, 0, false, false, result[i]); PIAPackets.push_back(newPIAPacket); } //send the packets sendPackets(PIAPackets); std::cout << "created " << result.size() << " packets\n"; }
uint8_t handleTopPacket(void) { if(USART_GetFlagStatus(USART2, USART_FLAG_RXNE)) { uint8_t received = USART_ReceiveData(USART2); if(START_BYTE == received) { uint8_t timer = 0; //Timer used to stop the function from waiting for data if there is an error GPIO_SetBits(GPIOD, GREED_LED); //Turns on the green led uint8_t counter = 1; //Counter used to count how many bytes we have read in from the top borad while(counter < PACKET_SIZE && timer < 0xFFFF) //Waits until all 16 bytes are read in. If no data comes then the function will break //out after a short period of time { if(USART_GetFlagStatus(USART2, USART_FLAG_RXNE)) //if data is received store it in the array storage { received = USART_ReceiveData(USART2); if(received != START_BYTE) { storage[counter] = received; //Reads in the data from the buffer into an array counter++; //Increments the counter } else { return(0); } } GPIO_SetBits(GPIOD, ORANGE_LED); timer++; } if(1 || (checksum(storage, PACKET_SIZE - 3) == storage[PACKET_SIZE - 2]) && (storage[PACKET_SIZE - 1] == END_BYTE)) //Checks the check sum and the end byte { GPIO_ResetBits(GPIOD, ORANGE_LED); convertTBtoBB(storage); //Converts the data from the top board into motor controller commands that we can use sendPackets(); //Sends the motor controller commands produced by the convert function return(1); //Reading the packet was successful! } else { USART_puts(USART1, (checksum(storage, PACKET_SIZE - 3))); USART_puts(USART1,storage[PACKET_SIZE - 2]); return(0); //Returns 0 if the check sum or end byte were incorrect } } else return(0); //Makes the function recursive until we get a response from the top board } else return(0); }
/** * 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 HttpdSendLocalFile::run(){ sp<Retval> retval; while(true){ { AutoLock _l(this); if( !m_bLive ) { DFWLOG(DFWLOG_D|DFWLOG_ID(DFWLOG_HTTPD_ID), "send local file is stoped"); return; } } if( DFW_RET(retval, sendPackets()) ){ DFWLOG_R(DFWLOG_D|DFWLOG_ID(DFWLOG_HTTPD_ID), retval, ""); } queueClient(); }//end while(true) }
/** * 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); } }
bool calculatePaths(struct distance_table * dt, struct link_costs * ln, struct route_table * rt, struct neighbors * nb, int node_id) { bool b_update = false; // Now calculate paths for (int i = 0; i < 4; i++) { // Obviously don't calculate the path to itself if (node_id == i) continue; // Determine the best path using the distance vector algo bool visited[4] = {(node_id==0), (node_id==1), (node_id==2), (node_id==3)}; struct path_value pv = distanceVector(dt, ln, node_id, i, 0, &visited); // If the path changes, notify - this could be a different value, or different route if (pv.value != dt->costs[pv.node_id][node_id] || rt->route[i][0] != pv.route[0] || rt->route[i][1] != pv.route[1] || rt->route[i][2] != pv.route[2] || rt->route[i][3] != pv.route[3]) { // Set the new path value b_update = true; setNewPathValue(dt, rt, node_id, pv); // Console Notifications printf("rtupdate%d: cost to node #%d updated to %d\r\n", node_id, pv.node_id, pv.value); } } if (b_update) { printf("rtupdate%d: sending out packets to neighbors with new values: [%d,%d,%d,%d]\r\n", node_id, dt->costs[0][node_id], dt->costs[1][node_id], dt->costs[2][node_id], dt->costs[3][node_id]); // Deliver packets to other nodes sendPackets(dt, rt, nb, node_id); } // Report results return b_update; }
void start(Transmitter* transmitter){ openSocket(transmitter); sendPackets(transmitter); freeTransmitterArrays(transmitter); }
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 */ }
// TODO slow loop icin sure ve timer ayarlanacak void RF24Mesh::slowloop() { handlePacket(); sendPackets(); }
//***************************************************************************** // // //***************************************************************************** void sendPayLoad(char* pcData, int length) { sendPackets(pcData, length); // data pointer __delay_cycles(7500000); //Important to make sure All packet sent }
void sendPacketsNode1() { sendPackets(&dt1, &rt1, &nb1, 1); }
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) ; }
/* Node specific */ void sendPacketsNode0() { sendPackets(&dt0, &rt0, &nb0, 0); }