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

Lock mechanism seems to be not working #3

Open
PhilippHaefele opened this issue Apr 16, 2018 · 6 comments
Open

Lock mechanism seems to be not working #3

PhilippHaefele opened this issue Apr 16, 2018 · 6 comments
Assignees

Comments

@PhilippHaefele
Copy link

PhilippHaefele commented Apr 16, 2018

I'm working on https://www.npmjs.com/package/node-red-node-pi-gpiod and found some issues regarding the Lock mechanism of this library.

Seems that something went wrong in acquireLock().
You are checking in Line 46 if the lock entry !== undefined what is ok for waiting if it is set, but it isn't set at startup, so the loop "content" will never be called. The result is that it never gets set.

I also ran into some problems with timeout() => was never called, so i used process.hrtime() instead.

Result would be something like:

const start = process.hrtime();

while (_LOCKS[this.host + ':' + this.port] !== undefined) {
    var diff = process.hrtime(start)[1] / (1000000 * 500);
        if (diff >= 1){
            break;
        }
}

if (_LOCKS[this.host + ':' + this.port] === undefined) {
    _LOCKS[this.host + ':' + this.port] = 'Locked';
} else {
    throw new Error('Can not acquire Lock');
}

But now i get errors because of the 2nd connection from _callback.js

So my question is how the lock was intended to work?

@miketrebilcock miketrebilcock self-assigned this Apr 17, 2018
@PhilippHaefele
Copy link
Author

Have forked the project and pushed my changes i used to for testing into this branch: https://github.com/Psykoman1990/js-pigpio/tree/fix-lock
Maybe this can help.
Maybe more/all commands need the ", undefined, true);" extension as we need to wait until we get a response from pigpio before sending a new command.

@miketrebilcock
Copy link
Owner

Thanks @Psykoman1990 sorry for not responding sooner. I'll try and look at it this week.

@PhilippHaefele
Copy link
Author

Looked into this issue some days ago again. To use hrtime() is maybe not the best solution too, as it leads to 100% CPU usage. I'll try to look into this again to find an ever better solution. Quite new to JS.

@PhilippHaefele
Copy link
Author

Didn't found any better solution for waiting for release of lock. Do you remember why you only added some "undefined, true" at the end of some "set-_pi_gpio_command" calls?
These ones are the ones without: SERVO, PFS, PUD & FG.

@PhilippHaefele
Copy link
Author

@miketrebilcock Would really appreciate it if you could have a look at this and respond to my last question. Thank you

@PhilippHaefele
Copy link
Author

@miketrebilcock Would be nice if you can have a look at this issue. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants