|
@ -0,0 +1,41 @@ |
|
|
|
|
|
package com.iflytop.gd.hardware.service; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.iflytop.gd.common.cmd.DeviceCommand; |
|
|
|
|
|
import com.iflytop.gd.hardware.command.CommandHandler; |
|
|
|
|
|
import com.iflytop.gd.hardware.command.SupportDevice.CmdDevice; |
|
|
|
|
|
import com.iflytop.gd.hardware.command.SupportMethod; |
|
|
|
|
|
import com.iflytop.gd.hardware.command.command_handler.FanHandler; |
|
|
|
|
|
|
|
|
|
|
|
import java.security.InvalidParameterException; |
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
public class HardwareService { |
|
|
|
|
|
private final Map<String, CommandHandler> cmdHandlers = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
public void post_initialize() |
|
|
|
|
|
{ |
|
|
|
|
|
cmdHandlers.put(CmdDevice.FAN1.getStrValue(), new FanHandler(0)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boolean sendCommand(DeviceCommand cmd) |
|
|
|
|
|
{ |
|
|
|
|
|
String strMethod = cmd.getCmdCode(); |
|
|
|
|
|
|
|
|
|
|
|
SupportMethod.checkMethod(strMethod); |
|
|
|
|
|
|
|
|
|
|
|
if(cmdHandlers.containsKey(cmd.getDevice())) { |
|
|
|
|
|
return cmdHandlers.get(cmd.getDevice()).execute(command); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
throw new InvalidParameterException(StringHelper.format("[Device]: {}", command.getDevice())); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 这里或者搞成自定义结构体 |
|
|
|
|
|
void sendCmdResponse(int cmdId, int resultCode, String resultMsg) |
|
|
|
|
|
{ |
|
|
|
|
|
// 发送命令成功 |
|
|
|
|
|
} |
|
|
|
|
|
} |