-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
157 lines (113 loc) · 4.18 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h> //memcpy
#include "system.h"
#include "timer.h"
#include "display.h"
#include "enc28j60.h"
#include "dmx.h"
#include "artnet.h"
#include "EtherCard.h"
uint8_t Ethernet::buffer[590];
BufferFiller bfill;
volatile uint8_t missedFrames = 0;
static uint16_t homePage() {
bfill = ether.tcpOffset();
char* name = "ArtNetNode 1";
char* ip = "2.0.0.10";
uint8_t portA = 1;
uint8_t portB = 2;
uint8_t portC = 3;
uint8_t portD = 4;
bfill.emit_p(PSTR("<!DOCTYPE html><html lang=\"de\"><head><meta charset=\"utf-8\" /><title>ArtNet Node</title><style>html,body{margin:20px;font-family:Arial;background:#eff0f1;color:#fff}#main{width:400px;margin:auto;padding:10px;background:#505659;font-weight:bold;text-align:center;border-bottom-left-radius:4px;border-bottom-right-radius:4px;font-size:13px}#header{border-top-left-radius:4px;border-top-right-radius:4px;width:400px;margin:auto;padding:10px;background:#0e89f6}input{background:#3a3f41;border:none;border-radius:2px;padding:8px;color:#fff;text-align:center;width:90%}input[type=submit]{width:100%;background:#575d60;border:#62696c 1px solid }.num{width:40px}td{text-align:left}td.c{text-align:right}</style></head><body><div id=\"header\"> Settings</div><div id=\"main\"><form method=\"POST\"> <br><table width=\"400px\" ><tr><td >IP</td><td class=\"c\" width=\"80%\"><input type=\"text\" value=\"$S\" name=\"ip\"></td></tr><tr><td >Name</td><td class=\"c\" width=\"80%\"><input type=\"text\" value=\"$S\" name=\"name\"></td></tr><tr><td >Port A</td><td class=\"c\"><input type=\"text\" class=\"num\" value=\"$D\" name=\"a\"></td></tr><tr><td>Port B</td><td class=\"c\"><input type=\"text\" class=\"num\" value=\"$D\" name=\"b\"></td></tr><tr><td>Port C</td><td class=\"c\"><input type=\"text\" class=\"num\" value=\"$D\" name=\"c\"></td></tr></table> <br> <input type=\"submit\" value=\"Save\" /></form></div></body></html>")
,name, ip, portA, portB, portC, portD);
return bfill.position();
}
//TODO: Move WebPage Stuff into other module
int main (void) {
cli();/* disable interrupts */
setUp32MhzInternalOsc();
setupTimer0();
//Setup debug leds
PORTA.DIR = 0x03;
PORTA.OUTCLR = 0x03;
setupTWI();
setupDisplay();
setCursor(0,0);
writeStr("Setup Eth0");
static uint8_t macaddr[] = { 0x70,0x69,0x69,0x2D,0x30,0x31 };
//TODO: Load from EEPROM
static uint8_t ipaddr[] = { 2,0,0,10 };
setCursor(0,0);
writeStr("IP:");
writeInt(ipaddr[0]);
writeStr(".");
writeInt(ipaddr[1]);
writeStr(".");
writeInt(ipaddr[2]);
writeStr(".");
writeInt(ipaddr[3]);
ether.begin(sizeof Ethernet::buffer, macaddr);
ether.staticSetup(ipaddr);
ether.enableBroadcast();
ether.udpServerListenOnPort(artnet.udpArtNet, UDP_PORT_ARTNET);
clearDisplay();
setCursor(0,0);
writeStr("Setup DMX");
setupDMX();
ether.buffer[0] = 0;
uint16_t counter = 0;
PMIC.CTRL |= PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
sei();
setCursor(0,0);
writeStr("DMX 1 2 3 4");
uint8_t receivedPost = 0;
while(1) {
uint16_t pos = ether.packetLoop(ether.packetReceive());
//Handle TCP packages
if(pos) {
char* data = (char *) Ethernet::buffer + pos;
if (strncmp("GET / ", data, 7) == 0) {
ether.httpServerReply(homePage()); // send web page data
} else if (strncmp("POST / ", data, 7) == 0) {
receivedPost = 1;
char result[5]; result[0] = 0;
EtherCard::findKeyVal(data, result, 4, "a");
/* setCursor(0,0);
writeStr(result);*/
ether.httpServerReply(homePage()); // send web page data
}
}
if(ether.isReceiveError()) {
PORTA.OUTTGL = 0x02;
missedFrames++;
}
if(counter == 0) {
counter = 12000;
setCursor(15,0);
if(ether.isLinkUp()) {
writeStr("L");
} else {
writeStr(" ");
}
setCursor(15,1);
if(receivedPost == 1) {
writeStr("P");
} else {
writeStr(" ");
}
setCursor(0,1);
writeStr("FPS ");
writeIntWidth( artnet.getUniverseFPS(0), 2);
writeStr(" ");
writeIntWidth( artnet.getUniverseFPS(1), 2);
writeStr(" ");
writeIntWidth( artnet.getUniverseFPS(2), 2);
writeStr(" ");
writeIntWidth( artnet.getUniverseFPS(3), 2);
}
counter--;
}
return 0;
}