Skip to content

Commit

Permalink
Merge branch 'dev/rx_callbacks' into dev/frame_synchronizer
Browse files Browse the repository at this point in the history
  • Loading branch information
thattil committed Sep 12, 2024
2 parents 5f00db7 + 68b1f1a commit a81a56c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 161 deletions.
20 changes: 3 additions & 17 deletions slsReceiverSoftware/include/sls/Receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,14 @@ class Receiver : private virtual slsDetectorDefs {
* - sls_receiver_header frame metadata,
* - dataCallbackHeader metadata
* - pointer to data
* - image size in bytes
* - image size in bytes. Can be modified to the new size to be
* written/streamed. (only smaller value allowed).
*/
void registerCallBackRawDataReady(void (*func)(sls_receiver_header &,
const dataCallbackHeader,
char *, size_t, void *),
char *, size_t &, void *),
void *arg);

/**
* Call back for raw data (modified)
* args to raw data ready callback are:
* - sls_receiver_header frame metadata,
* - dataCallbackHeader metadata
* - pointer to data
* - revDatasize is the reference of data size in bytes.
* Can be modified to the new size to be written/streamed. (only smaller
* value allowed).
*/
void registerCallBackRawDataModifyReady(
void (*func)(sls_receiver_header &, const dataCallbackHeader, char *,
size_t &, void *),
void *arg);

private:
std::unique_ptr<ClientInterface> tcpipInterface;
};
Expand Down
13 changes: 1 addition & 12 deletions slsReceiverSoftware/src/ClientInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,10 @@ void ClientInterface::registerCallBackAcquisitionFinished(
}

void ClientInterface::registerCallBackRawDataReady(
void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t,
void *),
void *arg) {
rawDataReadyCallBack = func;
pRawDataReady = arg;
}

void ClientInterface::registerCallBackRawDataModifyReady(
void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t &,
void *),
void *arg) {
rawDataModifyReadyCallBack = func;
rawDataReadyCallBack = func;
pRawDataReady = arg;
}

Expand Down Expand Up @@ -478,9 +470,6 @@ void ClientInterface::setDetectorType(detectorType arg) {
if (rawDataReadyCallBack != nullptr)
impl()->registerCallBackRawDataReady(rawDataReadyCallBack,
pRawDataReady);
if (rawDataModifyReadyCallBack != nullptr)
impl()->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,
pRawDataReady);

impl()->setThreadIds(parentThreadId, tcpThreadId);
}
Expand Down
13 changes: 2 additions & 11 deletions slsReceiverSoftware/src/ClientInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,9 @@ class ClientInterface : private virtual slsDetectorDefs {
/** params: sls_receiver_header, pointer to data, image size */
void registerCallBackRawDataReady(void (*func)(sls_receiver_header &,
const dataCallbackHeader,
char *, size_t, void *),
char *, size_t &, void *),
void *arg);

/** params: sls_receiver_header, pointer to data, reference to image size */
void registerCallBackRawDataModifyReady(
void (*func)(sls_receiver_header &, const dataCallbackHeader, char *,
size_t &, void *),
void *arg);

private:
void startTCPServer();
int functionTable();
Expand Down Expand Up @@ -193,10 +187,7 @@ class ClientInterface : private virtual slsDetectorDefs {
void *) = nullptr;
void *pAcquisitionFinished{nullptr};
void (*rawDataReadyCallBack)(sls_receiver_header &, dataCallbackHeader,
char *, size_t, void *) = nullptr;
void (*rawDataModifyReadyCallBack)(sls_receiver_header &,
dataCallbackHeader, char *, size_t &,
void *) = nullptr;
char *, size_t &, void *) = nullptr;
void *pRawDataReady{nullptr};

