Skip to content

Commit 9bbfae1

Browse files
committed
Stop acquisition gracefully when port communication is lost
- Correctly parses the data frame from a Port Controller - Run startAcquisition for the port control devices - Modified language when unable to acquire the communication lock
1 parent 15646f5 commit 9bbfae1

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

Source/Devices/PortController.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,19 @@ void PortController::processFrames()
6767
const GenericScopedLock<CriticalSection> frameLock(frameArray.getLock());
6868
oni_frame_t* frame = frameArray.removeAndReturn(0);
6969

70-
int16_t* dataPtr = (int16_t*)frame->data;
70+
int8_t* dataPtr = (int8_t*)frame->data;
7171

72-
int dataOffset = 4;
72+
int dataOffset = 8;
7373

74-
PortStatusCode code = (PortStatusCode) *(int8_t*)(dataPtr + dataOffset);
74+
uint32_t code = (uint32_t) *(dataPtr + dataOffset);
75+
uint32_t data = (uint32_t) *(dataPtr + dataOffset + 1);
7576

76-
errorFlag = ((uint32_t)code & LINKSTATE_SL) == 0;
77+
if (code & (uint32_t)PortStatusCode::SerdesLock)
78+
errorFlag = ((uint32_t)data & LINKSTATE_SL) == 0;
7779

7880
oni_destroy_frame(frame);
7981

80-
if (errorFlag)
81-
{
82-
LOGE("Port status changed and indicated an error occurred. Port status code is " + String((uint32_t)code))
83-
return;
84-
}
82+
LOGE("Port status changed for " + getName() + ". Port status code is " + String((uint32_t)code));
8583
}
8684
}
8785

@@ -100,7 +98,7 @@ DiscoveryParameters PortController::getHeadstageDiscoveryParameters(String heads
10098
return DiscoveryParameters();
10199
}
102100

103-
bool PortController::configureVoltage(float voltage) const
101+
bool PortController::configureVoltage(float voltage)
104102
{
105103
if (ctx == NULL) return false;
106104

@@ -129,15 +127,15 @@ bool PortController::configureVoltage(float voltage) const
129127
return false;
130128
}
131129

132-
void PortController::setVoltageOverride(float voltage, bool waitToSettle) const
130+
void PortController::setVoltageOverride(float voltage, bool waitToSettle)
133131
{
134132
if (ctx == NULL) return;
135133

136134
ONI_OK(oni_write_reg(ctx, (oni_dev_idx_t)port, (oni_reg_addr_t)PortControllerRegister::PORTVOLTAGE, (oni_reg_val_t)(voltage * 10)));
137135
if (waitToSettle) sleep_for(std::chrono::milliseconds(500));
138136
}
139137

140-
void PortController::setVoltage(float voltage) const
138+
void PortController::setVoltage(float voltage)
141139
{
142140
if (ctx == NULL) return;
143141

Source/Devices/PortController.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ class PortController : public OnixDevice
102102

103103
void updateDiscoveryParameters(DiscoveryParameters parameters);
104104

105-
bool configureVoltage(float voltage = defaultVoltage) const;
105+
bool configureVoltage(float voltage = defaultVoltage);
106106

107107
/** Sets the voltage to the given value, after setting the voltage to zero */
108-
void setVoltage(float voltage) const;
108+
void setVoltage(float voltage);
109109

110110
/** Overrides the voltage setting and directly sets it to the given voltage */
111-
void setVoltageOverride(float voltage, bool waitToSettle = true) const;
111+
void setVoltageOverride(float voltage, bool waitToSettle = true);
112112

113113
bool checkLinkState() const;
114114

Source/OnixSource.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,6 @@ bool OnixSource::isReady()
461461

462462
bool OnixSource::startAcquisition()
463463
{
464-
startThread();
465-
466464
frameReader.reset();
467465

468466
Array<OnixDevice*> devices;
@@ -475,16 +473,18 @@ bool OnixSource::startAcquisition()
475473
devices.add(portA.get());
476474
devices.add(portB.get());
477475

478-
frameReader = std::make_unique<FrameReader>(devices, context.get());
479-
frameReader->startThread();
480-
481-
for (auto source : sources)
476+
for (auto source : devices)
482477
{
483478
if (!source->isEnabled()) continue;
484479

485480
source->startAcquisition();
486481
}
487482

483+
frameReader = std::make_unique<FrameReader>(devices, context.get());
484+
frameReader->startThread();
485+
486+
startThread();
487+
488488
return true;
489489
}
490490

@@ -496,8 +496,8 @@ bool OnixSource::stopAcquisition()
496496
if (frameReader->isThreadRunning())
497497
frameReader->signalThreadShouldExit();
498498

499-
waitForThreadToExit(2000);
500-
frameReader->waitForThreadToExit(1000);
499+
if (!portA->getErrorFlag() && !portB->getErrorFlag())
500+
waitForThreadToExit(2000);
501501

502502
if (devicesFound)
503503
{

Source/OnixSourceEditor.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,29 @@ void OnixSourceEditor::buttonClicked(Button* b)
127127
{
128128
if (!thread->configurePortVoltage(PortName::PortA, portVoltageValueA->getText()))
129129
{
130-
CoreServices::sendStatusMessage("Unable to set port voltage for Port A.");
130+
CoreServices::sendStatusMessage("Unable to acquire communication lock on Port A.");
131131
connectButton->setToggleState(false, true);
132132
return;
133133
}
134134
}
135+
else
136+
{
137+
thread->setPortVoltage(PortName::PortA, 0);
138+
}
135139

136140
if (isHeadstageSelected(PortName::PortB))
137141
{
138142
if (!thread->configurePortVoltage(PortName::PortB, portVoltageValueB->getText()))
139143
{
140-
CoreServices::sendStatusMessage("Unable to set port voltage for Port B.");
144+
CoreServices::sendStatusMessage("Unable to acquire communication lock on Port B.");
141145
connectButton->setToggleState(false, true);
142146
return;
143147
}
144148
}
149+
else
150+
{
151+
thread->setPortVoltage(PortName::PortB, 0);
152+
}
145153

146154
thread->initializeDevices(true);
147155
canvas->refreshTabs();

0 commit comments

Comments
 (0)