Something went wrong. Try again.
Completely reimplimented in zig (eventually)
Something went wrong. Try again.
Java
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551package com.microchip.mplab.ipelib.common;
import com.microchip.crownking.Pair;import com.microchip.crownking.edc.PIC;import com.microchip.crownking.mplabinfo.FamilyDefinitions.Family;import com.microchip.mplab.crownkingx.xPIC;import com.microchip.mplab.ipelib.IPELibrary;import com.microchip.mplab.mdbcore.RI4Tool.families.FamilyCreator;import com.microchip.mplab.mdbcore.RI4Tool.families.RI4Family;import com.microchip.mplab.mdbcore.RI4Tool.families.RI4FamilyInterface;import com.microchip.mplab.mdbcore.RealICETool.utils.RIExceptions;import com.microchip.mplab.mdbcore.assemblies.Assembly;import com.microchip.mplab.mdbcore.assemblies.AssemblyFactory;import com.microchip.mplab.mdbcore.debugger.Debugger;import com.microchip.mplab.mdbcore.debugger.SDCardInterface;import com.microchip.mplab.mdbcore.sqtpenv.SQTPEnvironment;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URI;import java.net.URISyntaxException;import java.net.URL;import java.util.Properties;import java.util.prefs.Preferences;import org.openide.util.Exceptions;import org.openide.util.NbBundle;import org.w3c.dom.Document;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;
public class SharedData { private Debugger mdb = null; private Assembly mdbSession = null; private AssemblyFactory assemblyFactory = null; private SDCardInterface sdCardInterface = null; private SQTPEnvironment SQTPEnv = null; private boolean debugBit_Set = false; private boolean tool_connected = false; public boolean makePK2Work = false; private Preferences userPreferences = null; private Properties coreProperties = null; private byte[] pgmMemBytes = new byte[0]; private byte[] userIDMemBytes = new byte[0]; private byte[] bootMemBytes = new byte[0]; private byte[] testMemBytes = new byte[0]; private byte[] auxMemBytes = new byte[0]; private byte[] eeMemBytes = new byte[0]; private byte[] flashData = new byte[0]; private boolean requiresUI = false; private boolean userResponded = false; private int userResponse = 0; private Pair<Long, Long> EDataRange = null; private boolean isInvalidHexFile = false; private boolean isOTPSetForCECDevice = false; private static String bundle; private static final String OS_NAME = System.getProperty("os.name", "unknown"); private static final String OS_VERSION = System.getProperty("os.version", "unknown"); private static final String OS_ARCH = System.getProperty("os.arch", "unknown"); private static final String SERVER = "mplab-metrics.s3-website-us-west-2.amazonaws.com"; private static final String PRODUCT = "/ipe/"; private static SharedData ref;
public void setOTPForCECDevice(boolean flag) { this.isOTPSetForCECDevice = flag; }
public boolean getOTPForCECDevice() { return this.isOTPSetForCECDevice; }
public void setInvalidHexFlag(boolean flag) { this.isInvalidHexFile = flag; }
public boolean getInvalidHexFlag() { return this.isInvalidHexFile; }
public void setDebugBitFlag(boolean flag) { this.debugBit_Set = flag; }
public boolean getDebugBitFlag() { return this.debugBit_Set; }
public void setUIMode(boolean flag) { this.requiresUI = flag; }
public boolean getUIMode() { return this.requiresUI; }
public void setUserResponseFlag(boolean flag) { this.userResponded = flag; }
public boolean getUserResponseFlag() { return this.userResponded; }
public void setUserResponseCode(int code) { this.userResponse = code; }
public int getUserResponseCode() { return this.userResponse; }
public void setSQTPEnvironment(SQTPEnvironment se) { this.SQTPEnv = se; }
public SQTPEnvironment getSQTPEnvironment() { return this.SQTPEnv; }
public void setassemblyFactory(AssemblyFactory af) { this.assemblyFactory = af; }
public AssemblyFactory getassemblyFactory() { return this.assemblyFactory; }
public void setAssembly(Assembly Session) { this.mdbSession = Session; }
public Assembly getAssemblySession() { return this.mdbSession; }
public boolean isAssemblySessionActive() { boolean retVal = false; if (this.mdbSession != null) { retVal = true; }
return retVal; }
public Debugger getDebugger() { return this.mdb; }
public void setDebugger(Debugger dbg) { this.mdb = dbg; if (this.mdb != null) { this.tool_connected = this.mdb.IsConnected(); } }
public boolean setUserCoreProperties(Properties properties) { boolean retVal = false; if (this.mdbSession != null && this.assemblyFactory != null) { this.assemblyFactory.SetToolProperties(this.mdbSession, properties); retVal = true; } else { retVal = false; }
return retVal; }
public xPIC getDeviceName() { return this.mdbSession != null ? this.mdbSession.GetDevice() : null; }
public long getMSBLSB32(byte msb1, byte msb2, byte lsb1, byte lsb2) { long result = 0L; long tempMSB1 = 0L; long tempLSB1 = 0L; long tempMSB2 = 0L; long tempLSB2 = 0L; String s = null; s = String.format("%x", msb1); tempMSB1 = Integer.valueOf(s, 16).longValue(); tempMSB1 *= 16777216L; s = String.format("%x", msb2); tempMSB2 = Integer.valueOf(s, 16).longValue(); tempMSB2 *= 65536L; s = String.format("%x", lsb1); tempLSB1 = Integer.valueOf(s, 16).longValue(); tempLSB1 *= 256L; s = String.format("%x", lsb2); tempLSB2 = Integer.valueOf(s, 16).longValue(); return tempMSB1 + tempMSB2 + tempLSB1 + tempLSB2; }
public String getMSBLSB(byte msb, byte lsb) { int result = 0; int tempMSB = 0; int tempLSB = 0; String s = null; s = String.format("%02X", msb); tempMSB = Integer.valueOf(s, 16); tempMSB *= 256; return s.concat(String.format("%02X", lsb)); }
public int getMSBLSB_Integer(byte msb, byte lsb) { int result = 0; int tempMSB = 0; int tempLSB = 0; String s = null; s = String.format("%x", msb); tempMSB = Integer.valueOf(s, 16); tempMSB *= 256; s = String.format("%x", lsb); tempLSB = Integer.valueOf(s, 16); return tempMSB + tempLSB; }
public int getByteasInt(byte bite) { int result = 0; String s = null; s = String.format("%x", bite); return Integer.valueOf(s, 16); }
public boolean setPgmMemBytes(long memSize) { if (memSize != -1L) { this.pgmMemBytes = new byte[(int)memSize]; return true; } else { return false; } }
public boolean setPgmMemBytes(byte[] buffer) { System.arraycopy(buffer, 0, this.pgmMemBytes, 0, buffer.length); return true; }
public byte[] getPgmMemBytes() { return this.pgmMemBytes; }
public boolean setEEMemBytes(long eeMemSize) { if (eeMemSize != -1L) { this.eeMemBytes = new byte[(int)eeMemSize]; return true; } else { return false; } }
public boolean setEEMemBytes(byte[] buffer) { System.arraycopy(buffer, 0, this.eeMemBytes, 0, buffer.length); return true; }
public long hexToDecimal(String hexString) { long retVal = -1L;
try { if (!hexString.startsWith("0x") && !hexString.startsWith("0X")) { retVal = Long.valueOf(hexString, 16); } else { retVal = Long.decode(hexString); } } catch (Exception var5) { retVal = -1L; }
return retVal; }
public void setMemRange(Pair<Long, Long> eEDataRange) { this.EDataRange = eEDataRange; }
public void setSDCard(SDCardInterface sdInt) { this.sdCardInterface = sdInt; }
public SDCardInterface getSDCardInterface() { return this.mdbSession == null ? null : (SDCardInterface)this.mdbSession.getLookup().lookup(SDCardInterface.class); }
public boolean setUserIDMemBytes(long memSize) { if (memSize != -1L) { this.userIDMemBytes = new byte[(int)memSize]; return true; } else { return false; } }
public String getUserID(byte msb1, byte msb2, byte lsb1, byte lsb2) { String s = null; String specifier = ""; if (this.getAssemblySession().GetDevice().getFamily() == Family.Baseline) { specifier = "%X"; } else { specifier = "%02X"; }
s = String.format(specifier, msb1); s = s.concat(String.format(specifier, msb2)); s = s.concat(String.format(specifier, lsb1)); return s.concat(String.format(specifier, lsb2)); }
public boolean setFlashBytes(int siz) { if (siz != -1) { this.flashData = new byte[siz]; return true; } else { return false; } }
public boolean setFlashBytes(byte[] buffer) { System.arraycopy(buffer, 0, this.flashData, 0, buffer.length); return true; }
public boolean setBootFlashBytes(byte[] buffer) { System.arraycopy(buffer, 0, this.bootMemBytes, 0, buffer.length); return true; }
public boolean setBootFlashBytes(long memSize) { if (memSize != -1L) { this.bootMemBytes = new byte[(int)memSize]; return true; } else { return false; } }
public boolean setAuxMemBytes(long memSz) { if (memSz != -1L) { this.auxMemBytes = new byte[(int)memSz * 2]; return true; } else { return false; } }
public boolean setAuxMemBytes(byte[] buffer) { System.arraycopy(buffer, 0, this.auxMemBytes, 0, buffer.length); return true; }
public String getUserID(byte byt) { String s = null; String specifier = ""; if (this.getAssemblySession().GetDevice().getFamily() == Family.Baseline) { specifier = "%X"; } else { specifier = "%02X"; }
return String.format(specifier, byt); }
public String getNodeAttributeText(String FullNodePath, String Item, PIC pic) { String RetStr = null; Document doc = pic.getDoc(); Node node = pic.walk(doc, FullNodePath); if (node != null) { NamedNodeMap NNM = node.getAttributes(); if (NNM != null) { node = NNM.getNamedItem(Item); if (node != null) { RetStr = node.getNodeValue(); } } }
return RetStr; }
public boolean isConnected() { return this.mdb == null ? false : this.mdb.IsConnected(); }
public String[] getDevice_Tool() { return new String[]{this.mdbSession.GetDeviceName(), this.mdbSession.GetToolName()}; }
public void setUserParameters(Preferences usrProperties) { this.userPreferences = usrProperties; }
public Preferences getUserParameters() { return this.userPreferences; }
public String getUserParameters(String Parameter) { return this.userPreferences.get(Parameter, ""); }
public void setCoreParameters(Properties coreP) { this.coreProperties = coreP; }
public Properties getCoreParameters() { return this.coreProperties; }
public void setIPEMetricsToServer(String IPEVersion, String toolInfo, String devInfo) { try { String USER_AGENT = "MPLABXIPE/" + IPEVersion; StringBuilder sb = new StringBuilder(); boolean hasUserPermission = false; URL url = null; String urlString = null; String queryString = ""; String modulePermission = System.getProperty("statistics.connect", "true"); if (!modulePermission.equalsIgnoreCase("false")) { hasUserPermission = true; }
if (hasUserPermission) { if ("".equals(devInfo)) { devInfo = "NA"; }
if ("".equals(toolInfo)) { toolInfo = "NA"; }
sb.append("").append("tool=").append(toolInfo); sb.append("&").append("device=").append(devInfo); sb.append("&").append("os=").append(this.getOsInfo()); sb.append("&").append("ver=").append(OS_VERSION); sb.append("&").append("os_arch=").append(OS_ARCH); queryString = sb.toString(); URI uri; if (queryString != null && !queryString.isEmpty()) { uri = new URI("http", "mplab-metrics.s3-website-us-west-2.amazonaws.com", "/ipe/", queryString, null); } else { uri = new URI("http", "mplab-metrics.s3-website-us-west-2.amazonaws.com", "/ipe/", null, null); }
urlString = uri.toASCIIString(); url = new URL(urlString); HttpURLConnection con = (HttpURLConnection)url.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", USER_AGENT); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); StringBuilder response = new StringBuilder();
String inputLine; while ((inputLine = in.readLine()) != null) { response.append(inputLine); }
in.close(); System.out.println("\n" + response.toString()); } } catch (MalformedURLException var17) { } catch (IOException var18) { } catch (URISyntaxException var19) { } catch (Exception var20) { } }
public RI4FamilyInterface getRI4FamilyInstance() { RI4FamilyInterface ri4Family = null; FamilyCreator FC = new FamilyCreator(getSingletonObject().getAssemblySession().GetDevice());
try { ri4Family = FC.GetFamily(); } catch (RIExceptions var4) { Exceptions.printStackTrace(var4); }
if (ri4Family == null) { ri4Family = new RI4Family(); }
return ri4Family; }
public String getOsInfo() { String os; if (OS_NAME.startsWith("Windows")) { os = OS_NAME.replace(" ", "_"); } else { os = OS_NAME.replace(" ", "") + "_" + OS_VERSION; }
return os; }
private static String getString(String s) { if (bundle == null) { bundle = NbBundle.getMessage(IPELibrary.class, "ReadConfigMemoryActionName"); }
return bundle; }
SharedData() { }
public static SharedData getSingletonObject() { if (ref == null) { ref = new SharedData(); }
return ref; }
@Override public Object clone() throws CloneNotSupportedException { throw new CloneNotSupportedException(); }
public static enum PredefinedType implements SharedData.Type { READ_CONFIG_MEMORY("ReadConfigMemory"), UPLOAD_IMAGE("UploadImage"), READ_EXECUTION_MEMORY("ReadExecutionMemory");
private final String localizedName;
private PredefinedType(String resourceNamePrefix) { this.localizedName = SharedData.getString(resourceNamePrefix + "ActionName"); }
@Override public String getLocalizedName() { return this.localizedName; }
@Override public void setLocalizedName(String name) { throw new UnsupportedOperationException(); } }
public interface Type { int ordinal();
String name();
String getLocalizedName();
void setLocalizedName(String var1); }}