#ifndef MODULE_LCM_CTRL_H_
#define MODULE_LCM_CTRL_H_
#include 	<sys/time.h>
#include 	<sys/timeb.h>
#include    <sys/types.h>
#include    <sys/stat.h>
#include 	<sys/types.h>
#include 	<sys/ioctl.h>
#include 	<sys/socket.h>
#include 	<sys/ipc.h>
#include 	<sys/shm.h>
#include 	<sys/mman.h>
#include 	<linux/wireless.h>
#include 	<arpa/inet.h>
#include 	<netinet/in.h>

#include 	<unistd.h>
#include 	<stdarg.h>
#include    <stdio.h>      /*標準輸入輸出定義*/
#include    <stdlib.h>     /*標準函數庫定義*/
#include    <unistd.h>     /*Unix 標準函數定義*/
#include    <fcntl.h>      /*檔控制定義*/
#include    <termios.h>    /*PPSIX 終端控制定義*/
#include    <errno.h>      /*錯誤號定義*/
#include 	<string.h>
#include	<time.h>
#include	<ctype.h>
#include 	<ifaddrs.h>
#include 	<stdbool.h>
#include 	<dirent.h>
#include    "../Define/define.h"
#include    "../Config.h"
//------------------------------------------------------------------------------
#define DEFAULT_AC_INDEX                        (2)

#define TIME_MAX_SEC                            (2592000) // 一個月,秒數
#define POWER_MAX_KW                            (5000)
#define ENERGY_MAX_KWH                          (5000)

#define CMD_TITLE_1                             (0x5A)
#define CMD_TITLE_2                             (0xA5)
#define CMD_READ                                (0x80)
#define CMD_WRITE                               (0x81)
#define CMD_MULTI_WRITE                         (0x82)
#define CMD_MULTI_READ                          (0x83)

#define CMD_BACKLIGHT                           (0x01)
#define CMD_REGISTER                            (0x03)
//------------------------------------------------------------------------------
enum _BATTERY_LEVEL_FOR_MAP {
    _BATTERY_LEVEL_FOR_MAP_EMP = 0x00,
    _BATTERY_LEVEL_FOR_MAP_LV1 = 0x01,
    _BATTERY_LEVEL_FOR_MAP_LV2 = 0x02,
    _BATTERY_LEVEL_FOR_MAP_LV3 = 0x03,
    _BATTERY_LEVEL_FOR_MAP_LV4 = 0x04,
    _BATTERY_LEVEL_FOR_MAP_LV5 = 0x05,
};


//#define NOODOE_QR_CODE_URL                    "https://ev-alpha-test.noodoe.com/station?id=" ////For Audi
#define NOODOE_QR_CODE_URL                      "https://ev.noodoe.com/station?id=" ////For Audi
#define CTEP_VERSION 002
bool needReloadQr = true;
bool _saftydetect = false;
bool _isShow = false; //DS60-120 add
uint8_t _showInformIndex = 0; //DS60-120 add

int _port;
//char* pPortName         = "/dev/ttyO2";
char* pPortName = "/dev/ttyS3";
char* moduleName = "DMT80480T070_09WT";
uint8_t _totalCount;
uint8_t acgunCount;
//struct ChargingInfoData *_chargingInfoData[CHAdeMO_QUANTITY + CCS_QUANTITY + GB_QUANTITY];
//struct ChargingInfoData *ac_chargingInfo[AC_QUANTITY];

uint8_t ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
uint8_t isDiffStatus = false;
uint8_t isChangeBattMap = false;
// 當前選擇的槍號
#if defined DD360Audi
short _currentPage = _LCM_SELECT_GUN;
short _oldPage = _LCM_SELECT_GUN;
#else
short _currentPage = _LCM_NONE;
short _oldPage = _LCM_NONE;
#endif //defined DD360Audi
uint8_t _gunIndex = 0;
bool _wifi_conn_status = false;
bool _battery_display_ani = false;
uint8_t _curPage_index = 0;
bool _page_reload = false;

