@@ -613,6 +613,20 @@ def pgn(self):
613
613
_pgn += ps
614
614
return _pgn
615
615
616
+ @pgn .setter
617
+ def pgn (self , value ): # type: (int) -> None
618
+ self .extended = True
619
+ ps = value & 0xff
620
+ pf = (value >> 8 ) & 0xFF
621
+ _pgn = pf << 8
622
+ if pf >= 240 :
623
+ _pgn += ps
624
+
625
+ self .id &= 0xff0000ff
626
+ self .id |= (_pgn & 0xffff ) << 8 # default pgn is None -> mypy reports error
627
+
628
+
629
+
616
630
@property
617
631
def j1939_tuple (self ): # type: () -> typing.Tuple[int, int, int]
618
632
"""Get tuple (destination, PGN, source)
@@ -637,6 +651,11 @@ def j1939_source(self):
637
651
raise J1939needsExtendedIdetifier
638
652
return self .id & 0xFF
639
653
654
+ @j1939_source .setter
655
+ def j1939_source (self , value ): # type: (int) -> None
656
+ self .extended = True
657
+ self .id = (self .id & 0xffffff00 ) | (value & 0xff )
658
+
640
659
@property
641
660
def j1939_ps (self ):
642
661
if not self .extended :
@@ -659,7 +678,12 @@ def j1939_edp(self):
659
678
def j1939_priority (self ):
660
679
if not self .extended :
661
680
raise J1939needsExtendedIdetifier
662
- return (self .id >> 25 ) & 0x7
681
+ return (self .id >> 26 ) & 0x7
682
+
683
+ @j1939_priority .setter
684
+ def j1939_priority (self , value ): # type: (int) -> None
685
+ self .extended = True
686
+ self .id = (self .id & 0x2ffffff ) | ((value & 0x7 ) << 26 )
663
687
664
688
@property
665
689
def j1939_str (self ): # type: () -> str
@@ -733,9 +757,6 @@ class Frame(object):
733
757
receivers = attr .ib (factory = list ) # type: typing.MutableSequence[str]
734
758
signalGroups = attr .ib (factory = list ) # type: typing.MutableSequence[SignalGroup]
735
759
736
- j1939_pgn = attr .ib (default = 0 ) # type: typing.Optional[int]
737
- j1939_source = attr .ib (default = 0 ) # type: int
738
- j1939_prio = attr .ib (default = 0 ) # type: int
739
760
is_j1939 = attr .ib (default = False ) # type: bool
740
761
# ('cycleTime', '_cycleTime', int, None),
741
762
# ('sendType', '_sendType', str, None),
@@ -787,39 +808,28 @@ def pgn(self): # type: () -> int
787
808
788
809
@pgn .setter
789
810
def pgn (self , value ): # type: (int) -> None
790
- self .j1939_pgn = value
791
- self .recalc_J1939_id ()
792
- self .j1939_pgn = self .arbitration_id .pgn
811
+ self .arbitration_id .pgn = value
793
812
794
813
@property
795
814
def priority (self ): # type: () -> int
796
815
"""Get J1939 priority."""
797
- return self .j1939_prio
816
+ return self .arbitration_id . j1939_prio
798
817
799
818
@priority .setter
800
819
def priority (self , value ): # type: (int) -> None
801
820
"""Set J1939 priority."""
802
- self .j1939_prio = value
803
- self .recalc_J1939_id ()
821
+ self .arbitration_id .j1939_priority = value
804
822
805
823
@property
806
824
def source (self ): # type: () -> int
807
825
"""Get J1939 source."""
808
- return self .j1939_source
826
+ return self . arbitration_id .j1939_source
809
827
810
828
@source .setter
811
829
def source (self , value ): # type: (int) -> None
812
830
"""Set J1939 source."""
813
- self .j1939_source = value
814
- self .recalc_J1939_id ()
815
-
816
- def recalc_J1939_id (self ): # type: () -> None
817
- """Recompute J1939 ID"""
818
- self .arbitration_id .id = self .j1939_source & 0xff
819
- self .arbitration_id .id += (self .j1939_pgn & 0xffff ) << 8 # default pgn is None -> mypy reports error
820
- self .arbitration_id .id += (self .j1939_prio & 0x7 ) << 26
821
- self .arbitration_id .extended = True
822
- self .is_j1939 = True
831
+ self .arbitration_id .j1939_source = value
832
+
823
833
824
834
# @property
825
835
# def cycleTime(self):
0 commit comments