use of org.apache.plc4x.java.canopen.readwrite.CANOpenPayload in project plc4x by apache.
the class CANOpenFrameDataHandler method toCAN.
@Override
public Message toCAN(CANOpenFrame frame) {
try {
CANOpenPayload payload = frame.getPayload();
WriteBufferByteBased buffer = new WriteBufferByteBased(payload.getLengthInBytes(), ByteOrder.LITTLE_ENDIAN);
payload.serialize(buffer);
return builder.get().withId(frame.getService().getMin() + frame.getNodeId()).withData(buffer.getData()).create();
} catch (SerializationException e) {
throw new PlcRuntimeException(e);
}
}
use of org.apache.plc4x.java.canopen.readwrite.CANOpenPayload in project plc4x by apache.
the class CANOpenProtocolLogic method decode.
@Override
public void decode(ConversationContext<CANOpenFrame> context, CANOpenFrame msg) throws Exception {
int nodeId = msg.getNodeId();
CANOpenService service = msg.getService();
CANOpenPayload payload = msg.getPayload();
if (service != null && nodeId != this.configuration.getNodeId()) {
if (service.getPdo() && payload instanceof CANOpenPDOPayload) {
publishEvent(service, nodeId, payload);
} else if (service == CANOpenService.HEARTBEAT && payload instanceof CANOpenHeartbeatPayload) {
publishEvent(service, nodeId, payload);
} else {
logger.debug("Decoded CANOpen {} from {}, message {}", service, nodeId, payload);
}
}
// int identifier = msg.getIdentifier();
// CANOpenService service = CANOpenService.valueOf((byte) (identifier >> 7));
// if (service != null) {
// ReadBuffer buffer = new ReadBuffer(msg.getData());
// CANOpenPayload payload = CANOpenPayloadIO.staticParse(buffer, service);
//
//
// }
}
Aggregations