| 1 | /* |
|---|
| 2 | * File: DataPacker.h |
|---|
| 3 | * |
|---|
| 4 | * DataPacker has a single static public method packData(..) that returns the |
|---|
| 5 | * packed data message that is sent to the ATMS Server in the fep_reply struct |
|---|
| 6 | * via RPC. |
|---|
| 7 | * |
|---|
| 8 | * @author John A. Torres |
|---|
| 9 | * @version 9/8/2017 |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | #ifndef DATAPACKER_H |
|---|
| 13 | #define DATAPACKER_H |
|---|
| 14 | |
|---|
| 15 | // Include dependencies |
|---|
| 16 | #include "network.h" |
|---|
| 17 | #include <iostream> |
|---|
| 18 | #include <string.h> |
|---|
| 19 | #include <stdio.h> |
|---|
| 20 | |
|---|
| 21 | class DataPacker { |
|---|
| 22 | |
|---|
| 23 | public: |
|---|
| 24 | /** |
|---|
| 25 | * Returns packed data message to be sent to ATMS Server in fep_reply via RPC |
|---|
| 26 | * |
|---|
| 27 | * @param station The station for which the message is to be made |
|---|
| 28 | * @return The packed data message |
|---|
| 29 | */ |
|---|
| 30 | static unsigned char * packData(STATION *station); |
|---|
| 31 | |
|---|
| 32 | private: |
|---|
| 33 | // static message var |
|---|
| 34 | static unsigned char *msg; |
|---|
| 35 | /** |
|---|
| 36 | * Packs the static meta data into the msg |
|---|
| 37 | * |
|---|
| 38 | * @param station station being packed |
|---|
| 39 | * @return the msg |
|---|
| 40 | */ |
|---|
| 41 | unsigned char * staticDataPack(STATION *station); |
|---|
| 42 | /** |
|---|
| 43 | * Packs the dynamic (occ/vol) data into the message |
|---|
| 44 | * |
|---|
| 45 | * @param station the station being packed |
|---|
| 46 | * @param packNo number that specifies which lane types to compare |
|---|
| 47 | * @param pos position in the message (byte number) |
|---|
| 48 | * @return position (int) |
|---|
| 49 | */ |
|---|
| 50 | int dynamicDataPack(STATION *station, int packNo, int pos); |
|---|
| 51 | /** |
|---|
| 52 | * Returns the sum of values from byte 1 (after 0x0D0A) to the second to last byte |
|---|
| 53 | * |
|---|
| 54 | * @param dataptr msg data pointer |
|---|
| 55 | * @param len length of message |
|---|
| 56 | * @return checksum value |
|---|
| 57 | */ |
|---|
| 58 | char chksum(unsigned char *dataptr, int len); |
|---|
| 59 | /** |
|---|
| 60 | * Checks if there is data available at the specified lane |
|---|
| 61 | * @param flag |
|---|
| 62 | * @param num |
|---|
| 63 | * @return bool (is data available) |
|---|
| 64 | */ |
|---|
| 65 | bool DataAvail(char flag, int num); |
|---|
| 66 | /** |
|---|
| 67 | * Convert volume and occupancy data to a two-byte data packet |
|---|
| 68 | * @param vol |
|---|
| 69 | * @param occ |
|---|
| 70 | * @return the volume occupancy two byte data packet struct |
|---|
| 71 | */ |
|---|
| 72 | VOLOCC packVOLOCC(int vol, int occ); |
|---|
| 73 | |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | #endif /* DATAPACKER_H */ |
|---|
| 77 | |
|---|