pid_t parentThreadId{0};
Expand Down
26 changes: 4 additions & 22 deletions slsReceiverSoftware/src/DataProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ void DataProcessor::ProcessAnImage(sls_receiver_header &header, size_t &size,

try {
// callbacks
if (rawDataReadyCallBack != nullptr ||
rawDataModifyReadyCallBack != nullptr) {
if (rawDataReadyCallBack != nullptr) {

uint64_t frameIndex = fnum - firstIndex;
// update local copy only if it was updated (to prevent locking each
Expand All @@ -408,17 +407,8 @@ void DataProcessor::ProcessAnImage(sls_receiver_header &header, size_t &size,
flipRows,
localAdditionalJsonHeader};

// normal call back
if (rawDataReadyCallBack != nullptr) {
rawDataReadyCallBack(header, callbackHeader, data, size,
pRawDataReady);
}

// call back with modified size
else if (rawDataModifyReadyCallBack != nullptr) {
rawDataModifyReadyCallBack(header, callbackHeader, data, size,
pRawDataReady);
}
rawDataReadyCallBack(header, callbackHeader, data, size,
pRawDataReady);
}
} catch (const std::exception &e) {
throw RuntimeError("Get Data Callback Error: " + std::string(e.what()));
Expand Down Expand Up @@ -477,18 +467,10 @@ bool DataProcessor::CheckCount() {
}

void DataProcessor::registerCallBackRawDataReady(
void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t,
void *),
void *arg) {
rawDataReadyCallBack = func;
pRawDataReady = arg;
}

void DataProcessor::registerCallBackRawDataModifyReady(
void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t &,
void *),
void *arg) {
rawDataModifyReadyCallBack = func;
rawDataReadyCallBack = func;
pRawDataReady = arg;
}

Expand Down
23 changes: 2 additions & 21 deletions slsReceiverSoftware/src/DataProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,9 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
/** params: sls_receiver_header, pointer to data, image size */
void registerCallBackRawDataReady(void (*func)(sls_receiver_header &,
dataCallbackHeader, char *,
size_t, void *),
size_t &, void *),
void *arg);

/** params: sls_receiver_header, pointer to data, reference to image size */
void registerCallBackRawDataModifyReady(void (*func)(sls_receiver_header &,
dataCallbackHeader,
char *, size_t &,
void *),
void *arg);

private:
void RecordFirstIndex(uint64_t fnum);

Expand Down Expand Up @@ -210,19 +203,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject {
* dataSize in bytes is the size of the data in bytes.
*/
void (*rawDataReadyCallBack)(sls_receiver_header &, dataCallbackHeader,
char *, size_t, void *) = nullptr;

/**
* Call back for raw data (modified)
* args to raw data ready callback are
* sls_receiver_header frame metadata
* dataPointer is the pointer to the data
* revDatasize is the reference of data size in bytes. Can be modified to
* the new size to be written/streamed. (only smaller value).
*/
void (*rawDataModifyReadyCallBack)(sls_receiver_header &,
dataCallbackHeader, char *, size_t &,
void *) = nullptr;
char *, size_t &, void *) = nullptr;

void *pRawDataReady{nullptr};
};
Expand Down
18 changes: 1 addition & 17 deletions slsReceiverSoftware/src/Implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,11 +1128,6 @@ void Implementation::setNumberofUDPInterfaces(const int n) {
it->registerCallBackRawDataReady(rawDataReadyCallBack,
pRawDataReady);
}
if (rawDataModifyReadyCallBack) {
for (const auto &it : dataProcessor)
it->registerCallBackRawDataModifyReady(
rawDataModifyReadyCallBack, pRawDataReady);
}

// test socket buffer size with current set up
setUDPSocketBufferSize(0);
Expand Down Expand Up @@ -1813,7 +1808,7 @@ void Implementation::registerCallBackAcquisitionFinished(
}

void Implementation::registerCallBackRawDataReady(
void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t,
void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t &,
void *),
void *arg) {
rawDataReadyCallBack = func;
Expand All @@ -1822,15 +1817,4 @@ void Implementation::registerCallBackRawDataReady(
it->registerCallBackRawDataReady(rawDataReadyCallBack, pRawDataReady);
}

void Implementation::registerCallBackRawDataModifyReady(
void (*func)(sls_receiver_header &, dataCallbackHeader, char *, size_t &,
void *),
void *arg) {
rawDataModifyReadyCallBack = func;
pRawDataReady = arg;
for (const auto &it : dataProcessor)
it->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,
pRawDataReady);
}

} // namespace sls
13 changes: 2 additions & 11 deletions slsReceiverSoftware/src/Implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,8 @@ class Implementation : private virtual slsDetectorDefs {
/** params: sls_receiver_header, pointer to data, image size */
void registerCallBackRawDataReady(void (*func)(sls_receiver_header &,
dataCallbackHeader, char *,
size_t, void *),
size_t &, void *),
void *arg);
/** params: sls_receiver_header, pointer to data, reference to image size */
void registerCallBackRawDataModifyReady(void (*func)(sls_receiver_header &,
dataCallbackHeader,
char *, size_t &,
void *),
void *arg);

private:
void SetLocalNetworkParameters();
Expand Down Expand Up @@ -386,10 +380,7 @@ class Implementation : private virtual slsDetectorDefs {
void *){nullptr};
void *pAcquisitionFinished{nullptr};
void (*rawDataReadyCallBack)(sls_receiver_header &, dataCallbackHeader,
char *, size_t, void *){nullptr};
void (*rawDataModifyReadyCallBack)(sls_receiver_header &,
dataCallbackHeader, char *, size_t &,
void *){nullptr};
char *, size_t &, void *){nullptr};
void *pRawDataReady{nullptr};

