Skip to content

Commit

Permalink
Added stopOnOverflow property #US4R-101
Browse files Browse the repository at this point in the history
  • Loading branch information
pjarosik committed Mar 9, 2022
1 parent e8c95d4 commit b4a6ab2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
17 changes: 17 additions & 0 deletions arrus/core/api/devices/us4r/Us4R.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ class Us4R : public DeviceWithComponents {
*/
virtual void checkState() const = 0;

/**
* Set the system to stop when (RX or host) buffer overflow is detected.
*
* This property is set by default to true.
*
* @param isStopOnOverflow whether the system should stop when buffer overflow is detected.
*/
virtual void setStopOnOverflow(bool isStopOnOverflow) = 0;

/**
* Returns true if the system will be stopped when (RX of host) buffer overflow is detected.
*
* This property is set by default to true.
*
* @param isStopOnOverflow whether the system should stop when buffer overflow is detected.
*/
virtual bool isStopOnOverflow() const = 0;

Us4R(Us4R const&) = delete;
Us4R(Us4R const&&) = delete;
Expand Down
15 changes: 14 additions & 1 deletion arrus/core/devices/us4r/Us4RImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Us4RImpl::upload(const TxRxSequence &seq, unsigned short rxBufferNElements, cons
this->buffer.reset();
}
// Create output buffer.
this->buffer = std::make_shared<Us4ROutputBuffer>(us4oemComponentSize, shape, dataType, hostBufferNElements);
this->buffer = std::make_shared<Us4ROutputBuffer>(us4oemComponentSize, shape, dataType, hostBufferNElements, stopOnOverflow);
getProbeImpl()->registerOutputBuffer(this->buffer.get(), rxBuffer, workMode);
return {this->buffer, std::move(fcm)};
}
Expand Down Expand Up @@ -304,4 +304,17 @@ std::vector<unsigned short> Us4RImpl::getChannelsMask() {
return channelsMask;
}

void Us4RImpl::setStopOnOverflow(bool value) {
std::unique_lock<std::mutex> guard(deviceStateMutex);
if (this->state != State::STOPPED) {
logger->log(LogSeverity::INFO, "The StopOnOverflow property can be set "
"only when the device is stopped.");
}
this->stopOnOverflow = value;
}

bool Us4RImpl::isStopOnOverflow() const {
return stopOnOverflow;
}

}
3 changes: 3 additions & 0 deletions arrus/core/devices/us4r/Us4RImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class Us4RImpl : public Us4R {
unsigned char getVoltage() override;
float getMeasuredPVoltage() override;
float getMeasuredMVoltage() override;
void setStopOnOverflow(bool isStopOnOverflow) override;
bool isStopOnOverflow() const override;

private:
UltrasoundDevice *getDefaultComponent();
Expand All @@ -157,6 +159,7 @@ class Us4RImpl : public Us4R {
// AFE parameters.
std::optional<RxSettings> rxSettings;
std::vector<unsigned short> channelsMask;
bool stopOnOverflow{true};
};

}
Expand Down
9 changes: 8 additions & 1 deletion arrus/core/devices/us4r/Us4ROutputBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ class Us4ROutputBuffer : public framework::DataBuffer {
Us4ROutputBuffer(const std::vector<size_t> &us4oemOutputSizes,
const framework::NdArray::Shape &elementShape,
const framework::NdArray::DataType elementDataType,
const unsigned nElements)
const unsigned nElements,
bool stopOnOverflow)
: elementSize(0) {
ARRUS_REQUIRES_TRUE(us4oemOutputSizes.size() <= 16,
"Currently Us4R data buffer supports up to 16 us4oem modules.");
Expand Down Expand Up @@ -178,6 +179,7 @@ class Us4ROutputBuffer : public framework::DataBuffer {
elementAddress, elementSize, elementShape, elementDataType, filledAccumulator, i));
}
this->initialize();
this->stopOnOverflow = stopOnOverflow;
}

~Us4ROutputBuffer() override {
Expand Down Expand Up @@ -286,6 +288,10 @@ class Us4ROutputBuffer : public framework::DataBuffer {
this->elements[element]->registerReleaseFunction(releaseFunction);
}

bool isStopOnOverflow() {
return this->stopOnOverflow;
}


private:
std::mutex mutex;
Expand All @@ -307,6 +313,7 @@ class Us4ROutputBuffer : public framework::DataBuffer {
RUNNING, SHUTDOWN, INVALID
};
State state{State::RUNNING};
bool stopOnOverflow{true};

/**
* Throws IllegalStateException when the buffer is in invalid state.
Expand Down
21 changes: 15 additions & 6 deletions arrus/core/devices/us4r/probeadapter/ProbeAdapterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,13 @@ void ProbeAdapterImpl::registerOutputBuffer(Us4ROutputBuffer *bufferDst, const U
// Overflow handling
ius4oem->RegisterReceiveOverflowCallback([this, bufferDst]() {
try {
this->logger->log(LogSeverity::ERROR, "Rx overflow, stopping the device.");
this->getMasterUs4oem()->stop();
bufferDst->markAsInvalid();
if(bufferDst->isStopOnOverflow()) {
this->logger->log(LogSeverity::ERROR, "Rx data overflow, stopping the device.");
this->getMasterUs4oem()->stop();
bufferDst->markAsInvalid();
} else {
this->logger->log(LogSeverity::WARNING, "Rx data overflow ...");
}
} catch (const std::exception &e) {
logger->log(LogSeverity::ERROR, format("RX overflow callback exception: ", e.what()));
} catch (...) {
Expand All @@ -359,9 +363,14 @@ void ProbeAdapterImpl::registerOutputBuffer(Us4ROutputBuffer *bufferDst, const U

ius4oem->RegisterTransferOverflowCallback([this, bufferDst]() {
try {
this->logger->log(LogSeverity::ERROR, "Host overflow, stopping the device.");
this->getMasterUs4oem()->stop();
bufferDst->markAsInvalid();
if(bufferDst->isStopOnOverflow()) {
this->logger->log(LogSeverity::ERROR, "Host data overflow, stopping the device.");
this->getMasterUs4oem()->stop();
bufferDst->markAsInvalid();
}
else {
this->logger->log(LogSeverity::WARNING, "Host data overflow ...");
}
} catch (const std::exception &e) {
logger->log(LogSeverity::ERROR, format("Host overflow callback exception: ", e.what()));
} catch (...) {
Expand Down

0 comments on commit b4a6ab2

Please sign in to comment.