Skip to content

Commit

Permalink
Update frame.py
Browse files Browse the repository at this point in the history
Updates to run in the SINTEF lab

I changed collections to collections.abs in frame.py. Since Sequence was moved to collections.abc as of Python 3.7.

It seems that we are receiving frequency and not frequency deviations. I therefore implemented iicsys#3 (comment) . I also implemented iicsys#35 (comment) to fix a bug.
  • Loading branch information
Hofsmo committed Aug 10, 2022
1 parent 17029c0 commit 7013d81
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions synchrophasor/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""

import collections
import collections.abc
from abc import ABCMeta, abstractmethod
from struct import pack, unpack
from time import time
Expand Down Expand Up @@ -232,7 +232,7 @@ def set_time(self, soc=None, frasec=None):
self.set_soc(int(t)) # Get current timestamp

if frasec is not None:
if isinstance(frasec, collections.Sequence):
if isinstance(frasec, collections.abc.Sequence):
self.set_frasec(*frasec)
else:
self.set_frasec(frasec) # Just set fraction of second and use default values for other arguments.
Expand Down Expand Up @@ -1858,6 +1858,7 @@ def __init__(self, pmu_id_code, stat, phasors, freq, dfreq, analog, digital, cfg
self.cfg = cfg
self.set_stat(stat)
self.set_phasors(phasors)
print("Freq is " +str(freq))
self.set_freq(freq)
self.set_dfreq(dfreq)
self.set_analog(analog)
Expand Down Expand Up @@ -1917,7 +1918,7 @@ def _stat2int(measurement_status="ok", sync=True, sorting="timestamp", trigger=F
if isinstance(trigger_reason, str):
trigger_reason = DataFrame.TRIGGER_REASON[trigger_reason]

stat = measurement_status << 2
stat = measurement_status << 1
if not sync:
stat |= 1

Expand Down Expand Up @@ -1952,7 +1953,7 @@ def _stat2int(measurement_status="ok", sync=True, sorting="timestamp", trigger=F
@staticmethod
def _int2stat(stat):

measurement_status = DataFrame.MEASUREMENT_STATUS_WORDS[stat >> 15]
measurement_status = DataFrame.MEASUREMENT_STATUS_WORDS[stat >> 14]
sync = bool(stat & 0x2000)

if stat & 0x1000:
Expand All @@ -1964,8 +1965,8 @@ def _int2stat(stat):
cfg_change = bool(stat & 0x400)
modified = bool(stat & 0x200)

time_quality = DataFrame.TIME_QUALITY_WORDS[stat & 0x1c0]
unlocked = DataFrame.UNLOCKED_TIME_WORDS[stat & 0x30]
time_quality = DataFrame.TIME_QUALITY_WORDS[stat & 0x1c0>>6]
unlocked = DataFrame.UNLOCKED_TIME_WORDS[stat & 0x30>>4]
trigger_reason = DataFrame.TRIGGER_REASON_WORDS[stat & 0xf]

return measurement_status, sync, sorting, trigger, cfg_change, modified, time_quality, unlocked, trigger_reason
Expand Down Expand Up @@ -2141,7 +2142,8 @@ def _freq2int(freq, data_format):
data_format = DataFrame._int2format(data_format)

if data_format[3]: # FREQ/DFREQ floating point
if not -32.767 <= freq <= 32.767:
#if not -32.767 <= freq <= 32.767:
if not -100 <= freq <= 100:
raise ValueError("FREQ must be in range -32.767 <= FREQ <= 32.767.")

freq = unpack("!I", pack("!f", float(freq)))[0]
Expand Down Expand Up @@ -2419,7 +2421,7 @@ def convert2frame(byte_data, cfg):

if not CommonFrame._check_crc(byte_data):
raise FrameError("CRC failed. Configuration frame not valid.")

print(cfg)
num_pmu = cfg.get_num_pmu()
data_format = cfg.get_data_format()
phasor_num = cfg.get_phasor_num()
Expand Down

0 comments on commit 7013d81

Please sign in to comment.