Last active
December 22, 2018 07:11
-
-
Save VanitySoft/92ab23556eeacd03a41c60a5c28623aa to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package com.vanitysoft.morgua; | |
import java.io.ByteArrayInputStream; | |
import java.io.DataInputStream; | |
import java.io.IOException; | |
import org.apache.commons.codec.DecoderException; | |
import org.apache.commons.codec.binary.Hex; | |
import org.apache.commons.lang3.StringUtils; | |
import org.himalay.cayenne.LPPDataFactory; | |
import org.himalay.msgs.runtime.IntegerHolder; | |
public class MorguaApp { | |
/* | |
Device with 2 temperature sensors | |
Payload (Hex) 03 67 01 10 05 67 00 FF | |
Data Channel | Type | Value | |
03 ⇒ 3 | 67 ⇒ Temperature | 0110 = 272 ⇒ 27.2°C | |
(MISSING) 05 ⇒ 5 | 67 ⇒ Temperature | 00FF = 255 ⇒ 25.5°C | |
*/ | |
public static void main(String[] args) throws IOException, DecoderException{ | |
String hexString = StringUtils.deleteWhitespace("03 67 01 10 05 67 00 FF"); | |
byte[] bytes = Hex.decodeHex(hexString.toCharArray()); | |
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bytes)); | |
LPPDataFactory.LPPData data = LPPDataFactory.createMsg(dis, new IntegerHolder()); | |
data.dump(); | |
//Output | |
/* | |
* Temperature_ | |
header | |
LPPHeader | |
dataChannel=3(0x3) | |
messageType=103(0x67) | |
_value=272(0x110) | |
*/ | |
//but , where is second data chanel/data? | |
// Acceleration | |
String hexString2 = StringUtils.deleteWhitespace("06 71 04 D2 FB 2E 00 00"); | |
byte[] bytes2 = Hex.decodeHex(hexString2.toCharArray()); | |
DataInputStream dis2 = new DataInputStream(new ByteArrayInputStream(bytes2)); | |
data = LPPDataFactory.createMsg(dis2, new IntegerHolder()); | |
data.dump(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to check if there is more to read from InputStream.