diff options
author | Jakob Odersky <jakob@odersky.com> | 2016-04-18 02:02:30 -0700 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2016-04-18 02:02:30 -0700 |
commit | 1093e00d79fdf8c01bdfdea726a7696e5714b9c4 (patch) | |
tree | 9f105eaf879bf99fcbab62ba15da020602d72f18 | |
parent | 8290d53a83a0f02142753870be1b38bf740ff204 (diff) | |
download | sbt-mavlink-1093e00d79fdf8c01bdfdea726a7696e5714b9c4.tar.gz sbt-mavlink-1093e00d79fdf8c01bdfdea726a7696e5714b9c4.tar.bz2 sbt-mavlink-1093e00d79fdf8c01bdfdea726a7696e5714b9c4.zip |
Fixes to parser
- Add array length to crc seed
- Handle char types
4 files changed, 19 insertions, 7 deletions
diff --git a/mavlink-library/src/main/scala/com/github/jodersky/mavlink/Parser.scala b/mavlink-library/src/main/scala/com/github/jodersky/mavlink/Parser.scala index e6f0f07..ce645be 100644 --- a/mavlink-library/src/main/scala/com/github/jodersky/mavlink/Parser.scala +++ b/mavlink-library/src/main/scala/com/github/jodersky/mavlink/Parser.scala @@ -131,10 +131,10 @@ class Parser(reporter: Reporter) { case "uint64_t" => IntType(8, false) case "float" => FloatType(4) case "double" => FloatType(8) - case "char" => IntType(1, true) + case "char" => CharType case ArrayPattern("char", l) => StringType(l.toInt) case ArrayPattern(u, l) => ArrayType(parseType(u, node, file), l.toInt) case unknown => fatal("unknown field type " + unknown, node, file) } -}
\ No newline at end of file +} diff --git a/mavlink-library/src/main/scala/com/github/jodersky/mavlink/trees/package.scala b/mavlink-library/src/main/scala/com/github/jodersky/mavlink/trees/package.scala index f59eda6..a26be77 100644 --- a/mavlink-library/src/main/scala/com/github/jodersky/mavlink/trees/package.scala +++ b/mavlink-library/src/main/scala/com/github/jodersky/mavlink/trees/package.scala @@ -18,12 +18,18 @@ package trees { for (field <- orderedFields) { c = c.accumulate((field.nativeType + " ").getBytes) c = c.accumulate((field.name + " ").getBytes) + + field.tpe match { + case ArrayType(_, len) => c = c.accumulate(len.toByte) + case _ => + } + } (c.lsb ^ c.msb).toByte } } - trait Type extends Tree { + sealed trait Type extends Tree { def width: Int // width in bytes of the type def sizeof: Int = width // size of bytes of the type } @@ -42,4 +48,4 @@ package trees { override def sizeof = width * maxLength } -}
\ No newline at end of file +} diff --git a/mavlink-library/src/main/twirl/org/mavlink/messages/messages.scala.txt b/mavlink-library/src/main/twirl/org/mavlink/messages/messages.scala.txt index 7290d4c..731464d 100644 --- a/mavlink-library/src/main/twirl/org/mavlink/messages/messages.scala.txt +++ b/mavlink-library/src/main/twirl/org/mavlink/messages/messages.scala.txt @@ -17,7 +17,9 @@ import java.nio.charset.Charset case FloatType(4) => {Float} case FloatType(8) => {Double} case StringType(_) => {String} + case CharType => {Byte} case ArrayType(underlying, _) => {Seq[@__scalaFieldType(underlying)]} + case t => {sys.error("unsupported type: " + @t)} }} @__scalaFieldFormal(field: Field) = {@__scalaFieldName(field): @__scalaFieldType(field.tpe)} @@ -36,8 +38,10 @@ import java.nio.charset.Charset case i => i } new String(bytes, 0, length, Charset.forName("UTF-8")) - }} + }} + case CharType => {@{buffer}.get()} case ArrayType(underlying, length) => {for (i <- 0 until @length) yield {@__bufferReadMethod(buffer, underlying)}} + case t => {sys.error("unsupported type: " + @t)} }} @__bufferWriteMethod(buffer: String, data: String, tpe: Type) = {@tpe match { case IntType(1, _) => {@{buffer}.put(@data)} @@ -54,8 +58,10 @@ import java.nio.charset.Charset while (@{buffer}.position < endPosition) { @{buffer}.put(0: Byte) } - }} + }} + case CharType => {@{buffer}.put(@data)} case ArrayType(underlying, length) => {for (i <- 0 until @length) {@__bufferWriteMethod(buffer, data + "(i)", underlying)}} + case t => {sys.error("unsupported type: " + @t)} }} @__commentParagraphs(paragraphs: Seq[String]) = {@paragraphs.mkString("/**\n * ", "\n * ", "\n */")} diff --git a/project/Build.scala b/project/Build.scala index e522654..3e15ecc 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -11,7 +11,7 @@ object ApplicationBuild extends Build { scalaVersion := "2.10.6", scalacOptions ++= Seq("-feature", "-deprecation"), organization := "com.github.jodersky", - version := "0.6.0", + version := "0.7.0-SNAPSHOT", licenses := Seq(("LGPL", url("http://opensource.org/licenses/LGPL-3.0"))) ) |