nsn

/******************************************************************************************************
 *                                                                                                    *
 *                                           NSN_Echo                                            *
 *                                                                                                    *
 *        Title: XCC Verification Program                                                                   *
 *      Version: 1                                                                                      *
 *    Developer: Dr.Lou.31600                                                                  *
 *   Source Codes are the intellectual property of the author.                                        *
 *   Generated by The Xcelious Programming Facility (XPF) using the NSN Blueprint.                    *
 *                                                                                                    *
 ******************************************************************************************************/

package xcelious.blueprint.ivp;
import xcelious.blueprint.common.ChainCodeWorkArea;
import com.csa.support.api.CSAPI;								// Include the CSA Platform Interface
import com.csa.common.utils.DateUtils;							// Include the Date and Time Utilities
import java.util.Date;											// Include the standard Java Date package
import java.util.Iterator;										// Include the standard Java Iterator
import java.util.Set;											// Include the standatd Java Keyset


import com.csa.truenorth.nsn.TConnector;
import com.csa.truenorth.nsn.TCore;
import com.csa.truenorth.nsn.TCorelet;
import com.csa.truenorth.nsn.TNetwork;
import com.csa.truenorth.nsn.TPin;
import com.csa.truenorth.nsn.TSynapse;
import com.csa.truenorth.nsn.TrueNorth;

public class NSN_Echo1 extends TrueNorth
{
	TCorelet mainCorelet;										//
	TConnector inputConnector;									//
	TPin inputPin1;												//
	TPin inputPin2;												//
	TPin inputPin3;												//
	TPin inputPin4;												//
	TConnector outputConnector;									//
	TPin outputPin1;											//
	TPin outputPin2;											//
	TPin outputPin3;											//
	TPin outputPin4;											//
	TCore copyCore;												//
	TCopy copySynapse1;											//
	TCopy copySynapse2;											//
	TCopy copySynapse3;											//
	TCopy copySynapse4;											//
	TCore echoCore;												//
	TEcho echoSynapse1;											//
	TEcho echoSynapse2;											//
	TEcho echoSynapse3;											//
	TEcho echoSynapse4;											//
	TNetwork coreNet1;
	TNetwork coreNet2;
	TNetwork coreNet3;
	TNetwork coreNet4;

	public NSN_Echo1()											//
		{														//
		super();												//
		System.out.println("NSN_Echo1 - Constructor");			//
		}														//

