ngscopeclient 0.1-dev+51fbda87c
USB2PCSDecoder.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopeprotocols *
4* *
5* Copyright (c) 2012-2022 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
35#ifndef USB2PCSDecoder_h
36#define USB2PCSDecoder_h
37
38#include "USB2PMADecoder.h"
39
44{
45public:
46
47 enum SymbolType
48 {
49 TYPE_SYNC,
50 TYPE_EOP,
51 TYPE_RESET,
52 //TODO: handle suspend (idle for >3 ms)
53 //TODO: handle resume
54 TYPE_DATA,
55 TYPE_ERROR
56 };
57
58 USB2PCSSymbol(SymbolType type = TYPE_SYNC, uint8_t data = 0)
59 : m_type(type)
60 , m_data(data)
61 {
62 }
63
64 SymbolType m_type;
65 uint8_t m_data;
66
67 bool operator==(const USB2PCSSymbol& rhs) const
68 {
69 return (m_type == rhs.m_type);
70 }
71};
72
73class USB2PCSWaveform : public SparseWaveform<USB2PCSSymbol>
74{
75public:
77 virtual std::string GetText(size_t) override;
78 virtual std::string GetColor(size_t) override;
79};
80
81class USB2PCSDecoder : public Filter
82{
83public:
84 USB2PCSDecoder(const std::string& color);
85
86 virtual void Refresh() override;
87
88 static std::string GetProtocolName();
89
90 virtual bool ValidateChannel(size_t i, StreamDescriptor stream) override;
91
92 PROTOCOL_DECODER_INITPROC(USB2PCSDecoder)
93
94protected:
95 enum BusSpeed
96 {
97 SPEED_1M,
98 SPEED_12M,
99 SPEED_480M
100 };
101
102 enum DecodeState
103 {
104 STATE_IDLE,
105 STATE_SYNC,
106 STATE_DATA
107 };
108
109 void RefreshIterationIdle(
110 size_t nin,
111 DecodeState& state,
112 BusSpeed& speed,
113 size_t& ui_width,
114 USB2PCSWaveform* cap,
115 USB2PMAWaveform* din,
116 size_t& count,
117 int64_t& offset
118 );
119
120 void RefreshIterationSync(
121 size_t nin,
122 DecodeState& state,
123 BusSpeed speed,
124 size_t& ui_width,
125 USB2PCSWaveform* cap,
126 USB2PMAWaveform* din,
127 size_t& count,
128 int64_t& offset,
129 uint8_t& data,
130 bool& first
131 );
132
133 void RefreshIterationData(
134 size_t nin,
135 size_t nlast,
136 DecodeState& state,
137 BusSpeed speed,
138 size_t& ui_width,
139 USB2PCSWaveform* cap,
140 USB2PMAWaveform* din,
141 size_t& count,
142 int64_t& offset,
143 uint8_t& data);
144};
145
146#endif
Declaration of USB2PMADecoder.
Abstract base class for all filter graph blocks which are not physical instrument channels.
Definition: Filter.h:95
A waveform sampled at irregular intervals.
Definition: Waveform.h:460
Descriptor for a single stream coming off a channel.
Definition: StreamDescriptor.h:46
Definition: USB2PCSDecoder.h:82
virtual void Refresh() override
Evaluates a filter graph node.
Definition: USB2PCSDecoder.cpp:70
A single symbol at the PCS layer (byte or command)
Definition: USB2PCSDecoder.h:44
Definition: USB2PCSDecoder.h:74
virtual std::string GetColor(size_t) override
Returns the displayed color (in HTML #rrggbb or #rrggbbaa notation) of a given protocol sample.
Definition: USB2PCSDecoder.cpp:508
virtual std::string GetText(size_t) override
Returns the text representation of a given protocol sample.
Definition: USB2PCSDecoder.cpp:529
Definition: USB2PMADecoder.h:67