mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
virtual servers checked
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h> // usleep
|
||||
#include <netinet/in.h>
|
||||
#ifdef VIRTUAL
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
@ -1191,42 +1192,30 @@ int configureMAC() {
|
||||
int srcport = udpDetails.srcport;
|
||||
int dstport = udpDetails.dstport;
|
||||
|
||||
LOG(logINFOBLUE, ("Configuring MAC\n"));
|
||||
char src_mac[50], src_ip[INET_ADDRSTRLEN],dst_mac[50], dst_ip[INET_ADDRSTRLEN];
|
||||
getMacAddressinString(src_mac, 50, srcmac);
|
||||
getMacAddressinString(dst_mac, 50, dstmac);
|
||||
getIpAddressinString(src_ip, srcip);
|
||||
getIpAddressinString(dst_ip, dstip);
|
||||
|
||||
LOG(logINFO, (
|
||||
"\tSource IP : %s\n"
|
||||
"\tSource MAC : %s\n"
|
||||
"\tSource Port : %d\n"
|
||||
"\tDest IP : %s\n"
|
||||
"\tDest MAC : %s\n"
|
||||
"\tDest Port : %d\n",
|
||||
src_ip, src_mac, srcport,
|
||||
dst_ip, dst_mac, dstport));
|
||||
|
||||
#ifdef VIRTUAL
|
||||
char cDestIp[MAX_STR_LENGTH];
|
||||
memset(cDestIp, 0, MAX_STR_LENGTH);
|
||||
sprintf(cDestIp, "%d.%d.%d.%d", (dstip>>24)&0xff,(dstip>>16)&0xff,(dstip>>8)&0xff,(dstip)&0xff);
|
||||
LOG(logINFO, ("1G UDP: Destination (IP: %s, port:%d)\n", cDestIp, dstport));
|
||||
if (setUDPDestinationDetails(0, cDestIp, dstport) == FAIL) {
|
||||
if (setUDPDestinationDetails(0, dst_ip, dstport) == FAIL) {
|
||||
LOG(logERROR, ("could not set udp destination IP and port\n"));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
#endif
|
||||
LOG(logINFOBLUE, ("Configuring MAC\n"));
|
||||
|
||||
LOG(logINFO, ("\tSource IP : %d.%d.%d.%d \t\t(0x%08x)\n",
|
||||
(srcip>>24)&0xff,(srcip>>16)&0xff,(srcip>>8)&0xff,(srcip)&0xff, srcip));
|
||||
LOG(logINFO, ("\tSource MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n",
|
||||
(unsigned int)((srcmac>>40)&0xFF),
|
||||
(unsigned int)((srcmac>>32)&0xFF),
|
||||
(unsigned int)((srcmac>>24)&0xFF),
|
||||
(unsigned int)((srcmac>>16)&0xFF),
|
||||
(unsigned int)((srcmac>>8)&0xFF),
|
||||
(unsigned int)((srcmac>>0)&0xFF),
|
||||
(long long unsigned int)srcmac));
|
||||
LOG(logINFO, ("\tSource Port : %d \t\t\t(0x%08x)\n", srcport, srcport));
|
||||
|
||||
LOG(logINFO, ("\tDest. IP : %d.%d.%d.%d \t\t(0x%08x)\n",
|
||||
(dstip>>24)&0xff,(dstip>>16)&0xff,(dstip>>8)&0xff,(dstip)&0xff, dstip));
|
||||
LOG(logINFO, ("\tDest. MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n",
|
||||
(unsigned int)((dstmac>>40)&0xFF),
|
||||
(unsigned int)((dstmac>>32)&0xFF),
|
||||
(unsigned int)((dstmac>>24)&0xFF),
|
||||
(unsigned int)((dstmac>>16)&0xFF),
|
||||
(unsigned int)((dstmac>>8)&0xFF),
|
||||
(unsigned int)((dstmac>>0)&0xFF),
|
||||
(long long unsigned int)dstmac));
|
||||
LOG(logINFO, ("\tDest. Port : %d \t\t\t(0x%08x)\n\n",dstport, dstport));
|
||||
|
||||
// start addr
|
||||
uint32_t addr = BASE_UDP_RAM;
|
||||
@ -2015,7 +2004,7 @@ int startStateMachine(){
|
||||
if(createUDPSocket(0) != OK) {
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logINFOBLUE, ("starting state machine\n"));
|
||||
LOG(logINFOBLUE, ("Starting State Machine\n"));
|
||||
// set status to running
|
||||
virtual_status = 1;
|
||||
virtual_stop = 0;
|
||||
@ -2040,10 +2029,18 @@ int startStateMachine(){
|
||||
|
||||
#ifdef VIRTUAL
|
||||
void* start_timer(void* arg) {
|
||||
int64_t periodns = getPeriod();
|
||||
int numFrames = (getNumFrames() *
|
||||
getNumTriggers() );
|
||||
int64_t exp_ns = getExpTime();
|
||||
int numRepeats = getNumTriggers();
|
||||
if (getTiming() == AUTO_TIMING) {
|
||||
if (burstMode == BURST_OFF) {
|
||||
numRepeats = 1;
|
||||
} else {
|
||||
numRepeats = getNumBursts();
|
||||
}
|
||||
}
|
||||
int repeatPeriodNs = getBurstPeriod();
|
||||
int numFrames = getNumFrames();
|
||||
int64_t periodNs = getPeriod();
|
||||
int64_t expUs = getExpTime() / 1000;
|
||||
int imagesize = NCHAN * NCHIP * 2;
|
||||
int datasize = imagesize;
|
||||
int packetsize = datasize + sizeof(sls_detector_header);
|
||||
@ -2053,61 +2050,81 @@ void* start_timer(void* arg) {
|
||||
memset(imageData, 0, imagesize);
|
||||
{
|
||||
int i = 0;
|
||||
for (i = 0; i < imagesize; i += sizeof(uint8_t)) {
|
||||
*((uint8_t*)(imageData + i)) = i;
|
||||
for (i = 0; i < imagesize; i += sizeof(uint16_t)) {
|
||||
*((uint16_t*)(imageData + i)) = i;
|
||||
}
|
||||
}
|
||||
|
||||
int frameNr = 0;
|
||||
// loop over number of frames
|
||||
for(frameNr=0; frameNr!= numFrames; ++frameNr ) {
|
||||
{
|
||||
int repeatNr = 0;
|
||||
int frameHeaderNr = 0;
|
||||
// loop over number of repeats
|
||||
for(repeatNr=0; repeatNr!= numRepeats; ++repeatNr ) {
|
||||
|
||||
//check if virtual_stop is high
|
||||
if(virtual_stop == 1){
|
||||
break;
|
||||
}
|
||||
struct timespec rbegin, rend;
|
||||
clock_gettime(CLOCK_REALTIME, &rbegin);
|
||||
|
||||
// sleep for exposure time
|
||||
struct timespec begin, end;
|
||||
clock_gettime(CLOCK_REALTIME, &begin);
|
||||
usleep(exp_ns / 1000);
|
||||
int frameNr = 0;
|
||||
// loop over number of frames
|
||||
for(frameNr = 0; frameNr != numFrames; ++frameNr ) {
|
||||
|
||||
//check if virtual_stop is high
|
||||
if(virtual_stop == 1){
|
||||
break;
|
||||
}
|
||||
|
||||
char packetData[packetsize];
|
||||
memset(packetData, 0, packetsize);
|
||||
// set header
|
||||
sls_detector_header* header = (sls_detector_header*)(packetData);
|
||||
header->frameNumber = frameNr;
|
||||
header->packetNumber = 0;
|
||||
header->modId = 0;
|
||||
header->row = detPos[X];
|
||||
header->column = detPos[Y];
|
||||
header->detType = (uint16_t)myDetectorType;
|
||||
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
|
||||
// sleep for exposure time
|
||||
struct timespec begin, end;
|
||||
clock_gettime(CLOCK_REALTIME, &begin);
|
||||
usleep(expUs);
|
||||
|
||||
// fill data
|
||||
memcpy(packetData + sizeof(sls_detector_header), imageData, datasize);
|
||||
char packetData[packetsize];
|
||||
memset(packetData, 0, packetsize);
|
||||
// set header
|
||||
sls_detector_header* header = (sls_detector_header*)(packetData);
|
||||
header->detType = (uint16_t)myDetectorType;
|
||||
header->version = SLS_DETECTOR_HEADER_VERSION - 1;
|
||||
header->frameNumber = frameHeaderNr;
|
||||
++frameHeaderNr;
|
||||
header->packetNumber = 0;
|
||||
header->modId = 0;
|
||||
header->row = detPos[X];
|
||||
header->column = detPos[Y];
|
||||
|
||||
// send 1 packet = 1 frame
|
||||
sendUDPPacket(0, packetData, packetsize);
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
LOG(logINFO, ("Sent frame: %d\n", frameNr));
|
||||
// fill data
|
||||
memcpy(packetData + sizeof(sls_detector_header), imageData, datasize) ;
|
||||
|
||||
// calculate time left in period
|
||||
int64_t time_ns = ((end.tv_sec - begin.tv_sec) * 1E9 +
|
||||
(end.tv_nsec - begin.tv_nsec));
|
||||
// send 1 packet = 1 frame
|
||||
sendUDPPacket(0, packetData, packetsize);
|
||||
|
||||
// sleep for (period - exptime)
|
||||
if (frameNr < numFrames) { // if there is a next frame
|
||||
if (periodns > time_ns) {
|
||||
usleep((periodns - time_ns)/ 1000);
|
||||
clock_gettime(CLOCK_REALTIME, &end);
|
||||
LOG(logINFO, ("Sent frame: %d (bursts: %d)\n", frameNr, repeatNr));
|
||||
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 (periodNs > timeNs) {
|
||||
usleep((periodNs - timeNs)/ 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
clock_gettime(CLOCK_REALTIME, &rend);
|
||||
int64_t timeNs = ((rend.tv_sec - rbegin.tv_sec) * 1E9 +
|
||||
(rend.tv_nsec - rbegin.tv_nsec));
|
||||
|
||||
// sleep for (repeatPeriodNs - time remaining)
|
||||
if (repeatNr < numRepeats) { // if there is a next repeat
|
||||
if (repeatPeriodNs > timeNs) {
|
||||
usleep((repeatPeriodNs - timeNs)/ 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set register frames left
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closeUDPSocket(0);
|
||||
// set status to idle
|
||||
|
||||
virtual_status = 0;
|
||||
LOG(logINFOBLUE, ("Finished Acquiring\n"));
|
||||
return NULL;
|
||||
|
Reference in New Issue
Block a user