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 6 to Rev 7
- ↔ Reverse comparison
Rev 6 → Rev 7
/trunk/sw/WebExponentiator/.classpath
0,0 → 1,24
<?xml version="1.0" encoding="UTF-8"?> |
<classpath> |
<classpathentry kind="src" path="src/main/java"/> |
<classpathentry excluding="messages/" kind="src" path="src/main/resources"/> |
<classpathentry kind="src" path="src/main/resources/messages"/> |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12"> |
<attributes> |
<attribute name="module" value="true"/> |
<attribute name="maven.pomderived" value="true"/> |
</attributes> |
</classpathentry> |
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0"> |
<attributes> |
<attribute name="owner.project.facets" value="jst.web"/> |
</attributes> |
</classpathentry> |
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> |
<attributes> |
<attribute name="maven.pomderived" value="true"/> |
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> |
</attributes> |
</classpathentry> |
<classpathentry kind="output" path="target/classes"/> |
</classpath> |
/trunk/sw/WebExponentiator/.project
0,0 → 1,37
<?xml version="1.0" encoding="UTF-8"?> |
<projectDescription> |
<name>WebExponentiator</name> |
<comment></comment> |
<projects> |
</projects> |
<buildSpec> |
<buildCommand> |
<name>org.eclipse.jdt.core.javabuilder</name> |
<arguments> |
</arguments> |
</buildCommand> |
<buildCommand> |
<name>org.eclipse.wst.common.project.facet.core.builder</name> |
<arguments> |
</arguments> |
</buildCommand> |
<buildCommand> |
<name>org.eclipse.wst.validation.validationbuilder</name> |
<arguments> |
</arguments> |
</buildCommand> |
<buildCommand> |
<name>org.eclipse.m2e.core.maven2Builder</name> |
<arguments> |
</arguments> |
</buildCommand> |
</buildSpec> |
<natures> |
<nature>org.eclipse.m2e.core.maven2Nature</nature> |
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature> |
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> |
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> |
<nature>org.eclipse.jdt.core.javanature</nature> |
<nature>org.eclipse.wst.jsdt.core.jsNature</nature> |
</natures> |
</projectDescription> |
/trunk/sw/WebExponentiator/.settings/.jsdtscope
0,0 → 1,12
<?xml version="1.0" encoding="UTF-8"?> |
<classpath> |
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="WebContent"/> |
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/> |
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject"> |
<attributes> |
<attribute name="hide" value="true"/> |
</attributes> |
</classpathentry> |
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/> |
<classpathentry kind="output" path=""/> |
</classpath> |
/trunk/sw/WebExponentiator/.settings/org.eclipse.jdt.core.prefs
0,0 → 1,11
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.compliance=12 |
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.forbiddenReference=warning |
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning |
org.eclipse.jdt.core.compiler.release=enabled |
org.eclipse.jdt.core.compiler.source=12 |
/trunk/sw/WebExponentiator/.settings/org.eclipse.m2e.core.prefs
0,0 → 1,4
activeProfiles= |
eclipse.preferences.version=1 |
resolveWorkspaceProjects=true |
version=1 |
/trunk/sw/WebExponentiator/.settings/org.eclipse.wst.common.component
0,0 → 1,11
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> |
<wb-module deploy-name="WebExponentiator-0.0.1-SNAPSHOT"> |
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> |
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/> |
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> |
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> |
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources/messages"/> |
<property name="context-root" value="WebExponentiator"/> |
<property name="java-output-path" value="/WebExponentiator/build/classes"/> |
</wb-module> |
</project-modules> |
/trunk/sw/WebExponentiator/.settings/org.eclipse.wst.common.project.facet.core.xml
0,0 → 1,10
<?xml version="1.0" encoding="UTF-8"?> |
<faceted-project> |
<runtime name="Apache Tomcat v9.0"/> |
<fixed facet="wst.jsdt.web"/> |
<fixed facet="java"/> |
<fixed facet="jst.web"/> |
<installed facet="java" version="12"/> |
<installed facet="jst.web" version="4.0"/> |
<installed facet="wst.jsdt.web" version="1.0"/> |
</faceted-project> |
/trunk/sw/WebExponentiator/.settings/org.eclipse.wst.jsdt.ui.superType.container
0,0 → 1,10
org.eclipse.wst.jsdt.launching.baseBrowserLibrary |
/trunk/sw/WebExponentiator/.settings/org.eclipse.wst.validation.prefs
0,0 → 1,2
disabled=06target |
eclipse.preferences.version=1 |
trunk/sw/WebExponentiator/.settings
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/WebContent/META-INF/MANIFEST.MF
===================================================================
--- trunk/sw/WebExponentiator/WebContent/META-INF/MANIFEST.MF (nonexistent)
+++ trunk/sw/WebExponentiator/WebContent/META-INF/MANIFEST.MF (revision 7)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
Index: trunk/sw/WebExponentiator/WebContent/META-INF
===================================================================
--- trunk/sw/WebExponentiator/WebContent/META-INF (nonexistent)
+++ trunk/sw/WebExponentiator/WebContent/META-INF (revision 7)
trunk/sw/WebExponentiator/WebContent/META-INF
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp/exponentiate.jsp
===================================================================
--- trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp/exponentiate.jsp (nonexistent)
+++ trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp/exponentiate.jsp (revision 7)
@@ -0,0 +1,23 @@
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<%@ include file="/WEB-INF/jsp/include.jsp" %>
+
+
+
+
+
+
+
+
+
+
+
+
+">
+
+
\ No newline at end of file
Index: trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp/include.jsp
===================================================================
--- trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp/include.jsp (nonexistent)
+++ trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp/include.jsp (revision 7)
@@ -0,0 +1,5 @@
+<%@ page session="false"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
+<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
\ No newline at end of file
Index: trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp/start.jsp
===================================================================
--- trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp/start.jsp (nonexistent)
+++ trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp/start.jsp (revision 7)
@@ -0,0 +1,15 @@
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<%@ include file="/WEB-INF/jsp/include.jsp" %>
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp
===================================================================
--- trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp (nonexistent)
+++ trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp (revision 7)
${el} | +
trunk/sw/WebExponentiator/WebContent/WEB-INF/jsp
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/WebContent/WEB-INF/lib
===================================================================
--- trunk/sw/WebExponentiator/WebContent/WEB-INF/lib (nonexistent)
+++ trunk/sw/WebExponentiator/WebContent/WEB-INF/lib (revision 7)
trunk/sw/WebExponentiator/WebContent/WEB-INF/lib
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/WebContent/WEB-INF
===================================================================
--- trunk/sw/WebExponentiator/WebContent/WEB-INF (nonexistent)
+++ trunk/sw/WebExponentiator/WebContent/WEB-INF (revision 7)
trunk/sw/WebExponentiator/WebContent/WEB-INF
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/WebContent/index.jsp
===================================================================
--- trunk/sw/WebExponentiator/WebContent/index.jsp (nonexistent)
+++ trunk/sw/WebExponentiator/WebContent/index.jsp (revision 7)
@@ -0,0 +1,4 @@
+<%@ include file="/WEB-INF/jsp/include.jsp" %>
+
+<%-- Redirected because we can't set the welcome page to a virtual URL. --%>
+
\ No newline at end of file
Index: trunk/sw/WebExponentiator/WebContent
===================================================================
--- trunk/sw/WebExponentiator/WebContent (nonexistent)
+++ trunk/sw/WebExponentiator/WebContent (revision 7)
trunk/sw/WebExponentiator/WebContent
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/pom.xml
===================================================================
--- trunk/sw/WebExponentiator/pom.xml (nonexistent)
+++ trunk/sw/WebExponentiator/pom.xml (revision 7)
@@ -0,0 +1,141 @@
+
+ 4.0.0
+ WebExponentiator
+ WebExponentiator
+ 0.0.1-SNAPSHOT
+ war
+
+ src
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+ 12
+
+
+
+ maven-war-plugin
+ 3.2.1
+
+ WebContent
+
+
+
+
+
+
+ org.springframework
+ spring-core
+ 5.1.8.RELEASE
+
+
+ org.springframework
+ spring-context
+ 5.1.8.RELEASE
+
+
+ org.springframework
+ spring-aop
+ 5.1.8.RELEASE
+
+
+ org.springframework
+ spring-webmvc
+ 5.1.8.RELEASE
+
+
+ org.springframework
+ spring-web
+ 5.1.8.RELEASE
+
+
+ com.fasterxml.jackson.core
+ jackson-core
+ 2.9.5
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.9.5
+
+
+
+ commons-dbcp
+ commons-dbcp
+ 1.4
+
+
+
+ org.aspectj
+ aspectjrt
+ 1.9.4
+
+
+
+ javax.servlet.jsp
+ javax.servlet.jsp-api
+ 2.3.3
+ provided
+
+
+ javax.servlet
+ javax.servlet-api
+ 4.0.1
+ provided
+
+
+ javax.servlet
+ jstl
+ 1.2
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.9
+
+
+ org.apache.directory.studio
+ org.apache.commons.lang
+ 2.6
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.26
+
+
+ org.slf4j
+ slf4j-log4j12
+ 1.7.26
+
+
+ org.slf4j
+ jcl-over-slf4j
+ 1.7.26
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+
+ javax.inject
+ javax.inject
+ 1
+
+
+
+ com.fazecast
+ jSerialComm
+ 2.5.1
+
+
+ junit
+ junit
+ 4.12
+
+
+
\ No newline at end of file
Index: trunk/sw/WebExponentiator/src/main/java/webexponentiator/config/AppContext.java
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator/config/AppContext.java (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator/config/AppContext.java (revision 7)
@@ -0,0 +1,24 @@
+package webexponentiator.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.support.ResourceBundleMessageSource;
+
+@Configuration
+@ComponentScan(basePackages = {
+ "webexponentiator"
+})
+public class AppContext {
+
+ @Bean
+ public ResourceBundleMessageSource messageSource() {
+
+ var source = new ResourceBundleMessageSource();
+ source.setBasenames("messages/messages");
+ source.setUseCodeAsDefaultMessage(true);
+
+ return source;
+ }
+
+}
Index: trunk/sw/WebExponentiator/src/main/java/webexponentiator/config/AppInitializer.java
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator/config/AppInitializer.java (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator/config/AppInitializer.java (revision 7)
@@ -0,0 +1,28 @@
+package webexponentiator.config;
+
+import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
+
+public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
+
+ @Override
+ protected Class < ? > [] getRootConfigClasses() {
+ return new Class[] {
+ AppContext.class
+ };
+ //return null;
+ }
+
+ @Override
+ protected Class < ? > [] getServletConfigClasses() {
+ return new Class[] {
+ WebMvcConfig.class
+ };
+ }
+
+ @Override
+ protected String[] getServletMappings() {
+ return new String[] {
+ "/"
+ };
+ }
+}
Index: trunk/sw/WebExponentiator/src/main/java/webexponentiator/config/WebMvcConfig.java
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator/config/WebMvcConfig.java (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator/config/WebMvcConfig.java (revision 7)
@@ -0,0 +1,39 @@
+package webexponentiator.config;
+
+import org.springframework.context.annotation.Bean;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.view.InternalResourceViewResolver;
+import org.springframework.web.servlet.view.JstlView;
+
+/**
+ * @author Ramesh Fadatare
+ */
+
+@Configuration
+@EnableWebMvc
+@ComponentScan(basePackages = {
+ "webexponentiator"
+})
+public class WebMvcConfig implements WebMvcConfigurer {
+
+ @Bean
+ public InternalResourceViewResolver resolver() {
+ InternalResourceViewResolver resolver = new InternalResourceViewResolver();
+ resolver.setViewClass(JstlView.class);
+ resolver.setPrefix("/WEB-INF/jsp/");
+ resolver.setSuffix(".jsp");
+ return resolver;
+ }
+
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry
+ .addResourceHandler("/resources/**")
+ .addResourceLocations("/resources/");
+ }
+
+}
\ No newline at end of file
Index: trunk/sw/WebExponentiator/src/main/java/webexponentiator/config
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator/config (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator/config (revision 7)
trunk/sw/WebExponentiator/src/main/java/webexponentiator/config
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/src/main/java/webexponentiator/controller/ExponentiationController.java
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator/controller/ExponentiationController.java (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator/controller/ExponentiationController.java (revision 7)
@@ -0,0 +1,203 @@
+package webexponentiator.controller;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Random;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import webexponentiator.util.Command;
+import webexponentiator.util.Communication;
+
+@Controller
+public class ExponentiationController {
+
+ /** Logger for this class and subclasses */
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ private static Communication communication;
+
+ @RequestMapping("/exponentiation")
+ public String showExponentiation(Model model) {
+ String ret = getPort();
+ ArrayList exponentiation = modularExponentiation();
+ logger.info("Starting exponentiation");
+ if (null == exponentiation) {
+ exponentiation = new ArrayList();
+ exponentiation.add(ret);
+ }
+ logger.info("Ending exponentiation");
+ model.addAttribute("exponentiation", exponentiation);
+ return "exponentiate";
+ }
+
+ private synchronized ArrayList modularExponentiation() {
+ ArrayList result = new ArrayList();
+ if (communication.getConnected()) {
+ 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"
+ * ));
+ */
+ logger.info("Send base");
+ result.add(sendBase(base.toString(10)));
+ logger.info("Send modulus");
+ result.add(sendModulus(modulus.toString(10)));
+ logger.info("Send exponent");
+ result.add(sendExponent(exponent.toString(10)));
+ logger.info("Send residuum");
+ result.add(sendResiduum(residuum.toString(10)));
+ logger.info("Send power");
+ result.add(sendPower());
+ logger.info("Send result");
+ result.add(sendResult());
+ logger.info("Send prepare");
+ result.add(sendPrepare());
+ result.add("Expected result " + expectedResult.toString(16));
+ result.add("Equal = 0? " + expectedResult.toString(16).compareTo(result.get(5)));
+ communication.disconnect();
+ return result;
+ }
+ return null;
+ }
+
+ 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 - " + 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 + " " + 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 + " " + 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 + " " + 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 + " " + 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 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]);
+ }
+ }
+ }
+
+ private void waitMicron(String string) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ logger.error("Wait for data happen -" + string);
+ e.printStackTrace();
+ }
+
+ }
+
+ private synchronized String getPort() {
+ logger.info("getPort() start");
+ if (communication == null) {
+ communication = new Communication();
+ }
+ ArrayList ports = communication.searchForPorts();
+ if (communication.getConnected()) {
+ return "COM3";
+ }
+ for (String port : ports) {
+ if (port.contains("COM3")) {
+ communication.connect();
+ if (communication.getConnected() == true) {
+ if (communication.initIOStream() == true) {
+ return "COM3";
+ }
+ return "Something happens - initIOStream";
+ }
+ return "Something happens - getConnected";
+ }
+ }
+ logger.info("getPort() end");
+ return "Something happens - COM3 not found";
+ }
+}
Index: trunk/sw/WebExponentiator/src/main/java/webexponentiator/controller/StartController.java
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator/controller/StartController.java (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator/controller/StartController.java (revision 7)
@@ -0,0 +1,35 @@
+package webexponentiator.controller;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.stereotype.Controller;
+//import org.springframework.web.servlet.mvc.Controller;
+
+@Controller
+public class StartController {
+
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ @GetMapping("/start")
+ public ModelAndView handleRequest()
+ throws ServletException, IOException {
+
+ String now = (new Date()).toString();
+ logger.info("Returning hello view with " + now);
+
+ Map myModel = new HashMap();
+ myModel.put("now", now);
+
+ return new ModelAndView("start", "model", myModel);
+ }
+
+}
\ No newline at end of file
Index: trunk/sw/WebExponentiator/src/main/java/webexponentiator/controller
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator/controller (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator/controller (revision 7)
trunk/sw/WebExponentiator/src/main/java/webexponentiator/controller
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/src/main/java/webexponentiator/util/Command.java
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator/util/Command.java (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator/util/Command.java (revision 7)
@@ -0,0 +1,12 @@
+package webexponentiator.util;
+
+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/WebExponentiator/src/main/java/webexponentiator/util/Communication.java
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator/util/Communication.java (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator/util/Communication.java (revision 7)
@@ -0,0 +1,215 @@
+package webexponentiator.util;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.fazecast.jSerialComm.SerialPort;
+import com.fazecast.jSerialComm.SerialPortDataListener;
+import com.fazecast.jSerialComm.SerialPortEvent;
+
+public class Communication implements SerialPortDataListener {
+
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ 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() {
+
+ }
+
+ // 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 ArrayList searchForPorts() {
+
+ ArrayList result = new ArrayList();
+
+ ports = SerialPort.getCommPorts();
+ logger.info("COM ports identified");
+
+ for (SerialPort port:ports) {
+ String portName = port.getDescriptivePortName();
+ if (portName.contains("COM3")) {
+ selectedPort = portName;
+ }
+ // get only serial ports
+ result.add(portName);
+ portMap.put(portName, port);
+ }
+
+ return result;
+ }
+
+ public String connect() {
+ 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());
+
+ // for controlling GUI elements
+
+ // logging
+ logger.info(selectedPort + " opened successfully.");
+
+ return "COM3 connected ok";
+ }
+
+ 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;
+
+ }
+
+ public void initListener() {
+ serialPort.addDataListener(this);
+ }
+
+ public void disconnect() {
+ // close the serial port
+ try {
+ serialPort.removeDataListener();
+ input.close();
+ output.close();
+ serialPort.closePort();
+ setConnected(false);
+
+ logger.info("Disconnected.");
+ } catch (Exception e) {
+ logger.error("Failed to close " + serialPort.getDescriptivePortName() + "("
+ + e.toString() + ")");
+ }
+ }
+
+ 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) {
+ logger.error("Failed to read data. (" + e.toString() + ")");
+ }
+ return null;
+ }
+
+ @Override
+ public int getListeningEvents() {
+ return SerialPort.LISTENING_EVENT_DATA_AVAILABLE;
+ }
+
+ @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);
+ //TODO Something for retrieve data
+ //window.appendText(data.toString(10) + "\n");
+ }
+ }
+ } catch (Exception e) {
+ logger.error("Failed to read data. (" + e.toString() + ")");
+ }
+ }
+ }
+
+ public void writeByte(byte b) {
+ try {
+ output.write(b);
+ Thread.sleep(1);
+ } catch (Exception e) {
+ logger.error("Failed to write data. (" + e.toString() + ")");
+ }
+ }
+
+ // 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(1);
+ } catch (Exception e) {
+ logger.error("Failed to write data. (" + e.toString() + ")");
+ }
+ }
+
+ final public boolean getConnected() {
+ return bConnected;
+ }
+
+ private void setConnected(boolean bConnected) {
+ this.bConnected = bConnected;
+ }
+
+}
Index: trunk/sw/WebExponentiator/src/main/java/webexponentiator/util
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator/util (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator/util (revision 7)
trunk/sw/WebExponentiator/src/main/java/webexponentiator/util
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/src/main/java/webexponentiator
===================================================================
--- trunk/sw/WebExponentiator/src/main/java/webexponentiator (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java/webexponentiator (revision 7)
trunk/sw/WebExponentiator/src/main/java/webexponentiator
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/src/main/java
===================================================================
--- trunk/sw/WebExponentiator/src/main/java (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/java (revision 7)
trunk/sw/WebExponentiator/src/main/java
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/src/main/resources/messages/log4j.properties
===================================================================
--- trunk/sw/WebExponentiator/src/main/resources/messages/log4j.properties (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/resources/messages/log4j.properties (revision 7)
@@ -0,0 +1,8 @@
+ #Set root logger 's level and its appender to an appender called CONSOLE which is defined below.
+ log4j.rootLogger=DEBUG, CONSOLE
+
+ #Set the behavior of the CONSOLE appender
+ log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+ log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+ log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
+
Index: trunk/sw/WebExponentiator/src/main/resources/messages/messages_pl.properties
===================================================================
--- trunk/sw/WebExponentiator/src/main/resources/messages/messages_pl.properties (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/resources/messages/messages_pl.properties (revision 7)
@@ -0,0 +1,7 @@
+title=WebExponentiator
+heading=WebExponentiator
+info=Now is
+opencoms=Open com ports
+home=Home
+start=Start page
+exponentiate_title=Exponentiation page
\ No newline at end of file
Index: trunk/sw/WebExponentiator/src/main/resources/messages
===================================================================
--- trunk/sw/WebExponentiator/src/main/resources/messages (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/resources/messages (revision 7)
trunk/sw/WebExponentiator/src/main/resources/messages
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/src/main/resources
===================================================================
--- trunk/sw/WebExponentiator/src/main/resources (nonexistent)
+++ trunk/sw/WebExponentiator/src/main/resources (revision 7)
trunk/sw/WebExponentiator/src/main/resources
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/src/main
===================================================================
--- trunk/sw/WebExponentiator/src/main (nonexistent)
+++ trunk/sw/WebExponentiator/src/main (revision 7)
trunk/sw/WebExponentiator/src/main
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/src
===================================================================
--- trunk/sw/WebExponentiator/src (nonexistent)
+++ trunk/sw/WebExponentiator/src (revision 7)
trunk/sw/WebExponentiator/src
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/target/classes/messages/log4j.properties
===================================================================
--- trunk/sw/WebExponentiator/target/classes/messages/log4j.properties (nonexistent)
+++ trunk/sw/WebExponentiator/target/classes/messages/log4j.properties (revision 7)
@@ -0,0 +1,8 @@
+ #Set root logger 's level and its appender to an appender called CONSOLE which is defined below.
+ log4j.rootLogger=DEBUG, CONSOLE
+
+ #Set the behavior of the CONSOLE appender
+ log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+ log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+ log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
+
Index: trunk/sw/WebExponentiator/target/classes/messages/messages_pl.properties
===================================================================
--- trunk/sw/WebExponentiator/target/classes/messages/messages_pl.properties (nonexistent)
+++ trunk/sw/WebExponentiator/target/classes/messages/messages_pl.properties (revision 7)
@@ -0,0 +1,7 @@
+title=WebExponentiator
+heading=WebExponentiator
+info=Now is
+opencoms=Open com ports
+home=Home
+start=Start page
+exponentiate_title=Exponentiation page
\ No newline at end of file
Index: trunk/sw/WebExponentiator/target/classes/messages
===================================================================
--- trunk/sw/WebExponentiator/target/classes/messages (nonexistent)
+++ trunk/sw/WebExponentiator/target/classes/messages (revision 7)
trunk/sw/WebExponentiator/target/classes/messages
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/target/classes
===================================================================
--- trunk/sw/WebExponentiator/target/classes (nonexistent)
+++ trunk/sw/WebExponentiator/target/classes (revision 7)
trunk/sw/WebExponentiator/target/classes
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF
===================================================================
--- trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF (nonexistent)
+++ trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/MANIFEST.MF (revision 7)
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Built-By: gajos-user
+Build-Jdk: 12.0.1
+Created-By: Maven Integration for Eclipse
+
Index: trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator/WebExponentiator/pom.properties
===================================================================
--- trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator/WebExponentiator/pom.properties (nonexistent)
+++ trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator/WebExponentiator/pom.properties (revision 7)
@@ -0,0 +1,7 @@
+#Generated by Maven Integration for Eclipse
+#Fri Aug 16 17:39:14 CEST 2019
+m2e.projectLocation=E\:\\eclipse201906\\WebExponentiator
+m2e.projectName=WebExponentiator
+groupId=WebExponentiator
+artifactId=WebExponentiator
+version=0.0.1-SNAPSHOT
Index: trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator/WebExponentiator/pom.xml
===================================================================
--- trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator/WebExponentiator/pom.xml (nonexistent)
+++ trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator/WebExponentiator/pom.xml (revision 7)
@@ -0,0 +1,141 @@
+
+ 4.0.0
+ WebExponentiator
+ WebExponentiator
+ 0.0.1-SNAPSHOT
+ war
+
+ src
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+ 12
+
+
+
+ maven-war-plugin
+ 3.2.1
+
+ WebContent
+
+
+
+
+
+
+ org.springframework
+ spring-core
+ 5.1.8.RELEASE
+
+
+ org.springframework
+ spring-context
+ 5.1.8.RELEASE
+
+
+ org.springframework
+ spring-aop
+ 5.1.8.RELEASE
+
+
+ org.springframework
+ spring-webmvc
+ 5.1.8.RELEASE
+
+
+ org.springframework
+ spring-web
+ 5.1.8.RELEASE
+
+
+ com.fasterxml.jackson.core
+ jackson-core
+ 2.9.5
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.9.5
+
+
+
+ commons-dbcp
+ commons-dbcp
+ 1.4
+
+
+
+ org.aspectj
+ aspectjrt
+ 1.9.4
+
+
+
+ javax.servlet.jsp
+ javax.servlet.jsp-api
+ 2.3.3
+ provided
+
+
+ javax.servlet
+ javax.servlet-api
+ 4.0.1
+ provided
+
+
+ javax.servlet
+ jstl
+ 1.2
+
+
+
+ org.apache.commons
+ commons-lang3
+ 3.9
+
+
+ org.apache.directory.studio
+ org.apache.commons.lang
+ 2.6
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.26
+
+
+ org.slf4j
+ slf4j-log4j12
+ 1.7.26
+
+
+ org.slf4j
+ jcl-over-slf4j
+ 1.7.26
+
+
+ log4j
+ log4j
+ 1.2.17
+
+
+
+ javax.inject
+ javax.inject
+ 1
+
+
+
+ com.fazecast
+ jSerialComm
+ 2.5.1
+
+
+ junit
+ junit
+ 4.12
+
+
+
\ No newline at end of file
Index: trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator/WebExponentiator
===================================================================
--- trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator/WebExponentiator (nonexistent)
+++ trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator/WebExponentiator (revision 7)
trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator/WebExponentiator
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator
===================================================================
--- trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator (nonexistent)
+++ trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator (revision 7)
trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven/WebExponentiator
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven
===================================================================
--- trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven (nonexistent)
+++ trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven (revision 7)
trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF/maven
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF
===================================================================
--- trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF (nonexistent)
+++ trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF (revision 7)
trunk/sw/WebExponentiator/target/m2e-wtp/web-resources/META-INF
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/target/m2e-wtp/web-resources
===================================================================
--- trunk/sw/WebExponentiator/target/m2e-wtp/web-resources (nonexistent)
+++ trunk/sw/WebExponentiator/target/m2e-wtp/web-resources (revision 7)
trunk/sw/WebExponentiator/target/m2e-wtp/web-resources
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/target/m2e-wtp
===================================================================
--- trunk/sw/WebExponentiator/target/m2e-wtp (nonexistent)
+++ trunk/sw/WebExponentiator/target/m2e-wtp (revision 7)
trunk/sw/WebExponentiator/target/m2e-wtp
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator/target
===================================================================
--- trunk/sw/WebExponentiator/target (nonexistent)
+++ trunk/sw/WebExponentiator/target (revision 7)
trunk/sw/WebExponentiator/target
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property
Index: trunk/sw/WebExponentiator
===================================================================
--- trunk/sw/WebExponentiator (nonexistent)
+++ trunk/sw/WebExponentiator (revision 7)
trunk/sw/WebExponentiator
Property changes :
Added: bugtraq:number
## -0,0 +1 ##
+true
\ No newline at end of property