-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/examples v0.6 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alien588
wants to merge
53
commits into
main
Choose a base branch
from
feature/examples-v0.6
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 44da1ba
Added a utility method for retrieval of sample rate from domain data …
alien588 d4b9472
2.0 example draft
alien588 1e67a95
tree_traversal example update
alien588 6b346c1
Updated Tree traversal example
alien588 eb83099
Added first iteration of tree traversal
alien588 0fafd54
Updated framework of the example
alien588 b5a15c3
Updated numenclatire and creted a simple version of the display sctript
alien588 33b3752
Addressed code review
alien588 cca8ea5
Missing changes required by the code review
alien588 ed39e4f
Removed use of block reader
alien588 ad407d5
Mssing dots
alien588 f4b2a53
Updated comment
alien588 a5f03dc
Updated calculation of sampleRate
alien588 ec07eb5
Fixed sampleRate calculation function in daq_utils
alien588 d02ccae
Addressing a code review
alien588 d27e326
Added a new utility method for checking if the data rule is linear
alien588 cd757d5
Refactored sample rate calculation method
alien588 a0d2f18
Fixed a typo
alien588 b4ed30e
Renaming functions and misc printout format fix
alien588 2d836d1
Added basic information display for nodes when traversing the tree
alien588 7f63be8
Updated structure
alien588 d2b0566
Added sceleton for globalID search
alien588 1a84ccd
Removed hanging TODO comments and misc.
alien588 c9cbf11
Removed unnecesary comments
alien588 2591238
Missed it
alien588 36bcb0e
Updated exaple to a working state
alien588 39204d3
Remowed access new line
alien588 568f656
Updated example and removed dangling comments
alien588 b00df6e
Merge branch 'main' into feature/examples-v0.6
alien588 481bbdb
Updated the example
alien588 72c0eb7
Renamed example
alien588 27b7ded
Renamed variable for greater clarity
alien588 0c8b358
Updated example description
alien588 4033bfe
Set required openDAQ CMake flags
JakaMohorko e5d530f
Disable logging, use instance builder and module path
JakaMohorko ef7e4af
Added a utility method for retrieval of sample rate from domain data …
alien588 9a1c2a7
2.0 example draft
alien588 e645142
Addressed code review
alien588 8d033ba
Missing changes required by the code review
alien588 034ddbb
Updated exaple to a working state
alien588 72765da
Updated example and removed dangling comments
alien588 a0ed3af
Renamed example
alien588 bf54bf4
Merge branch 'main' into feature/examples-v0.6
alien588 a5fd85e
Removing merging artifacts
alien588 ced9806
Removing artifacts 2.0
alien588 e48d4c0
Code review pt.1
alien588 8afe760
Addressed code review
alien588 30f3325
Removed redundant function
alien588 7423063
Addessed the second code review
alien588 9f2e794
Addressed the requested minor changes
alien588 724772a
Updated comment about channels
alien588 1065cec
Removed unnecessary indents
alien588 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
alien588 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.