ngscopeclient v0.2
Loading...
Searching...
No Matches
CommandLineDriver.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2026 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
38#ifndef CommandLineDriver_h
39#define CommandLineDriver_h
40
45class CommandLineDriver: public virtual SCPIDevice
46{
47public:
50
51
52protected:
53 // Make sure several request don't collide before we received the corresponding response
54 std::recursive_mutex m_transportMutex;
55
64 std::string ConverseSingle(const std::string& commandString, bool hasEcho = true);
65
66
77 size_t ConverseMultiple(
78 const std::string& commandString,
79 std::vector<std::string> &readLines,
80 bool hasEcho = true,
81 std::function<void(float)> progress = nullptr,
82 size_t expecedLines = 0);
83
93 bool ConverseSweep(int64_t &sweepStart, int64_t &sweepStop, int64_t &points, bool setFreqValues = false);
94
103 bool ConverseSweep(int64_t &sweepStart, int64_t &sweepStop, bool setFreqValues = false)
104 {
105 int64_t unused;
106 return ConverseSweep(sweepStart, sweepStop, unused, setFreqValues);
107 }
108
117 std::string ConverseString(
118 const std::string& commandString,
119 std::function<void(float)> progress = nullptr,
120 size_t expecedLines = 0);
121
127 std::string DrainTransport();
128
129 size_t m_maxResponseSize;
130 double m_communicationTimeout;
131
132 // @brief Trailer string expected at the end of a response from the device (command prompt)
133 inline static const std::string TRAILER_STRING = "ch> ";
134 // @brief Legth of the trailer string expected at the end of a response from the device (command prompt)
135 inline static const size_t TRAILER_STRING_LENGTH = TRAILER_STRING.size();
136 // @brief End Of Line string
137 inline static const std::string EOL_STRING = "\r\n";
138 // @brief Size of the EOL string
139 inline static const size_t EOL_STRING_LENGTH = EOL_STRING.size();
140};
141#endif
Helper class for command line drivers: provides helper methods for command line based communication w...
Definition CommandLineDriver.h:46
std::string DrainTransport()
Consume any pending data from the transport layer.
Definition CommandLineDriver.cpp:194
std::string ConverseSingle(const std::string &commandString, bool hasEcho=true)
Converse with the device : send a command and read the reply over several lines.
Definition CommandLineDriver.cpp:91
bool ConverseSweep(int64_t &sweepStart, int64_t &sweepStop, bool setFreqValues=false)
Set and/or read the sweep values from the device.
Definition CommandLineDriver.h:103
bool ConverseSweep(int64_t &sweepStart, int64_t &sweepStop, int64_t &points, bool setFreqValues=false)
Set and/or read the sweep values from the device.
Definition CommandLineDriver.cpp:159
size_t ConverseMultiple(const std::string &commandString, std::vector< std::string > &readLines, bool hasEcho=true, std::function< void(float)> progress=nullptr, size_t expecedLines=0)
Converse with the device by sending a command and receiving a single line response.
Definition CommandLineDriver.cpp:58
std::string ConverseString(const std::string &commandString, std::function< void(float)> progress=nullptr, size_t expecedLines=0)
Base method to converse with the device.
Definition CommandLineDriver.cpp:111
An SCPI-based device.
Definition SCPIDevice.h:37
Abstraction of a transport layer for moving SCPI data between endpoints.
Definition SCPITransport.h:53