addd kernel version

This commit is contained in:
maliakal_d 2021-11-03 11:46:46 +01:00
parent 1da2761654
commit eff64f99f2
25 changed files with 111 additions and 41 deletions

View File

@ -19,7 +19,7 @@ This document describes the differences between vx.x.x and v6.0.0.
1. New or Changed Features 1. New or Changed Features
========================== ==========================
- kernelversion

View File

@ -224,6 +224,19 @@ class Detector(CppDetectorApi):
""" """
return ut.lhex(self.getDetectorServerVersion()) return ut.lhex(self.getDetectorServerVersion())
@property
@element
def kernelversion(self):
"""
Kernel version on the detector including time and date
Example
-------
>>> d.kernelversion
'#37 PREEMPT Thu Oct 13 14:51:04 CEST 2016'
"""
return self.getKernelVersion()
@property @property
def clientversion(self): def clientversion(self):
"""Client software version in format [YYMMDD] """Client software version in format [YYMMDD]
@ -1656,6 +1669,7 @@ class Detector(CppDetectorApi):
'client': self.clientversion, 'client': self.clientversion,
'firmware': self.firmwareversion, 'firmware': self.firmwareversion,
'detectorserver': self.detectorserverversion, 'detectorserver': self.detectorserverversion,
'kernel': self.kernelversion,
'receiver': self.rx_version} 'receiver': self.rx_version}
@property @property

View File

