Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5271c1a
Updated iteration to for loop style from while iteration
alien588 Dec 24, 2025
44da1ba
Added a utility method for retrieval of sample rate from domain data …
alien588 Dec 24, 2025
d4b9472
2.0 example draft
alien588 Jan 6, 2026
1e67a95
tree_traversal example update
alien588 Jan 7, 2026
6b346c1
Updated Tree traversal example
alien588 Jan 7, 2026
eb83099
Added first iteration of tree traversal
alien588 Jan 9, 2026
0fafd54
Updated framework of the example
alien588 Jan 12, 2026
b5a15c3
Updated numenclatire and creted a simple version of the display sctript
alien588 Jan 12, 2026
33b3752
Addressed code review
alien588 Dec 9, 2025
cca8ea5
Missing changes required by the code review
alien588 Dec 9, 2025
ed39e4f
Removed use of block reader
alien588 Jan 6, 2026
ad407d5
Mssing dots
alien588 Jan 6, 2026
f4b2a53
Updated comment
alien588 Jan 6, 2026
a5f03dc
Updated calculation of sampleRate
alien588 Jan 6, 2026
ec07eb5
Fixed sampleRate calculation function in daq_utils
alien588 Jan 6, 2026
d02ccae
Addressing a code review
alien588 Jan 7, 2026
d27e326
Added a new utility method for checking if the data rule is linear
alien588 Jan 7, 2026
cd757d5
Refactored sample rate calculation method
alien588 Jan 7, 2026
a0d2f18
Fixed a typo
alien588 Jan 7, 2026
b4ed30e
Renaming functions and misc printout format fix
alien588 Jan 8, 2026
2d836d1
Added basic information display for nodes when traversing the tree
alien588 Jan 12, 2026
7f63be8
Updated structure
alien588 Jan 13, 2026
d2b0566
Added sceleton for globalID search
alien588 Jan 13, 2026
1a84ccd
Removed hanging TODO comments and misc.
alien588 Jan 14, 2026
c9cbf11
Removed unnecesary comments
alien588 Jan 14, 2026
2591238
Missed it
alien588 Jan 14, 2026
36bcb0e
Updated exaple to a working state
alien588 Jan 15, 2026
39204d3
Remowed access new line
alien588 Jan 15, 2026
568f656
Updated example and removed dangling comments
alien588 Jan 16, 2026
b00df6e
Merge branch 'main' into feature/examples-v0.6
alien588 Jan 20, 2026
481bbdb
Updated the example
alien588 Jan 20, 2026
72c0eb7
Renamed example
alien588 Jan 20, 2026
27b7ded
Renamed variable for greater clarity
alien588 Jan 20, 2026
0c8b358
Updated example description
alien588 Jan 21, 2026
4033bfe
Set required openDAQ CMake flags
JakaMohorko Jan 21, 2026
e5d530f
Disable logging, use instance builder and module path
JakaMohorko Jan 21, 2026
ef7e4af
Added a utility method for retrieval of sample rate from domain data …
alien588 Dec 24, 2025
9a1c2a7
2.0 example draft
alien588 Jan 6, 2026
e645142
Addressed code review
alien588 Dec 9, 2025
8d033ba
Missing changes required by the code review
alien588 Dec 9, 2025
034ddbb
Updated exaple to a working state
alien588 Jan 15, 2026
72765da
Updated example and removed dangling comments
alien588 Jan 16, 2026
a0ed3af
Renamed example
alien588 Jan 20, 2026
bf54bf4
Merge branch 'main' into feature/examples-v0.6
alien588 Jan 21, 2026
a5fd85e
Removing merging artifacts
alien588 Jan 21, 2026
ced9806
Removing artifacts 2.0
alien588 Jan 21, 2026
e48d4c0
Code review pt.1
alien588 Jan 26, 2026
8afe760
Addressed code review
alien588 Jan 27, 2026
30f3325
Removed redundant function
alien588 Jan 27, 2026
7423063
Addessed the second code review
alien588 Jan 27, 2026
9f2e794
Addressed the requested minor changes
alien588 Jan 30, 2026
724772a
Updated comment about channels
alien588 Jan 30, 2026
1065cec
Removed unnecessary indents
alien588 Feb 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ set(EXAMPLE_SOURCES
stream_reader_read_in_loop.c
read_with_formatted_timestamps.c
print_data_descriptor_and_calculater_sample_rate.c
create_and_read_sample_rate_buffers.c)

