// Path: app/src/main/java/in/co/gorest/grblcontroller/listeners/MachineStatusListener.java
// public static class CompileTimeOptions{
// 
//     public final boolean variableSpindle;
//     public final boolean lineNumbers;
//     public final boolean mistCoolant;
//     public final boolean coreXY;
//     public final boolean parkingMotion;
//     public final boolean homingForceOrigin;
//     public final boolean homingSingleAxis;
//     public final boolean twoLimitSwitchesOnAxis;
//     public final boolean feedRageOverrideInProbeCycles;
//     public final boolean restoreAllRom;
//     public final boolean restoreRomSettings;
//     public final boolean restoreRomParameterData;
//     public final boolean writeUserString;
//     public final boolean forceSyncOnRomWrite;
//     public final boolean forceSyncOnCoordinateChange;
//     public final boolean homingInitLock;
//     public final int plannerBuffer;
//     public final int serialRxBuffer;
// 
//     public CompileTimeOptions(String enabled, int plannerBf, int serialRxBf){
//         String enabledUpper = enabled.toUpperCase();
// 
//         variableSpindle = enabledUpper.contains("V");
//         lineNumbers = enabledUpper.contains("N");
//         mistCoolant = enabledUpper.contains("M");
//         coreXY = enabledUpper.contains("C");
//         parkingMotion = enabledUpper.contains("P");
//         homingForceOrigin = enabledUpper.contains("Z");
//         homingSingleAxis = enabledUpper.contains("H");
//         twoLimitSwitchesOnAxis = enabledUpper.contains("T");
//         feedRageOverrideInProbeCycles = enabledUpper.contains("A");
//         restoreAllRom = enabledUpper.contains("*");
//         restoreRomSettings = enabledUpper.contains("$");
//         restoreRomParameterData = enabledUpper.contains("#");
//         writeUserString = enabledUpper.contains("I");
//         forceSyncOnRomWrite = enabledUpper.contains("E");
//         forceSyncOnCoordinateChange = enabledUpper.contains("W");
//         homingInitLock = enabledUpper.contains("L");
//         plannerBuffer = plannerBf;
//         serialRxBuffer = serialRxBf;
//     }
// 
// }
// 
// Path: app/src/main/java/in/co/gorest/grblcontroller/model/Overrides.java
// public enum Overrides {
//     CMD_FEED_OVR_RESET,             // 0x90
//     CMD_FEED_OVR_COARSE_PLUS,       // 0x91
//     CMD_FEED_OVR_COARSE_MINUS,      // 0x92
//     CMD_FEED_OVR_FINE_PLUS ,        // 0x93
//     CMD_FEED_OVR_FINE_MINUS ,       // 0x94
//     CMD_RAPID_OVR_RESET,            // 0x95
//     CMD_RAPID_OVR_MEDIUM,           // 0x96
//     CMD_RAPID_OVR_LOW,              // 0x97
//     CMD_SPINDLE_OVR_RESET,          // 0x99
//     CMD_SPINDLE_OVR_COARSE_PLUS,    // 0x9A
//     CMD_SPINDLE_OVR_COARSE_MINUS,   // 0x9B
//     CMD_SPINDLE_OVR_FINE_PLUS,      // 0x9C
//     CMD_SPINDLE_OVR_FINE_MINUS,     // 0x9D
//     CMD_TOGGLE_SPINDLE,             // 0x9E
//     CMD_TOGGLE_FLOOD_COOLANT,       // 0xA0
//     CMD_TOGGLE_MIST_COOLANT,        // 0xA1
// }
// 
// Path: app/src/main/java/in/co/gorest/grblcontroller/model/Position.java
// public class Position {
//     private final Double cordX;
//     private final Double cordY;
//     private final Double cordZ;
// 
// 
//     private static final NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.ENGLISH);
//     private static final DecimalFormat decimalFormat = (DecimalFormat) numberFormat;
// 
//     public Position(double x, double y, double z){
//         this.cordX = x; this.cordY = y; this.cordZ = z;
//         decimalFormat.applyPattern("#0.###");
//     }
// 
//     public Double getCordX(){ return this.cordX; }
//     public Double getCordY(){ return this.cordY; }
//     public Double getCordZ(){ return this.cordZ; }
// 
//     private Double roundDouble(Double value){
//         String s = decimalFormat.format(value);
//         return Double.parseDouble(s);
//     }
// 
//     public boolean hasChanged(Position position){
//         return (position.getCordX().compareTo(this.cordX) != 0) || (position.getCordY().compareTo(this.cordY) != 0) || (position.getCordZ().compareTo(this.cordZ) != 0);
//     }
// 
//     public boolean atZero(){
//         return Math.abs(this.cordX) == 0 && Math.abs(this.cordY) == 0 && Math.abs(this.cordZ) == 0;
//     }
// 
// }


