Skip to content

Commit

Permalink
Merge pull request #39 from WolfgangFahl/master
Browse files Browse the repository at this point in the history
adds to_JSON to telegram_control
  • Loading branch information
ganehag authored Jan 22, 2025
2 parents a7aabaa + 775bcc5 commit d1a7552
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions meterbus/telegram_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,22 @@ def __iter__(self):
yield self.body.bodyHeader.ci_field.parts[0]
yield self.compute_crc()
yield self._header.stopField.parts[0]

def to_JSON(self):
"""Convert telegram data to JSON string"""
data = {
"header": {
"start": self.header.startField.parts[0],
"length": len(self.body.bodyHeader.ci_field.parts) + 2,
"control": self.header.cField.parts[0],
"address": self.header.aField.parts[0],
"crc": self.header.crcField.parts[0],
"stop": self._header.stopField.parts[0]
},
"body": {
"ci_field": self.body.bodyHeader.ci_field.parts[0]
},
"computed_crc": self.compute_crc(),
"crc_valid": self.check_crc()
}
return json.dumps(data)

0 comments on commit d1a7552

Please sign in to comment.