Art-Net transmission via UDP ver 1.0 vs ver 22
i have sketch transmitting artnet udp protocol works when compiled , uploaded arduino v22. when compile , upload arduino 1.0 (after changing think appropriate calls), not transmit properly.
when run wire shark on transmission, being transmitted arp packet, instead of udp packet.
i running duemilanove, w.5100 ethernet shield.
attached find both v22 , v1.0 sketches.
here v1.0 sketch
v22 follow in next post
when run wire shark on transmission, being transmitted arp packet, instead of udp packet.
i running duemilanove, w.5100 ethernet shield.
attached find both v22 , v1.0 sketches.
here v1.0 sketch
code: [select]
/*
artnet_send v1.0
potentiometers attached analog in 0 , 1
sends artnet packets every 3.5 seconds, or when potentiometers change.
*/
#include <spi.h>
#include <ethernet.h>
#include <ethernetudp.h>
byte mac[] = { 0x90, 0xa2, 0xda, 0x00, 0x87, 0xd5 };
byte ip[] = { 192, 168, 15,12}; // local network ip
//byte ip[] = { 2, 0, 0, 177 }; // proper artnet protocol ip
byte gw[] = {ip[0], ip[1], ip[2], 1 };
byte sn[] = { 255, 0, 0, 0 };
byte sendip[] = {ip[0], 255, 255, 255};
unsigned int localport = 6454; // art-net communicates via udp port=6454
// **** constants ****
const int number_of_channels=512;
const int max_buffer_udp = 531;//18+512+1; //18bit udp header+512bit dmx packet+1 stopbit
ethernetudp udp;
// **** buffers ****
//char
uint8_t packetbuffer[max_buffer_udp]; //udp packet, 0-17 header, 18 - 530 dmx buffer
unsigned char buffer_dmx[number_of_channels];
// **** art-net identification variables ****
unsigned char artnethead[8]="art-net"; //field 1, (0-7)
short opcode=0x5000;
byte artnet_version_1= 0; //field 3 (10)
byte artnet_version_2=14; //field 4 (11)
byte seq_artnet=0; //filed 5 (12)
byte artnet_physical=0; //field 6 (13)
//int incoming_universe = 0; //field 7 (15, 14)
int dmx_chan_tx = 512; //field 8 & 9 (16-17)
int packetsize = 0;
int senduniverse = 2;//universe of artnet sent
int senddmxch = 508; // base channel of dmx sent on selected universe
int senddmxnum = 2; // number of dmx channels sent
long lasttxtime = 0; //time of last transmission
int maxtxtime = 3500; //3.5 seconds maximum between transmissions
boolean diffdmxval = 0; // has dmx changed?
// slider pot input generate dmx value
const int levelpin[] = {0,1};
void setup()
{
pinmode(4,output);
digitalwrite(4,high); //disables sd card
serial.begin(9600);
ethernet.begin( mac, ip, gw, sn);
udp.begin(localport);
(int = 0; i<dmx_chan_tx; i++) // set initial dmx values 0
{
buffer_dmx[i] = 0;
} //end set dmx values 0
(int = 18; i<max_buffer_udp; i++) //set packet buffer '0', except header
{
packetbuffer[i] = 0;
}
// set packet header buffer
(int = 0; i<8; i++)
{
packetbuffer[i] = artnethead[i];
}
packetbuffer[8] = 0x00;//opcode; // low byte
packetbuffer[9] = 0x50;//(opcode >> 8); // high byte
packetbuffer[10] = artnet_version_1; //protocol version high
packetbuffer[11] = artnet_version_2; // prococol version low
//packetbuffer[12] = seq_artnet: // sequence number(increment each transmission)
packetbuffer[13] = artnet_physical; // physical input receiving dmx signal
packetbuffer[14] = senduniverse; // universe being transmitted (low byte)
packetbuffer[15] = (senduniverse >> 8); // universe being transmitted (high byte)
packetbuffer[16] = (dmx_chan_tx >> 8); // # of transmitting dmx chan (high byte)
packetbuffer[17] = dmx_chan_tx; // # of transmitting dmx chan (low byte)
}// end setup
void loop()
{
//read potentiometer, convert reading scale (0-ff)
(int =0; i< senddmxnum; i++)
{
buffer_dmx[senddmxch+i] = getlevel(i); //insert reading potentiometer dmx buffer
if (buffer_dmx[senddmxch+i] == packetbuffer[senddmxch+17+i] && diffdmxval == false)
{
diffdmxval = false;//if no change of dmx value, not send packet
} else
{
diffdmxval = true; //if change of dmx value, write udp buffer, , send packet
}
// copy values buffer_dmx packetbuffer
packetbuffer[senddmxch+17+i] = buffer_dmx[senddmxch +i];
}
// ***** max time between transmissions
if (millis() - lasttxtime > maxtxtime)
{
diffdmxval = true;
}
packetbuffer[12] = seq_artnet; //load seq# udp buffer
//send artnet packet if value change, or timeout
switch (diffdmxval)
{
case false: //if no new dmx value, not transmit
break;
case true:
{
udp.beginpacket(sendip, localport);
udp.write(packetbuffer,max_buffer_udp); //
int goodudp = udp.endpacket(); //send built packet
// int goodudp = udp.sendpacket(packetbuffer,max_buffer_udp,sendip, localport); //depreciated uno
if (goodudp == 1)
{
lasttxtime = millis(); //packet sent, reset timer,
seq_artnet ++; //increment sequence number in artnet header
}
diffdmxval =false; //reset state change detection
}
break;
}
delay(10);
}//end loop
unsigned char getlevel(int i)
{
int levelpot = analogread(levelpin[i]);
levelpot = map(levelpot,0,1023,0,255);
return(levelpot);
}
v22 follow in next post
here v22 sketch
any thoughts doing wrong?
code: [select]
/*
artnet_send v22
potentiometers attached analog in 0 , 1
sends artnet packets every 3.5 seconds, or when potentiometers change.
*/
#include <spi.h>
#include <ethernet.h>
#include <udp.h>
#include <stdint.h>
byte mac[] = { 0x90, 0xa2, 0xda, 0x00, 0x87, 0xd5 };
byte ip[] = { 192, 168, 15,12}; // local network ip
//byte ip[] = { 2, 0, 0, 177 }; // proper artnet protocol ip
byte gw[] = {ip[0], ip[1], ip[2], 1 };
byte sn[] = { 255, 0, 0, 0 };
byte sendip[] = {ip[0], 255, 255, 255};
unsigned int localport = 6454; // art-net communicates via udp port=6454
// **** constants ****
const int number_of_channels=512;
const int max_buffer_udp = 531;//18+512+1; //18bit udp header+512bit dmx packet+1 stopbit
// **** buffers ****
//char
uint8_t packetbuffer[max_buffer_udp]; //udp packet, 0-17 header, 18 - 530 dmx buffer
unsigned char buffer_dmx[number_of_channels];
// **** art-net identification variables ****
unsigned char artnethead[8]="art-net"; //field 1, (0-7)
short opcode=0x5000;
byte artnet_version_1= 0; //field 3 (10)
byte artnet_version_2=14; //field 4 (11)
byte seq_artnet=0; //filed 5 (12)
byte artnet_physical=0; //field 6 (13)
//int incoming_universe = 0; //field 7 (15, 14)
int dmx_chan_tx = 512; //field 8 & 9 (16-17)
int packetsize = 0;
int senduniverse = 2;//universe of artnet sent
int senddmxch = 508; // base channel of dmx sent on selected universe
int senddmxnum = 2; // number of dmx channels sent
long lasttxtime = 0; //time of last transmission
int maxtxtime = 3500; //3.5 seconds maximum between transmissions
boolean diffdmxval = 0; // has dmx changed?
// slider pot input generate dmx value
const int levelpin[] = {0,1};
void setup()
{
pinmode(4,output);
digitalwrite(4,high); //disables sd card
// serial.begin(9600);
ethernet.begin( mac, ip, gw, sn);
udp.begin(localport);
(int = 0; i<dmx_chan_tx; i++) // set initial dmx values 0
{
buffer_dmx[i] = 0;
} //end set dmx values 0
(int = 18; i<max_buffer_udp; i++) //set packet buffer '0', except header
{
packetbuffer[i] = 0;
}
// set packet header buffer
(int = 0; i<8; i++)
{
packetbuffer[i] = artnethead[i];
}
packetbuffer[8] = 0x00;//opcode; // low byte
packetbuffer[9] = 0x50;//(opcode >> 8); // high byte
packetbuffer[10] = artnet_version_1; //protocol version high
packetbuffer[11] = artnet_version_2; // prococol version low
//packetbuffer[12] = seq_artnet: // sequence number(increment each transmission)
packetbuffer[13] = artnet_physical; // physical input receiving dmx signal
packetbuffer[14] = senduniverse; // universe being transmitted (low byte)
packetbuffer[15] = (senduniverse >> 8); // universe being transmitted (high byte)
packetbuffer[16] = (dmx_chan_tx >> 8); // # of transmitting dmx chan (high byte)
packetbuffer[17] = dmx_chan_tx; // # of transmitting dmx chan (low byte)
}// end setup
void loop()
{
//read potentiometer, convert reading scale (0-ff)
(int =0; i< senddmxnum; i++)
{
buffer_dmx[senddmxch+i] = getlevel(i); //insert reading potentiometer dmx buffer
if (buffer_dmx[senddmxch+i] == packetbuffer[senddmxch+17+i] && diffdmxval == false)
{
diffdmxval = false;//if no change of dmx value, not send packet
} else
{
diffdmxval = true; //if change of dmx value, write udp buffer, , send packet
}
// copy values buffer_dmx packetbuffer
packetbuffer[senddmxch+17+i] = buffer_dmx[senddmxch +i];
}
// ***** max time between transmissions
if (millis() - lasttxtime > maxtxtime)
{
diffdmxval = true;
}
packetbuffer[12] = seq_artnet; //load seq# udp buffer
//send artnet packet if value change, or timeout
switch (diffdmxval)
{
case false: //if no new dmx value, not transmit
break;
case true:
{
int goodudp = udp.sendpacket(packetbuffer,max_buffer_udp,sendip, localport); //depreciated uno
if (goodudp > 0)
{
lasttxtime = millis(); //packet sent, reset timer,
seq_artnet ++; //increment sequence number in artnet header
}
diffdmxval =false; //reset state change detection
}
break;
}
delay(10);
}//end loop
unsigned char getlevel(int i)
{
int levelpot = analogread(levelpin[i]);
levelpot = map(levelpot,0,1023,0,255);
return(levelpot);
}
any thoughts doing wrong?
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Art-Net transmission via UDP ver 1.0 vs ver 22
arduino
Comments
Post a Comment