PlcCommunicaterのsendBufferをフィールド共有から、毎回allocateするように変更
特に必要ないためByteBufferのdirectAllocateを全てallocateに変更
@@ -1,4 +1,4 @@ | ||
1 | -version=2.1.33 | |
1 | +version=2.1.34 | |
2 | 2 | license1=<html>\ |
3 | 3 | <body style="font\:Serif">\ |
4 | 4 | <p style="font-size\:1.3em">F-11</p><br> |
@@ -79,7 +79,7 @@ | ||
79 | 79 | sendData = ByteBuffer.wrap(WifeUtilities.toByteArray("c0000209080706050403020110ff")); |
80 | 80 | waiter.syncSendRecv(sendData, recvData); |
81 | 81 | assertEquals(0, recvData.remaining()); |
82 | - | |
82 | + | |
83 | 83 | // クローズ |
84 | 84 | waiter.close(); |
85 | 85 | } |
@@ -152,7 +152,7 @@ | ||
152 | 152 | sendData = ByteBuffer.wrap(WifeUtilities.toByteArray("c0000209080706050403020110ff")); |
153 | 153 | waiter.syncSendRecv(sendData, recvData); |
154 | 154 | assertEquals(0, recvData.remaining()); |
155 | - | |
155 | + | |
156 | 156 | // クローズ |
157 | 157 | waiter.close(); |
158 | 158 | } |
@@ -306,7 +306,7 @@ | ||
306 | 306 | private ServerSocketChannel serverSocketChannel; |
307 | 307 | private final int port; |
308 | 308 | |
309 | - private ByteBuffer buffer = ByteBuffer.allocateDirect(1024); | |
309 | + private ByteBuffer buffer = ByteBuffer.allocate(1024); | |
310 | 310 | |
311 | 311 | public TcpServer(int port) throws Exception { |
312 | 312 | this.port = port; |
@@ -60,7 +60,7 @@ | ||
60 | 60 | private SendData sendData; |
61 | 61 | |
62 | 62 | /** 受信バッファ */ |
63 | - private final ByteBuffer recvBuffer = ByteBuffer.allocateDirect(2048); | |
63 | + private final ByteBuffer recvBuffer = ByteBuffer.allocate(2048); | |
64 | 64 | |
65 | 65 | /** リスナーのマップ */ |
66 | 66 | private final Map<String, RecvListener> id2listenerMap = Collections |
@@ -78,7 +78,7 @@ | ||
78 | 78 | } |
79 | 79 | |
80 | 80 | /* |
81 | - * IDKey生成テスト | |
81 | + * IDKey生成テスト | |
82 | 82 | */ |
83 | 83 | public void testMakeIDKey() throws Exception { |
84 | 84 | TcpPortChannel port = |
@@ -281,7 +281,7 @@ | ||
281 | 281 | private ServerSocketChannel serverSocketChannel; |
282 | 282 | private final int port; |
283 | 283 | |
284 | - private ByteBuffer buffer = ByteBuffer.allocateDirect(1024); | |
284 | + private ByteBuffer buffer = ByteBuffer.allocate(1024); | |
285 | 285 | |
286 | 286 | public TcpServer(int port) throws Exception { |
287 | 287 | this.port = port; |
@@ -40,6 +40,7 @@ | ||
40 | 40 | import org.F11.scada.WifeUtilities; |
41 | 41 | import org.F11.scada.server.converter.Converter; |
42 | 42 | import org.F11.scada.server.converter.FINS; |
43 | +import org.F11.scada.server.converter.FINSTCP; | |
43 | 44 | import org.F11.scada.server.event.WifeCommand; |
44 | 45 | |
45 | 46 | /** |
@@ -166,7 +167,7 @@ | ||
166 | 167 | return 5001; |
167 | 168 | } |
168 | 169 | public String getPlcCommKind() { |
169 | - return "FINS"; | |
170 | + return "FINSTCP"; | |
170 | 171 | } |
171 | 172 | public int getPlcNetNo() { |
172 | 173 | return 1; |
@@ -202,7 +203,7 @@ | ||
202 | 203 | return 5; |
203 | 204 | } |
204 | 205 | }; |
205 | - commTcp = new PlcCommunicater(device, converter); | |
206 | + commTcp = new PlcCommunicater(device, new FINSTCP()); | |
206 | 207 | System.out.println("setUp end"); |
207 | 208 | } |
208 | 209 |
@@ -426,16 +427,19 @@ | ||
426 | 427 | private final int port; |
427 | 428 | private Map<String, byte[]> resMap = new HashMap<String, byte[]>(); |
428 | 429 | |
429 | - private ByteBuffer recvBuffer = ByteBuffer.allocateDirect(1024); | |
430 | + private ByteBuffer recvBuffer = ByteBuffer.allocate(2048); | |
430 | 431 | private ByteBuffer sendBuffer = ByteBuffer.allocate(2048); |
431 | 432 | |
432 | 433 | public TcpServer(int port) throws Exception { |
433 | - resMap.put("01028200000000011234", | |
434 | + resMap.put("46494e530000000c000000000000000000000005", WifeUtilities.toByteArray("00000000000000000005")); | |
435 | + resMap.put("46494e530000001c00000002000000008000020102030405000101028200000000011234", | |
434 | 436 | WifeUtilities.toByteArray("01020000")); |
435 | - resMap.put("0101820000000001", | |
437 | + resMap.put("46494e530000001a0000000200000000800002010203040500010101820000000001", | |
436 | 438 | WifeUtilities.toByteArray("010100001234")); |
437 | - resMap.put("0101820000000004", | |
439 | + resMap.put("46494e530000001a0000000200000000800002010203040500020101820000000004", | |
438 | 440 | WifeUtilities.toByteArray("010100001234567887654321")); |
441 | + resMap.put("46494e530000001a0000000200000000800002010203040500010101820000000004", | |
442 | + WifeUtilities.toByteArray("010100001234567887654321")); | |
439 | 443 | |
440 | 444 | this.port = port; |
441 | 445 | selector = SelectorProvider.provider().openSelector(); |
@@ -480,21 +484,32 @@ | ||
480 | 484 | |
481 | 485 | Thread.yield(); |
482 | 486 | |
483 | - byte[] recvData = new byte[recvBuffer.remaining() - 10]; | |
484 | - recvBuffer.position(10); | |
487 | + byte[] recvData = new byte[recvBuffer.remaining()]; | |
488 | + recvBuffer.position(0); | |
485 | 489 | recvBuffer.get(recvData); |
490 | +// System.out.println("recvData=" + WifeUtilities.toString(recvData)); | |
491 | + recvBuffer.flip(); | |
486 | 492 | byte[] sendData = resMap.get(WifeUtilities.toString(recvData)); |
493 | +// System.out.println("sendData=" + sendData); | |
487 | 494 | if (sendData != null) { |
488 | - sendBuffer.clear(); | |
489 | - sendBuffer.put(WifeUtilities.toByteArray("c00002")); | |
490 | - sendBuffer.put(recvBuffer.get(6)); | |
491 | - sendBuffer.put(recvBuffer.get(7)); | |
492 | - sendBuffer.put(recvBuffer.get(8)); | |
493 | - sendBuffer.put(recvBuffer.get(3)); | |
494 | - sendBuffer.put(recvBuffer.get(4)); | |
495 | - sendBuffer.put(recvBuffer.get(5)); | |
496 | - sendBuffer.put(recvBuffer.get(9)); | |
497 | - sendBuffer.put(sendData).flip(); | |
495 | + if ("00000000000000000005".equals(WifeUtilities.toString(sendData))) { | |
496 | + sendBuffer.clear(); | |
497 | + sendBuffer.put(WifeUtilities.toByteArray("46494e530000001c0000000200000000")); | |
498 | + sendBuffer.put(WifeUtilities.toByteArray("c00002")); | |
499 | + sendBuffer.put(sendData).flip(); | |
500 | + } else { | |
501 | + sendBuffer.clear(); | |
502 | + sendBuffer.put(WifeUtilities.toByteArray("46494e530000001c0000000200000000")); | |
503 | + sendBuffer.put(WifeUtilities.toByteArray("c00002")); | |
504 | + sendBuffer.put(recvBuffer.get(22)); | |
505 | + sendBuffer.put(recvBuffer.get(23)); | |
506 | + sendBuffer.put(recvBuffer.get(24)); | |
507 | + sendBuffer.put(recvBuffer.get(19)); | |
508 | + sendBuffer.put(recvBuffer.get(20)); | |
509 | + sendBuffer.put(recvBuffer.get(21)); | |
510 | + sendBuffer.put(recvBuffer.get(25)); | |
511 | + sendBuffer.put(sendData).flip(); | |
512 | + } | |
498 | 513 | System.out.println("server:" |
499 | 514 | + WifeUtilities.toString(sendBuffer)); |
500 | 515 | } else { |
@@ -45,11 +45,11 @@ | ||
45 | 45 | private volatile LinkageCommand linkageCommand; |
46 | 46 | |
47 | 47 | /** 送信バッファ */ |
48 | - private ByteBuffer sendBuffer = ByteBuffer.allocateDirect(2048); | |
48 | +// private ByteBuffer sendBuffer = ByteBuffer.allocate(2048); | |
49 | 49 | /** 受信バッファ */ |
50 | - private ByteBuffer recvBuffer = ByteBuffer.allocateDirect(2048); | |
50 | + private ByteBuffer recvBuffer = ByteBuffer.allocate(2048); | |
51 | 51 | /** 読込みデータバッファ */ |
52 | - private ByteBuffer recvData = ByteBuffer.allocateDirect(2048); | |
52 | + private ByteBuffer recvData = ByteBuffer.allocate(2048); | |
53 | 53 | /** FINS/TCPプロトコル通信の有無 */ |
54 | 54 | private boolean isFinsTcp; |
55 | 55 |
@@ -191,12 +191,13 @@ | ||
191 | 191 | InterruptedException { |
192 | 192 | recvData.clear(); |
193 | 193 | while (converter.hasCommand()) { |
194 | + ByteBuffer sendBuffer = ByteBuffer.allocate(2048); | |
194 | 195 | sendBuffer.clear(); |
195 | 196 | converter.nextCommand(sendBuffer); |
196 | 197 | sendBuffer.flip(); |
197 | 198 | // 送信後受信待ち |
198 | 199 | waiter.syncSendRecv(sendBuffer, recvBuffer); |
199 | - WifeException ex = checkError(); | |
200 | + WifeException ex = checkError(sendBuffer); | |
200 | 201 | // エラー発生なら試行を繰り返す |
201 | 202 | for (int i = 0; i < device.getPlcRetryCount() && ex != null; i++) { |
202 | 203 | if (ex != null) { |
@@ -209,7 +210,7 @@ | ||
209 | 210 | sendBuffer.flip(); |
210 | 211 | // 送信後受信待ち |
211 | 212 | waiter.syncSendRecv(sendBuffer, recvBuffer); |
212 | - ex = checkError(); | |
213 | + ex = checkError(sendBuffer); | |
213 | 214 | } |
214 | 215 | // エラー発生ならば、二重化PLCと通信 |
215 | 216 | if (ex != null && device.getPlcIpAddress2() != null |
@@ -224,7 +225,7 @@ | ||
224 | 225 | sendBuffer.flip(); |
225 | 226 | // 送信後受信待ち |
226 | 227 | waiter.syncSendRecv(sendBuffer, recvBuffer); |
227 | - ex = checkError(); | |
228 | + ex = checkError(sendBuffer); | |
228 | 229 | // エラー発生なら試行を繰り返す |
229 | 230 | for (int i = 0; i < device.getPlcRetryCount() && ex != null; i++) { |
230 | 231 | if (ex != null) { |
@@ -237,7 +238,7 @@ | ||
237 | 238 | sendBuffer.flip(); |
238 | 239 | // 送信後受信待ち |
239 | 240 | waiter.syncSendRecv(sendBuffer, recvBuffer); |
240 | - ex = checkError(); | |
241 | + ex = checkError(sendBuffer); | |
241 | 242 | } |
242 | 243 | } |
243 | 244 | // FINS/TCPでエラー発生ならばポートを再オープン |
@@ -251,7 +252,7 @@ | ||
251 | 252 | sendBuffer.flip(); |
252 | 253 | // 送信後受信待ち |
253 | 254 | waiter.syncSendRecv(sendBuffer, recvBuffer); |
254 | - ex = checkError(); | |
255 | + ex = checkError(sendBuffer); | |
255 | 256 | // エラー発生なら試行を繰り返す |
256 | 257 | for (int i = 0; i < device.getPlcRetryCount() && ex != null; i++) { |
257 | 258 | if (ex != null) { |
@@ -264,7 +265,7 @@ | ||
264 | 265 | sendBuffer.flip(); |
265 | 266 | // 送信後受信待ち |
266 | 267 | waiter.syncSendRecv(sendBuffer, recvBuffer); |
267 | - ex = checkError(); | |
268 | + ex = checkError(sendBuffer); | |
268 | 269 | } |
269 | 270 | } |
270 | 271 |
@@ -279,7 +280,7 @@ | ||
279 | 280 | recvData.flip(); |
280 | 281 | } |
281 | 282 | |
282 | - private WifeException checkError() throws WifeException, | |
283 | + private WifeException checkError(ByteBuffer sendBuffer) throws WifeException, | |
283 | 284 | InterruptedException { |
284 | 285 | WifeException ex = null; |
285 | 286 | if (recvBuffer.remaining() <= 0) { |
@@ -348,7 +348,7 @@ | ||
348 | 348 | private ServerSocketChannel serverSocketChannel; |
349 | 349 | private final int port; |
350 | 350 | |
351 | - private ByteBuffer buffer = ByteBuffer.allocateDirect(1024); | |
351 | + private ByteBuffer buffer = ByteBuffer.allocate(1024); | |
352 | 352 | |
353 | 353 | public TcpServer(int port) throws Exception { |
354 | 354 | this.port = port; |
@@ -56,7 +56,7 @@ | ||
56 | 56 | private SendData sendData; |
57 | 57 | |
58 | 58 | /** 受信バッファ */ |
59 | - private final ByteBuffer recvBuffer = ByteBuffer.allocateDirect(2048); | |
59 | + private final ByteBuffer recvBuffer = ByteBuffer.allocate(2048); | |
60 | 60 | |
61 | 61 | /** リスナーのマップ */ |
62 | 62 | private final Map<String, RecvListener> id2listenerMap = |