CBielstein / APRSsharp

APRS# - Modern APRS software for the amateur radio community
MIT License
12 stars 5 forks source link

Refactor `Packet` to separate out information field logic #93

Closed CBielstein closed 2 years ago

CBielstein commented 2 years ago

Description

Currently, the Packet class is a poor abstraction. It holds all possible parameters for each implemented different type of APRS packet. This approach of a single class for all packets leads to bloated code (the file is currently over 400 lines), difficulty of displaying relevant fields (all fields are nullable and leaves the UI to find what isn't null), and difficulty of plugging in new packet decode types (long switch statements, difficult test cases, etc.)

This PR breaks the Packet abstraction up by introducing a separate family of classes to represent the APRS info field. The Packet class is now meant to hold information all packets will provide in the network layer (i.e., TNC2 or AX.25) (path, sender, received time, etc.) plus an information field, which holds relevant information in encoded in the packet.

The InfoField class is abstract and extended by classes representing each group of APRS packets, grouped by logical similarity of use, encoding, and data. The InfoField classes take either the encoded string to decode or the specific arguments to encode, which makes encoding new packets much easier.

The result is classes that are well-normalized and no files over 175 lines. Packet.cs is now at only 41 lines, which is under 10% of its original length.

This is a large PR, but remember that nearly 90% of line changes have the same logic moved to new files being validated by the same test.

Resolves #77

Changes

Validation

image

CBielstein commented 2 years ago

Updated the output for easier debugging. Here's a screenshot of the new output.

image

CBielstein commented 2 years ago

Looks like this handles a start on #80 as well by adding in some basic per-type packet printout.