implement optional device status updates

This commit is contained in:
Andre Dunford 2022-12-05 22:29:33 -08:00
parent 35cdfa5922
commit 9b38a1fc3d
8 changed files with 49 additions and 16 deletions

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,6 +123,7 @@ void Manual::Work() {
HW::GetTemps(&p.manualStatusV1.temp_source, &p.manualStatusV1.temp_LO);
Communication::Send(p);
HW::Ref::update();
if(HW::getStatusUpdateFlag()) {
Protocol::PacketInfo packet;
packet.type = Protocol::PacketType::DeviceStatusV1;
// Enable PLL chips for temperature reading
@ -135,6 +136,8 @@ void Manual::Work() {
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;
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();