mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 19:30:03 +02:00
somewhere between fork and pipes, crashes at sendingudppacket at print
This commit is contained in:
parent
7c7f7e8c70
commit
eeed102bf3
@ -19,10 +19,10 @@ install(TARGETS slsProjectCWarnings
|
|||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
)
|
)
|
||||||
add_subdirectory(ctbDetectorServer)
|
#add_subdirectory(ctbDetectorServer)
|
||||||
add_subdirectory(eigerDetectorServer)
|
#add_subdirectory(eigerDetectorServer)
|
||||||
add_subdirectory(gotthardDetectorServer)
|
#add_subdirectory(gotthardDetectorServer)
|
||||||
add_subdirectory(jungfrauDetectorServer)
|
#add_subdirectory(jungfrauDetectorServer)
|
||||||
add_subdirectory(mythen3DetectorServer)
|
add_subdirectory(mythen3DetectorServer)
|
||||||
add_subdirectory(gotthard2DetectorServer)
|
#add_subdirectory(gotthard2DetectorServer)
|
||||||
add_subdirectory(moenchDetectorServer)
|
#add_subdirectory(moenchDetectorServer)
|
||||||
|
@ -10,6 +10,7 @@ add_executable(mythen3DetectorServer_virtual
|
|||||||
../slsDetectorServer/src/LTC2620_Driver.c
|
../slsDetectorServer/src/LTC2620_Driver.c
|
||||||
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
||||||
../slsDetectorServer/src/programFpgaNios.c
|
../slsDetectorServer/src/programFpgaNios.c
|
||||||
|
../slsDetectorServer/src/clogger.c
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
@ -24,6 +24,7 @@ extern udpStruct udpDetails;
|
|||||||
extern const enum detectorType myDetectorType;
|
extern const enum detectorType myDetectorType;
|
||||||
|
|
||||||
// Global variable from communication_funcs.c
|
// Global variable from communication_funcs.c
|
||||||
|
extern int isControlServer;
|
||||||
extern void getMacAddressinString(char* cmac, int size, uint64_t mac);
|
extern void getMacAddressinString(char* cmac, int size, uint64_t mac);
|
||||||
extern void getIpAddressinString(char* cip, uint32_t ip);
|
extern void getIpAddressinString(char* cip, uint32_t ip);
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ int initCheckDone = 0;
|
|||||||
char initErrorMessage[MAX_STR_LENGTH];
|
char initErrorMessage[MAX_STR_LENGTH];
|
||||||
|
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
|
//int pipeFDs[2];
|
||||||
pthread_t pthread_virtual_tid;
|
pthread_t pthread_virtual_tid;
|
||||||
int virtual_status = 0;
|
int virtual_status = 0;
|
||||||
int virtual_stop = 0;
|
int virtual_stop = 0;
|
||||||
@ -1351,10 +1353,16 @@ int startStateMachine(){
|
|||||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||||
// set status to running
|
// set status to running
|
||||||
virtual_status = 1;
|
virtual_status = 1;
|
||||||
|
/*if (isControlServer) {
|
||||||
|
//write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status));
|
||||||
|
}*/
|
||||||
virtual_stop = 0;
|
virtual_stop = 0;
|
||||||
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
||||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||||
virtual_status = 0;
|
virtual_status = 0;
|
||||||
|
/*if (isControlServer) {
|
||||||
|
//write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status));
|
||||||
|
}*/
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
||||||
@ -1455,6 +1463,9 @@ void* start_timer(void* arg) {
|
|||||||
closeUDPSocket(0);
|
closeUDPSocket(0);
|
||||||
|
|
||||||
virtual_status = 0;
|
virtual_status = 0;
|
||||||
|
/*if (isControlServer) {
|
||||||
|
//write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status));
|
||||||
|
} */
|
||||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1475,6 +1486,13 @@ int stopStateMachine(){
|
|||||||
|
|
||||||
enum runStatus getRunStatus(){
|
enum runStatus getRunStatus(){
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
|
/*if (!isControlServer) {
|
||||||
|
LOG(logINFORED, ("***** reading\n"));
|
||||||
|
while (read(pipeFDs[PIPE_READ], &virtual_status, sizeof(virtual_status)) > 0) {
|
||||||
|
LOG(logINFORED, ("virtual status:%d\n", virtual_status));
|
||||||
|
}
|
||||||
|
LOG(logINFORED, ("***** final %d\n", virtual_status));
|
||||||
|
}*/
|
||||||
if(virtual_status == 0){
|
if(virtual_status == 0){
|
||||||
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
||||||
return IDLE;
|
return IDLE;
|
||||||
@ -1550,6 +1568,12 @@ void readFrame(int *ret, char *mess) {
|
|||||||
|
|
||||||
u_int32_t runBusy() {
|
u_int32_t runBusy() {
|
||||||
#ifdef VIRTUAL
|
#ifdef VIRTUAL
|
||||||
|
/*if (!isControlServer) {
|
||||||
|
LOG(logINFORED, ("runbusy \n"));
|
||||||
|
while (read(pipeFDs[PIPE_READ], &virtual_status, sizeof(virtual_status)) > 0) {
|
||||||
|
LOG(logINFORED, ("runbusy virtual status:%d\n", virtual_status));
|
||||||
|
}
|
||||||
|
}*/
|
||||||
return virtual_status;
|
return virtual_status;
|
||||||
#endif
|
#endif
|
||||||
u_int32_t s = (bus_r(PAT_STATUS_REG) & PAT_STATUS_RUN_BUSY_MSK);
|
u_int32_t s = (bus_r(PAT_STATUS_REG) & PAT_STATUS_RUN_BUSY_MSK);
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
|
#define CTRL_SRVR_INIT_TIME_US (300 * 1000)
|
||||||
|
|
||||||
|
#define PIPE_WRITE 1
|
||||||
|
#define PIPE_READ 0
|
||||||
|
|
||||||
/* Hardware Definitions */
|
/* Hardware Definitions */
|
||||||
#define NCOUNTERS (3)
|
#define NCOUNTERS (3)
|
||||||
#define MAX_COUNTER_MSK (0x7)
|
#define MAX_COUNTER_MSK (0x7)
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
// Global variables from communication_funcs
|
// Global variables from communication_funcs
|
||||||
extern int isControlServer;
|
extern int isControlServer;
|
||||||
@ -23,6 +24,9 @@ extern int checkModuleFlag;
|
|||||||
|
|
||||||
|
|
||||||
// Global variables from slsDetectorFunctionList
|
// Global variables from slsDetectorFunctionList
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
//extern int pipeFDs[2];
|
||||||
|
#endif
|
||||||
#ifdef GOTTHARDD
|
#ifdef GOTTHARDD
|
||||||
extern int phaseShift;
|
extern int phaseShift;
|
||||||
#endif
|
#endif
|
||||||
@ -31,7 +35,8 @@ void error(char *msg){
|
|||||||
perror(msg);
|
perror(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
// print version
|
// print version
|
||||||
if (argc > 1 && !strcasecmp(argv[1], "-version")) {
|
if (argc > 1 && !strcasecmp(argv[1], "-version")) {
|
||||||
int version = 0;
|
int version = 0;
|
||||||
@ -61,11 +66,7 @@ int main(int argc, char *argv[]){
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < argc; ++i) {
|
for (i = 1; i < argc; ++i) {
|
||||||
if(!strcasecmp(argv[i],"-stopserver")) {
|
if(!strcasecmp(argv[i],"-devel")){
|
||||||
LOG(logINFO, ("Detected stop server\n"));
|
|
||||||
isControlServer = 0;
|
|
||||||
}
|
|
||||||
else if(!strcasecmp(argv[i],"-devel")){
|
|
||||||
LOG(logINFO, ("Detected developer mode\n"));
|
LOG(logINFO, ("Detected developer mode\n"));
|
||||||
debugflag = 1;
|
debugflag = 1;
|
||||||
}
|
}
|
||||||
@ -82,7 +83,7 @@ int main(int argc, char *argv[]){
|
|||||||
LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1]));
|
LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1]));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
LOG(logINFO, ("Detected port: %d\n", portno));
|
LOG(logINFO, ("Detected control port: %d\n", portno));
|
||||||
}
|
}
|
||||||
#ifdef GOTTHARDD
|
#ifdef GOTTHARDD
|
||||||
else if(!strcasecmp(argv[i],"-phaseshift")){
|
else if(!strcasecmp(argv[i],"-phaseshift")){
|
||||||
@ -100,33 +101,53 @@ int main(int argc, char *argv[]){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef STOP_SERVER
|
|
||||||
char cmd[MAX_STR_LENGTH];
|
|
||||||
memset(cmd, 0, MAX_STR_LENGTH);
|
|
||||||
#endif
|
|
||||||
if (isControlServer) {
|
|
||||||
LOG(logINFO, ("Opening control server on port %d \n", portno));
|
|
||||||
#ifdef STOP_SERVER
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < argc; ++i) {
|
|
||||||
if (i > 0) {
|
|
||||||
strcat(cmd, " ");
|
|
||||||
}
|
|
||||||
strcat(cmd, argv[i]);
|
|
||||||
}
|
|
||||||
char temp[50];
|
|
||||||
memset(temp, 0, sizeof(temp));
|
|
||||||
sprintf(temp, " -stopserver -port %d &", portno + 1);
|
|
||||||
strcat(cmd, temp);
|
|
||||||
|
|
||||||
LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd));
|
// stop server
|
||||||
system(cmd);
|
#ifdef STOP_SERVER
|
||||||
}
|
|
||||||
|
// create pipes to communicate with stop server
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
/*if (pipe(pipeFDs) < 0) {
|
||||||
|
LOG(logERROR, ("Could not create pipes to communicate with stop server\n"));
|
||||||
|
return -1;
|
||||||
|
}*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// fork stop server
|
||||||
|
pid_t cpid = fork();
|
||||||
|
if (cpid < 0) {
|
||||||
|
LOG(logERROR, ("Could not create fork a stop server\n"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
//fcntl(pipeFDs[PIPE_READ], F_SETFL, O_NONBLOCK);
|
||||||
|
//fcntl(pipeFDs[PIPE_WRITE], F_SETFL, O_NONBLOCK);
|
||||||
|
|
||||||
|
// stop server (child process)
|
||||||
|
if (cpid == 0) {
|
||||||
|
isControlServer = 0;
|
||||||
|
++portno;
|
||||||
|
LOG(logINFOBLUE, ("Stop server [%d]\n", portno));
|
||||||
|
// change name of stop server to distinguish
|
||||||
|
char stopServerSuffix[30];
|
||||||
|
memset(stopServerSuffix, 0, sizeof(stopServerSuffix));
|
||||||
|
sprintf(stopServerSuffix, " Stop_Server %d", portno);
|
||||||
|
//strcat(argv[0], stopServerSuffix);
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
//close(pipeFDs[PIPE_WRITE]);
|
||||||
|
//fcntl(pipeFDs[PIPE_READ], F_SETFL, O_NONBLOCK);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
LOG(logINFO,("Opening stop server on port %d \n", portno));
|
isControlServer = 1;
|
||||||
|
LOG(logINFOBLUE, ("Control server [%d]\n", portno));
|
||||||
|
#ifdef VIRTUAL
|
||||||
|
//close(pipeFDs[PIPE_READ]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
init_detector();
|
init_detector();
|
||||||
|
|
||||||
@ -142,7 +163,7 @@ int main(int argc, char *argv[]){
|
|||||||
if (isControlServer) {
|
if (isControlServer) {
|
||||||
LOG(logINFOBLUE, ("Control Server Ready...\n\n"));
|
LOG(logINFOBLUE, ("Control Server Ready...\n\n"));
|
||||||
} else {
|
} else {
|
||||||
LOG(logINFO, ("Stop Server Ready...\n\n"));
|
LOG(logINFOBLUE, ("Stop Server Ready...\n\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// waits for connection
|
// waits for connection
|
||||||
|
@ -49,7 +49,6 @@ void test_onchip_dac(defs::dacIndex index, const std::string &dacname, int dacva
|
|||||||
auto dacValueStr = sls::ToStringHex(dacvalue);
|
auto dacValueStr = sls::ToStringHex(dacvalue);
|
||||||
auto chipIndexStr = std::to_string(chipIndex);
|
auto chipIndexStr = std::to_string(chipIndex);
|
||||||
std::ostringstream oss_set, oss_get;
|
std::ostringstream oss_set, oss_get;
|
||||||
std::cout << "chipindexstr:"<<chipIndexStr<<" dacvaluestr:"<<dacValueStr<<std::endl;
|
|
||||||
proxy.Call(dacname, {chipIndexStr, dacValueStr}, -1, PUT, oss_set);
|
proxy.Call(dacname, {chipIndexStr, dacValueStr}, -1, PUT, oss_set);
|
||||||
REQUIRE(oss_set.str() == dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
|
REQUIRE(oss_set.str() == dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
|
||||||
proxy.Call(dacname, {chipIndexStr}, -1, GET, oss_get);
|
proxy.Call(dacname, {chipIndexStr}, -1, GET, oss_get);
|
||||||
|
@ -852,9 +852,88 @@ TEST_CASE("temp_fpga", "[.cmd][.new]") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* acquisition */
|
||||||
|
|
||||||
|
TEST_CASE("clearbusy", "[.cmd][.new]") {
|
||||||
|
Detector det;
|
||||||
|
CmdProxy proxy(&det);
|
||||||
|
REQUIRE_NOTHROW(proxy.Call("clearbusy", {}, -1, PUT));
|
||||||
|
REQUIRE_THROWS(proxy.Call("clearbusy", {"0"}, -1, PUT));
|
||||||
|
REQUIRE_THROWS(proxy.Call("clearbusy", {}, -1, GET));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("start", "[.cmd][.rx][.new]") {
|
||||||
|
Detector det;
|
||||||
|
CmdProxy proxy(&det);
|
||||||
|
// PUT only command
|
||||||
|
REQUIRE_THROWS(proxy.Call("start", {}, -1, GET));
|
||||||
|
auto prev_val = det.getExptime();
|
||||||
|
det.setExptime(std::chrono::seconds(10));
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
proxy.Call("start", {}, -1, PUT, oss);
|
||||||
|
REQUIRE(oss.str() == "start successful\n");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
proxy.Call("status", {}, -1, GET, oss);
|
||||||
|
REQUIRE(oss.str() == "status running\n");
|
||||||
|
}
|
||||||
|
det.stopDetector();
|
||||||
|
for (int i = 0; i != det.size(); ++i) {
|
||||||
|
det.setExptime(prev_val[i], {i});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("stop", "[.cmd][.rx][.new]") {
|
||||||
|
Detector det;
|
||||||
|
CmdProxy proxy(&det);
|
||||||
|
// PUT only command
|
||||||
|
REQUIRE_THROWS(proxy.Call("stop", {}, -1, GET));
|
||||||
|
auto prev_val = det.getExptime();
|
||||||
|
det.setExptime(std::chrono::seconds(10));
|
||||||
|
det.startDetector();
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
proxy.Call("status", {}, -1, GET, oss);
|
||||||
|
REQUIRE(oss.str() == "status running\n");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
proxy.Call("stop", {}, -1, PUT, oss);
|
||||||
|
REQUIRE(oss.str() == "stop successful\n");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
proxy.Call("status", {}, -1, GET, oss);
|
||||||
|
REQUIRE(oss.str() == "status idle\n");
|
||||||
|
}
|
||||||
|
for (int i = 0; i != det.size(); ++i) {
|
||||||
|
det.setExptime(prev_val[i], {i});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("status", "[.cmd][.rx][.new]") {
|
||||||
|
Detector det;
|
||||||
|
CmdProxy proxy(&det);
|
||||||
|
auto prev_val = det.getExptime();
|
||||||
|
det.setExptime(std::chrono::seconds(10));
|
||||||
|
det.startReceiver();
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
proxy.Call("status", {}, -1, GET, oss);
|
||||||
|
REQUIRE(oss.str() == "status running\n");
|
||||||
|
}
|
||||||
|
det.stopReceiver();
|
||||||
|
{
|
||||||
|
std::ostringstream oss;
|
||||||
|
proxy.Call("status", {}, -1, GET, oss);
|
||||||
|
REQUIRE(oss.str() == "status idle\n");
|
||||||
|
}
|
||||||
|
for (int i = 0; i != det.size(); ++i) {
|
||||||
|
det.setExptime(prev_val[i], {i});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user