iicsys / pypmu

pyPMU - Python implementation of the IEEE C37.118 synchrophasor standard
BSD 3-Clause "New" or "Revised" License
62 stars 46 forks source link

UDP Support V0.1 #16

Closed poledna closed 4 years ago

poledna commented 4 years ago

Firstly I'd like to appreciate the work done by @sstevan and @tp0x45 on this awesome project. And Specially thank @sstevan for the support on doing this PR.

A lot of commit and tests for UDP Support, so a short description of what's happening.

I've added the method getReceivedData and the keyword argument receivedData1 on CommonFrame because it's useful for my application and as it is a keyword argument(kwarg)it shouldn't affect backwards compatibility. On the Topic of kwargs I've added the kwargs config2 on PDC init because my PMU won't answer the cfg2 on UDP so I've capture the CFG2 in TCP mode and the use it on UDP ergo the need for a kwarg with the insertion of the cfg2 frame to the PDC class. Also shouldn't change the backward compatibility and doesn't affect TCP connection, in the tests I've made.

On the pmu.py file there are the biggest changes due to UDP. To be noticed that due to issues with daemonic threads and processes I've named them to make them easier to be found. Also I've passed the logger through to the pdc_handler method though the creation of the Process(this removes the need for the logger to be recreated). Also in the pdc_handler method should be seen that there is a 60 second send, on UDP, of the CFG2 frame to the recipient that's due to the OpenPDC for some reason not "being green" without this send each 60 seconds (can provide images if necessary). Also on this file I've added "from traceback import print_exception" that's because of debugging purposes that without was really hard to catch the unhanded exceptions. Probably should be removed. But helps to find error so I left it there to your discretion. As well on this file I've added a list that writes down where to send when start command is received and deletes when stop command is received. So that the module is capable of sending to more than one recipient. Again useful for my application. Also I commented out the sleep on the last lines because I found the need to command the sleep time not using only delay but as shown in tinyRandomPMU(only python 3.8 compatible),the program takes in account the time the program takes to execute.(I removed this file because I couldn't find the source of this algorithm I referenced, in the future can come back as an example)

There's also an interesting thing on UDP (acknowledge I didn't test this on Windows, only on Linux) but for some reason if you read the UDP socket only the 4 first bytes to get the size of the packet, it drops the rest that's the reason the packet read is of the entire packet and not by parts as it is in TCP.

There's also the change I've commented in issue #10 of the value change on line 401 of frame.py get_fracsec method.

I've started on Multicast as well, because the Python syntax isn't much different than UDP, but is still not fully functional. At least I had problems with making it work.

I've added also a acknowledgement to the project that is funding my research. Can (and probably should) be discussed the placement.