package com.zy.acs.conveyor.core.constant;
|
|
|
/**
|
* 任务下发字段枚举(对应 §2.4)
|
*/
|
public enum TaskField {
|
TASK_NUMBER("DB13", 0, 4),
|
START_STATION("DB13", 4, 2),
|
DEST_STATION("DB13", 6, 2),
|
DIRECTION("DB13", 8, 1),
|
ROUTE_NUMBER("DB13", 10, 2);
|
|
private final String addressPattern;
|
private final int offset;
|
private final int byteLength;
|
|
TaskField(String addressPattern, int offset, int byteLength) {
|
this.addressPattern = addressPattern;
|
this.offset = offset;
|
this.byteLength = byteLength;
|
}
|
|
public String getAddressPattern() {
|
return addressPattern;
|
}
|
|
public int getOffset() {
|
return offset;
|
}
|
|
public int getByteLength() {
|
return byteLength;
|
}
|
|
/**
|
* 根据 DB 块编号和站点偏移生成具体地址
|
*
|
* @param dbBlock DB块编号
|
* @param stationBaseOffset 站点基址偏移(站点号*站点长度)
|
* @return PLC4X 地址字符串,如 "DB100.DBD0"
|
*/
|
public String buildAddress(int dbBlock, int stationBaseOffset) {
|
int finalOffset = stationBaseOffset + offset;
|
return String.format(addressPattern, dbBlock, finalOffset);
|
}
|
}
|