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}
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
add_subdirectory(ctbDetectorServer)
|
||||
add_subdirectory(eigerDetectorServer)
|
||||
add_subdirectory(gotthardDetectorServer)
|
||||
add_subdirectory(jungfrauDetectorServer)
|
||||
#add_subdirectory(ctbDetectorServer)
|
||||
#add_subdirectory(eigerDetectorServer)
|
||||
#add_subdirectory(gotthardDetectorServer)
|
||||
#add_subdirectory(jungfrauDetectorServer)
|
||||
add_subdirectory(mythen3DetectorServer)
|
||||
add_subdirectory(gotthard2DetectorServer)
|
||||
add_subdirectory(moenchDetectorServer)
|
||||
#add_subdirectory(gotthard2DetectorServer)
|
||||
#add_subdirectory(moenchDetectorServer)
|
||||
|
@ -10,6 +10,7 @@ add_executable(mythen3DetectorServer_virtual
|
||||
../slsDetectorServer/src/LTC2620_Driver.c
|
||||
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
||||
../slsDetectorServer/src/programFpgaNios.c
|
||||
../slsDetectorServer/src/clogger.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -24,6 +24,7 @@ extern udpStruct udpDetails;
|
||||
extern const enum detectorType myDetectorType;
|
||||
|
||||
// Global variable from communication_funcs.c
|
||||
extern int isControlServer;
|
||||
extern void getMacAddressinString(char* cmac, int size, uint64_t mac);
|
||||
extern void getIpAddressinString(char* cip, uint32_t ip);
|
||||
|
||||
@ -32,6 +33,7 @@ int initCheckDone = 0;
|
||||
char initErrorMessage[MAX_STR_LENGTH];
|
||||
|
||||
#ifdef VIRTUAL
|
||||
//int pipeFDs[2];
|
||||
pthread_t pthread_virtual_tid;
|
||||
int virtual_status = 0;
|
||||
int virtual_stop = 0;
|
||||
@ -1351,10 +1353,16 @@ int startStateMachine(){
|
||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||
// set status to running
|
||||
virtual_status = 1;
|
||||
/*if (isControlServer) {
|
||||
//write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status));
|
||||
}*/
|
||||
virtual_stop = 0;
|
||||
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||
virtual_status = 0;
|
||||
/*if (isControlServer) {
|
||||
//write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status));
|
||||
}*/
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
||||
@ -1455,6 +1463,9 @@ void* start_timer(void* arg) {
|
||||
closeUDPSocket(0);
|
||||
|
||||
virtual_status = 0;
|
||||
/*if (isControlServer) {
|
||||
//write(pipeFDs[PIPE_WRITE], &virtual_status, sizeof(virtual_status));
|
||||
} */
|
||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||
return NULL;
|
||||
}
|
||||
@ -1475,6 +1486,13 @@ int stopStateMachine(){
|
||||
|
||||
enum runStatus getRunStatus(){
|
||||
#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){
|
||||
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
||||
return IDLE;
|
||||
@ -1550,6 +1568,12 @@ void readFrame(int *ret, char *mess) {
|
||||
|
||||
u_int32_t runBusy() {
|
||||
#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;
|
||||
#endif
|
||||
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 PIPE_WRITE 1
|
||||
#define PIPE_READ 0
|
||||
|
||||
/* Hardware Definitions */
|
||||
#define NCOUNTERS (3)
|
||||
#define MAX_COUNTER_MSK (0x7)
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
// Global variables from communication_funcs
|
||||
extern int isControlServer;
|
||||
@ -23,6 +24,9 @@ extern int checkModuleFlag;
|
||||
|
||||
|
||||
// Global variables from slsDetectorFunctionList
|
||||
#ifdef VIRTUAL
|
||||
//extern int pipeFDs[2];
|
||||
#endif
|
||||
#ifdef GOTTHARDD
|
||||
extern int phaseShift;
|
||||
#endif
|
||||
@ -31,7 +35,8 @@ void error(char *msg){
|
||||
perror(msg);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
// print version
|
||||
if (argc > 1 && !strcasecmp(argv[1], "-version")) {
|
||||
int version = 0;
|
||||
@ -61,11 +66,7 @@ int main(int argc, char *argv[]){
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if(!strcasecmp(argv[i],"-stopserver")) {
|
||||
LOG(logINFO, ("Detected stop server\n"));
|
||||
isControlServer = 0;
|
||||
}
|
||||
else if(!strcasecmp(argv[i],"-devel")){
|
||||
if(!strcasecmp(argv[i],"-devel")){
|
||||
LOG(logINFO, ("Detected developer mode\n"));
|
||||
debugflag = 1;
|
||||
}
|
||||
@ -82,7 +83,7 @@ int main(int argc, char *argv[]){
|
||||
LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1]));
|
||||
return -1;
|
||||
}
|
||||
LOG(logINFO, ("Detected port: %d\n", portno));
|
||||
LOG(logINFO, ("Detected control port: %d\n", portno));
|
||||
}
|
||||
#ifdef GOTTHARDD
|
||||
else if(!strcasecmp(argv[i],"-phaseshift")){
|
||||
@ -100,33 +101,53 @@ int main(int argc, char *argv[]){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// stop server
|
||||
#ifdef STOP_SERVER
|
||||
char cmd[MAX_STR_LENGTH];
|
||||
memset(cmd, 0, MAX_STR_LENGTH);
|
||||
|
||||
// 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
|
||||
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));
|
||||
system(cmd);
|
||||
}
|
||||
|
||||
// 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
|
||||
} 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();
|
||||
|
||||
@ -142,7 +163,7 @@ int main(int argc, char *argv[]){
|
||||
if (isControlServer) {
|
||||
LOG(logINFOBLUE, ("Control Server Ready...\n\n"));
|
||||
} else {
|
||||
LOG(logINFO, ("Stop Server Ready...\n\n"));
|
||||
LOG(logINFOBLUE, ("Stop Server Ready...\n\n"));
|
||||
}
|
||||
|
||||
// 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 chipIndexStr = std::to_string(chipIndex);
|
||||
std::ostringstream oss_set, oss_get;
|
||||
std::cout << "chipindexstr:"<<chipIndexStr<<" dacvaluestr:"<<dacValueStr<<std::endl;
|
||||
proxy.Call(dacname, {chipIndexStr, dacValueStr}, -1, PUT, oss_set);
|
||||
REQUIRE(oss_set.str() == dacname + " " + chipIndexStr + " " + dacValueStr + "\n");
|
||||
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