Skip to content

Commit 90a8661

Browse files
committed
Finalising commsdsl2wireshark implementation.
1 parent 09c51a8 commit 90a8661

15 files changed

Lines changed: 375 additions & 42 deletions

File tree

app/commsdsl2comms/test/test6/Schema.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
<validValue name="M2" val="2" />
77
<validValue name="M3" val="3" />
88
<validValue name="M4" val="4" />
9+
<validValue name="M5" val="5" />
10+
<validValue name="M6" val="6" />
11+
<validValue name="M7" val="7" />
12+
<validValue name="M8" val="8" />
913
</enum>
1014

1115
<enum name="E1" type="uint16" nonUniqueAllowed="true" validCheckVersion="true" >
@@ -116,6 +120,58 @@
116120
</enum>
117121
</message>
118122

123+
<message name="Msg5" id="MsgId.M5">
124+
<int name="F1" type="intvar" length="3" />
125+
<int name="F2" type="intvar" endian="big" length="3" />
126+
</message>
127+
128+
<message name="Msg6" id="MsgId.M6">
129+
<int name="F1" type="intvar" />
130+
<int name="F2" type="intvar" endian="big" />
131+
<int name="F3" type="uintvar" />
132+
<int name="F4" type="uintvar" endian="big" />
133+
</message>
134+
135+
<message name="Msg7" id="MsgId.M7">
136+
<enum name="F1" type="uintvar" length="3">
137+
<validValue name="V1" val="128" />
138+
<validValue name="V2" val="0x7fff" />
139+
<validValue name="V3" val="0x1fffff" />
140+
</enum>
141+
<enum name="F2" type="intvar" length="3">
142+
<validValue name="V1" val="-128" />
143+
<validValue name="V2" val="0x7fff" />
144+
</enum>
145+
<enum name="F3" type="uintvar">
146+
<validValue name="V1" val="0xffff" />
147+
<validValue name="V2" val="0xfffffffff" />
148+
</enum>
149+
<enum name="F4" type="intvar">
150+
<validValue name="V1" val="-512" />
151+
<validValue name="V2" val="-2048" />
152+
</enum>
153+
</message>
154+
155+
<message name="Msg8" id="MsgId.M8">
156+
<enum name="F1" type="uintvar" length="3" endian="big">
157+
<validValue name="V1" val="128" />
158+
<validValue name="V2" val="0x7fff" />
159+
<validValue name="V3" val="0x1fffff" />
160+
</enum>
161+
<enum name="F2" type="intvar" length="3" endian="big">
162+
<validValue name="V1" val="-128" />
163+
<validValue name="V2" val="0x7fff" />
164+
</enum>
165+
<enum name="F3" type="uintvar" endian="big">
166+
<validValue name="V1" val="0xffff" />
167+
<validValue name="V2" val="0xfffffffff" />
168+
</enum>
169+
<enum name="F4" type="intvar" endian="big">
170+
<validValue name="V1" val="-512" />
171+
<validValue name="V2" val="-2048" />
172+
</enum>
173+
</message>
174+
119175
<frame name="Frame">
120176
<id name="ID" field="MsgId" />
121177
<payload name="Data" />

app/commsdsl2comms/test/test6/test6Test.th

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public:
1313
void test1();
1414
void test2();
1515
void test3();
16+
void test4();
1617

1718
using Interface =
1819
test6::Message<
@@ -87,3 +88,25 @@ void TestSuite::test3()
8788
TS_ASSERT_EQUALS(*(dynamic_cast<Test3_Msg2*>(readMsg.get())), msg2);
8889
}
8990

