本文整理了Java中com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacketStream
类的一些代码示例,展示了ZToolPacketStream
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZToolPacketStream
类的具体详情如下:
包路径:com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacketStream
类名称:ZToolPacketStream
[英]Reads a packet from the input stream, verifies checksum and creates an XBeeResponse object
[中]从输入流读取数据包,验证校验和,并创建XBeerResponse对象
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
/**
* Returns number of bytes remaining, relative to the stated packet length (not including checksum).
*
* @return number of bytes remaining to be read excluding checksum
*/
public int getFrameDataBytesRead() {
// subtract out the 1 length bytes and API PROFILE_ID_HOME_AUTOMATION 2 bytes
return this.getBytesRead() - 3;
}
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
private int[] readRemainingBytes() throws IOException {
int[] value = new int[length - this.getFrameDataBytesRead()];
for (int i = 0; i < value.length; i++) {
value[i] = this.read("Remaining bytes " + (value.length - i));
// log.debug("byte " + i + " is " + value[i]);
}
return value;
}
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
if (val == ZToolPacket.START_BYTE) {
final ZToolPacketStream packetStream = new ZToolPacketStream(port);
final ZToolPacket response = packetStream.parsePacket();
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
final ZToolPacket response;
this.length = read("Length");
final int apiIdMSB = this.read("API PROFILE_ID_HOME_AUTOMATION MSB");
final int apiIdLSB = this.read("API PROFILE_ID_HOME_AUTOMATION LSB");
final DoubleByte apiId = new DoubleByte(apiIdMSB, apiIdLSB);
frameData[i] = this.read("Data " + i + "-th");
i++;
frameData = this.readRemainingBytes();
response = parsePayload(apiId, frameData);
int fcs = this.read("Checksum");
if (!this.isDone()) {
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
/**
* Number of bytes remaining to be read, including the checksum
*
* @return number of bytes remaining to be read including checksum
*/
public int getRemainingBytes() {
// add one for checksum byte (not included) in packet length
return length - this.getFrameDataBytesRead() + 1;
}
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
@Override
public int read(final String context) throws IOException {
int b = read();
logger.trace("Read {} byte, val is {}", context, ByteUtils.formatByte(b));
return b;
}
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
protected ZToolPacket getPacket(String stringData) {
int[] packet = getPacketData(stringData);
byte[] byteArray = new byte[packet.length - 1];
for (int c = 1; c < packet.length; c++) {
byteArray[c - 1] = (byte) packet[c];
}
ByteArrayInputStream stream = new ByteArrayInputStream(byteArray);
ZigBeePort port = new TestPort(stream, null);
try {
ZToolPacket ztoolPacket = new ZToolPacketStream(port).parsePacket();
assertFalse(ztoolPacket.isError());
return ztoolPacket;
} catch (IOException e) {
return null;
}
}
代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee
/**
* TODO implement as class that extends inputstream?
* <p/>
* This method reads bytes from the underlying input stream and performs the following tasks: keeps track of how
* many bytes we've read, un-escapes bytes if necessary and verifies the checksum.
*/
@Override
public int read() throws IOException {
int b = port.read();
if (b == -1) {
throw new ZToolParseException("Read -1 from input stream while reading packet!");
}
bytesRead++;
// when verifying checksum you must add the checksum that we are verifying
// when computing checksum, do not include start byte; when verifying, include checksum
checksum.addByte(b);
// log.debug("Read byte " + ByteUtils.formatByte(b) + " at position " + bytesRead + ", data length is " +
// this.length.getLength() + ", #escapeBytes is " + escapeBytes + ", remaining bytes is " +
// this.getRemainingBytes());
if (this.getFrameDataBytesRead() >= (length + 1)) {
// this is checksum and final byte of packet
done = true;
// log.debug("Checksum byte is " + b);
/*
* if (!checksum.verify()) {/////////////Maybe expected in ZTool is 0x00, not FF//////////////////// throw
* new ZToolParseException("Checksum is incorrect. Expected 0xff, but got " + checksum.getChecksum()); }
*/
}
return b;
}
内容来源于网络,如有侵权,请联系作者删除!