|
|
@ -3,6 +3,7 @@ package a8k.base_hardware; |
|
|
|
import a8k.a8k_can_protocol.*; |
|
|
|
import a8k.a8k_can_protocol.MId; |
|
|
|
import a8k.appbean.HardwareException; |
|
|
|
import a8k.appbean.Pos2d; |
|
|
|
import a8k.appbean.appevent.A8kHardwareReport; |
|
|
|
import a8k.service.AppEventBusService; |
|
|
|
import a8k.utils.ByteArray; |
|
|
@ -112,8 +113,7 @@ public class A8kCanBusService { |
|
|
|
client.connect(); |
|
|
|
} 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(); |
|
|
|
} |
|
|
|
} |
|
|
@ -140,9 +140,6 @@ public class A8kCanBusService { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
|
// module opeation |
|
|
|
// |
|
|
@ -182,24 +179,54 @@ public class A8kCanBusService { |
|
|
|
callcmd(id.toInt(), CmdId.kmodule_active_cfg); |
|
|
|
} |
|
|
|
|
|
|
|
// public static final int kxymotor_enable = 0x0301; |
|
|
|
// public static final int kxymotor_move_by = 0x0302; |
|
|
|
// public static final int kxymotor_move_to = 0x0303; |
|
|
|
// public static final int kxymotor_move_to_zero = 0x0304; |
|
|
|
// public static final int kxymotor_read_pos = 0x0306; |
|
|
|
// public static final int kxymotor_read_inio_index_in_stm32 = 0x0307; |
|
|
|
// public static final int kxymotor_read_inio = 0x0308; |
|
|
|
// public static final int kxymotor_set_pos = 0x0309; |
|
|
|
// public static final int kxymotor_motor_move_by_direct = 0x030a; |
|
|
|
// public static final int kxymotor_read_enc_direct = 0x030b; |
|
|
|
|
|
|
|
public void hbotEnable(MId mid, int enable) throws HardwareException { |
|
|
|
callcmd(mid.toInt(), CmdId.kxymotor_enable, enable); |
|
|
|
} |
|
|
|
|
|
|
|
public void hbotMoveBy(MId mid, int x, int y) throws HardwareException { |
|
|
|
callcmd(mid.toInt(), CmdId.kxymotor_move_by, x, y); |
|
|
|
} |
|
|
|
|
|
|
|
public void hbotMoveTo(MId mid, int x, int y) throws HardwareException { |
|
|
|
callcmd(mid.toInt(), CmdId.kxymotor_move_to, x, y); |
|
|
|
} |
|
|
|
|
|
|
|
public void hbotMoveToZero(MId mid) throws HardwareException { |
|
|
|
callcmd(mid.toInt(), CmdId.kxymotor_move_to_zero); |
|
|
|
} |
|
|
|
|
|
|
|
public Pos2d hbotReadPos(MId mid) throws HardwareException { |
|
|
|
Pos2d pos = new Pos2d(0, 0); |
|
|
|
var packet = callcmd(mid.toInt(), CmdId.kxymotor_read_pos); |
|
|
|
pos.x = packet.getContentI32(0); |
|
|
|
pos.y = packet.getContentI32(1); |
|
|
|
return pos; |
|
|
|
} |
|
|
|
|
|
|
|
public int hbotReadInio(MId mid) throws HardwareException { |
|
|
|
var packet = callcmd(mid.toInt(), CmdId.kxymotor_read_inio); |
|
|
|
return packet.getContentI32(0); |
|
|
|
} |
|
|
|
|
|
|
|
public void hbotSetPos(MId mid, int x, int y) throws HardwareException { |
|
|
|
callcmd(mid.toInt(), CmdId.kxymotor_set_pos, x, y); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void hbotMoveByDirect(MId mid, int motor1_dpos, int motor2_dpos) throws HardwareException { |
|
|
|
callcmd(mid.toInt(), CmdId.kxymotor_motor_move_by_direct, motor1_dpos, motor2_dpos); |
|
|
|
} |
|
|
|
|
|
|
|
public int hbotReadEncDirect(MId mid) throws HardwareException { |
|
|
|
var packet = callcmd(mid.toInt(), CmdId.kxymotor_read_enc_direct); |
|
|
|
return packet.getContentI32(0); |
|
|
|
} |
|
|
|
|
|
|
|
public int hbotReadInioIndexInStm32(MId mid, int ioIndex) throws HardwareException { |
|
|
|
var packet = callcmd(mid.toInt(), CmdId.kxymotor_read_inio_index_in_stm32, ioIndex); |
|
|
|
return packet.getContentI32(0); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
@ -355,38 +382,31 @@ public class A8kCanBusService { |
|
|
|
return this.callcmd(moduleId, cmdId, new Integer[]{p0, p1}); |
|
|
|
} |
|
|
|
|
|
|
|
public A8kPacket callcmd(Integer moduleId, Integer cmdId, Integer p0, Integer p1, Integer p2) |
|
|
|
throws HardwareException { |
|
|
|
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 { |
|
|
|
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 { |
|
|
|
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 { |
|
|
|
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 { |
|
|
|
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 { |
|
|
|
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 acitionOvertime) |
|
|
|
throws HardwareException, InterruptedException { |
|
|
|
public void callblockcmd(Integer moduleId, Integer cmdId, Integer acitionOvertime) throws HardwareException, InterruptedException { |
|
|
|
this.callblockcmd(moduleId, cmdId, new Integer[]{}, acitionOvertime); |
|
|
|
} |
|
|
|
|
|
|
@ -413,7 +433,9 @@ public class A8kCanBusService { |
|
|
|
try { |
|
|
|
return this.sendCmd(pack, A8kPacket.CMD_OVERTIME); |
|
|
|
} catch (HardwareException e) { |
|
|
|
if (e.getErrorCode() != A8kEcode.Overtime.toInt()); { |
|
|
|
if (e.getErrorCode() != A8kEcode.Overtime.toInt()) |
|
|
|
; |
|
|
|
{ |
|
|
|
throw e; |
|
|
|
} |
|
|
|
} |
|
|
@ -421,8 +443,7 @@ public class A8kCanBusService { |
|
|
|
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); |
|
|
|
this.sendCmdAutoResend(packet, A8kPacket.CMD_OVERTIME); |
|
|
|
|
|
|
@ -505,8 +526,7 @@ public class A8kCanBusService { |
|
|
|
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 (waitingReceiptIndex == packet.getPacketIndex()) { |
|
|
|
receiptQueue.add(packet); |
|
|
|