mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-21 06:13:41 +00:00
split device info and status protocol messages
This commit is contained in:
parent
37d8474260
commit
c6ef075f4f
22 changed files with 248 additions and 204 deletions
|
|
@ -117,7 +117,7 @@ inline void App_Process() {
|
|||
sweepActive = VNA::Setup(recv_packet.settings);
|
||||
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||
break;
|
||||
case Protocol::PacketType::ManualControl:
|
||||
case Protocol::PacketType::ManualControlV1:
|
||||
sweepActive = false;
|
||||
last_measure_packet = recv_packet;
|
||||
Manual::Setup(recv_packet.manual);
|
||||
|
|
@ -145,12 +145,21 @@ inline void App_Process() {
|
|||
SA::Setup(recv_packet.spectrumSettings);
|
||||
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||
break;
|
||||
case Protocol::PacketType::RequestDeviceInfo:
|
||||
case Protocol::PacketType::RequestDeviceInfo: {
|
||||
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||
Protocol::PacketInfo p;
|
||||
p.type = Protocol::PacketType::DeviceInfo;
|
||||
HW::fillDeviceInfo(&p.info);
|
||||
p.info = HW::Info;
|
||||
Communication::Send(p);
|
||||
}
|
||||
break;
|
||||
case Protocol::PacketType::RequestDeviceStatus: {
|
||||
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
|
||||
Protocol::PacketInfo p;
|
||||
p.type = Protocol::PacketType::DeviceStatusV1;
|
||||
HW::getDeviceStatus(&p.statusV1);
|
||||
Communication::Send(p);
|
||||
}
|
||||
break;
|
||||
case Protocol::PacketType::SetIdle:
|
||||
HW::SetMode(HW::Mode::Idle);
|
||||
|
|
|
|||
|
|
@ -91,8 +91,9 @@ uint16_t Protocol::EncodePacket(const PacketInfo &packet, uint8_t *dest, uint16_
|
|||
case PacketType::SweepSettings: payload_size = sizeof(packet.settings); break;
|
||||
case PacketType::Reference: payload_size = sizeof(packet.reference); break;
|
||||
case PacketType::DeviceInfo: payload_size = sizeof(packet.info); break;
|
||||
case PacketType::Status: payload_size = sizeof(packet.status); break;
|
||||
case PacketType::ManualControl: payload_size = sizeof(packet.manual); break;
|
||||
case PacketType::DeviceStatusV1: payload_size = sizeof(packet.statusV1); break;
|
||||
case PacketType::ManualStatusV1: payload_size = sizeof(packet.manualStatusV1); break;
|
||||
case PacketType::ManualControlV1: payload_size = sizeof(packet.manual); break;
|
||||
case PacketType::FirmwarePacket: payload_size = sizeof(packet.firmware); break;
|
||||
case PacketType::Generator: payload_size = sizeof(packet.generator); break;
|
||||
case PacketType::SpectrumAnalyzerSettings: payload_size = sizeof(packet.spectrumSettings); break;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Protocol {
|
||||
|
||||
static constexpr uint16_t Version = 9;
|
||||
static constexpr uint16_t Version = 10;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
|
|
@ -50,17 +50,8 @@ using DeviceInfo = struct _deviceInfo {
|
|||
uint8_t FW_major;
|
||||
uint8_t FW_minor;
|
||||
uint8_t FW_patch;
|
||||
uint8_t hardware_version;
|
||||
char HW_Revision;
|
||||
uint8_t extRefAvailable:1;
|
||||
uint8_t extRefInUse:1;
|
||||
uint8_t FPGA_configured:1;
|
||||
uint8_t source_locked:1;
|
||||
uint8_t LO1_locked:1;
|
||||
uint8_t ADC_overload:1;
|
||||
uint8_t unlevel:1;
|
||||
uint8_t temp_source;
|
||||
uint8_t temp_LO1;
|
||||
uint8_t temp_MCU;
|
||||
uint64_t limits_minFreq;
|
||||
uint64_t limits_maxFreq;
|
||||
uint32_t limits_minIFBW;
|
||||
|
|
@ -74,7 +65,21 @@ using DeviceInfo = struct _deviceInfo {
|
|||
uint64_t limits_maxFreqHarmonic;
|
||||
};
|
||||
|
||||
using ManualStatus = struct _manualstatus {
|
||||
using DeviceStatusV1 = struct _deviceStatusV1 {
|
||||
uint8_t extRefAvailable:1;
|
||||
uint8_t extRefInUse:1;
|
||||
uint8_t FPGA_configured:1;
|
||||
uint8_t source_locked:1;
|
||||
uint8_t LO1_locked:1;
|
||||
uint8_t ADC_overload:1;
|
||||
uint8_t unlevel:1;
|
||||
uint8_t temp_source;
|
||||
uint8_t temp_LO1;
|
||||
uint8_t temp_MCU;
|
||||
};
|
||||
|
||||
|
||||
using ManualStatusV1 = struct _manualstatusV1 {
|
||||
int16_t port1min, port1max;
|
||||
int16_t port2min, port2max;
|
||||
int16_t refmin, refmax;
|
||||
|
|
@ -87,7 +92,7 @@ using ManualStatus = struct _manualstatus {
|
|||
uint8_t LO_locked :1;
|
||||
};
|
||||
|
||||
using ManualControl = struct _manualControl {
|
||||
using ManualControlV1 = struct _manualControlV1 {
|
||||
// Highband Source
|
||||
uint8_t SourceHighCE :1;
|
||||
uint8_t SourceHighRFEN :1;
|
||||
|
|
@ -170,8 +175,8 @@ enum class PacketType : uint8_t {
|
|||
None = 0,
|
||||
Datapoint = 1,
|
||||
SweepSettings = 2,
|
||||
Status = 3,
|
||||
ManualControl = 4,
|
||||
ManualStatusV1 = 3,
|
||||
ManualControlV1 = 4,
|
||||
DeviceInfo = 5,
|
||||
FirmwarePacket = 6,
|
||||
Ack = 7,
|
||||
|
|
@ -192,6 +197,8 @@ enum class PacketType : uint8_t {
|
|||
FrequencyCorrection = 22,
|
||||
RequestAcquisitionFrequencySettings = 23,
|
||||
AcquisitionFrequencySettings = 24,
|
||||
DeviceStatusV1 = 25,
|
||||
RequestDeviceStatus = 26,
|
||||
};
|
||||
|
||||
using PacketInfo = struct _packetinfo {
|
||||
|
|
@ -201,10 +208,11 @@ using PacketInfo = struct _packetinfo {
|
|||
SweepSettings settings;
|
||||
ReferenceSettings reference;
|
||||
GeneratorSettings generator;
|
||||
DeviceStatusV1 statusV1;
|
||||
DeviceInfo info;
|
||||
ManualControl manual;
|
||||
ManualControlV1 manual;
|
||||
FirmwarePacket firmware;
|
||||
ManualStatus status;
|
||||
ManualStatusV1 manualStatusV1;
|
||||
SpectrumAnalyzerSettings spectrumSettings;
|
||||
SpectrumAnalyzerResult spectrumResult;
|
||||
AmplitudeCorrectionPoint amplitudePoint;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ void Generator::Setup(Protocol::GeneratorSettings g) {
|
|||
HW::SetIdle();
|
||||
return;
|
||||
}
|
||||
Protocol::ManualControl m;
|
||||
Protocol::ManualControlV1 m;
|
||||
// LOs not required
|
||||
m.LO1CE = 0;
|
||||
m.LO1Frequency = 1000000000;
|
||||
|
|
|
|||
|
|
@ -299,9 +299,7 @@ void HW::SetOutputUnlevel(bool unlev) {
|
|||
unlevel = unlev;
|
||||
}
|
||||
|
||||
void HW::fillDeviceInfo(Protocol::DeviceInfo *info, bool updateEvenWhenBusy) {
|
||||
// copy constant default values
|
||||
memcpy(info, &HW::Info, sizeof(HW::Info));
|
||||
void HW::getDeviceStatus(Protocol::DeviceStatusV1 *status, bool updateEvenWhenBusy) {
|
||||
if(activeMode == Mode::Idle || updateEvenWhenBusy) {
|
||||
// updating values from FPGA allowed
|
||||
|
||||
|
|
@ -318,21 +316,21 @@ void HW::fillDeviceInfo(Protocol::DeviceInfo *info, bool updateEvenWhenBusy) {
|
|||
if(limits.P1min < -ADC_LIMIT || limits.P1max > ADC_LIMIT
|
||||
|| limits.P2min < -ADC_LIMIT || limits.P2max > ADC_LIMIT
|
||||
|| limits.Rmin < -ADC_LIMIT || limits.Rmax > ADC_LIMIT) {
|
||||
info->ADC_overload = true;
|
||||
status->ADC_overload = true;
|
||||
} else {
|
||||
info->ADC_overload = false;
|
||||
status->ADC_overload = false;
|
||||
}
|
||||
auto status = FPGA::GetStatus();
|
||||
info->LO1_locked = (status & (int) FPGA::Interrupt::LO1Unlock) ? 0 : 1;
|
||||
info->source_locked = (status & (int) FPGA::Interrupt::SourceUnlock) ? 0 : 1;
|
||||
info->extRefAvailable = Ref::available();
|
||||
info->extRefInUse = extRefInUse;
|
||||
info->unlevel = unlevel;
|
||||
info->temp_LO1 = tempLO;
|
||||
info->temp_source = tempSource;
|
||||
auto FPGA_status = FPGA::GetStatus();
|
||||
status->LO1_locked = (FPGA_status & (int) FPGA::Interrupt::LO1Unlock) ? 0 : 1;
|
||||
status->source_locked = (FPGA_status & (int) FPGA::Interrupt::SourceUnlock) ? 0 : 1;
|
||||
status->extRefAvailable = Ref::available();
|
||||
status->extRefInUse = extRefInUse;
|
||||
status->unlevel = unlevel;
|
||||
status->temp_LO1 = tempLO;
|
||||
status->temp_source = tempSource;
|
||||
FPGA::ResetADCLimits();
|
||||
}
|
||||
info->temp_MCU = STM::getTemperature();
|
||||
status->temp_MCU = STM::getTemperature();
|
||||
}
|
||||
|
||||
bool HW::Ref::available() {
|
||||
|
|
|
|||
|
|
@ -70,17 +70,8 @@ static constexpr Protocol::DeviceInfo Info = {
|
|||
.FW_major = FW_MAJOR,
|
||||
.FW_minor = FW_MINOR,
|
||||
.FW_patch = FW_PATCH,
|
||||
.hardware_version = 1,
|
||||
.HW_Revision = HW_REVISION,
|
||||
.extRefAvailable = 0,
|
||||
.extRefInUse = 0,
|
||||
.FPGA_configured = 0,
|
||||
.source_locked = 0,
|
||||
.LO1_locked = 0,
|
||||
.ADC_overload = 0,
|
||||
.unlevel = 0,
|
||||
.temp_source = 0,
|
||||
.temp_LO1 = 0,
|
||||
.temp_MCU = 0,
|
||||
.limits_minFreq = 0,
|
||||
.limits_maxFreq = 6000000000,
|
||||
.limits_minIFBW = DefaultADCSamplerate / MaxSamples,
|
||||
|
|
@ -120,7 +111,7 @@ using AmplitudeSettings = struct _amplitudeSettings {
|
|||
AmplitudeSettings GetAmplitudeSettings(int16_t cdbm, uint64_t freq = 0, bool applyCorrections = false, bool port2 = false);
|
||||
|
||||
bool GetTemps(uint8_t *source, uint8_t *lo);
|
||||
void fillDeviceInfo(Protocol::DeviceInfo *info, bool updateEvenWhenBusy = false);
|
||||
void getDeviceStatus(Protocol::DeviceStatusV1 *status, bool updateEvenWhenBusy = false);
|
||||
namespace Ref {
|
||||
bool available();
|
||||
bool usingExternal();
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
static bool active = false;
|
||||
static uint32_t samples;
|
||||
static Protocol::ManualStatus status;
|
||||
static Protocol::ManualStatusV1 status;
|
||||
|
||||
using namespace HWHAL;
|
||||
|
||||
void Manual::Setup(Protocol::ManualControl m) {
|
||||
void Manual::Setup(Protocol::ManualControlV1 m) {
|
||||
HW::SetMode(HW::Mode::Manual);
|
||||
samples = m.Samples;
|
||||
FPGA::AbortSweep();
|
||||
|
|
@ -99,38 +99,38 @@ void Manual::Work() {
|
|||
return;
|
||||
}
|
||||
Protocol::PacketInfo p;
|
||||
p.type = Protocol::PacketType::Status;
|
||||
p.status = status;
|
||||
p.type = Protocol::PacketType::ManualStatusV1;
|
||||
p.manualStatusV1 = status;
|
||||
uint16_t isr_flags = FPGA::GetStatus();
|
||||
if (!(isr_flags & 0x0002)) {
|
||||
p.status.source_locked = 1;
|
||||
p.manualStatusV1.source_locked = 1;
|
||||
} else {
|
||||
p.status.source_locked = 0;
|
||||
p.manualStatusV1.source_locked = 0;
|
||||
}
|
||||
if (!(isr_flags & 0x0001)) {
|
||||
p.status.LO_locked = 1;
|
||||
p.manualStatusV1.LO_locked = 1;
|
||||
} else {
|
||||
p.status.LO_locked = 0;
|
||||
p.manualStatusV1.LO_locked = 0;
|
||||
}
|
||||
auto limits = FPGA::GetADCLimits();
|
||||
FPGA::ResetADCLimits();
|
||||
p.status.port1min = limits.P1min;
|
||||
p.status.port1max = limits.P1max;
|
||||
p.status.port2min = limits.P2min;
|
||||
p.status.port2max = limits.P2max;
|
||||
p.status.refmin = limits.Rmin;
|
||||
p.status.refmax = limits.Rmax;
|
||||
HW::GetTemps(&p.status.temp_source, &p.status.temp_LO);
|
||||
p.manualStatusV1.port1min = limits.P1min;
|
||||
p.manualStatusV1.port1max = limits.P1max;
|
||||
p.manualStatusV1.port2min = limits.P2min;
|
||||
p.manualStatusV1.port2max = limits.P2max;
|
||||
p.manualStatusV1.refmin = limits.Rmin;
|
||||
p.manualStatusV1.refmax = limits.Rmax;
|
||||
HW::GetTemps(&p.manualStatusV1.temp_source, &p.manualStatusV1.temp_LO);
|
||||
Communication::Send(p);
|
||||
HW::Ref::update();
|
||||
Protocol::PacketInfo packet;
|
||||
packet.type = Protocol::PacketType::DeviceInfo;
|
||||
packet.type = Protocol::PacketType::DeviceStatusV1;
|
||||
// Enable PLL chips for temperature reading
|
||||
bool srcEn = FPGA::IsEnabled(FPGA::Periphery::SourceChip);
|
||||
bool LOEn = FPGA::IsEnabled(FPGA::Periphery::LO1Chip);
|
||||
FPGA::Enable(FPGA::Periphery::SourceChip);
|
||||
FPGA::Enable(FPGA::Periphery::LO1Chip);
|
||||
HW::fillDeviceInfo(&packet.info, true);
|
||||
HW::getDeviceStatus(&packet.statusV1, true);
|
||||
// restore PLL state
|
||||
FPGA::Enable(FPGA::Periphery::SourceChip, srcEn);
|
||||
FPGA::Enable(FPGA::Periphery::LO1Chip, LOEn);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
namespace Manual {
|
||||
|
||||
void Setup(Protocol::ManualControl m);
|
||||
void Setup(Protocol::ManualControlV1 m);
|
||||
bool MeasurementDone(const FPGA::SamplingResult &result);
|
||||
void Work();
|
||||
void Stop();
|
||||
|
|
|
|||
|
|
@ -385,8 +385,8 @@ void SA::Work() {
|
|||
// send device info every nth point
|
||||
FPGA::Enable(FPGA::Periphery::SourceChip); // needs to enable the chip to get a valid temperature reading
|
||||
Protocol::PacketInfo packet;
|
||||
packet.type = Protocol::PacketType::DeviceInfo;
|
||||
HW::fillDeviceInfo(&packet.info, true);
|
||||
packet.type = Protocol::PacketType::DeviceStatusV1;
|
||||
HW::getDeviceStatus(&packet.statusV1, true);
|
||||
FPGA::Disable(FPGA::Periphery::SourceChip);
|
||||
Communication::Send(packet);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -367,8 +367,8 @@ void VNA::Work() {
|
|||
HW::Ref::update();
|
||||
// Compile info packet
|
||||
Protocol::PacketInfo packet;
|
||||
packet.type = Protocol::PacketType::DeviceInfo;
|
||||
HW::fillDeviceInfo(&packet.info, true);
|
||||
packet.type = Protocol::PacketType::DeviceStatusV1;
|
||||
HW::getDeviceStatus(&packet.statusV1, true);
|
||||
Communication::Send(packet);
|
||||
// do not reset unlevel flag here, as it is calculated only once at the setup of the sweep
|
||||
// Start next sweep
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue