Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5ca71d9910c3
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7d1d590cbd69
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Jul 30, 2020

  1. Copy the full SHA
    2ad3f0c View commit details
  2. Merge pull request #201 from noopwafel/uart-transport

    add SCPIUARTTransport (fixes #159)
    azonenberg authored Jul 30, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7d1d590 View commit details
Showing with 205 additions and 0 deletions.
  1. +1 −0 scopehal/CMakeLists.txt
  2. +132 −0 scopehal/SCPIUARTTransport.cpp
  3. +70 −0 scopehal/SCPIUARTTransport.h
  4. +1 −0 scopehal/scopehal.cpp
  5. +1 −0 scopehal/scopehal.h
1 change: 1 addition & 0 deletions scopehal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ set(SCOPEHAL_SOURCES
SCPILxiTransport.cpp
SCPINullTransport.cpp
SCPITMCTransport.cpp
SCPIUARTTransport.cpp
SCPIDevice.cpp

IBISParser.cpp
132 changes: 132 additions & 0 deletions scopehal/SCPIUARTTransport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Alyssa Milburn
@brief Implementation of SCPIUARTTransport
*/

#include "scopehal.h"

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

SCPIUARTTransport::SCPIUARTTransport(string args)
{
char devfile[128];
unsigned int baudrate = 0;
if(2 != sscanf(args.c_str(), "%127[^:]:%u", devfile, &baudrate))
{
//default if port not specified
m_devfile = args;
m_baudrate = 115200;
}
else
{
m_devfile = devfile;
m_baudrate = baudrate;
}

LogDebug("Connecting to SCPI oscilloscope at %s:%d\n", m_devfile.c_str(), m_baudrate);

if(!m_uart.Connect(m_devfile, m_baudrate))
{
m_uart.Close();
LogError("Couldn't connect to UART\n");
return;
}
}

SCPIUARTTransport::~SCPIUARTTransport()
{
}

bool SCPIUARTTransport::IsConnected()
{
return m_uart.IsValid();
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual transport code

string SCPIUARTTransport::GetTransportName()
{
return "uart";
}

string SCPIUARTTransport::GetConnectionString()
{
char tmp[256];
snprintf(tmp, sizeof(tmp), "%s:%u", m_devfile.c_str(), m_baudrate);
return string(tmp);
}

bool SCPIUARTTransport::SendCommand(string cmd)
{
LogTrace("Sending %s\n", cmd.c_str());
string tempbuf = cmd + "\n";
return m_uart.Write((unsigned char*)tempbuf.c_str(), tempbuf.length());
}

string SCPIUARTTransport::ReadReply()
{
//FIXME: there *has* to be a more efficient way to do this...
// (see the same code in Socket)
char tmp = ' ';
string ret;
while(true)
{
if(!m_uart.Read((unsigned char*)&tmp, 1))
break;
if( (tmp == '\n') || (tmp == ';') )
break;
else
ret += tmp;
}
LogTrace("Got %s\n", ret.c_str());
return ret;
}

void SCPIUARTTransport::SendRawData(size_t len, const unsigned char* buf)
{
m_uart.Write(buf, len);
}

void SCPIUARTTransport::ReadRawData(size_t len, unsigned char* buf)
{
m_uart.Read(buf, len);
}

bool SCPIUARTTransport::IsCommandBatchingSupported()
{
return true;
}
70 changes: 70 additions & 0 deletions scopehal/SCPIUARTTransport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Alyssa Milburn
@brief Declaration of SCPIUARTTransport
*/

#ifndef SCPIUARTTransport_h
#define SCPIUARTTransport_h

#include "../xptools/UART.h"

/**
@brief Abstraction of a transport layer for moving SCPI data between endpoints
*/
class SCPIUARTTransport : public SCPITransport
{
public:
SCPIUARTTransport(std::string args);
virtual ~SCPIUARTTransport();

virtual std::string GetConnectionString();
static std::string GetTransportName();

virtual bool SendCommand(std::string cmd);
virtual std::string ReadReply();
virtual void ReadRawData(size_t len, unsigned char* buf);
virtual void SendRawData(size_t len, const unsigned char* buf);

virtual bool IsCommandBatchingSupported();
virtual bool IsConnected();

TRANSPORT_INITPROC(SCPIUARTTransport)

protected:
UART m_uart;

std::string m_devfile;
unsigned int m_baudrate;
};

#endif
1 change: 1 addition & 0 deletions scopehal/scopehal.cpp
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@ void TransportStaticInit()
{
AddTransportClass(SCPISocketTransport);
AddTransportClass(SCPITMCTransport);
AddTransportClass(SCPIUARTTransport);
AddTransportClass(SCPINullTransport);
AddTransportClass(VICPSocketTransport);

1 change: 1 addition & 0 deletions scopehal/scopehal.h
Original file line number Diff line number Diff line change
@@ -59,6 +59,7 @@
#include "SCPILxiTransport.h"
#include "SCPINullTransport.h"
#include "SCPITMCTransport.h"
#include "SCPIUARTTransport.h"
#include "VICPSocketTransport.h"
#include "SCPIDevice.h"