package com.microchip.mplab.ipelib.device; import com.microchip.crownking.edc.Programming; import com.microchip.crownking.mplabinfo.DeviceSupport.ToolSupport; import com.microchip.crownking.mplabinfo.FamilyDefinitions.Family; import com.microchip.crownking.mplabinfo.FamilyDefinitions.SubFamily; import com.microchip.mplab.comm.MPLABCommEvent; import com.microchip.mplab.comm.MPLABCommProviderInterface; import com.microchip.mplab.comm.MPLABCommStringDescriptor; import com.microchip.mplab.comm.MPLABCommTool; import com.microchip.mplab.crownkingx.xPIC; import com.microchip.mplab.ipelib.common.SharedData; import com.microchip.mplab.ipelib.tools.IPENotifier; import com.microchip.mplab.ipelib.toolsupport.ToolSupportProvider; import com.microchip.mplab.libs.packmanagerservice.interfaces.MPLABPackContext; import com.microchip.mplab.libs.packmanagerservice.packmanagerservicefactory.PackManagerService; import com.microchip.mplab.libs.toolpacksupport.interfaces.ToolPackRelease; import com.microchip.mplab.logger.MPLABLogger; import com.microchip.mplab.mdbcore.MessageMediator.Message; import com.microchip.mplab.mdbcore.assemblies.Assembly; import com.microchip.mplab.mdbcore.assemblies.AssemblyFactory; import com.microchip.mplab.mdbcore.checksum.Checksum; import com.microchip.mplab.mdbcore.checksum.common.BufferChecksumHelper.MemoryRegion; import com.microchip.mplab.mdbcore.common.debug.CommonUtils; import com.microchip.mplab.mdbcore.common.debug.CommonEnumerations.coordinatedResetOperation; import com.microchip.mplab.mdbcore.debugger.DebugException; import com.microchip.mplab.mdbcore.debugger.Debugger; import com.microchip.mplab.mdbcore.debugger.MCDebugger; import com.microchip.mplab.mdbcore.debugger.MDBDebugTool; import com.microchip.mplab.mdbcore.debugger.SDCardInterface; import com.microchip.mplab.mdbcore.debugger.Debugger.CONNECTION_TYPE; import com.microchip.mplab.mdbcore.debugger.Debugger.PROGRAM_OPERATION; import com.microchip.mplab.mdbcore.debugger.MDBDebugTool.MEMTYPE; import com.microchip.mplab.mdbcore.pa.service.commands.FirmwareInfo; import com.microchip.mplab.mdbcore.platformtool.PlatformTool; import com.microchip.mplab.mdbcore.platformtool.PlatformToolBrowser; import com.microchip.mplab.mdbcore.platformtool.PlatformToolMeta; import com.microchip.mplab.mdbcore.platformtool.PlatformToolMetaManager; import com.microchip.mplab.mdbcore.platformtool.util.PlatformMPLABCommStringParser; import com.microchip.mplab.mdbcore.pm5.service.commands.responses.Pm5Versions; import com.microchip.mplab.mdbcore.pm5.service.utils.ServiceQueries; import com.microchip.mplab.mdbcore.pm5.service.utils.ServiceQueryException; import com.microchip.mplab.mdbcore.sqtpenv.SQTPEnvironment; import com.microchip.mplab.mdbcore.sqtpenv.SQTPEnvironment.SQTPError; import com.microchip.mplab.mdbcore.sqtpenv.pm3EnvExtractor.EnvStructure; import com.microchip.mplab.util.observers.Observer; import java.io.File; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.logging.Level; import org.openide.util.Lookup; import org.openide.util.Utilities; import org.openide.util.Lookup.Result; public class ToolsLookup implements Observer { PlatformToolBrowser browser = null; ArrayList toolsList = new ArrayList(); ArrayList Serial_toolsList = new ArrayList(); private SharedData sharedData; List connectedTools; private String s = ""; private AssemblyFactory af; private Assembly session = null; public boolean toolChanged = false; private IPENotifier ipeNotify = null; private boolean hold_tool_scan = false; private HashMap mytoolsmap; private boolean isPM3ToolOnly = false; private String deviceToCheck; private static int pm3Count = 0; private MPLABCommProviderInterface comm = null; private boolean holdInReset = true; private ServiceQueries pm5Services = null; public ToolsLookup(boolean noDoScan) { this.ipeNotify = IPENotifier.getIPENotifierController(); this.browser = new PlatformToolBrowser(this); this.sharedData = SharedData.getSingletonObject(); this.mytoolsmap = new LinkedHashMap<>(); this.isPM3ToolOnly = true; } public ToolsLookup() { this.ipeNotify = IPENotifier.getIPENotifierController(); this.browser = new PlatformToolBrowser(this); this.sharedData = SharedData.getSingletonObject(); this.mytoolsmap = new HashMap<>(); try { boolean var1 = this.doScan(); } catch (Exception var2) { } } public void UpdateToolList() { this.doScan(); this.ipeNotify.setToolList(this.toolsList, ""); } public boolean Pm3hasSDCard() { Debugger mdb = this.sharedData.getDebugger(); boolean retVal = false; if (!this.sharedData.getAssemblySession().GetToolName().contains("PM3")) { return false; } else { try { if (mdb != null) { this.s = ""; this.hold_tool_scan = true; mdb.Connect(CONNECTION_TYPE.PROGRAMMER); retVal = this.sharedData.getSDCardInterface().PM3hasSDCard(); } else { retVal = false; } } catch (Exception var4) { this.s = var4.toString(); retVal = false; } this.hold_tool_scan = false; return retVal; } } public boolean FormatPM3SDCard() { Debugger mdb = this.sharedData.getDebugger(); boolean retVal = false; try { if (mdb != null) { this.s = ""; this.hold_tool_scan = true; mdb.Connect(CONNECTION_TYPE.PROGRAMMER); retVal = this.sharedData.getSDCardInterface().FormatPM3SDCard(); } else { retVal = false; } } catch (Exception var4) { this.s = var4.toString(); retVal = false; } this.hold_tool_scan = false; return retVal; } public EnvStructure getEnvStructure() { EnvStructure retVal = null; try { this.s = ""; this.hold_tool_scan = true; retVal = ((SQTPEnvironment)this.sharedData.getAssemblySession().lookup(SQTPEnvironment.class)).getEnvStructure(); } catch (Exception var3) { this.s = var3.toString(); retVal = null; } this.hold_tool_scan = false; return retVal; } public String GetPM3EnvironmentFromPM3SDCard(String path, boolean b) { Debugger mdb = this.sharedData.getDebugger(); String retVal = ""; try { if (mdb != null) { this.s = ""; this.hold_tool_scan = true; mdb.Connect(CONNECTION_TYPE.PROGRAMMER); retVal = this.sharedData.getSDCardInterface().GetPM3EnvironmentFromPM3SDCard(path, b); } else { retVal = ""; } } catch (Exception var6) { this.s = var6.toString(); retVal = ""; } this.hold_tool_scan = false; return retVal; } public boolean transferImageToPM3() { if (this.isGreaterThan1MB()) { IPENotifier.getIPENotifierController().setMessageNotification("Transferring image is not supported for this device."); return false; } else { Debugger mdb = this.sharedData.getDebugger(); boolean retVal = false; if (!this.sharedData.getAssemblySession().GetToolName().contains("PM3")) { return false; } else { try { if (mdb != null) { this.s = ""; mdb.Connect(CONNECTION_TYPE.PROGRAMMER); retVal = this.sharedData.getSDCardInterface().TransferToPM3(); } else { retVal = false; } } catch (Exception var4) { this.s = var4.toString(); retVal = false; } return retVal; } } } private boolean isGreaterThan1MB() { boolean isGreaterthan1MB = false; xPIC picdevicedb = this.session.GetDevice(); if (picdevicedb != null && (picdevicedb.getFamily() == Family.SEE || picdevicedb.getFamily() == Family.SST)) { if (((Long)picdevicedb.getEEDataRange().second + 1L - (Long)picdevicedb.getEEDataRange().first) / 1048576L > 1L) { isGreaterthan1MB = true; } } else if (picdevicedb.getSubFamily() == SubFamily.PIC32 && ((Long)picdevicedb.getCodeRange().second + 1L - (Long)picdevicedb.getCodeRange().first) / 1048576L > 1L) { isGreaterthan1MB = true; } return isGreaterthan1MB; } public boolean transferImageFromPM3() { if (this.isGreaterThan1MB()) { IPENotifier.getIPENotifierController().setMessageNotification("\nTransferring image is not supported for this device.\n"); return false; } else { Debugger mdb = this.sharedData.getDebugger(); boolean retVal = false; if (!this.sharedData.getAssemblySession().GetToolName().contains("PM3")) { return false; } else { try { if (mdb != null) { this.s = ""; mdb.Connect(CONNECTION_TYPE.PROGRAMMER); retVal = this.sharedData.getSDCardInterface().TransferToPC(); } else { retVal = false; } } catch (Exception var4) { this.s = var4.toString(); retVal = false; } return retVal; } } } public ArrayList getSerialToolsList() { return this.Serial_toolsList; } public String getDeviceID() { Debugger mdb = this.sharedData.getDebugger(); String t = ""; try { t = mdb.GetDeviceIDInfo(); } catch (DebugException var4) { } return t; } public List getConnectedTools() { return this.connectedTools; } public static ArrayList removeDuplicates(ArrayList list) { ArrayList newList = new ArrayList<>(); for (T element : list) { if (!newList.contains(element)) { newList.add(element); } } return newList; } private boolean doScan() { String smallName = null; if (this.browser == null) { return false; } else { this.toolsList.clear(); pm3Count = 0; this.browser.scan(); this.connectedTools = this.browser.getExistingTools(); Map toolAvailability = this.browser.getToolAvailability(); for (PlatformTool t : this.connectedTools) { String platformToolID = t.getID(); String platformToolClassName = PlatformToolMetaManager.getTool(platformToolID).getClassName(); String platformToolFlavor = PlatformToolMetaManager.getTool(platformToolID).getFlavor(); List ts = null; ts = PlatformToolMetaManager.getTool(platformToolID).getToolSupportForDevice(this.deviceToCheck); String sNo = PlatformMPLABCommStringParser.getSerialNumber(t.getToolDescriptor()); if (sNo.contains("null") && t.getToolDescriptor().contains("")) { sNo = this.getIPAddressFromDescription(t.getToolDescriptor()); } String toolDesc = t.getToolDescriptor(); ToolSupportProvider toolserprovider = ToolSupportProvider.getSingletonObject(); toolserprovider.setToolSerialNumber(sNo); int totals = 0; boolean supported = true; if (sNo != null) { totals++; for (PlatformToolMeta meta : PlatformToolMetaManager.getAllTools()) { supported = true; if (t.getID().equalsIgnoreCase(meta.getID())) { smallName = t.getName(); if (smallName.equalsIgnoreCase("pm3")) { pm3Count++; } break; } supported = false; } if (supported) { if (toolAvailability != null && toolAvailability.containsKey(t.getIndex()) && !toolAvailability.get(t.getIndex()) && Utilities.isWindows()) { smallName = "Incompatible driver -" + smallName; } String toDisplay = smallName + " S.No : " + sNo; if (smallName.contains("PM5") && this.isIPAddress(sNo)) { toDisplay = smallName + " IP:" + sNo; } if (smallName.contains("PM3") && pm3Count > 1) { this.ipeNotify.setMessageNotification("Warning: More than one PM3 is connected\n"); } this.toolsList.add(toDisplay); this.toolsList = removeDuplicates(this.toolsList); ToolsLookup.ToolDetails toolDetails = new ToolsLookup.ToolDetails(); toolDetails.toolClass = platformToolClassName; toolDetails.toolFlavour = platformToolFlavor; toolDetails.toolSN = toolDesc; toolDetails.ts = ts; toolDetails.toolID = platformToolID; toolDetails.toolName = smallName; this.mytoolsmap.put(toDisplay, toolDetails); } } } return true; } } public void initAttachTool() { this.comm = (MPLABCommProviderInterface)Lookup.getDefault().lookup(MPLABCommProviderInterface.class); if (this.comm != null) { this.comm.Attach(this, null); } } public String getToolIDFromMapInfo(String toolAsShown) { String retID = null; ToolsLookup.ToolDetails td = this.mytoolsmap.get(toolAsShown); if (td != null) { retID = td.toolID; } return retID; } public List getSupport(String toolAsShown, String dev) { this.deviceToCheck = dev; this.doScan(); return this.mytoolsmap.get(toolAsShown).ts; } public String[] doScan_matlab() { String smallName = null; PlatformToolBrowser browser = new PlatformToolBrowser(this); if (browser != null) { this.toolsList.clear(); browser.scan(); this.connectedTools = browser.getExistingTools(); String[] tList = new String[this.connectedTools.size()]; int ind = 0; for (PlatformTool t : this.connectedTools) { String platformToolID = t.getID(); String platformToolClassName = PlatformToolMetaManager.getTool(platformToolID).getClassName(); String platformToolFlavor = PlatformToolMetaManager.getTool(platformToolID).getFlavor(); String sNo = PlatformMPLABCommStringParser.getSerialNumber(t.getToolDescriptor()); String toolDesc = t.getToolDescriptor(); int totals = 0; boolean supported = true; if (sNo != null) { totals++; supported = true; if (t.getID().equals("RealICEPlatformTool")) { smallName = "Real ICE"; } else if (t.getID().equals("PICkit3PlatformTool")) { smallName = "PICkit3"; } else if (t.getID().equals("ICD3PlatformTool")) { smallName = "ICD 3"; } else if (t.getID().equals("PM3PlatformTool")) { smallName = "PM3"; } else if (t.getID().equals("PK3OBPlatformTool")) { smallName = "PKOB"; } else if (t.getID().equals("PKOBSKDEPlatformTool")) { smallName = "PKOB SKDE"; } else if (t.getID().equals("pk4hybrid")) { smallName = "PICkit4"; } else { supported = false; } if (supported) { String toDisplay = smallName + " S.No : " + sNo; tList[ind] = toDisplay; ind++; this.toolsList.add(toDisplay); ToolsLookup.ToolDetails toolDetails = new ToolsLookup.ToolDetails(); toolDetails.toolClass = platformToolClassName; toolDetails.toolFlavour = platformToolFlavor; toolDetails.toolSN = toolDesc; toolDetails.toolID = platformToolID; this.mytoolsmap.put(toDisplay, toolDetails); } } } return tList; } else { return null; } } public boolean readMemory() throws DebugException { int retDebugBit = 0; boolean retVal = false; Debugger mdb = this.sharedData.getDebugger(); if (!this.sharedData.getAssemblySession().GetPluginBoardName().equals("")) { mdb.Disconnect(); } try { if (mdb == null) { return false; } this.s = ""; this.hold_tool_scan = true; mdb.Connect(CONNECTION_TYPE.PROGRAMMER); retDebugBit = mdb.UploadRawDebugImage(); if (retDebugBit != 0) { if (!this.sharedData.getUIMode()) { System.out.println("IPE:Warning: Debug bit is set on target image. This may not run correctly in production.\n"); } else { this.ipeNotify.setMessageNotification("Warning: Debug bit is set on target image. This may not run correctly in production.\n"); } } retVal = true; } catch (Exception var7) { this.s = var7.toString(); if (var7 instanceof DebugException && ((DebugException)var7).Code() == 11) { if (!this.sharedData.getUIMode()) { throw (DebugException)var7; } com.microchip.mplab.mdbcore.MessageMediator.MessageMediator mm = (com.microchip.mplab.mdbcore.MessageMediator.MessageMediator)Lookup.getDefault() .lookup(com.microchip.mplab.mdbcore.MessageMediator.MessageMediator.class); Message msg = new Message(var7.getMessage(), "Partition mode mismatch", null, 35); mm.handleMessage(msg, 12); } retVal = false; } this.hold_tool_scan = false; return retVal; } public boolean eraseMemory() { boolean retVal = false; Debugger mdb = this.sharedData.getDebugger(); if (!this.sharedData.getAssemblySession().GetPluginBoardName().equals("")) { mdb.Disconnect(); } try { if (mdb != null) { this.s = ""; this.hold_tool_scan = true; mdb.Connect(CONNECTION_TYPE.PROGRAMMER); mdb.Erase(); retVal = true; } else { retVal = false; } } catch (Exception var4) { this.s = var4.toString(); retVal = false; } this.hold_tool_scan = false; return retVal; } public boolean WriteMemory() { boolean retVal = false; Debugger mdb = this.sharedData.getDebugger(); if (!this.sharedData.getAssemblySession().GetPluginBoardName().equals("")) { mdb.Disconnect(); } try { if (mdb == null) { return retVal; } this.s = ""; this.hold_tool_scan = true; if (this.isCoordinatedResetAndProgramOpRequired()) { CECOTPSupport cecObject = new CECOTPSupport(mdb, this.session); retVal = cecObject.processCECOTPMemory(false); } else { mdb.Connect(CONNECTION_TYPE.PROGRAMMER); mdb.Program(PROGRAM_OPERATION.AUTO_SELECT); retVal = true; } } catch (Exception var4) { this.s = var4.toString(); retVal = false; } this.hold_tool_scan = false; return retVal; } public boolean verifyMemory() { boolean result = false; Debugger mdb = this.sharedData.getDebugger(); if (!this.sharedData.getAssemblySession().GetPluginBoardName().equals("")) { mdb.Disconnect(); } try { if (mdb == null) { return false; } this.s = ""; this.hold_tool_scan = true; if (this.isCoordinatedResetAndProgramOpRequired() && this.sharedData.getOTPForCECDevice()) { CECOTPSupport cecObject = new CECOTPSupport(mdb, this.session); result = cecObject.processCECOTPMemory(true); } else { mdb.Connect(CONNECTION_TYPE.PROGRAMMER); result = mdb.Verify(); } } catch (Exception var4) { this.s = var4.toString(); this.ipeNotify.setMessageNotification("IPE:Verify Failed"); result = false; } this.hold_tool_scan = false; return result; } public String getErrorString() { return this.s; } public boolean blankCheck() { boolean result = false; Debugger mdb = this.sharedData.getDebugger(); if (!this.sharedData.getAssemblySession().GetPluginBoardName().equals("")) { mdb.Disconnect(); } try { if (mdb == null) { return false; } this.s = ""; this.hold_tool_scan = true; mdb.Connect(CONNECTION_TYPE.PROGRAMMER); result = mdb.BlankCheck(); } catch (Exception var4) { this.s = var4.toString(); this.ipeNotify.setMessageNotification("IPE:Blank Check Failed"); result = false; } this.hold_tool_scan = false; return result; } public boolean justConnect() { Debugger mdb = this.sharedData.getDebugger(); try { if (mdb == null) { return false; } this.s = ""; this.hold_tool_scan = true; mdb.Connect(CONNECTION_TYPE.PROGRAMMER); } catch (Exception var3) { this.s = var3.toString(); return false; } this.hold_tool_scan = false; return true; } public boolean createAssemblySession(String deviceName) { this.af = (AssemblyFactory)Lookup.getDefault().lookup(AssemblyFactory.class); try { this.session = this.af.Create(deviceName); } catch (Exception var3) { return false; } if (this.session != null) { this.session.SetHeader(""); this.session.SetPluginBoard(""); if (this.session != null) { this.sharedData = SharedData.getSingletonObject(); this.sharedData.setAssembly(this.session); } if (this.af != null) { this.sharedData = SharedData.getSingletonObject(); this.sharedData.setassemblyFactory(this.af); } return true; } else { return false; } } public boolean createAssemblySession(String deviceSelected, String packName, String packVersion, String packVendor, ToolPackRelease toolPackRelease) { this.af = (AssemblyFactory)Lookup.getDefault().lookup(AssemblyFactory.class); try { MPLABPackContext pack = new MPLABPackContext(packName, packVersion, packVendor); this.session = this.af.Create(deviceSelected, PackManagerService.getDeviceProvider().getDevice(deviceSelected, pack), toolPackRelease); } catch (Exception var7) { return false; } if (this.session != null) { this.session.SetHeader(""); this.session.SetPluginBoard(""); this.sharedData = SharedData.getSingletonObject(); this.sharedData.setAssembly(this.session); if (this.af != null) { this.sharedData.setassemblyFactory(this.af); return true; } else { return false; } } else { return false; } } public void Update(Object test) { MPLABCommEvent event = (MPLABCommEvent)test; MPLABCommTool tool = event.Tool; int index = event.ListIndex; MPLABCommStringDescriptor dev = (MPLABCommStringDescriptor)tool.GetDescriptor(-2, 0, 0); this.comm = (MPLABCommProviderInterface)Lookup.getDefault().lookup(MPLABCommProviderInterface.class); String friendlyName = this.comm.GetFriendlyName(index); PlatformTool t = this.getToolInfoFromToolString(dev.content, index, friendlyName); if (event.EventType == 1) { try { if (!this.hold_tool_scan) { boolean retVal = this.doScan(); retVal = this.ipeNotify.setToolList(this.toolsList, ""); } } catch (Exception var12) { } } else if (event.EventType == 0) { if (t != null && t.getName().contains("PM3") && pm3Count > 0) { pm3Count--; } try { String smallName = ""; if (!this.hold_tool_scan) { this.doScan(); for (PlatformToolMeta meta : PlatformToolMetaManager.getAllTools()) { if (t.getID().equalsIgnoreCase(meta.getID())) { smallName = t.getName(); break; } } String sNo = PlatformMPLABCommStringParser.getSerialNumber(t.getToolDescriptor()); this.ipeNotify.setToolList(this.toolsList, smallName + " S.No : " + sNo); } } catch (Exception var13) { } } } private PlatformTool getToolInfoFromToolString(String toolString, int index, String friendlyName) { String[] fields = PlatformMPLABCommStringParser.splitFields(toolString); String vid = PlatformMPLABCommStringParser.getVid(fields); String pid = PlatformMPLABCommStringParser.getPid(fields); String serialNumber = PlatformMPLABCommStringParser.getSerialNumber(toolString); String toolID = null; String toolName = null; String product = null; PlatformToolMeta platformTool; if (vid != null && !vid.isEmpty() && pid != null && !pid.isEmpty()) { platformTool = PlatformToolMetaManager.getToolWithVIDPID(vid + pid); } else { platformTool = PlatformToolMetaManager.getToolWithManAndProd( PlatformMPLABCommStringParser.getManufacturerString(toolString), PlatformMPLABCommStringParser.getProductIDString(toolString) ); } if (platformTool != null) { toolID = platformTool.getID(); toolName = platformTool.getName(); product = platformTool.getProduct(); } PlatformTool res = null; if (toolName != null) { res = new PlatformTool(toolID, toolName, index, toolString, friendlyName, vid + pid, product); } return res; } public boolean connectNonROHSPM3(Debugger mdb) { boolean retVal = false; if (mdb != null) { this.af .ChangeTool( this.session, "PM3PlatformTool", "com.microchip.mplab.mdbcore.PM3.PgmToolManager", "programmer", ":=MPLABComm-USB-Microchip:=04D8:=A001:=0004:=?:=?:=?:=x:=b:=end" ); try { mdb.Connect(CONNECTION_TYPE.PROGRAMMER); retVal = true; } catch (DebugException var4) { retVal = false; } } return retVal; } private String getPM3SerialNoInformation() { MPLABCommProviderInterface commProviderInterface = null; if (commProviderInterface == null) { commProviderInterface = (MPLABCommProviderInterface)Lookup.getDefault().lookup(MPLABCommProviderInterface.class); } if (commProviderInterface != null) { Map toolMap = commProviderInterface.GetCurrentToolList(); for (int i : toolMap.keySet()) { String dev = toolMap.get(i); if (commProviderInterface.GetToolState(i, 0) == 1 && dev.contains("A001")) { return dev; } } } return null; } public Boolean getPM3SerialInformation() { boolean retval = false; if (Boolean.parseBoolean(this.session.GetToolProperties().getProperty("com.port", "false"))) { this.Serial_toolsList.clear(); MPLABCommProviderInterface commProviderInterface = null; if (commProviderInterface == null) { commProviderInterface = (MPLABCommProviderInterface)Lookup.getDefault().lookup(MPLABCommProviderInterface.class); } if (commProviderInterface != null) { Map toolMap = commProviderInterface.GetCurrentToolList(null, "MPLABComm-USB(04D8),MPLABComm-SERIALPORT-Range(1-100)", null, null); for (int i : toolMap.keySet()) { String dev = toolMap.get(i); if (commProviderInterface.GetToolState(i, 0) == 1 && dev.contains("SERIAL")) { int ind = dev.indexOf("COM"); int ind1 = dev.indexOf(":=end"); String port = dev.substring(ind, ind1); this.Serial_toolsList.add(this.Serial_toolsList.size(), "PM3 " + port); ToolsLookup.ToolDetails td = new ToolsLookup.ToolDetails(); td.toolID = "PM3PlatformTool"; td.toolClass = "com.microchip.mplab.mdbcore.PM3.PgmToolManager"; td.toolFlavour = "programmer"; td.toolSN = dev; this.mytoolsmap.put("PM3 " + port, td); retval = true; } } } return retval; } else { this.doScan(); this.ipeNotify.setToolList(this.toolsList, ""); return true; } } private String getIPAddressFromDescription(String description) { String prod = "?"; int si = description.indexOf(":="); if (si != -1) { String ssn = description.substring(si + 7); int ei = ssn.indexOf(":="); prod = ssn.substring(0, ei); } return prod; } public boolean createDebuggerSession(String toolCboxitem) { boolean retVal = false; try { if (toolCboxitem != null && !this.isPM3ToolOnly) { ToolsLookup.ToolDetails toolInfo = this.mytoolsmap.get(toolCboxitem); if (toolInfo != null) { if (toolInfo.toolSN.contains("")) { String ip = this.getIPAddressFromDescription(toolInfo.toolSN); this.session.GetToolProperties().setProperty("pm5.ethernet.ipaddress", ip); } this.af.ChangeTool(this.session, toolInfo.toolID, toolInfo.toolClass, toolInfo.toolFlavour, toolInfo.toolSN); retVal = true; } } if (this.isPM3ToolOnly) { String retString = this.getPM3SerialNoInformation(); if (retString != null) { this.af.ChangeTool(this.session, "PM3PlatformTool", "com.microchip.mplab.mdbcore.PM3.PgmToolManager", "programmer", retString); retVal = true; } } if (!this.sharedData.getUIMode()) { this.sharedData.getassemblyFactory().SetToolProperties(this.session, this.sharedData.getCoreParameters()); } Debugger mdb = (Debugger)this.session.getLookup().lookup(Debugger.class); this.sharedData.setDebugger(mdb); SDCardInterface sdc = (SDCardInterface)this.session.getLookup().lookup(SDCardInterface.class); this.sharedData.setSDCard(sdc); } catch (Exception var5) { var5.printStackTrace(); retVal = false; } return retVal; } public boolean Connect() { boolean retVal = false; Debugger mdb = this.sharedData.getDebugger(); if (mdb != null) { try { this.hold_tool_scan = true; mdb.Connect(CONNECTION_TYPE.PROGRAMMER); retVal = true; } catch (DebugException var4) { retVal = false; } this.sharedData.setDebugger(mdb); } this.hold_tool_scan = false; return retVal; } public boolean disconnectTarget() { boolean result = false; try { Debugger mdb = this.sharedData.getDebugger(); if (mdb != null) { mdb.Disconnect(); this.sharedData.setDebugger(mdb); } return result; } catch (Exception var3) { this.s = var3.toString(); return false; } } public void releaseFromReset() throws DebugException { Debugger mdb = this.sharedData.getDebugger(); if (mdb != null) { this.holdInReset = false; mdb.ReleaseFromReset(); } } public void holdInReset() throws DebugException { Debugger mdb = this.sharedData.getDebugger(); if (mdb != null) { this.holdInReset = true; mdb.HoldInReset(); } } public boolean connectAsPTG() { Debugger mdb = this.sharedData.getDebugger(); if (mdb != null) { mdb.Disconnect(); try { this.hold_tool_scan = true; mdb.Connect(CONNECTION_TYPE.PROGRAMMER_TO_GO); if (this.holdInReset) { mdb.HoldInReset(); } mdb.Program(PROGRAM_OPERATION.PROGRAMMER_TO_GO); return true; } catch (DebugException var3) { return false; } } else { this.hold_tool_scan = false; return false; } } public ArrayList getActiveToolList() { boolean retVal = this.doScan(); return retVal ? this.toolsList : null; } public ArrayList getCurrentAvailableToolList() { return this.toolsList; } public long getCRC32(File f) { Checksum ckSum = (Checksum)this.sharedData.getAssemblySession().lookup(Checksum.class); long ret = -1L; try { ret = ckSum.getCRC32FileChecksum(f); } catch (Exception var6) { ret = -1L; } return ret; } public long getChecksum() { Checksum ckSum = (Checksum)this.sharedData.getAssemblySession().lookup(Checksum.class); long ret = -1L; try { ret = ckSum.getChecksum(false); } catch (Exception var5) { ret = -1L; } return ret; } public long getUnprotectedCsum() { Checksum ckSum = (Checksum)this.sharedData.getAssemblySession().lookup(Checksum.class); long ret = -1L; try { ret = ckSum.getUnprotectedChecksum(); } catch (Exception var5) { ret = -1L; } return ret; } public long getEEChecksum() { Checksum ckSum = (Checksum)this.sharedData.getAssemblySession().lookup(Checksum.class); long ret = -1L; try { ret = ckSum.getEEPROMonlyChecksum(); } catch (Exception var5) { ret = -1L; } return ret; } public long getFlashdataChecksum() { Checksum ckSum = (Checksum)this.sharedData.getAssemblySession().lookup(Checksum.class); long ret = -1L; try { ret = ckSum.getFlashDataonlyChecksum(); } catch (Exception var5) { ret = -1L; } return ret; } public boolean hasChecksum() { boolean bHasChecksum = true; xPIC picdevicedb = this.session.GetDevice(); try { if (picdevicedb instanceof xPIC) { Programming program = picdevicedb.getProgramming(); if (program != null) { bHasChecksum = program.getAsBooleanElse("haschecksum", true); if (picdevicedb.getFamily() == Family.ARM32BIT || picdevicedb.getFamily() == Family.AVR || !bHasChecksum) { bHasChecksum = false; } } } } catch (Exception var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); } return bHasChecksum; } public Map getBufferChecksum() { Map res = null; try { Checksum ckSum = (Checksum)this.sharedData.getAssemblySession().lookup(Checksum.class); res = ckSum.getBufferChecksum(); } catch (Exception var3) { res = null; } return res; } public boolean setSQTPEnvironment() { boolean retVal = false; SQTPEnvironment SQTPEnv = (SQTPEnvironment)this.sharedData.getAssemblySession().lookup(SQTPEnvironment.class); if (SQTPEnv != null) { this.sharedData.setSQTPEnvironment(SQTPEnv); retVal = SQTPEnv.intializeEnvironment(); } else { retVal = false; } return retVal; } public boolean loadEnvironment(String path) { boolean retVal = false; SQTPEnvironment SQTPEnv = this.sharedData.getSQTPEnvironment(); if (SQTPEnv != null) { System.out.print("IPE:Loading Environment..."); retVal = SQTPEnv.LoadPM3File(path); } else { retVal = false; } return retVal; } public boolean deleteEnvironment(String path) { boolean retVal = false; SQTPEnvironment SQTPEnv = this.sharedData.getSQTPEnvironment(); if (SQTPEnv != null) { retVal = SQTPEnv.deleteEnvironment(path); } else { retVal = false; } return retVal; } public boolean viewEnviroment(String path) { boolean retVal = false; SQTPEnvironment SQTPEnv = this.sharedData.getSQTPEnvironment(); if (SQTPEnv != null) { retVal = SQTPEnv.viewEnvironment(path); } else { retVal = false; } return retVal; } public boolean copyEnviroment(String srcPath, String dstPath, String srcEnvString, String dstEnvString) { boolean retVal = false; SQTPEnvironment SQTPEnv = this.sharedData.getSQTPEnvironment(); if (SQTPEnv != null) { retVal = SQTPEnv.copyEnvironment(srcPath, dstPath, srcEnvString, dstEnvString); } else { retVal = false; } return retVal; } public boolean saveEnvironment(String envPath, String envName, boolean isPM3File, String sqtpFile, String miscFile, String envDesc) { boolean retVal = false; SQTPEnvironment SQTPEnv = this.sharedData.getSQTPEnvironment(); if (SQTPEnv != null) { retVal = SQTPEnv.saveEnvironment(envPath, envName, isPM3File, sqtpFile, miscFile, envDesc); } else { retVal = false; } if (!retVal) { this.disconnectTarget(); } return retVal; } public SQTPError setSQTPSequence(String numPath) { SQTPError error = null; SQTPEnvironment SQTPEnv = this.sharedData.getSQTPEnvironment(); if (SQTPEnv != null) { error = SQTPEnv.LoadSQTPValue(numPath); } else { error = SQTPError.OTHER_ERROR; } return error; } public void UnloadSQTPFile() { SQTPError error = null; SQTPEnvironment SQTPEnv = this.sharedData.getSQTPEnvironment(); if (SQTPEnv != null) { SQTPEnv.UnloadSQTPFile(); } } public SQTPError loadNextSQTPSequence(String numPath) { SQTPError error = null; SQTPEnvironment SQTPEnv = this.sharedData.getSQTPEnvironment(); if (numPath.contains("MPLAB PM3 Card")) { SDCardInterface sdcard = this.sharedData.getSDCardInterface(); String num = numPath.replace("\\", "/"); num = num.replace("MPLAB PM3 Card/", ""); sdcard.UpdatePm3SQTPFile(num); } if (SQTPEnv != null) { error = SQTPEnv.LoadSQTPValue(numPath); if (error == SQTPError.SUCCESS) { error = SQTPEnv.LoadNextSQTPValue(); error = SQTPEnv.LoadSQTPValue(numPath); Long address = SQTPEnv.getAddressValue(); String memType = SQTPEnv.getmemType(); String nextSqtpSequence = SQTPEnv.getNextSqtpValuetobeLoaded(); if (error != SQTPError.FILE_EXHAUSTED) { String msg = "Next SQTP: (Data = 0x" + nextSqtpSequence + " , Address = 0x" + Long.toHexString(address) + " Region = " + memType + ")"; IPENotifier.getIPENotifierController().setMessageNotification(msg + "\n"); } } } else { error = SQTPError.OTHER_ERROR; } return error; } public int getPM3Checksum() { int retVal = -1; SDCardInterface si = this.sharedData.getSDCardInterface(); if (si != null) { retVal = si.GetDeviceChecksum(); } return retVal; } public int getPM3DeviceID() { int retVal = -1; SDCardInterface si = this.sharedData.getSDCardInterface(); if (si != null) { retVal = si.GetDeviceId(); } return retVal; } public boolean DownloadOS(String path) { boolean retVal = false; SDCardInterface si = this.sharedData.getSDCardInterface(); if (si != null) { retVal = si.DownloadOS(path); } return retVal; } public boolean DownloadBIOS(String path) { boolean retVal = false; SDCardInterface si = this.sharedData.getSDCardInterface(); if (si != null) { retVal = si.DownloadBIOS(path); } return retVal; } public boolean DownloadDB(String path) { boolean retVal = false; SDCardInterface si = this.sharedData.getSDCardInterface(); if (si != null) { retVal = si.DownloadDB(path); } return retVal; } public int getPM3DeviceIDRevision() { int retVal = -1; SDCardInterface si = this.sharedData.getSDCardInterface(); if (si != null) { retVal = si.GetDeviceIdRevision(); } return retVal; } public int getPM3ErrorCode() { int retVal = -1; SDCardInterface si = this.sharedData.getSDCardInterface(); if (si != null) { retVal = si.GetErrorCode(); } return retVal; } public void setPM3toSafeMode(boolean safeModeFlag) { boolean retVal = false; SDCardInterface si = this.sharedData.getSDCardInterface(); if (si != null) { si.setSafeMode(safeModeFlag); } } public boolean SaveOStoPM3Card() { boolean retVal = false; SDCardInterface si = this.sharedData.getSDCardInterface(); if (si != null) { retVal = si.SaveOStoPM3Card(); } return retVal; } public boolean WriteAVR_ARMFuses(Optional start, Optional end) { boolean retVal = false; Debugger mdb = this.sharedData.getDebugger(); if (!this.sharedData.getAssemblySession().GetPluginBoardName().equals("")) { mdb.Disconnect(); } try { if (mdb == null) { return retVal; } this.s = ""; this.hold_tool_scan = true; if (mdb instanceof MCDebugger) { if (this.sharedData.getAssemblySession().GetDevice().getFamily() == Family.AVR) { ((MCDebugger)mdb).ProgramAVR_ARMFuses(MEMTYPE.CONFIG_MEMORY, Optional.empty(), Optional.empty()); } else { ((MCDebugger)mdb).ProgramAVR_ARMFuses(MEMTYPE.CONFIG_MEMORY, start, end); } } retVal = true; } catch (Exception var6) { this.s = var6.toString(); retVal = false; } this.hold_tool_scan = false; return retVal; } public boolean readAVR_SAMFuses(Optional start, Optional end) { boolean retVal = false; Debugger mdb = this.sharedData.getDebugger(); try { if (mdb == null) { return retVal; } this.s = ""; this.hold_tool_scan = true; if (mdb instanceof MCDebugger) { retVal = ((MCDebugger)mdb).ReadTargetMemoryExplicit(MEMTYPE.CONFIG_MEMORY, start, end); } } catch (Exception var6) { this.s = var6.toString(); retVal = false; } this.hold_tool_scan = false; return retVal; } public Map getToolsMap() { return this.mytoolsmap; } public boolean isCoordinatedResetAndProgramOpRequired() { boolean retVal = false; if (this.session != null && CommonUtils.coordinatedResetAndProgramOpRequired(this.session.GetDevice(), false) == coordinatedResetOperation.eProgramAlwaysInitializeEntryAddressOnReset) { retVal = true; } return retVal; } private void preparePM5InterfaceObject() { if (this.pm5Services == null) { try { Result res = SharedData.getSingletonObject().getAssemblySession().getLookup().lookupResult(MDBDebugTool.class); for (Class cls : res.allClasses()) { if (cls.getName().compareTo(this.sharedData.getAssemblySession().GetToolClass()) == 0) { MDBDebugTool dbgtool = null; dbgtool = (MDBDebugTool)this.sharedData.getAssemblySession().getLookup().lookup(cls); if (dbgtool != null) { try { this.pm5Services = (ServiceQueries)dbgtool; } catch (Exception var6) { MPLABLogger.mplog.log(Level.INFO, var6.getMessage()); } } } } } catch (Exception var7) { MPLABLogger.mplog.log(Level.INFO, var7.toString()); } } } public List listAdapters() throws ServiceQueryException { this.preparePM5InterfaceObject(); List results = new ArrayList<>(); if (this.pm5Services != null) { try { results = this.pm5Services.listUnits(""); } catch (ServiceQueryException var3) { MPLABLogger.mplog.log(Level.INFO, var3.getMessage()); throw new ServiceQueryException(var3.getErrorMessage()); } } return results; } public Map> listEnvironments(List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); Map> results = new HashMap<>(); if (this.pm5Services != null) { try { results = this.pm5Services.listEnvironments(adapters); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } return results; } public Map getActiveEnvironments(List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); Map results = new HashMap<>(); if (this.pm5Services != null) { try { results = this.pm5Services.getActiveEnvironments(adapters); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } return results; } public Map getFirmwareInfo(List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); Map results = new HashMap<>(); if (this.pm5Services != null) { try { results = this.pm5Services.getFirmwareInfo(adapters); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } return results; } public void setActiveEnvironments(List adapters, String environment) throws ServiceQueryException { this.preparePM5InterfaceObject(); if (this.pm5Services != null) { try { this.pm5Services.setActiveEnvironments(adapters, environment); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } } public void deleteEnvironments(String environment, List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); if (this.pm5Services != null) { try { this.pm5Services.deleteEnvironments(environment, adapters); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } } public void transferEnvironment(String environment, List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); if (this.pm5Services != null) { try { this.pm5Services.transferEnvironment(environment, adapters); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } } public List listPM5Units() throws ServiceQueryException { this.preparePM5InterfaceObject(); List results = new ArrayList<>(); if (this.pm5Services != null) { try { results = this.pm5Services.listUnits(""); } catch (ServiceQueryException var3) { MPLABLogger.mplog.log(Level.INFO, var3.getMessage()); throw new ServiceQueryException(var3.getErrorMessage()); } } return results; } public List listPM5MainSubUnits(String serialNum) throws ServiceQueryException { this.preparePM5InterfaceObject(); List results = new ArrayList<>(); if (this.pm5Services != null) { try { results = this.pm5Services.listSubUnits(serialNum); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } return results; } public List listPM5MainEnvironments(String serialNum) throws ServiceQueryException { this.preparePM5InterfaceObject(); List results = new ArrayList<>(); if (this.pm5Services != null) { try { results = this.pm5Services.listEnvironments(serialNum); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } return results; } public Map> listPM5MainSubEnvironments(String serialNum, List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); Map> results = new HashMap<>(); if (this.pm5Services != null) { try { results = this.pm5Services.listSubEnvironments(serialNum, adapters); } catch (ServiceQueryException var5) { MPLABLogger.mplog.log(Level.INFO, var5.getMessage()); throw new ServiceQueryException(var5.getErrorMessage()); } } return results; } public Map getPM5MainSubActiveEnvironments(String serialNum, List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); Map results = new HashMap<>(); if (this.pm5Services != null) { try { results = this.pm5Services.getSubsActiveEnvironments(serialNum, adapters); } catch (ServiceQueryException var5) { MPLABLogger.mplog.log(Level.INFO, var5.getMessage()); throw new ServiceQueryException(var5.getErrorMessage()); } } return results; } public void setPM5MainSubActiveEnvironments(String serialNum, List adapters, String environment) throws ServiceQueryException { this.preparePM5InterfaceObject(); if (this.pm5Services != null) { try { this.pm5Services.setSubsActiveEnvironments(serialNum, adapters, environment); } catch (ServiceQueryException var5) { MPLABLogger.mplog.log(Level.INFO, var5.getMessage()); throw new ServiceQueryException(var5.getErrorMessage()); } } } public void deletePM5MainEnvironments(String environment, String serialNum) throws ServiceQueryException { this.preparePM5InterfaceObject(); if (this.pm5Services != null) { try { this.pm5Services.deleteEnvironment(environment, serialNum); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } } public void deletePM5MainSubEnvironments(String environment, String serialNum, List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); if (this.pm5Services != null) { try { this.pm5Services.deleteSubEnvironments(environment, serialNum, adapters); } catch (ServiceQueryException var5) { MPLABLogger.mplog.log(Level.INFO, var5.getMessage()); throw new ServiceQueryException(var5.getErrorMessage()); } } } public Pm5Versions getPM5MainFirmwareInfo(String serialNum) throws ServiceQueryException { this.preparePM5InterfaceObject(); Pm5Versions pm5Version = null; if (this.pm5Services != null) { try { pm5Version = this.pm5Services.getFirmwareInfo(serialNum); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } return pm5Version; } public Map getPM5MainSubFirmwareInfo(String serialNum, List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); Map pm5Version = new HashMap<>(); if (this.pm5Services != null) { try { pm5Version = this.pm5Services.getSubFirmwareInfo(serialNum, adapters); } catch (ServiceQueryException var5) { MPLABLogger.mplog.log(Level.INFO, var5.getMessage()); throw new ServiceQueryException(var5.getErrorMessage()); } } return pm5Version; } public void transferPM5MainEnvironment(String environment, String serialNum) throws ServiceQueryException { this.preparePM5InterfaceObject(); if (this.pm5Services != null) { try { this.pm5Services.transferEnvironment(environment, serialNum); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } } public void transferEnvironmentToPM5MainSub(String environment, String serialNum, List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); if (this.pm5Services != null) { try { this.pm5Services.transferEnvironmentToSubs(environment, serialNum, adapters); } catch (ServiceQueryException var5) { MPLABLogger.mplog.log(Level.INFO, var5.getMessage()); throw new ServiceQueryException(var5.getErrorMessage()); } } } public Map listPM5MainSubPgmStats(String environment, String serialNum, List adapters) throws ServiceQueryException { this.preparePM5InterfaceObject(); Map results = new HashMap<>(); if (this.pm5Services != null) { try { results = this.pm5Services.listSubPgmStats(environment, serialNum, adapters); } catch (ServiceQueryException var6) { MPLABLogger.mplog.log(Level.INFO, var6.getMessage()); throw new ServiceQueryException(var6.getErrorMessage()); } } return results; } public String getPM5Logs(String serialNum) throws ServiceQueryException { this.preparePM5InterfaceObject(); String results = ""; if (this.pm5Services != null) { try { results = this.pm5Services.getPM5Logs(serialNum); } catch (ServiceQueryException var4) { MPLABLogger.mplog.log(Level.INFO, var4.getMessage()); throw new ServiceQueryException(var4.getErrorMessage()); } } return results; } public boolean isIPAddress(String sNo) { if (sNo != null && !sNo.isEmpty()) { String[] octets = sNo.split("\\."); if (octets.length != 4) { return false; } else { for (String octet : octets) { try { int value = Integer.parseInt(octet); if (value < 0 || value > 255) { return false; } } catch (NumberFormatException var8) { return false; } } return true; } } else { return false; } } public class ToolDetails { String toolID = ""; String toolName = ""; String toolClass = ""; String toolFlavour = ""; String toolSN = ""; List ts = null; public String getToolID() { return this.toolID; } public String getToolName() { return this.toolName; } public String getToolSN() { return this.toolSN; } } }