Merge pull request #168 from andredunford/update_dev_status

implement optional device status updates
This commit is contained in:
jankae 2022-12-07 07:58:37 +01:00 committed by GitHub
commit 83e9817415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 57 additions and 16 deletions

View File

@ -248,6 +248,8 @@ The following packet types are available:
27 & VNADatapoint & D$\rightarrow$H & Sent for every sampled frequency within the sweep in VNA mode &None \\
28 & SetTrigger & D$\leftrightarrow$H & Updates the trigger status for synchronization over USB & None\\
29 & ClearTrigger & D$\leftrightarrow$H & Updates the trigger status for synchronization over USB & None\\
30 & StopStatusUpdates & H$\rightarrow$D & Stops the automatic transmission of device status packets & None\\
31 & StartStatusUpdates & H$\rightarrow$D & Starts the automatic transmission of device status packets & None\\
\end{longtable}
\end{ThreePartTable}
An Ack is transmitted by the device for every received command after it has been handled successfully. If additional responses are triggered by the command, they are transmitted after this Ack.
@ -1010,4 +1012,10 @@ This packet is used when multiple devices are synchronized over USB and can be t
\subsection{ClearTrigger}
This packet is used when multiple devices are synchronized over USB and can be transmitted in both directions. It has no payload. Synchronized devices must be logically organized in a closed loop. When a ClearTrigger packet is received from any devices in the loop it must be passed on to the next device in the loop.
\subsection{StopStatusUpdates}
This packet instructs the device to stop sending automatically scheduled DeviceStatusV1 packets. Device status can still be requested explicitly via RequestDeviceStatus packets.
\subsection{StartStatusUpdates}
This packet instructs the device to start sending automatically scheduled DeviceStatusV1 packets. This restores default update behaviour if a StopStatusUpdates packet has previously been sent.
\end{document}

View File

@ -173,6 +173,16 @@ inline void App_Process() {
Communication::Send(p);
}
break;
case Protocol::PacketType::StopStatusUpdates: {
HW::setStatusUpdateFlag(false);
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
}
break;
case Protocol::PacketType::StartStatusUpdates: {
HW::setStatusUpdateFlag(true);
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
}
break;
case Protocol::PacketType::SetIdle:
HW::SetMode(HW::Mode::Idle);
sweepActive = false;

View File

@ -123,6 +123,8 @@ uint16_t Protocol::EncodePacket(const PacketInfo &packet, uint8_t *dest, uint16_
case PacketType::RequestDeviceStatus:
case PacketType::SetTrigger:
case PacketType::ClearTrigger:
case PacketType::StopStatusUpdates:
case PacketType::StartStatusUpdates:
// no payload
break;
case PacketType::VNADatapoint: payload_size = packet.VNAdatapoint->requiredBufferSize(); break;

View File

@ -364,6 +364,8 @@ enum class PacketType : uint8_t {
VNADatapoint = 27,
SetTrigger = 28,
ClearTrigger = 29,
StopStatusUpdates = 30,
StartStatusUpdates = 31,
};
using PacketInfo = struct _packetinfo {

View File

@ -21,6 +21,8 @@ static bool extRefInUse = false;
HW::Mode activeMode;
static bool unlevel = false;
static bool StatusUpdateFlag = true;
static Protocol::ReferenceSettings ref;
static volatile uint64_t lastISR;
@ -438,8 +440,16 @@ uint64_t HW::getLastISRTimestamp() {
return lastISR;
}
bool HW::getStatusUpdateFlag(){
return StatusUpdateFlag;
}
void HW::setStatusUpdateFlag(bool flag){
StatusUpdateFlag = flag;
}
void HW::updateDeviceStatus() {
if(activeMode == Mode::Idle || activeMode == Mode::Generator) {
if(StatusUpdateFlag && (activeMode == Mode::Idle || activeMode == Mode::Generator)) {
static uint32_t last_update = 0;
if(HAL_GetTick() - last_update >= 1000) {
last_update = HAL_GetTick();

View File

@ -102,6 +102,10 @@ uint64_t getLastISRTimestamp();
void SetOutputUnlevel(bool unlev);
bool getStatusUpdateFlag();
void setStatusUpdateFlag(bool flag);
void updateDeviceStatus();
using AmplitudeSettings = struct _amplitudeSettings {

View File

@ -123,18 +123,21 @@ void Manual::Work() {
HW::GetTemps(&p.manualStatusV1.temp_source, &p.manualStatusV1.temp_LO);
Communication::Send(p);
HW::Ref::update();
Protocol::PacketInfo packet;
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::getDeviceStatus(&packet.statusV1, true);
// restore PLL state
FPGA::Enable(FPGA::Periphery::SourceChip, srcEn);
FPGA::Enable(FPGA::Periphery::LO1Chip, LOEn);
Communication::Send(packet);
if(HW::getStatusUpdateFlag()) {
Protocol::PacketInfo packet;
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::getDeviceStatus(&packet.statusV1, true);
// restore PLL state
FPGA::Enable(FPGA::Periphery::SourceChip, srcEn);
FPGA::Enable(FPGA::Periphery::LO1Chip, LOEn);
Communication::Send(packet);
}
// Trigger next status update
FPGA::StartSweep();
}

View File

@ -428,7 +428,7 @@ void SA::Work() {
// setup for next step
signalIDstep = 0;
if(pointCnt % 10 == 0) {
if(HW::getStatusUpdateFlag() && pointCnt % 10 == 0) {
// 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;

View File

@ -325,8 +325,10 @@ void VNA::Work() {
// Compile info packet
Protocol::PacketInfo packet;
packet.type = Protocol::PacketType::DeviceStatusV1;
HW::getDeviceStatus(&packet.statusV1, true);
Communication::Send(packet);
if(HW::getStatusUpdateFlag()) {
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
FPGA::StartSweep();