91+
void TestSuite::test4()
92+
{
93+
Msg5 msg;
94+
msg.field_f1().value() = -128;
95+
msg.field_f2().value() = -512;
96+
TS_ASSERT_EQUALS(msg.doLength(), 4U);
97+
98+
std::vector<std::uint8_t> buf;
99+
buf.resize(msg.doLength());
100+
auto writeIter = buf.data();
101+
auto es = msg.write(writeIter, buf.size());
102+
TS_ASSERT_EQUALS(es, comms::ErrorStatus::Success);
103+
104+
static const std::uint8_t ExpBuf[] = {
105+
0x80, 0x7f,
106+
0xfc, 0x00,
107+
};
108+
static const std::size_t ExpBufSize = std::extent<decltype(ExpBuf)>::value;
109+
110+
TS_ASSERT_EQUALS(buf.size(), ExpBufSize);
111+
TS_ASSERT(std::equal(buf.begin(), buf.end(), std::begin(ExpBuf)));
112+
}

app/commsdsl2emscripten/test/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ endif ()
3838

3939
foreach (name ${tests})
4040
set (test_dir "${tests_path}/${name}")
41-
file (GLOB schema_files ${test_dir}/Schema*.xml)
4241
set (this_test_dir "${CMAKE_CURRENT_SOURCE_DIR}/${name}")
42+
43+
if (EXISTS ${this_test_dir}/disabled.txt)
44+
continue ()
45+
endif ()
46+
47+
file (GLOB schema_files ${test_dir}/Schema*.xml)
4348
set (code_input_dir "${this_test_dir}/src")
4449
set (code_input_param)
4550
if (EXISTS "${code_input_dir}/")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Due to enums with big unsigned underlying type, not accepted by emscripten.

app/commsdsl2wireshark/src/WiresharkEnumField.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,18 @@ std::string WiresharkEnumField::wiresharkFieldRegistrationImpl(const WiresharkFi
5252
{"REF_NAME", wiresharkFieldRefName(refField)},
5353
{"DISP_NAME", wiresharkFieldNameVarNameStr(refField)},
5454
{"VALS_NAME", wiresharkFieldObjName(refField) + strings::genValsSuffixStr()},
55-
{"BASE", "base.DEC_HEX"},
55+
{"BASE", "base.DEC"},
5656
{"MASK", wiresharkForcedIntegralFieldMask(refField)},
5757
{"DESC", wiresharkFieldDescriptionStr(refField)},
5858
};
5959

60-
if (obj.parseHexAssign()) {
61-
repl["BASE"] = "base.HEX_DEC";
60+
if (genIsUnsignedType()) {
61+
// Cannot display hex value
62+
repl["BASE"] = "base.DEC_HEX";
63+
64+
if (obj.parseHexAssign()) {
65+
repl["BASE"] = "base.HEX_DEC";
66+
}
6267
}
6368

6469
if (repl["TYPE"].empty()) {
@@ -313,17 +318,20 @@ std::string WiresharkEnumField::wiresharkVarLengthCodeInternal(bool& hasVal) con
313318
}
314319

315320
if (parseObj.parseEndian() == commsdsl::parse::ParseEndian_Little) {
316-
return wiresharkIntegralFieldVarLengthLittleEndianCode();
321+
return wiresharkIntegralFieldVarLengthLittleEndianCode(!genIsUnsignedUnderlyingType());
317322
}
318323

319-
return wiresharkIntegralFieldVarLengthBigEndianCode();
324+
return wiresharkIntegralFieldVarLengthBigEndianCode(!genIsUnsignedUnderlyingType());
320325
}
321326

322327
std::string WiresharkEnumField::wiresharkVarLengthCodeLargeNumInternal() const
323328
{
324-
// TODO: Implement and test
325-
assert(false);
326-
return strings::genEmptyString();
329+
auto parseObj = genEnumFieldParseObj();
330+
if (parseObj.parseEndian() == commsdsl::parse::ParseEndian_Little) {
331+
return wiresharkIntegralFieldVarLengthLargeNumLittleEndianCode(!genIsUnsignedType());
332+
}
333+
334+
return wiresharkIntegralFieldVarLengthLargeNumBigEndianCode(!genIsUnsignedType());
327335
}
328336

329337
} // namespace commsdsl2wireshark

0 commit comments

Comments
 (0)