// LCM - HW
uint8_t _everyPageRollChange = 0;
short __logo = 0x0000;
short __conn_status = 0x0030;
short __ethernet_status = 0x0032;
short __3G4G_status = 0x0036;
short __3G4G_status1 = 0x0037;
short __3G4G_move_status = 0x0038;
short __wifi_status = 0x003C;

short __sel_gun_btn = 0x0040;
short __ret_home_btn = 0x0042;
short __stop_method_btn = 0x0044;
short __lcm_version = 0x004A;
short __qr_code = 0x0250;
short __main_rfid = 0x0052;
short __main_qr = 0x0054;
short __main_app = 0x0056;

short __plug_in_arrow = 0x0060;

short __conn_line = 0x0066;

short __gun_type_index = 0x0070;
short __cmp_gun_type_index = 0x0080; ////For Audi
short __batt_map_empty = 0x0090; ////For Audi
short __qr_code_pre = 0x0280;

short __side_top = 0x0090;
short __side_down = 0x0092;
short __side_mid = 0x0094;

short __conn_line_chag = 0x0096;
short __batt_map = 0x0100;
short __soc_value_charging = 0x0102;
short __remain_time_map = 0x0106;
short __power_map = 0x0108;
short __energy_map = 0x010A;
short __remain_time_tx = 0x0110;

short __trp_remain_time_map = 0x0116;
short __trp_power_map = 0x0118;
short __trp_energy_map = 0x011A;

short __output_eng_tx = 0x0120;
short __total_out_eng_tx = 0x0130;
short __conn_line_comp = 0x0140;
short __charging_fee_map = 0x0146;
short __charging_fee_tx = 0x0150;

short __money_by_rate = 0x0200;
short __money_rate = 0x0220;
short __money_rate_map = 0x0230;

//DS60-120 add
short __csu_ver_string = 0x0300;
short __csu_ver_value = 0x0310;
short __fan_speed_string = 0x0390;
short __fan_speed_value = 0x0400;

short __dc1_ver_string = 0x0320;
short __dc1_ver_value = 0x0330;
short __dc2_ver_string = 0x0340;
short __dc2_ver_value = 0x0350;
short __eth0_ip_string = 0x0360;
short __eth0_ip_value = 0x0370;
short __sn_string = 0x0410;
short __sn_value = 0x0420;

//For Audi, for select gun
short __left_gun_map = 0x0260;
short __right_gun_map = 0x0262;
short __add_chk_btn = 0x0264;
//short __station_id            = 0x0270;
short __balance = 0x0270;
short __remain_balance = 0x0280;
short __custStationIdL1 = 0x0450;
//short __custStationIdL2       = 0x0470;
short _emergency_map = 0x011C;
short __logo_cmp = 0x014A;

