Quellcode durchsuchen

Add command to set LED

Fabio Battaglia vor 4 Jahren
Ursprung
Commit
1631b29d9a

+ 25 - 0
src/main/java/info/hkzlab/dupal/analyzer/board/boardio/DuPALCmdInterface.java

@@ -11,6 +11,10 @@ import info.hkzlab.dupal.analyzer.utilities.BitUtils;
 public class DuPALCmdInterface {
     private static final Logger logger = LoggerFactory.getLogger(DuPALCmdInterface.class);
 
+    public static enum DuPAL_LED {
+        P20_LED, P24_LED
+    }
+
     private final DuPALManager dpm;
     public final PALSpecs palSpecs;
 
@@ -24,6 +28,27 @@ public class DuPALCmdInterface {
         return DuPALProto.handleREADResponse(dpm.readResponse());
     }
 
+    public int getBoardVersion() {
+        dpm.writeCommand(DuPALProto.buildMODELCommand());
+        return DuPALProto.handleMODELResponse(dpm.readResponse());
+    }
+    
+    public boolean setLED(DuPAL_LED led, boolean enabled) {
+        int led_status = enabled ? 1 : 0;
+
+        switch(led) {
+            case P20_LED:
+                led_status |= 0x02;
+                break;
+            case P24_LED:
+                led_status |= 0x04;
+                break;
+        }
+
+        dpm.writeCommand(DuPALProto.buildLEDCommand(led_status));
+        return (DuPALProto.handleLEDResponse(dpm.readResponse()) == led_status);
+    }
+
     public int write(int data) throws DuPALBoardException {
         int res;
         dpm.writeCommand(DuPALProto.buildWRITECommand(data));

+ 7 - 17
src/main/java/info/hkzlab/dupal/analyzer/board/dupalproto/DuPALProto.java

@@ -3,10 +3,6 @@ package info.hkzlab.dupal.analyzer.board.dupalproto;
 import java.util.ArrayList;
 
 public class DuPALProto {
-    public static enum DuPAL_LED {
-        P20_LED, P24_LED
-    }
-
     private final static String CMD_START = ">";
     private final static String CMD_END = "<";
    
@@ -30,19 +26,8 @@ public class DuPALProto {
         return CMD_START+CMD_READ+CMD_END;
     }
 
-    public static String buildLEDCommand(DuPAL_LED led, boolean enabled) {
-        int led_status = enabled ? 1 : 0;
-
-        switch(led) {
-            case P20_LED:
-                led_status |= 0x02;
-                break;
-            case P24_LED:
-                led_status |= 0x04;
-                break;
-        }
-
-        return ""+CMD_START+CMD_LED+" "+String.format("%02X", led_status & 0xFF)+CMD_END;
+    public static String buildLEDCommand(int status) {
+        return ""+CMD_START+CMD_LED+" "+String.format("%02X", status & 0xFF)+CMD_END;
     }
 
     public static boolean isStringResponseCommand(String cmd) {
@@ -90,6 +75,10 @@ public class DuPALProto {
     public static int handleMODELResponse(final String response) {
         return handleREADResponse(response);
     }
+    
+    public static int handleLEDResponse(final String response) {
+        return handleREADResponse(response);
+    }
 
     public static int handleWRITEResponse(final String response) {
          String[] readRes = parseResponse(response);
@@ -115,6 +104,7 @@ public class DuPALProto {
             response = response.substring(1, response.length()-1).trim();
             char command = response.charAt(0);
             switch(command) {
+                case CMD_LED:
                 case CMD_MODEL:
                 case CMD_READ: 
                 case CMD_WRITE: {