create_and_read_sample_rate_buffers.c
tree_traversal.c)

foreach(src ${EXAMPLE_SOURCES})
get_filename_component(exec_name ${src} NAME_WLE)
Expand Down
363 changes: 363 additions & 0 deletions examples/tree_traversal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,363 @@
/*
* In openDAQ devices are represented by a tree structure. Example demonstrates how to fully explore that tree and displays
* the type of the object alongside its name. After saving every object into an dictionary, example displays all of saved objects
* globalIds.
*/

#include <daq_utils.h>

enum ComponentType
{
DaqUnknown = 0,
DaqDevice,
DaqFunctionBlock,
DaqIOFolder,
DaqChannel,
DaqServer,
DaqSignal,
DaqFolder,
DaqComponent,
DaqSyncComponent,
DaqInputPort
};

void printDaqObject(daqBaseObject* baseObject, enum ComponentType compType, uint8_t indent);

enum ComponentType getComponentType(daqBaseObject* baseObject);

void printDaqDevice(daqBaseObject* baseObject, uint8_t indent);

void printDaqChannel(daqBaseObject* baseObject, uint8_t indent);

void printDaqFunctionBlock(daqBaseObject* baseObject, uint8_t indent);

void printDaqFolder(daqBaseObject* baseObject, uint8_t indent);

void printDaqServer(daqBaseObject* baseObject, uint8_t indent);

void printDaqSyncComponent(daqBaseObject* baseObject, uint8_t indent);

void printInputPort(daqBaseObject* baseObject, uint8_t indent);

void printDaqSignal(daqBaseObject* baseObject, uint8_t indent);

void printDaqObject(daqBaseObject* baseObject, enum ComponentType compType, uint8_t indent)
{
switch (compType)
{
case DaqDevice:
printDaqDevice(baseObject, indent);
break;

case DaqServer:
printDaqServer(baseObject, indent);
break;

case DaqSyncComponent:
printDaqSyncComponent(baseObject, indent);
break;

case DaqChannel:
printDaqChannel(baseObject, indent);
break;

case DaqFunctionBlock:
printDaqFunctionBlock(baseObject, indent);
break;

case DaqFolder:
printDaqFolder(baseObject, indent);
break;

case DaqInputPort:
printInputPort(baseObject, indent);
break;

case DaqSignal:
printDaqSignal(baseObject, indent);
break;

default:
break;
}
}

enum ComponentType getComponentType(daqBaseObject* baseObject)
{
if (DAQ_SUPPORTS_INTERFACE(baseObject, DAQ_DEVICE_INTF_ID))
return DaqDevice;

else if (DAQ_SUPPORTS_INTERFACE(baseObject, DAQ_SERVER_INTF_ID))
return DaqServer;

else if (DAQ_SUPPORTS_INTERFACE(baseObject, DAQ_SYNC_COMPONENT_INTF_ID))
return DaqSyncComponent;

else if (DAQ_SUPPORTS_INTERFACE(baseObject, DAQ_CHANNEL_INTF_ID))
return DaqChannel;

else if (DAQ_SUPPORTS_INTERFACE(baseObject, DAQ_FUNCTION_BLOCK_INTF_ID))
return DaqFunctionBlock;

else if (DAQ_SUPPORTS_INTERFACE(baseObject, DAQ_FOLDER_INTF_ID))
return DaqFolder;

else if (DAQ_SUPPORTS_INTERFACE(baseObject, DAQ_INPUT_PORT_INTF_ID))
return DaqInputPort;

else if (DAQ_SUPPORTS_INTERFACE(baseObject, DAQ_SIGNAL_INTF_ID))
return DaqSignal;

return DaqUnknown;
}

