Stefan Schuermans commited on 2017-06-04 19:58:53
Showing 5 changed files, with 81 additions and 35 deletions.
... | ... |
@@ -14,14 +14,10 @@ |
14 | 14 |
# |
15 | 15 |
# You should have received a copy of the GNU Lesser General Public License |
16 | 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 |
-# BlinkenLightsInteractiveMovieProgram |
|
18 |
-# Copyright (C) 2004-2011: Stefan Schuermans <stefan@schuermans.info> |
|
19 |
-# Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html |
|
20 |
-# a blinkenarea.org project |
|
21 |
- |
|
22 |
-VERSION_MAJOR=0 |
|
23 |
-VERSION_MINOR=1 |
|
24 |
-VERSION_REVISION=2 |
|
17 |
+ |
|
18 |
+VERSION_MAJOR=1 |
|
19 |
+VERSION_MINOR=2 |
|
20 |
+VERSION_REVISION=0 |
|
25 | 21 |
|
26 | 22 |
JAVAC=javac |
27 | 23 |
JAR=jar |
... | ... |
@@ -110,9 +110,9 @@ class Config |
110 | 110 |
void procDistriAddr(String settingPart2, String value) |
111 | 111 |
throws Exception |
112 | 112 |
{ |
113 |
- int dist; |
|
113 |
+ int dist, addr_cnt, addr_i; |
|
114 | 114 |
Distri distri; |
115 |
- InetSocketAddress addr; |
|
115 |
+ InetSocketAddress [] addrs; |
|
116 | 116 |
|
117 | 117 |
// get distributor number |
118 | 118 |
try { |
... | ... |
@@ -130,14 +130,31 @@ class Config |
130 | 130 |
errorExc(String.format("no distributor with number \"%d\"" + |
131 | 131 |
" in line %d of config file", dist, m_lineNo)); |
132 | 132 |
|
133 |
- // get address |
|
134 |
- addr = AddrParser.parseAddr(value); |
|
135 |
- if (addr == null) { |
|
133 |
+ // check if maximum number of addresses reached |
|
134 |
+ if (distri.m_addrs != null && |
|
135 |
+ distri.m_addrs.length > Constants.addrMaxCnt) { |
|
136 |
+ errorExc(String.format("too many addresses (\"%s\") for distributor" + |
|
137 |
+ " with number \"%u\" in line %u of config file\n", |
|
138 |
+ value, dist, m_lineNo)); |
|
139 |
+ } |
|
140 |
+ |
|
141 |
+ // get address andd add it to distributor |
|
142 |
+ if (distri.m_addrs != null) { |
|
143 |
+ addr_cnt = distri.m_addrs.length; |
|
144 |
+ } else { |
|
145 |
+ addr_cnt = 0; |
|
146 |
+ } |
|
147 |
+ addrs = new InetSocketAddress [addr_cnt + 1]; |
|
148 |
+ for (addr_i = 0; addr_i < addr_cnt; ++addr_i) { |
|
149 |
+ addrs[addr_i] = distri.m_addrs[addr_i]; |
|
150 |
+ } |
|
151 |
+ addrs[addr_cnt] = AddrParser.parseAddr(value); |
|
152 |
+ if (addrs[addr_cnt] == null) { |
|
136 | 153 |
errorExc("invalid addess \"" + value + |
137 | 154 |
"\" for distributor with number \"%u\"" + |
138 | 155 |
String.format(" in line %d of config file", m_lineNo)); |
139 | 156 |
} |
140 |
- distri.m_addr = addr; |
|
157 |
+ distri.m_addrs = addrs; |
|
141 | 158 |
} |
142 | 159 |
|
143 | 160 |
/** |
... | ... |
@@ -427,6 +444,22 @@ class Config |
427 | 444 |
procSetting(setting, value); |
428 | 445 |
} |
429 | 446 |
|
447 |
+ /** |
|
448 |
+ * @brief set default addresses of distributors |
|
449 |
+ */ |
|
450 |
+ void setDefDistriAddrs() |
|
451 |
+ { |
|
452 |
+ int i; |
|
453 |
+ Distri distri; |
|
454 |
+ |
|
455 |
+ for (i = 0; i < m_display.m_distris.length; ++i) { |
|
456 |
+ distri = m_display.m_distris[i]; |
|
457 |
+ if (distri != null) { |
|
458 |
+ distri.addrDef(); |
|
459 |
+ } |
|
460 |
+ } |
|
461 |
+ } |
|
462 |
+ |
|
430 | 463 |
/** |
431 | 464 |
* @brief process config file |
432 | 465 |
* |
... | ... |
@@ -465,6 +498,9 @@ class Config |
465 | 498 |
br.close(); |
466 | 499 |
fr.close(); |
467 | 500 |
|
501 |
+ // set default addresses of distributors |
|
502 |
+ setDefDistriAddrs(); |
|
503 |
+ |
|
468 | 504 |
info(String.format("%dx%d input format, ", m_display.m_size.m_x, |
469 | 505 |
m_display.m_size.m_y) + |
470 | 506 |
String.format("%d distributors, ", m_display.m_distriCnt ) + |
... | ... |
@@ -26,6 +26,8 @@ class Constants |
26 | 26 |
* that can be in the system, |
27 | 27 |
* number of distributor addresses |
28 | 28 |
* available */ |
29 |
+ static int addrMaxCnt = 8; /**< maximum number of network address(es) |
|
30 |
+ * for a distributor */ |
|
29 | 31 |
static int outputMaxCnt = 128; /**< maximum number of outputs per |
30 | 32 |
* distributor */ |
31 | 33 |
static int pixelMaxCnt = 1024; /**< maximum number of pixels that can |
... | ... |
@@ -160,7 +160,7 @@ public class Display |
160 | 160 |
/// send image data to distributors |
161 | 161 |
public void send() |
162 | 162 |
{ |
163 |
- int dist; |
|
163 |
+ int dist, addr_i; |
|
164 | 164 |
Distri distri; |
165 | 165 |
|
166 | 166 |
// send data to all distributors |
... | ... |
@@ -168,15 +168,17 @@ public class Display |
168 | 168 |
distri = m_distris[dist]; |
169 | 169 |
if (distri != null) { |
170 | 170 |
|
171 |
- if (distri.m_addr != null) { |
|
171 |
+ if (distri.m_addrs != null) { |
|
172 |
+ // send message as UDP packet to each address |
|
173 |
+ for (addr_i = 0; addr_i < distri.m_addrs.length; ++addr_i) { |
|
172 | 174 |
try { |
173 |
- // send message as UDP packet |
|
174 | 175 |
DatagramPacket pack = new DatagramPacket(distri.m_msgBuf, |
175 | 176 |
distri.m_msgBuf.length, |
176 |
- distri.m_addr); |
|
177 |
+ distri.m_addrs[addr_i]); |
|
177 | 178 |
m_sock.send(pack); |
178 | 179 |
} catch (java.io.IOException e) { |
179 | 180 |
} |
181 |
+ } // for addr_i |
|
180 | 182 |
} |
181 | 183 |
|
182 | 184 |
} // if distri |
... | ... |
@@ -37,22 +37,6 @@ class Distri |
37 | 37 |
m_outputCnt = outputCnt; |
38 | 38 |
m_pixelCnt = pixelCnt; |
39 | 39 |
|
40 |
- // initialize address to default |
|
41 |
- try { |
|
42 |
- int intIp = Constants.destIpBase + |
|
43 |
- m_distri * Constants.destIpStep; |
|
44 |
- byte [] byteIp = { |
|
45 |
- (byte)(intIp >> 24), |
|
46 |
- (byte)(intIp >> 16), |
|
47 |
- (byte)(intIp >> 8), |
|
48 |
- (byte)intIp |
|
49 |
- }; |
|
50 |
- m_addr = new InetSocketAddress(InetAddress.getByAddress(byteIp), |
|
51 |
- Constants.destPort); |
|
52 |
- } catch (java.io.IOException e) { |
|
53 |
- m_addr = null; |
|
54 |
- } |
|
55 |
- |
|
56 | 40 |
// allocate default mappings |
57 | 41 |
m_mapRed = new Mapping(); |
58 | 42 |
m_mapGreen = new Mapping(); |
... | ... |
@@ -71,10 +55,36 @@ class Distri |
71 | 55 |
m_msgBuf[Constants.mcufOfsPixelsU16 + 1] = (byte)m_pixelCnt; |
72 | 56 |
} |
73 | 57 |
|
58 |
+ /** |
|
59 |
+ * @brief initialize address to default if no address is set |
|
60 |
+ */ |
|
61 |
+ void addrDef() |
|
62 |
+ { |
|
63 |
+ if (m_addrs == null) { |
|
64 |
+ try { |
|
65 |
+ int intIp = Constants.destIpBase + |
|
66 |
+ m_distri * Constants.destIpStep; |
|
67 |
+ byte [] byteIp = { |
|
68 |
+ (byte)(intIp >> 24), |
|
69 |
+ (byte)(intIp >> 16), |
|
70 |
+ (byte)(intIp >> 8), |
|
71 |
+ (byte)intIp |
|
72 |
+ }; |
|
73 |
+ m_addrs = new InetSocketAddress[1]; |
|
74 |
+ m_addrs[0] = new InetSocketAddress(InetAddress.getByAddress(byteIp), |
|
75 |
+ Constants.destPort); |
|
76 |
+ } catch (java.io.IOException e) { |
|
77 |
+ m_addrs = null; |
|
78 |
+ } |
|
79 |
+ } |
|
80 |
+ } |
|
81 |
+ |
|
74 | 82 |
int m_distri; ///< number of this distributor |
75 | 83 |
int m_outputCnt; ///< number of outputs |
76 | 84 |
int m_pixelCnt; ///< number pixels connected to every output |
77 |
- InetSocketAddress m_addr; ///< network address of distributor |
|
85 |
+ InetSocketAddress [] m_addrs; /**< network address(es) of distributor, |
|
86 |
+ multiple addresses mean the packets are |
|
87 |
+ sent to each address */ |
|
78 | 88 |
Mapping m_mapRed; ///< mapping information for red channel |
79 | 89 |
Mapping m_mapGreen; ///< mapping information for Green channel |
80 | 90 |
Mapping m_mapBlue; ///< mapping information for blue channel |
81 | 91 |