protected byte[] processStringGetRequest(BidibCommand bidibMessage) { byte[] response = null; try { StringGetMessage stringGetMessage = (StringGetMessage) bidibMessage; int stringId = stringGetMessage.getStringId(); LOGGER.info("Get STRING[{}]: {}", stringId, stringValue[stringId]); StringResponse stringResponse = new StringResponse(bidibMessage.getAddr(), getNextSendNum(), ByteUtils.getLowByte(stringGetMessage.getNamespace()), ByteUtils.getLowByte(stringGetMessage.getStringId()), stringValue[stringId]); response = stringResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create string response failed.", ex); } return response; }
/** * Get a string value from the node. * * @param namespace * the namespace * @param index * the index * @return the string data instance * @throws ProtocolException */ public StringData getString(int namespace, int index) throws ProtocolException { BidibMessage response = send(new StringGetMessage(namespace, index), null, true, StringResponse.TYPE); if (response instanceof StringResponse) { return ((StringResponse) response).getStringData(); } return null; }
break; case BidibLibrary.MSG_STRING: result = new StringResponse(result.getAddr(), result.getNum(), result.getType(), result.getData()); break; default:
public StringData getStringData() { StringData stringData = new StringData(); byte[] data = getData(); stringData.setNamespace(ByteUtils.getInt(data[0])); stringData.setIndex(ByteUtils.getInt(data[1])); stringData.setValue(ByteUtils.cstr(data, 2)); return stringData; } }
protected byte[] processStringSetRequest(BidibCommand bidibMessage) { byte[] response = null; try { StringSetMessage stringSetMessage = (StringSetMessage) bidibMessage; int stringId = stringSetMessage.getStringId(); stringValue[stringId] = stringSetMessage.getString(); StringResponse stringResponse = new StringResponse(bidibMessage.getAddr(), getNextSendNum(), ByteUtils.getLowByte(stringSetMessage.getNamespace()), ByteUtils.getLowByte(stringSetMessage.getStringId()), stringValue[stringId]); response = stringResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create string response failed.", ex); } return response; }
/** * Set a string value in the node. * * @param namespace * the namespace * @param index * the index * @return the string data instance * @throws ProtocolException */ public StringData setString(int namespace, int index, String value) throws ProtocolException { BidibMessage response = send(new StringSetMessage(namespace, index, value), null, true, StringResponse.TYPE); if (response instanceof StringResponse) { return ((StringResponse) response).getStringData(); } return null; }