Bitstream Interpretation Library (BIL)
0.1
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
bitstream
V5BitstreamXMLWriter.cpp
Go to the documentation of this file.
1
6
#include <
bitstream/Bitstream.hpp
>
7
#include <
bitstream/PacketOpcode.hpp
>
8
#include <
bitstream/V5BitstreamXMLWriter.hpp
>
9
#include <
configuration/V5FrameAddress.hpp
>
10
#include <
configuration/V5FrameAddressString.hpp
>
11
#include <
packetprocessor/V5CommandCode.hpp
>
12
#include <
packetprocessor/V5RegisterAddress.hpp
>
13
#include <
util/HexPrint.hpp
>
14
#include <
util/XMLWriter.hpp
>
15
16
using namespace
bil;
17
18
19
const
char
TAGNAME_BUSWIDTHPATTERN
[] =
"buswidthpattern"
;
20
const
char
TAGNAME_DUMMYWORD
[] =
"dummyword"
;
21
const
char
TAGNAME_SYNCWORD
[] =
"syncword"
;
22
const
char
TAGNAME_TYPE1PACKET
[] =
"type1packet"
;
23
const
char
TAGNAME_TYPE2PACKET
[] =
"type2packet"
;
24
25
const
char
ATTRIBNAME_OPCODE
[] =
"opcode"
;
26
const
char
ATTRIBNAME_REGISTER
[] =
"register"
;
27
const
char
ATTRIBNAME_WORDCOUNT
[] =
"wordcount"
;
28
29
30
V5BitstreamXMLWriter::V5BitstreamXMLWriter
(
XMLWriter
& xmlWriter):
31
m_xmlWriter(xmlWriter)
32
{
33
34
}
35
36
37
void
V5BitstreamXMLWriter::visit
(
const
BuswidthPattern
& buswidthPattern)
38
{
39
V5BitstreamSyntaxChecker::visit
(buswidthPattern);
40
writePacketTag
(buswidthPattern);
41
}
42
43
44
void
V5BitstreamXMLWriter::visit
(
const
DummyWord
& dummyWord)
45
{
46
V5BitstreamSyntaxChecker::visit
(dummyWord);
47
writePacketTag
(dummyWord);
48
}
49
50
51
void
V5BitstreamXMLWriter::visit
(
const
SyncWord
& syncWord)
52
{
53
V5BitstreamSyntaxChecker::visit
(syncWord);
54
writePacketTag
(syncWord);
55
}
56
57
58
void
V5BitstreamXMLWriter::visit
(
const
Type1Packet
& type1Packet)
59
{
60
V5BitstreamSyntaxChecker::visit
(type1Packet);
61
writePacketTag
(
TAGNAME_TYPE1PACKET
, type1Packet);
62
}
63
64
65
void
V5BitstreamXMLWriter::visit
(
const
Type2Packet
& type2Packet)
66
{
67
V5BitstreamSyntaxChecker::visit
(type2Packet);
68
writePacketTag
(
TAGNAME_TYPE2PACKET
, type2Packet);
69
}
70
71
72
void
V5BitstreamXMLWriter::writePacketTag
(
const
BuswidthPattern
&)
73
{
74
m_xmlWriter.
beginElement
(
TAGNAME_BUSWIDTHPATTERN
,
true
);
75
m_xmlWriter.
endElement
(
false
);
76
}
77
78
79
void
V5BitstreamXMLWriter::writePacketTag
(
const
DummyWord
& dummyWord)
80
{
81
m_xmlWriter.
beginElement
(
TAGNAME_DUMMYWORD
,
true
);
82
m_xmlWriter.
addData
(
hexString
(dummyWord.
value
()),
false
);
83
m_xmlWriter.
endElement
(
false
);
84
}
85
86
87
void
V5BitstreamXMLWriter::writePacketTag
(
const
SyncWord
&)
88
{
89
m_xmlWriter.
beginElement
(
TAGNAME_SYNCWORD
,
true
);
90
m_xmlWriter.
endElement
(
false
);
91
}
92
93
94
void
V5BitstreamXMLWriter::writePacketTag
(
const
std::string& tagName,
const
Type2Packet
& type2Packet)
95
{
96
// write opening tag
97
m_xmlWriter.
beginElement
(tagName,
true
);
98
99
// get opcode string representation. if that fails, take hex value.
100
std::string tempStr(
PacketOpcode::toString
(type2Packet.
opcode
()));
101
if
(tempStr.empty()) tempStr =
hexString
(type2Packet.
opcode
());
102
// write opcode attribute
103
m_xmlWriter.
addAttribute
(
ATTRIBNAME_OPCODE
, tempStr);
104
105
// if packet is NO_OP packet, then there is nothing more to write
106
if
(
PacketOpcode::NO_OP
!= type2Packet.
opcode
())
107
{
108
// get register string representation. if that fails, take hex value.
109
tempStr =
V5RegisterAddress::toString
(
lastType1Address
());
110
if
(tempStr.empty()) tempStr =
hexString
(
lastType1Address
());
111
// write register attribute
112
m_xmlWriter.
addAttribute
(
ATTRIBNAME_REGISTER
, tempStr);
113
114
// write word count
115
m_xmlWriter.
addAttribute
(
ATTRIBNAME_WORDCOUNT
, type2Packet.
wordCount
());
116
117
// write element data if present
118
if
(
PacketOpcode::REGISTER_WRITE
== type2Packet.
opcode
())
119
writeData
(type2Packet.
dataWords
(), type2Packet.
wordCount
());
120
}
121
122
// close packet tag
123
m_xmlWriter.
endElement
(
false
);
124
}
125
126
127
void
V5BitstreamXMLWriter::writeData
(
const
boost::uint32_t* words,
size_t
wordCount)
128
{
129
// data for CMD register: write command name
130
if
((
V5RegisterAddress::CMD
==
lastType1Address
()) && (1 == wordCount))
131
{
132
std::string cmdStr(
V5CommandCode::toString
(*words));
133
if
(cmdStr.empty()) cmdStr =
hexString
(*words);
134
m_xmlWriter.
addData
(cmdStr,
false
);
135
}
136
// data for FAR register: write address
137
else
if
((
V5RegisterAddress::FAR
==
lastType1Address
()) && (1 == wordCount))
138
{
139
V5FrameAddress
fa;
140
fa.
rawAddress
(*words);
141
m_xmlWriter.
addData
(
toExpandedString
(fa),
false
);
142
}
143
// all other data: write hex values
144
else
m_xmlWriter.
addData
(
hexString
(words, wordCount),
false
);
145
}
146
147
148
void
bil::writeV5BitstreamXML
(
XMLWriter
& xmlWriter,
const
Bitstream
& bs)
149
{
150
V5BitstreamXMLWriter
bsXMLWriter(xmlWriter);
151
bs.
runVisitor
(bsXMLWriter);
152
}
Generated on Wed Aug 8 2012 21:57:40 for Bitstream Interpretation Library (BIL) by
1.8.1.1