/* 
 * File:   ziehl_tr1200ip_simulator.h
 * Author: Jan Hudec
 *
 * Created on 25. dubna 2019, 18:00
 */

#ifndef ZIEHL_TR1200IP_SIMULATOR_H
#define ZIEHL_TR1200IP_SIMULATOR_H

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

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

class ziehl_tr1200ip_simulator
{
private:
    // generator
    std::vector<std::map<time_t, float>> _temperatures;
    std::map<int, float> _static_temp_values;
    float _deadband;
    int _sensors;
    int _temp_min;
    int _temp_max;
    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:
    uint64_t time_treshold;
    uint64_t goose_time_treshold;

    ziehl_tr1200ip_simulator();
    ~ziehl_tr1200ip_simulator();

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

#endif /* ZIEHL_TR1200IP_SIMULATOR_H */