package com.microchip.mplab.ipelib; import com.microchip.crownking.Pair; import com.microchip.crownking.edc.edcDendron; import com.microchip.crownking.mplabinfo.DeviceSupport.ToolSupport; import com.microchip.crownking.mplabinfo.FamilyDefinitions.Family; import com.microchip.crownking.opt.OptionLanguage.Signature; import com.microchip.mplab.crownkingx.xPIC; import com.microchip.mplab.ipelib.common.SharedData; import com.microchip.mplab.ipelib.device.CDevice; import com.microchip.mplab.ipelib.device.PgmRangeStringValidator; import com.microchip.mplab.ipelib.device.PreserveEERangeValidator; import com.microchip.mplab.ipelib.device.PreservePGMRangeValidator; import com.microchip.mplab.ipelib.device.PreserveProgramMemoryEndOptionValidator; import com.microchip.mplab.ipelib.device.PreserveProgramMemoryStartOptionValidator; import com.microchip.mplab.ipelib.device.ProgramMemoryEndOptionValidator; import com.microchip.mplab.ipelib.device.ProgramMemoryStartOptionValidator; import com.microchip.mplab.ipelib.device.ToolsLookup; import com.microchip.mplab.ipelib.tools.IPENotifier; import com.microchip.mplab.ipelib.toolsupport.ToolType; import com.microchip.mplab.lib.scripting.ScriptOptValidator; import com.microchip.mplab.libs.MPLABDocumentLocator.MPLABDocumentLocator; import com.microchip.mplab.libs.RI4ToolsController.DataClasses.PtgImageInfo; import com.microchip.mplab.libs.atmelice.device.DeviceInfoFactory; import com.microchip.mplab.libs.atmelice.device.DeviceQuery; import com.microchip.mplab.libs.atmelice.device.atdf.AvrToolsDeviceFileType; import com.microchip.mplab.libs.scripting.runner.ScriptControllerException; import com.microchip.mplab.libs.scripting.runner.ScriptRunner; import com.microchip.mplab.libs.scripting.runner.ScriptRunner.Type; import com.microchip.mplab.libs.toolpacksupport.factory.ToolPackManager; import com.microchip.mplab.libs.toolpacksupport.interfaces.ToolPack; import com.microchip.mplab.libs.toolpacksupport.interfaces.ToolPackCapabilitiesProvider; import com.microchip.mplab.libs.toolpacksupport.interfaces.ToolPackRelease; import com.microchip.mplab.libs.toolpacksupport.interfaces.ToolPackReleaseFinder; import com.microchip.mplab.logger.MPLABLogger; import com.microchip.mplab.mdbcore.CodeGuardMediator.CodeGuardMediatorInterface; import com.microchip.mplab.mdbcore.ConfigBitsChecker.ConfigBitsCheckerInterface; import com.microchip.mplab.mdbcore.MessageMediator.Message; import com.microchip.mplab.mdbcore.RealICETool.utils.RIExceptions; import com.microchip.mplab.mdbcore.assemblies.Assembly; import com.microchip.mplab.mdbcore.checksum.common.BufferChecksumHelper.MemoryRegion; import com.microchip.mplab.mdbcore.common.debug.interfaces.PtgDetails; import com.microchip.mplab.mdbcore.common.debug.interfaces.ScriptMediator; import com.microchip.mplab.mdbcore.debugger.DebugException; import com.microchip.mplab.mdbcore.debugger.Debugger; import com.microchip.mplab.mdbcore.debugger.Debugger.CONNECTION_TYPE; import com.microchip.mplab.mdbcore.debugger.internal.Debugger2; import com.microchip.mplab.mdbcore.loader.LoadException; import com.microchip.mplab.mdbcore.loader.Loader; import com.microchip.mplab.mdbcore.loader.Loader.Output; import com.microchip.mplab.mdbcore.memory.PhysicalMemory; import com.microchip.mplab.mdbcore.memory.memorytypes.ProgramMemory; import com.microchip.mplab.mdbcore.pa.service.commands.FirmwareInfo; import com.microchip.mplab.mdbcore.platformtool.PlatformToolMeta; import com.microchip.mplab.mdbcore.platformtool.PlatformToolMetaManager; import com.microchip.mplab.mdbcore.platformtool.PlatformToolMeta.DocumentChanger; import com.microchip.mplab.mdbcore.platformtool.PlatformToolMeta.OptionLanguageSignatureProxy; import com.microchip.mplab.mdbcore.pm5.service.commands.responses.Pm5Versions; import com.microchip.mplab.mdbcore.pm5.service.utils.ServiceQueryException; import com.microchip.mplab.mdbcore.sqtpenv.SQTPEnvironment.SQTPError; import com.microchip.mplab.mdbcore.sqtpenv.pm3EnvExtractor.EnvStructure; import java.awt.Color; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Properties; import java.util.logging.Level; import java.util.prefs.Preferences; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import org.openide.util.Exceptions; import org.openide.util.NbBundle; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class IPELibrary { private ToolsLookup toolsLookup = null; private SharedData shareData; private CDevice deviceInfo; private PreserveProgramMemoryStartOptionValidator preserveStart; private PreserveProgramMemoryEndOptionValidator preserveEnd; private ProgramMemoryStartOptionValidator pgmStart; private ProgramMemoryEndOptionValidator pgmEnd; private PreservePGMRangeValidator prvPgmRange; private PreserveEERangeValidator prvEERange; private PgmRangeStringValidator pgmRange; private boolean isPartitionMisMatchError; private String parttnMisMatchErrorMsg = ""; private PlatformToolMeta toolMeta = null; private String toolID = ""; private Signature sig = null; public ScriptRunner runner; private ScriptMediator mediator; int runnerId = -1; public final IPELibrary.CommandLoader cmdloader = new IPELibrary.CommandLoader(); private boolean checkForPythonFileExists = false; private Map deviceActions = new HashMap<>(); private long pgmMemBeginAddr = 0L; private long pgmMemEndAddr = 0L; private Debugger2 mdb2; public IPELibrary() { this.toolsLookup = new ToolsLookup(); this.deviceInfo = new CDevice(); this.shareData = SharedData.getSingletonObject(); this.isPartitionMisMatchError = false; } public IPELibrary(boolean noDoScan) { this.toolsLookup = new ToolsLookup(noDoScan); this.deviceInfo = new CDevice(); this.shareData = SharedData.getSingletonObject(); this.isPartitionMisMatchError = false; } public Pair getMemoryRange(String memType) { return this.deviceInfo.getMemoryRange(memType); } public boolean isValidRange(long startAddr, long endAddr, String memoryType) { boolean retVal = false; if (memoryType.compareToIgnoreCase("program") == 0) { retVal = this.deviceInfo.isValidProgramMemoryRange(startAddr, endAddr); } else if (memoryType.compareToIgnoreCase("eeprom") == 0) { retVal = this.deviceInfo.isValidEEMemoryRange(startAddr, endAddr); } else if (memoryType.compareToIgnoreCase("userid") != 0 && memoryType.compareToIgnoreCase("config") != 0) { if (memoryType.compareToIgnoreCase("flash") == 0) { retVal = this.deviceInfo.isValidFlashMemoryRange(startAddr, endAddr); } else if (memoryType.compareToIgnoreCase("auxiliary") == 0) { retVal = this.deviceInfo.isValidAuxiliaryRange(startAddr, endAddr); } } return retVal; } public boolean isDeviceCodeProtected() { boolean retVal = false; ConfigBitsCheckerInterface CF = (ConfigBitsCheckerInterface)this.shareData.getAssemblySession().getLookup().lookup(ConfigBitsCheckerInterface.class); try { retVal = CF.CheckField(106, true); } catch (NoSuchFieldException var4) { } return retVal; } public void setCalibrationdatatoMemory(long addrs, int bytesPW, byte[] data) { PhysicalMemory pm = this.getMemory(ProgramMemory.class); pm.Write(addrs, bytesPW, data); this.setProgramMemory(pm); } public String getToolIDFromToolInfo(String toolAsShown) { return this.toolsLookup.getToolIDFromMapInfo(toolAsShown); } public List getSupport(String tool, String device) { return this.toolsLookup.getSupport(tool, device); } public ArrayList queryToolList() { return this.toolsLookup.getActiveToolList(); } public ArrayList querySerialToolList() { return this.toolsLookup.getSerialToolsList(); } public ArrayList getCurrentAvailableToolList() { return this.toolsLookup.getCurrentAvailableToolList(); } public boolean createAssemblySession(String deviceName) { boolean retVal = this.toolsLookup.createAssemblySession(deviceName); if (retVal) { retVal = this.deviceInfo.getDeviceInfo(); } return retVal; } public boolean createAssemblySession(String deviceSelected, String packName, String packVersion, String packVendor, ToolPackRelease toolPackRelease) { boolean retVal = this.toolsLookup.createAssemblySession(deviceSelected, packName, packVersion, packVendor, toolPackRelease); if (retVal) { retVal = this.deviceInfo.getDeviceInfo(); } return retVal; } public void load_like_mplab8(boolean t) { this.shareData.getSQTPEnvironment().Load_like_MPLAB8(t); } public boolean createSQTPEnvironmentSession() { return this.toolsLookup.setSQTPEnvironment(); } public boolean CreateSQTPFile(RandomAccessFile sqtp, Properties props) { return this.shareData.getSQTPEnvironment().CreateSQTPFile(sqtp, props); } public void UnloadSQTP() { this.shareData.getSQTPEnvironment().UnloadSQTPFile(); } public boolean deleteEnvironment(String path) { return this.toolsLookup.deleteEnvironment(path); } public boolean viewEnvironment(String path) { return this.toolsLookup.viewEnviroment(path); } public boolean loadEnvironment(String path) { return this.toolsLookup.loadEnvironment(path); } public boolean copyEnvironment(String srcPath, String destPath, String srcEnvName, String dstEnvName) { return this.toolsLookup.copyEnviroment(srcPath, destPath, srcEnvName, dstEnvName); } public boolean saveEnvironment(String envPath, String envName, boolean isPM3File, String sqtpFile, String miscFile, String envDesc) { return this.toolsLookup.saveEnvironment(envPath, envName, isPM3File, sqtpFile, miscFile, envDesc); } public SQTPError loadSQTPFile(String numFilePath) { this.toolsLookup.UnloadSQTPFile(); return this.toolsLookup.setSQTPSequence(numFilePath); } public SQTPError loadNextSQTPSequence(String numFilePath) { return this.toolsLookup.loadNextSQTPSequence(numFilePath); } public boolean createDebuggerSession(String toolName) { boolean retVal = false; try { retVal = this.toolsLookup.createDebuggerSession(toolName); } catch (Exception var4) { retVal = false; } return retVal; } public void setUI(boolean isUI) { this.shareData.setUIMode(isUI); } public void setDebugBitFlag(boolean flag) { this.shareData.setDebugBitFlag(flag); } public int loadHexFile(ArrayList files, boolean resetDebugBit) { int retVal = -1; boolean isCoordinatedResetFlagSet = false; Assembly mdbSession = this.shareData.getAssemblySession(); Loader loader = (Loader)mdbSession.getLookup().lookup(Loader.class); try { if (this.isCoordinatedResetAndProgramOpRequired()) { isCoordinatedResetFlagSet = true; } loader.ResetInvalidConfigurationBits(resetDebugBit); this.shareData.setInvalidHexFlag(false); int dbgBit = loader.Load(files, null, isCoordinatedResetFlagSet, new Output() { Message message = new Message(); public void PrintMessage(String msg) { this.message.setMessageString(msg); if (IPELibrary.this.shareData.getUIMode()) { this.message.setTextColorForOutputWindow(Color.BLACK); } if (msg.startsWith("Warning:")) { this.message.setTextColorForOutputWindow(Color.RED); System.out.println("IPE:" + msg); IPELibrary.this.shareData.setInvalidHexFlag(false); } IPENotifier.getIPENotifierController().SetMessageObjectNotify(this.message, 1); } public void PrintError(String msg) { this.message.setTextColorForOutputWindow(Color.RED); IPENotifier.getIPENotifierController().setMessageNotification(msg + "\n"); } }); retVal = dbgBit; if (this.shareData.getInvalidHexFlag()) { retVal = -1; } return retVal; } catch (LoadException var9) { int var10 = -1; if (this.shareData.getUIMode()) { Message message = new Message(); message.setTextColorForOutputWindow(Color.RED); message.setMessageString(var9.getMessage()); IPENotifier.getIPENotifierController().SetMessageObjectNotify(message, 1); } return var10; } } public boolean exportHexFile(String filePath) { boolean retVal = true; Assembly mdbSession = this.shareData.getAssemblySession(); Loader loader = (Loader)mdbSession.getLookup().lookup(Loader.class); try { loader.Save(filePath, true); } catch (LoadException var6) { retVal = false; } return retVal; } public boolean programTarget() { if (this.isMaintainActiveConnectionSupport() && !this.isCoordinatedResetAndProgramOpRequired()) { this.toolsLookup.Connect(); } return this.toolsLookup.WriteMemory(); } public boolean isMaintainActiveConnectionSupport() { boolean isMaintainConnectionDisabled = false; Boolean isMaintainConnection = this.toolMeta.hasCapability("disable-maintain-connection"); if (isMaintainConnection != null && this.isATDeviceInAssembly() && (isMaintainConnection || this.getXPICDeviceInfo().getFamily().equals(Family.ARM32BIT) && !isMaintainConnection)) { isMaintainConnectionDisabled = isMaintainConnection; } return isMaintainConnectionDisabled; } public CodeGuardMediatorInterface getCodeGuardInstance() { return (CodeGuardMediatorInterface)this.shareData.getAssemblySession().getLookup().lookup(CodeGuardMediatorInterface.class); } public boolean readTarget() { boolean retVal = false; if (this.isMaintainActiveConnectionSupport()) { this.toolsLookup.Connect(); } try { if (this.useAllExecutableRegions() && "auto".equals(this.shareData.getCoreParameters().getProperty("AutoSelectMemRanges"))) { this.shareData.getCoreParameters().setProperty("AutoSelectMemRanges", "manual"); } retVal = this.toolsLookup.readMemory(); if (this.isMaintainActiveConnectionSupport()) { this.toolsLookup.disconnectTarget(); } } catch (Exception var3) { if (((DebugException)var3).Code() == 11) { this.isPartitionMisMatchError = true; this.parttnMisMatchErrorMsg = var3.getMessage(); retVal = false; } } return retVal; } public boolean useAllExecutableRegions() { boolean retVal = false; String DevName = this.shareData.getAssemblySession().GetDeviceName(); xPIC picdevicedb = this.shareData.getAssemblySession().GetDevice(); if (picdevicedb.getArchitecture() != null && (picdevicedb.getArchitecture().toUpperCase().startsWith("CORTEX") || picdevicedb.getArchitecture().toUpperCase().startsWith("ARM9")) || DevName.startsWith("PIC32CZ") || DevName.startsWith("PIC32CX") || DevName.startsWith("PIC32MZ") || DevName.contains("WBZ")) { retVal = true; } return retVal; } public String getPartitionMisMatchErrorMsg() { return this.parttnMisMatchErrorMsg; } public boolean eraseTarget() { if (this.isMaintainActiveConnectionSupport()) { this.toolsLookup.Connect(); } boolean retVal = this.toolsLookup.eraseMemory(); if (this.isMaintainActiveConnectionSupport()) { this.toolsLookup.disconnectTarget(); } return retVal; } public boolean verifyTarget() { return this.toolsLookup.verifyMemory(); } public boolean blankCheck() { return this.toolsLookup.blankCheck(); } public boolean justConnect() { return this.toolsLookup.justConnect(); } public boolean disconnectTarget() { return this.toolsLookup.disconnectTarget(); } public boolean ConnectTarget() { return this.toolsLookup.Connect(); } public Debugger getDebugerSession() { return this.shareData.getDebugger(); } public String getErrorString() { return this.toolsLookup.getErrorString(); } public void HoldInReset() { try { if (this.isMaintainActiveConnectionSupport()) { this.toolsLookup.Connect(); } this.toolsLookup.holdInReset(); if (this.isMaintainActiveConnectionSupport()) { this.toolsLookup.disconnectTarget(); } } catch (DebugException var2) { Exceptions.printStackTrace(var2); } } public void UpdateSerialTools() { this.toolsLookup.getPM3SerialInformation(); } public void ReleaseFromReset() { try { if (this.isMaintainActiveConnectionSupport()) { this.toolsLookup.Connect(); } this.toolsLookup.releaseFromReset(); if (this.isMaintainActiveConnectionSupport()) { this.toolsLookup.disconnectTarget(); } } catch (DebugException var2) { Exceptions.printStackTrace(var2); } } public boolean hasVPPfirst() { return this.deviceInfo.hasVPPFirst(); } public long getDataFlashAddrs() { return this.deviceInfo.getDataFlashEndAddrs(); } public boolean hasLVP() { return this.shareData.getAssemblySession().GetDevice().getProgramming().haslvp2(); } public boolean hasHighVoltageMCLR() { return this.deviceInfo.getXPICDeviceInfo().getPower().hasHighVoltageMCLR2(); } protected boolean HasPin(xPIC pic, String PinName) { boolean HasPin = false; edcDendron edcUtil = new edcDendron(); Node pinList = pic.first("PinList"); if (pinList != null) { for (Node pin = edcUtil.first(pinList, "Pin"); pin != null; pin = edcUtil.next(pin, "Pin")) { String name = null; for (Node virtualPin = edcUtil.first(pin, "VirtualPin"); virtualPin != null; virtualPin = edcUtil.next(virtualPin, "VirtualPin")) { name = edcUtil.get(virtualPin, "name"); if (name.equals(PinName)) { HasPin = true; return HasPin; } } } } return HasPin; } public String getcrc32FileChecksum(File file) { String retVal = "N/A"; try { long cksum = this.toolsLookup.getCRC32(file); if (cksum != -1L) { retVal = String.format("%8X", cksum).trim(); if (retVal.length() >= 8) { retVal = retVal.substring(retVal.length() - 8); } } else { retVal = "N/A"; } } catch (Exception var5) { retVal = "N/A"; } return retVal; } public String getChecksum() { String retVal = "N/A"; try { long cksum = this.toolsLookup.getChecksum(); if (cksum != -1L) { retVal = Long.toHexString(cksum).toUpperCase(); } else { retVal = "N/A"; } } catch (Exception var4) { retVal = "N/A"; } return retVal; } public String getUnprotectedCsum() { String retVal = "N/A"; try { long cksum = this.toolsLookup.getUnprotectedCsum(); if (cksum != -1L) { retVal = Long.toHexString(cksum).toUpperCase(); } else { retVal = "N/A"; } } catch (Exception var4) { retVal = "N/A"; } return retVal; } public String getEEChecksum() { String retVal = "N/A"; try { long cksum = this.toolsLookup.getEEChecksum(); if (cksum != -1L) { retVal = Long.toHexString(cksum).toUpperCase(); } else { retVal = "N/A"; } } catch (Exception var4) { retVal = "N/A"; } return retVal; } public boolean hasChecksum() { boolean retVal = false; try { retVal = this.toolsLookup.hasChecksum(); } catch (Exception var3) { MPLABLogger.mplog.log(Level.INFO, var3.getMessage()); } return retVal; } public String getFlashdataChecksum() { String retVal = "N/A"; try { long cksum = this.toolsLookup.getFlashdataChecksum(); if (cksum != -1L) { retVal = Long.toHexString(cksum).toUpperCase(); } else { retVal = "N/A"; } } catch (Exception var4) { retVal = "N/A"; } return retVal; } public Map getBufferChecksum() { new HashMap(); Map bufCkSum; try { bufCkSum = this.toolsLookup.getBufferChecksum(); } catch (Exception var3) { bufCkSum = null; } return bufCkSum; } public boolean setCorePropertiesInSession(Properties coreProps) { this.shareData.setCoreParameters(coreProps); if (this.shareData.getAssemblySession() != null) { this.shareData.getassemblyFactory().SetToolProperties(this.shareData.getAssemblySession(), coreProps); return true; } else { return false; } } public void setPowerProperties(Preferences usrProperties) { this.shareData.setUserParameters(usrProperties); } public void setOTPForCECDevice(boolean isOTPSet) { this.shareData.setOTPForCECDevice(isOTPSet); } public boolean isEEMemory() { return this.deviceInfo.isEEMemory(); } public boolean isBootMem() { return this.deviceInfo.isBootMem(); } public boolean isConfigMemory() { return this.deviceInfo.isConfigMemory(); } public boolean isProgramMemory() { return this.deviceInfo.isProgramMemory(); } public boolean isDataFlash() { return this.deviceInfo.isDataFlash(); } public boolean isAuxMem() { return this.deviceInfo.isAuxMem(); } public boolean isDeviceID() { return this.deviceInfo.isDeviceID(); } public boolean isUserID() { return this.deviceInfo.isUserID(); } public boolean isOTPmemory() { return this.deviceInfo.hasOTPMemory(); } public boolean isFlashData() { return this.deviceInfo.isFlashData(); } public String getPM3DeviceChecksum() { String retVal = "N/A"; try { int cksum = this.toolsLookup.getPM3Checksum(); if (cksum != -1) { retVal = Integer.toHexString(cksum).toUpperCase(); } } catch (Exception var3) { retVal = "N/A"; } return retVal; } public int getPM3ErrorCode() { return this.toolsLookup.getPM3ErrorCode(); } public void setUserProperties(Preferences usrProperties) { this.shareData.setUserParameters(usrProperties); } public boolean checkVoltageSlab(float voltage) { return this.deviceInfo.checkVoltageSlab(voltage); } public String getPM3DeviceID() { String retVal = "N/A"; try { int devid = this.toolsLookup.getPM3DeviceID(); if (devid >= 0) { retVal = Integer.toHexString(devid).toUpperCase(); } else if (devid == -2) { retVal = "FFFF"; } else { retVal = "0"; } } catch (Exception var3) { retVal = "N/A"; } return retVal; } public String getPM3DeviceIDRevision() { String retVal = "N/A"; retVal = this.toolsLookup.getDeviceID(); Pattern p = Pattern.compile("(?<=Device Rev= )\\d+"); Matcher m = p.matcher(retVal); if (m.find()) { retVal = m.group(); } return retVal; } public xPIC getXPICDeviceInfo() { return this.deviceInfo.getXPICDeviceInfo(); } public PhysicalMemory getMemory(Class cMemory) { return this.deviceInfo.getMemory(cMemory); } public void clearAll() { this.deviceInfo.clearAll(); } public void setProgramMemory(PhysicalMemory pm) { this.deviceInfo.setProgramMemory(pm); } public String getProgramMemoryRange() { String rangeVal = ""; xPIC picdevicedb = this.shareData.getAssemblySession().GetDevice(); Pair ePgmMemRange = picdevicedb.getInstRange(); if (picdevicedb.getMainPartition().hasAuxCode()) { ePgmMemRange = picdevicedb.getCodeRange(); } if (!picdevicedb.getIDOntoPartition().isEmpty()) { ePgmMemRange = picdevicedb.getMainPartition().getFileRange(); } if (ePgmMemRange != null && (Long)ePgmMemRange.second != 0L) { this.pgmMemBeginAddr = (Long)ePgmMemRange.first; this.pgmMemEndAddr = (Long)ePgmMemRange.second; if (this.getAssemblySession().GetDeviceName().startsWith("PIC32CZ")) { List nodes = picdevicedb.getMainPartition().getCodeRegions(); NamedNodeMap p = nodes.get(1).getAttributes(); String be = p.getNamedItem("edc:beginaddr").getNodeValue(); String en = p.getNamedItem("edc:endaddr").getNodeValue(); be = be.substring(2); en = en.substring(2); this.pgmMemBeginAddr = Long.parseLong(be, 16); this.pgmMemEndAddr = Long.parseLong(en, 16); } rangeVal = String.format("%x-%x", this.pgmMemBeginAddr, this.pgmMemEndAddr - 1L); } return rangeVal; } public void setEEMemory(PhysicalMemory eem) { this.deviceInfo.setEEMemory(eem); } public void setBootMem(PhysicalMemory boot) { this.deviceInfo.setBootMem(boot); } public void setFlashMemory(PhysicalMemory fd) { this.deviceInfo.setFlashMemory(fd); } public void setDataFlashMemory(PhysicalMemory fd) { this.deviceInfo.setDataFlashMemory(fd); } public void setIDMem(PhysicalMemory IDMem) { this.deviceInfo.setIDMem(IDMem); } public void setConfigMem(PhysicalMemory configMem) { this.deviceInfo.setConfigMem(configMem); } public boolean connectAsPTG() { return this.toolsLookup.connectAsPTG(); } public Assembly getAssemblySession() { return this.shareData.getAssemblySession(); } public void setUSerResponse(int i) { this.shareData.setUserResponseFlag(true); this.shareData.setUserResponseCode(i); } public boolean transferImageToPM3() { boolean hasImage = false; try { hasImage = this.toolsLookup.transferImageToPM3(); } catch (Exception var3) { hasImage = false; } return hasImage; } public boolean transferImageFromPM3() { boolean hasImage = false; try { hasImage = this.toolsLookup.transferImageFromPM3(); } catch (Exception var3) { hasImage = false; } return hasImage; } public boolean PM3hasSDCard() { boolean hasCard = false; try { hasCard = this.toolsLookup.Pm3hasSDCard(); } catch (Exception var3) { hasCard = false; } return hasCard; } public void doscan() { this.toolsLookup.initAttachTool(); this.toolsLookup.UpdateToolList(); } public boolean DownloadOS(String path) { return this.toolsLookup.DownloadOS(path); } public boolean DownloadBIOS(String path) { return this.toolsLookup.DownloadBIOS(path); } public boolean DownloadDB(String path) { return this.toolsLookup.DownloadDB(path); } public String GetPM3EnvironmentFromPM3SDCard(String path, boolean Futureflag) { return this.toolsLookup.GetPM3EnvironmentFromPM3SDCard(path.replace("\\", "/"), false); } public boolean FormatSDCard() { return this.toolsLookup.FormatPM3SDCard(); } public EnvStructure getEnvStructure() { return this.toolsLookup.getEnvStructure(); } public String getDeviceNameInEnv(String pm3File) { String deviceName = ""; String actualPath = pm3File; pm3File = pm3File.replace("\\", "/"); if (pm3File.contains(";")) { String tempPath = pm3File.split(";")[0]; actualPath = tempPath; } File pm3 = new File(actualPath); RandomAccessFile envFile = null; if (pm3.exists()) { try { envFile = new RandomAccessFile(pm3, "r"); envFile.seek(560L); } catch (IOException var10) { Exceptions.printStackTrace(var10); } byte[] device = new byte[100]; try { envFile.read(device); } catch (IOException var9) { Exceptions.printStackTrace(var9); } try { deviceName = new String(device, "UTF-16LE"); } catch (UnsupportedEncodingException var8) { Exceptions.printStackTrace(var8); } deviceName = deviceName.trim(); } else { System.out.print("IPE:Could not open environment file for read."); } return deviceName; } public String getToolNameInEnv(String pm3File) { String toolName = ""; String actualPath = pm3File; pm3File = pm3File.replace("\\", "/"); if (pm3File.contains(";")) { String tempPath = pm3File.split(";")[0]; actualPath = tempPath; } File pm3 = new File(actualPath); RandomAccessFile envFile = null; if (pm3.exists()) { try { envFile = new RandomAccessFile(pm3, "r"); envFile.seek(6583L); } catch (IOException var9) { Exceptions.printStackTrace(var9); } byte[] tool = new byte[30]; try { envFile.read(tool); } catch (IOException var8) { Exceptions.printStackTrace(var8); } toolName = new String(tool); toolName = toolName.trim(); } else { System.out.print("IPE:Could not open environment file for read."); } return toolName; } public String getSqtpFileNameInEnv(String pm3File) throws UnsupportedEncodingException { String sqtpFileName = ""; String actualPath = pm3File; pm3File = pm3File.replace("\\", "/"); if (pm3File.contains(";")) { String tempPath = pm3File.split(";")[0]; actualPath = tempPath; } File pm3 = new File(actualPath); RandomAccessFile envFile = null; if (pm3.exists()) { try { envFile = new RandomAccessFile(pm3, "rw"); envFile.seek(6328L); } catch (IOException var10) { Exceptions.printStackTrace(var10); } byte[] sqtpFile = new byte[255]; try { envFile.read(sqtpFile); } catch (IOException var9) { Exceptions.printStackTrace(var9); } String numFile = new String(sqtpFile, "UTF-16LE"); numFile = numFile.trim(); String ext = ".NUM"; if (numFile.contains(".num")) { ext = ".num"; numFile = numFile.substring(0, numFile.lastIndexOf(ext)).concat(ext); numFile = numFile.replace("\\", ""); if (!pm3File.contains(";")) { sqtpFileName = pm3.getAbsolutePath() .substring(0, pm3.getAbsolutePath().lastIndexOf(System.getProperty("file.separator"))) .concat(System.getProperty("file.separator") + numFile); } } } return sqtpFileName; } public List getPK5PTGImageList() throws RIExceptions { List retList = null; if (!this.shareData.isConnected()) { try { this.getDebugerSession().Connect(CONNECTION_TYPE.PROGRAMMER_TO_GO); } catch (DebugException var3) { MPLABLogger.mplog.log(Level.INFO, var3.getMessage()); } } Optional ptgD = this.getPTGDetailsProvider(); if (ptgD.isPresent()) { retList = ptgD.get().getPTGImageList(); } return retList; } public void runPtgGoButton() throws Exception { try { Optional ptgD = this.getPTGDetailsProvider(); if (ptgD.isPresent()) { ptgD.get().ptgGoButtonPress(); } } catch (Exception var2) { MPLABLogger.mplog.log(Level.INFO, var2.getMessage()); } } public Optional getPTGDetailsProvider() { Optional ptgD = null; if (this.shareData.getDebugger() != null) { try { this.setDebugger2(this.shareData.getDebugger()); } catch (Exception var3) { MPLABLogger.mplog.log(Level.INFO, var3.getMessage()); } } if (this.mdb2 != null) { ptgD = this.mdb2.getPTGDetailsProvider(); } return ptgD; } private void setDebugger2(Debugger mdb) throws Exception { if (Debugger2.class.isAssignableFrom(mdb.getClass())) { this.mdb2 = (Debugger2)mdb; } else { throw new Exception("Internal fatal error. Could not get access to Debugger2 interface"); } } public PtgImageInfo getPK5PTGActiveImage() { PtgImageInfo prtActiveimage = null; Optional ptgD = this.getPTGDetailsProvider(); if (ptgD.isPresent()) { prtActiveimage = ptgD.get().getPTGActiveImage(); } return prtActiveimage; } public void setPK5PTGActiveImage(PtgImageInfo img) { Optional ptgD = this.getPTGDetailsProvider(); if (ptgD.isPresent()) { ptgD.get().setPTGActiveImage(img); } } public void deletePK5PTGImage(PtgImageInfo img) { Optional ptgD = this.getPTGDetailsProvider(); if (ptgD.isPresent()) { ptgD.get().deletePTGImage(img); } } public void resetPK5PTGStats(PtgImageInfo img) { Optional ptgD = this.getPTGDetailsProvider(); if (ptgD.isPresent()) { ptgD.get().resetPTGProgrammingStatistics(img); } } public void setSafeMode(boolean safemode) { this.toolsLookup.setPM3toSafeMode(safemode); } public void setPlatformMeta(String toolID) { this.toolID = toolID; List listOfAllTools = PlatformToolMetaManager.getAllTools(); List platformTools = new LinkedList<>(); for (PlatformToolMeta meta : listOfAllTools) { platformTools.add(meta.getID()); } for (String platformTool : platformTools) { if (platformTool.toLowerCase().contains(toolID.toLowerCase())) { this.toolMeta = PlatformToolMetaManager.getTool(platformTool); break; } } } public PlatformToolMeta GetPlatformMeta() { return this.toolMeta; } public String getActualToolFromShortToolName(String shortToolName) { String actualToolName = null; IPELibrary.ToolShortName[] toolList = IPELibrary.ToolShortName.values(); for (int i = 0; i < IPELibrary.ToolShortName.values().length; i++) { if (shortToolName.equalsIgnoreCase(toolList[i].name())) { actualToolName = toolList[i].getToolId(); break; } } return actualToolName; } public String getPlatformToolIDFromActualTool(String actualToolName) { String platformToolID = null; actualToolName = this.getActualToolFromShortToolName(actualToolName); ToolType[] toolList = ToolType.values(); for (int i = 0; i < ToolType.values().length; i++) { if (actualToolName.equalsIgnoreCase(toolList[i].name())) { platformToolID = toolList[i].getToolId(); break; } } return platformToolID; } public Pair isValidPreservepgmStartAddress(String startAddr) { this.preserveStart = new PreserveProgramMemoryStartOptionValidator(); return this.preserveStart.validate(startAddr); } public Pair isValidPreservepgmRangeAddresses(String Str) { this.prvPgmRange = new PreservePGMRangeValidator(); return this.prvPgmRange.validate(Str); } public Pair isValidEERangeAddresses(String Str) { this.prvEERange = new PreserveEERangeValidator(); return this.prvEERange.validate(Str); } public Pair isValidpgmRangeAddresses(String Str) { this.pgmRange = new PgmRangeStringValidator(); return this.pgmRange.validate(Str); } public String getPgmRangeHint() { this.pgmRange = new PgmRangeStringValidator(); return this.pgmRange.getHint(); } public String getPreservePgmRangeHint() { this.prvPgmRange = new PreservePGMRangeValidator(); return this.prvPgmRange.getHint(); } public String getPreserveEERangeHint() { this.prvEERange = new PreserveEERangeValidator(); return this.prvEERange.getHint(); } public Pair isValidPreservepgmEndAddress(String endAddr) { this.preserveEnd = new PreserveProgramMemoryEndOptionValidator(); return this.preserveEnd.validate(endAddr); } public Pair isValidpgmStartAddress(String startAddr) { this.pgmStart = new ProgramMemoryStartOptionValidator(); return this.pgmStart.validate(startAddr); } public String getDeviceID() { return this.toolsLookup.getDeviceID(); } public Pair isValidpgmEndAddress(String endAddr) { this.pgmEnd = new ProgramMemoryEndOptionValidator(); return this.pgmEnd.validate(endAddr); } public boolean setLoggerLocation() { if (System.getProperty("os.name").contains("Windows")) { String tempPath = System.getProperty("java.io.tmpdir"); tempPath = tempPath + "/MPLABLog.xml"; MPLABLogger.setLogFileName(tempPath); return true; } else { return false; } } public String getASCIIValuefor1Values(byte msb) { return this.validate(msb); } public String getASCIIValuefor2Values(byte msb, byte lsb) { byte[] byteArray = new byte[]{msb, lsb}; String result = ""; for (int i = 0; i < byteArray.length; i++) { result = result + this.validate(byteArray[i]); } return result; } public String getASCIIValue(byte msb1, byte msb2, byte lsb1, byte lsb2) { byte[] byteArray = new byte[]{msb1, msb2, lsb1, lsb2}; String result = ""; for (int i = 0; i < byteArray.length; i++) { result = result + this.validate(byteArray[i]); } return result; } private String validate(byte value) { byte[] byteArray = new byte[]{value}; String result = ""; int temp = 0; String s = String.format("%x", value); temp = Integer.valueOf(s, 16); if (temp >= 32 && temp < 127) { try { result = new String(byteArray, "ASCII"); } catch (UnsupportedEncodingException var7) { MPLABLogger.mplog.log(Level.INFO, var7.getMessage()); } return result; } else { return "."; } } public void setIPEMetricsToServer(String IPEVersion, String toolInfo, String devInfo) { this.shareData.setIPEMetricsToServer(IPEVersion, toolInfo, devInfo); } public boolean isPartitionMisMatch() { return this.isPartitionMisMatchError; } public boolean hasDIA_DCI_Memory() { return this.deviceInfo.hasDIA_DCI_Memory(); } public boolean hasDIAMemory() { return this.deviceInfo.hasDIAMemory(); } public boolean isToolConnected() { return this.shareData.isConnected(); } public String[] GetDevice_Tool() { return this.shareData == null ? null : this.shareData.getDevice_Tool(); } public String[] gettools() { return this.toolsLookup.doScan_matlab(); } public boolean CheckAssemblySessionActive() { return this.shareData == null ? false : this.shareData.isAssemblySessionActive(); } public boolean SaveOStoPM3Card() { return this.toolsLookup.SaveOStoPM3Card(); } public boolean isUserIDSQTP(String path) { return this.shareData.getSQTPEnvironment().isUserIDSQTP(path); } public CDevice getDeviceInfo() { return this.deviceInfo; } public boolean isPartitioned() { return this.deviceInfo.isPartitioned(); } public boolean isCoordinatedResetAndProgramOpRequired() { return this.toolsLookup.isCoordinatedResetAndProgramOpRequired(); } public boolean isATDeviceInAssembly() { boolean retVal = false; try { if (this.getXPICDeviceInfo().getFamily() != null && (this.getXPICDeviceInfo().getFamily().equals(Family.AVR) || this.getXPICDeviceInfo().getFamily().equals(Family.ARM32BIT))) { retVal = true; } } catch (Exception var3) { MPLABLogger.mplog.log(Level.INFO, var3.getMessage()); } return retVal; } public boolean isARMDeviceInAssembly() { boolean retVal = false; if (this.getXPICDeviceInfo().getFamily() != null && this.getXPICDeviceInfo().getFamily().equals(Family.ARM32BIT)) { retVal = true; } return retVal; } public boolean isAVRDeviceInAssembly() { boolean retVal = false; if (this.getXPICDeviceInfo().getFamily() != null && this.getXPICDeviceInfo().getFamily().equals(Family.AVR)) { retVal = true; } return retVal; } public boolean isPIC32DeviceInAssembly() { boolean retVal = false; if (this.getXPICDeviceInfo().getFamily() != null && this.getXPICDeviceInfo().getFamily().equals(Family.PIC32)) { retVal = true; } return retVal; } public List getAtmelDeviceInterfaceList(String deviceName) { List interfaceTypes = null; if (this.getXPICDeviceInfo().getFamily().equals(Family.AVR) || this.getXPICDeviceInfo().getFamily().equals(Family.ARM32BIT)) { Optional atdf = DeviceInfoFactory.get(deviceName); if (atdf.isPresent()) { DeviceQuery query = new DeviceQuery(atdf.get()); interfaceTypes = query.getInterfaces().stream().map(i -> i.getType()).map(i -> i.toString().toLowerCase()).collect(Collectors.toList()); } } return interfaceTypes; } public boolean programAVR_ARMFuses(Optional start, Optional end) { boolean retVal = false; if (this.isARMDeviceInAssembly()) { this.toolsLookup.Connect(); long startAddr = (Long)this.deviceInfo.getXPICDeviceInfo().getMainPartition().getDCRRange().first; long endAddr = (Long)this.deviceInfo.getXPICDeviceInfo().getMainPartition().getDCRRange().second; start = Optional.of(startAddr); end = Optional.of(endAddr); retVal = this.toolsLookup.WriteAVR_ARMFuses(start, end); this.toolsLookup.disconnectTarget(); } else { this.toolsLookup.Connect(); } return this.toolsLookup.WriteAVR_ARMFuses(start, end); } public boolean readAVR_SAMFuses(Optional start, Optional end) { boolean retVal = false; if (this.isATDeviceInAssembly()) { this.toolsLookup.Connect(); retVal = this.toolsLookup.readAVR_SAMFuses(start, end); this.toolsLookup.disconnectTarget(); } else { retVal = this.toolsLookup.readAVR_SAMFuses(start, end); } return retVal; } public Map getToolsMap() { return this.toolsLookup.getToolsMap(); } public String getToolNameBasedOnID(String id) { List listOfAllTools = PlatformToolMetaManager.getAllTools(); String name = ""; for (PlatformToolMeta meta : listOfAllTools) { if (meta.getID().equalsIgnoreCase(id)) { name = meta.getName(); break; } } return name; } public IPELibrary.ToolPackReleaseWithReasonIfNotFound getToolPackRelease(Properties properties, String deviceName) { ToolPackRelease toolPackRelease = null; String errorString = null; if (!MPLABDocumentLocator.isReadingFromDFPFeatureEnabled()) { return null; } else if (this.GetPlatformMeta() == null) { errorString = getString("NO_TOOL_PACK_INTERNAL_ERROR_NO_META"); return new IPELibrary.ToolPackReleaseWithReasonIfNotFound(toolPackRelease, errorString); } else { ToolPackCapabilitiesProvider toolPackCapabilitiesProvider = this.GetPlatformMeta().getToolPackCapabilitiesProvider(); if (toolPackCapabilitiesProvider == null) { return null; } else { ToolPackReleaseFinder toolPackReleaseFinder = ToolPackManager.getToolPackReleaseFinder(); if (!toolPackCapabilitiesProvider.isUseToolPacks(properties)) { return null; } else if (toolPackCapabilitiesProvider.isUseLatestToolPack(properties)) { ToolPack toolPack = ToolPackManager.createMicrochipToolPack(this.toolID); toolPackRelease = toolPackReleaseFinder.getLatestToolPackRelease(toolPack, deviceName); if (toolPackRelease == null) { errorString = getString("COULD_NOT_FIND_LATEST_TOOL_PACK", this.toolID); } return new IPELibrary.ToolPackReleaseWithReasonIfNotFound(toolPackRelease, errorString); } else { String toolPackVersion = toolPackCapabilitiesProvider.getToolPackVersion(properties); if (toolPackVersion != null && !toolPackVersion.isEmpty()) { ToolPack toolPack = ToolPackManager.createMicrochipToolPack(this.toolID); toolPackRelease = toolPackReleaseFinder.getToolPackRelease(toolPack, toolPackVersion, deviceName); if (toolPackRelease != null) { return new IPELibrary.ToolPackReleaseWithReasonIfNotFound(toolPackRelease, errorString); } else if (toolPackReleaseFinder.isToolPackReleasePresent(toolPack, toolPackVersion)) { errorString = getString("PACK_DOES_NOT_HAVE_SUPPORT_FOR_DEVICE", toolPackVersion, deviceName); return new IPELibrary.ToolPackReleaseWithReasonIfNotFound(toolPackRelease, errorString); } else { errorString = getString("COULD_NOT_FIND_SPECIFIC_TOOL_PACK", this.toolID, toolPackVersion); return new IPELibrary.ToolPackReleaseWithReasonIfNotFound(toolPackRelease, errorString); } } else { errorString = getString("COULD_NOT_FIND_SPECIFIC_TOOL_PACK", this.toolID); return new IPELibrary.ToolPackReleaseWithReasonIfNotFound(toolPackRelease, errorString); } } } } } private static String getString(String s) { return NbBundle.getMessage(IPELibrary.class, s); } private static String getString(String s, Object o) { return NbBundle.getMessage(IPELibrary.class, s, o); } private static String getString(String s, Object o1, Object o2) { return NbBundle.getMessage(IPELibrary.class, s, o1, o2); } public String[] showMPLABCommVerInfo() { String[] sCommver = new String[2]; if (this.shareData.getUIMode()) { sCommver[0] = System.getProperty("com.microchip.mplab.comm.USBAccess.version", "N/A"); sCommver[1] = System.getProperty("com.microchip.mplab.comm.SerialAccess.version", "N/A"); } return sCommver; } public DocumentChanger getChanger() { return new IPELibrary.OptModifier(); } public Map getDeviceActionsMap() { return this.deviceActions; } public void loadScriptCommands() { Thread t = new Thread(new Runnable() { @Override public void run() { IPELibrary.this.loadToolScripts(); } }); t.start(); } private void loadToolScripts() { try { File f = this.runner.getToolDeviceFile(); if (f != null) { this.runner.loadModule(f); this.runner.loadFileIfExists(this.runner.getRepoLocation(), "properties_" + f.toString()); } this.runner.loadFileIfExists(this.runner.getRepoLocation(), "properties_device.py"); this.loadScriptCommands("onloadDFP"); } catch (NullPointerException | ScriptControllerException var2) { MPLABLogger.mplog.log(Level.INFO, var2.getMessage()); } } private void loadScriptCommands(String loadFuncName) { try { this.cmdloader.setCommandsKey(loadFuncName); this.runner.executeFunctionIfPresent(loadFuncName, new Object[]{this.cmdloader}); } catch (Exception var3) { MPLABLogger.mplog.log(Level.INFO, var3.getMessage()); } } public boolean initPlatformTool(String toolConnected) { boolean retVal = true; this.toolMeta = null; List listOfAllTools = PlatformToolMetaManager.getAllTools(); List platformTools = new LinkedList<>(); for (PlatformToolMeta meta : listOfAllTools) { platformTools.add(meta.getID()); } for (String platformTool : platformTools) { if (platformTool.equalsIgnoreCase(toolConnected)) { this.toolMeta = PlatformToolMetaManager.getTool(platformTool); break; } } return retVal; } public void initScript() { this.deviceActions.clear(); this.mediator = (ScriptMediator)this.shareData.getAssemblySession().getLookup().lookup(ScriptMediator.class); String platformID = this.toolMeta.getID(); String platformName = this.toolMeta.getName(); try { this.runner = this.mediator.setupRunner(platformID, platformName); if (this.runner != null) { File toolDeviceFile = this.runner.getToolDeviceFile(); if (toolDeviceFile != null) { if (toolDeviceFile.exists()) { this.checkForPythonFileExists = true; } } else { this.checkForPythonFileExists = false; } } } catch (Exception var4) { this.runner = this.mediator.getScriptRunner(Type.JYTHON2_7); } if (this.runnerId < 0) { this.runnerId = ScriptOptValidator.addNewRunner(this.runner); } this.runner.put("ide", this.cmdloader); this.loadToolScripts(); this.sig = this.toolMeta.getSignature(platformID); OptionLanguageSignatureProxy osp = (OptionLanguageSignatureProxy)this.sig; osp.setDocChanger(this.getChanger()); } public boolean getPythonFileStatus() { return this.checkForPythonFileExists; } public List listAdapters() throws ServiceQueryException { new ArrayList(); try { this.toolsLookup.Connect(); return this.toolsLookup.listAdapters(); } catch (ServiceQueryException var3) { throw new ServiceQueryException(var3.getErrorMessage()); } } public Map> listEnvironments(List adapters) throws ServiceQueryException { new HashMap(); try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.listEnvironments(adapters); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public Map getActiveEnvironments(List adapters) throws ServiceQueryException { new HashMap(); try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.getActiveEnvironments(adapters); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public Map getFirmwareInfo(List adapters) throws ServiceQueryException { new HashMap(); try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.getFirmwareInfo(adapters); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public void setActiveEnvironments(List adapters, String environment) throws ServiceQueryException { try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } this.toolsLookup.setActiveEnvironments(adapters, environment); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public void deleteEnvironments(String environment, List adapters) throws ServiceQueryException { try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } this.toolsLookup.deleteEnvironments(environment, adapters); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public void transferEnvironment(String environment, List adapters) throws ServiceQueryException { try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } this.toolsLookup.transferEnvironment(environment, adapters); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public List listPM5Units() throws ServiceQueryException { new ArrayList(); try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.listPM5Units(); } catch (ServiceQueryException var3) { throw new ServiceQueryException(var3.getErrorMessage()); } } public List listPM5MainSubUnits(String serialNum) throws ServiceQueryException { new ArrayList(); try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.listPM5MainSubUnits(serialNum); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public List listPM5MainEnvironments(String serialNum) throws ServiceQueryException { new ArrayList(); try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.listPM5MainEnvironments(serialNum); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public Map> listPM5MainSubEnvironments(String serialNum, List adapters) throws ServiceQueryException { new HashMap(); try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.listPM5MainSubEnvironments(serialNum, adapters); } catch (ServiceQueryException var5) { throw new ServiceQueryException(var5.getErrorMessage()); } } public Map getPM5MainSubActiveEnvironments(String serialNum, List adapters) throws ServiceQueryException { new HashMap(); try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.getPM5MainSubActiveEnvironments(serialNum, adapters); } catch (ServiceQueryException var5) { throw new ServiceQueryException(var5.getErrorMessage()); } } public void setPM5MainSubActiveEnvironments(String serialNum, List adapters, String environment) throws ServiceQueryException { try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } this.toolsLookup.setPM5MainSubActiveEnvironments(serialNum, adapters, environment); } catch (ServiceQueryException var5) { throw new ServiceQueryException(var5.getErrorMessage()); } } public void deletePM5MainEnvironments(String environment, String serialNum) throws ServiceQueryException { try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } this.toolsLookup.deletePM5MainEnvironments(environment, serialNum); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public void deletePM5MainSubEnvironments(String environment, String serialNum, List adapters) throws ServiceQueryException { try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } this.toolsLookup.deletePM5MainSubEnvironments(environment, serialNum, adapters); } catch (ServiceQueryException var5) { throw new ServiceQueryException(var5.getErrorMessage()); } } public Pm5Versions getPM5MainFirmwareInfo(String serialNum) throws ServiceQueryException { Pm5Versions pm5Version = null; try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.getPM5MainFirmwareInfo(serialNum); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public Map getPM5MainSubFirmwareInfo(String serialNum, List adapters) throws ServiceQueryException { new HashMap(); try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.getPM5MainSubFirmwareInfo(serialNum, adapters); } catch (ServiceQueryException var5) { throw new ServiceQueryException(var5.getErrorMessage()); } } public void transferPM5MainEnvironment(String environment, String serialNum) throws ServiceQueryException { try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } this.toolsLookup.transferPM5MainEnvironment(environment, serialNum); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public void transferEnvironmentToPM5MainSub(String environment, String serialNum, List adapters) throws ServiceQueryException { try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } this.toolsLookup.transferEnvironmentToPM5MainSub(environment, serialNum, adapters); } catch (ServiceQueryException var5) { throw new ServiceQueryException(var5.getErrorMessage()); } } public Map listPM5MainSubPgmStats(String environment, String serialNum, List adapters) throws ServiceQueryException { new HashMap(); try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.listPM5MainSubPgmStats(environment, serialNum, adapters); } catch (ServiceQueryException var6) { throw new ServiceQueryException(var6.getErrorMessage()); } } public String getPM5Logs(String serialNum) throws ServiceQueryException { String results = ""; try { if (!this.shareData.isConnected()) { this.toolsLookup.Connect(); } return this.toolsLookup.getPM5Logs(serialNum); } catch (ServiceQueryException var4) { throw new ServiceQueryException(var4.getErrorMessage()); } } public class CommandLoader { private String source; String uri = "http://crownking/opt"; public void addEnumProperty(Document tree, String id, String location, String name, String desc, String defaultVal, String choicesString) { IPELibrary.CommandLoader.InsertionPoint n = this.findInsertionPoint(tree, location); if (n != null) { String[] choices = choicesString.split("\n"); if (choices.length == 0) { IPELibrary.this.runner .printErrorMessage( "No selections were provided in <" + choicesString + ">. Please state selection list as \n separated selections , e.g. or ", "Script error" ); } else { Element newNode = tree.createElementNS(this.uri, "opt:enumOption"); newNode.setAttributeNS(this.uri, "opt:id", id); newNode.setAttributeNS(this.uri, "opt:name", name); newNode.setAttributeNS(this.uri, "opt:textdefault", defaultVal); if (!"".equals(desc)) { newNode.setTextContent(desc); } for (String c : choices) { String[] options = c.split("\\|"); if (options.length < 2) { IPELibrary.this.runner .printErrorMessage("Selection <" + c + "> is incomplete. Please describe as or ", "Script error"); } else { Element selectionNode = tree.createElementNS(this.uri, "opt:selection"); selectionNode.setAttributeNS(this.uri, "opt:text", options[0]); selectionNode.setAttributeNS(this.uri, "opt:name", options[1]); if (options.length > 2) { selectionNode.setTextContent(options[2]); } newNode.insertBefore(selectionNode, null); } } this.insertOrReplaceNodeBefore(n, newNode, id, true); } } } public String expandProjectMacros(String projectName, String params) { return this.expandProjectMacrosEx(projectName, null, params, true); } public String expandProjectMacrosEx(String projectName, String conf, String params, boolean debugMode) { return "board.xboard"; } public void addTextProperty(Document tree, String id, String location, String name, String desc, String defaultVal) { this.addTextPropertyExt(tree, id, location, name, desc, defaultVal, null); } public void addBooleanProperty(Document tree, String id, String location, String name, String desc, boolean defaultVal) { IPELibrary.CommandLoader.InsertionPoint n = this.findInsertionPoint(tree, location); if (n != null) { Element newNode = tree.createElementNS(this.uri, "opt:booleanOption"); newNode.setAttributeNS(this.uri, "opt:id", id); newNode.setAttributeNS(this.uri, "opt:name", name); newNode.setAttributeNS(this.uri, "opt:booldefault", defaultVal ? "true" : "false"); newNode.setTextContent(desc); this.insertOrReplaceNodeBefore(n, newNode, id, true); } } public void addCommand(String directory, String func) { this.addCommandWithArgs(directory, func); } public void addCommandWithArgs(String directory, String func) { String[] list = directory.split("\\|"); IPELibrary.this.deviceActions.put(list[list.length - 1], func); } public void addPropCategory(Document tree, String id, String location, String name) { IPELibrary.CommandLoader.InsertionPoint n = this.findInsertionPoint(tree, location); if (n != null) { Element newNode = tree.createElementNS(this.uri, "opt:optionCategory"); newNode.setAttributeNS(this.uri, "opt:id", id); newNode.setAttributeNS(this.uri, "opt:name", name); this.insertOrReplaceNodeBefore(n, newNode, id, false); Element dummyChild = tree.createElementNS(this.uri, "opt:stringOption"); dummyChild.setAttributeNS(this.uri, "opt:id", "lastid"); dummyChild.setAttributeNS(this.uri, "opt:name", "last"); dummyChild.setAttributeNS(this.uri, "opt:showif", "${dummy}"); newNode.appendChild(dummyChild); } } private IPELibrary.CommandLoader.InsertionPoint findInsertionPoint(Document tree, String location) { String[] path = location.split("\\|"); int pathLength = path.length; IPELibrary.CommandLoader.InsertionPoint p = new IPELibrary.CommandLoader.InsertionPoint(); p.parent = this.searchNode(tree, path, 0, pathLength - 1); if (p.parent == null) { IPELibrary.this.runner.printErrorMessage("Location " + location + " was not found in the opt file ", "Script error"); } p.child = this.searchNode(p.parent, path, pathLength - 1, pathLength); return p; } Node searchNode(Node n, String[] kw, int idx, int maxL) { if (idx == maxL) { return n; } else { for (Node var8 = n.getFirstChild(); var8 != null; var8 = var8.getNextSibling()) { if (var8.getNodeType() == 1) { Element e = (Element)var8; String id = e.getAttribute("opt:id"); if (kw[idx].equals("*") || id.equals(kw[idx])) { Node answer = this.searchNode(var8, kw, idx + 1, maxL); if (answer != null) { return answer; } } } } return null; } } public void addTextPropertyExt(Document tree, String id, String location, String name, String desc, String defaultVal, String validator) { IPELibrary.CommandLoader.InsertionPoint n = this.findInsertionPoint(tree, location); if (n != null) { Element newNode = tree.createElementNS(this.uri, "opt:stringOption"); newNode.setAttributeNS(this.uri, "opt:id", id); newNode.setAttributeNS(this.uri, "opt:name", name); if (validator != null) { newNode.setAttributeNS(this.uri, "opt:a0", Integer.toString(IPELibrary.this.runnerId)); newNode.setAttributeNS(this.uri, "opt:a1", validator); newNode.setAttributeNS(this.uri, "opt:validatorclass", "com.microchip.mplab.lib.scripting.ScriptOptValidator"); } newNode.setAttributeNS(this.uri, "opt:textpreferred", defaultVal); newNode.setTextContent(desc); this.insertOrReplaceNodeBefore(n, newNode, id, true); } } public void setCommandsKey(String s) { this.source = s; } private void insertOrReplaceNodeBefore(IPELibrary.CommandLoader.InsertionPoint ip, Node newNode, String id, boolean replace) { Node pn = ip.parent; Node n = ip.child; for (Node cn = pn.getFirstChild(); cn != null; cn = cn.getNextSibling()) { if (cn.getNodeType() == 1) { Element prevElement = (Element)cn; String nodeId = prevElement.getAttribute("opt:id"); if (nodeId.equals(id)) { if (n == cn) { n = n.getNextSibling(); } if (!replace) { return; } pn.removeChild(cn); break; } } } if (n == null) { pn.appendChild(newNode); } else { pn.insertBefore(newNode, n); } } class InsertionPoint { Node parent; Node child; } } class OptModifier implements DocumentChanger { public Document change(Document in) { IPELibrary.this.runner.executeFunctionIfPresent("onShowPropsDFP", new Object[]{in}); IPELibrary.this.runner.executeFunctionIfPresent("onShowProps", new Object[]{in}); return in; } } public final class ToolPackReleaseWithReasonIfNotFound { public final ToolPackRelease toolPackRelease; public final String reasonNotFound; public ToolPackReleaseWithReasonIfNotFound(ToolPackRelease toolPackRelease, String reasonNotFound) { this.toolPackRelease = toolPackRelease; this.reasonNotFound = reasonNotFound; } } public static enum ToolShortName { SNAP("snap"), ICD4("ICD_4_2"), ICD5("ICD_5"), PK4("PICkit_4"), PK5("PICkit_5"), PKOB4("Curiosity_Starter_Kits"), PKOB("Starter_Kits"), AICE("AtmelIce"), PM3("PM3"), PK3("PICkit3"), ICD3("ICD3"), Edbg("Edbg"), MEdbg("MEdbg"), NEdbg("NEdbg"), RICE("RealIce"), ICE4("ICE_4"), J32("j32"), PKBASIC("PICKITBasic"), PM5PA("PM5PA"), PM5("PM5"); private final String toolId; private ToolShortName(String toolId) { this.toolId = toolId; } public String getToolId() { return this.toolId; } } }