Skip to content

Commit

Permalink
fixed state mask and simplified generated requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Feb 7, 2018
1 parent 5bfbcff commit 2cd0c2c
Show file tree
Hide file tree
Showing 26 changed files with 254 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ Licensed to the Apache Software Foundation (ASF) under one
package org.apache.plc4x.java.ads.api.commands;

import org.apache.plc4x.java.ads.api.commands.types.*;
import org.apache.plc4x.java.ads.api.commands.types.Length;
import org.apache.plc4x.java.ads.api.generic.ADSData;
import org.apache.plc4x.java.ads.api.generic.AMSHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.*;
import org.apache.plc4x.java.ads.api.generic.types.AMSNetId;
import org.apache.plc4x.java.ads.api.generic.types.AMSPort;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.Invoke;
import org.apache.plc4x.java.ads.api.util.ByteValue;

/**
Expand All @@ -33,6 +35,7 @@ Licensed to the Apache Software Foundation (ASF) under one
* Note: We recommend to announce not more then 550 notifications per device.
* You can increase the payload by organizing the data in structures.
*/
@ADSCommandType(Command.ADS_Add_Device_Notification)
public class ADSAddDeviceNotificationRequest extends AMSTCPPaket {

/**
Expand Down Expand Up @@ -99,16 +102,6 @@ public ADSData getAdsData() {
return buildADSData(indexGroup, indexOffset, length, transmissionMode, maxDelay, cycleTime, reserved);
}

@Override
protected Command getCommandId() {
return Command.ADS_Add_Device_Notification;
}

@Override
protected State getStateId() {
return State.ADS_REQUEST_TCP;
}

public static class Reserved extends ByteValue {

private static final Reserved INSTANCE = new Reserved();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.State;

/**
* A notification is created in an ADS device.
*/
@ADSCommandType(Command.ADS_Add_Device_Notification)
public class ADSAddDeviceNotificationResponse extends AMSTCPPaket {

/**
Expand All @@ -53,13 +53,4 @@ public ADSData getAdsData() {
return buildADSData(result, notificationHandle);
}

@Override
protected Command getCommandId() {
return Command.ADS_Add_Device_Notification;
}

@Override
protected State getStateId() {
return State.ADS_RESPONSE_TCP;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.apache.plc4x.java.ads.api.commands;

import org.apache.plc4x.java.ads.api.generic.types.Command;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Annotates a ADS command with the according command type flag.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ADSCommandType {
Command value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.plc4x.java.ads.api.generic.AMSHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.*;
import org.apache.plc4x.java.ads.api.generic.types.AMSNetId;
import org.apache.plc4x.java.ads.api.generic.types.AMSPort;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.Invoke;

/**
* One before defined notification is deleted in an ADS device.
*/
@ADSCommandType(Command.ADS_Delete_Device_Notification)
public class ADSDeleteDeviceNotificationRequest extends AMSTCPPaket {

/**
Expand Down Expand Up @@ -55,13 +59,4 @@ public ADSData getAdsData() {
return buildADSData(notificationHandle);
}

@Override
protected Command getCommandId() {
return Command.ADS_Delete_Device_Notification;
}

@Override
protected State getStateId() {
return State.ADS_REQUEST_TCP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.State;

/**
* One before defined notification is deleted in an ADS device.
*/
@ADSCommandType(Command.ADS_Delete_Device_Notification)
public class ADSDeleteDeviceNotificationResponse extends AMSTCPPaket {

/**
Expand All @@ -46,13 +46,4 @@ public ADSData getAdsData() {
return buildADSData(result);
}

@Override
protected Command getCommandId() {
return Command.ADS_Delete_Device_Notification;
}

@Override
protected State getStateId() {
return State.ADS_RESPONSE_TCP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.plc4x.java.ads.api.generic.AMSHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.*;
import org.apache.plc4x.java.ads.api.generic.types.AMSNetId;
import org.apache.plc4x.java.ads.api.generic.types.AMSPort;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.Invoke;
import org.apache.plc4x.java.ads.api.util.ByteReadable;

import java.util.List;
Expand All @@ -35,6 +38,7 @@ Licensed to the Apache Software Foundation (ASF) under one
* <p>
* The data which are transfered at the Device Notification are multiple nested into one another. The Notification Stream contains an array with elements of type AdsStampHeader. This array again contains elements of type AdsNotificationSample.
*/
@ADSCommandType(Command.ADS_Device_Notification)
public class ADSDeviceNotificationRequest extends AMSTCPPaket {

/**
Expand Down Expand Up @@ -76,13 +80,4 @@ public ADSData getAdsData() {
return buildADSData(length, stamps, buildADSData(adsStampHeaders.toArray(new ByteReadable[adsStampHeaders.size()])));
}

@Override
protected Command getCommandId() {
return Command.ADS_Device_Notification;
}

@Override
protected State getStateId() {
return State.ADS_REQUEST_TCP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.plc4x.java.ads.api.generic.ADSData;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.State;

/**
* Data will carry forward independently from an ADS device to a Client
*/
@ADSCommandType(Command.ADS_Device_Notification)
public class ADSDeviceNotificationResponse extends AMSTCPPaket {

public ADSDeviceNotificationResponse() {
Expand All @@ -38,13 +38,4 @@ public ADSData getAdsData() {
return ADSData.EMPTY;
}

@Override
protected Command getCommandId() {
return Command.ADS_Device_Notification;
}

@Override
protected State getStateId() {
return State.ADS_RESPONSE_TCP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.plc4x.java.ads.api.generic.AMSHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.*;
import org.apache.plc4x.java.ads.api.generic.types.AMSNetId;
import org.apache.plc4x.java.ads.api.generic.types.AMSPort;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.Invoke;

/**
* Reads the name and the version number of the ADS device.
* <p>
* No additional data required
*/
@ADSCommandType(Command.ADS_Read_Device_Info)
public class ADSReadDeviceInfoRequest extends AMSTCPPaket {
public ADSReadDeviceInfoRequest(AMSTCPHeader amstcpHeader, AMSHeader amsHeader) {
super(amstcpHeader, amsHeader);
Expand All @@ -47,13 +51,4 @@ public ADSData getAdsData() {
return ADSData.EMPTY;
}

@Override
protected Command getCommandId() {
return Command.ADS_Read_Device_Info;
}

@Override
protected State getStateId() {
return State.ADS_REQUEST_TCP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.State;

/**
* Reads the name and the version number of the ADS device.
*/
@ADSCommandType(Command.ADS_Read_Device_Info)
public class ADSReadDeviceInfoResponse extends AMSTCPPaket {
/**
* 4 bytes ADS error number.
Expand Down Expand Up @@ -65,13 +65,4 @@ public ADSData getAdsData() {
return buildADSData(result, majorVersion, minorVersion, version, device);
}

@Override
protected Command getCommandId() {
return Command.ADS_Read_Device_Info;
}

@Override
protected State getStateId() {
return State.ADS_RESPONSE_TCP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.plc4x.java.ads.api.generic.AMSHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.*;
import org.apache.plc4x.java.ads.api.generic.types.AMSNetId;
import org.apache.plc4x.java.ads.api.generic.types.AMSPort;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.Invoke;

/**
* With ADS Read data can be read from an ADS device. The data are addressed by the Index Group and the Index Offset
*/
@ADSCommandType(Command.ADS_Read)
public class ADSReadRequest extends AMSTCPPaket {

/**
Expand Down Expand Up @@ -73,13 +77,4 @@ public ADSData getAdsData() {
return buildADSData(indexGroup, indexOffset, length);
}

@Override
protected Command getCommandId() {
return Command.ADS_Read;
}

@Override
protected State getStateId() {
return State.ADS_REQUEST_TCP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.State;

/**
* With ADS Read data can be read from an ADS device
*/
@ADSCommandType(Command.ADS_Read)
public class ADSReadResponse extends AMSTCPPaket {

/**
Expand Down Expand Up @@ -58,13 +58,4 @@ public ADSData getAdsData() {
return buildADSData(result, length, data);
}

@Override
protected Command getCommandId() {
return Command.ADS_Read;
}

@Override
protected State getStateId() {
return State.ADS_RESPONSE_TCP;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.plc4x.java.ads.api.generic.AMSHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPHeader;
import org.apache.plc4x.java.ads.api.generic.AMSTCPPaket;
import org.apache.plc4x.java.ads.api.generic.types.*;
import org.apache.plc4x.java.ads.api.generic.types.AMSNetId;
import org.apache.plc4x.java.ads.api.generic.types.AMSPort;
import org.apache.plc4x.java.ads.api.generic.types.Command;
import org.apache.plc4x.java.ads.api.generic.types.Invoke;

/**
* Reads the ADS status and the device status of an ADS device.
* <p>
* No additional data required
*/
@ADSCommandType(Command.ADS_Read_State)
public class ADSReadStateRequest extends AMSTCPPaket {
public ADSReadStateRequest(AMSTCPHeader amstcpHeader, AMSHeader amsHeader) {
super(amstcpHeader, amsHeader);
Expand All @@ -47,13 +51,4 @@ public ADSData getAdsData() {
return ADSData.EMPTY;
}

@Override
protected Command getCommandId() {
return Command.ADS_Read_State;
}

@Override
protected State getStateId() {
return State.ADS_REQUEST_TCP;
}
}
Loading

0 comments on commit 2cd0c2c

Please sign in to comment.