@ -67,6 +67,10 @@ void init_det(py::module &m) {
(Result<int64_t>(Detector::*)(sls::Positions) const) & (Result<int64_t>(Detector::*)(sls::Positions) const) &
Detector::getDetectorServerVersion, Detector::getDetectorServerVersion,
py::arg() = Positions{}) py::arg() = Positions{})
.def("getKernelVersion",
(Result<std::string>(Detector::*)(sls::Positions) const) &
Detector::getKernelVersion,
py::arg() = Positions{})
.def("getSerialNumber", .def("getSerialNumber",
(Result<int64_t>(Detector::*)(sls::Positions) const) & (Result<int64_t>(Detector::*)(sls::Positions) const) &
Detector::getSerialNumber, Detector::getSerialNumber,

View File

@ -101,7 +101,7 @@ void basictests() {
} }
// does check only if flag is 0 (by default), set by command line // does check only if flag is 0 (by default), set by command line
if ((!debugflag) && (!updateFlag) && if ((!debugflag) && (!updateFlag) &&
((checkKernelVersion() == FAIL) || (checkType() == FAIL) || ((validateKernelVersion(KERNEL_DATE_VRSN) == FAIL) || (checkType() == FAIL) ||
(testFpga() == FAIL) || (testBus() == FAIL))) { (testFpga() == FAIL) || (testBus() == FAIL))) {
sprintf(initErrorMessage, sprintf(initErrorMessage,
"Could not pass basic tests of FPGA and bus. Dangerous to " "Could not pass basic tests of FPGA and bus. Dangerous to "
@ -184,15 +184,6 @@ void basictests() {
#endif #endif
} }
int checkKernelVersion() {
#ifdef VIRTUAL
return OK;
#endif
char buf[255] = {0};
strcpy(buf, KERNEL_DATE_VRSN);
return validateKernelVersion(buf);
}
int checkType() { int checkType() {
#ifdef VIRTUAL #ifdef VIRTUAL
return OK; return OK;

View File

@ -96,7 +96,7 @@ void basictests() {
} }
// does check only if flag is 0 (by default), set by command line // does check only if flag is 0 (by default), set by command line
if ((!debugflag) && (!updateFlag) && if ((!debugflag) && (!updateFlag) &&
((checkKernelVersion() == FAIL) || (checkType() == FAIL) || ((validateKernelVersion(KERNEL_DATE_VRSN) == FAIL) || (checkType() == FAIL) ||
(testFpga() == FAIL) || (testBus() == FAIL))) { (testFpga() == FAIL) || (testBus() == FAIL))) {
strcpy(initErrorMessage, "Could not pass basic tests of FPGA and bus. " strcpy(initErrorMessage, "Could not pass basic tests of FPGA and bus. "
"Dangerous to continue.\n"); "Dangerous to continue.\n");
@ -177,15 +177,6 @@ void basictests() {
#endif #endif
} }
int checkKernelVersion() {
#ifdef VIRTUAL
return OK;
#endif
char buf[255] = {0};
strcpy(buf, KERNEL_DATE_VRSN);
return validateKernelVersion(buf);
}
int checkType() { int checkType() {
#ifdef VIRTUAL #ifdef VIRTUAL
return OK; return OK;

View File

@ -28,6 +28,8 @@ int getAbsPath(char *buf, size_t bufSize, char *fname);
int getTimeFromString(char *buf, time_t *result); int getTimeFromString(char *buf, time_t *result);
int getKernelVersion(char* retvals);
int validateKernelVersion(char *expectedVersion); int validateKernelVersion(char *expectedVersion);
void validate(int *ret, char *mess, int arg, int retval, char *modename, void validate(int *ret, char *mess, int arg, int retval, char *modename,

View File

@ -60,9 +60,7 @@ typedef struct udpStruct_s {
int isInitCheckDone(); int isInitCheckDone();
int getInitResult(char **mess); int getInitResult(char **mess);
void basictests(); void basictests();
#if defined(MYTHEN3D) || defined(GOTTHARD2D) int getKernelVersion(char* retvals);
int checkKernelVersion();
#endif
#if defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || \ #if defined(GOTTHARDD) || defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || \
defined(MOENCHD) || defined(MYTHEN3D) || defined(GOTTHARD2D) defined(MOENCHD) || defined(MYTHEN3D) || defined(GOTTHARD2D)
int checkType(); int checkType();

View File

@ -277,3 +277,4 @@ int get_udp_first_dest(int);
int set_udp_first_dest(int); int set_udp_first_dest(int);
int get_readout_speed(int); int get_readout_speed(int);
int set_readout_speed(int); int set_readout_speed(int);
int get_kernel_version(int);

View File

@ -96,28 +96,44 @@ int getTimeFromString(char *buf, time_t *result) {
return OK; return OK;
} }
int validateKernelVersion(char *expectedVersion) { int getKernelVersion(char* retvals) {
// extract kernel date string
struct utsname buf = {0}; struct utsname buf = {0};
if (uname(&buf) == -1) { if (uname(&buf) == -1) {
LOG(logERROR, ("Could not get kernel version\n")); strcpy(retvals, "Failed to get utsname structure from uname\n");
LOG(logERROR, (retvals));
return FAIL; return FAIL;
} }
strcpy(retvals, buf.version);
LOG(logINFOBLUE, ("Kernel Version: %s\n", retvals));
return OK;
}
int validateKernelVersion(char *expectedVersion) {
// extract kernel date string
char version[255] = {0};
if (getKernelVersion(version) == FAIL) {
LOG(logERROR, ("Could not validate kernel version\n"));
return FAIL;
}
LOG(logDEBUG, ("utsname.version:%s\n", version));
char currentVersion[255] = {0};
#ifdef VIRTUAL
strcpy(currentVersion, expectedVersion);
#else
// remove first word (#version number) // remove first word (#version number)
const char *ptr = strchr(buf.version, ' '); const char *ptr = strchr(version, ' ');
if (ptr == NULL) { if (ptr == NULL) {
LOG(logERROR, ("Could not parse kernel version\n")); LOG(logERROR, ("Could not parse kernel version\n"));
return FAIL; return FAIL;
} }
char output[255]; strcpy(currentVersion, version + (ptr - version + 1));
memset(output, 0, sizeof(output)); #endif
strcpy(output, buf.version + (ptr - buf.version + 1));
// convert kernel date string into time // convert kernel date string into time
time_t kernelDate; time_t kernelDate;
if (getTimeFromString(output, &kernelDate) == FAIL) { if (getTimeFromString(currentVersion, &kernelDate) == FAIL) {
LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", output)); LOG(logERROR, ("Could not parse retrieved kernel date, %s\n", currentVersion));
return FAIL; return FAIL;
} }
@ -133,11 +149,11 @@ int validateKernelVersion(char *expectedVersion) {
if (kernelDate < expDate) { if (kernelDate < expDate) {
LOG(logERROR, ("Kernel Version Incompatible (too old)! Expected: [%s], " LOG(logERROR, ("Kernel Version Incompatible (too old)! Expected: [%s], "
"Got [%s]\n", "Got [%s]\n",
expectedVersion, output)); expectedVersion, currentVersion));
return FAIL; return FAIL;
} }
LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", output, LOG(logINFOBLUE, ("Kernel Version Compatible: %s [min.: %s]\n", currentVersion,
expectedVersion)); expectedVersion));
return OK; return OK;
} }

View File

@ -193,7 +193,7 @@ int main(int argc, char *argv[]) {
memset(portCmd, 0, 256); memset(portCmd, 0, 256);
sprintf(portCmd, "-p%d", portno); sprintf(portCmd, "-p%d", portno);
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {
LOG(logINFOBLUE, ("i:%d argv[i]:%s\n", i, argv[i])); LOG(logDEBUG, ("i:%d argv[i]:%s\n", i, argv[i]));
// remove port argument (--port) and [value] // remove port argument (--port) and [value]
if (!strcasecmp(argv[i], "--port")) { if (!strcasecmp(argv[i], "--port")) {
++i; ++i;

View File

@ -414,6 +414,8 @@ void function_table() {
flist[F_SET_UDP_FIRST_DEST] = &set_udp_first_dest; flist[F_SET_UDP_FIRST_DEST] = &set_udp_first_dest;
flist[F_GET_READOUT_SPEED] = &get_readout_speed; flist[F_GET_READOUT_SPEED] = &get_readout_speed;
flist[F_SET_READOUT_SPEED] = &set_readout_speed; flist[F_SET_READOUT_SPEED] = &set_readout_speed;
flist[F_GET_KERNEL_VERSION] = &get_kernel_version;
// check // check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
LOG(logERROR, ("The last detector function enum has reached its " LOG(logERROR, ("The last detector function enum has reached its "
@ -9412,3 +9414,23 @@ int set_readout_speed(int file_des) {
#endif #endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
} }
int get_kernel_version(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
char retvals[MAX_STR_LENGTH];
memset(retvals, 0, MAX_STR_LENGTH);
LOG(logDEBUG1, ("Getting kernel version\n"));
// get only
ret = getKernelVersion(retvals);
if (ret == FAIL) {
snprintf(mess, MAX_STR_LENGTH,
"Could not get kernel version. %s\n", retvals);
LOG(logERROR, (mess));
} else {
LOG(logDEBUG1, ("kernel version: [%s]\n", retvals));
}
return Server_SendResult(file_des, OTHER, retvals, sizeof(retvals));
}

View File

@ -81,6 +81,8 @@ class Detector {
Result<int64_t> getDetectorServerVersion(Positions pos = {}) const; Result<int64_t> getDetectorServerVersion(Positions pos = {}) const;
Result<std::string> getKernelVersion(Positions pos = {}) const;
/* [Jungfrau][Gotthard][Mythen3][Gotthard2][CTB][Moench] */ /* [Jungfrau][Gotthard][Mythen3][Gotthard2][CTB][Moench] */
Result<int64_t> getSerialNumber(Positions pos = {}) const; Result<int64_t> getSerialNumber(Positions pos = {}) const;

View File

@ -275,7 +275,7 @@ std::string CmdProxy::Versions(int action) {
if (!args.empty()) { if (!args.empty()) {
WrongNumberOfParameters(0); WrongNumberOfParameters(0);
} }
auto t = det->getFirmwareVersion(); auto t = det->getFirmwareVersion(std::vector<int>{det_id});
os << "\nDetector Type: " << OutString(det->getDetectorType()) os << "\nDetector Type: " << OutString(det->getDetectorType())
<< "\nPackage Version: " << det->getPackageVersion() << std::hex << "\nPackage Version: " << det->getPackageVersion() << std::hex
<< "\nClient Version: 0x" << det->getClientVersion(); << "\nClient Version: 0x" << det->getClientVersion();
@ -285,10 +285,12 @@ std::string CmdProxy::Versions(int action) {
os << "\nFirmware Version: " << OutStringHex(t); os << "\nFirmware Version: " << OutStringHex(t);
} }
os << "\nDetector Server Version: " os << "\nDetector Server Version: "
<< OutStringHex(det->getDetectorServerVersion()); << OutStringHex(det->getDetectorServerVersion(std::vector<int>{det_id}));
os << "\nDetector Server Version: "
<< OutString(det->getKernelVersion({std::vector<int>{det_id}}));
if (det->getUseReceiverFlag().squash(true)) { if (det->getUseReceiverFlag().squash(true)) {
os << "\nReceiver Version: " os << "\nReceiver Version: "
<< OutStringHex(det->getReceiverVersion()); << OutStringHex(det->getReceiverVersion(std::vector<int>{det_id}));
} }
os << std::dec << '\n'; os << std::dec << '\n';
} else if (action == defs::PUT_ACTION) { } else if (action == defs::PUT_ACTION) {

View File

@ -767,6 +767,7 @@ class CmdProxy {
{"clientversion", &CmdProxy::ClientVersion}, {"clientversion", &CmdProxy::ClientVersion},
{"firmwareversion", &CmdProxy::FirmwareVersion}, {"firmwareversion", &CmdProxy::FirmwareVersion},
{"detectorserverversion", &CmdProxy::detectorserverversion}, {"detectorserverversion", &CmdProxy::detectorserverversion},
{"kernelversion", &CmdProxy::kernelversion},
{"rx_version", &CmdProxy::rx_version}, {"rx_version", &CmdProxy::rx_version},
{"serialnumber", &CmdProxy::serialnumber}, {"serialnumber", &CmdProxy::serialnumber},
{"moduleid", &CmdProxy::moduleid}, {"moduleid", &CmdProxy::moduleid},
@ -1206,6 +1207,10 @@ class CmdProxy {
detectorserverversion, getDetectorServerVersion, detectorserverversion, getDetectorServerVersion,
"\n\tOn-board detector server software version in format [0xYYMMDD]."); "\n\tOn-board detector server software version in format [0xYYMMDD].");
GET_COMMAND(
kernelversion, getKernelVersion,
"\n\tGet kernel version on the detector including time and date.");
GET_COMMAND_HEX(rx_version, getReceiverVersion, GET_COMMAND_HEX(rx_version, getReceiverVersion,
"\n\tReceiver version in format [0xYYMMDD]."); "\n\tReceiver version in format [0xYYMMDD].");

View File

@ -117,6 +117,10 @@ Result<int64_t> Detector::getDetectorServerVersion(Positions pos) const {
return pimpl->Parallel(&Module::getDetectorServerVersion, pos); return pimpl->Parallel(&Module::getDetectorServerVersion, pos);
} }
Result<std::string> Detector::getKernelVersion(Positions pos) const {
return pimpl->Parallel(&Module::getKernelVersion, pos);
}
Result<int64_t> Detector::getSerialNumber(Positions pos) const { Result<int64_t> Detector::getSerialNumber(Positions pos) const {
return pimpl->Parallel(&Module::getSerialNumber, pos); return pimpl->Parallel(&Module::getSerialNumber, pos);
} }

View File

@ -94,6 +94,12 @@ int64_t Module::getDetectorServerVersion() const {
return sendToDetector<int64_t>(F_GET_SERVER_VERSION); return sendToDetector<int64_t>(F_GET_SERVER_VERSION);
} }
std::string Module::getKernelVersion() const {
char retval[MAX_STR_LENGTH]{};
sendToDetector(F_GET_KERNEL_VERSION, nullptr, retval);
return retval;
}
int64_t Module::getSerialNumber() const { int64_t Module::getSerialNumber() const {
return sendToDetector<int64_t>(F_GET_SERIAL_NUMBER); return sendToDetector<int64_t>(F_GET_SERIAL_NUMBER);
} }

View File

@ -91,6 +91,7 @@ class Module : public virtual slsDetectorDefs {
int64_t getFirmwareVersion() const; int64_t getFirmwareVersion() const;
int64_t getDetectorServerVersion() const; int64_t getDetectorServerVersion() const;
std::string getKernelVersion() const;
int64_t getSerialNumber() const; int64_t getSerialNumber() const;
int getModuleId() const; int getModuleId() const;
int64_t getReceiverSoftwareVersion() const; int64_t getReceiverSoftwareVersion() const;

View File

@ -103,6 +103,13 @@ TEST_CASE("detectorserverversion", "[.cmd]") {
REQUIRE_THROWS(proxy.Call("detectorserverversion", {"0"}, -1, PUT)); REQUIRE_THROWS(proxy.Call("detectorserverversion", {"0"}, -1, PUT));
} }
TEST_CASE("kernelversion", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
REQUIRE_NOTHROW(proxy.Call("kernelversion", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("kernelversion", {"0"}, -1, PUT));
}
TEST_CASE("serialnumber", "[.cmd]") { TEST_CASE("serialnumber", "[.cmd]") {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);

View File

@ -253,6 +253,7 @@ enum detFuncs {
F_SET_UDP_FIRST_DEST, F_SET_UDP_FIRST_DEST,
F_GET_READOUT_SPEED, F_GET_READOUT_SPEED,
F_SET_READOUT_SPEED, F_SET_READOUT_SPEED,
F_GET_KERNEL_VERSION,
NUM_DET_FUNCTIONS, NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this RECEIVER_ENUM_START = 256, /**< detector function should not exceed this
@ -608,9 +609,12 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_SET_UDP_FIRST_DEST: return "F_SET_UDP_FIRST_DEST"; case F_SET_UDP_FIRST_DEST: return "F_SET_UDP_FIRST_DEST";
case F_GET_READOUT_SPEED: return "F_GET_READOUT_SPEED"; case F_GET_READOUT_SPEED: return "F_GET_READOUT_SPEED";
case F_SET_READOUT_SPEED: return "F_SET_READOUT_SPEED"; case F_SET_READOUT_SPEED: return "F_SET_READOUT_SPEED";
case F_GET_KERNEL_VERSION: return "F_GET_KERNEL_VERSION";
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";
case F_EXEC_RECEIVER_COMMAND: return "F_EXEC_RECEIVER_COMMAND"; case F_EXEC_RECEIVER_COMMAND: return "F_EXEC_RECEIVER_COMMAND";
case F_LOCK_RECEIVER: return "F_LOCK_RECEIVER"; case F_LOCK_RECEIVER: return "F_LOCK_RECEIVER";
case F_GET_LAST_RECEIVER_CLIENT_IP: return "F_GET_LAST_RECEIVER_CLIENT_IP"; case F_GET_LAST_RECEIVER_CLIENT_IP: return "F_GET_LAST_RECEIVER_CLIENT_IP";