// CTEP
short __remain_time = 0x0110;
short __present_power = 0x0120;
short __present_energy = 0x0130;
short __date_map = 0x0470;
short __time_map = 0x0480;
short __time_am_pm = 0x0489;
short __Prepare_EnergyCost = 0x0500;
short __Prepare_ParkingFee = 0x0510;
short __Charge_EnergyCost = 0x0610;
short __Charge_ParkingFee = 0x0620;
short __Charge_TotalCost = 0x0630;
short __Complete_EnergyCost = 0x0640;
short __Complete_ParkingFee = 0x0650;
short __Complete_TotalCost = 0x0660;
short __Receipt_value = 0x0670;
short __Animation_Price = 0x6010;
short __receipt_backgroud = 0x0700;
// ICON ID
uint8_t _disappear = 0;
uint8_t _disconnect = 1;
uint8_t _connect = 2;
uint8_t _warning = 3;
uint8_t _arrow_dark = 4;
uint8_t _arrow_light = 5;
uint8_t _3G4G_disconnect = 6;
uint8_t __3G4G_connect = 7;
uint8_t _wifi_disconnect = 8;
uint8_t _wifi_connect = 9;
uint8_t _logo = 10;
uint8_t _conn_map1 = 11;
uint8_t _conn_map2 = 12;
uint8_t _sel_gun_btn = 13;
uint8_t _back_home_btn = 14;
uint8_t _stop_charging_btn = 15;
uint8_t _stop_charging_btn_scan = 16;
uint8_t _chademo_dark = 17;
uint8_t _ccs_dark = 18;
uint8_t _gbt_dark = 19;
uint8_t _actype_dark = 20;
uint8_t _chademo_light = 21;
uint8_t _ccs_light = 22;
uint8_t _gbt_light = 23;
uint8_t _actype_light = 24;
uint8_t _main_none_rfid = 25;
uint8_t _main_rfid = 26;
uint8_t _main_none_app = 27;
uint8_t _main_app = 28;
uint8_t _main_none_qr = 29;
uint8_t _main_qr = 30;
uint8_t _charging_map1 = 31;
uint8_t _charging_map2 = 32;
uint8_t _battery_empty = 33;
uint8_t _battery_cap_20 = 34;
uint8_t _battery_cap_40 = 35;
uint8_t _battery_cap_60 = 36;
uint8_t _battery_cap_80 = 37;
uint8_t _battery_cap_100 = 38;
uint8_t _battery_map = 39;
uint8_t _power_map = 40;
uint8_t _time_map = 41;
uint8_t _complete_map = 42;
uint8_t _battery_soc_20 = 43;
uint8_t _battery_soc_40 = 44;
uint8_t _battery_soc_60 = 45;
uint8_t _battery_soc_80 = 46;
uint8_t _battery_soc_100 = 47;
uint8_t _battery_eng_map = 48;
uint8_t _money_map = 49;
uint8_t _elapse_time_map = 50;
uint8_t _charging_money = 51;
//uint8_t _side_none_rfid       = 52;
//uint8_t _side_rfid            = 53;
//uint8_t _side_none_app        = 54;
//uint8_t _side_app             = 55;
//uint8_t _side_none_qr         = 56;
//uint8_t _side_qr              = 57;
uint8_t _eth_disconnect = 52; //58;
uint8_t _eth_connect = 53; //59;

uint8_t _chademo_dark_cmp = 54;
uint8_t _ccs_dark_cmp = 55;
uint8_t _gbt_dark_cmp = 56;
uint8_t _actype_dark_cmp = 57;
uint8_t _chademo_light_cmp = 58;
uint8_t _ccs_light_cmp = 59;
uint8_t _gbt_light_cmp = 60;
uint8_t _actype_light_cmp = 61;

uint8_t _logo_cmp = 62;
uint8_t _battery_eng_trp_map = 63;
uint8_t _money_trp_map = 64;
uint8_t _elapse_time_trp_map = 65;
#if defined DD360Audi
////For Audi
uint8_t _left_gun_disable_map = 66;
uint8_t _left_gun_enable_map = 67;
uint8_t _right_gun_disable_map = 68;
uint8_t _right_gun_enable_map = 69;
uint8_t _select_gun_btn = 70;
uint8_t _emergency_disable_map = 72;
// For replug
struct timespec showReplugStrTimer;
struct timespec showFullTargetTimer;
short __show_StatusString_value_1 = 0x0460;
short __show_StatusString_value_2 = 0x0462;
uint8_t _showfulltarget_1 = 73;
uint8_t _showfulltarget_2 = 74;
uint8_t _showReplugStr_1 = 75;
uint8_t _showReplugStr_2 = 76;
// Select Gun for Audi
short __show_selectgun_value = 0x0464;
uint8_t _showselectgun_left = 77;
uint8_t _showselectgun_right = 78;
// Wait for gun plugin Audi
short __show_waitgunplug_value = 0x0468;
uint8_t _showwaitgunplug_left = 80;
uint8_t _showwaitgunplug_right = 81;
#else
short __show_handshark_value = 0x0464;
short __show_GFD_value = 0x0466;
short __show_precharge_value = 0x0468;
uint8_t _receipt_bk = 67;

uint8_t _show_handshark_dark = 67;
uint8_t _show_handshark_light = 68;
uint8_t _show_GFD_dark = 69;
uint8_t _show_GFD_light = 70;
uint8_t _show_precharge_dark = 71;
uint8_t _show_precharge_light = 72;
#endif


#endif //MODULE_LCM_CTRL_H_