// class objects
Expand Down
58 changes: 16 additions & 42 deletions slsReceiverSoftware/src/MultiReceiverApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,15 @@ void AcquisitionFinished(
<< "\n\t]";
}

void printDataCallBackHeader(slsDetectorDefs::sls_receiver_header &header,
slsDetectorDefs::dataCallbackHeader callbackHeader,
char *dataPointer, size_t imageSize,
void *objectPointer) {
/**
* Get Receiver Data Call back
* Prints in different colors(for each receiver process) the different headers
* for each image call back.
*/
void GetData(slsDetectorDefs::sls_receiver_header &header,
slsDetectorDefs::dataCallbackHeader callbackHeader,
char *dataPointer, size_t &imageSize, void *objectPointer) {

slsDetectorDefs::sls_detector_header detectorHeader = header.detHeader;

PRINT_IN_COLOR(
Expand Down Expand Up @@ -136,36 +141,9 @@ void printDataCallBackHeader(slsDetectorDefs::sls_receiver_header &header,
detectorHeader.version,
// header->packetsMask.to_string().c_str(),
((uint8_t)(*((uint8_t *)(dataPointer)))), imageSize);
}

/**
* Get Receiver Data Call back
* Prints in different colors(for each receiver process) the different headers
* for each image call back.
*/
void GetData(slsDetectorDefs::sls_receiver_header &header,
slsDetectorDefs::dataCallbackHeader callbackHeader,
char *dataPointer, size_t imageSize, void *objectPointer) {
printDataCallBackHeader(header, callbackHeader, dataPointer, imageSize,
objectPointer);
}

/**
* Get Receiver Data Call back (modified)
* Prints in different colors(for each receiver process) the different headers
* for each image call back.
* @param modifiedImageSize new data size in bytes after the callback.
* This will be the size written/streamed. (only smaller value is allowed).
*/
void GetData(slsDetectorDefs::sls_receiver_header &header,
slsDetectorDefs::dataCallbackHeader callbackHeader,
char *dataPointer, size_t &modifiedImageSize,
void *objectPointer) {
printDataCallBackHeader(header, callbackHeader, dataPointer,
modifiedImageSize, objectPointer);

// if data is modified, eg ROI and size is reduced
modifiedImageSize = 26000;
imageSize = 26000;
}

/**
Expand Down Expand Up @@ -254,26 +232,22 @@ int main(int argc, char *argv[]) {
throw;
}
/** - register callbacks. remember to set file write enable to 0
(using the client) if we should not write files and you will write data
using the callbacks */
* (using the client) if we should not write files and you will
* write data using the callbacks */
if (withCallback) {

/** - Call back for start acquisition */
cprintf(BLUE, "Registering StartAcq()\n");
cprintf(BLUE, "Registering StartAcq()\n");
receiver->registerCallBackStartAcquisition(StartAcq, nullptr);

/** - Call back for acquisition finished */
cprintf(BLUE, "Registering AcquisitionFinished()\n");
cprintf(BLUE, "Registering AcquisitionFinished()\n");
receiver->registerCallBackAcquisitionFinished(
AcquisitionFinished, nullptr);

/* - Call back for raw data */
cprintf(BLUE, "Registering GetData() \n");
if (withCallback == 1)
receiver->registerCallBackRawDataReady(GetData, nullptr);
else if (withCallback == 2)
receiver->registerCallBackRawDataModifyReady(GetData,
nullptr);
cprintf(BLUE, "Registering GetData() \n");
receiver->registerCallBackRawDataReady(GetData, nullptr);
}

/** - as long as no Ctrl+C */
Expand Down
9 changes: 1 addition & 8 deletions slsReceiverSoftware/src/Receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,10 @@ void Receiver::registerCallBackAcquisitionFinished(
}

void Receiver::registerCallBackRawDataReady(
void (*func)(sls_receiver_header &, const dataCallbackHeader, char *,
size_t, void *),
void *arg) {
tcpipInterface->registerCallBackRawDataReady(func, arg);
}

void Receiver::registerCallBackRawDataModifyReady(
void (*func)(sls_receiver_header &, const dataCallbackHeader, char *,
size_t &, void *),
void *arg) {
tcpipInterface->registerCallBackRawDataModifyReady(func, arg);
tcpipInterface->registerCallBackRawDataReady(func, arg);
}

} // namespace sls

0 comments on commit a81a56c

Please sign in to comment.