dtgd
Dependencies: EthernetNetIf mbed DmxArtNet
Revision 0:d7c1b9e83e55, committed 2012-02-13
- Comitter:
- demian
- Date:
- Mon Feb 13 15:51:02 2012 +0000
- Commit message:
- gffgd
Changed in this revision
diff -r 000000000000 -r d7c1b9e83e55 DMX.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DMX.lib Mon Feb 13 15:51:02 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/okini3939/code/DMX/#7826eb77d9ea
diff -r 000000000000 -r d7c1b9e83e55 DmxArtNet.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DmxArtNet.lib Mon Feb 13 15:51:02 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/okini3939/code/DmxArtNet/#c59dc374fc64
diff -r 000000000000 -r d7c1b9e83e55 EthernetNetIf.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Mon Feb 13 15:51:02 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 000000000000 -r d7c1b9e83e55 config.h
diff -r 000000000000 -r d7c1b9e83e55 dbg.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dbg.h Mon Feb 13 15:51:02 2012 +0000 @@ -0,0 +1,7 @@ +#define DEBUG + +#ifdef DEBUG +#define DBG(...) printf("dbg:" __VA_ARGS__) +#else +#define DBG(...) +#endif
diff -r 000000000000 -r d7c1b9e83e55 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Feb 13 15:51:02 2012 +0000 @@ -0,0 +1,155 @@ +/* + * "Node" Device + * "Universe" 512 DMX datas + * "Sub-Net" 16 Universe + * "Server" Controller + * + * can use over 40 Sub-Net on network. + */ + +#include "mbed.h" +#include "EthernetNetIf.h" +#include "DmxArtNet.h" +#include "DMX.h" + + +#define LED_NET_ACT_ON led_yk = 0 +#define LED_NET_ACT_OFF led_yk = 1 +#define LED_NET_G_ON led_gayk = 1; led_gkya = 0 +#define LED_NET_Y_ON led_gayk = 0; led_gkya = 1 +#define LED_NET_GY_OFF led_gayk = 0; led_gkya = 0 + +extern "C" void mbed_mac_address(char *s); + +DigitalOut led_red(p22), led_yellow(p23); +DigitalOut led_gayk(p24),led_gkya(p25), led_yk(p26); +DigitalIn eth_link(P1_25), eth_speed(P1_26); +DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4); +EthernetNetIf *eth; +DmxArtNet art; +DMX dmx1(p13, p14); +DMX dmx2(p28, p27); +Serial pc(USBTX, USBRX); + +void no_memory () { + printf("panic: can't allocate to memory!\r\n"); + exit(-1); +} + +void shutdown () { + art.ArtPollReply.NumPorts = 0; + strcpy(art.ArtPollReply.NodeReport, "Shutdown"); + art.SendArtPollReply(); + art.Done(); +} + +int main () { + int i, u; + char mac[6]; + IpAddr ip; + EthernetErr ethErr; + + set_new_handler(no_memory); // new handler function + + pc.baud(112500); + + eth_link.mode(PullUp); + eth_speed.mode(PullUp); + + if (! eth_link) { + LED_NET_G_ON; + } + LED_NET_ACT_ON; + + mbed_mac_address(mac); + ip = IpAddr(2, mac[3], mac[4], mac[5]); + eth = new EthernetNetIf(ip, IpAddr(255,0,0,0), IpAddr(0,0,0,0), IpAddr(0,0,0,0)); + ethErr = eth->setup(); + if (ethErr) { + LED_NET_Y_ON; + led_red = 1; + return -1; + } + pc.printf("Bind to interface: %d.%d.%d.%d\r\n", (unsigned char)ip[0], (unsigned char)ip[1], (unsigned char)ip[2], (unsigned char)ip[3]); + + art.BindIpAddress = ip; + art.BCastAddress = IpAddr(2,255,255,255); + + art.InitArtPollReplyDefaults(); + // Device + art.ArtPollReply.PortType[0] = 128; // output + art.ArtPollReply.PortType[1] = 128; // output + art.ArtPollReply.PortType[2] = 64; // input + art.ArtPollReply.GoodInput[2] = 4; + art.ArtPollReply.PortType[3] = 64; // input + art.ArtPollReply.GoodInput[3] = 4; + + art.Init(); + art.SendArtPollReply(); // announce to art-net nodes + + while (1) { + Net::poll(); + if (! eth_link) { + LED_NET_G_ON; + } else { + LED_NET_GY_OFF; + } + + if (art.Work()) { + LED_NET_ACT_ON; + led_yellow = 1; + u = art.LastRecievedUniverse; + if (u == 0) { + led1 = 1; + for (i = 0; i < 512; i ++) { + dmx1.put(i, art.DmxIn[u][i]); + } + } else + if (u == 1) { + led2 = 1; + for (i = 0; i < 512; i ++) { + dmx2.put(i, art.DmxIn[u][i]); + } + } + pc.printf("recv, node %d, data %d\r\n", u, art.DmxIn[u][0]); + led1 = 0; + led2 = 0; + led_yellow = 0; + } + + if (dmx1.is_recived) { + led3 = 1; + led_yellow = 1; + dmx1.is_recived = 0; + u = 0; + for (i = 0; i < 512; i ++) { + art.DmxIn[u][i] = dmx1.get(i); + } + LED_NET_ACT_ON; + art.ArtPollReply.GoodInput[u] = 128; + art.Send_ArtDmx(u, 0, (char*)art.DmxIn[u], 512); + pc.printf("send, node %d, data %d\r\n", u, art.DmxIn[u][0]); + led3 = 0; + led_yellow = 0; + } + + if (dmx2.is_recived) { + led4 = 1; + led_yellow = 1; + dmx2.is_recived = 0; + u = 1; + for (i = 0; i < 512; i ++) { + art.DmxIn[u][i] = dmx2.get(i); + } + LED_NET_ACT_ON; + art.ArtPollReply.GoodInput[u] = 128; + art.Send_ArtDmx(u, 0, (char*)art.DmxIn[u], 512); + pc.printf("send, node %d, data %d\r\n", u, art.DmxIn[u][0]); + led4 = 0; + led_yellow = 0; + } + + LED_NET_ACT_OFF; + } +} +
diff -r 000000000000 -r d7c1b9e83e55 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Feb 13 15:51:02 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912