E131Controller::~E131Controller() { qDebug() << Q_FUNC_INFO; disconnect(m_UdpSocket, SIGNAL(readyRead()), this, SLOT(processPendingPackets())); m_UdpSocket->close(); }
ArtNetController::ArtNetController(QString ipaddr, QList<QNetworkAddressEntry> interfaces, QString macAddress, Type type, QObject *parent) : QObject(parent) { m_ipAddr = QHostAddress(ipaddr); m_MACAddress = macAddress; int i = 0; foreach(QNetworkAddressEntry iface, interfaces) { if (iface.ip() == m_ipAddr) { m_broadcastAddr = iface.broadcast(); break; } i++; } qDebug() << "[ArtNetController] Broadcast address:" << m_broadcastAddr.toString() << "(MAC:" << m_MACAddress << ")"; qDebug() << "[ArtNetController] type: " << type; m_packetizer = new ArtNetPacketizer(); m_packetSent = 0; m_packetReceived = 0; m_UdpSocket = new QUdpSocket(this); if (m_UdpSocket->bind(ARTNET_DEFAULT_PORT, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint) == false) return; connect(m_UdpSocket, SIGNAL(readyRead()), this, SLOT(processPendingPackets())); // don't send a Poll if we're an input if (type == Output) { QByteArray pollPacket; m_packetizer->setupArtNetPoll(pollPacket); qint64 sent = m_UdpSocket->writeDatagram(pollPacket.data(), pollPacket.size(), m_broadcastAddr, ARTNET_DEFAULT_PORT); if (sent < 0) { qDebug() << "Unable to send initial Poll packet"; qDebug() << "Errno: " << m_UdpSocket->error(); qDebug() << "Errmgs: " << m_UdpSocket->errorString(); } else m_packetSent++; } else { m_dmxValues.fill(0, 2048); } m_type = type; }
ArtNetController::ArtNetController(QString ipaddr, QList<QNetworkAddressEntry> interfaces, QList<QString> macAddrList, Type type, QObject *parent) : QObject(parent) { m_ipAddr = QHostAddress(ipaddr); int i = 0; foreach(QNetworkAddressEntry iface, interfaces) { if (iface.ip() == m_ipAddr) { m_broadcastAddr = iface.broadcast(); m_MACAddress = macAddrList.at(i); break; } i++; } /* // calculate the broadcast address quint32 ip = m_ipAddr.toIPv4Address(); quint32 mask = QHostAddress("255.255.255.0").toIPv4Address(); // will it work in all cases ? quint32 broadcast = (ip & mask) | (0xFFFFFFFFU & ~mask); m_broadcastAddr = QHostAddress(broadcast); */ qDebug() << "[ArtNetController] Broadcast address:" << m_broadcastAddr.toString() << "(MAC:" << m_MACAddress << ")"; qDebug() << "[ArtNetController] type: " << type; m_packetizer = new ArtNetPacketizer(); m_UdpSocket = new QUdpSocket(this); if (m_UdpSocket->bind(m_broadcastAddr, ARTNET_DEFAULT_PORT, QUdpSocket::ShareAddress) == false) return; connect(m_UdpSocket, SIGNAL(readyRead()), this, SLOT(processPendingPackets())); // don't send a Poll if we're an input if (type == Output) { QByteArray pollPacket; m_packetizer->setupArtNetPoll(pollPacket); m_UdpSocket->writeDatagram(pollPacket.data(), pollPacket.size(), m_broadcastAddr, ARTNET_DEFAULT_PORT); } else { for (int i = 0; i < 2048; i++) m_dmxValues.append((char)0x00); } m_type = type; }
ArtNetController::~ArtNetController() { qDebug() << Q_FUNC_INFO; disconnect(m_UdpSocket, SIGNAL(readyRead()), this, SLOT(processPendingPackets())); m_UdpSocket->close(); QMapIterator<int, QByteArray *> it(m_dmxValuesMap); while(it.hasNext()) { it.next(); QByteArray *ba = it.value(); delete ba; } m_dmxValuesMap.clear(); }
E131Controller::E131Controller(QString ipaddr, QList<QNetworkAddressEntry> interfaces, QList<QString> macAddrList, Type type, QObject *parent) : QObject(parent) { m_ipAddr = QHostAddress(ipaddr); int i = 0; foreach(QNetworkAddressEntry iface, interfaces) { if (iface.ip() == m_ipAddr) { m_MACAddress = macAddrList.at(i); break; } i++; } qDebug() << "[E131Controller] type: " << type; m_packetizer = new E131Packetizer(); m_packetSent = 0; m_packetReceived = 0; m_type = type; m_UdpSocket = new QUdpSocket(this); // reset initial DMX values if we're an input if (type == Input) { m_dmxValues.fill(0, 2048); if (m_UdpSocket->bind(E131_DEFAULT_PORT, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint) == false) { qDebug() << Q_FUNC_INFO << "Socket input bind failed !!"; return; } } else { if (m_UdpSocket->bind(m_ipAddr, E131_DEFAULT_PORT, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint) == false) { qDebug() << Q_FUNC_INFO << "Socket output bind failed !!"; return; } } connect(m_UdpSocket, SIGNAL(readyRead()), this, SLOT(processPendingPackets())); }
E131Controller::E131Controller(QString ipaddr, QString macAddress, Type type, quint32 line, QObject *parent) : QObject(parent) { m_ipAddr = QHostAddress(ipaddr); m_MACAddress = macAddress; m_line = line; qDebug() << "[E131Controller] type: " << type; m_packetizer = new E131Packetizer(); m_packetSent = 0; m_packetReceived = 0; m_type = type; m_inputRefCount = 0; m_outputRefCount = 0; m_UdpSocket = new QUdpSocket(this); // reset initial DMX values if we're an input if (type == Input) { m_dmxValues.fill(0, 512); if (m_UdpSocket->bind(E131_DEFAULT_PORT, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint) == false) { qDebug() << Q_FUNC_INFO << "Socket input bind failed !!"; return; } m_inputRefCount = 1; } else { if (m_UdpSocket->bind(m_ipAddr, E131_DEFAULT_PORT, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint) == false) { qDebug() << Q_FUNC_INFO << "Socket output bind failed !!"; return; } m_outputRefCount = 1; } connect(m_UdpSocket, SIGNAL(readyRead()), this, SLOT(processPendingPackets())); }