-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
Current measurement #260
base: master
Are you sure you want to change the base?
Current measurement #260
Conversation
Eliminate function using older setup format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of outstream passed into dccwaveform will corrupt wifi buffers if the command is given from a wifi connected jmri or throttle. (Same problem for Ethernet)
Asynchronous additions to wifi/ethernet streams require special handling as the stream is shared between multiple clients and may or may not be in a client transaction at the time the message is issued.
For examples see how prog track commands use callback mechanism and stash the client id.
Please help me to understand. What is async about those calls? They are made from the loop function, similar like responses in DCCExParser. outStream is just a pointer to the stream that is also used in DCCExParser within the same loop system. That way I can send feedback right when analogRead is done. Alternatively I could set a flag and do a separate reporting function and call it from SerialManager.loop2 with serial as parameter. Also this, in my understanding, would be in sync with everything else. What am I missing? |
What you are missing is that the stream passed to parse is only valid for the duration of the parse call... sometimes its a serial (in which case your code would work) and sometimes its a ring buffer ready prepared to return output to the wifi/ethernet caller. Most commands reply immediately without caring but things that want to reply later (eg a cv read) need to re-prepare the buffer to the correct client before writing. The prog track commands have to follow due process to ensure that the reply goes to the original caller AND that only one caller can be asking! The alternative is to create a broadcast function like those in CommandDistributor and send the current to all non-withrottle clients. |
Ok, I added broadcastCurrent. After reviewing the other broadcast functions, this seemed to me like the most logical approach. |
Change overview
a) Internal
After each current measurement, the getCurrentmA() value is squared and added to a rolling average. When getCurrentRMS() is called, the rolling average is divided by buffer size and rounded sqrt is reported. This is the current in mA. Advantage is the calculation is done in DCC EX. Disadvantage is that due to the average calculation reaction of going down to zero is slow
b) broadcast
After each current measurement, the getCurrentmA() result is sent to the serial interface. Processing of RMS calculation is done on the host computer where more memory is available to do a ring buffer for each track for the square values, leading to faster phase out if zero current. This is my preferred solution for the RedHat, would also work for JMRI