示例#1
0
 def regular_date(self):
     return GooseTimestamp(1.1, Quality(raw_value=b'\x00'))
示例#2
0
    'goose_timestamp':
    time(),
    'status_number':
    1,
    'sequence_number':
    0,
    'test':
    True,
    'configuration_revision':
    13,
    'needs_commissioning':
    True,
    # ALL DATA
    'all_data': (Boolean(True), VisibleString('Content'), DoublePrecision(1.2),
                 SinglePrecision(3.4), Signed(-5), Unsigned(6),
                 Timestamp(705762855.123456789,
                           Quality(False, False, True, 13)))
}

publisher = Publisher(**data)

goose = bytes(publisher)
nic.send(goose)

for index, goose in enumerate(publisher):
    nic.send(bytes(goose))
    if index == 0xF:
        break

print(f'{(time_ns() - now) / 1000}us')
示例#3
0
 def test_decode_accuracy_unspecified(self):
     assert Quality(time_accuracy=0x1F).time_accuracy == 'Unspecified'
示例#4
0
class TestTimestamp:

    test_data = {
        id: ['min', 'extreme', 'generic'],
        'attr': [(0.0, Quality(raw_value=b'\x00')),
                 (1598487698.4095, Quality(raw_value=b'\xF8')),
                 (1598487698.0, Quality())],
        bytes: [
            b'\x00\x00\x00\x00\x00\x00\x00\x00',
            b'\x5F\x46\xFC\x92\x00\x0F\xFF\xF8',
            b'\x5F\x46\xFC\x92\x00\x00\x00\x20'
        ],
    }

    @mark.parametrize("attr, byte",
                      zip(test_data['attr'], test_data[bytes]),
                      ids=test_data[id])
    def test_encode_attr(self, attr, byte):
        timestamp, quality = attr
        assert Timestamp(timestamp, quality).raw_value == byte

    @mark.parametrize("attr, byte",
                      zip(test_data['attr'], test_data[bytes]),
                      ids=test_data[id])
    def test_decode_timestamp(self, attr, byte):
        assert Timestamp(byte).value == attr[0]

    @mark.parametrize("attr, byte",
                      zip(test_data['attr'], test_data[bytes]),
                      ids=test_data[id])
    def test_decode_leap(self, attr, byte):
        assert Timestamp(byte).leap_seconds_known == attr[1].leap_seconds_known

    @mark.parametrize("attr, byte",
                      zip(test_data['attr'], test_data[bytes]),
                      ids=test_data[id])
    def test_decode_fail(self, attr, byte):
        assert Timestamp(byte).clock_failure == attr[1].clock_failure

    @mark.parametrize("attr, byte",
                      zip(test_data['attr'], test_data[bytes]),
                      ids=test_data[id])
    def test_decode_sync(self, attr, byte):
        assert Timestamp(
            byte).clock_not_synchronized == attr[1].clock_not_synchronized

    @mark.parametrize("attr, byte",
                      zip(test_data['attr'], test_data[bytes]),
                      ids=test_data[id])
    def test_decode_accuracy(self, attr, byte):
        assert Timestamp(byte).time_accuracy == attr[1].time_accuracy

    # === EXCEPTIONS ===
    def test_encode_type(self):
        assert raises(TypeError, Timestamp, 123)

    def test_encode_missing_quality(self):
        assert raises(TypeError, Timestamp, 123.123)

    def test_decode_length(self):
        assert raises(ValueError, Timestamp, b'')
示例#5
0
 def test_decode_accuracy(self, attr, byte):
     assert Quality(raw_value=byte).time_accuracy == attr[3]
示例#6
0
 def test_decode_sync(self, attr, byte):
     assert Quality(raw_value=byte).clock_not_synchronized == attr[2]
示例#7
0
 def test_decode_fail(self, attr, byte):
     assert Quality(raw_value=byte).clock_failure == attr[1]
示例#8
0
 def test_decode_leap(self, attr, byte):
     assert Quality(raw_value=byte).leap_seconds_known == attr[0]
示例#9
0
 def test_encode_attr(self, attr, byte):
     leap_second, clock_fail, clock_not_sync, accuracy = attr
     assert bytes(Quality(leap_second, clock_fail, clock_not_sync,
                          accuracy)) == byte