Skip to content

Commit

Permalink
+ barrier service for pi; * fixed bugs in the barrier service; - remo…
Browse files Browse the repository at this point in the history
…ved trackelementstatus reporter project.
  • Loading branch information
benedekh committed Oct 6, 2017
1 parent fd3033b commit dc7b6e7
Show file tree
Hide file tree
Showing 30 changed files with 31 additions and 596 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ cd src/java

| Logical Component | Physical location | Comments | Owner|
|:-------------------:|:------------------------|:--------:|:---:|
| Barrier | <components_path_prefix>.barrier | Sends open/close commands to the barrier over the network, depnending on the occupancy of certain segments. | benedekh
| Dashboard | <components_path_prefix>.dashboard | Dashboard for the model railway track. | zsoltmazlo
| GPIO Manager | <components_path_prefix>.gpiomanager | To control the GPIO pins of the Beagle Bone Black embedded units from Java. | hegyibalint
| Leapmotion | <components_path_prefix>.leapmotion | Leapmotion sensor code in Java. | pappist (Papp István)
Expand Down
1 change: 1 addition & 0 deletions config-management/ansible/deploy-root.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
- include: utils/deploy-gradle.yaml service_name=dashboard
- include: utils/deploy-gradle.yaml service_name=occupancyquery
- include: utils/deploy-gradle.yaml service_name=touchboard
- include: utils/deploy-gradle.yaml service_name=barrier
- include: utils/deploy-systemd.yaml service_name=xpressnet
10 changes: 10 additions & 0 deletions config-management/ansible/files/modes3-barrier.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=MoDeS3 Barrier Server
After=syslog.target network.target mosquitto.service

[Service]
ExecStart=/modes3/hu.bme.mit.inf.modes3.components.barrier/bin/hu.bme.mit.inf.modes3.components.barrier -address root.modes3.intra -port 1883
Restart=always

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class TrackSupervisor implements ITrackSupervisor {
if (newValue == SegmentOccupancy.OCCUPIED) {
supervisorWrapper.sendBarrierMessage("closed")
} else if (supervisedSections.entrySet.forall[it.value == SegmentOccupancy.FREE]) {
println("OPENED IS SENT")
supervisorWrapper.sendBarrierMessage("opened")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class Main {
new ArgumentDescriptorWithParameter("address", "The address of the transport server", String))
registry.registerArgumentWithOptions(
new ArgumentDescriptorWithParameter("port", "The port used by the transport server", Integer))
registry.registerArgumentWithOptions(
new ArgumentDescriptorWithParameter("barriertopic", "Topic to be used by the barrier controller", String))

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

val railwayTrackCommunicationStack = MessagingServiceFactory::createStackForEveryTopic(registry, loggerFactory)
val barrierCommunicationStack = JsonDispatcherFactory::createMQTTStackWithJSON(registry, loggerFactory)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hu.bme.mit.inf.modes3.components.barrier.comm

import hu.bme.mit.inf.modes3.components.barrier.comm.json.BarrierStateMessage
import hu.bme.mit.inf.modes3.messaging.messages.status.BarrierStateMessage
import hu.bme.mit.inf.modes3.messaging.mms.MessagingService
import org.slf4j.ILoggerFactory
import org.slf4j.Logger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package hu.bme.mit.inf.modes3.components.barrier.comm.json

import com.google.gson.Gson
import hu.bme.mit.inf.modes3.messaging.messages.status.BarrierStateMessage
import hu.bme.mit.inf.modes3.messaging.mms.dispatcher.AbstractMessageDispatcher
import org.slf4j.ILoggerFactory
import org.slf4j.Logger
Expand All @@ -18,7 +20,10 @@ class JsonDispatcher extends AbstractMessageDispatcher {

override convertMessageToRaw(Object message) throws IllegalArgumentException {
try {
return (message as BarrierStateMessage).serialize
val barrierMessage = message as BarrierStateMessage
val gson = new Gson
val str = gson.toJson(barrierMessage)
return str.bytes
} catch (Exception ex) {
logger.error(ex.message)
throw new IllegalArgumentException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package hu.bme.mit.inf.modes3.components.barrier.comm.json

import hu.bme.mit.inf.modes3.components.util.jopt.ArgumentRegistry
import hu.bme.mit.inf.modes3.messaging.mms.MessagingService
import hu.bme.mit.inf.modes3.messaging.messages.core.InternalMessageToTopicMapper
import hu.bme.mit.inf.modes3.messaging.messages.status.BarrierStateMessage
import hu.bme.mit.inf.modes3.messaging.mms.TopicBasedMessagingService
import hu.bme.mit.inf.modes3.transports.config.TopicBasedTransportConfiguration
import hu.bme.mit.inf.modes3.transports.mqtt.MQTTTransport
import org.slf4j.ILoggerFactory

class JsonDispatcherFactory {

def static createMQTTStackWithJSON(ArgumentRegistry argumentRegistry, ILoggerFactory factory) {
return new MessagingService(
return new TopicBasedMessagingService(
new MQTTTransport(loadMQTTConfiguration(argumentRegistry), factory),
new JsonDispatcher(factory),
factory
Expand All @@ -20,7 +22,7 @@ class JsonDispatcherFactory {
val address = registry.getParameterStringValue('address')
val id = registry.getParameterStringValue('id')
val port = registry.getParameterIntegerValue('port')
val barriertopic = registry.getParameterStringValue('barriertopic')
val barriertopic = InternalMessageToTopicMapper.INSTANCE.getTopic(BarrierStateMessage.simpleName)

return new TopicBasedTransportConfiguration(id, address, port, barriertopic)
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit dc7b6e7

Please sign in to comment.