Skip to content

Commit

Permalink
Each segment has its own yakindu message topic, each node of the dist…
Browse files Browse the repository at this point in the history
…ributed yakindu statecharts subscribes only for those yakindu topics in which it is interested in (controlled sections + turnout + neighbour segment topics), yakindu messages are moved to the common messages package and sending yakindu message is also possible using the communication lib.
  • Loading branch information
benedekh committed Feb 21, 2018
1 parent 5e805f6 commit 7f46b39
Show file tree
Hide file tree
Showing 33 changed files with 285 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class Main {

registry.parseArguments(args)

val occupancyTopics = TopicFactory::createSegmentTopics(#{SegmentOccupancyMessage}).toSet
val supervisedSections = #{15, 24}
val occupancyTopics = TopicFactory::createSegmentTopics(supervisedSections, #{SegmentOccupancyMessage}).toSet
val railwayTrackCommunicationStack = MessagingServiceFactory::createStackForTopics(registry, loggerFactory, occupancyTopics)

val barrierCommunicationStack = JsonDispatcherFactory::createMQTTStackWithJSON(registry, loggerFactory)
val supervisedSections = #{15, 24}

val component = new TrackSupervisor(supervisedSections)
val componentWrapper = new TrackSupervisorBridge(component, railwayTrackCommunicationStack, barrierCommunicationStack, loggerFactory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import hu.bme.mit.gamma.impl.async_t4.AsyncT4Component
import hu.bme.mit.gamma.impl.async_t5.AsyncT5Component
import hu.bme.mit.gamma.impl.async_t6.AsyncT6Component
import hu.bme.mit.gamma.impl.interfaces.ProtocolInterface
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.dispatcher.IYakinduMessageSender
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper.IYakinduProtocolDispatcher
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper.IYakinduProtocolRestarter
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper.PortWithDirection
Expand All @@ -17,10 +16,11 @@ import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper.Tu
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper.YakinduProtocolAdapter
import hu.bme.mit.inf.modes3.messaging.communication.command.trackelement.interfaces.ITrackElementCommander
import hu.bme.mit.inf.modes3.messaging.communication.state.trackelement.interfaces.ITrackElementStateRegistry
import hu.bme.mit.inf.modes3.messaging.communication.yakindu.interfaces.IYakinduMessageSender
import org.slf4j.ILoggerFactory
import org.slf4j.Logger

import static hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.ConnectionDirection.*
import static hu.bme.mit.inf.modes3.messaging.messages.enums.ConnectionDirection.*

class SafetyLogicInitializer {
val Logger logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.dispa
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper.YakinduProtocolDispatcher
import hu.bme.mit.inf.modes3.messaging.communication.factory.MessagingServiceFactory
import hu.bme.mit.inf.modes3.messaging.communication.factory.TopicFactory
import hu.bme.mit.inf.modes3.messaging.communication.factory.YakinduTopicFactory
import hu.bme.mit.inf.modes3.messaging.messages.command.SegmentCommand
import hu.bme.mit.inf.modes3.messaging.messages.status.SegmentOccupancyMessage
import hu.bme.mit.inf.modes3.messaging.messages.status.SegmentStateMessage
import hu.bme.mit.inf.modes3.utils.common.jopt.ArgumentDescriptorWithParameter
import hu.bme.mit.inf.modes3.utils.common.jopt.ArgumentRegistry
import hu.bme.mit.inf.modes3.utils.conf.layout.LayoutConfiguration
Expand All @@ -20,27 +20,27 @@ class Main {

def static void main(String[] args) {
System.setProperty(SimpleLogger.LOG_FILE_KEY, "System.out")
//System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "trace")
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "info")

val loggerFactory = new SimpleLoggerFactory
val logger = loggerFactory.getLogger(Main.name)
val layout = LayoutConfiguration.INSTANCE

val registry = new ArgumentRegistry(loggerFactory)
registry.registerArgumentWithOptions(new ArgumentDescriptorWithParameter("id", "ID of the turnout", String))
registry.registerArgumentWithOptions(new ArgumentDescriptorWithParameter("address", "The address of the transport server", String))
registry.registerArgumentWithOptions(new ArgumentDescriptorWithParameter("port", "The port used by the transport server", Integer))

registry.parseArguments(args);
registry.parseArguments(args)

val hostname = registry.getParameterStringValue("id")
val turnoutID = Integer.valueOf(hostname.split("\\.").head.replace('t', ''))

val controlledSections = LayoutConfiguration.INSTANCE.getControlledSections(turnoutID)
val turnoutSegmentItself = LayoutConfiguration.INSTANCE.getSegmentIdsOfTurnout(turnoutID)

val sectionTopics = controlledSections.map[TopicFactory::createSegmentTopics(it, #{SegmentCommand, SegmentStateMessage, SegmentOccupancyMessage})].flatten.toSet
val turnoutOccupancyTopic = turnoutSegmentItself.map[TopicFactory::createSegmentTopics(it, #{SegmentOccupancyMessage})].flatten.toSet
val controlledSections = layout.getControlledSections(turnoutID)
val turnoutSegmentItself = layout.getSegmentIdsOfTurnout(turnoutID)

val sectionTopics = TopicFactory::createSegmentTopics(controlledSections, #{SegmentCommand, SegmentOccupancyMessage})
val turnoutOccupancyTopic = TopicFactory::createSegmentTopics(turnoutSegmentItself, #{SegmentOccupancyMessage})
val turnoutTopics = TopicFactory::createTurnoutTopics(turnoutID)

val topics = newHashSet
Expand All @@ -51,7 +51,21 @@ class Main {
val communicationStack = MessagingServiceFactory::createStackForTopics(registry, loggerFactory, topics)
logger.debug('''Subscribed for railway track topics: «topics»''')

val yakinduStack = JsonDispatcherFactory::createMQTTStackWithJSON(registry, loggerFactory)
val neighbourSections = controlledSections.map[layout.getNeighbourSectionIds(it)].flatten.toSet
val turnoutSegments = layout.getSegmentIdsOfTurnout(turnoutID)

val neighbourSectionYakinduTopics = YakinduTopicFactory::createYakinduTopics(neighbourSections)
val controlledSectionsYakinduTopics = YakinduTopicFactory::createYakinduTopics(controlledSections)
val turnoutYakinduTopics = YakinduTopicFactory::createYakinduTopics(turnoutSegments)

val yakinduTopics = newHashSet
yakinduTopics.addAll(neighbourSectionYakinduTopics)
yakinduTopics.addAll(controlledSectionsYakinduTopics)
yakinduTopics.addAll(turnoutYakinduTopics)

val yakinduStack = JsonDispatcherFactory::createMQTTStackWithJSON(registry, loggerFactory, yakinduTopics)
logger.debug('''Subscribed for yakindu topics: «yakinduTopics»''')

val yakinduDispatcher = (yakinduStack.dispatcher as JsonMessageDispatcher)
val yakinduProtocolDispatcher = new YakinduProtocolDispatcher(loggerFactory)
yakinduDispatcher.canGoToListener = yakinduProtocolDispatcher
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.bridge

import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.dispatcher.IYakinduMessageSender
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper.IYakinduProtocolDispatcher
import hu.bme.mit.inf.modes3.messaging.communication.command.trackelement.interfaces.ITrackElementCommander
import hu.bme.mit.inf.modes3.messaging.communication.state.trackelement.interfaces.ITrackElementStateRegistry
import hu.bme.mit.inf.modes3.messaging.communication.yakindu.interfaces.IYakinduMessageSender

interface ISafetyLogicBridge extends IYakinduMessageSender, IYakinduProtocolDispatcher {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.bridge

import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.ConnectionDirection
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.ISafetyLogic
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.dispatcher.IYakinduMessageSender
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.dispatcher.YakinduMessageSender
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper.IYakinduProtocolDispatcher
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper.PortWithDirection
import hu.bme.mit.inf.modes3.messaging.communication.common.AbstractCommunicationComponent
import hu.bme.mit.inf.modes3.messaging.communication.yakindu.YakinduMessageSender
import hu.bme.mit.inf.modes3.messaging.communication.yakindu.interfaces.IYakinduMessageSender
import hu.bme.mit.inf.modes3.messaging.messages.enums.ConnectionDirection
import hu.bme.mit.inf.modes3.messaging.mms.MessagingService
import org.eclipse.xtend.lib.annotations.Accessors
import org.slf4j.ILoggerFactory
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
package hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.dispatcher

import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.messages.YakinduProtocolMessage
import hu.bme.mit.inf.modes3.messaging.communication.factory.MessagingServiceFactory
import hu.bme.mit.inf.modes3.messaging.messages.core.InternalMessageToTopicMapper
import hu.bme.mit.inf.modes3.utils.common.jopt.ArgumentRegistry
import java.util.Set
import org.slf4j.ILoggerFactory

class JsonDispatcherFactory {

def static createMQTTStackWithJSON(ArgumentRegistry argumentRegistry, ILoggerFactory factory) {
val topics = InternalMessageToTopicMapper.INSTANCE.getTopics(YakinduProtocolMessage.simpleName)
val dispatcher = new JsonMessageDispatcher(factory)
val communicationStack = MessagingServiceFactory::createStackForTopics(argumentRegistry, factory, topics, dispatcher)

val logger = factory.getLogger(JsonDispatcherFactory.name)
logger.debug('''Subscribed for Yakindu topics: «topics»''')

return communicationStack
def static createMQTTStackWithJSON(ArgumentRegistry argumentRegistry, ILoggerFactory factory, Set<String> topics) {
return MessagingServiceFactory::createStackForTopics(argumentRegistry, factory, topics, new JsonMessageDispatcher(factory))
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.dispatcher

import com.google.gson.Gson
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.messages.YakinduProtocolMessage
import hu.bme.mit.inf.modes3.messaging.communication.yakindu.interfaces.ICanGoToListener
import hu.bme.mit.inf.modes3.messaging.communication.yakindu.interfaces.ICannotGoToListener
import hu.bme.mit.inf.modes3.messaging.communication.yakindu.interfaces.IReleaseToListener
import hu.bme.mit.inf.modes3.messaging.communication.yakindu.interfaces.IReserveToListener
import hu.bme.mit.inf.modes3.messaging.messages.yakindu.YakinduProtocolMessage
import hu.bme.mit.inf.modes3.messaging.mms.dispatcher.AbstractMessageDispatcher
import org.eclipse.xtend.lib.annotations.Accessors
import org.slf4j.ILoggerFactory
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper

import hu.bme.mit.gamma.impl.interfaces.ProtocolInterface
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.ConnectionDirection
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.dispatcher.IYakinduMessageSender
import hu.bme.mit.inf.modes3.messaging.communication.yakindu.interfaces.IYakinduMessageSender
import hu.bme.mit.inf.modes3.messaging.messages.enums.ConnectionDirection

class YakinduProtocolAdapter implements ProtocolInterface.Listener.Required {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.wrapper

import hu.bme.mit.gamma.impl.interfaces.ProtocolInterface
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.ConnectionDirection
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comm.dispatcher.IYakinduMessageSender
import hu.bme.mit.inf.modes3.components.safetylogic.componentlevel.sc.comparators.ProvidedProtocolInterfaceComparator
import hu.bme.mit.inf.modes3.messaging.communication.yakindu.interfaces.IYakinduMessageSender
import hu.bme.mit.inf.modes3.messaging.messages.enums.ConnectionDirection
import java.util.Map
import java.util.Set
import java.util.concurrent.ConcurrentHashMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,31 @@ import hu.bme.mit.inf.modes3.utils.common.jopt.ArgumentDescriptorWithParameter
import hu.bme.mit.inf.modes3.utils.common.jopt.ArgumentRegistry
import hu.bme.mit.inf.modes3.utils.conf.layout.LayoutConfiguration
import hu.bme.mit.inf.modes3.utils.conf.layout.SegmentDirection
import java.net.InetAddress
import org.slf4j.impl.SimpleLoggerFactory

class Main {

def static void main(String[] args) {
val loggerFactory = new SimpleLoggerFactory
val logger = loggerFactory.getLogger(Main.name)
val layout = LayoutConfiguration.INSTANCE

val registry = new ArgumentRegistry(loggerFactory)
registry.registerArgumentWithOptions(new ArgumentDescriptorWithParameter("id", "ID of the turnout", String))
registry.registerArgumentWithOptions(new ArgumentDescriptorWithParameter("address", "The address of the transport server", String))
registry.registerArgumentWithOptions(new ArgumentDescriptorWithParameter("port", "The port used by the transport server", Integer))

registry.parseArguments(args);
registry.parseArguments(args)

val hostname = InetAddress.getLocalHost().getHostName();
logger.info("Hostname: " + hostname);
val turnoutID = Integer.valueOf(hostname.split("\\.").head.replace('t', ''));
val controlledSections = LayoutConfiguration.INSTANCE.getControlledSections(turnoutID)
val facingSegment = LayoutConfiguration.INSTANCE.getTurnoutVicinitySegmentsByDirection(turnoutID, SegmentDirection.FACING)
val turnoutSegmentItself = LayoutConfiguration.INSTANCE.getSegmentIdsOfTurnout(turnoutID)
val hostname = registry.getParameterStringValue("id")
val turnoutID = Integer.valueOf(hostname.split("\\.").head.replace('t', ''))

val sectionTopics = controlledSections.map[TopicFactory::createSegmentTopics(it, #{SegmentCommand, SegmentStateMessage})].flatten.toSet
val facingSegmentOccupancyTopic = facingSegment.map[TopicFactory::createSegmentTopics(it, #{SegmentOccupancyMessage})].flatten.toSet
val turnoutOccupancyTopic = turnoutSegmentItself.map[TopicFactory::createSegmentTopics(it, #{SegmentOccupancyMessage})].flatten.toSet
val controlledSections = layout.getControlledSections(turnoutID)
val facingSegment = layout.getTurnoutVicinitySegmentsByDirection(turnoutID, SegmentDirection.FACING)
val turnoutSegmentItself = layout.getSegmentIdsOfTurnout(turnoutID)

val sectionTopics = TopicFactory::createSegmentTopics(controlledSections, #{SegmentCommand, SegmentStateMessage})
val facingSegmentOccupancyTopic = TopicFactory::createSegmentTopics(facingSegment, #{SegmentOccupancyMessage})
val turnoutOccupancyTopic = TopicFactory::createSegmentTopics(turnoutSegmentItself, #{SegmentOccupancyMessage})

val turnoutTopics = TopicFactory::createTurnoutTopics(turnoutID)
val defaultTopics = TopicFactory::createDefaultTopics
Expand Down
Loading

0 comments on commit 7f46b39

Please sign in to comment.