void printObjectList(daqList* list, enum ComponentType compType, uint8_t indent)
{
daqBaseObject* listMember = NULL;
daqSizeT count = 0;
daqList_getCount(list, &count);
if (count <= 0)
return;
daqList_getItemAt(list, 0, &listMember);

if (compType == DaqUnknown)
compType = getComponentType(listMember);

count = 0;
daqList_getCount(list, &count);

for (daqSizeT i = 0; i < count; i++)
{
daqList_getItemAt(list, i, &listMember);

printDaqObject(listMember, compType, indent);

daqReleaseRef(listMember);
}
}

void printDaqDevice(daqBaseObject* baseObject, uint8_t indent)
{
daqDevice* device = NULL;
daqQueryInterface(baseObject, DAQ_DEVICE_INTF_ID, &device);
daqString* localId = NULL;
daqComponent_getLocalId((daqComponent*)device, &localId);

if (localId != NULL)
{
printf("%*c", indent, ' ');
printDaqFormattedString("Device: %s\n", localId);
}

// IOFolder is a SPECIAL TYPE of FOLDER that only accepts
// IChannel and IIoFolderConfig components.
daqFolder* ioFolder = NULL;
daqDevice_getInputsOutputsFolder(device, &ioFolder);
if (ioFolder != NULL)
{
printDaqFolder(ioFolder, indent+1);
daqReleaseRef(ioFolder);
}

daqSyncComponent* syncComponent = NULL;
daqDevice_getSyncComponent(device, &syncComponent);
if (syncComponent != NULL)
{
printDaqSyncComponent(syncComponent, indent+1);
daqReleaseRef(syncComponent);
}

daqList* devices = NULL;
daqDevice_getDevices(device, &devices, NULL);
if (devices != NULL)
{
printObjectList(devices, DaqDevice, indent+1);
daqReleaseRef(devices);
}

daqList* functionBlocks = NULL;
daqDevice_getFunctionBlocks(device, &functionBlocks, NULL);
if (functionBlocks != NULL)
{
printObjectList(functionBlocks, DaqFunctionBlock, indent+1);
daqReleaseRef(functionBlocks);
}

daqList* servers = NULL;
daqDevice_getServers(device, &servers);
if (servers != NULL)
{
printObjectList(servers, DaqServer, indent+1);
daqReleaseRef(servers);
}

daqReleaseRef(localId);
daqReleaseRef(device);
}

void printDaqChannel(daqBaseObject* baseObject, uint8_t indent)
{
// Channels represent physical sensors in openDAQ.
// Their internal structure is the same as that of the function block.
printDaqFunctionBlock(baseObject, indent);
}

void printDaqFunctionBlock(daqBaseObject* baseObject, uint8_t indent)
{
daqFunctionBlock* functionBlock = NULL;
daqQueryInterface(baseObject, DAQ_FUNCTION_BLOCK_INTF_ID, &functionBlock);
daqString* localId = NULL;
daqComponent_getLocalId((daqComponent*)functionBlock, &localId);

if (localId != NULL)
{
printf("%*c", indent, ' ');
printDaqFormattedString("Function block: %s\n", localId);
}

daqList* functionBlocks = NULL;
daqFunctionBlock_getFunctionBlocks(functionBlock, &functionBlocks, NULL);
if (functionBlocks != NULL)
{
printObjectList(functionBlocks, DaqFunctionBlock, indent+1);
daqReleaseRef(functionBlocks);
}

daqList* inputPorts = NULL;
daqFunctionBlock_getInputPorts(functionBlock, &inputPorts, NULL);
if (inputPorts != NULL)
{
printObjectList(inputPorts, DaqInputPort, indent+1);
daqReleaseRef(inputPorts);
}

daqList* listOfSignals = NULL;
daqFunctionBlock_getSignals(functionBlock, &listOfSignals, NULL);
if (listOfSignals != NULL)
{
printObjectList(listOfSignals, DaqSignal, indent+1);
daqReleaseRef(listOfSignals);
}

daqReleaseRef(localId);
daqReleaseRef(functionBlock);
}