	public void nsnLoadProgram()								//
		{   													//
		logicTrace(1001,"NSN_Echo1 - nsnLoadProgram");			//
		mainCorelet = new TCorelet("NSN-Echo",4);				//
		inputConnector = new TConnector("Prog.Input.API");		//
		inputPin1 = new TPin("Prog.Input.Pin1");				//
		inputPin2 = new TPin("Prog.Input.Pin2");				//
		inputPin3 = new TPin("Prog.Input.Pin3");				//
		inputPin4 = new TPin("Prog.Input.Pin4");				//

		outputConnector = new TConnector("Prog.Output.API");	//
		outputPin1 = new TPin("Prog.Output.Pin1");				//
		outputPin2 = new TPin("Prog.Output.Pin2");				//
		outputPin3 = new TPin("Prog.Output.Pin3");				//
		outputPin4 = new TPin("Prog.Output.Pin4");				//

		copyCore = new TCore("Copy.Core");						//
		copyCore.dispatchMode = propagate; 						//
		copySynapse1 = new TCopy("Copy.Synapse1");				//
		copySynapse2 = new TCopy("Copy.Synapse2");				//
		copySynapse3 = new TCopy("Copy.Synapse3");				//
		copySynapse4 = new TCopy("Copy.Synapse4");				//

		echoCore = new TCore("Echo.Core");						//
		echoCore.dispatchMode = propagate; 						//
		echoSynapse1 = new TEcho("Echo.Synapse1");				//
		echoSynapse2 = new TEcho("Echo.Synapse2");				//
		echoSynapse3 = new TEcho("Echo.Synapse3");				//
		echoSynapse4 = new TEcho("Echo.Synapse4");				//

		coreNet1 = new TNetwork("CoreNet1");					//
		coreNet2 = new TNetwork("CoreNet2");					//
		coreNet3 = new TNetwork("CoreNet3");					//
		coreNet4 = new TNetwork("CoreNet4");					//

		copyCore.mapSynapse(copySynapse1);						//
		copyCore.mapSynapse(copySynapse2);						//
		copyCore.mapSynapse(copySynapse3);						//
		copyCore.mapSynapse(copySynapse4);						//
		copyCore.integrate("Copy.Synapse1.Axon","Copy.Synapse1.Neuron"); //
		copyCore.integrate("Copy.Synapse2.Axon","Copy.Synapse2.Neuron"); //
		copyCore.integrate("Copy.Synapse3.Axon","Copy.Synapse3.Neuron"); //
		copyCore.integrate("Copy.Synapse4.Axon","Copy.Synapse4.Neuron"); //

		echoCore.mapSynapse(echoSynapse1);						//
		echoCore.mapSynapse(echoSynapse2);						//
		echoCore.mapSynapse(echoSynapse3);						//
		echoCore.mapSynapse(echoSynapse4);						//
		echoCore.integrate("Echo.Synapse1.Axon","Echo.Synapse1.Neuron"); //
		echoCore.integrate("Echo.Synapse2.Axon","Echo.Synapse2.Neuron"); //
		echoCore.integrate("Echo.Synapse3.Axon","Echo.Synapse3.Neuron"); //
		echoCore.integrate("Echo.Synapse4.Axon","Echo.Synapse4.Neuron"); //

		mainCorelet.allocateCore(copyCore);						//
		mainCorelet.allocateCore(echoCore);						//

		mainCorelet.allocateNetwork(coreNet1);					//
		mainCorelet.connect("Copy.Synapse1.Neuron","Echo.Synapse1.Axon","CoreNet1"); //
		mainCorelet.allocateNetwork(coreNet2);					//
		mainCorelet.connect("Copy.Synapse2.Neuron","Echo.Synapse2.Axon","CoreNet2"); //
		mainCorelet.allocateNetwork(coreNet3);					//
		mainCorelet.connect("Copy.Synapse3.Neuron","Echo.Synapse3.Axon","CoreNet3"); //
		mainCorelet.allocateNetwork(coreNet4);					//
		mainCorelet.connect("Copy.Synapse4.Neuron","Echo.Synapse4.Axon","CoreNet4"); //

		inputConnector.ioType = "Input";						//
		inputConnector.assignPin(inputPin1);						//
		inputConnector.assignPin(inputPin2);						//
		inputConnector.assignPin(inputPin3);						//
		inputConnector.assignPin(inputPin4);						//
		mainCorelet.allocateConnector(inputConnector);			//
		mainCorelet.connectInput("Prog.Input.Pin1","Copy.Synapse1.Axon"); //
		mainCorelet.connectInput("Prog.Input.Pin2","Copy.Synapse2.Axon"); //
		mainCorelet.connectInput("Prog.Input.Pin3","Copy.Synapse3.Axon"); //
		mainCorelet.connectInput("Prog.Input.Pin4","Copy.Synapse4.Axon"); //

		outputConnector.ioType = "Output";						//
		outputConnector.assignPin(outputPin1);					//
		outputConnector.assignPin(outputPin2);					//
		outputConnector.assignPin(outputPin3);					//
		outputConnector.assignPin(outputPin4);					//
		mainCorelet.allocateConnector(outputConnector);			//
		mainCorelet.connectOutput("Prog.Output.Pin1","Echo.Synapse1.Neuron"); //
		mainCorelet.connectOutput("Prog.Output.Pin2","Echo.Synapse2.Neuron"); //
		mainCorelet.connectOutput("Prog.Output.Pin3","Echo.Synapse3.Neuron"); //
		mainCorelet.connectOutput("Prog.Output.Pin4","Echo.Synapse4.Neuron"); //
		}

