本文整理汇总了Java中com.rapplogic.xbee.util.ByteUtils类的典型用法代码示例。如果您正苦于以下问题:Java ByteUtils类的具体用法?Java ByteUtils怎么用?Java ByteUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteUtils类属于com.rapplogic.xbee.util包,在下文中一共展示了ByteUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ZNetApiAtExample
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public ZNetApiAtExample() throws XBeeException {
try {
// replace with port and baud rate of your XBee
xbee.open("COM6", 9600);
// get the 8 byte SH/SL address
log.debug("SH is " + ByteUtils.toBase16(((AtCommandResponse)xbee.sendAtCommand(new AtCommand("SH"))).getValue()));
log.debug("SL is " + ByteUtils.toBase16(((AtCommandResponse)xbee.sendAtCommand(new AtCommand("SL"))).getValue()));
// uncomment to run
// this.configureIOSamples(xbee);
// this.associationStatus(xbee);
// this.nodeDiscover(xbee);
// this.configureCoordinator(xbee);
// this.configureEndDevice(xbee);
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例2: sendPacket
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
/**
* This exists solely for the XMPP project. Use sendRequest instead
*
* Not Thread Safe
*
* @param packet
* @throws RuntimeException when serial device is disconnected
*/
public void sendPacket(int[] packet) throws IOException {
// TODO should we synchronize on read lock so we are sending/recv. simultaneously?
// TODO call request listener with byte array
if (!this.isConnected()) {
throw new XBeeNotConnectedException();
}
if (log.isInfoEnabled()) {
log.info("Sending packet to XBee " + ByteUtils.toBase16(packet));
}
for (int packetByte : packet) {
// if connection lost
//Caused by: com.rapplogic.xbee.api.XBeeException
//Caused by: java.io.IOException: Input/output error in writeArray
xbeeConnection.getOutputStream().write(packetByte);
}
xbeeConnection.getOutputStream().flush();
}
示例3: main
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public static void main(String[] args) {
//83 56 78 24 00 01 02 00 03 ff 85
Checksum ck = new Checksum();
ck.addByte(0x83);
ck.addByte(0x56);
ck.addByte(0x78);
ck.addByte(0x26);
ck.addByte(0x00);
ck.addByte(0x01);
ck.addByte(0x02);
ck.addByte(0x00);
ck.addByte(0x03);
ck.addByte(0xff);
// checksum
ck.addByte(0x83);
// checksum is 0x83
//ck.compute();
ck.verify();
System.out.println("checksum is " + ByteUtils.formatByte(ck.getChecksum()));
}
示例4: ZNetApiAtExample
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public ZNetApiAtExample() throws XBeeException {
try {
// replace with port and baud rate of your XBee
xbee.open("COM6", 9600);
// get the 8 byte SH/SL address
log.debug("SH is " + ByteUtils.toBase16(((AtCommandResponse)xbee.sendAtCommand(new AtCommand("SH"))).getValue()));
log.debug("SL is " + ByteUtils.toBase16(((AtCommandResponse)xbee.sendAtCommand(new AtCommand("SL"))).getValue()));
// uncomment to run
// this.configureIOSamples(xbee);
// this.associationStatus(xbee);
// this.nodeDiscover(xbee);
// this.configureCoordinator(xbee);
// this.configureEndDevice(xbee);
} finally {
xbee.close();
}
}
示例5: BroadcastSenderExample
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
private BroadcastSenderExample() throws XBeeException {
XBee xbee = new XBee();
try {
// replace with your com port and baud rate. this is the com port of my coordinator
xbee.open("/dev/ttyUSB0", 9600);
while (true) {
// put some arbitrary data in the payload
int[] payload = ByteUtils.stringToIntArray("the\nquick\nbrown\nfox");
ZNetTxRequest request = new ZNetTxRequest(XBeeAddress64.BROADCAST, payload);
// make it a broadcast packet
request.setOption(ZNetTxRequest.Option.BROADCAST);
log.info("request packet bytes (base 16) " + ByteUtils.toBase16(request.getXBeePacket().getPacket()));
xbee.sendAsynchronous(request);
// we just assume it was sent. that's just the way it is with broadcast.
// no transmit status response is sent, so don't bother calling getResponse()
try {
// wait a bit then send another packet
Thread.sleep(15000);
} catch (InterruptedException e) {
}
}
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例6: ZBNodeDiscoverExample
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public ZBNodeDiscoverExample() throws XBeeException, InterruptedException {
try {
// replace with your serial port
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
// get the Node discovery timeout
xbee.sendAsynchronous(new AtCommand("NT"));
AtCommandResponse nodeTimeout = (AtCommandResponse) xbee.getResponse();
// default is 6 seconds
int nodeDiscoveryTimeout = ByteUtils.convertMultiByteToInt(nodeTimeout.getValue()) * 100;
log.info("Node discovery timeout is " + nodeDiscoveryTimeout + " milliseconds");
log.info("Sending Node Discover command");
xbee.sendAsynchronous(new AtCommand("ND"));
// NOTE: increase NT if you are not seeing all your nodes reported
List<? extends XBeeResponse> responses = xbee.collectResponses(nodeDiscoveryTimeout);
log.info("Time is up! You should have heard back from all nodes by now. If not make sure all nodes are associated and/or try increasing the node timeout (NT)");
for (XBeeResponse response : responses) {
if (response instanceof AtCommandResponse) {
AtCommandResponse atResponse = (AtCommandResponse) response;
if (atResponse.getCommand().equals("ND") && atResponse.getValue() != null && atResponse.getValue().length > 0) {
ZBNodeDiscover nd = ZBNodeDiscover.parse((AtCommandResponse)response);
log.info("Node Discover is " + nd);
}
}
}
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例7: isDigitalEnabled
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public boolean isDigitalEnabled(int pin) {
if (pin >=0 && pin <= 7) {
return ByteUtils.getBit(this.digitalChannelMaskLsb, pin + 1);
} else if (pin >=10 && pin <= 12) {
return ByteUtils.getBit(this.digitalChannelMaskMsb, pin - 7);
} else {
throw new IllegalArgumentException("Unsupported pin: " + pin);
}
}
示例8: isAnalogEnabled
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public boolean isAnalogEnabled(int pin) {
if (pin >=0 && pin <= 3) {
return ByteUtils.getBit(this.analogChannelMask, pin + 1);
} else {
throw new IllegalArgumentException("Unsupported pin: " + pin);
}
}
示例9: isDigitalOn
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
/**
* If digital I/O line (DIO0) is enabled: returns true if digital 0 is HIGH (ON); false if it is LOW (OFF).
* If digital I/O line is not enabled this method returns null as it has no value.
* <p/>
* Important: the pin number corresponds to the logical pin (e.g. D4), not the physical pin number.
* <p/>
* Digital I/O pins seem to report high when open circuit (unconnected)
*
* @return
*/
public Boolean isDigitalOn(int pin) {
if (this.isDigitalEnabled(pin)) {
if (pin >=0 && pin <= 7) {
return ByteUtils.getBit(dioLsb, pin + 1);
} else if (pin >=10 && pin <= 12) {
return ByteUtils.getBit(dioMsb, pin - 7);
}
}
return null;
}
示例10: toString
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public String toString() {
return super.toString() +
",sourceEndpoint=" + ByteUtils.toBase16(this.getSourceEndpoint()) +
",destinationEndpoint=" + ByteUtils.toBase16(this.getDestinationEndpoint()) +
",clusterId(msb)=" + ByteUtils.toBase16(this.getClusterId().getMsb()) +
",clusterId(lsb)=" + ByteUtils.toBase16(this.getClusterId().getLsb()) +
",profileId(msb)=" + ByteUtils.toBase16(this.getProfileId().getMsb()) +
",profileId(lsb)=" + ByteUtils.toBase16(this.getProfileId().getLsb());
}
示例11: toString
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public String toString() {
return "nodeAddress16=" + this.nodeAddress16 +
", nodeAddress64=" + this.nodeAddress64 +
", nodeIdentifier=" + this.nodeIdentifier +
", parentAddress=" + this.getParent() +
", deviceType=" + this.deviceType +
", status=" + this.status +
", profileId=" + ByteUtils.toBase16(this.profileId) +
", mfgId=" + ByteUtils.toBase16(this.mfgId);
}
示例12: toString
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public String toString() {
return super.toString() +
",destAddr64=" + this.destAddr64 +
",destAddr16=" + this.destAddr16 +
",broadcastRadius=" + this.broadcastRadius +
",option=" + this.option +
",payload=" + ByteUtils.toBase16(this.payload);
}
示例13: toString
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public String toString() {
// 8/19/09 fixed null pointer on length.get16BitValue
return "apiId=" + this.apiId +
",length=" + (length == null ? "null" : length.get16BitValue()) +
",checksum=" + ByteUtils.toBase16(checksum) +
",error=" + this.error;
}
示例14: toString
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
public String toString() {
return "command=" + this.getCommand() +
",status=" + this.getStatus() + ",value=" +
(this.value == null ? "null" : ByteUtils.toBase16(this.getValue())) +
"," +
super.toString();
}
示例15: isDigitalOn
import com.rapplogic.xbee.util.ByteUtils; //导入依赖的package包/类
/**
* Returns the digital value of the specified pin.
* Returns null if pin is not configured for Digital input
*
* @return
*/
public Boolean isDigitalOn(int pin) {
if (!parent.isDigitalEnabled(pin)) {
return null;
}
if (pin >= 0 && pin <= 7) {
return ByteUtils.getBit(dioLsb, pin + 1);
} else {
// pin 8
return ByteUtils.getBit(dioMsb, 1);
}
}