From 77fb8280f18e7b00ddb9e9ae109f4813e4a26662 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 5 Jan 2022 12:55:21 +0100 Subject: [PATCH] warning in using abs for unsigned (missing packets) in rxr, but also trying to print to signed in command line (so as not to change api atm) --- slsDetectorSoftware/include/sls/Detector.h | 4 ++- slsDetectorSoftware/src/CmdProxy.cpp | 35 ++++++++++++++++++++++ slsDetectorSoftware/src/CmdProxy.h | 3 +- slsReceiverSoftware/src/Implementation.cpp | 14 ++++++--- 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 4667a9c40..8096b3cbc 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -588,7 +588,9 @@ class Detector { Result getFramesCaught(Positions pos = {}) const; - /** Gets the number of missing packets for each port in receiver. */ + /** Gets the number of missing packets for each port in receiver. + * Troubleshoot: If they are large numbers, convert it to signed to get + * number of access packets received */ Result> getNumMissingPackets(Positions pos = {}) const; diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 09b2bac7a..3181e08be 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1,3 +1,4 @@ + // SPDX-License-Identifier: LGPL-3.0-or-other // Copyright (C) 2021 Contributors to the SLS Detector Package #include "CmdProxy.h" @@ -1273,6 +1274,40 @@ std::string CmdProxy::DetectorStatus(int action) { return os.str(); } +std::string CmdProxy::RxMissingPackets(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + os << "Number of missing packets for each port in receiver. If " + "negative, they are packets in excess. " + << '\n'; + } else if (action == defs::GET_ACTION) { + if (!args.empty()) { + WrongNumberOfParameters(0); + } + auto tmp = det->getNumMissingPackets(std::vector{det_id}); + // convert to signed missing packets (to get excess) + /* + Result> mp(tmp.size()); + for (unsigned int i = 0; i < mp.size(); ++i) { + mp[i] = static_cast(tmp[i]); + } + */ + + Result> mp; + for (auto val : tmp) { + mp.push_back(static_cast(val)); + } + + os << OutString(mp) << '\n'; + } else if (action == defs::PUT_ACTION) { + throw sls::RuntimeError("Cannot put"); + } else { + throw sls::RuntimeError("Unknown action"); + } + return os.str(); +} + std::string CmdProxy::Scan(int action) { std::ostringstream os; os << cmd << ' '; diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 70b47cd0c..0e3c544da 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -859,7 +859,7 @@ class CmdProxy { {"rx_status", &CmdProxy::ReceiverStatus}, {"status", &CmdProxy::DetectorStatus}, {"rx_framescaught", &CmdProxy::rx_framescaught}, - {"rx_missingpackets", &CmdProxy::rx_missingpackets}, + {"rx_missingpackets", &CmdProxy::RxMissingPackets}, {"nextframenumber", &CmdProxy::nextframenumber}, {"trigger", &CmdProxy::Trigger}, {"scan", &CmdProxy::Scan}, @@ -1128,6 +1128,7 @@ class CmdProxy { /* acquisition */ std::string ReceiverStatus(int action); std::string DetectorStatus(int action); + std::string RxMissingPackets(int action); std::string Scan(int action); std::string Trigger(int action); /* Network Configuration (Detector<->Receiver) */ diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index a768c9a30..298e17dbc 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -595,18 +595,24 @@ void Implementation::stopReceiver() { LOG(logINFO) << "Status: " << sls::ToString(status); { // statistics - std::vector mp = getNumMissingPackets(); + auto tmp = getNumMissingPackets(); + // convert to signed missing packets (to get excess) + std::vector mp; + for (auto val : tmp) { + mp.push_back(static_cast(val)); + } + // print summary uint64_t tot = 0; for (int i = 0; i < numThreads; i++) { int nf = dataProcessor[i]->GetNumCompleteFramesCaught(); tot += nf; - std::string mpMessage = std::to_string((int64_t)mp[i]); - if ((int64_t)mp[i] < 0) { + std::string mpMessage = std::to_string(mp[i]); + if (mp[i] < 0) { mpMessage = std::to_string(abs(mp[i])) + std::string(" (Extra)"); } - TLogLevel lev = (((int64_t)mp[i]) > 0) ? logINFORED : logINFOGREEN; + TLogLevel lev = ((mp[i]) > 0) ? logINFORED : logINFOGREEN; LOG(lev) << // udp port number could be the second if selected interface is // 2 for jungfrau