1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-08-10 13:33:49 -04:00

LimeSDR REST API: support GPIO

This commit is contained in:
f4exb
2018-11-29 01:21:44 +01:00
parent f96978d196
commit 5319eac2ff
25 changed files with 546 additions and 12 deletions
@@ -599,6 +599,17 @@ bool LimeSDROutput::handleMessage(const Message& message)
return true;
}
else if (DeviceLimeSDRShared::MsgReportGPIOChange::match(message))
{
DeviceLimeSDRShared::MsgReportGPIOChange& report = (DeviceLimeSDRShared::MsgReportGPIOChange&) message;
m_settings.m_gpioDir = report.getGPIODir();
m_settings.m_gpioPins = report.getGPIOPins();
// no GUI for the moment only REST API
return true;
}
else if (MsgGetStreamInfo::match(message))
{
// qDebug() << "LimeSDROutput::handleMessage: MsgGetStreamInfo";
@@ -700,6 +711,7 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo
bool forwardChangeTxDSP = false;
bool forwardChangeAllDSP = false;
bool forwardClockSource = false;
bool forwardGPIOChange = false;
bool ownThreadWasRunning = false;
bool doCalibration = false;
bool doLPCalibration = false;
@@ -916,6 +928,32 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo
}
}
if ((m_settings.m_gpioDir != settings.m_gpioDir) || force)
{
if (LMS_GPIODirWrite(m_deviceShared.m_deviceParams->getDevice(), &settings.m_gpioDir, 1) < 0)
{
qCritical("LimeSDROutput::applySettings: could not set GPIO directions to %u", settings.m_gpioDir);
}
else
{
forwardGPIOChange = true;
qDebug("LimeSDROutput::applySettings: GPIO directions set to %u", settings.m_gpioDir);
}
}
if ((m_settings.m_gpioPins != settings.m_gpioPins) || force)
{
if (LMS_GPIOWrite(m_deviceShared.m_deviceParams->getDevice(), &settings.m_gpioPins, 1) < 0)
{
qCritical("LimeSDROutput::applySettings: could not set GPIO pins to %u", settings.m_gpioPins);
}
else
{
forwardGPIOChange = true;
qDebug("LimeSDROutput::applySettings: GPIO pins set to %u", settings.m_gpioPins);
}
}
m_settings = settings;
double clockGenFreqAfter;
@@ -1072,6 +1110,30 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo
}
}
if (forwardGPIOChange)
{
const std::vector<DeviceSourceAPI*>& sourceBuddies = m_deviceAPI->getSourceBuddies();
std::vector<DeviceSourceAPI*>::const_iterator itSource = sourceBuddies.begin();
for (; itSource != sourceBuddies.end(); ++itSource)
{
DeviceLimeSDRShared::MsgReportGPIOChange *report = DeviceLimeSDRShared::MsgReportGPIOChange::create(
m_settings.m_gpioDir, m_settings.m_gpioPins);
(*itSource)->getSampleSourceInputMessageQueue()->push(report);
}
// send to sink buddies
const std::vector<DeviceSinkAPI*>& sinkBuddies = m_deviceAPI->getSinkBuddies();
std::vector<DeviceSinkAPI*>::const_iterator itSink = sinkBuddies.begin();
for (; itSink != sinkBuddies.end(); ++itSink)
{
DeviceLimeSDRShared::MsgReportGPIOChange *report = DeviceLimeSDRShared::MsgReportGPIOChange::create(
m_settings.m_gpioDir, m_settings.m_gpioPins);
(*itSink)->getSampleSinkInputMessageQueue()->push(report);
}
}
QLocale loc;
qDebug().noquote() << "LimeSDROutput::applySettings: center freq: " << m_settings.m_centerFrequency << " Hz"
@@ -1092,6 +1154,8 @@ bool LimeSDROutput::applySettings(const LimeSDROutputSettings& settings, bool fo
<< " m_antennaPath: " << m_settings.m_antennaPath
<< " m_extClock: " << m_settings.m_extClock
<< " m_extClockFreq: " << loc.toString(m_settings.m_extClockFreq)
<< " m_gpioDir: " << m_settings.m_gpioDir
<< " m_gpioPins: " << m_settings.m_gpioPins
<< " force: " << force
<< " forceNCOFrequency: " << forceNCOFrequency
<< " doCalibration: " << doCalibration
@@ -1165,6 +1229,12 @@ int LimeSDROutput::webapiSettingsPutPatch(
if (deviceSettingsKeys.contains("transverterMode")) {
settings.m_transverterMode = response.getLimeSdrOutputSettings()->getTransverterMode() != 0;
}
if (deviceSettingsKeys.contains("gpioDir")) {
settings.m_gpioDir = response.getLimeSdrOutputSettings()->getGpioDir() & 0xFF;
}
if (deviceSettingsKeys.contains("gpioPins")) {
settings.m_gpioPins = response.getLimeSdrOutputSettings()->getGpioPins() & 0xFF;
}
MsgConfigureLimeSDR *msg = MsgConfigureLimeSDR::create(settings, force);
m_inputMessageQueue.push(msg);
@@ -1206,6 +1276,8 @@ void LimeSDROutput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& r
response.getLimeSdrOutputSettings()->setNcoFrequency(settings.m_ncoFrequency);
response.getLimeSdrOutputSettings()->setTransverterDeltaFrequency(settings.m_transverterDeltaFrequency);
response.getLimeSdrOutputSettings()->setTransverterMode(settings.m_transverterMode ? 1 : 0);
response.getLimeSdrOutputSettings()->setGpioDir(settings.m_gpioDir);
response.getLimeSdrOutputSettings()->setGpioPins(settings.m_gpioPins);
}
int LimeSDROutput::webapiRunGet(
@@ -1240,6 +1312,8 @@ void LimeSDROutput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& respo
{
bool success = false;
double temp = 0.0;
uint8_t gpioDir = 0;
uint8_t gpioPins = 0;
lms_stream_status_t status;
status.active = false;
status.fifoFilledCount = 0;
@@ -1262,9 +1336,14 @@ void LimeSDROutput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& respo
response.getLimeSdrOutputReport()->setLinkRate(status.linkRate);
response.getLimeSdrOutputReport()->setHwTimestamp(status.timestamp);
if (m_deviceShared.m_deviceParams->getDevice()) {
if (m_deviceShared.m_deviceParams->getDevice())
{
LMS_GetChipTemperature(m_deviceShared.m_deviceParams->getDevice(), 0, &temp);
LMS_GPIODirRead(m_deviceShared.m_deviceParams->getDevice(), &gpioDir, 1);
LMS_GPIORead(m_deviceShared.m_deviceParams->getDevice(), &gpioPins, 1);
}
response.getLimeSdrOutputReport()->setTemperature(temp);
response.getLimeSdrOutputReport()->setGpioDir(gpioDir);
response.getLimeSdrOutputReport()->setGpioPins(gpioPins);
}