|
@ -1,6 +1,6 @@ |
|
|
package com.iflytop.uf.connection; |
|
|
package com.iflytop.uf.connection; |
|
|
import com.iflytop.uf.UfActiveRecord; |
|
|
import com.iflytop.uf.UfActiveRecord; |
|
|
import com.iflytop.uf.UfApplication; |
|
|
|
|
|
|
|
|
import com.iflytop.uf.UfEventBus; |
|
|
import com.iflytop.uf.model.UfMdbActuator; |
|
|
import com.iflytop.uf.model.UfMdbActuator; |
|
|
import com.iflytop.uf.model.UfMdbActuatorCmd; |
|
|
import com.iflytop.uf.model.UfMdbActuatorCmd; |
|
|
import com.iflytop.uf.util.UfByteBuffer; |
|
|
import com.iflytop.uf.util.UfByteBuffer; |
|
@ -8,13 +8,10 @@ import com.iflytop.uf.util.UfClassHelper; |
|
|
import com.iflytop.uf.util.UfCommon; |
|
|
import com.iflytop.uf.util.UfCommon; |
|
|
import org.java_websocket.client.WebSocketClient; |
|
|
import org.java_websocket.client.WebSocketClient; |
|
|
import org.java_websocket.handshake.ServerHandshake; |
|
|
import org.java_websocket.handshake.ServerHandshake; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.net.URI; |
|
|
import java.net.URI; |
|
|
import java.net.URISyntaxException; |
|
|
import java.net.URISyntaxException; |
|
|
import java.nio.ByteBuffer; |
|
|
import java.nio.ByteBuffer; |
|
|
import java.nio.ByteOrder; |
|
|
import java.nio.ByteOrder; |
|
|
import java.nio.file.Files; |
|
|
|
|
|
import java.nio.file.Path; |
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Timer; |
|
|
import java.util.Timer; |
|
@ -78,8 +75,8 @@ public class UfZcancmderWebsocket extends UfConnectionBase { |
|
|
@Override |
|
|
@Override |
|
|
synchronized public String execute(UfMdbActuatorCmd command) { |
|
|
synchronized public String execute(UfMdbActuatorCmd command) { |
|
|
UfCommon.delay(20); // 先延时个20ms,测试一下会不会死掉 |
|
|
UfCommon.delay(20); // 先延时个20ms,测试一下会不会死掉 |
|
|
|
|
|
|
|
|
var parts = command.cmdKey.split("_"); |
|
|
var parts = command.cmdKey.split("_"); |
|
|
|
|
|
|
|
|
for (int i = 0; i < parts.length; i++) { |
|
|
for (int i = 0; i < parts.length; i++) { |
|
|
parts[i] = parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1); |
|
|
parts[i] = parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1); |
|
|
} |
|
|
} |
|
@ -263,6 +260,12 @@ public class UfZcancmderWebsocket extends UfConnectionBase { |
|
|
private void handleOnTextMessage( String text ) { |
|
|
private void handleOnTextMessage( String text ) { |
|
|
ByteBuffer message = UfByteBuffer.fromHex(text); |
|
|
ByteBuffer message = UfByteBuffer.fromHex(text); |
|
|
message.order(ByteOrder.LITTLE_ENDIAN); |
|
|
message.order(ByteOrder.LITTLE_ENDIAN); |
|
|
|
|
|
byte messageType = message.get(5); |
|
|
|
|
|
if ( 0x03 == messageType ) { // event |
|
|
|
|
|
this.handleOnTextEventMessage(message); |
|
|
|
|
|
return ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
short packetIndex = message.getShort(0); |
|
|
short packetIndex = message.getShort(0); |
|
|
if ( packetIndex != this.currentPacketIndex ) { |
|
|
if ( packetIndex != this.currentPacketIndex ) { |
|
|
return ; // 可能超时了, 所以忽略掉 ~~~ |
|
|
return ; // 可能超时了, 所以忽略掉 ~~~ |
|
@ -273,7 +276,6 @@ public class UfZcancmderWebsocket extends UfConnectionBase { |
|
|
this.timeoutTimer = null; |
|
|
this.timeoutTimer = null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
byte messageType = message.get(5); |
|
|
|
|
|
if ( 0x01 == messageType ) { // ack message |
|
|
if ( 0x01 == messageType ) { // ack message |
|
|
this.handleOnTextAckMessage(message); |
|
|
this.handleOnTextAckMessage(message); |
|
|
} else if ( 0x02 == messageType ) { // error message |
|
|
} else if ( 0x02 == messageType ) { // error message |
|
@ -283,6 +285,15 @@ public class UfZcancmderWebsocket extends UfConnectionBase { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// handle on text event message |
|
|
|
|
|
private void handleOnTextEventMessage( ByteBuffer message ) { |
|
|
|
|
|
short mainCmdId = message.getShort(2); |
|
|
|
|
|
byte subCmdId = message.get(4); |
|
|
|
|
|
int eventId = mainCmdId << 8; |
|
|
|
|
|
eventId = eventId | Byte.toUnsignedInt(subCmdId); |
|
|
|
|
|
UfEventBus.getInstance().emit("ZCanCmderWebSocketEvent", eventId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// handle on text error message |
|
|
// handle on text error message |
|
|
private void handleOnTextErrorMessage(ByteBuffer message) { |
|
|
private void handleOnTextErrorMessage(ByteBuffer message) { |
|
|
Integer errorCode = message.getInt(8); |
|
|
Integer errorCode = message.getInt(8); |
|
|