Skip to content

Commit

Permalink
Merge pull request #160 from slaclab/ESCRYODET-448
Browse files Browse the repository at this point in the history
Fix BaseTransmitter bug
  • Loading branch information
jesusvasquez333 authored Nov 9, 2019
2 parents 06aaa23 + 37a2062 commit 0a64ffd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
Binary file added .DS_Store
Binary file not shown.
18 changes: 9 additions & 9 deletions include/smurf/core/transmitters/BaseTransmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <rogue/GilRelease.h>
#include "smurf/core/common/SmurfHeader.h"
#include "smurf/core/common/SmurfPacket.h"
#include "smurf/core/transmitters/BaseTransmitterChannel.h"

namespace bp = boost::python;
namespace ris = rogue::interfaces::stream;
Expand All @@ -42,9 +43,8 @@ namespace smurf
class BaseTransmitter;
typedef std::shared_ptr<BaseTransmitter> BaseTransmitterPtr;

class BaseTransmitterChannel;

class BaseTransmitter: public std::enable_shared_from_this<smurf::core::transmitters::BaseTransmitter> {
class BaseTransmitter: public std::enable_shared_from_this<smurf::core::transmitters::BaseTransmitter>
{
public:
BaseTransmitter();
virtual ~BaseTransmitter() {};
Expand All @@ -59,10 +59,10 @@ namespace smurf
const bool getDisable() const;

// Get data channel
std::shared_ptr<smurf::core::transmitters::BaseTransmitterChannel> getDataChannel();
BaseTransmitterChannelPtr getDataChannel();

// Get meta data channel
std::shared_ptr<smurf::core::transmitters::BaseTransmitterChannel> getMetaChannel();
BaseTransmitterChannelPtr getMetaChannel();

// Clear all counter.
void clearCnt();
Expand Down Expand Up @@ -101,9 +101,9 @@ namespace smurf
std::condition_variable txCV; // Variable to notify the thread new data is ready
std::mutex txMutex; // Mutex used for accessing the conditional variable

// Inteface channels
std::shared_ptr<smurf::core::transmitters::BaseTransmitterChannel> dataChannel;
std::shared_ptr<smurf::core::transmitters::BaseTransmitterChannel> metaChannel;
// Interface channels
BaseTransmitterChannelPtr dataChannel;
BaseTransmitterChannelPtr metaChannel;

// Transmit method. Will run in the pktTransmitterThread thread.
// Here is where the method 'transmit' is called.
Expand Down
7 changes: 6 additions & 1 deletion python/pysmurf/core/devices/_SmurfProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,12 @@ def __init__(self, name, description, root=None, txDevice=None, **kwargs):
if txDevice:
self.transmitter = txDevice
self.add(self.transmitter)
pyrogue.streamConnect(self.fifo, self.transmitter)
# Connect the data channel to the FIFO.
pyrogue.streamConnect(self.fifo, self.transmitter.getDataChannel())
# If a root was defined, connect it to the meta channel.
# Use streamTap as it was already connected to the file writer.
if root:
pyrogue.streamTap(root, self.transmitter.getMetaChannel())

def setTesBias(self, index, val):
pass
Expand Down
30 changes: 18 additions & 12 deletions src/smurf/core/transmitters/BaseTransmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
*-----------------------------------------------------------------------------
**/

#include <iostream>
#include <boost/python.hpp>
#include "smurf/core/common/Timer.h"
#include "smurf/core/transmitters/BaseTransmitter.h"
#include "smurf/core/transmitters/BaseTransmitterChannel.h"

namespace bp = boost::python;
namespace sct = smurf::core::transmitters;
Expand All @@ -40,9 +39,6 @@ sct::BaseTransmitter::BaseTransmitter()
{
if( pthread_setname_np( pktTransmitterThread.native_handle(), "SmurfPacketTx" ) )
perror( "pthread_setname_np failed for the SmurfPacketTx thread" );

dataChannel = sct::BaseTransmitterChannel::create(shared_from_this(),0);
metaChannel = sct::BaseTransmitterChannel::create(shared_from_this(),1);
}

sct::BaseTransmitterPtr sct::BaseTransmitter::create()
Expand All @@ -66,13 +62,23 @@ void sct::BaseTransmitter::setup_python()
}

// Get data channel
sct::BaseTransmitterChannelPtr sct::BaseTransmitter::getDataChannel() {
return dataChannel;
sct::BaseTransmitterChannelPtr sct::BaseTransmitter::getDataChannel()
{
// Create the dataChanenl object the first time this is called
if (!dataChannel)
dataChannel = sct::BaseTransmitterChannel::create(shared_from_this(),0);

return dataChannel;
}

// Get meta data channel
sct::BaseTransmitterChannelPtr sct::BaseTransmitter::getMetaChannel() {
return dataChannel;
sct::BaseTransmitterChannelPtr sct::BaseTransmitter::getMetaChannel()
{
// Create the metaChanenl object the first time this is called
if (!metaChannel)
metaChannel = sct::BaseTransmitterChannel::create(shared_from_this(),1);

return metaChannel;
}

void sct::BaseTransmitter::setDisable(bool d)
Expand Down Expand Up @@ -103,12 +109,12 @@ void sct::BaseTransmitter::acceptDataFrame(ris::FramePtr frame)
if (disable)
return;

// When a new packet is recived, add it to the dual buffer. This will
// When a new packet is received, add it to the dual buffer. This will
// allow to prepare a new packet while the previous one is still being
// transmitted. The packet will be transmitted in a different thread.

// Check if the buffer is not full.
// If the buffer is full, the packet will be droped
// If the buffer is full, the packet will be dropped
if (pktCount < 2)
{
// Add a new packet into the buffer
Expand Down Expand Up @@ -138,7 +144,7 @@ void sct::BaseTransmitter::acceptMetaFrame(ris::FramePtr frame)
ris::FrameLockPtr fLock = frame->lock();

if ( frame->bufferCount() != 1 ) return;

std::string cfg(reinterpret_cast<char const*>(frame->beginRead().ptr()), frame->getPayload());
fLock->unlock();

Expand Down
2 changes: 1 addition & 1 deletion src/smurf/core/transmitters/BaseTransmitterChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace bp = boost::python;
namespace sct = smurf::core::transmitters;

sct::BaseTransmitterChannel::BaseTransmitterChannel(sct::BaseTransmitterPtr bt, uint32_t channel)
sct::BaseTransmitterChannel::BaseTransmitterChannel(sct::BaseTransmitterPtr bt, uint32_t channel)
{
channel_ = channel;
bt_ = bt;
Expand Down

0 comments on commit 0a64ffd

Please sign in to comment.