bool DDAProtocol :: exec() { int errorCount = ERROR_COUNT; while(!m_terminated) { if(rxPacket()) { errorCount = ERROR_COUNT; unsigned txSize = m_txData.size(); if(!txSize) { //Send ACK unsigned char tx = ACK; serial_write(m_serial, &tx, 1); } else { txPacket(); waitAck(); } handleData(m_rxData); m_rxData.clear(); } else { if(--errorCount <= 0) return false; } } return true; }
void broadCast(void) { genPacket(); txPacket(buff); OperationMode = Listening; }
bool E36ZKE4::query() { const uint8_t cmd[] = CMD_QUERY; DS2Packet txPacket(address, cmd, sizeof(cmd), packetType); DS2Packet* reply = diag.query(txPacket, DS2_BOTH); if(reply != NULL) { delete reply; return true; } return false; }
void PhysicalMedium::processTxList() { std::list<DeviceNode *>::iterator iter; /* Iterate through unreg list and remove and delete all nodes that * have timedout. */ iter = pimpl->txList.begin(); while (iter != pimpl->txList.end()) { DeviceNode *node = *iter; if (node->hasTxTimerExpired()) { NetSimPacket * pkt = node->getTxPacket(); int txDoneResult; assert(pkt); // This will set Tx Done Result node->handleTxTimerExpired(); txDoneResult = pkt->getTxDoneResult(); node->sendTxDoneIndication(txDoneResult); xlog(LOG_DEBUG, "%s: Node (0x%016llx) Tx Done Ind(%d)", pimpl->name, node, txDoneResult); if (txDoneResult == TX_DONE_OK) { xlog(LOG_DEBUG, "%s: Node (0x%016llx) Tx packet", pimpl->name, node); txPacket(node, pkt); pimpl->stats.tx_pkts_ok++; } else if (txDoneResult == TX_DONE_COLLIDED) { pimpl->stats.tx_pkts_collided++; } else if (txDoneResult == TX_DONE_FAILURE) { pimpl->stats.tx_pkts_failed++; } else { throw "Invalid TX Done Result"; } xlog(LOG_DEBUG, "%s: ok(%d) collided(%d) failed(%d)", pimpl->name, pimpl->stats.tx_pkts_ok, pimpl->stats.tx_pkts_collided, pimpl->stats.tx_pkts_failed); // Delete and Clear transmitted packet node->setTxPacket(NULL); xlog(LOG_DEBUG, "%s: Removing Node ID (0x%016llx) from TX list", pimpl->name, node->getNodeId()); iter = pimpl->txList.erase(iter); } else { // Node not registered or timed out iter++; } } }
void libHubsan::bind() { Serial.println("Sending beacon packets..."); byte status_byte = 0x00; // variable to hold W/R register data. // Generate 4 byte random session id. randomSeed(analogRead(0)); for (int i=0;i<4;i++){ _sessionid[i] = random(255); } for (int i=0;i<16;i++){ // Initialize packet array. _txpacket[i] = 0x00; } _txpacket[0] = 0x01; // Bind level = 01 (Unbound - BEACON lvl 1 Packet) _txpacket[1] = _channel; // Selected Channel for (int i=0;i<4;i++){ _txpacket[i+2] = _sessionid[i]; } getChecksum(_txpacket); // Transmit ANNOUNCE Packet until a response is heard. while (true){ txPacket(_txpacket); a7105.sendStrobe(A7105_RX); // Switch to RX mode. bool response = false; for (int i=0;i<15;i++){ // Listen to see if there was a response. a7105.readRegister(A7105_00_MODE,status_byte); if (CHECK_BIT(status_byte,0)==false){ response = true; break; } delay(1); } if (response){ break; } a7105.sendStrobe(A7105_STANDBY); } rxPacket(_rxpacket); // Escalate handshake. _txpacket[0] = 0x03; // Bind Level = 01 (Unbound - BEACON lvl 3 Packet) getChecksum(_txpacket); while (true){ txPacket(_txpacket); a7105.sendStrobe(A7105_RX); // Switch to RX mode. bool response = false; for (int i=0;i<15;i++){ // Listen to see if there was a response. a7105.readRegister(A7105_00_MODE,status_byte); if (CHECK_BIT(status_byte,0)==false){ response = true; break; } delay(1); } if (response){ break; } a7105.sendStrobe(A7105_STANDBY); } rxPacket(_rxpacket); // Set IDCode to the session value. a7105.writeRegister(A7105_06_ID_DATA,4,_sessionid); // Commence confirmation handshake. _txpacket[0] = 0x01; // Bind Level = 01 (Mid-Bind - Confirmation of IDCODE change packet) getChecksum(_txpacket); while (true){ txPacket(_txpacket); a7105.sendStrobe(A7105_RX); // Switch to RX mode. bool response = false; for (int i=0;i<15;i++){ // Listen to see if there was a response. a7105.readRegister(A7105_00_MODE,status_byte); if (CHECK_BIT(status_byte,0)==false){ response = true; break; } delay(1); } if (response){ break; } a7105.sendStrobe(A7105_STANDBY); } rxPacket(_rxpacket); // Commence full handshake escalation. _txpacket[0] = 0x09; for (int i=0;i<10;i++){ _txpacket[2] = byte(i); getChecksum(_txpacket); while (true){ txPacket(_txpacket); a7105.sendStrobe(A7105_RX); // Switch to RX mode. bool response = false; for (int i=0;i<15;i++){ // Listen to see if there was a response. a7105.readRegister(A7105_00_MODE,status_byte); if (CHECK_BIT(status_byte,0)==false){ response = true; break; } delay(1); } if (response){ break; } a7105.sendStrobe(A7105_STANDBY); } rxPacket(_rxpacket); } a7105.writeRegister(A7105_1F_CODE_I,0x0F); // Enable FEC. a7105.sendStrobe(A7105_STANDBY); }