Skip to content

Commit

Permalink
Start optimising
Browse files Browse the repository at this point in the history
at 1000Hz it is OK

INFO: RAW data file: /dev/shm/module_0_0.raw size 3774873600
INFO: Send 36000 frames in 36.020763s

INFO: RAW data file: /dev/shm/module_2_0.raw size 3774873600
INFO: Send 36000 frames in 36.001865s
  • Loading branch information
graeme-winter committed Dec 4, 2024
1 parent b76732d commit ce23e94
Showing 1 changed file with 6 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2757,7 +2757,7 @@ void *start_timer(void *arg) {

char filename[80];

sprintf(filename, "/tmp/module_%d_%d.raw", detPos[3], detPos[0]);
sprintf(filename, "/dev/shm/module_%d_%d.raw", detPos[3], detPos[0]);

struct stat fileinfo;
stat(filename, &fileinfo);
Expand All @@ -2777,14 +2777,9 @@ void *start_timer(void *arg) {
}
int firstDest = getFirstUDPDestination();

// FIXME replace this with a forced cycle time which will wait for
// period between sending frame j and j+1
int transmissionDelayUs = getTransmissionDelayFrame() * 1000;
int numInterfaces = getNumberofUDPInterfaces();
int64_t periodNs = getPeriod();
int numFrames = (getNumFrames() * getNumTriggers() *
(getNumAdditionalStorageCells() + 1));
int64_t expUs = getExpTime() / 1000;

// Data size here is 4096 x uint16_t pixels
const int dataSize = 8192;
Expand All @@ -2809,16 +2804,6 @@ void *start_timer(void *arg) {
const int packetsPerFrame =
((maxPacketsPerFrame / 2) * readNRows) / (maxRows / 2);

// Generate data - nope we will be pulling this from a configuration file
char imageData[DATA_BYTES];


const int npixels = (NCHAN * NCHIP);
const int pixelsPerPacket = dataSize / NUM_BYTES_PER_PIXEL;
int dataVal = 0;
int gainVal = 0;
int pixelVal = 0;

uint64_t frameNr = 0;
getNextFrameNumber(&frameNr);
int iRxEntry = firstDest;
Expand All @@ -2844,18 +2829,18 @@ void *start_timer(void *arg) {
break;
}

int srcOffset = 0;
int srcOffset2 = DATA_BYTES / 2;
int row0 = (numInterfaces == 1 ? detPos[1] : detPos[3]);
int col0 = (numInterfaces == 1 ? detPos[0] : detPos[2]);
int row1 = detPos[1];
int col1 = detPos[0];
// loop packet (128 packets)
for (int i = 0; i != maxPacketsPerFrame; ++i, chunk++) {

char packetData[packetsize];

unsigned long long chunk_offset = (chunk * 0x2000) % fileinfo.st_size;
fseek(fin, chunk_offset, SEEK_SET);
fread(imageData, 0x2000, 1, fin);
fread(packetData + sizeof(sls_detector_header), 0x2000, 1, fin);

const int startval =
(maxPacketsPerFrame / 2) - (packetsPerFrame / 2);
Expand All @@ -2864,8 +2849,6 @@ void *start_timer(void *arg) {

// first interface
if (numInterfaces == 1 || i < (maxPacketsPerFrame / 2)) {
char packetData[packetsize];
memset(packetData, 0, packetsize);
sls_detector_header *header =
(sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType;
Expand All @@ -2876,11 +2859,6 @@ void *start_timer(void *arg) {
header->row = row0;
header->column = col0;

// fill data
memcpy(packetData + sizeof(sls_detector_header),
imageData + srcOffset, dataSize);
srcOffset += dataSize;

if (i >= startval && i <= endval) {
sendUDPPacket(iRxEntry, 0, packetData, packetsize);
LOG(logDEBUG1, ("Sent packet: %d [interface 0]\n", i));
Expand All @@ -2891,10 +2869,8 @@ void *start_timer(void *arg) {
else if (numInterfaces == 2 && i >= (maxPacketsPerFrame / 2)) {
pnum = i % (maxPacketsPerFrame / 2);

char packetData2[packetsize];
memset(packetData2, 0, packetsize);
sls_detector_header *header =
(sls_detector_header *)(packetData2);
(sls_detector_header *)(packetData);
header->detType = (uint16_t)myDetectorType;
header->version = SLS_DETECTOR_HEADER_VERSION;
header->frameNumber = frameNr + iframes;
Expand All @@ -2903,20 +2879,13 @@ void *start_timer(void *arg) {
header->row = row1;
header->column = col1;

// fill data
memcpy(packetData2 + sizeof(sls_detector_header),
imageData + srcOffset2, dataSize);
srcOffset2 += dataSize;

if (i >= startval && i <= endval) {
sendUDPPacket(iRxEntry, 1, packetData2, packetsize);
sendUDPPacket(iRxEntry, 1, packetData, packetsize);
LOG(logDEBUG1,
("Sent packet: %d [interface 1]\n", pnum));
}
}
}
LOG(logINFO, ("Sent frame %d [#%ld] to E%d\n", iframes,
frameNr + iframes, iRxEntry));
++iRxEntry;
if (iRxEntry == numUdpDestinations) {
iRxEntry = 0;
Expand Down

0 comments on commit ce23e94

Please sign in to comment.