1
zhang
2 天以前 4ab8c2aa4996e2d16fe0a214e2a41a4c77378d35
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.zy.acs.conveyor.core.constant;
 
 
/**
 * 任务下发字段枚举(对应 §2.4)
 */
public enum TaskField {
    ALL("DB13", 0, 12),
    TASK_NUMBER("DB13", 0, 4),
    START_STATION("DB13", 4, 2),
    DEST_STATION("DB13", 6, 2),
    DIRECTION("DB13", 8, 2),
    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);
    }
}