Open sources are helping a lot in developing DLMS.
Because of the GPRS dynamic IP, the meter is being developed as client mode. When using the attach function of GXNet.java using an example source, the socket receiverThread is alive and cannot be synchronized.
I added interrupt of the receiverThread in the ListenerThread.java and it synchronizes well.
However, when the first packet is sent and the response is received, the first 0x00 is not received, so the wrapper cannot be processed.
I solved it by adding 0x00, but it did not solve the root cause.
Is it possible to update the source?
Forums
Hi, Is the meter sending the…
Hi,
Is the meter sending the first 0x00 and it is lost? This is used with dynamic TCP/IP meters that are using WRAPPER. Can you tell a little nit more about this?
BR,
Mikko
Hi, Below is an output of…
Hi,
Below is an output of tcpdump and ReceiveParameters' reply for aarq and aare by calling the attach function.
- AARQ
TX: 00 01 00 01 00 01 00 38 60 36 A1 09 06 07 60 85 74 05 08 01 01 8A 02 07 80 8B 07 60 85 74 05 08 02 01 AC 0A 80 08 31 32 33 34 35 36 37 38 BE 10 04 0E 01 00 00 00 06 5F 1F 04 00 42 1E 5D FF FF
- AARQ tcpdump
09:42:19.040382 IP 192.168.0.221.dsmeter_iatc > 172.56.201.252.11681: Flags [P.], seq 2321643238:2321643302, ack 2952634414, win 4096, length 64
0x0000: 4500 0068 0000 4000 4006 02d6 c0a8 00dd E..h..@.@.......
0x0010: ac38 c9fc 0fdc 2da1 8a61 76e6 affd a02e .8....-..av.....
0x0020: 5018 1000 d8cf 0000 0001 0001 0001 0038 P..............8
0x0030: 6036 a109 0607 6085 7405 0801 018a 0207 `6....`.t.......
0x0040: 808b 0760 8574 0508 0201 ac0a 8008 3132 ...`.t........12
0x0050: 3334 3536 3738 be10 040e 0100 0000 065f 345678........._
0x0060: 1f04 0042 1e5d ffff ...B.]..
- AARE
RX: 01 00 01 00 01 00 2B 61 29 A1 09 06 07 60 85 74 05 08 01 01 A2 03 02 01 00 A3 05 A1 03 02 01 00 BE 10 04 0E 08 00 06 5F 1F 04 00 00 18 1D 00 F3 00 07
- AARE tcpdump
09:42:19.546763 IP 172.56.201.252.11681 > 192.168.0.221.dsmeter_iatc: Flags [.], ack 64, win 16320, length 0
0x0000: 4500 0028 0000 0000 ef06 9415 ac38 c9fc E..(.........8..
0x0010: c0a8 00dd 2da1 0fdc affd a02e 8a61 7726 ....-........aw&
0x0020: 5010 3fc0 a928 0000 0000 0000 0000 P.?..(........
09:42:19.826285 IP 172.56.201.252.11681 > 192.168.0.221.dsmeter_iatc: Flags [P.], seq 1:52, ack 64, win 16384, length 51
0x0000: 4500 005b 0000 0000 ef06 93e2 ac38 c9fc E..[.........8..
0x0010: c0a8 00dd 2da1 0fdc affd a02e 8a61 7726 ....-........aw&
0x0020: 5018 4000 df02 0000 0001 0001 0001 002b P.@............+
0x0030: 6129 a109 0607 6085 7405 0801 01a2 0302 a)....`.t.......
0x0040: 0100 a305 a103 0201 00be 1004 0e08 0006 ................
0x0050: 5f1f 0400 0018 1d00 f300 07 _..........
Below is a code that uses your example as it is and adds an exception because 0x00 was missing in the first response. From the second response, it is normal.
synchronized (media.getSynchronous()) {
while ( !succeeded ) {
if ( !reply.isStreaming() ) {
log.debug("{}\r\nTX: {}", meterNo, GXCommon.bytesToHex(data));
media.send(data, null);
}
succeeded = media.receive(p);
if ( !succeeded ) {
if (p.getEop() == null) {
p.setCount(client.getFrameSize(rd));
}
// Try to read again...
if ( pos++ == 3 ) {
throw new RuntimeException(meterNo + " : Failed to receive reply from the device in given time.");
}
log.debug("{} Data send failed. Try to resend {}/3", meterNo, pos);
}
}
// first reply without 0x00
if ( p.getReply()[0] != 0x00 ) {
log.debug("\r\nRX: {}", GXCommon.bytesToHex(p.getReply()));
byte[] temp = new byte[p.getReply().length + 1];
temp[0] = 0x00;
System.arraycopy(p.getReply(), 0, temp, 1, p.getReply().length);
rd = new GXByteBuffer(temp);
}
else {
rd = new GXByteBuffer(p.getReply());
}
BR,
Jongsung
Hi, Move media.send after…
Hi,
Move media.send after synchronous line. Something like this:
synchronized (media.getSynchronous())
{
media.send(data, null);
....
}
I believe that your TCP/IP network is so fast that the first byte is received and handled async and not sync mode.
BR,
Mikko
Hi Unfortunately, I tried…
Hi
Unfortunately, I tried the method you told me, but it didn't work out.
As you said, asynchronous ReceiveThread gets 0x00.
So, I modified the attach() function of GXNet and ListenerThread to synchronize the ReceiveThread because it seemed that the ReceiveThread running asynchronous was a problem.
I confirmed that asynchronous and synchronous modes work normally.
Below is the revised code of the attach() function and ListenerThread.
-- GXNet.attach()
synchronized (tcpIpClients) {
for (Closeable it : tcpIpClients) {
if (it instanceof Socket) {
Socket s = (Socket) it;
if (s.getRemoteSocketAddress().toString().equals(address)) {
net.socket = s;
net.hostName = hostName;
net.port = port;
// synch working, but 0x00 problem
// listenerThread.stopReceiveThread(address);
tcpIpClients.remove(s);
// reused old receiveThread
net.receiverThread = listenerThread.getReceiveThread(address);
// sync net
net.receiverThread.setParentMedia(net);
// new ReceiveThread(net, (Closeable) net.socket);
// net.receiverThread.start();
log.info("Receiver thread run:{}", address);
break;
}
}
}
}
-- ListenerThread.java
private Map<String, ReceiveThread> receiveThreadMap = new HashMap<>();
public final void run() {
...
if ( exist ) {
ReceiveThread receiver = new ReceiveThread(parentMedia,
(java.io.Closeable) socket);
// save a receiveThread to use in attach()
receiveThreadMap.put(socket.getRemoteSocketAddress().toString(), receiver);
receiver.start();
}
...
}
public ReceiveThread getReceiveThread(String address) {
return receiveThreadMap.get(address);
}
BR,
Jongsung