ngscopeclient 0.1-dev+51fbda87c
CommandLineDriver.h
Go to the documentation of this file.
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
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(const std::string commandString, std::vector<std::string> &readLines, bool hasEcho = true, std::function<void(float)> progress = nullptr, size_t expecedLines = 0);
78
88 bool ConverseSweep(int64_t &sweepStart, int64_t &sweepStop, int64_t &points, bool setFreqValues = false);
89
98 bool ConverseSweep(int64_t &sweepStart, int64_t &sweepStop, bool setFreqValues = false)
99 {
100 int64_t unused;
101 return ConverseSweep(sweepStart, sweepStop, unused, setFreqValues);
102 }
103
112 std::string ConverseString(const std::string commandString, std::function<void(float)> progress = nullptr, size_t expecedLines = 0);
113
119 std::string DrainTransport();
120
121 size_t m_maxResponseSize;
122 double m_communicationTimeout;
123
124 // @brief Trailer string expected at the end of a response from the device (command prompt)
125 inline static const std::string TRAILER_STRING = "ch> ";
126 // @brief Legth of the trailer string expected at the end of a response from the device (command prompt)
127 inline static const size_t TRAILER_STRING_LENGTH = TRAILER_STRING.size();
128 // @brief End Of Line string
129 inline static const std::string EOL_STRING = "\r\n";
130 // @brief Size of the EOL string
131 inline static const size_t EOL_STRING_LENGTH = EOL_STRING.size();
132};
133#endif
Helper class for command line drivers: provides helper methods for command line based communication w...
Definition: CommandLineDriver.h:46
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:81
bool ConverseSweep(int64_t &sweepStart, int64_t &sweepStop, bool setFreqValues=false)
Set and/or read the sweep values from the device.
Definition: CommandLineDriver.h:98
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:101
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:146
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:53
std::string DrainTransport()
Consume any pending data from the transport layer.
Definition: CommandLineDriver.cpp:181
An SCPI-based device.
Definition: SCPIDevice.h:37
Abstraction of a transport layer for moving SCPI data between endpoints.
Definition: SCPITransport.h:47