#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/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>      /*�зǿ�J��X�w�q*/
#include    <stdlib.h>     /*�зǨ�Ʈw�w�q*/
#include    <unistd.h>     /*Unix �зǨ�Ʃw�q*/
#include    <fcntl.h>      /*�ɱ���w�q*/
#include    <termios.h>    /*PPSIX �׺ݱ���w�q*/
#include    <errno.h>      /*���~���w�q*/
#include 	<errno.h>
#include 	<string.h>
#include	<time.h>
#include	<ctype.h>
#include 	<ifaddrs.h>
#include 	<stdbool.h>
#include	"../../define.h"

#define ARRAY_SIZE(A)		(sizeof(A) / sizeof(A[0]))
#define PASS				1
#define FAIL				-1
#define YES					1
#define NO					0

typedef unsigned char 			byte;

struct SysConfigAndInfo			*ShmSysConfigAndInfo;
struct StatusCodeData 			*ShmStatusCodeData;
struct FanModuleData			*ShmFanModuleData;

#define NO_DEFINE			255
#define DEFAULT_AC_INDEX	2

#define TIME_MAX_SEC		2592000 // �@�Ӥ�A����
#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,
};

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

byte ac_ani_battery_level = _BATTERY_LEVEL_FOR_MAP_LV5;
byte isDiffStatus = false;
byte isChangeBattMap = false;
// ���e��ܪ��j��
short _currentPage = _LCM_NONE;
short _oldPage = _LCM_NONE;
byte _gunIndex = 0;
bool _wifi_conn_status = false;
bool _battery_display_ani = false;
byte _curPage_index = 0;
bool _page_reload = false;

// LCM - HW
byte _everyPageRollChange = 0;
short __conn_status = 0x0030;
short __ethernet_status = 0x0032;
short __3G4G_status = 0x0036;
short __wifi_status = 0x003C;

short __sel_gun_btn = 0x0040;
short __ret_home_btn = 0x0042;
short __stop_method_btn = 0x0044;

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 __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 __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;

// ICON ID
byte _disappear = 0;
byte _disconnect = 1;
byte _connect = 2;
byte _warning = 3;
byte _arrow_dark = 4;
byte _arrow_light = 5;
byte _3G4G_disconnect = 6;
byte __3G4G_connect = 7;
byte _wifi_disconnect = 8;
byte _wifi_connect = 9;
byte _logo = 10;
byte _conn_map1 = 11;
byte _conn_map2 = 12;
byte _sel_gun_btn = 13;
byte _back_home_btn = 14;
byte _stop_charging_btn = 15;
byte _stop_charging_btn_scan = 16;
byte _chademo_dark = 17;
byte _ccs_dark = 18;
byte _gbt_dark = 19;
byte _actype_dark = 20;
byte _chademo_light = 21;
byte _ccs_light = 22;
byte _gbt_light = 23;
byte _actype_light = 24;
byte _main_none_rfid = 25;
byte _main_rfid = 26;
byte _main_none_app = 27;
byte _main_app = 28;
byte _main_none_qr = 29;
byte _main_qr = 30;
byte _charging_map1 = 31;
byte _charging_map2 = 32;
byte _battery_empty = 33;
byte _battery_cap_20 = 34;
byte _battery_cap_40 = 35;
byte _battery_cap_60 = 36;
byte _battery_cap_80 = 37;
byte _battery_cap_100 = 38;
byte _battery_map = 39;
byte _power_map = 40;
byte _time_map = 41;
byte _complete_map = 42;
byte _battery_soc_20 = 43;
byte _battery_soc_40 = 44;
byte _battery_soc_60 = 45;
byte _battery_soc_80 = 46;
byte _battery_soc_100 = 47;
byte _battery_eng_map = 48;
byte _money_map = 49;
byte _elapse_time_map = 50;
byte _charging_money = 51;
byte _side_none_rfid = 52;
byte _side_rfid = 53;
byte _side_none_app = 54;
byte _side_app = 55;
byte _side_none_qr = 56;
byte _side_qr = 57;
byte _eth_disconnect = 58;
byte _eth_connect = 59;