import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import in.co.gorest.grblcontroller.listeners.MachineStatusListener.CompileTimeOptions;
import in.co.gorest.grblcontroller.model.Overrides;
import in.co.gorest.grblcontroller.model.Position;
            String[] parts = buildOptions.split(",");
            if (parts.length >= 3) {
                int tmpPBuffer = Integer.parseInt(parts[1]);
                if (tmpPBuffer > 0) plannerBuffer = tmpPBuffer;

                int tmpRxBuffer = Integer.parseInt(parts[2]);
                if (tmpRxBuffer > 0) serialRxBuffer = tmpRxBuffer;
            }
        }

        return new CompileTimeOptions(buildOptions, plannerBuffer, serialRxBuffer);
    }

    private final static String EEPROM_COMMAND_PATTERN = "G10|G28|G30|\\$x=|\\$I|\\$N|\\$RST=|G5[456789]|\\$\\$|\\$#";
    private final static Pattern EEPROM_COMMAND = Pattern.compile(EEPROM_COMMAND_PATTERN, Pattern.CASE_INSENSITIVE);
    public static boolean hasRomAccess(String command){
        return EEPROM_COMMAND.matcher(command).find();
    }

    public static String implode(String glue, String[] array) {
        if(array == null || array.length == 0) return "";

        StringBuilder sb = new StringBuilder();
        sb.append(array[0]);
        for(int i = 1; i < array.length; i++) sb.append(glue).append(array[i]);

        return sb.toString();
    }


