diff options
4 files changed, 18 insertions, 12 deletions
diff --git a/mavlink-library/src/main/twirl/org/mavlink/Parser.scala.txt b/mavlink-library/src/main/twirl/org/mavlink/Parser.scala.txt index 48af210..97068e6 100644 --- a/mavlink-library/src/main/twirl/org/mavlink/Parser.scala.txt +++ b/mavlink-library/src/main/twirl/org/mavlink/Parser.scala.txt @@ -101,10 +101,10 @@ class Parser(receiver: Packet => Unit, error: Parser.Errors.Error => Unit = _ => inbound.payload += c inbound.currentLength += 1 inbound.crc = inbound.crc.accumulate(c) - if(inbound.currentLength >= Packet.MaxPayloadLength) { + if(inbound.currentLength > Packet.MaxPayloadLength) { state = Idle error(Errors.OverflowError) - } else if (inbound.currentLength>= inbound.length) { + } else if (inbound.currentLength >= inbound.length) { state = GotPayload } 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 e973547..939c1d1 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 @@ -28,7 +28,7 @@ import java.nio.charset.Charset case FloatType(4) => {@{buffer}.getFloat()} case FloatType(8) => {@{buffer}.getDouble()} case StringType(maxLength) =>{{ - val bytes = Array[Byte](@maxLength) + val bytes = new Array[Byte](@maxLength) @{buffer}.get(bytes, 0, @maxLength) val length = bytes.indexOf(0) match { case -1 => @maxLength @@ -49,7 +49,7 @@ import java.nio.charset.Charset { val bytes = @{data}.getBytes(Charset.forName("UTF-8")) val endPosition = @{buffer}.position + @maxLength - @{buffer}.put(bytes, 0, math.max(bytes.length, @maxLength)) + @{buffer}.put(bytes, 0, math.min(bytes.length, @maxLength)) while (@{buffer}.position < endPosition) { @{buffer}.put(0: Byte) } diff --git a/mavlink-plugin/src/sbt-test/sbt-mavlink/codec/mavlink.xml b/mavlink-plugin/src/sbt-test/sbt-mavlink/codec/mavlink.xml index fcbdc35..7bdcbc2 100644 --- a/mavlink-plugin/src/sbt-test/sbt-mavlink/codec/mavlink.xml +++ b/mavlink-plugin/src/sbt-test/sbt-mavlink/codec/mavlink.xml @@ -103,13 +103,13 @@ <field type="uint16_t" name="rxerrors">receive errors</field> <field type="uint16_t" name="fixed">count of error corrected packets</field> </message> - <message name="TEST_MESSAGE" id="110"> + <message name="TEST_MESSAGE" id="254"> <description>Test</description> - <field type="uint8_t[2]" name="bytearray">a byte array</field> - <field type="float[20]" name="floatarray">a float array</field> - <field type="char" name="chars">a char</field> - <field type="double" name="doubles">a double</field> - <field type="char[20]" name="strings">a string</field> + <field type="uint16_t[2]" name="test_short_array">a byte array</field> + <field type="float[20]" name="test_float_array">a float array</field> + <field type="uint8_t" name="test_byte">a byte</field> + <field type="double" name="test_double">a double</field> + <field type="char[20]" name="test_string">a string</field> </message> </messages> </mavlink> diff --git a/mavlink-plugin/src/sbt-test/sbt-mavlink/codec/src/main/scala/Main.scala b/mavlink-plugin/src/sbt-test/sbt-mavlink/codec/src/main/scala/Main.scala index b7772a7..3a93fae 100644 --- a/mavlink-plugin/src/sbt-test/sbt-mavlink/codec/src/main/scala/Main.scala +++ b/mavlink-plugin/src/sbt-test/sbt-mavlink/codec/src/main/scala/Main.scala @@ -30,7 +30,13 @@ object Main { val assembler = new Assembler(SenderSystemId, SenderComponentId) //create an explicit message - val message = Heartbeat(0) + val message = TestMessage( + Array[Short](1,2), + Array.fill[Float](20)(0.2f), + 3: Byte, + 42.0, + "hello world" + ) //pack the message into a payload val (id: Byte, payload: Array[Byte]) = Message.pack(message) @@ -42,5 +48,5 @@ object Main { val data = packet.toArray parser.push(data) } - + }
\ No newline at end of file |