ngscopeclient 0.1-dev+51fbda87c
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
46 int64_t m_offset;
47
49 int64_t m_len;
50
51 //Arbitrary header properties (human readable)
52 std::map<std::string, std::string> m_headers;
53
54 //Packet bytes
55 std::vector<uint8_t> m_data;
56
57 //Text color of the packet
58 std::string m_displayForegroundColor;
59
60 //Background color of the packet
61 std::string m_displayBackgroundColor;
62
63 //Packed colors
64 uint32_t m_displayForegroundColorPacked;
65 uint32_t m_displayBackgroundColorPacked;
66
67 bool m_packedColorsValid;
68
69 void RefreshColors()
70 {
71 if(m_packedColorsValid)
72 return;
73 m_packedColorsValid = true;
74
75 m_displayForegroundColorPacked = ColorFromString(m_displayForegroundColor);
76 m_displayBackgroundColorPacked = ColorFromString(m_displayBackgroundColor);
77 }
78};
79
84class PacketDecoder : public Filter
85{
86public:
87 PacketDecoder(const std::string& color, Filter::Category cat);
88 virtual ~PacketDecoder();
89
90 const std::vector<Packet*>& GetPackets()
91 { return m_packets; }
92
93 virtual std::vector<std::string> GetHeaders() =0;
94
95 virtual bool GetShowDataColumn();
96 virtual bool GetShowImageColumn();
97
98 virtual Packet* CreateMergedHeader(Packet* pack, size_t i);
99 virtual bool CanMerge(Packet* first, Packet* cur, Packet* next);
100
107 {
108 PROTO_COLOR_DEFAULT, //Default color if not otherwise specified
109 PROTO_COLOR_ERROR, //Malformed packets, or packets indicating an error condition
110 PROTO_COLOR_STATUS, //Reading or writing status registers
111 PROTO_COLOR_CONTROL, //Reading or writing control registers
112 PROTO_COLOR_DATA_READ, //Reading unspecified data
113 PROTO_COLOR_DATA_WRITE, //Writing unspecified data
114 PROTO_COLOR_COMMAND, //Executing commands of some sort
115
116 PROTO_STANDARD_COLOR_COUNT
117 };
118
119 static std::string m_backgroundColors[PROTO_STANDARD_COLOR_COUNT];
120
127 { m_packets.clear(); }
128
129protected:
130 void ClearPackets();
131
132 std::vector<Packet*> m_packets;
133};
134
135#endif
Declaration of Filter.
uint32_t ColorFromString(const string &str, unsigned int alpha)
Converts a hex color code plus externally supplied default alpha value into a packed RGBA color.
Definition: Waveform.cpp:272
Abstract base class for all filter graph blocks which are not physical instrument channels.
Definition: Filter.h:95
Category
Category the filter should be displayed under in the GUI.
Definition: Filter.h:108
Definition: PacketDecoder.h:85
void ClearPackets()
Destroys all currently attached packets.
Definition: PacketDecoder.cpp:80
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:110
virtual Packet * CreateMergedHeader(Packet *pack, size_t i)
Creates a summary packet for one or more merged packets.
Definition: PacketDecoder.cpp:121
void DetachPackets()
Clears the list of packets attached to this filter without freeing memory.
Definition: PacketDecoder.h:126
PacketColor
Standard colors for protocol analyzer lines.
Definition: PacketDecoder.h:107
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