Newer
Older
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* @author ETSI / STF462 / Alexandre Berge
* @version $URL: $
* $Id: $
*/
package org.etsi.ttcn.codec.its.uppertester;
import org.etsi.ttcn.codec.CodecBuffer;
import org.etsi.ttcn.codec.IMarkerCallback;
import org.etsi.ttcn.codec.MainCodec;
import org.etsi.ttcn.tci.RecordValue;
import org.etsi.ttcn.tci.Type;
import org.etsi.ttcn.tci.Value;
import java.util.HashMap;
import java.util.Map;
public class UtDenmTrigger extends UtRecord implements IMarkerCallback {
private byte flags = 0x00;
public UtDenmTrigger(MainCodec mainCodec) {
super(mainCodec);
}
@Override
public Value decode(CodecBuffer buf, Type decodingHypothesis) {
setLengths();
return super.decode(buf, decodingHypothesis);
}
@Override
public CodecBuffer preEncode(Value value) {
setLengths();
CodecBuffer buf = super.preEncode(value);
CodecBuffer bufFlags = new CodecBuffer();
bufFlags.setMarker("flags", 0, this);
buf.append(bufFlags);
return buf;
}
private void setLengths() {
mainCodec.setHint("TimestampItsLen", "48");
mainCodec.setHint("ValidityDurationLen", "24");
mainCodec.setHint("InformationQualityLen", "8");
mainCodec.setHint("CauseCodeTypeLen", "8");
mainCodec.setHint("SubCauseCodeTypeLen", "8");
mainCodec.setHint("RelevanceDistanceLen", "8");
mainCodec.setHint("RelevanceTrafficDirectionLen", "8");
mainCodec.setHint("TransmissionIntervalLen", "16");
mainCodec.setHint("StationIDLen", "32");
mainCodec.setHint("SequenceNumberLen", "16");
mainCodec.setHint("integerLen", "8");
}
@Override
public CodecBuffer encode(Value value) {
RecordValue rv = (RecordValue)value;
String[] fields = rv.getFieldNames();
CodecBuffer buf = new CodecBuffer();
for(int i=0; i < fields.length; i++) {
Value fieldValue = rv.getField(fields[i]);
if(!fieldValue.notPresent()) {
CodecBuffer fieldBuf = mainCodec.encode(fieldValue);
postEncodeField(fields[i], fieldBuf);
buf.append(fieldBuf);
flags = (byte) (flags | (PresenceFlag.value(fields[i])).byteValue());
}
else {
String hint = mainCodec.getHint(fieldValue.getType().getName() + "Len");
if(hint != null) {
int lengthInBits = java.lang.Integer.parseInt(hint);
int lengthInBytes = lengthInBits / 8 + (((lengthInBits % 8) > 0)?1:0);
for(int j=0; j < lengthInBytes; j++) {
buf.appendBytes(new byte[]{0x00});
}
}
}
}
return buf;
}
@Override
public void run(String markerName, CodecBuffer leftBuf, CodecBuffer rightBuf) {
CodecBuffer bufFlags = new CodecBuffer(new byte[] {flags});
bufFlags.append(rightBuf);
rightBuf.setBytes(bufFlags.getBytes());
}
private enum PresenceFlag {
/* DenmTrigger*/
validityDuration(0x80),
repetitionDuration(0x40),
transmissionInterval(0x04),
repetitionInterval(0x02),
/* DenmUpdate */
//validityDuration(0x80),
situation(0x40),
relevanceDistance(0x20),
relevanceTrafficDirection(0x10),
trafficClass(0x08),
//transmissionInterval(0x04),
//repetitionInterval(0x02),
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* Reserved */
reserved(0x00);
private byte value;
private static final Map<String, Byte> PresenceFlags = new HashMap<String, Byte>();
private PresenceFlag(int value) {
this.value = (byte)value;
}
public static Byte value(String name) {
Byte res = PresenceFlags.get(name);
if(res == null) {
return value("reserved");
}
return res;
}
static {
for (PresenceFlag item : PresenceFlag.values()) {
PresenceFlags.put(item.name(), new Byte(item.value));
}
}
}
}