	public String nsnExecute()									//
		{														//
		String retCode = "ok";									//
		String result = "";
		Object data1 = null;
		Object data2 = null;
		Object data3 = null;
		Object data4 = null;
		logicTrace(1001,"NSN_Echo1 - nsnExecute");				//
		mainCorelet.ingress("Prog.Input.Pin1","E");				//
		mainCorelet.ingress("Prog.Input.Pin2","C");				//
		mainCorelet.ingress("Prog.Input.Pin3","H");				//
		mainCorelet.ingress("Prog.Input.Pin4","O");				//
		mainCorelet.dispatch();									//
		data1 = mainCorelet.egress("Prog.Output.Pin1");	//
		data2 = mainCorelet.egress("Prog.Output.Pin2");	//
		data3 = mainCorelet.egress("Prog.Output.Pin3");	//
		data4 = mainCorelet.egress("Prog.Output.Pin4");	//
		logicTrace(1001,"NSN_Echo1 - Output Pin1:" + (String)data1);	//
		result = result + (String)data1;
		logicTrace(1001,"NSN_Echo1 - Output Pin2:" + (String)data2);	//
		result = result + (String)data2;
		logicTrace(1001,"NSN_Echo1 - Output Pin3:" + (String)data3);	//
		result = result + (String)data3;
		logicTrace(1001,"NSN_Echo1 - Output Pin4:" + (String)data4);	//
		result = result + (String)data4;

		logicTrace(1001,"NSN_Echo1 - Output Collection:" + result);	//

//		for (int tx = 0; tx < mainCorelet.traceCtr; tx++)		//
//			{
//			logicTrace(9999,mainCorelet.traceData[tx].traceInfo); //
//			}

		setNsnCorelet(mainCorelet);								//

		ChainCodeWorkArea ccwa = new ChainCodeWorkArea();		// Allocate Chain Code Work Area (CCWA)
																//
		ccwa.setParmKeyList(progParms.keySet());				// Set the Keyset for the program paramters
		ccwa.setParmKeys(ccwa.getParmKeyList().iterator());		// Get the program parameters keyset iterator
																//
		while (ccwa.getParmKeys().hasNext())					// Iterate through the program
			{													//  parameter list
			ccwa.setWkKey((String) ccwa.getParmKeys().next());	// Get the paramter name
			ccwa.setWkValue((String) progParms.get(ccwa.getWkKey())); // Get the parameter value
			logicTrace(1002,"NSN_Echo1 - Exec Parm:" // Program logic trace
						    + ccwa.getWkKey()					// Display parameter name
						    + " Value:"							//  and
						    + ccwa.getWkValue());				//   value
			}													// Continue parameter iteration
																//
		ccwa.setToday(new Date());								// Get the current date and time
       	ccwa.setDateUtils(new DateUtils());						// Create the DateUtils Object
       	ccwa.setReptDate(ccwa.getDateUtils().reptTimeStamp());	// Retrieve the formatted date and time
        ccwa.setUserGreeting(ccwa.getDateUtils().getGreeting(ccwa.getToday())); // Retrieve the greeting
		logicTrace(1003,"NSN_Echo1 - TimeStamp:"	// Program logic trace
						+ ccwa.getReptDate()					// Display the formatted date and time
						+ " Greeting:"							// Display the user greeting
						+ ccwa.getUserGreeting());				// i.e. Good Afternoon
																//
																//

	    addSymbol("&LedgerHeader","Xcelious Programming Facility (XPF)");
	    addSymbol("&LedgerTitle","HyperLedger Chain Code Workbench");
	    addSymbol("&LedgerFontColor","blue");
	    addSymbol("&LedgerNoticeColor","green");
	    addSymbol("&ProdLogoURL","http://www.scepterx.com/MediaLib/XCCProdIntro.png");

		addSymbol("&PageHeader","Xcelious Programming Facility (XPF)");
	    addSymbol("&PageTitle","HyperLedger Java Chain Code Workbench");
	    addSymbol("&PageFontColor","navy");
	    addSymbol("&PageNoticeColor","green");
	    addSymbol("&DevLogoURL","http://www.scepterx.com/MediaLib/CTOLogo.png");

	    addSymbol("&DevName","Developer: Dr.Lou.31600");
	    addSymbol("&ProgMessage1","Neural Synaptic Network");

		addSymbol("&PageMessage2",ccwa.getReptDate());			// Symbolic substitution for PageMessage1
	    addSymbol("&PageMessage3",ccwa.getUserGreeting());		// Symbolic substitution for PageMessage2
		return epilog();											//
		}

}

class TCopy extends TSynapse									//
{																//
																//
	public TCopy(String synapseId)								//
		{														//
		super(synapseId);										//
		System.out.println("NSN_Echo1 - TCopy - Constructor");				//
		}														//

	public void execute()										//
		{														//
		System.out.println("NSN_Echo1 - TCopy - Synapse:" + ident + " Buff:" + (String)axon.buffer); //
		trace("Buff:" + (String)axon.buffer);					//
		dendrite.storage = axon.buffer;							//
		neuron.buffer = axon.buffer;							//
		}														//
}
class TEcho extends TSynapse									//
	{																//
																	//
	public TEcho(String synapseId)								//
		{														//
		super(synapseId);										//
		System.out.println("NSN_Echo1 - TEcho - Constructor");				//
		}														//

	public void execute()										//
		{														//
		System.out.println("NSN_Echo1 - TEcho - Synapse:" + ident + " Buff:" + (String)axon.buffer); //
		trace("Buff:" + (String)axon.buffer);					//
		dendrite.storage = axon.buffer;							//
		neuron.buffer = axon.buffer;							//
		}														//

}