-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_router.ino
128 lines (110 loc) · 3.71 KB
/
video_router.ino
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
/*
* NMS Modification of QUARTZ Q1600-AV-1616 Video Router
*/
#include <EtherCard.h>
#include <EEPROM.h>
//static byte mymac[] = { 0x51,0x75,0x61,0x72,0x74,0x7A }; // MAC Address (Quartz)
//static byte myip[] = { 192,168,1,234 }; // IP Address
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,1,200 };
byte Ethernet::buffer[500];
BufferFiller bfill;
void setup() {
pinMode(A0,OUTPUT); // Destination Address Line MSB
pinMode(A1,OUTPUT); // Destination Address Line 2
pinMode(A2,OUTPUT); // Destination Address Line 3
pinMode(A3,OUTPUT); // Destination Address Line LSB
pinMode(A4,OUTPUT); // Destination Enable (Active LOW)
pinMode(2,OUTPUT); // Source Address Bus MSB
pinMode(3,OUTPUT); // Source Address Bus Line 2
pinMode(4,OUTPUT); // Source Address Bus LSB
pinMode(5,OUTPUT); // Source Bank Select (1-8)
pinMode(6,OUTPUT); // Source Bank Select (9-16)
pinMode(9,OUTPUT); // Buzzer/Boot LED
pinMode(8,OUTPUT); // Network Error LED
digitalWrite(8,HIGH); // (off by default)
if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0) // Set up Ethernet
digitalWrite(8,LOW); // Turn on the Network Error LED
ether.staticSetup(myip);
digitalWrite(A4,HIGH);
Serial.begin(9600); // Set up Serial
for (int dest=0; dest<=15; dest++)
{
int source=EEPROM.read(dest);
route(source,dest);
}
digitalWrite(9,LOW);
}
static word homePage() {
bfill = ether.tcpOffset();
bfill.emit_p(PSTR(
"HTTP/1.0 200 OK\r\n"
"Content-Type: application/json\r\n"
"Pragma: no-cache\r\n"
"Access-Control-Allow-Origin: *\r\n"
"\r\n"
"[$D,$D,$D,$D,$D,$D,$D,$D,$D,$D,$D,$D,$D,$D,$D,$D]"),
EEPROM.read(0), EEPROM.read(1), EEPROM.read(2), EEPROM.read(3), EEPROM.read(4), EEPROM.read(5), EEPROM.read(6), EEPROM.read(7), EEPROM.read(8),
EEPROM.read(9), EEPROM.read(10), EEPROM.read(11), EEPROM.read(12), EEPROM.read(13), EEPROM.read(14), EEPROM.read(15));
return bfill.position();
}
void loop() {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (pos) // check if valid tcp data is received
{
char* data = (char*) Ethernet::buffer + pos;
data += 5;
if(data[0] == '?')
{
int source = (data[1]-65);
int dest = (data[2]-65);
if(source < 16 && dest < 16)
{
digitalWrite(9,HIGH);
route(source,dest);
EEPROM.update(dest, source);
digitalWrite(9,LOW);
Serial.write(" ");
Serial.print(bitRead(dest,3));
Serial.print(bitRead(dest,2));
Serial.print(bitRead(dest,1));
Serial.print(bitRead(dest,0));
Serial.write(" ");
Serial.print(bitRead(source,3));
Serial.print(bitRead(source,2));
Serial.print(bitRead(source,1));
Serial.print(bitRead(source,0));
Serial.write(" \r\n[ OK ] Routed\r\n");
}
}
ether.httpServerReply(homePage()); // send web page data
}
delay(100);
}
void route(int source, int destination) {
/*
* Sets up the source and destination busses for a particular address.
*/
digitalWrite(A0,bitRead(destination,0));
digitalWrite(A1,bitRead(destination,1));
digitalWrite(A2,bitRead(destination,2));
digitalWrite(A3,bitRead(destination,3));
digitalWrite(2,bitRead(source,0));
digitalWrite(3,bitRead(source,1)); // choose source
digitalWrite(4,bitRead(source,2));
if(bitRead(source,3)) // Do we want 1-8 or 9-16?
{
digitalWrite(6,LOW);
digitalWrite(5,HIGH);
}
else
{
digitalWrite(6,HIGH);
digitalWrite(5,LOW);
}
delay(100);
digitalWrite(A4,LOW);
delay(100);
digitalWrite(A4,HIGH);
}