/* 
 * File:   mega_meg44pan_simulator.h
 * Author: Jan Hudec
 *
 * Created on 16. května 2019, 17:20
 */

#ifndef MEGA_MEG44PAN_SIMULATOR_H
#define MEGA_MEG44PAN_SIMULATOR_H

#include <string>
#include <vector>
#include <map>

#include <sv_publisher.h>
#include <goose_publisher.h>
#include <hal_time.h>

class mega_meg44pan_simulator 
{
private:
    // generator
    std::vector<std::map<time_t, float>> _voltages;
    int _sensors;
    float _voltage_center;
    float _voltage_inner_bound;
    float _voltage_outer_bound;
    float _inner_to_outer_ratio;
    int _monitoring_time;
    int _time_factor;
    time_t _t;
    struct tm _ti;
    
    // iec
    SVPublisher _sv_pub;
    GoosePublisher _gp_pub;
    LinkedList _dataset;
    LinkedList _dataset_sp;
    std::string _interface;
    uint8_t _vlan_priority;
    uint16_t _vlan_id;
    uint16_t _sv_app_id;
    uint8_t _sv_mac[2];
    int _sv_ratio;
    uint16_t _goose_app_id;
    uint8_t _goose_mac[2];
    int _goose_time_min;
    int _goose_time_max;
    unsigned long _goose_counter;
    std::map<std::string, SVPublisher_ASDU> _asdu_units;
    std::map<std::string, std::vector<int>> _asdu_units_offsets;
public:
    int time_treshold;
    bool spike;
    
    mega_meg44pan_simulator();
    ~mega_meg44pan_simulator();

    void parse_config(std::string filename);
    void init_iec();
    void save_voltages(std::string filename);
    void generate_voltages();
    void retransmit_goose(int i = 0, float temp = 0, time_t t = 0);
};

#endif /* MEGA_MEG44PAN_SIMULATOR_H */

