Skip to content

Commit

Permalink
Merge pull request #21 from jwszolek/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jwszolek authored May 28, 2018
2 parents 247f0c9 + b232f88 commit d798d72
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 103 deletions.
26 changes: 26 additions & 0 deletions src/main/groovy/dsl/engine/GraphProducer.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,32 @@ class GraphProducer {
}


def parseSimObject(def input) {

def simItems = [:]

input.catalog.each { k, v ->
if (v.toString().contains("'type':'action'")) {

def rawAdapter = v.toString().replace("[", "{").replace("]", "}").replace("\'", "\"")
def valueMap = new JsonSlurper().parseText(rawAdapter)

def simTime = ""
valueMap.each { ak, av ->
if (ak.contains("stop")) simTime = av
}

if(!simTime.isEmpty()){
simItems.put("simTime",simTime)
}
}
}
return simItems
}




def formatInput(def input) {

//define central node
Expand Down
19 changes: 12 additions & 7 deletions src/main/groovy/dsl/engine/SimDriver.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ class SimDriver {
NetworkModel model = new NetworkModel(null,"SMOL Simulation Engine",true,true, varList)
Experiment exp = new Experiment("SMOLSimulationExperiment", new SingleUnitTimeFormatter(referenceUnit, epsilon,6,false))

model.connectToExperiment(exp)
exp.stop(new TimeInstant(10000, TimeUnit.MILLISECONDS));

def simObject = (Map<String,String>)new GraphProducer().parseSimObject(properties)
def simTime = Double.parseDouble(simObject.getOrDefault("simTime",""))

exp.tracePeriod(new TimeInstant(0), new TimeInstant(10000,TimeUnit.MILLISECONDS));
exp.debugPeriod(new TimeInstant(0), new TimeInstant(10000,TimeUnit.MILLISECONDS));
model.connectToExperiment(exp)

if(simTime != 0) {
exp.stop(new TimeInstant(simTime, TimeUnit.MILLISECONDS));
exp.tracePeriod(new TimeInstant(0), new TimeInstant(simTime, TimeUnit.MILLISECONDS));
exp.debugPeriod(new TimeInstant(0), new TimeInstant(simTime, TimeUnit.MILLISECONDS));
}else{
exp.stop(new TimeInstant(1000, TimeUnit.MILLISECONDS));
exp.tracePeriod(new TimeInstant(0), new TimeInstant(1000, TimeUnit.MILLISECONDS));
exp.debugPeriod(new TimeInstant(0), new TimeInstant(1000, TimeUnit.MILLISECONDS));
}

LogsWritrer lw = new LogsWritrer()
exp.register(lw)
Expand All @@ -40,10 +47,8 @@ class SimDriver {
exp.setShowProgressBarAutoclose(true)
exp.setShowProgressBar(true)


exp.start()
exp.report()

exp.finish()
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/sim/network/NetworkModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void doInitialSchedules() {
//TODO: it needs to be more genetic - we should support different types, not only RS232Adapter
if(!converterInfo.isEmpty()){
RS232MessageGenerator rs232MessageGenerator = new RS232MessageGenerator(this, name, true,
converterInfo.values().stream().findFirst().get());
converterInfo.values().stream().findFirst().get(),sensorObj.destAddress, sensorObj.freq);
rs232MessageGenerator.schedule(new TimeSpan(0));
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/sim/network/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public static void main(String[] args) throws IOException {

model.connectToExperiment(exp);
exp.setShowProgressBar(false);
exp.stop(new TimeInstant(10000, TimeUnit.MILLISECONDS));
exp.stop(new TimeInstant(1000, TimeUnit.MILLISECONDS));


exp.tracePeriod(new TimeInstant(0), new TimeInstant(10000,TimeUnit.MILLISECONDS));
exp.debugPeriod(new TimeInstant(0), new TimeInstant(10000,TimeUnit.MILLISECONDS));
exp.tracePeriod(new TimeInstant(0), new TimeInstant(1000,TimeUnit.MILLISECONDS));
exp.debugPeriod(new TimeInstant(0), new TimeInstant(1000,TimeUnit.MILLISECONDS));

LogsWritrer lw = new LogsWritrer();
//
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/sim/network/rs232/RS232Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import desmoj.core.simulator.Queue;
import desmoj.core.simulator.TimeSpan;
import main.java.com.sim.network.EthAdapter;
import main.java.com.sim.network.EthFrame;
import main.java.com.sim.network.TCPMessage;

import java.util.concurrent.TimeUnit;
Expand All @@ -30,9 +29,13 @@ public void eventRoutine() throws SuspendExecution {
if(!inRS232AdapterQueue.isEmpty()){
TCPMessage msg = inRS232AdapterQueue.first();
inRS232AdapterQueue.remove(msg);
ethAdapter.outMsgQueue.insert(msg);
getEthAdapter().outMsgQueue.insert(msg);
}

schedule(new TimeSpan(1, TimeUnit.MICROSECONDS));
}

public EthAdapter getEthAdapter() {
return ethAdapter;
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/sim/network/rs232/RS232ConverterEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public void eventRoutine(RS232Message rs232Message) throws SuspendExecution {
this.receivedMsg = rs232Message;

TCPMessage tcpMessage = new TCPMessage(model, "RS232 To TCP", true);
// tcpMessage.setDstAddress();
// tcpMessage.setDstAddress();
tcpMessage.setDstAddress(rs232Message.getTcpDstAddress());
tcpMessage.setDstAddress(rs232Adapter.getEthAdapter().getAdapterAddress());
if(this.rs232Adapter.inRS232AdapterQueue != null) {
this.rs232Adapter.inRS232AdapterQueue.insert(tcpMessage);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/sim/network/rs232/RS232Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@

public class RS232Message extends Entity {

private String tcpDstAddress;


public RS232Message(Model owner, String name, boolean showInTrace) {
super(owner, name, showInTrace);
}

public String getTcpDstAddress() {
return tcpDstAddress;
}

public void setTcpDstAddress(String tcpDstAddress) {
this.tcpDstAddress = tcpDstAddress;
}
}
12 changes: 10 additions & 2 deletions src/main/java/com/sim/network/rs232/RS232MessageGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,30 @@
public class RS232MessageGenerator extends ExternalEvent {

private RS232Adapter rs232Adapter;
private String destAddress;
private double scheduleValue;

public RS232MessageGenerator(Model owner, String name, boolean showInTrace, RS232Adapter rsConverter) {

public RS232MessageGenerator(Model owner, String name, boolean showInTrace, RS232Adapter rsConverter, String destAddress, double scheduleValue) {
super(owner, name, showInTrace);
this.rs232Adapter = rsConverter;
this.rs232Adapter = rsConverter;
this.destAddress = destAddress;
this.scheduleValue = scheduleValue;
}

@Override
public void eventRoutine() throws SuspendExecution {
NetworkModel model = (NetworkModel)getModel();
RS232Message msg = new RS232Message(model, "RS232 Message", true);
msg.setTcpDstAddress(destAddress);
sendTraceNote("RS232 Message Created ");


RS232ConverterEvent converter = new RS232ConverterEvent(model, "RS232 Converter Event", true, this.rs232Adapter);
converter.schedule(msg, new TimeSpan(10, TimeUnit.MICROSECONDS));


schedule(new TimeSpan(100, TimeUnit.MILLISECONDS));
schedule(new TimeSpan(this.scheduleValue, TimeUnit.MILLISECONDS));
}
}
101 changes: 19 additions & 82 deletions src/main/resources/knx-schema2.smol
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ tn "eth3", {
}


san "temp-sensor-1", {
connect "eth1"
destAddress "2"
freq "50"
}

san "temp-sensor-2", {
connect "eth3"
destAddress "2"
Expand All @@ -38,105 +32,48 @@ san "temp-sensor-4", {
}


/*expander "rs485", {
expander "rs485", {
connect "eth1"
}

expander "rs485-2", {
connect "eth3"
}


san "temp-sensor-1", {
san "temp-sensor-rs485-1", {
connect "rs485"
destAddress "2"
freq "55"
}

san "temp-sensor-2", {
san "temp-sensor-rs485-2", {
connect "rs485"
destAddress "2"
freq "56"
}

san "temp-sensor-3", {
connect "rs485-2"
destAddress "2"
}*/

/*san "temp-sensor-4", {
connect "rs485-2"
destAddress "2"
}*/


action "draw", {
fullmap "true"
}


action "sim", {
stop "1s"
}













/*
adapter "eth1", {
ip "1"
}

adapter "eth2", {
ip "2"
}


converter "rs485", {
connect "eth1"
}

converter "rs485-2", {
connect "eth2"
}


sensor "temperature1", {
san "temp-sensor-rs485-3", {
connect "rs485"
destAddress "2"
freq "57"
}

sensor "temperature2", {
san "temp-sensor-rs485-4", {
connect "rs485"
destAddress "2"
freq "58"
}

sensor "temperature3", {
connect "rs485-2"
}

sensor "humidity1", {
san "temp-sensor-rs485-5", {
connect "rs485"
destAddress "2"
freq "59"
}

sensor "humidity2", {
connect "rs485"
}

sensor "alarm-module", {
connect "rs485-2"
action "draw", {
fullmap "true"
}

sensor "hvac-control-module", {
connect "rs485-2"
// stop after 1 sek
action "sim", {
stop "20000"
}

sensor "dashboard", {
connect "rs485"
} */

9 changes: 5 additions & 4 deletions src/main/resources/network.smol
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
adapter "Server", {
ip "2"

}

adapter "eth1", {
ip "1"
generator_connected "true"
dst "Server"
}

adapter "Server", {
ip "2"
}

converter "rs485", {
dst "Server"
}
Expand Down

0 comments on commit d798d72

Please sign in to comment.