// Path: app/src/main/java/in/co/gorest/grblcontroller/listeners/MachineStatusListener.java
// public static class CompileTimeOptions{
// 
//     public final boolean variableSpindle;
//     public final boolean lineNumbers;
//     public final boolean mistCoolant;
//     public final boolean coreXY;
//     public final boolean parkingMotion;
//     public final boolean homingForceOrigin;
//     public final boolean homingSingleAxis;
//     public final boolean twoLimitSwitchesOnAxis;
//     public final boolean feedRageOverrideInProbeCycles;
//     public final boolean restoreAllRom;
//     public final boolean restoreRomSettings;
//     public final boolean restoreRomParameterData;
//     public final boolean writeUserString;
//     public final boolean forceSyncOnRomWrite;
//     public final boolean forceSyncOnCoordinateChange;
//     public final boolean homingInitLock;
//     public final int plannerBuffer;
//     public final int serialRxBuffer;
// 
//     public CompileTimeOptions(String enabled, int plannerBf, int serialRxBf){
//         String enabledUpper = enabled.toUpperCase();
// 
//         variableSpindle = enabledUpper.contains("V");
//         lineNumbers = enabledUpper.contains("N");
//         mistCoolant = enabledUpper.contains("M");
//         coreXY = enabledUpper.contains("C");
//         parkingMotion = enabledUpper.contains("P");
//         homingForceOrigin = enabledUpper.contains("Z");
//         homingSingleAxis = enabledUpper.contains("H");
//         twoLimitSwitchesOnAxis = enabledUpper.contains("T");
//         feedRageOverrideInProbeCycles = enabledUpper.contains("A");
//         restoreAllRom = enabledUpper.contains("*");
//         restoreRomSettings = enabledUpper.contains("$");
//         restoreRomParameterData = enabledUpper.contains("#");
//         writeUserString = enabledUpper.contains("I");
//         forceSyncOnRomWrite = enabledUpper.contains("E");
//         forceSyncOnCoordinateChange = enabledUpper.contains("W");
//         homingInitLock = enabledUpper.contains("L");
//         plannerBuffer = plannerBf;
//         serialRxBuffer = serialRxBf;
//     }
// 
// }
// 
// Path: app/src/main/java/in/co/gorest/grblcontroller/model/Overrides.java
// public enum Overrides {
//     CMD_FEED_OVR_RESET,             // 0x90
//     CMD_FEED_OVR_COARSE_PLUS,       // 0x91
//     CMD_FEED_OVR_COARSE_MINUS,      // 0x92
//     CMD_FEED_OVR_FINE_PLUS ,        // 0x93
//     CMD_FEED_OVR_FINE_MINUS ,       // 0x94
//     CMD_RAPID_OVR_RESET,            // 0x95
//     CMD_RAPID_OVR_MEDIUM,           // 0x96
//     CMD_RAPID_OVR_LOW,              // 0x97
//     CMD_SPINDLE_OVR_RESET,          // 0x99
//     CMD_SPINDLE_OVR_COARSE_PLUS,    // 0x9A
//     CMD_SPINDLE_OVR_COARSE_MINUS,   // 0x9B
//     CMD_SPINDLE_OVR_FINE_PLUS,      // 0x9C
//     CMD_SPINDLE_OVR_FINE_MINUS,     // 0x9D
//     CMD_TOGGLE_SPINDLE,             // 0x9E
//     CMD_TOGGLE_FLOOD_COOLANT,       // 0xA0
//     CMD_TOGGLE_MIST_COOLANT,        // 0xA1
// }
// 
// Path: app/src/main/java/in/co/gorest/grblcontroller/model/Position.java
// public class Position {
//     private final Double cordX;
//     private final Double cordY;
//     private final Double cordZ;
// 
// 
//     private static final NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.ENGLISH);
//     private static final DecimalFormat decimalFormat = (DecimalFormat) numberFormat;
// 
//     public Position(double x, double y, double z){
//         this.cordX = x; this.cordY = y; this.cordZ = z;
//         decimalFormat.applyPattern("#0.###");
//     }
// 
//     public Double getCordX(){ return this.cordX; }
//     public Double getCordY(){ return this.cordY; }
//     public Double getCordZ(){ return this.cordZ; }
// 
//     private Double roundDouble(Double value){
//         String s = decimalFormat.format(value);
//         return Double.parseDouble(s);
//     }
// 
//     public boolean hasChanged(Position position){
//         return (position.getCordX().compareTo(this.cordX) != 0) || (position.getCordY().compareTo(this.cordY) != 0) || (position.getCordZ().compareTo(this.cordZ) != 0);
//     }
// 
//     public boolean atZero(){
//         return Math.abs(this.cordX) == 0 && Math.abs(this.cordY) == 0 && Math.abs(this.cordZ) == 0;
//     }
// 
// }


// Path: app/src/main/java/in/co/gorest/grblcontroller/util/GrblUtils.java
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import in.co.gorest.grblcontroller.listeners.MachineStatusListener.CompileTimeOptions;
import in.co.gorest.grblcontroller.model.Overrides;
import in.co.gorest.grblcontroller.model.Position;

            String[] parts = buildOptions.split(",");
            if (parts.length >= 3) {
                int tmpPBuffer = Integer.parseInt(parts[1]);
                if (tmpPBuffer > 0) plannerBuffer = tmpPBuffer;

                int tmpRxBuffer = Integer.parseInt(parts[2]);
                if (tmpRxBuffer > 0) serialRxBuffer = tmpRxBuffer;
            }
        }

        return new CompileTimeOptions(buildOptions, plannerBuffer, serialRxBuffer);
    }

    private final static String EEPROM_COMMAND_PATTERN = "G10|G28|G30|\\$x=|\\$I|\\$N|\\$RST=|G5[456789]|\\$\\$|\\$#";
    private final static Pattern EEPROM_COMMAND = Pattern.compile(EEPROM_COMMAND_PATTERN, Pattern.CASE_INSENSITIVE);
    public static boolean hasRomAccess(String command){
        return EEPROM_COMMAND.matcher(command).find();
    }

    public static String implode(String glue, String[] array) {
        if(array == null || array.length == 0) return "";

        StringBuilder sb = new StringBuilder();
        sb.append(array[0]);
        for(int i = 1; i < array.length; i++) sb.append(glue).append(array[i]);

        return sb.toString();
    }


    static public Byte getOverrideForEnum(final Overrides command) {