Skip to content
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

There needs to be a deterministic way to determine when a metaSignal command has completed #42

Open
chefsteph9 opened this issue Jun 1, 2017 · 0 comments
Assignees

Comments

@chefsteph9
Copy link
Contributor

Currently, there is just a timer after the dataHub.megaSignalCommand is issued to make sure that it has been executed. This is non-deterministic and is not guaranteed to work. There needs to be a way for the DataHub to let the web page know when the MetaSignalCommand has executed.

An example of code that uses a timer when a better solution is needed is the addNewSignals function in
io-mapping-scripts.js:

    $scope.addNewSignals = function () {
        var promises = [];
        $.each($scope.mapping.Type.Fields, function (i, f) {
            var ms = {
                'AnalyticProjectName': $('#proj' + f.Identifier).val(),
                'AnalyticInstanceName': $('#inst' + f.Identifier).val(),
                'DeviceID': '00000000-0000-0000-0000-000000000000',
                'RuntimeID': 0,
                'SignalID': $('#signalID' + f.Identifier).val(),
                'PointTag': $('#point' + f.Identifier).val(),
                'SignalType': $('#type' + f.Identifier).val(),
                'Description': $('#desc' + f.Identifier).val()
            }
            $scope.mapping.FieldMappings[i].Expression = $('#point' + f.Identifier).val();
            promises.push(dataHub.metaSignalCommand(ms));
        });

        $(promises).whenAll().done(function () {
            // TODO: The setTimout is a temporary solution. A more permanent solution would involve maintaining a count of the number of metasignals sent and received
            // and refreshing the metadata when we know that all metasignal commands have been executed sucessfully.
            setTimeout(function () {  
                $(window).one('metaDataReceived', function () {  
                    dataHub.getMeasurementDetails().done(function (md) {
                        $.each($scope.mapping.Type.Fields, function (i, f) {
                            var signals = $.grep(md, function (d) { return d.PointTag == $('#point' + f.Identifier).val() });
                            if (signals.length > 0) {
                                $('#signalID' + f.Identifier).val(signals[0].SignalID);
                            }
                        });
                    });
                });
                dataHub.refreshMetaData();
            }, 1100); // If it's not working, make this number bigger. See: TODO above.
        });
        $scope.signalsAdded = true;
        $('#signalDialog').modal('hide');
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants