void COC::sendPacket(std::shared_ptr<BaseLib::Systems::Packet> packet) { try { if(!packet) { _out.printWarning("Warning: Packet was nullptr."); return; } if(!_socket) { _out.printError("Error: Couldn't write to COC device, because the device descriptor is not valid: " + _settings->device); return; } if(packet->payload()->size() > 54) { if(_bl->debugLevel >= 2) _out.printError("Error: Tried to send packet larger than 64 bytes. That is not supported."); return; } std::shared_ptr<MAXPacket> maxPacket(std::dynamic_pointer_cast<MAXPacket>(packet)); if(!maxPacket) return; std::string packetHex = packet->hexString(); if(_bl->debugLevel > 3) _out.printInfo("Info: Sending (" + _settings->id + ", WOR: " + (maxPacket->getBurst() ? "yes" : "no") + "): " + packetHex); if(maxPacket->getBurst()) writeToDevice(stackPrefix + "Zs" + packetHex + "\n" + stackPrefix + "Zr\n"); else writeToDevice(stackPrefix + "Zf" + packetHex + "\n" + stackPrefix + "Zr\n"); } catch(const std::exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(BaseLib::Exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } }
void TICC1100::sendPacket(std::shared_ptr<BaseLib::Systems::Packet> packet) { try { if(!packet) { _out.printWarning("Warning: Packet was nullptr."); return; } if(_fileDescriptor->descriptor == -1 || _gpioDescriptors[1]->descriptor == -1 || _stopped) return; if(packet->payload()->size() > 54) { _out.printError("Error: Tried to send packet larger than 64 bytes. That is not supported."); return; } std::shared_ptr<MAXPacket> maxPacket(std::dynamic_pointer_cast<MAXPacket>(packet)); if(!maxPacket) return; std::vector<uint8_t> packetBytes = maxPacket->byteArray(); int64_t timeBeforeLock = BaseLib::HelperFunctions::getTime(); _sendingPending = true; _txMutex.lock(); _sendingPending = false; if(_stopCallbackThread || _fileDescriptor->descriptor == -1 || _gpioDescriptors[1]->descriptor == -1 || _stopped) { _txMutex.unlock(); return; } _sending = true; sendCommandStrobe(CommandStrobes::Enum::SIDLE); sendCommandStrobe(CommandStrobes::Enum::SFTX); _lastPacketSent = BaseLib::HelperFunctions::getTime(); if(_lastPacketSent - timeBeforeLock > 100) { _out.printWarning("Warning: Timing problem. Sending took more than 100ms. Do you have enough system resources?"); } if(maxPacket->getBurst()) { sendCommandStrobe(CommandStrobes::Enum::STX); usleep(1000000); } writeRegisters(Registers::Enum::FIFO, packetBytes); if(!maxPacket->getBurst()) sendCommandStrobe(CommandStrobes::Enum::STX); if(_bl->debugLevel > 3) { if(packet->timeSending() > 0) { _out.printInfo("Info: Sending (" + _settings->id + ", WOR: " + (maxPacket->getBurst() ? "yes" : "no") + "): " + packet->hexString() + " Planned sending time: " + BaseLib::HelperFunctions::getTimeString(packet->timeSending())); } else { _out.printInfo("Info: Sending (" + _settings->id + ", WOR: " + (maxPacket->getBurst() ? "yes" : "no") + "): " + packet->hexString()); } } //Unlocking of _txMutex takes place in mainThread } catch(const std::exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(BaseLib::Exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } }