Search in sources :

Example 1 with CANOpenPayload

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);
    }
}
Also used : PlcRuntimeException(org.apache.plc4x.java.api.exceptions.PlcRuntimeException) SerializationException(org.apache.plc4x.java.spi.generation.SerializationException) CANOpenPayload(org.apache.plc4x.java.canopen.readwrite.CANOpenPayload) WriteBufferByteBased(org.apache.plc4x.java.spi.generation.WriteBufferByteBased)

Example 2 with CANOpenPayload

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);
// 
// 
// }
}
Also used : CANOpenPDOPayload(org.apache.plc4x.java.canopen.readwrite.CANOpenPDOPayload) CANOpenHeartbeatPayload(org.apache.plc4x.java.canopen.readwrite.CANOpenHeartbeatPayload) CANOpenService(org.apache.plc4x.java.canopen.readwrite.CANOpenService) CANOpenPayload(org.apache.plc4x.java.canopen.readwrite.CANOpenPayload)

Aggregations

CANOpenPayload (org.apache.plc4x.java.canopen.readwrite.CANOpenPayload)2 PlcRuntimeException (org.apache.plc4x.java.api.exceptions.PlcRuntimeException)1 CANOpenHeartbeatPayload (org.apache.plc4x.java.canopen.readwrite.CANOpenHeartbeatPayload)1 CANOpenPDOPayload (org.apache.plc4x.java.canopen.readwrite.CANOpenPDOPayload)1 CANOpenService (org.apache.plc4x.java.canopen.readwrite.CANOpenService)1 SerializationException (org.apache.plc4x.java.spi.generation.SerializationException)1 WriteBufferByteBased (org.apache.plc4x.java.spi.generation.WriteBufferByteBased)1