OpenCores
URL https://opencores.org/ocsvn/mod_mult_exp/mod_mult_exp/trunk

Subversion Repositories mod_mult_exp

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /mod_mult_exp
    from Rev 7 to Rev 8
    Reverse comparison

Rev 7 → Rev 8

/trunk/sw/SerialCommExponentiator/.classpath
0,0 → 1,43
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-12.0.1">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/commons-lang3-3.1.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/jSerialComm-2.5.1.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/swt.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.osgi_3.14.0.v20190517-1309.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.osgi_3.14.0.v20190517-1309.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.commands_3.9.400.v20190516-1358.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.commands_3.9.400.v20190516-1358.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.equinox.common_3.10.400.v20190516-1504.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.equinox.common_3.10.400.v20190516-1504.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.equinox.registry_3.8.400.v20190516-1504.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.equinox.registry_3.8.400.v20190516-1504.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.runtime_3.15.300.v20190508-0543.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.runtime_3.15.300.v20190508-0543.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.text_3.8.200.v20190519-2344.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.text_3.8.200.v20190519-2344.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.swt.win32.win32.x86_64_3.111.0.v20190605-1801.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.swt.win32.win32.x86_64_3.111.0.v20190605-1801.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.jface_3.16.0.v20190528-0922.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.jface_3.16.0.v20190528-0922.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.jface.text_3.15.200.v20190519-2344.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.jface.text_3.15.200.v20190519-2344.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.ui.workbench_3.115.0.v20190521-1602.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.ui.workbench_3.115.0.v20190521-1602.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/com.ibm.icu_64.2.0.v20190507-1337.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/com.ibm.icu_64.2.0.v20190507-1337.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.ui.forms_3.8.0.v20190519-1034.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.ui.forms_3.8.0.v20190519-1034.jar"/>
<classpathentry kind="lib" path="E:/projekty/SerialCommunication/lib/commons-lang3-3.1.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.databinding_1.7.400.v20190513-2118.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.databinding_1.7.400.v20190513-2118.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.databinding.beans_1.5.0.v20190510-1100.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.databinding.beans_1.5.0.v20190510-1100.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.databinding.observable_1.7.0.v20190515-0910.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.databinding.observable_1.7.0.v20190515-0910.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.databinding.property_1.7.0.v20190510-1100.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.core.databinding.property_1.7.0.v20190510-1100.jar"/>
<classpathentry kind="lib" path="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.jface.databinding_1.9.0.v20190519-0933.jar" sourcepath="C:/Users/gajos-user/.p2/pool/plugins/org.eclipse.jface.databinding_1.9.0.v20190519-0933.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/trunk/sw/SerialCommExponentiator/.project
0,0 → 1,17
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SerialCommExponentiator</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
/trunk/sw/SerialCommExponentiator/.settings/org.eclipse.jdt.core.prefs
0,0 → 1,14
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=12
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=12
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=12
trunk/sw/SerialCommExponentiator/.settings Property changes : Added: bugtraq:number ## -0,0 +1 ## +true \ No newline at end of property Index: trunk/sw/SerialCommExponentiator/bin =================================================================== --- trunk/sw/SerialCommExponentiator/bin (nonexistent) +++ trunk/sw/SerialCommExponentiator/bin (revision 8)
trunk/sw/SerialCommExponentiator/bin Property changes : Added: bugtraq:number ## -0,0 +1 ## +true \ No newline at end of property Index: trunk/sw/SerialCommExponentiator/lib/commons-lang3-3.1.jar =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: trunk/sw/SerialCommExponentiator/lib/commons-lang3-3.1.jar =================================================================== --- trunk/sw/SerialCommExponentiator/lib/commons-lang3-3.1.jar (nonexistent) +++ trunk/sw/SerialCommExponentiator/lib/commons-lang3-3.1.jar (revision 8)
trunk/sw/SerialCommExponentiator/lib/commons-lang3-3.1.jar Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: trunk/sw/SerialCommExponentiator/lib/jSerialComm-2.5.1.jar =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: trunk/sw/SerialCommExponentiator/lib/jSerialComm-2.5.1.jar =================================================================== --- trunk/sw/SerialCommExponentiator/lib/jSerialComm-2.5.1.jar (nonexistent) +++ trunk/sw/SerialCommExponentiator/lib/jSerialComm-2.5.1.jar (revision 8)
trunk/sw/SerialCommExponentiator/lib/jSerialComm-2.5.1.jar Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: trunk/sw/SerialCommExponentiator/lib/swt.jar =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: trunk/sw/SerialCommExponentiator/lib/swt.jar =================================================================== --- trunk/sw/SerialCommExponentiator/lib/swt.jar (nonexistent) +++ trunk/sw/SerialCommExponentiator/lib/swt.jar (revision 8)
trunk/sw/SerialCommExponentiator/lib/swt.jar Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: trunk/sw/SerialCommExponentiator/lib =================================================================== --- trunk/sw/SerialCommExponentiator/lib (nonexistent) +++ trunk/sw/SerialCommExponentiator/lib (revision 8)
trunk/sw/SerialCommExponentiator/lib Property changes : Added: bugtraq:number ## -0,0 +1 ## +true \ No newline at end of property Index: trunk/sw/SerialCommExponentiator/src/module-info.java =================================================================== --- trunk/sw/SerialCommExponentiator/src/module-info.java (nonexistent) +++ trunk/sw/SerialCommExponentiator/src/module-info.java (revision 8) @@ -0,0 +1,5 @@ +module serialCommExponentiator { + requires commons.lang3; + requires com.fazecast.jSerialComm; + requires swt; +} \ No newline at end of file Index: trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm/Command.java =================================================================== --- trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm/Command.java (nonexistent) +++ trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm/Command.java (revision 8) @@ -0,0 +1,12 @@ +package webexponentiator.serialcomm; + +public class Command { + public static final int MAX_WORD = 512; + public static final String mn_read_base = "00000000"; + public static final String mn_read_modulus = "00000001"; + public static final String mn_read_exponent = "00000010"; + public static final String mn_read_residuum = "00000011"; + public static final String mn_count_power = "00000100"; + public static final String mn_show_result = "00000101"; + public static final String mn_prepare_for_data = "00000111"; +} Index: trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm/Communication.java =================================================================== --- trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm/Communication.java (nonexistent) +++ trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm/Communication.java (revision 8) @@ -0,0 +1,267 @@ +package webexponentiator.serialcomm; + +import com.fazecast.jSerialComm.SerialPort; +import com.fazecast.jSerialComm.SerialPortDataListener; +import com.fazecast.jSerialComm.SerialPortEvent; + +import java.io.InputStream; +import java.io.OutputStream; +import java.math.BigInteger; +import java.util.HashMap; + +import org.apache.commons.lang3.ArrayUtils; +import org.eclipse.swt.graphics.Color; + +public class Communication implements SerialPortDataListener { + + //passed from main GUI + Window window = null; + String selectedPort = "COM3"; + // just a boolean flag that i use for enabling + // and disabling buttons depending on whether the program + // is connected to a serial port or not + private boolean bConnected = false; + + // the timeout value for connecting with the port + final static int TIMEOUT = 2000; + + // for containing the ports that will be found + private SerialPort[] ports = null; + // map the port names to CommPortIdentifiers + private HashMap portMap = new HashMap(); + + // this is the object that contains the opened port + private SerialPort serialPort = null; + + // input and output streams for sending and receiving data + private InputStream input = null; + private OutputStream output = null; + + public Communication(Window window) { + this.window = window; + } + + // a string for recording what goes on in the program + // this string is written to the GUI + String logText = ""; + + // search for all the serial ports + // pre style="font-size: 11px;": none + // post: adds all the found ports to a combo box on the GUI + public void searchForPorts() { + + ports = SerialPort.getCommPorts(); + + for (SerialPort port:ports) { + String portName = port.getDescriptivePortName(); + if (portName.contains("COM3")) { + selectedPort = portName; + } + // get only serial ports + window.combo.add(portName); + portMap.put(portName, port); + } + } + + // connect to the selected port in the combo box + // pre style="font-size: 11px;": ports are already found by using the + // searchForPorts + // method + // post: the connected comm port is stored in commPort, otherwise, + // an exception is generated + public void connect() { + if (window.combo.getSelectionIndex() >= 0) { + selectedPort = (String) window.combo.getItem(window.combo.getSelectionIndex()); + serialPort = (SerialPort) portMap.get(selectedPort); + serialPort.setBaudRate(115200); + serialPort.setNumDataBits(8); + serialPort.setNumStopBits(1); + serialPort.setParity(SerialPort.ODD_PARITY); + + // the method below returns an object of type CommPort + setConnected(serialPort.openPort()); + if (getConnected()) { + // logging + logText = selectedPort + " opened successfully."; + window.text.setForeground(new Color(window.shlPcExponentiator.getDisplay(), 0, 0, 0)); + window.appendText(logText + "\n"); + window.toggleControls(); + } else { + logText = selectedPort + " was not opened"; + window.text.setForeground(new Color(window.shlPcExponentiator.getDisplay(), 255, 0, 0)); + window.appendText(logText + "\n"); + } + } + } + // open the input and output streams + // pre style="font-size: 11px;": an open port + // post: initialized input and output streams for use to communicate data + public boolean initIOStream() { + // return value for whether opening the streams is successful or not + boolean successful = false; + + input = serialPort.getInputStream(); + output = serialPort.getOutputStream(); + + successful = true; + return successful; + } + + // starts the event listener that knows whenever data is available to be + // read + // pre style="font-size: 11px;": an open serial port + // post: an event listener for the serial port that knows when data is + // received + public void initListener() { + serialPort.addDataListener(this); + } + + //disconnect the serial port + //pre style="font-size: 11px;": an open serial port + //post: closed serial port + public void disconnect() + { + //close the serial port + try { + serialPort.removeDataListener(); + input.close(); + output.close(); + serialPort.closePort(); + setConnected(false); + window.toggleControls(); + + logText = "Disconnected."; + window.text.setForeground(new Color(window.shlPcExponentiator.getDisplay(), 255, 0, 0)); + window.appendText(logText + "\n"); + + logText = "Disconnected."; + } catch (Exception e) { + logText = "Failed to close " + serialPort.getDescriptivePortName() + + "(" + e.toString() + ")"; + window.text.setForeground(new Color(window.shlPcExponentiator.getDisplay(), 255, 0, 0)); + window.appendText(logText + "\n"); + } + } + + + @Override + public int getListeningEvents() { + return SerialPort.LISTENING_EVENT_DATA_AVAILABLE; + } + + //what happens when data is received + //pre style="font-size: 11px;": serial event is triggered + //post: processing on the data it reads + @Override + public void serialEvent(SerialPortEvent evt) { + if (evt.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE) { + try { + byte[] buffer = new byte[10]; + int n = input.read(buffer); + if (n > 0) { + if (n == 1) { + BigInteger command = new BigInteger(new byte[] { 0, + buffer[0] }); + final String s = "Command = " + command.toString(16) + + "\n"; + //TODO Something for retrieve data + //window.appendText(s); + } else { + ArrayUtils.reverse(buffer); + BigInteger data = new BigInteger(buffer); +// buffer = ArrayUtils.subarray(buffer, 0, buffer.length - 2); +// buffer = ArrayUtils.add(buffer, (byte)0); +// ArrayUtils.reverse(buffer); +// BigInteger data = new BigInteger(buffer); +// window.appendText(data.toString(10) + "\n"); + } + window.appendText("\n"); + } + } catch (Exception e) { + logText = "Failed to read data. (" + e.toString() + ")"; + window.text.setForeground(new Color(window.shlPcExponentiator.getDisplay(), 255, 0, 0)); + window.appendText(logText + "\n"); + } + } + } + + public String readData() { + try { + byte[] buffer = new byte[65]; + int n = input.read(buffer); + if (n > 0) { + if (n == 1) { + BigInteger command = new BigInteger(new byte[] { 0, + buffer[0] }); + String s = "Command = " + command.toString(16); + return s; + } else { + buffer = ArrayUtils.subarray(buffer, 0, buffer.length - 1); + buffer = ArrayUtils.add(buffer, (byte)0); + ArrayUtils.reverse(buffer); + BigInteger data = new BigInteger(buffer); + return data.toString(16); + } + } + } catch (Exception e) { + window.appendText("Failed to read data. (" + e.toString() + ")"); + } + return null; + } + + //method that can be called to send data + //pre style="font-size: 11px;": open serial port + //post: data sent to the other device + public void writeData(String str) + { + try + { + BigInteger bi = new BigInteger(str, 2); + byte [] b = bi.toByteArray(); + if (b.length == 2) { + output.write(b[1]); + } else { + output.write(b); + } + Thread.sleep(50); + //ArrayUtils.reverse(b); + /*String [] data = str.split(" "); + byte [] b = new byte [data.length]; + for (int i = 0; i < data.length; i++) { + Byte toSend = Byte.decode(data[i]); + b[i] = toSend; + + } + ArrayUtils.reverse(b); + for (int i = 0; i < b.length; i++) { + output.write(b[i]); + Thread.sleep(1); + }*/ + //b = Arrays.copyOfRange(b, 1, b.length); + //ArrayUtils.reverse(b); + //for (int i = 0; i < b.length; i++) { + // output.write(b[i]); + // Thread.sleep(10); + //} + //output.flush(); + } + catch (Exception e) + { + logText = "Failed to write data. (" + e.toString() + ")"; + window.text.setForeground(new Color(window.shlPcExponentiator.getDisplay(), 255, 0, 0)); + window.appendText(logText + "\n"); + } + } + + final public boolean getConnected() + { + return bConnected; + } + + public void setConnected(boolean bConnected) + { + this.bConnected = bConnected; + } + + +} Index: trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm/Window.java =================================================================== --- trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm/Window.java (nonexistent) +++ trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm/Window.java (revision 8) @@ -0,0 +1,432 @@ +package webexponentiator.serialcomm; + +import java.math.BigInteger; +import java.util.Date; +import java.util.Random; + +import org.apache.commons.lang3.ArrayUtils; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import webexponentiator.serialcomm.Command; + +import org.eclipse.swt.custom.CLabel; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.graphics.Point; + +public class Window { + + //Communicator object + Communication communication = null; + public Display display; + protected Shell shlPcExponentiator; + public Text text; + private Text text_2; + public Combo combo; + private Button btnConnect; + private Button btnDisconnect; + private Button btnSendAutomated; + private Button btnSendResult; + private Button btnSendPrepare; + private Button btnBase; + private Button btnModulus; + private Button btnExponent; + private Button btnResiduum; + private Button btnPowerMod; + + public void toggleControls() + { + if (communication.getConnected() == true) + { + btnDisconnect.setEnabled(true); + btnConnect.setEnabled(false); + btnSendAutomated.setEnabled(true); + btnSendResult.setEnabled(true); + btnSendPrepare.setEnabled(true); + btnBase.setEnabled(true); + btnModulus.setEnabled(true); + btnExponent.setEnabled(true); + btnResiduum.setEnabled(true); + btnPowerMod.setEnabled(true); + } + else + { + btnDisconnect.setEnabled(false); + btnConnect.setEnabled(true); + btnSendAutomated.setEnabled(false); + btnSendResult.setEnabled(false); + btnSendPrepare.setEnabled(false); + btnBase.setEnabled(false); + btnModulus.setEnabled(false); + btnExponent.setEnabled(false); + btnResiduum.setEnabled(false); + btnPowerMod.setEnabled(false); + } + } + + /** + * Launch the application. + * + * @param args + */ + public static void main(String[] args) { + try { + Window window = new Window(); + window.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Open the window. + */ + public void open() { + display = Display.getDefault(); + createContents(); + communication = new Communication(this); + communication.searchForPorts(); + toggleControls(); + shlPcExponentiator.open(); + shlPcExponentiator.layout(); + while (!shlPcExponentiator.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + + /** + * Create contents of the window. + */ + protected void createContents() { + shlPcExponentiator = new Shell(SWT.CLOSE | SWT.MIN | SWT.TITLE); + shlPcExponentiator.setSize(new Point(483, 369)); + shlPcExponentiator.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent arg0) { + if (communication.getConnected()) { + communication.disconnect(); + } + } + }); + shlPcExponentiator.setSize(493, 399); + shlPcExponentiator.setText("PC Exponentiator"); + shlPcExponentiator.setLayout(null); + + Composite composite = new Composite(shlPcExponentiator, SWT.NONE); + composite.setBounds(0, 0, 483, 369); + + text = new Text(composite, SWT.BORDER | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI); + this.text.setBounds(10, 171, 463, 188); + + combo = new Combo(composite, SWT.NONE); + combo.setBounds(10, 10, 124, 23); + + btnConnect = new Button(composite, SWT.NONE); + btnConnect.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + communication.connect(); + if (communication.getConnected() == true) + { + if (communication.initIOStream() == true) + { + communication.initListener(); + } + } + } + }); + btnConnect.setBounds(140, 10, 75, 25); + btnConnect.setText("Connect"); + + btnDisconnect = new Button(composite, SWT.NONE); + btnDisconnect.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + communication.disconnect(); + } + }); + btnDisconnect.setBounds(221, 10, 75, 25); + btnDisconnect.setText("Disconnect"); + + Label lblLog = new Label(composite, SWT.NONE); + lblLog.setBounds(10, 150, 55, 15); + lblLog.setText("Log"); + + btnSendAutomated = new Button(composite, SWT.NONE); + btnSendAutomated.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + Random r = new Random(new Date().getTime()); + BigInteger modulus = BigInteger.probablePrime(512, r); + BigInteger base = new BigInteger(512, r).mod(modulus); + BigInteger exponent = new BigInteger(512, r).mod(modulus); + BigInteger residuum = new BigInteger("2").modPow(new BigInteger("1024"), modulus); + BigInteger expectedResult = base.modPow(exponent, modulus); + /* + * result.add(sendBase( + * "10831972010009692284864743082963908985928244572237504978567815597954452424901701848115907348099319027887255346705501542390228546770547307022309796259930536" + * )); result.add(sendModulus( + * "11639194216848075599002265489360912001411488135138961225285267565441921553320210324625995654671521634712013831000392536053201786146999373798311679376312847" + * )); result.add(sendExponent( + * "1164213079911476522452523716613118512153792329806743382289257300977572318091588414675225325908322428116294194315992613761814533537627230020523566408522775" + * )); result.add(sendResiduum( + * "1710026381007983649390259627245755642172838934666512596966326197048317423109472713444486555154343967450576033188072022772979735585191761951832684734601532" + * )); + */ + appendText("Send " + sendBase(base.toString(10)) + "\n"); + appendText("Send " + sendModulus(modulus.toString(10)) + "\n"); + appendText("Send " + sendExponent(exponent.toString(10)) + "\n"); + appendText("Send " + sendResiduum(residuum.toString(10)) + "\n"); + appendText(sendPower() + "\n"); + String result = sendResult(); + if (null != result) { + appendText("Result = \n" + result + "\n"); + } else { + appendText("Result is NULL!!! \n"); + } + appendText("Send prepare\n" + sendPrepare() + "\n"); + appendText("Expected result " + expectedResult.toString(16) + "\n"); + if (expectedResult.toString(16).compareTo(result) == 0) { + appendText("Expected result = calculated result"); + } else { + appendText("Calculated result ERROR!\nExpected result is \n" + expectedResult + "\nCalculated result is\n" + result + "\n"); + } + + +// for (int i = 0; i < dataProtocol.length; i++) { +// String [] el = dataProtocol[i].split(" "); +// ArrayUtils.reverse(el); +// for (int j = 0; j < el.length; j++) { +// communication.writeData(el[j]); +// } +// } + } + }); + btnSendAutomated.setBounds(256, 119, 91, 25); + btnSendAutomated.setText("Send automated"); + + text_2 = new Text(composite, SWT.BORDER); + text_2.setBounds(10, 60, 463, 21); + + btnSendResult = new Button(composite, SWT.NONE); + btnSendResult.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + String result = sendResult(); + if (null != result) { + appendText("Result = " + result + "\n"); + } else { + appendText("Result is NULL!!! \n"); + } + } + }); + btnSendResult.setBounds(91, 119, 75, 25); + btnSendResult.setText("Send result"); + + btnSendPrepare = new Button(composite, SWT.NONE); + btnSendPrepare.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + appendText("Send prepare:\n" + sendPrepare() + "\n"); + } + }); + btnSendPrepare.setBounds(172, 119, 75, 25); + btnSendPrepare.setText("Send prepare"); + + btnBase = new Button(composite, SWT.NONE); + btnBase.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + String text = text_2.getText(); + try { + BigInteger bi = new BigInteger(text, 10); + appendText("Send base:\n" + sendBase(text) + "\n"); + } catch (NumberFormatException e) { + appendText("Wrong number format to send base \n"); + } + } + }); + btnBase.setBounds(10, 85, 75, 25); + btnBase.setText("Base"); + + btnModulus = new Button(composite, SWT.NONE); + btnModulus.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + String text = text_2.getText(); + try { + BigInteger bi = new BigInteger(text, 10); + appendText("Send modulus:\n" + sendModulus(text) + "\n"); + } catch (NumberFormatException e) { + appendText("Wrong number format to send modulus"); + } + } + }); + btnModulus.setBounds(91, 85, 75, 25); + btnModulus.setText("Modulus"); + + btnExponent = new Button(composite, SWT.NONE); + btnExponent.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + String text = text_2.getText(); + try { + BigInteger bi = new BigInteger(text, 10); + appendText("Send exponent:\n" + sendExponent(text) + "\n"); + } catch (NumberFormatException e) { + appendText("Wrong number format to send exponent"); + } + } + }); + btnExponent.setBounds(172, 85, 75, 25); + btnExponent.setText("Exponent"); + + btnResiduum = new Button(composite, SWT.NONE); + btnResiduum.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + String text = text_2.getText(); + try { + BigInteger bi = new BigInteger(text, 10); + appendText("Send residuum:\n" + sendResiduum(text) + "\n"); + } catch (NumberFormatException e) { + appendText("Wrong number format to send residuum"); + } + } + }); + btnResiduum.setBounds(256, 85, 75, 25); + btnResiduum.setText("Residuum"); + + btnPowerMod = new Button(composite, SWT.NONE); + btnPowerMod.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent arg0) { + appendText("Send power:\n" + sendPower() + "\n"); + } + }); + btnPowerMod.setBounds(10, 119, 75, 25); + btnPowerMod.setText("Power Mod"); + + CLabel lblWriteHexadecimalValue = new CLabel(composite, SWT.NONE); + lblWriteHexadecimalValue.setBottomMargin(1); + lblWriteHexadecimalValue.setTopMargin(1); + lblWriteHexadecimalValue.setBounds(10, 39, 172, 21); + lblWriteHexadecimalValue.setText("Write DECIMAL value:"); + } + + private String sendPrepare() { + sendData(new String[] { Command.mn_prepare_for_data }); + waitMicron("prepare"); + return "prepare"; + } + + private String sendResult() { + sendData(new String[] { Command.mn_show_result}); + waitMicron("show result"); + return communication.readData(); + } + + private String sendPower() { + sendData(new String[] { Command.mn_count_power }); + waitMicron("count power"); + return "count power \n" + communication.readData(); + } + + private String sendResiduum(String string) { + String residuum = parseDataToSend(string, 10); + String[] send = { Command.mn_read_residuum, residuum }; + sendData(send); + waitMicron("residuum"); + return "residuum - " + string + "\n" + communication.readData(); + } + + private String sendExponent(String string) { + String exponent = parseDataToSend(string, 10); + String[] send = { Command.mn_read_exponent, exponent }; + sendData(send); + waitMicron("exponent"); + return "exponent - " + string + "\n" + communication.readData(); + } + + private String sendModulus(String string) { + String modulus = parseDataToSend(string, 10); + String[] send = { Command.mn_read_modulus, modulus }; + sendData(send); + waitMicron("modulus"); + return "modulus - " + string + "\n" + communication.readData(); + } + + private String sendBase(String data) { + String base = parseDataToSend(data, 10); + String[] send = { Command.mn_read_base, base }; + sendData(send); + waitMicron("base"); + return "base - " + data + "\n" + communication.readData(); + } + + + private String parseDataToSend(String string, int radix) { + BigInteger strBi = new BigInteger(string, radix); + String result = new String(""); + for (int i = Command.MAX_WORD - 1; i >= strBi.bitLength(); i--) { + result = result.concat("0"); + + if (i % 8 == 0) { + result = result.concat(" "); + } + } + + for (int i = strBi.bitLength() - 1; i >= 0; i--) { + if (strBi.testBit(i)) { + result = result.concat("1"); + } else { + result = result.concat("0"); + } + + if (i % 8 == 0) { + result = result.concat(" "); + } + } + + return result; + } + + private void waitMicron(String string) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + appendText("Wait for data happen -" + string); + e.printStackTrace(); + } + + } + + private void sendData(String [] data) { + for (int i = 0; i < data.length; i++) { + String [] el = data[i].split(" "); + ArrayUtils.reverse(el); + for (int j = 0; j < el.length; j++) { + communication.writeData(el[j]); + } + } + } + + public void appendText(final String s) { + display.syncExec(new Runnable() { + public void run() { + text.append(s); + } + }); + + } +} Index: trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm =================================================================== --- trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm (nonexistent) +++ trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm (revision 8)
trunk/sw/SerialCommExponentiator/src/webexponentiator/serialcomm Property changes : Added: bugtraq:number ## -0,0 +1 ## +true \ No newline at end of property Index: trunk/sw/SerialCommExponentiator/src/webexponentiator =================================================================== --- trunk/sw/SerialCommExponentiator/src/webexponentiator (nonexistent) +++ trunk/sw/SerialCommExponentiator/src/webexponentiator (revision 8)
trunk/sw/SerialCommExponentiator/src/webexponentiator Property changes : Added: bugtraq:number ## -0,0 +1 ## +true \ No newline at end of property Index: trunk/sw/SerialCommExponentiator/src =================================================================== --- trunk/sw/SerialCommExponentiator/src (nonexistent) +++ trunk/sw/SerialCommExponentiator/src (revision 8)
trunk/sw/SerialCommExponentiator/src Property changes : Added: bugtraq:number ## -0,0 +1 ## +true \ No newline at end of property Index: trunk/sw/SerialCommExponentiator =================================================================== --- trunk/sw/SerialCommExponentiator (nonexistent) +++ trunk/sw/SerialCommExponentiator (revision 8)
trunk/sw/SerialCommExponentiator Property changes : Added: bugtraq:number ## -0,0 +1 ## +true \ No newline at end of property

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.