-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation Split Classes in own files package structure removed unnecessary imports
- Loading branch information
diekmann
committed
Feb 19, 2013
1 parent
a2b0966
commit ac2f5b3
Showing
8 changed files
with
162 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<bacdevices> | ||
<device cname="SensorSink">192.168.56.101</device> | ||
<device cname="SensorSink">192.168.56.20</device> | ||
<device cname="SensorSink">192.168.56.102</device> | ||
</bacdevices> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/scala/tum/in/net/bacnet/deviceFactory/MyBACnetDevices.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package tum.in.net.bacnet.deviceFactory | ||
|
||
|
||
import tum.in.net.bacnet.lowlevel.device.MyLocalDevice | ||
import tum.in.net.bacnet.lowlevel.SlaveDeviceReading | ||
|
||
|
||
/** | ||
* reads an xml file with other known BACnet devices | ||
* queries and sets their values | ||
* supervisory device | ||
*/ | ||
class MyReader(val localDevice: MyLocalDevice = new MyLocalDevice( | ||
broadcastAddress = "127.0.0.255", | ||
name = "corny's reader", | ||
deviceId=1234), abortOnNoRemotes: Boolean = true){ | ||
|
||
def readConfigFromXML(file: java.io.File): List[String] = { | ||
println("reading configuration file "+file) | ||
val knownDevicesFromConfig = scala.io.Source.fromFile(file) | ||
val otherDevicesString: String = try { | ||
knownDevicesFromConfig.mkString | ||
} finally { | ||
knownDevicesFromConfig.close() | ||
} | ||
import scala.xml._ | ||
require(!otherDevicesString.isEmpty()) | ||
|
||
// config template | ||
// val xmlOtherDevices = <bacdevices> | ||
// <device>192.168.56.102</device> | ||
// <device>192.168.56.103</device> | ||
// <device>192.168.56.104</device> | ||
// </bacdevices> | ||
|
||
val xmlOtherDevices = XML.loadString(otherDevicesString) | ||
assert(xmlOtherDevices.isInstanceOf[scala.xml.Elem]) | ||
val deviceIPs: NodeSeq = (xmlOtherDevices \\ "bacdevices") | ||
try{ | ||
assert(!deviceIPs.isEmpty) | ||
} catch { | ||
case e: java.lang.AssertionError => | ||
println("Error: "+e) | ||
if (abortOnNoRemotes) | ||
throw e | ||
else | ||
println("continue") | ||
} | ||
val deviceIPsList: List[String] = (for (node <- (deviceIPs \\ "device"))yield node.text).toList | ||
println("parsed devices from config: "+deviceIPsList) | ||
deviceIPsList | ||
} | ||
|
||
val otherDevices: List[String] = readConfigFromXML(new java.io.File("otherdevices.xml")) | ||
|
||
|
||
val localReader = new SlaveDeviceReading(localDevice=localDevice, | ||
otherDevices=otherDevices, | ||
abortOnNoRemotes=abortOnNoRemotes) | ||
|
||
def start(initLocalDevice: Boolean = true) = { | ||
if (initLocalDevice){ | ||
localDevice.initialize() | ||
} | ||
localReader.start() | ||
// TODO | ||
// we could pass abortOnNoRemotes=true and catch the assertion error, if no remote devices are found | ||
// retry every X seconds | ||
// although, this is better done in the SlaveDeviceReading's act method act | ||
} | ||
} | ||
|
||
|
||
/** | ||
* reads an xml file with other known BACnet devices | ||
* queries and sets their values | ||
* Also is an active BACnet device with changing Input/Output values | ||
*/ | ||
class MyReaderWriterActiveMasterSlaveDevice{ | ||
|
||
val hostname: String = try { | ||
java.net.InetAddress.getLocalHost.getHostName | ||
}catch{ | ||
case e: java.net.UnknownHostException => | ||
println("Error: "+e) | ||
val hostnameguess_array = e.toString().split(' ') | ||
if (hostnameguess_array.length < 2){ | ||
null | ||
} | ||
|
||
val hostnameguess = hostnameguess_array(hostnameguess_array.length - 1) | ||
if (hostnameguess.length() >= 5){ | ||
println("guessing hostname `"+hostnameguess+"'") | ||
hostnameguess | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
/* acts, changes values */ | ||
val localSlaveDevice = new MySlaveDevice( | ||
broadcastAddress = "127.0.0.255", | ||
name=hostname, | ||
randomValues=true) | ||
|
||
val localDevice = localSlaveDevice.localDevice | ||
|
||
val localReader = new MyReader(localDevice, abortOnNoRemotes=false) | ||
|
||
|
||
def start() = { | ||
localSlaveDevice.start() | ||
localReader.start(initLocalDevice=false) | ||
} | ||
|
||
} |
15 changes: 13 additions & 2 deletions
15
...ala/tum/in/net/bacnet/MySlaveDevice.scala → .../bacnet/deviceFactory/MySlaveDevice.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
...ala/tum/in/net/bacnet/SlaveDeviceIO.scala → ...n/net/bacnet/lowlevel/SlaveDeviceIO.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters