Search in sources :

Example 1 with CANOpenService

use of org.apache.plc4x.java.canopen.readwrite.CANOpenService in project plc4x by apache.

the class CANOpenFrameDataHandler method fromCAN.

@Override
public CANOpenFrame fromCAN(FrameData frame) {
    CANOpenService service = StaticHelper.serviceId((short) frame.getNodeId());
    int nodeId = Math.abs(service.getMin() - frame.getNodeId());
    return new CANOpenFrame((short) nodeId, service, frame.read(CANOpenPayload::staticParse, service));
}
Also used : CANOpenService(org.apache.plc4x.java.canopen.readwrite.CANOpenService) CANOpenFrame(org.apache.plc4x.java.canopen.readwrite.CANOpenFrame)

Example 2 with CANOpenService

use of org.apache.plc4x.java.canopen.readwrite.CANOpenService 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)

Example 3 with CANOpenService

use of org.apache.plc4x.java.canopen.readwrite.CANOpenService in project plc4x by apache.

the class CANOpenPDOField method of.

public static CANOpenPDOField of(String addressString) {
    Matcher matcher = getMatcher(addressString);
    int nodeId = Integer.parseInt(matcher.group("nodeId"));
    String pdo = matcher.group("pdo");
    CANOpenService service = CANOpenService.valueOf(pdo);
    String canDataTypeString = matcher.group("canDataType");
    CANOpenDataType canOpenDataType = CANOpenDataType.valueOf(canDataTypeString);
    return new CANOpenPDOField(nodeId, service, canOpenDataType);
}
Also used : Matcher(java.util.regex.Matcher) CANOpenService(org.apache.plc4x.java.canopen.readwrite.CANOpenService) CANOpenDataType(org.apache.plc4x.java.canopen.readwrite.CANOpenDataType)

Aggregations

CANOpenService (org.apache.plc4x.java.canopen.readwrite.CANOpenService)3 Matcher (java.util.regex.Matcher)1 CANOpenDataType (org.apache.plc4x.java.canopen.readwrite.CANOpenDataType)1 CANOpenFrame (org.apache.plc4x.java.canopen.readwrite.CANOpenFrame)1 CANOpenHeartbeatPayload (org.apache.plc4x.java.canopen.readwrite.CANOpenHeartbeatPayload)1 CANOpenPDOPayload (org.apache.plc4x.java.canopen.readwrite.CANOpenPDOPayload)1 CANOpenPayload (org.apache.plc4x.java.canopen.readwrite.CANOpenPayload)1