ngscopeclient v0.3
Loading...
Searching...
No Matches
PacketDecoder.h
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
30#ifndef PacketDecoder_h
31#define PacketDecoder_h
32
33#include "Filter.h"
34
39class Packet
40{
41public:
42 Packet();
43 virtual ~Packet();
44
47
50
51 //Arbitrary header properties (human readable)
52 std::map<std::string, std::string> m_headers;
53
54 //Raw header bytes
55 std::vector<uint8_t> m_headerdata;
56
57 //Packet bytes
58 std::vector<uint8_t> m_data;
59
60 //Text color of the packet
61 std::string m_displayForegroundColor;
62
63 //Background color of the packet
64 std::string m_displayBackgroundColor;
65
66 //Packed colors
67 uint32_t m_displayForegroundColorPacked;
68 uint32_t m_displayBackgroundColorPacked;
69
70 bool m_packedColorsValid;
71
72 void RefreshColors()
73 {
74 if(m_packedColorsValid)
75 return;
76 m_packedColorsValid = true;
77
78 m_displayForegroundColorPacked = ColorFromString(m_displayForegroundColor);
79 m_displayBackgroundColorPacked = ColorFromString(m_displayBackgroundColor);
80 }
81};
82
87class PacketDecoder : public Filter
88{
89public:
90 PacketDecoder(const std::string& color, Filter::Category cat);
91 virtual ~PacketDecoder();
92
93 const std::vector<Packet*>& GetPackets()
94 { return m_packets; }
95
96 virtual std::vector<std::string> GetHeaders() =0;
97
98 virtual bool GetShowDataColumn();
99 virtual bool GetShowImageColumn();
100
101 virtual Packet* CreateMergedHeader(Packet* pack, size_t i);
102 virtual bool CanMerge(Packet* first, Packet* cur, Packet* next);
103
105 virtual std::string GetDecodedField(Packet* pack, size_t i)
106 { return pack->m_headers[GetHeaders()[i]]; }
107
114 {
115 PROTO_COLOR_DEFAULT, //Default color if not otherwise specified
116 PROTO_COLOR_ERROR, //Malformed packets, or packets indicating an error condition
117 PROTO_COLOR_STATUS, //Reading or writing status registers
118 PROTO_COLOR_CONTROL, //Reading or writing control registers
119 PROTO_COLOR_DATA_READ, //Reading unspecified data
120 PROTO_COLOR_DATA_WRITE, //Writing unspecified data
121 PROTO_COLOR_COMMAND, //Executing commands of some sort
122
123 PROTO_STANDARD_COLOR_COUNT
124 };
125
126 static std::string m_backgroundColors[PROTO_STANDARD_COLOR_COUNT];
127
134 { m_packets.clear(); }
135
136protected:
137 void ClearPackets();
138
139 std::vector<Packet*> m_packets;
140};
141
142#endif
Declaration of Filter.
Definition AcceleratorBuffer.h:204
Abstract base class for all filter graph blocks which are not physical instrument channels.
Definition Filter.h:105
Category
Category the filter should be displayed under in the GUI.
Definition Filter.h:118
Definition PacketDecoder.h:88
virtual std::string GetDecodedField(Packet *pack, size_t i)
Transition helper until we deprecate the old header API to get the decoded text of the Nth header.
Definition PacketDecoder.h:105
void ClearPackets()
Destroys all currently attached packets.
Definition PacketDecoder.cpp:84
virtual bool CanMerge(Packet *first, Packet *cur, Packet *next)
Checks if multiple packets can be merged under a single heading in the protocol analyzer view.
Definition PacketDecoder.cpp:114
virtual Packet * CreateMergedHeader(Packet *pack, size_t i)
Creates a summary packet for one or more merged packets.
Definition PacketDecoder.cpp:125
void DetachPackets()
Clears the list of packets attached to this filter without freeing memory.
Definition PacketDecoder.h:133
PacketColor
Standard colors for protocol analyzer lines.
Definition PacketDecoder.h:114
Definition PacketDecoder.h:40
int64_t m_offset
Offset of the packet from the start of the capture (femtoseconds)
Definition PacketDecoder.h:46
int64_t m_len
Duration time of the packet (femtoseconds)
Definition PacketDecoder.h:49