summaryrefslogtreecommitdiff
path: root/ebus-scala
diff options
context:
space:
mode:
Diffstat (limited to 'ebus-scala')
-rw-r--r--ebus-scala/.classpath7
-rw-r--r--ebus-scala/.gitignore3
-rw-r--r--ebus-scala/.project18
-rw-r--r--ebus-scala/Main.scala (renamed from ebus-scala/src/App.scala)80
4 files changed, 43 insertions, 65 deletions
diff --git a/ebus-scala/.classpath b/ebus-scala/.classpath
deleted file mode 100644
index bc01bff..0000000
--- a/ebus-scala/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/ebus-scala/.gitignore b/ebus-scala/.gitignore
index be9619d..5b82eed 100644
--- a/ebus-scala/.gitignore
+++ b/ebus-scala/.gitignore
@@ -1 +1,2 @@
-.scala_dependencies
+target
+project
diff --git a/ebus-scala/.project b/ebus-scala/.project
deleted file mode 100644
index a19eae3..0000000
--- a/ebus-scala/.project
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>ebus-scala</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.scala-ide.sdt.core.scalabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.scala-ide.sdt.core.scalanature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/ebus-scala/src/App.scala b/ebus-scala/Main.scala
index 8bd27e9..8202eb1 100644
--- a/ebus-scala/src/App.scala
+++ b/ebus-scala/Main.scala
@@ -16,6 +16,44 @@ class EbusDefinition(val ebusXmlFile: String) {
}
}
+class EbusPacket(val source: Char,
+ val destination: Char,
+ val primaryCommand: Char,
+ val secondaryCommand: Char,
+ val payloadLength: Char,
+ val payload: List[Char],
+ val crc: Char,
+ val rawLength: Int) {
+ val length = 6 + payload.size
+
+ override def toString: String = {
+ val p = if (payload.size == 0)
+ ""
+ else
+ payload.map(a => "%02x".format(a.toInt)).
+ reduceLeft((a: Any, b: String) => a + " " + b)
+
+ "Ebus: d=%02x pC=%02x sC=%02x pL=%02x crc=%02x p=%s".format(
+ destination.toInt, primaryCommand.toInt, secondaryCommand.toInt, payloadLength.toInt,
+ crc.toInt, p.toString)
+ }
+
+ /**
+ * Die CRC-Prüfsumme wird vom jeweiligen Sender über der expandierten Bytesendefolge mit dem
+ * Generatorpolynom X8 +X7 + X4 + X3 + X +1 gebildet und als letztes Byte der Nachricht,
+ * sofern notwendig, sogar expandiert gesendet.
+ *
+ * Generatorpol. 11001101
+ */
+ def calcCrc: Char = {
+ //val foo = payload.reduce((a, b) => ((a.intValue + b.intValue) % 256).toChar)
+ //val sum = destination + primaryCommand + secondaryCommand + payloadLength + foo
+
+ val crc = 1 + 1
+ 1
+ }
+}
+
object EbusPacket {
/**
* Wird von {@link EbusReader} mit einer Streamposition aufgerufen.
@@ -34,7 +72,7 @@ object EbusPacket {
val payloadLength = stream.apply(4).toChar
rawLength = 5
- var payload = new Array[Char](payloadLength)
+ var payload = List[Char]()
for (i <- 0 until payloadLength) {
var it = stream.apply(rawLength).toChar
rawLength += 1
@@ -53,7 +91,8 @@ object EbusPacket {
rawLength -= 1
}
}
- payload.update(i, it)
+ //payload.update(i, it)
+ payload = payload :+ it
}
val crc = stream.apply(5 + payloadLength).toChar
rawLength += 1
@@ -71,43 +110,6 @@ object EbusPacket {
}
}
-class EbusPacket(val source: Char,
- val destination: Char,
- val primaryCommand: Char,
- val secondaryCommand: Char,
- val payloadLength: Char,
- val payload: Array[Char],
- val crc: Char,
- val rawLength: Int) {
- val length = 6 + payload.size
-
- override def toString: String = {
- val p = if (payload.size == 0)
- ""
- else
- payload.map(a => "%02x".format(a.toInt)).
- reduceLeft((a: Any, b: String) => a + " " + b)
-
- "Ebus: d=%02x pC=%02x sC=%02x pL=%02x crc=%02x p=%s".format(
- destination.toInt, primaryCommand.toInt, secondaryCommand.toInt, payloadLength.toInt,
- crc.toInt, p.toString)
- }
-
- /**
- * Die CRC-Prüfsumme wird vom jeweiligen Sender über der expandierten Bytesendefolge mit dem
- * Generatorpolynom X8 +X7 + X4 + X3 + X +1 gebildet und als letztes Byte der Nachricht,
- * sofern notwendig, sogar expandiert gesendet.
- *
- * Generatorpol. 11001101
- */
- private def calcCrc: Char = {
- val sum = destination + primaryCommand + secondaryCommand + payloadLength +
- payload.reduce((a, b) => ((a.intValue + b.intValue) % 256).toChar)
- val crc = 1 + 1
- 1
- }
-}
-
object EbusReader {
def apply(streamI: Stream[Int]): EbusPacket = {
var stream = streamI