mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-10 12:00:43 +02:00
@ -16,6 +16,7 @@ add_executable(ctbDetectorServer_virtual
|
||||
../slsDetectorServer/src/LTC2620.c
|
||||
../slsDetectorServer/src/MAX1932.c
|
||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
||||
../slsDetectorServer/src/communication_virtual.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -10,6 +10,9 @@
|
||||
#include "MAX1932.h" // hv
|
||||
#include "INA226.h" // i2c
|
||||
#include "ALTERA_PLL.h" // pll
|
||||
#ifdef VIRTUAL
|
||||
#include "communication_virtual.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h> // usleep
|
||||
@ -30,6 +33,7 @@ extern uint64_t udpFrameNumber;
|
||||
extern uint32_t udpPacketNumber;
|
||||
|
||||
// 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);
|
||||
|
||||
@ -427,6 +431,12 @@ void initStopServer() {
|
||||
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -469,7 +479,12 @@ void setupDetector() {
|
||||
digitalEnable = 0;
|
||||
naSamples = 1;
|
||||
ndSamples = 1;
|
||||
|
||||
#ifdef VIRTUAL
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
#endif
|
||||
|
||||
ALTERA_PLL_ResetPLLAndReconfiguration();
|
||||
resetCore();
|
||||
@ -2153,10 +2168,21 @@ int startStateMachine(){
|
||||
}
|
||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||
virtual_status = 1;
|
||||
virtual_stop = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
if (virtual_stop != 0) {
|
||||
LOG(logERROR, ("Cant start acquisition. "
|
||||
"Stop server has not updated stop status to 0\n"));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
||||
@ -2190,6 +2216,10 @@ int startStateMachine(){
|
||||
|
||||
#ifdef VIRTUAL
|
||||
void* start_timer(void* arg) {
|
||||
if (!isControlServer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int64_t periodNs = getPeriod();
|
||||
int numFrames = (getNumFrames() *
|
||||
getNumTriggers() );
|
||||
@ -2216,6 +2246,8 @@ void* start_timer(void* arg) {
|
||||
// loop over number of frames
|
||||
for(frameNr = 0; frameNr != numFrames; ++frameNr ) {
|
||||
|
||||
// update the virtual stop from stop server
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
//check if virtual_stop is high
|
||||
if(virtual_stop == 1){
|
||||
break;
|
||||
@ -2268,6 +2300,9 @@ void* start_timer(void* arg) {
|
||||
closeUDPSocket(0);
|
||||
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||
return NULL;
|
||||
}
|
||||
@ -2276,7 +2311,18 @@ void* start_timer(void* arg) {
|
||||
int stopStateMachine(){
|
||||
LOG(logINFORED, ("Stopping State Machine\n"));
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
virtual_stop = 1;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
// read till status is idle
|
||||
int tempStatus = 1;
|
||||
while(tempStatus == 1) {
|
||||
tempStatus = ComVirtual_getStatus();
|
||||
}
|
||||
virtual_stop = 0;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
LOG(logINFO, ("Stopped State Machine\n"));
|
||||
}
|
||||
return OK;
|
||||
#endif
|
||||
//stop state machine
|
||||
@ -2295,7 +2341,10 @@ int stopStateMachine(){
|
||||
|
||||
enum runStatus getRunStatus(){
|
||||
#ifdef VIRTUAL
|
||||
if(virtual_status == 0){
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
if(virtual_status == 0) {
|
||||
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
||||
return IDLE;
|
||||
}else{
|
||||
@ -2567,6 +2616,9 @@ int readFrameFromFifo() {
|
||||
|
||||
uint32_t runBusy() {
|
||||
#ifdef VIRTUAL
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
return virtual_status;
|
||||
#endif
|
||||
uint32_t s = (bus_r(STATUS_REG) & STATUS_RN_BSY_MSK);
|
||||
|
@ -5,6 +5,7 @@ set(src
|
||||
../slsDetectorServer/src/communication_funcs.c
|
||||
../slsDetectorServer/src/communication_funcs_UDP.c
|
||||
../slsDetectorServer/src/common.c
|
||||
../slsDetectorServer/src/communication_virtual.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -6,6 +6,8 @@
|
||||
#ifndef VIRTUAL
|
||||
#include "FebControl.h"
|
||||
#include "Beb.h"
|
||||
#else
|
||||
#include "communication_virtual.h"
|
||||
#endif
|
||||
|
||||
#include <unistd.h> //to gethostname
|
||||
@ -71,6 +73,9 @@ int eiger_tau_ns = 0;
|
||||
|
||||
|
||||
#ifdef VIRTUAL
|
||||
pthread_t virtual_tid;
|
||||
int virtual_status=0;
|
||||
int virtual_stop = 0;
|
||||
//values for virtual server
|
||||
int64_t eiger_virtual_exptime = 0;
|
||||
int64_t eiger_virtual_subexptime = 0;
|
||||
@ -84,11 +89,8 @@ int eiger_virtual_transmission_delay_left=0;
|
||||
int eiger_virtual_transmission_delay_right=0;
|
||||
int eiger_virtual_transmission_delay_frame=0;
|
||||
int eiger_virtual_transmission_flowcontrol_10g=0;
|
||||
int eiger_virtual_status=0;
|
||||
int eiger_virtual_activate=1;
|
||||
pthread_t eiger_virtual_tid;
|
||||
int eiger_virtual_stop = 0;
|
||||
uint64_t eiger_virtual_startingframenumber = 0;
|
||||
uint64_t eiger_virtual_startingframenumber = 1;
|
||||
int eiger_virtual_detPos[2] = {0, 0};
|
||||
int eiger_virtual_test_mode = 0;
|
||||
int eiger_virtual_quad_mode = 0;
|
||||
@ -353,6 +355,10 @@ void initControlServer() {
|
||||
void initStopServer() {
|
||||
#ifdef VIRTUAL
|
||||
getModuleConfiguration();
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
}
|
||||
return;
|
||||
#else
|
||||
getModuleConfiguration();
|
||||
@ -469,6 +475,12 @@ void setupDetector() {
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef VIRTUAL
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
#endif
|
||||
|
||||
LOG(logINFOBLUE, ("Setting Default Parameters\n"));
|
||||
//setting default measurement parameters
|
||||
@ -1803,11 +1815,22 @@ int startStateMachine() {
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||
eiger_virtual_status = 1;
|
||||
eiger_virtual_stop = 0;
|
||||
if (pthread_create(&eiger_virtual_tid, NULL, &start_timer, NULL)) {
|
||||
virtual_status = 1;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
if (virtual_stop != 0) {
|
||||
LOG(logERROR, ("Cant start acquisition. "
|
||||
"Stop server has not updated stop status to 0\n"));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if (pthread_create(&virtual_tid, NULL, &start_timer, NULL)) {
|
||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||
eiger_virtual_status = 0;
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFO ,("Virtual Acquisition started\n"));
|
||||
@ -1841,6 +1864,10 @@ int startStateMachine() {
|
||||
|
||||
#ifdef VIRTUAL
|
||||
void* start_timer(void* arg) {
|
||||
if (!isControlServer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int64_t periodNs = eiger_virtual_period;
|
||||
int numFrames = nimages_per_request;
|
||||
int64_t expUs = eiger_virtual_exptime / 1000;
|
||||
@ -1894,14 +1921,19 @@ void* start_timer(void* arg) {
|
||||
|
||||
// Send data
|
||||
{
|
||||
int frameNr = 1;
|
||||
uint64_t frameNr = 0;
|
||||
getStartingFrameNumber(&frameNr);
|
||||
// loop over number of frames
|
||||
for(frameNr = 1; frameNr <= numFrames; ++frameNr ) {
|
||||
int iframes = 0;
|
||||
for(iframes = 0; iframes != numFrames; ++iframes ) {
|
||||
|
||||
usleep(eiger_virtual_transmission_delay_frame);
|
||||
|
||||
// update the virtual stop from stop server
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
//check if virtual_stop is high
|
||||
if(eiger_virtual_stop == 1){
|
||||
if(virtual_stop == 1){
|
||||
setStartingFrameNumber(frameNr + iframes + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1923,7 +1955,7 @@ void* start_timer(void* arg) {
|
||||
sls_detector_header* header = (sls_detector_header*)(packetData);
|
||||
header->detType = 3;//(uint16_t)myDetectorType; updated when firmware updates
|
||||
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
|
||||
header->frameNumber = frameNr;
|
||||
header->frameNumber = frameNr + iframes;
|
||||
header->packetNumber = i;
|
||||
header->row = row;
|
||||
header->column = colLeft;
|
||||
@ -1933,7 +1965,7 @@ void* start_timer(void* arg) {
|
||||
header = (sls_detector_header*)(packetData2);
|
||||
header->detType = 3;//(uint16_t)myDetectorType; updated when firmware updates
|
||||
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
|
||||
header->frameNumber = frameNr;
|
||||
header->frameNumber = frameNr + iframes;
|
||||
header->packetNumber = i;
|
||||
header->row = row;
|
||||
header->column = colRight;
|
||||
@ -1979,25 +2011,29 @@ void* start_timer(void* arg) {
|
||||
sendUDPPacket(1, packetData2, packetsize);
|
||||
}
|
||||
}
|
||||
LOG(logINFO, ("Sent frame: %d\n", frameNr));
|
||||
LOG(logINFO, ("Sent frame: %d\n", iframes));
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 +
|
||||
(end.tv_nsec - begin.tv_nsec));
|
||||
|
||||
// sleep for (period - exptime)
|
||||
if (frameNr < numFrames) { // if there is a next frame
|
||||
if (iframes < numFrames) { // if there is a next frame
|
||||
if (periodNs > timeNs) {
|
||||
usleep((periodNs - timeNs)/ 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
setStartingFrameNumber(frameNr + numFrames);
|
||||
}
|
||||
|
||||
|
||||
closeUDPSocket(0);
|
||||
closeUDPSocket(1);
|
||||
|
||||
eiger_virtual_status = 0;
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||
return NULL;
|
||||
}
|
||||
@ -2009,7 +2045,18 @@ void* start_timer(void* arg) {
|
||||
int stopStateMachine() {
|
||||
LOG(logINFORED, ("Going to stop acquisition\n"));
|
||||
#ifdef VIRTUAL
|
||||
eiger_virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
virtual_stop = 1;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
// read till status is idle
|
||||
int tempStatus = 1;
|
||||
while(tempStatus == 1) {
|
||||
tempStatus = ComVirtual_getStatus();
|
||||
}
|
||||
virtual_stop = 0;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
LOG(logINFO, ("Stopped State Machine\n"));
|
||||
}
|
||||
return OK;
|
||||
#else
|
||||
if ((Feb_Control_StopAcquisition() != STATUS_IDLE) || (!Beb_StopAcquisition()) ) {
|
||||
@ -2069,7 +2116,10 @@ int startReadOut() {
|
||||
|
||||
enum runStatus getRunStatus() {
|
||||
#ifdef VIRTUAL
|
||||
if (eiger_virtual_status == 0) {
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
if (virtual_status == 0) {
|
||||
LOG(logINFO, ("Status: IDLE\n"));
|
||||
return IDLE;
|
||||
} else {
|
||||
@ -2100,7 +2150,7 @@ enum runStatus getRunStatus() {
|
||||
void readFrame(int *ret, char *mess) {
|
||||
#ifdef VIRTUAL
|
||||
// wait for status to be done
|
||||
while(eiger_virtual_status == 1){
|
||||
while(virtual_status == 1){
|
||||
usleep(500);
|
||||
}
|
||||
LOG(logINFOGREEN, ("acquisition successfully finished\n"));
|
||||
|
@ -11,6 +11,7 @@ add_executable(gotthard2DetectorServer_virtual
|
||||
../slsDetectorServer/src/ALTERA_PLL_CYCLONE10.c
|
||||
../slsDetectorServer/src/ASIC_Driver.c
|
||||
../slsDetectorServer/src/programFpgaNios.c
|
||||
../slsDetectorServer/src/communication_virtual.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "ASIC_Driver.h"
|
||||
#ifdef VIRTUAL
|
||||
#include "communication_funcs_UDP.h"
|
||||
#include "communication_virtual.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
@ -27,6 +28,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);
|
||||
|
||||
@ -337,6 +339,12 @@ void initStopServer() {
|
||||
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -386,7 +394,12 @@ void setupDetector() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VIRTUAL
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
#endif
|
||||
|
||||
// pll defines
|
||||
ALTERA_PLL_C10_SetDefines(REG_OFFSET, BASE_READOUT_PLL, BASE_SYSTEM_PLL, PLL_RESET_REG, PLL_RESET_REG, PLL_RESET_READOUT_MSK, PLL_RESET_SYSTEM_MSK, READOUT_PLL_VCO_FREQ_HZ, SYSTEM_PLL_VCO_FREQ_HZ);
|
||||
@ -2006,10 +2019,21 @@ int startStateMachine(){
|
||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||
// set status to running
|
||||
virtual_status = 1;
|
||||
virtual_stop = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
if (virtual_stop != 0) {
|
||||
LOG(logERROR, ("Cant start acquisition. "
|
||||
"Stop server has not updated stop status to 0\n"));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
||||
@ -2028,6 +2052,10 @@ int startStateMachine(){
|
||||
|
||||
#ifdef VIRTUAL
|
||||
void* start_timer(void* arg) {
|
||||
if (!isControlServer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int numRepeats = getNumTriggers();
|
||||
if (getTiming() == AUTO_TIMING) {
|
||||
if (burstMode == BURST_OFF) {
|
||||
@ -2067,6 +2095,8 @@ void* start_timer(void* arg) {
|
||||
// loop over number of frames
|
||||
for(frameNr = 0; frameNr != numFrames; ++frameNr ) {
|
||||
|
||||
// update the virtual stop from stop server
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
//check if virtual_stop is high
|
||||
if(virtual_stop == 1){
|
||||
break;
|
||||
@ -2125,6 +2155,9 @@ void* start_timer(void* arg) {
|
||||
closeUDPSocket(0);
|
||||
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||
return NULL;
|
||||
}
|
||||
@ -2134,7 +2167,18 @@ void* start_timer(void* arg) {
|
||||
int stopStateMachine(){
|
||||
LOG(logINFORED, ("Stopping State Machine\n"));
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
virtual_stop = 1;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
// read till status is idle
|
||||
int tempStatus = 1;
|
||||
while(tempStatus == 1) {
|
||||
tempStatus = ComVirtual_getStatus();
|
||||
}
|
||||
virtual_stop = 0;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
LOG(logINFO, ("Stopped State Machine\n"));
|
||||
}
|
||||
return OK;
|
||||
#endif
|
||||
//stop state machine
|
||||
@ -2145,7 +2189,10 @@ int stopStateMachine(){
|
||||
|
||||
enum runStatus getRunStatus(){
|
||||
#ifdef VIRTUAL
|
||||
if(virtual_status == 0){
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
if(virtual_status == 0) {
|
||||
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
||||
return IDLE;
|
||||
}else{
|
||||
@ -2219,6 +2266,9 @@ void readFrame(int *ret, char *mess) {
|
||||
|
||||
u_int32_t runBusy() {
|
||||
#ifdef VIRTUAL
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
return virtual_status;
|
||||
#endif
|
||||
u_int32_t s = (bus_r(FLOW_STATUS_REG) & FLOW_STATUS_RUN_BUSY_MSK);
|
||||
|
@ -10,6 +10,7 @@ add_executable(gotthardDetectorServer_virtual
|
||||
../slsDetectorServer/src/common.c
|
||||
../slsDetectorServer/src/commonServerFunctions.c
|
||||
../slsDetectorServer/src/communication_funcs_UDP.c
|
||||
../slsDetectorServer/src/communication_virtual.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "LTC2620.h" // dacs
|
||||
#ifdef VIRTUAL
|
||||
#include "communication_funcs_UDP.h"
|
||||
#include "communication_virtual.h"
|
||||
#endif
|
||||
|
||||
#include "string.h"
|
||||
@ -23,6 +24,7 @@ extern const enum detectorType myDetectorType;
|
||||
int phaseShift = DEFAULT_PHASE_SHIFT;
|
||||
|
||||
// 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);
|
||||
|
||||
@ -354,6 +356,12 @@ void initStopServer() {
|
||||
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -362,6 +370,13 @@ void initStopServer() {
|
||||
void setupDetector() {
|
||||
LOG(logINFO, ("This Server is for 1 Gotthard module (1280 channels)\n"));
|
||||
|
||||
#ifdef VIRTUAL
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialization
|
||||
setPhaseShiftOnce();
|
||||
|
||||
@ -1496,10 +1511,21 @@ int startStateMachine(){
|
||||
}
|
||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||
virtual_status = 1;
|
||||
virtual_stop = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
if (virtual_stop != 0) {
|
||||
LOG(logERROR, ("Cant start acquisition. "
|
||||
"Stop server has not updated stop status to 0\n"));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
||||
@ -1519,6 +1545,10 @@ int startStateMachine(){
|
||||
|
||||
#ifdef VIRTUAL
|
||||
void* start_timer(void* arg) {
|
||||
if (!isControlServer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int64_t periodNs = getPeriod();
|
||||
int numFrames = (getNumFrames() *
|
||||
getNumTriggers() );
|
||||
@ -1549,6 +1579,8 @@ void* start_timer(void* arg) {
|
||||
// loop over number of frames
|
||||
for(frameNr = 0; frameNr != numFrames; ++frameNr ) {
|
||||
|
||||
// update the virtual stop from stop server
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
//check if virtual_stop is high
|
||||
if(virtual_stop == 1){
|
||||
break;
|
||||
@ -1595,6 +1627,9 @@ void* start_timer(void* arg) {
|
||||
closeUDPSocket(0);
|
||||
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||
return NULL;
|
||||
}
|
||||
@ -1603,7 +1638,18 @@ void* start_timer(void* arg) {
|
||||
int stopStateMachine(){
|
||||
LOG(logINFORED, ("Stopping State Machine\n"));
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
virtual_stop = 1;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
// read till status is idle
|
||||
int tempStatus = 1;
|
||||
while(tempStatus == 1) {
|
||||
tempStatus = ComVirtual_getStatus();
|
||||
}
|
||||
virtual_stop = 0;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
LOG(logINFO, ("Stopped State Machine\n"));
|
||||
}
|
||||
return OK;
|
||||
#endif
|
||||
//stop state machine
|
||||
@ -1625,7 +1671,10 @@ int stopStateMachine(){
|
||||
|
||||
enum runStatus getRunStatus(){
|
||||
#ifdef VIRTUAL
|
||||
if(virtual_status == 0){
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
if(virtual_status == 0) {
|
||||
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
||||
return IDLE;
|
||||
}else{
|
||||
@ -1727,6 +1776,9 @@ void readFrame(int *ret, char *mess){
|
||||
|
||||
u_int32_t runBusy() {
|
||||
#ifdef VIRTUAL
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
return virtual_status;
|
||||
#endif
|
||||
return runState(logDEBUG1) & STATUS_RN_BSY_MSK;
|
||||
|
@ -12,6 +12,7 @@ add_executable(jungfrauDetectorServer_virtual
|
||||
../slsDetectorServer/src/MAX1932.c
|
||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
||||
../slsDetectorServer/src/communication_funcs_UDP.c
|
||||
../slsDetectorServer/src/communication_virtual.c
|
||||
)
|
||||
|
||||
target_include_directories(jungfrauDetectorServer_virtual
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "common.h"
|
||||
#ifdef VIRTUAL
|
||||
#include "communication_funcs_UDP.h"
|
||||
#include "communication_virtual.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
@ -25,6 +26,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);
|
||||
|
||||
@ -373,6 +375,12 @@ void initStopServer() {
|
||||
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -394,6 +402,13 @@ void setupDetector() {
|
||||
clkPhase[i] = 0;
|
||||
}
|
||||
}
|
||||
#ifdef VIRTUAL
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
#endif
|
||||
|
||||
ALTERA_PLL_ResetPLL();
|
||||
resetCore();
|
||||
resetPeripheral();
|
||||
@ -545,16 +560,24 @@ int selectStoragecellStart(int pos) {
|
||||
|
||||
int setStartingFrameNumber(uint64_t value) {
|
||||
LOG(logINFO, ("Setting starting frame number: %llu\n",(long long unsigned int)value));
|
||||
#ifdef VIRTUAL
|
||||
setU64BitReg(value, FRAME_NUMBER_LSB_REG, FRAME_NUMBER_MSB_REG);
|
||||
#else
|
||||
// decrement is for firmware
|
||||
setU64BitReg(value - 1, FRAME_NUMBER_LSB_REG, FRAME_NUMBER_MSB_REG);
|
||||
// need to set it twice for the firmware to catch
|
||||
setU64BitReg(value - 1, FRAME_NUMBER_LSB_REG, FRAME_NUMBER_MSB_REG);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
int getStartingFrameNumber(uint64_t* retval) {
|
||||
#ifdef VIRTUAL
|
||||
*retval = getU64BitReg(FRAME_NUMBER_LSB_REG, FRAME_NUMBER_MSB_REG);
|
||||
#else
|
||||
// increment is for firmware
|
||||
*retval = (getU64BitReg(GET_FRAME_NUMBER_LSB_REG, GET_FRAME_NUMBER_MSB_REG) + 1);
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -1625,10 +1648,21 @@ int startStateMachine(){
|
||||
}
|
||||
LOG(logINFOBLUE, ("starting state machine\n"));
|
||||
virtual_status = 1;
|
||||
virtual_stop = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
if (virtual_stop != 0) {
|
||||
LOG(logERROR, ("Cant start acquisition. "
|
||||
"Stop server has not updated stop status to 0\n"));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
||||
@ -1649,6 +1683,10 @@ int startStateMachine(){
|
||||
|
||||
#ifdef VIRTUAL
|
||||
void* start_timer(void* arg) {
|
||||
if (!isControlServer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int numInterfaces = getNumberofUDPInterfaces();
|
||||
int64_t periodNs = getPeriod();
|
||||
int numFrames = (getNumFrames() *
|
||||
@ -1675,13 +1713,18 @@ void* start_timer(void* arg) {
|
||||
|
||||
// Send data
|
||||
{
|
||||
int frameNr = 0;
|
||||
for(frameNr = 0; frameNr != numFrames; ++frameNr ) {
|
||||
uint64_t frameNr = 0;
|
||||
getStartingFrameNumber(&frameNr);
|
||||
int iframes = 0;
|
||||
for(iframes = 0; iframes != numFrames; ++iframes ) {
|
||||
|
||||
usleep(transmissionDelayUs);
|
||||
|
||||
// update the virtual stop from stop server
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
//check if virtual_stop is high
|
||||
if(virtual_stop == 1){
|
||||
setStartingFrameNumber(frameNr + iframes + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1702,7 +1745,7 @@ void* start_timer(void* arg) {
|
||||
sls_detector_header* header = (sls_detector_header*)(packetData);
|
||||
header->detType = (uint16_t)myDetectorType;
|
||||
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
|
||||
header->frameNumber = frameNr;
|
||||
header->frameNumber = frameNr + iframes;
|
||||
header->packetNumber = i;
|
||||
header->modId = 0;
|
||||
header->row = detPos[2];
|
||||
@ -1737,18 +1780,19 @@ void* start_timer(void* arg) {
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG(logINFO, ("Sent frame: %d\n", frameNr));
|
||||
LOG(logINFO, ("Sent frame: %d\n", iframes));
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
int64_t timeNs = ((end.tv_sec - begin.tv_sec) * 1E9 +
|
||||
(end.tv_nsec - begin.tv_nsec));
|
||||
|
||||
// sleep for (period - exptime)
|
||||
if (frameNr < numFrames) { // if there is a next frame
|
||||
if (iframes < numFrames) { // if there is a next frame
|
||||
if (periodNs > timeNs) {
|
||||
usleep((periodNs - timeNs)/ 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
setStartingFrameNumber(frameNr + numFrames);
|
||||
}
|
||||
|
||||
closeUDPSocket(0);
|
||||
@ -1757,6 +1801,9 @@ void* start_timer(void* arg) {
|
||||
}
|
||||
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||
return NULL;
|
||||
}
|
||||
@ -1765,7 +1812,18 @@ void* start_timer(void* arg) {
|
||||
int stopStateMachine(){
|
||||
LOG(logINFORED, ("Stopping State Machine\n"));
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
virtual_stop = 1;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
// read till status is idle
|
||||
int tempStatus = 1;
|
||||
while(tempStatus == 1) {
|
||||
tempStatus = ComVirtual_getStatus();
|
||||
}
|
||||
virtual_stop = 0;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
LOG(logINFO, ("Stopped State Machine\n"));
|
||||
}
|
||||
return OK;
|
||||
#endif
|
||||
//stop state machine
|
||||
@ -1783,7 +1841,10 @@ int stopStateMachine(){
|
||||
|
||||
enum runStatus getRunStatus(){
|
||||
#ifdef VIRTUAL
|
||||
if(virtual_status == 0){
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
if(virtual_status == 0) {
|
||||
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
||||
return IDLE;
|
||||
}else{
|
||||
@ -1857,6 +1918,9 @@ void readFrame(int *ret, char *mess){
|
||||
|
||||
u_int32_t runBusy() {
|
||||
#ifdef VIRTUAL
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
return virtual_status;
|
||||
#endif
|
||||
u_int32_t s = (bus_r(STATUS_REG) & RUN_BUSY_MSK);
|
||||
|
@ -14,6 +14,7 @@ add_executable(moenchDetectorServer_virtual
|
||||
../slsDetectorServer/src/MAX1932.c
|
||||
../slsDetectorServer/src/programFpgaBlackfin.c
|
||||
../slsDetectorServer/src/readDefaultPattern.c
|
||||
../slsDetectorServer/src/communication_virtual.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -8,6 +8,9 @@
|
||||
#include "MAX1932.h" // hv
|
||||
#include "ALTERA_PLL.h" // pll
|
||||
#include "common.h"
|
||||
#ifdef VIRTUAL
|
||||
#include "communication_virtual.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h> // usleep
|
||||
@ -28,6 +31,7 @@ extern uint64_t udpFrameNumber;
|
||||
extern uint32_t udpPacketNumber;
|
||||
|
||||
// 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);
|
||||
|
||||
@ -422,6 +426,12 @@ void initStopServer() {
|
||||
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -474,6 +484,12 @@ void setupDetector() {
|
||||
adcEnableMask_1g = 0;
|
||||
adcEnableMask_10g = 0;
|
||||
nSamples = 1;
|
||||
#ifdef VIRTUAL
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
#endif
|
||||
|
||||
ALTERA_PLL_ResetPLLAndReconfiguration();
|
||||
resetCore();
|
||||
@ -1815,10 +1831,21 @@ int startStateMachine(){
|
||||
}
|
||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||
virtual_status = 1;
|
||||
virtual_stop = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
if (virtual_stop != 0) {
|
||||
LOG(logERROR, ("Cant start acquisition. "
|
||||
"Stop server has not updated stop status to 0\n"));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
||||
@ -1852,6 +1879,10 @@ int startStateMachine(){
|
||||
|
||||
#ifdef VIRTUAL
|
||||
void* start_timer(void* arg) {
|
||||
if (!isControlServer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int64_t periodNs = getPeriod();
|
||||
int numFrames = (getNumFrames() *
|
||||
getNumTriggers() );
|
||||
@ -1878,6 +1909,8 @@ void* start_timer(void* arg) {
|
||||
// loop over number of frames
|
||||
for(frameNr = 0; frameNr != numFrames; ++frameNr ) {
|
||||
|
||||
// update the virtual stop from stop server
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
//check if virtual_stop is high
|
||||
if(virtual_stop == 1){
|
||||
break;
|
||||
@ -1929,6 +1962,9 @@ void* start_timer(void* arg) {
|
||||
closeUDPSocket(0);
|
||||
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||
return NULL;
|
||||
}
|
||||
@ -1937,7 +1973,18 @@ void* start_timer(void* arg) {
|
||||
int stopStateMachine(){
|
||||
LOG(logINFORED, ("Stopping State Machine\n"));
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
virtual_stop = 1;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
// read till status is idle
|
||||
int tempStatus = 1;
|
||||
while(tempStatus == 1) {
|
||||
tempStatus = ComVirtual_getStatus();
|
||||
}
|
||||
virtual_stop = 0;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
LOG(logINFO, ("Stopped State Machine\n"));
|
||||
}
|
||||
return OK;
|
||||
#endif
|
||||
//stop state machine
|
||||
@ -1956,7 +2003,10 @@ int stopStateMachine(){
|
||||
|
||||
enum runStatus getRunStatus(){
|
||||
#ifdef VIRTUAL
|
||||
if(virtual_status == 0){
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
if(virtual_status == 0) {
|
||||
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
||||
return IDLE;
|
||||
}else{
|
||||
@ -2191,6 +2241,9 @@ int readFrameFromFifo() {
|
||||
|
||||
uint32_t runBusy() {
|
||||
#ifdef VIRTUAL
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
return virtual_status;
|
||||
#endif
|
||||
uint32_t s = (bus_r(STATUS_REG) & STATUS_RN_BSY_MSK);
|
||||
|
@ -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/communication_virtual.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "ALTERA_PLL_CYCLONE10.h"
|
||||
#ifdef VIRTUAL
|
||||
#include "communication_funcs_UDP.h"
|
||||
#include "communication_virtual.h"
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
@ -24,6 +25,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);
|
||||
|
||||
@ -324,6 +326,12 @@ void initStopServer() {
|
||||
LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -348,6 +356,12 @@ void setupDetector() {
|
||||
dacValues[i] = 0;
|
||||
}
|
||||
}
|
||||
#ifdef VIRTUAL
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
#endif
|
||||
|
||||
// pll defines
|
||||
ALTERA_PLL_C10_SetDefines(REG_OFFSET, BASE_READOUT_PLL, BASE_SYSTEM_PLL, PLL_RESET_REG, PLL_RESET_REG, PLL_RESET_READOUT_MSK, PLL_RESET_SYSTEM_MSK, READOUT_PLL_VCO_FREQ_HZ, SYSTEM_PLL_VCO_FREQ_HZ);
|
||||
@ -1351,10 +1365,21 @@ int startStateMachine(){
|
||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||
// set status to running
|
||||
virtual_status = 1;
|
||||
virtual_stop = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
if (virtual_stop != 0) {
|
||||
LOG(logERROR, ("Cant start acquisition. "
|
||||
"Stop server has not updated stop status to 0\n"));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) {
|
||||
LOG(logERROR, ("Could not start Virtual acquisition thread\n"));
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFOGREEN, ("Virtual Acquisition started\n"));
|
||||
@ -1375,6 +1400,10 @@ int startStateMachine(){
|
||||
|
||||
#ifdef VIRTUAL
|
||||
void* start_timer(void* arg) {
|
||||
if (!isControlServer) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int64_t periodNs = getPeriod();
|
||||
int numFrames = (getNumFrames() *
|
||||
getNumTriggers() );
|
||||
@ -1401,6 +1430,8 @@ void* start_timer(void* arg) {
|
||||
// loop over number of frames
|
||||
for (frameNr = 0; frameNr != numFrames; ++frameNr) {
|
||||
|
||||
// update the virtual stop from stop server
|
||||
virtual_stop = ComVirtual_getStop();
|
||||
//check if virtual_stop is high
|
||||
if(virtual_stop == 1){
|
||||
break;
|
||||
@ -1455,6 +1486,9 @@ void* start_timer(void* arg) {
|
||||
closeUDPSocket(0);
|
||||
|
||||
virtual_status = 0;
|
||||
if (isControlServer) {
|
||||
ComVirtual_setStatus(virtual_status);
|
||||
}
|
||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||
return NULL;
|
||||
}
|
||||
@ -1464,7 +1498,18 @@ void* start_timer(void* arg) {
|
||||
int stopStateMachine(){
|
||||
LOG(logINFORED, ("Stopping State Machine\n"));
|
||||
#ifdef VIRTUAL
|
||||
virtual_stop = 0;
|
||||
if (!isControlServer) {
|
||||
virtual_stop = 1;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
// read till status is idle
|
||||
int tempStatus = 1;
|
||||
while(tempStatus == 1) {
|
||||
tempStatus = ComVirtual_getStatus();
|
||||
}
|
||||
virtual_stop = 0;
|
||||
ComVirtual_setStop(virtual_stop);
|
||||
LOG(logINFO, ("Stopped State Machine\n"));
|
||||
}
|
||||
return OK;
|
||||
#endif
|
||||
//stop state machine
|
||||
@ -1475,10 +1520,13 @@ int stopStateMachine(){
|
||||
|
||||
enum runStatus getRunStatus(){
|
||||
#ifdef VIRTUAL
|
||||
if(virtual_status == 0){
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
if(virtual_status == 0) {
|
||||
LOG(logINFOBLUE, ("Status: IDLE\n"));
|
||||
return IDLE;
|
||||
}else{
|
||||
} else{
|
||||
LOG(logINFOBLUE, ("Status: RUNNING\n"));
|
||||
return RUNNING;
|
||||
}
|
||||
@ -1550,6 +1598,9 @@ void readFrame(int *ret, char *mess) {
|
||||
|
||||
u_int32_t runBusy() {
|
||||
#ifdef VIRTUAL
|
||||
if (!isControlServer) {
|
||||
virtual_status = ComVirtual_getStatus();
|
||||
}
|
||||
return virtual_status;
|
||||
#endif
|
||||
u_int32_t s = (bus_r(PAT_STATUS_REG) & PAT_STATUS_RUN_BUSY_MSK);
|
||||
|
@ -11,6 +11,13 @@ typedef enum{
|
||||
OTHER
|
||||
}intType;
|
||||
|
||||
// communciate with stop server
|
||||
#ifdef VIRTUAL
|
||||
#define FILE_STATUS "/tmp/Sls_virtual_server_status_"
|
||||
#define FILE_STOP "/tmp/Sls_virtual_server_stop_"
|
||||
#define FD_STATUS 0
|
||||
#define FD_STOP 1
|
||||
#endif
|
||||
|
||||
int bindSocket(unsigned short int port_number);
|
||||
int acceptConnection(int socketDescriptor);
|
||||
|
14
slsDetectorServers/slsDetectorServer/include/communication_virtual.h
Executable file
14
slsDetectorServers/slsDetectorServer/include/communication_virtual.h
Executable file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#ifdef VIRTUAL
|
||||
// communciate between control and stop server
|
||||
|
||||
int ComVirtual_createFiles(const int port);
|
||||
void ComVirtual_setFileNames(const int port);
|
||||
void ComVirtual_setStatus(int value);
|
||||
int ComVirtual_getStatus();
|
||||
void ComVirtual_setStop(int value);
|
||||
int ComVirtual_getStop();
|
||||
int ComVirtual_writeToFile(int value, const char* fname, const char* serverName);
|
||||
int ComVirtual_readFromFile(int* value, const char* fname, const char* serverName);
|
||||
|
||||
#endif
|
@ -37,7 +37,7 @@ int setUDPDestinationDetails(int index, const char* ip, unsigned short int port)
|
||||
// convert ip to internet address
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
hints.ai_flags = 0;
|
||||
hints.ai_protocol = 0;
|
||||
@ -83,19 +83,16 @@ int createUDPSocket(int index) {
|
||||
LOG(logINFO, ("Udp client socket created for server (port %d, ip:%s)\n",
|
||||
udpDestinationPort[index], udpDestinationIp[index]));
|
||||
|
||||
// Using connect expects that the receiver (udp server) exists to listen to these packets
|
||||
// connecting allows to use "send/write" instead of "sendto", avoiding checking for server address for each packet
|
||||
// using write without a connect will end in segv
|
||||
if (connect(udpSockfd[index],udpServerAddrInfo[index]->ai_addr, udpServerAddrInfo[index]->ai_addrlen)==-1) {
|
||||
LOG(logERROR, ("Could not connect to UDP server at ip:%s, port:%d. (Error code:%d, %s)\n",
|
||||
udpDestinationIp[index], udpDestinationPort[index], errno, gai_strerror(errno)));
|
||||
}
|
||||
// using write without a connect will end in segv
|
||||
LOG(logINFO, ("Udp client socket connected\n",
|
||||
udpDestinationPort[index], udpDestinationIp[index]));
|
||||
return OK;
|
||||
}
|
||||
|
||||
int sendUDPPacket(int index, const char* buf, int length) {
|
||||
int n = write(udpSockfd[index], buf, length);
|
||||
int n = sendto(udpSockfd[index], buf, length, 0, udpServerAddrInfo[index]->ai_addr, udpServerAddrInfo[index]->ai_addrlen);
|
||||
// udp sends atomically, no need to handle partial data
|
||||
if (n == -1) {
|
||||
LOG(logERROR, ("Could not send udp packet for socket %d. (Error code:%d, %s)\n",
|
||||
|
120
slsDetectorServers/slsDetectorServer/src/communication_virtual.c
Executable file
120
slsDetectorServers/slsDetectorServer/src/communication_virtual.c
Executable file
@ -0,0 +1,120 @@
|
||||
#ifdef VIRTUAL
|
||||
#include "communication_virtual.h"
|
||||
#include "clogger.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h> // usleep
|
||||
|
||||
#define FILE_STATUS "/tmp/sls_virtual_server_status_"
|
||||
#define FILE_STOP "/tmp/sls_virtual_server_stop_"
|
||||
#define FD_STATUS 0
|
||||
#define FD_STOP 1
|
||||
#define FILE_NAME_LENGTH 1000
|
||||
|
||||
FILE* fd[2] = {NULL, NULL};
|
||||
char fnameStatus[FILE_NAME_LENGTH];
|
||||
char fnameStop[FILE_NAME_LENGTH];
|
||||
int portNumber = 0;
|
||||
|
||||
int ComVirtual_createFiles(const int port) {
|
||||
portNumber = port;
|
||||
// control server writign status file
|
||||
memset(fnameStatus, 0, FILE_NAME_LENGTH);
|
||||
sprintf(fnameStatus, "%s%d", FILE_STATUS, port);
|
||||
FILE* fd = NULL;
|
||||
if (NULL == (fd = fopen(fnameStatus, "w"))) {
|
||||
LOG(logERROR, ("Could not open the file %s for virtual communication\n",
|
||||
fnameStatus));
|
||||
return 0;
|
||||
}
|
||||
fclose(fd);
|
||||
LOG(logINFOBLUE, ("Created status file %s\n", fnameStatus));
|
||||
|
||||
// stop server writing stop file
|
||||
memset(fnameStop, 0, FILE_NAME_LENGTH);
|
||||
sprintf(fnameStop, "%s%d", FILE_STOP, port);
|
||||
if (NULL == (fd = fopen(fnameStop, "w"))) {
|
||||
LOG(logERROR, ("Could not open the file %s for virtual communication\n",
|
||||
fnameStop));
|
||||
return 0;
|
||||
}
|
||||
fclose(fd);
|
||||
LOG(logINFOBLUE, ("Created stop file %s\n", fnameStop));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ComVirtual_setFileNames(const int port) {
|
||||
portNumber = port;
|
||||
memset(fnameStatus, 0, FILE_NAME_LENGTH);
|
||||
memset(fnameStop, 0, FILE_NAME_LENGTH);
|
||||
sprintf(fnameStatus, "%s%d", FILE_STATUS, port);
|
||||
sprintf(fnameStop, "%s%d", FILE_STOP, port);
|
||||
}
|
||||
|
||||
void ComVirtual_setStatus(int value) {
|
||||
while (!ComVirtual_writeToFile(value, fnameStatus, "Control")) {
|
||||
usleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
int ComVirtual_getStatus() {
|
||||
int retval = 0;
|
||||
while (!ComVirtual_readFromFile(&retval, fnameStatus, "Stop")) {
|
||||
usleep(100);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void ComVirtual_setStop(int value) {
|
||||
while (!ComVirtual_writeToFile(value, fnameStop, "Stop")) {
|
||||
usleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
int ComVirtual_getStop() {
|
||||
int retval = 0;
|
||||
while (!ComVirtual_readFromFile(&retval, fnameStop, "Control")) {
|
||||
usleep(100);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
int ComVirtual_writeToFile(int value, const char* fname, const char* serverName) {
|
||||
FILE* fd = NULL;
|
||||
if (NULL == (fd = fopen(fname, "w"))) {
|
||||
LOG(logERROR, ("Vritual %s Server [%d] could not open "
|
||||
"the file %s for writing\n",
|
||||
serverName, portNumber, fname));
|
||||
return 0;
|
||||
}
|
||||
while (fwrite(&value, sizeof(value), 1, fd) < 1) {
|
||||
LOG(logERROR, ("Vritual %s Server [%d] could not write "
|
||||
"to file %s\n",
|
||||
serverName, portNumber, fname));
|
||||
return 0;
|
||||
}
|
||||
fclose(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ComVirtual_readFromFile(int* value, const char* fname, const char* serverName) {
|
||||
FILE* fd = NULL;
|
||||
if (NULL == (fd = fopen(fname, "r"))) {
|
||||
LOG(logERROR, ("Vritual %s Server [%d] could not open "
|
||||
"the file %s for reading\n",
|
||||
serverName, portNumber, fname));
|
||||
return 0;
|
||||
}
|
||||
while (fread(value, sizeof(int), 1, fd) < 1) {
|
||||
LOG(logERROR, ("Vritual %s Server [%d] could not read "
|
||||
"from file %s\n",
|
||||
serverName, portNumber, fname));
|
||||
return 0;
|
||||
}
|
||||
fclose(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -7,6 +7,9 @@
|
||||
#include "slsDetectorServer_funcs.h"
|
||||
#include "slsDetectorServer_defs.h"
|
||||
#include "versionAPI.h"
|
||||
#ifdef VIRTUAL
|
||||
#include "communication_virtual.h"
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
@ -31,7 +34,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;
|
||||
@ -50,8 +54,9 @@ int main(int argc, char *argv[]){
|
||||
}
|
||||
|
||||
int portno = DEFAULT_PORTNO;
|
||||
int retval = OK;
|
||||
int fd = 0;
|
||||
isControlServer = 1;
|
||||
debugflag = 0;
|
||||
checkModuleFlag = 1;
|
||||
|
||||
// if socket crash, ignores SISPIPE, prevents global signal handler
|
||||
// subsequent read/write to socket gives error - must handle locally
|
||||
@ -100,16 +105,19 @@ int main(int argc, char *argv[]){
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef STOP_SERVER
|
||||
char cmd[MAX_STR_LENGTH];
|
||||
memset(cmd, 0, MAX_STR_LENGTH);
|
||||
#endif
|
||||
// control server
|
||||
if (isControlServer) {
|
||||
LOG(logINFO, ("Opening control server on port %d \n", portno));
|
||||
#ifdef STOP_SERVER
|
||||
// start stop server process
|
||||
char cmd[MAX_STR_LENGTH];
|
||||
memset(cmd, 0, MAX_STR_LENGTH);
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < argc; ++i) {
|
||||
if (!strcasecmp(argv[i], "-port")) {
|
||||
i +=2;
|
||||
continue;
|
||||
}
|
||||
if (i > 0) {
|
||||
strcat(cmd, " ");
|
||||
}
|
||||
@ -123,31 +131,42 @@ int main(int argc, char *argv[]){
|
||||
LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd));
|
||||
system(cmd);
|
||||
}
|
||||
LOG(logINFOBLUE, ("Control Server [%d]\n", portno));
|
||||
#ifdef VIRTUAL
|
||||
// creating files for virtual servers to communicate with each other
|
||||
if (!ComVirtual_createFiles(portno)) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
// stop server
|
||||
else {
|
||||
LOG(logINFOBLUE, ("Stop Server [%d]\n", portno));
|
||||
#ifdef VIRTUAL
|
||||
ComVirtual_setFileNames(portno - 1);
|
||||
#endif
|
||||
} else {
|
||||
LOG(logINFO,("Opening stop server on port %d \n", portno));
|
||||
}
|
||||
|
||||
|
||||
init_detector();
|
||||
|
||||
{ // bind socket
|
||||
sockfd = bindSocket(portno);
|
||||
if (ret == FAIL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// bind socket
|
||||
sockfd = bindSocket(portno);
|
||||
if (ret == FAIL)
|
||||
return -1;
|
||||
// assign function table
|
||||
function_table();
|
||||
|
||||
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
|
||||
int retval = OK;
|
||||
while(retval != GOODBYE && retval != REBOOT) {
|
||||
fd = acceptConnection(sockfd);
|
||||
int fd = acceptConnection(sockfd);
|
||||
if (fd > 0) {
|
||||
retval = decode_function(fd);
|
||||
closeConnection(fd);
|
||||
|
@ -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,11 +852,118 @@ 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][.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(2));
|
||||
{
|
||||
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][.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(2));
|
||||
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][.new]") {
|
||||
Detector det;
|
||||
CmdProxy proxy(&det);
|
||||
auto prev_val = det.getExptime();
|
||||
det.setExptime(std::chrono::seconds(2));
|
||||
det.startDetector();
|
||||
{
|
||||
std::ostringstream oss;
|
||||
proxy.Call("status", {}, -1, GET, oss);
|
||||
REQUIRE(oss.str() == "status running\n");
|
||||
}
|
||||
det.stopDetector();
|
||||
{
|
||||
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("startingfnum", "[.cmd][.new]") {
|
||||
Detector det;
|
||||
CmdProxy proxy(&det);
|
||||
auto det_type = det.getDetectorType().squash();
|
||||
if (det_type == defs::EIGER || det_type == defs::JUNGFRAU) {
|
||||
auto prev_sfnum = det.getStartingFrameNumber();
|
||||
REQUIRE_THROWS(proxy.Call("startingfnum", {"0"}, -1, PUT));
|
||||
{
|
||||
std::ostringstream oss;
|
||||
proxy.Call("startingfnum", {"3"}, -1, PUT, oss);
|
||||
REQUIRE(oss.str() == "startingfnum 3\n");
|
||||
}
|
||||
{
|
||||
std::ostringstream oss;
|
||||
proxy.Call("startingfnum", {}, -1, GET, oss);
|
||||
REQUIRE(oss.str() == "startingfnum 3\n");
|
||||
}
|
||||
{
|
||||
std::ostringstream oss;
|
||||
proxy.Call("startingfnum", {"1"}, -1, PUT, oss);
|
||||
REQUIRE(oss.str() == "startingfnum 1\n");
|
||||
}
|
||||
for (int i = 0; i != det.size(); ++i) {
|
||||
det.setStartingFrameNumber(prev_sfnum[i], {i});
|
||||
}
|
||||
} else {
|
||||
REQUIRE_THROWS(proxy.Call("startingfnum", {}, -1, GET));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user