/* 
 * File:   DataPacker.h
 *
 * DataPacker has a single static public method packData(..) that returns the
 * packed data message that is sent to the ATMS Server in the fep_reply struct
 * via RPC.
 * 
 * @author John A. Torres
 * @version 9/8/2017
 */

#ifndef DATAPACKER_H
#define	DATAPACKER_H

// Include dependencies
#include "network.h"
#include <iostream>
#include <string.h>
#include <stdio.h>

class DataPacker {
    
public:
    /**
     * Returns packed data message to be sent to ATMS Server in fep_reply via RPC
     * 
     * @param station The station for which the message is to be made
     * @return The packed data message
     */
    static unsigned char * packData(STATION *station);

private:
    // static message var
    static unsigned char *msg;
    /**
     * Packs the static meta data into the msg
     * 
     * @param station station being packed
     * @return the msg
     */
    unsigned char * staticDataPack(STATION *station);
    /**
     * Packs the dynamic (occ/vol) data into the message
     * 
     * @param station the station being packed
     * @param packNo number that specifies which lane types to compare
     * @param pos position in the message (byte number)
     * @return position (int)
     */
    int dynamicDataPack(STATION *station, int packNo, int pos);
    /**
     * Returns the sum of values from byte 1 (after 0x0D0A) to the second to last byte
     * 
     * @param dataptr msg data pointer
     * @param len length of message
     * @return checksum value
     */
    char chksum(unsigned char *dataptr, int len);
    /**
     * Checks if there is data available at the specified lane
     * @param flag
     * @param num
     * @return bool (is data available)
     */
    bool DataAvail(char flag, int num);
    /**
     * Convert volume and occupancy data to a two-byte data packet
     * @param vol
     * @param occ
     * @return the volume occupancy two byte data packet struct
     */
    VOLOCC packVOLOCC(int vol, int occ);

};

#endif	/* DATAPACKER_H */