void printDaqFolder(daqBaseObject* baseObject, uint8_t indent)
{
daqFolder* folder = NULL;
daqQueryInterface(baseObject, DAQ_FOLDER_INTF_ID, &folder);
daqString* localId = NULL;
daqComponent_getName((daqComponent*) folder, &localId);

if (localId != NULL)
{
printf("%*c", indent, ' ');
printDaqFormattedString("Folder: %s\n", localId);
}

daqList* listOfItems = NULL;
daqFolder_getItems(folder, &listOfItems, NULL);
if (listOfItems != NULL)
{
printObjectList(listOfItems, DaqUnknown, indent+1);
daqReleaseRef(listOfItems);
}

daqReleaseRef(localId);
daqReleaseRef(folder);
}

void printDaqServer(daqBaseObject* baseObject, uint8_t indent)
{
daqServer* server = NULL;
daqQueryInterface(baseObject, DAQ_SERVER_INTF_ID, &server);

daqString* localId = NULL;
daqComponent_getLocalId((daqComponent*)server, &localId);

if (localId != NULL)
{
printf("%*c", indent, ' ');
printDaqFormattedString("Server: %s\n", localId);
}

daqList* listOfSignals = NULL;
daqServer_getSignals(server, &listOfSignals, NULL);
if (listOfSignals != NULL)
{
printObjectList(listOfSignals, DaqSignal, indent+1);
daqReleaseRef(listOfSignals);
}

daqReleaseRef(localId);
daqReleaseRef(server);
}

void printDaqSyncComponent(daqBaseObject* baseObject, uint8_t indent)
{
daqSyncComponent* syncComp = NULL;
daqQueryInterface(baseObject, DAQ_SYNC_COMPONENT_INTF_ID, &syncComp);
daqString* localId = NULL;
daqComponent_getLocalId((daqComponent*)syncComp, &localId);

if (localId != NULL)
{
printf("%*c", indent, ' ');
printDaqFormattedString("Sync component: %s\n", localId);
}

daqReleaseRef(localId);
daqReleaseRef(syncComp);
}

void printInputPort(daqBaseObject* baseObject, uint8_t indent)
{
daqInputPort* inputPort = NULL;
daqQueryInterface(baseObject, DAQ_INPUT_PORT_INTF_ID, &inputPort);
daqString* localId = NULL;
daqComponent_getLocalId((daqComponent*)inputPort, &localId);

if (localId != NULL)
{
printf("%*c", indent, ' ');
printDaqFormattedString("Input port: %s\n", localId);
}

daqReleaseRef(localId);
daqReleaseRef(inputPort);
}

void printDaqSignal(daqBaseObject* baseObject, uint8_t indent)
{
daqSignal* signal = NULL;
daqQueryInterface(baseObject, DAQ_SIGNAL_INTF_ID, &signal);
daqString* localId = NULL;
daqComponent_getLocalId((daqComponent*)signal, &localId);

if (localId != NULL)
{
printf("%*c", indent, ' ');
printDaqFormattedString("Signal: %s\n", localId);
}

daqReleaseRef(localId);
daqReleaseRef(signal);
}

int main()
{
daqInstance* simulatorInstance = NULL;
setupSimulator(&simulatorInstance);

daqInstance* instance = NULL;
daqDevice* simulator = NULL;
addSimulator(&simulator, &instance);

printDaqDevice((daqDevice*) instance, 0);

daqReleaseRef(simulator);
daqReleaseRef(instance);
daqReleaseRef(simulatorInstance);
return 0;
}