Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added the possibility to configure the PollReply #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions src/ArtNode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ArtNode.cpp
*
*
* Created by Tobias Ebsen
*
* 19/06/17 - More functions
Expand Down Expand Up @@ -60,6 +60,13 @@ uint32_t ArtNode::broadcastIP() {
return (~mask) | ip;
}

uint16_t ArtNode::getAddress(uint8_t subUni, uint8_t net) {
return subUni + (net << 8);
}
uint16_t ArtNode::getStartAddress() {
return config->portAddrOut[0] + (config->subnet << 4) + (config->net << 8);
}

uint8_t ArtNode::getPort(uint8_t net, uint8_t sub, uint8_t uni) {
if ((net == config->net) && (sub == config->subnet)) {
for (int i=0; i<config->numPorts; i++) {
Expand Down Expand Up @@ -116,30 +123,32 @@ ArtPoll * ArtNode::createPoll(uint8_t talkToMe, uint8_t priority) {
return poll;
}

ArtPollReply * ArtNode::createPollReply() {
ArtPollReply * ArtNode::createPollReply(uint8_t bindIndex, uint8_t numPortsLo, uint8_t portTypes[4], uint8_t portAddrIn[4], uint8_t portAddrOut[4]) {
ArtPollReply *reply = (ArtPollReply*)buffer;
memset(buffer, 0, sizeof(ArtPollReply));

setPacketHeader();
reply->OpCode = OpPollReply;
memcpy(reply->BoxAddr.IP, config->ip, 4);
reply->BoxAddr.Port = config->udpPort;

reply->VersionInfoHi = config->verHi;
reply->VersionInfoLo = config->verLo;

reply->NetSwitch = config->net;
reply->SubSwitch = config->subnet;

strcpy((char*)reply->ShortName, config->shortName);
strcpy((char*)reply->LongName, config->longName);

reply->NumPortsLo = config->numPorts;
memcpy(reply->PortTypes, config->portTypes, 4);
memset(reply->GoodInput, 0x8, config->numPorts); // Input disabled
memset(reply->GoodOutput, 0x80, config->numPorts); // Very important for MadMapper!
memcpy(reply->SwIn, config->portAddrIn, 4);
memcpy(reply->SwOut, config->portAddrOut, 4);

reply->NumPortsLo = numPortsLo;
memcpy(reply->PortTypes, portTypes, 4);
memset(reply->GoodInput, 0x8, numPortsLo); // Input disabled
memset(reply->GoodOutput, 0x80, numPortsLo); // Very important for MadMapper!
memcpy(reply->SwIn, portAddrIn, 4);
memcpy(reply->SwOut, portAddrOut, 4);
reply->BindIndex = bindIndex;

reply->Style = StyleNode;
memcpy(reply->Mac, config->mac, 6);
reply->Status2 = 0x8; // Supports 15bit address (ArtNet 3)
Expand All @@ -149,6 +158,10 @@ ArtPollReply * ArtNode::createPollReply() {
return reply;
}

ArtPollReply * ArtNode::createPollReply() {
return createPollReply(1, config->numPorts, config->portTypes, config->portAddrIn, config->portAddrOut);
}

ArtDmx * ArtNode::createDmx(uint8_t net, uint8_t subuni, uint16_t length) {
ArtDmx *dmx = (ArtDmx*)buffer;
setPacketHeader();
Expand Down Expand Up @@ -197,18 +210,18 @@ ArtAddress * ArtNode::createAddress() {
ArtIpProgReply * ArtNode::createIpProgReply() {
ArtIpProgReply *reply = (ArtIpProgReply*)buffer;
memset(buffer, 0, sizeof(ArtIpProgReply));

setPacketHeader();
reply->OpCode = OpIpProgReply;

reply->ProtVerHi = 0;
reply->ProtVerLo = ProtocolVersion;

reply->ProgIpHi = config->ip[0];
reply->ProgIp2 = config->ip[1];
reply->ProgIp1 = config->ip[2];
reply->ProgIpLo = config->ip[3];

reply->ProgSmHi = config->mask[0];
reply->ProgSm2 = config->mask[1];
reply->ProgSm1 = config->mask[2];
Expand All @@ -225,15 +238,15 @@ void ArtNode::handleAddress(ArtAddress * address) {

if (address->NetSwitch & 0x80)
config->net = address->NetSwitch & 0x7F;

if (address->SubSwitch & 0x80)
config->subnet = address->SubSwitch & 0x0F;

if (address->LongName[0] != 0)
memcpy(config->longName, address->LongName, 64);
if (address->ShortName[0] != 0)
memcpy(config->shortName, address->ShortName, 18);

for (int i = 0; i < 4; i++) {
if (address->SwIn[i] & 0x80)
config->portAddrIn[i] = address->SwIn[i];
Expand Down
14 changes: 9 additions & 5 deletions src/ArtNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ class ArtNode {
ArtNode(ArtConfig & config);
ArtNode(ArtConfig & config, int size);
ArtNode(ArtConfig & config, int size, unsigned char * buffer);

ArtConfig * getConfig();
uint32_t broadcastIP();

unsigned char* getBufferData();
unsigned int getBufferSize();
unsigned int getPacketSize();

uint16_t getAddress(uint8_t subUni, uint8_t net);
uint16_t getStartAddress();

uint8_t getPort(uint8_t net, uint8_t sub, uint8_t uni);
uint8_t getPort(uint8_t net, uint8_t subUni);
uint8_t getPort();
Expand All @@ -101,22 +104,23 @@ class ArtNode {

uint16_t getOpCode();
void setOpCode(uint16_t opCode);

ArtPoll * createPoll(uint8_t talkToMe = 0, uint8_t priority = 0);
ArtPollReply * createPollReply(uint8_t bindIndex, uint8_t numPortsLo, uint8_t portTypes[4], uint8_t portAddrIn[4], uint8_t portAddrOut[4]);
ArtPollReply * createPollReply();
ArtDmx * createDmx(uint8_t net = 0, uint8_t subnet = 0, uint16_t length = 512);
ArtSync * createSync();
ArtAddress * createAddress();
ArtIpProg * createIpProg();
ArtIpProgReply *createIpProgReply();

void handleAddress(ArtAddress * address);

template<typename T>
T* getDataAs() {
return (T*)buffer;
}

protected:

ArtConfig *config;
Expand All @@ -126,4 +130,4 @@ class ArtNode {
int packetSize;
};

#endif
#endif