A device connected via the USART-USB adapter sends data to the computer, the program on the computer receives the data packet (using the JSSC library) as an array of bytes. The array bytes are predefined parameters, such as Device Status, Serial Number, etc. accordingly, we need some kind of constant structure that implements the correspondence table - which byte is which parameter it is. Plus, we need some kind of constant structure to interpret the value of a parameter to a form suitable for output in the GUI, such as "FF" -> "IDLE", "FE" -> "SLEEP", etc. Moreover, there are dozens of such states and dozens of parameters. Now I started doing this:
public class Packet { public static String Partnum; public static String Version; public static String State; public static String LQI; public static String RSSI; public static String Freqest; public static String RXfifo; public static String VCO_VC_DAC; public static String WOR; public static void packetHandler(String[] arg) { Partnum = "0x"+arg[0]; Version = "0x"+arg[1]; // State if (arg[2].equals("0D")) { State = "RX"; } else if (arg[2].equals("01")) { State = "IDLE"; } else if (arg[2].equals("11")) { State = "RXFIFO_OVERFLOW"; } else { State = arg[2]; } LQI = arg[3]; Freqest = arg[4]; RSSI = arg[5]; RXfifo = arg[6]; VCO_VC_DAC = arg[7]; WOR = arg[8]+" "+arg[9]; } } It works, but I feel that this is not right and is not suitable for processing large packets. And the time for processing, even with a quantity of several parameters, is simply enormous. How to correctly parse and interpret the contents of a package with Java tools? Maybe there are some examples? what I found is interesting https://github.com/farrellf/TelemetryViewer/tree/master/Telemetry%20Viewer , but the package contains simply values for the output and as such does not require processing or interpretation.