|
@ -52,31 +52,29 @@ public class A8kCanBusService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private AppEventBusService eventBusService; |
|
|
private AppEventBusService eventBusService; |
|
|
|
|
|
|
|
|
public String uri; //assign by application.yml |
|
|
|
|
|
|
|
|
public String uri; // assign by application.yml |
|
|
private WebSocketClient client; |
|
|
private WebSocketClient client; |
|
|
|
|
|
|
|
|
//接收回执上下文 |
|
|
|
|
|
|
|
|
// 接收回执上下文 |
|
|
public BlockingQueue<A8kPacket> receiptQueue = new LinkedBlockingQueue<A8kPacket>(); // |
|
|
public BlockingQueue<A8kPacket> receiptQueue = new LinkedBlockingQueue<A8kPacket>(); // |
|
|
boolean isWaitingReceipt = false; // |
|
|
boolean isWaitingReceipt = false; // |
|
|
int waitingReceiptIndex = 0;// |
|
|
int waitingReceiptIndex = 0;// |
|
|
|
|
|
|
|
|
//发送包的packetIndex |
|
|
|
|
|
|
|
|
// 发送包的packetIndex |
|
|
int packetIndex = 0;// |
|
|
int packetIndex = 0;// |
|
|
|
|
|
|
|
|
//调试标志位 |
|
|
|
|
|
|
|
|
// 调试标志位 |
|
|
boolean debugFlag = false;// |
|
|
boolean debugFlag = false;// |
|
|
//websocket自动重连时间 |
|
|
|
|
|
|
|
|
// websocket自动重连时间 |
|
|
Timer autoConnectTimer = new Timer();// |
|
|
Timer autoConnectTimer = new Timer();// |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct |
|
|
@PostConstruct |
|
|
public void init() throws URISyntaxException { |
|
|
public void init() throws URISyntaxException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.info("BaseHardwareService initilized"); |
|
|
logger.info("BaseHardwareService initilized"); |
|
|
packetIndex = 0; |
|
|
packetIndex = 0; |
|
|
if (this.uri == null) { |
|
|
if (this.uri == null) { |
|
|
//this.uri = "ws://127.0.0.1:19005"; |
|
|
|
|
|
|
|
|
// this.uri = "ws://127.0.0.1:19005"; |
|
|
this.uri = "ws://192.168.8.10:19005"; |
|
|
this.uri = "ws://192.168.8.10:19005"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -104,7 +102,6 @@ public class A8kCanBusService { |
|
|
}; |
|
|
}; |
|
|
client.connect(); |
|
|
client.connect(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
autoConnectTimer.schedule(new TimerTask() { |
|
|
autoConnectTimer.schedule(new TimerTask() { |
|
|
@Override |
|
|
@Override |
|
|
public void run() { |
|
|
public void run() { |
|
@ -114,7 +111,8 @@ public class A8kCanBusService { |
|
|
client.connect(); |
|
|
client.connect(); |
|
|
} catch (IllegalStateException e) { |
|
|
} catch (IllegalStateException e) { |
|
|
} |
|
|
} |
|
|
} else if (client.getReadyState().equals(ReadyState.CLOSING) || client.getReadyState().equals(ReadyState.CLOSED)) { |
|
|
|
|
|
|
|
|
} else if (client.getReadyState().equals(ReadyState.CLOSING) |
|
|
|
|
|
|| client.getReadyState().equals(ReadyState.CLOSED)) { |
|
|
client.reconnect(); |
|
|
client.reconnect(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -125,7 +123,8 @@ public class A8kCanBusService { |
|
|
private A8kPacket packParamsToPacket(Integer moduleId, Integer cmdId, Integer[] params) { |
|
|
private A8kPacket packParamsToPacket(Integer moduleId, Integer cmdId, Integer[] params) { |
|
|
int subCmdId = cmdId & 0xFF; |
|
|
int subCmdId = cmdId & 0xFF; |
|
|
int mainCmdId = (cmdId >> 8) & 0xFFFF; |
|
|
int mainCmdId = (cmdId >> 8) & 0xFFFF; |
|
|
int bufferSize = 2 + 2 + 1 + 1 + 2 + 4 * params.length; // PacketIndex - MainCmdId - SubCmdId - CmdType - ModuleId - Parameters |
|
|
|
|
|
|
|
|
int bufferSize = 2 + 2 + 1 + 1 + 2 + 4 * params.length; // PacketIndex - MainCmdId - SubCmdId - CmdType - |
|
|
|
|
|
// ModuleId - Parameters |
|
|
ByteBuffer buffer = ByteBuffer.allocate(bufferSize); |
|
|
ByteBuffer buffer = ByteBuffer.allocate(bufferSize); |
|
|
buffer.order(ByteOrder.LITTLE_ENDIAN); |
|
|
buffer.order(ByteOrder.LITTLE_ENDIAN); |
|
|
buffer.putShort((short) 0); // PacketIndex |
|
|
buffer.putShort((short) 0); // PacketIndex |
|
@ -139,75 +138,228 @@ public class A8kCanBusService { |
|
|
return new A8kPacket(buffer.array()); |
|
|
return new A8kPacket(buffer.array()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//TODO |
|
|
|
|
|
|
|
|
// |
|
|
|
|
|
// module opeation |
|
|
|
|
|
// |
|
|
|
|
|
public void modulePing(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmodule_ping); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void moduleStop(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmodule_stop); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ModuleStatus getModuleStatus(int id) throws HardwareException { |
|
|
|
|
|
var packet = callcmd(id, CmdId.kmodule_get_status); |
|
|
|
|
|
return ModuleStatus.valueOf(packet.getContentI32(0)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void moduleSetReg(int id, RegIndex regindex, int reg) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmodule_set_reg, regindex.ordinal(), reg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int moduleGetReg(int id, RegIndex regindex) throws HardwareException { |
|
|
|
|
|
var packet = callcmd(id, CmdId.kmodule_get_reg, regindex.ordinal()); |
|
|
|
|
|
return packet.getContentI32(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int moduleGetError(int id) throws HardwareException { |
|
|
|
|
|
var packet = callcmd(id, CmdId.kmodule_get_error); |
|
|
|
|
|
return packet.getContentI32(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void moduleClearError(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmodule_clear_error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void moduleActiveCfg(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmodule_active_cfg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
|
// stepMotor |
|
|
|
|
|
// |
|
|
|
|
|
public void stepMotorEnable(int mid, int enable) throws HardwareException { |
|
|
|
|
|
callcmd(mid, CmdId.kstep_motor_enable, enable); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int stepMotorReadPos(int id) throws HardwareException { |
|
|
|
|
|
A8kPacket packet = callcmd(id, CmdId.kstep_motor_read_pos); |
|
|
|
|
|
return packet.getContentI32(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stepMotorEasyRotate(int id, int direction) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kstep_motor_easy_rotate, direction); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stepMotorEasyMoveBy(int id, int dpos) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kstep_motor_easy_move_by, dpos); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stepMotorEasyMoveTo(int id, int pos) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kstep_motor_easy_move_to, pos); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stepMotorEasyMoveToZero(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kstep_motor_easy_move_to_zero); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stepMotorEasySetCurrentPos(int id, int pos) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kstep_motor_easy_set_current_pos, pos); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stepMotorEasyMoveToIo(int id, int io) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kstep_motor_easy_move_to_io, io); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stepMotorStop(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kstep_motor_stop); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stepMotorActiveCfg(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kstep_motor_active_cfg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int stepMotorReadIoState(int id) throws HardwareException { |
|
|
|
|
|
var packet = callcmd(id, CmdId.kstep_motor_read_io_state); |
|
|
|
|
|
return packet.getContentI32(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stepMotorEasyMoveToEndPoint(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kstep_motor_easy_move_to_end_point); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void stepMotorEasyReciprocatingMotion(int id, int startpos, int endpos, int times) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kstep_motor_easy_reciprocating_motion, startpos, endpos, times); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
|
// MINI_SERVO |
|
|
|
|
|
// |
|
|
|
|
|
|
|
|
|
|
|
public void miniServoEnable(int id, int enable) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmini_servo_enable, enable); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int miniServoReadPos(int id) throws HardwareException { |
|
|
|
|
|
var packet = callcmd(id, CmdId.kmini_servo_read_pos); |
|
|
|
|
|
return packet.getContentI32(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void miniServoActiveCfg(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmini_servo_active_cfg); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void miniServoStop(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmini_servo_stop); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void miniServoSetMidPoint(int id) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmini_servo_set_mid_point); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int miniServoReadIoState(int id) throws HardwareException { |
|
|
|
|
|
var packet = callcmd(id, CmdId.kmini_servo_read_io_state); |
|
|
|
|
|
return packet.getContentI32(0); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void miniServoMoveTo(int id, int pos) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmini_servo_move_to, pos); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void miniServoRotate(int id, int direction) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmini_servo_rotate, direction); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void miniServoRotateWithTorque(int id, int torque) throws HardwareException { |
|
|
|
|
|
callcmd(id, CmdId.kmini_servo_rotate_with_torque, torque); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public boolean getIOState(IOId ioid) throws HardwareException { |
|
|
public boolean getIOState(IOId ioid) throws HardwareException { |
|
|
return false; |
|
|
|
|
|
|
|
|
if (ioid.mtype == ModuleType.kboard) { |
|
|
|
|
|
return callcmd(CmdId.kextboard_read_inio, ioid.mid, ioid.ioIndex).getContentI32(0) != 0; |
|
|
|
|
|
} else if (ioid.mtype == ModuleType.ktmc_step_motor) { |
|
|
|
|
|
return callcmd(CmdId.kstep_motor_read_io_state, ioid.mid, ioid.ioIndex).getContentI32(0) != 0; |
|
|
|
|
|
} else if (ioid.mtype == ModuleType.kmini_servo_motor_module) { |
|
|
|
|
|
return callcmd(CmdId.kmini_servo_read_io_state, ioid.mid, ioid.ioIndex).getContentI32(0) != 0; |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new HardwareException(ioid.mid, Errorcode.killegal_operation); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//TODO |
|
|
|
|
|
public void setIOState(IOId ioid, boolean val) throws HardwareException { |
|
|
public void setIOState(IOId ioid, boolean val) throws HardwareException { |
|
|
|
|
|
if (ioid.mtype == ModuleType.kboard) { |
|
|
|
|
|
callcmd(CmdId.kextboard_write_outio, ioid.mid, ioid.ioIndex, val ? 1 : 0); |
|
|
|
|
|
} else { |
|
|
|
|
|
throw new HardwareException(ioid.mid, Errorcode.killegal_operation); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId) throws HardwareException { |
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId) throws HardwareException { |
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{}); |
|
|
|
|
|
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[] {}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0) throws HardwareException { |
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0) throws HardwareException { |
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{p0}); |
|
|
|
|
|
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[] { p0 }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1) throws HardwareException { |
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1) throws HardwareException { |
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1}); |
|
|
|
|
|
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[] { p0, p1 }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2) throws HardwareException { |
|
|
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1, p2}); |
|
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2) |
|
|
|
|
|
throws HardwareException { |
|
|
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[] { p0, p1, p2 }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3) throws HardwareException { |
|
|
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1, p2, p3}); |
|
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3) |
|
|
|
|
|
throws HardwareException { |
|
|
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[] { p0, p1, p2, p3 }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{p0,p1,p2,p3}, acitionOvertime); |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer p3, |
|
|
|
|
|
Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[] { p0, p1, p2, p3 }, acitionOvertime); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{p0,p1,p2}, acitionOvertime); |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2, |
|
|
|
|
|
Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[] { p0, p1, p2 }, acitionOvertime); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{p0,p1}, acitionOvertime); |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer acitionOvertime) |
|
|
|
|
|
throws HardwareException, InterruptedException { |
|
|
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[] { p0, p1 }, acitionOvertime); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{p0}, acitionOvertime); |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer p0, Integer acitionOvertime) |
|
|
|
|
|
throws HardwareException, InterruptedException { |
|
|
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[] { p0 }, acitionOvertime); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//TODO |
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{}, acitionOvertime); |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer acitionOvertime) |
|
|
|
|
|
throws HardwareException, InterruptedException { |
|
|
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[] {}, acitionOvertime); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//TODO |
|
|
|
|
|
|
|
|
// TODO |
|
|
public Integer module_read_reg(Integer moduleId, RegIndex regindex) { |
|
|
public Integer module_read_reg(Integer moduleId, RegIndex regindex) { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
//TODO |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO |
|
|
public void module_write_reg(Integer moduleId, RegIndex regindex, Integer reg) { |
|
|
public void module_write_reg(Integer moduleId, RegIndex regindex, Integer reg) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer[] params) throws HardwareException { |
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer[] params) throws HardwareException { |
|
|
var packet = this.packParamsToPacket(moduleId, cmdId, params); |
|
|
var packet = this.packParamsToPacket(moduleId, cmdId, params); |
|
|
return this.sendCmd(packet, A8kPacket.CMD_OVERTIME); |
|
|
return this.sendCmd(packet, A8kPacket.CMD_OVERTIME); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public A8kPacket sendCmdAutoResend(A8kPacket pack, int overtime) throws HardwareException { |
|
|
public A8kPacket sendCmdAutoResend(A8kPacket pack, int overtime) throws HardwareException { |
|
|
//调用sendCmd, |
|
|
|
|
|
|
|
|
// 调用sendCmd, |
|
|
// 如果捕获到超时异常,则重发,最多重发三次 |
|
|
// 如果捕获到超时异常,则重发,最多重发三次 |
|
|
// 如果是其他异常,则直接抛出异常。 |
|
|
// 如果是其他异常,则直接抛出异常。 |
|
|
for (int i = 0; i < 3; i++) { |
|
|
for (int i = 0; i < 3; i++) { |
|
@ -222,18 +374,18 @@ public class A8kCanBusService { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer[] params, int acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
|
|
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer[] params, int acitionOvertime) |
|
|
|
|
|
throws HardwareException, InterruptedException { |
|
|
var packet = this.packParamsToPacket(moduleId, cmdId, params); |
|
|
var packet = this.packParamsToPacket(moduleId, cmdId, params); |
|
|
this.sendCmdAutoResend(packet, A8kPacket.CMD_OVERTIME); |
|
|
this.sendCmdAutoResend(packet, A8kPacket.CMD_OVERTIME); |
|
|
|
|
|
|
|
|
//调用sendCmdAutoResend |
|
|
|
|
|
|
|
|
// 调用sendCmdAutoResend |
|
|
// 通过kmodule_get_status判断指令是否完成,超时未完成则报错,则调用module_stop,同时抛出异常 |
|
|
// 通过kmodule_get_status判断指令是否完成,超时未完成则报错,则调用module_stop,同时抛出异常 |
|
|
// |
|
|
// |
|
|
|
|
|
|
|
|
long startedAt = System.currentTimeMillis(); |
|
|
long startedAt = System.currentTimeMillis(); |
|
|
do { |
|
|
do { |
|
|
var pack = this.callcmd(moduleId, CmdId.kmodule_get_status, new Integer[]{}); |
|
|
|
|
|
|
|
|
var pack = this.callcmd(moduleId, CmdId.kmodule_get_status, new Integer[] {}); |
|
|
var status = pack.getContentI32(0); |
|
|
var status = pack.getContentI32(0); |
|
|
if (0 == status) { |
|
|
if (0 == status) { |
|
|
break; |
|
|
break; |
|
@ -306,7 +458,8 @@ public class A8kCanBusService { |
|
|
logger.info("RX {}:({})", packet, rx); |
|
|
logger.info("RX {}:({})", packet, rx); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (packet.getPacketType() == A8kPacket.PACKET_TYPE_ACK || packet.getPacketType() == A8kPacket.PACKET_TYPE_ERROR_ACK) { |
|
|
|
|
|
|
|
|
if (packet.getPacketType() == A8kPacket.PACKET_TYPE_ACK |
|
|
|
|
|
|| packet.getPacketType() == A8kPacket.PACKET_TYPE_ERROR_ACK) { |
|
|
if (isWaitingReceipt) { |
|
|
if (isWaitingReceipt) { |
|
|
if (waitingReceiptIndex == packet.getPacketIndex()) { |
|
|
if (waitingReceiptIndex == packet.getPacketIndex()) { |
|
|
receiptQueue.add(packet); |
|
|
receiptQueue.add(packet); |
|
@ -321,7 +474,6 @@ public class A8kCanBusService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|
A8kCanBusService service = new A8kCanBusService(); |
|
|
A8kCanBusService service = new A8kCanBusService(); |
|
|
try { |
|
|
try { |
|
|