|
@ -0,0 +1,77 @@ |
|
|
|
|
|
package com.iflytop.handacid.hardware.command.handlers; |
|
|
|
|
|
|
|
|
|
|
|
import com.iflytop.handacid.app.core.command.DeviceCommand; |
|
|
|
|
|
import com.iflytop.handacid.common.enums.Action; |
|
|
|
|
|
import com.iflytop.handacid.common.enums.Device; |
|
|
|
|
|
import com.iflytop.handacid.hardware.comm.can.A8kCanBusService; |
|
|
|
|
|
import com.iflytop.handacid.hardware.command.CommandHandler; |
|
|
|
|
|
import com.iflytop.handacid.hardware.drivers.BleGamepadDriver; |
|
|
|
|
|
import com.iflytop.handacid.hardware.exception.HardwareException; |
|
|
|
|
|
import com.iflytop.handacid.hardware.type.BleGamepadMid; |
|
|
|
|
|
import com.iflytop.handacid.hardware.type.MId; |
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
|
|
|
@Component |
|
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
|
public class HardwareBoardHandler extends CommandHandler { |
|
|
|
|
|
private final A8kCanBusService canBus; |
|
|
|
|
|
|
|
|
|
|
|
private final Map<Device, MId> supportCmdDeviceMIdMap = Map.ofEntries( |
|
|
|
|
|
Map.entry(Device.HARDWARE_BOARD, MId.IO1Board) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
private final Set<Action> supportActions = Set.of(Action.GET); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected Map<Device, MId> getSupportCmdDeviceMIdMap() |
|
|
|
|
|
{ |
|
|
|
|
|
return supportCmdDeviceMIdMap; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected Set<Action> getSupportActions() { |
|
|
|
|
|
return supportActions; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public Object handleCommand(DeviceCommand command) throws Exception { |
|
|
|
|
|
// 发送命令 |
|
|
|
|
|
Object result = null; |
|
|
|
|
|
Device device = command.getDevice(); |
|
|
|
|
|
if (!getSupportCmdDeviceMIdMap().containsKey(device)) { |
|
|
|
|
|
throw new IllegalArgumentException("Device " + device + " not supported by BleGamepadHandler"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (command.getAction() == Action.GET) |
|
|
|
|
|
{ |
|
|
|
|
|
String io_board_version = get_version(MId.IO1Board); |
|
|
|
|
|
String acid_board_version = get_version(MId.HandAcidBoard); |
|
|
|
|
|
result = new HashMap<String, Object>() |
|
|
|
|
|
{{ |
|
|
|
|
|
put("io_board", io_board_version); |
|
|
|
|
|
put("acid_board", acid_board_version); |
|
|
|
|
|
}}; |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String get_version(MId id) throws HardwareException { |
|
|
|
|
|
Integer verNum = canBus.moduleReadVersion(id); |
|
|
|
|
|
// 版本号格式为:主版本号.次版本号.修订号 eg.1.0.0 |
|
|
|
|
|
String version = String.format("%d.%d.%d", (verNum / 100000) % 1000, (verNum / 100) % 1000, verNum % 100); |
|
|
|
|
|
log.info("mid: {}, version: {}",id.getDescription(), version); |
|
|
|
|
|
return version; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |