diff --git a/src/ir_reverser/.gitignore b/src/ir_reverser/.gitignore index 504ad78..8e2cbde 100644 --- a/src/ir_reverser/.gitignore +++ b/src/ir_reverser/.gitignore @@ -1,18 +1,5 @@ -out/ -libs/ -obj/ -.idea/ -ipch/ -x64/ -cmake-build-debug/ -cmake-build-release/ -Debug/ -Release/ -*.sdf -*.opensdf -.DS_Store -.vs -ir_decoder.vcxproj.user -irda_decoder.exe.stackdump -ir_decoder.VC.db -ir_decoder.VC.VC.opendb \ No newline at end of file +*/bin +*.class +*/.settings +*/.jar +*.bin diff --git a/src/ir_reverser/.idea/compiler.xml b/src/ir_reverser/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/src/ir_reverser/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ir_reverser/.idea/copyright/profiles_settings.xml b/src/ir_reverser/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/src/ir_reverser/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/ir_reverser/.idea/dictionaries/straw.xml b/src/ir_reverser/.idea/dictionaries/straw.xml new file mode 100644 index 0000000..6db066d --- /dev/null +++ b/src/ir_reverser/.idea/dictionaries/straw.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/ir_reverser/.idea/encodings.xml b/src/ir_reverser/.idea/encodings.xml new file mode 100644 index 0000000..d386cc3 --- /dev/null +++ b/src/ir_reverser/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/ir_reverser/.idea/misc.xml b/src/ir_reverser/.idea/misc.xml new file mode 100644 index 0000000..e94a2eb --- /dev/null +++ b/src/ir_reverser/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/ir_reverser/.idea/modules.xml b/src/ir_reverser/.idea/modules.xml new file mode 100644 index 0000000..d1a94ea --- /dev/null +++ b/src/ir_reverser/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/ir_reverser/.idea/sirius_code_robot.iml b/src/ir_reverser/.idea/sirius_code_robot.iml new file mode 100644 index 0000000..aeb6a4e --- /dev/null +++ b/src/ir_reverser/.idea/sirius_code_robot.iml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ir_reverser/.idea/uiDesigner.xml b/src/ir_reverser/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/src/ir_reverser/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ir_reverser/.idea/vcs.xml b/src/ir_reverser/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/src/ir_reverser/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/ir_reverser/.idea/workspace.xml b/src/ir_reverser/.idea/workspace.xml new file mode 100644 index 0000000..909acb3 --- /dev/null +++ b/src/ir_reverser/.idea/workspace.xml @@ -0,0 +1,1124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1468825739065 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + sirius_code_robot + + + + + + + + Android API 22 Platform + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/ir_reverser/CMakeLists.txt b/src/ir_reverser/CMakeLists.txt deleted file mode 100644 index 8e637fb..0000000 --- a/src/ir_reverser/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -cmake_minimum_required(VERSION 3.6) -project(ir_reverser) - -set(CMAKE_C_STANDARD 99) - -set(SOURCE_FILES src/ire_test_main.c - include/ire_tv_protocol_def.h) -add_executable(ir_reverser ${SOURCE_FILES}) \ No newline at end of file diff --git a/src/ir_reverser/classes/META-INF/MANIFEST.MF b/src/ir_reverser/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f763f46 --- /dev/null +++ b/src/ir_reverser/classes/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.yuekong.sirius.ircoderobot.SiriusCodeRobot + diff --git a/src/ir_reverser/include/ire_tv_protocol_def.h b/src/ir_reverser/include/ire_tv_protocol_def.h deleted file mode 100644 index ab05cdf..0000000 --- a/src/ir_reverser/include/ire_tv_protocol_def.h +++ /dev/null @@ -1,29 +0,0 @@ -/************************************************************************************** -Filename: -Revised: Date: 2017-01-09 -Revision: Revision: 1.0 - -Description: This file contains definitions of P-R format protocols - -Revision log: -* 2017-01-09: created by strawmanbobi -**************************************************************************************/ - -#ifndef IR_REVERSER_IRE_TV_PROTOCOL_DEF_H -#define IR_REVERSER_IRE_TV_PROTOCOL_DEF_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -typedef struct -{ - -} protocol; - -#ifdef __cplusplus -} -#endif - -#endif //IR_REVERSER_IRE_TV_PROTOCOL_DEF_H diff --git a/src/ir_reverser/libs/mysql-connector-java-5.0.8-bin.jar b/src/ir_reverser/libs/mysql-connector-java-5.0.8-bin.jar new file mode 100644 index 0000000..0170c3e Binary files /dev/null and b/src/ir_reverser/libs/mysql-connector-java-5.0.8-bin.jar differ diff --git a/src/ir_reverser/src/META-INF/MANIFEST.MF b/src/ir_reverser/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..f763f46 --- /dev/null +++ b/src/ir_reverser/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: com.yuekong.sirius.ircoderobot.SiriusCodeRobot + diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/SiriusCodeRobot.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/SiriusCodeRobot.java new file mode 100644 index 0000000..c015e6b --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/SiriusCodeRobot.java @@ -0,0 +1,91 @@ +/* + * Created by strawmanbobi + * 2016-07-18 + * + * Sirius IRDA code generating robot + */ + +package com.yuekong.sirius.ircoderobot; + +import com.yuekong.sirius.ircoderobot.robot.RemoteEncoder; +import com.yuekong.sirius.ircoderobot.robot.RemoteIndexGenerator; + +public class SiriusCodeRobot { + + private final static int FUNCTION_GENERATE_REMOTE_INDEX = 0; + private final static int FUNCTION_GENERATE_REMOTE_BINARY = 1; + + private static int mFunction = 0; + + public static void main(String[] args) { + try { + mFunction = Integer.parseInt(args[0]); + + switch(mFunction) { + case FUNCTION_GENERATE_REMOTE_INDEX: { + if (7 != args.length) { + System.out.println("invalid parameter"); + System.out.println("Please call this method like SiriusCodeRobot [function_code = 0] " + + "[source_xml_file_base] [ac_bin_file_base] [db_host] [db_name] [db_user] " + + "[db_password]"); + return; + } + String sourceXmlFileBase = args[1]; + String acBinFileBase = args[2]; + String dbHost = args[3]; + String dbName = args[4]; + String dbUser = args[5]; + String dbPassword = args[6]; + + RemoteIndexGenerator keyCodeStatRobot = new RemoteIndexGenerator(sourceXmlFileBase, acBinFileBase, + dbHost, dbName, dbUser, dbPassword); + + keyCodeStatRobot.generateAllRemoteIndexes(); + break; + } + + case FUNCTION_GENERATE_REMOTE_BINARY: { + if (10 != args.length) { + System.out.println("invalid parameter"); + System.out.println("Please call this method like SiriusCodeRobot [function_code = 1] " + + "[source_xml_file_base] [output_xml_file_base] [encoder_python_file] " + + "[encoder_python_base] [output_bin_file_base] [db_host] [db_name] [db_user] " + + "[db_password]"); + return; + } + String sourceXmlFileBase = args[1]; + String outputXmlFileBase = args[2]; + String encoderPythonFile = args[3]; + String encoderPythonBase = args[4]; + String outputBinFileBase = args[5]; + String dbHost = args[6]; + String dbName = args[7]; + String dbUser = args[8]; + String dbPassword = args[9]; + + RemoteEncoder remoteEncoder = new RemoteEncoder(sourceXmlFileBase, + outputXmlFileBase, + encoderPythonFile, + encoderPythonBase, + outputBinFileBase, + dbHost, + dbName, + dbUser, + dbPassword); + + remoteEncoder.encodeAllCommandRemote(); + break; + } + + default: { + break; + } + + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + + } + } +} \ No newline at end of file diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/Brand.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/Brand.java new file mode 100644 index 0000000..d47be6d --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/Brand.java @@ -0,0 +1,122 @@ +/** + * Created by strawmanbobi + * 2016-07-18 + */ + +package com.yuekong.sirius.ircoderobot.model; + +public class Brand { + + private int mBrandID; + private int mKookongBrandID; + private int mCategoryID; + private int mKookongCategoryID; + private int mPriority; + private String mBrandName; + private String mBrandNameEn; + private String mBrandNameTw; + private String mProtector; + + public Brand(int mBrandID, int mKookongBrandID, int mCategoryID, String mProtector, String mBrandNameTw, + String mBrandNameEn, String mBrandName, int mPriority, int mKookongCategoryID) { + this.mBrandID = mBrandID; + this.mKookongBrandID = mKookongBrandID; + this.mCategoryID = mCategoryID; + this.mProtector = mProtector; + this.mBrandNameTw = mBrandNameTw; + this.mBrandNameEn = mBrandNameEn; + this.mBrandName = mBrandName; + this.mPriority = mPriority; + this.mKookongCategoryID = mKookongCategoryID; + } + + public Brand() { + + } + + public String toString() { + return "Brand{" + + "mBrandID=" + mBrandID + + ", mKookongBrandID=" + mKookongBrandID + + ", mCategoryID=" + mCategoryID + + ", mKookongCategoryID=" + mKookongCategoryID + + ", mPriority=" + mPriority + + ", mBrandName='" + mBrandName + '\'' + + ", mBrandNameEn='" + mBrandNameEn + '\'' + + ", mBrandNameTw='" + mBrandNameTw + '\'' + + ", mProtector='" + mProtector + '\'' + + '}'; + } + + public int getmBrandID() { + return mBrandID; + } + + public void setmBrandID(int mBrandID) { + this.mBrandID = mBrandID; + } + + public int getmKookongBrandID() { + return mKookongBrandID; + } + + public void setmKookongBrandID(int mKookongBrandID) { + this.mKookongBrandID = mKookongBrandID; + } + + public int getmCategoryID() { + return mCategoryID; + } + + public void setmCategoryID(int mCategoryID) { + this.mCategoryID = mCategoryID; + } + + public int getmKookongCategoryID() { + return mKookongCategoryID; + } + + public void setmKookongCategoryID(int mKookongCategoryID) { + this.mKookongCategoryID = mKookongCategoryID; + } + + public int getmPriority() { + return mPriority; + } + + public void setmPriority(int mPriority) { + this.mPriority = mPriority; + } + + public String getmBrandName() { + return mBrandName; + } + + public void setmBrandName(String mBrandName) { + this.mBrandName = mBrandName; + } + + public String getmBrandNameEn() { + return mBrandNameEn; + } + + public void setmBrandNameEn(String mBrandNameEn) { + this.mBrandNameEn = mBrandNameEn; + } + + public String getmBrandNameTw() { + return mBrandNameTw; + } + + public void setmBrandNameTw(String mBrandNameTw) { + this.mBrandNameTw = mBrandNameTw; + } + + public String getmProtector() { + return mProtector; + } + + public void setmProtector(String mProtector) { + this.mProtector = mProtector; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/BrandCategoryRel.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/BrandCategoryRel.java new file mode 100644 index 0000000..b4f12a7 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/BrandCategoryRel.java @@ -0,0 +1,44 @@ +/** + * Created by strawmanbobi + * 2016-07-18 + */ + +package com.yuekong.sirius.ircoderobot.model; + +public class BrandCategoryRel { + + private int mKookongBrandID; + private int mKookongCategoryID; + + public BrandCategoryRel(int mKookongBrandID, int mKookongCategoryID) { + this.mKookongBrandID = mKookongBrandID; + this.mKookongCategoryID = mKookongCategoryID; + } + + public BrandCategoryRel() { + + } + + public String toString() { + return "BrandCategoryRel{" + + "mKookongBrandID=" + mKookongBrandID + + ", mKookongCategoryID=" + mKookongCategoryID + + '}'; + } + + public int getmKookongBrandID() { + return mKookongBrandID; + } + + public void setmKookongBrandID(int mKookongBrandID) { + this.mKookongBrandID = mKookongBrandID; + } + + public int getmKookongCategoryID() { + return mKookongCategoryID; + } + + public void setmKookongCategoryID(int mKookongCategoryID) { + this.mKookongCategoryID = mKookongCategoryID; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/BrandRemoteRel.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/BrandRemoteRel.java new file mode 100644 index 0000000..1e714ab --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/BrandRemoteRel.java @@ -0,0 +1,133 @@ +/** + * Created by Strawmanbobi + * 2015-07-18 + */ + +package com.yuekong.sirius.ircoderobot.model; + +public class BrandRemoteRel { + + private int mKookongCategoryID; + private int mKookongBrandID; + private int mKookongRemoteID; + private int mCategoryID; + private int mBrandID; + private int mRemoteID; + private int mPriority; + private String mCategoryName; + private String mBrandName; + private String mRemoteName; + + public BrandRemoteRel(int mKookongCategoryID, int mKookongBrandID, int mKookongRemoteID, int mCategoryID, int mBrandID, int mRemoteID, int mPriority, String mCategoryName, String mBrandName, String mRemoteName) { + this.mKookongCategoryID = mKookongCategoryID; + this.mKookongBrandID = mKookongBrandID; + this.mKookongRemoteID = mKookongRemoteID; + this.mCategoryID = mCategoryID; + this.mBrandID = mBrandID; + this.mRemoteID = mRemoteID; + this.mPriority = mPriority; + this.mCategoryName = mCategoryName; + this.mBrandName = mBrandName; + this.mRemoteName = mRemoteName; + } + + public BrandRemoteRel() { + + } + + @Override + public String toString() { + return "BrandRemoteRel{" + + "mKookongCategoryID=" + mKookongCategoryID + + ", mKookongBrandID=" + mKookongBrandID + + ", mKookongRemoteID=" + mKookongRemoteID + + ", mCategoryID=" + mCategoryID + + ", mBrandID=" + mBrandID + + ", mRemoteID=" + mRemoteID + + ", mPriority=" + mPriority + + ", mCategoryName='" + mCategoryName + '\'' + + ", mBrandName='" + mBrandName + '\'' + + ", mRemoteName='" + mRemoteName + '\'' + + '}'; + } + + public int getmKookongCategoryID() { + return mKookongCategoryID; + } + + public void setmKookongCategoryID(int mKookongCategoryID) { + this.mKookongCategoryID = mKookongCategoryID; + } + + public int getmKookongBrandID() { + return mKookongBrandID; + } + + public void setmKookongBrandID(int mKookongBrandID) { + this.mKookongBrandID = mKookongBrandID; + } + + public int getmKookongRemoteID() { + return mKookongRemoteID; + } + + public void setmKookongRemoteID(int mKookongRemoteID) { + this.mKookongRemoteID = mKookongRemoteID; + } + + public int getmPriority() { + return mPriority; + } + + public void setmPriority(int mPriority) { + this.mPriority = mPriority; + } + + public int getmCategoryID() { + return mCategoryID; + } + + public void setmCategoryID(int mCategoryID) { + this.mCategoryID = mCategoryID; + } + + public int getmBrandID() { + return mBrandID; + } + + public void setmBrandID(int mBrandID) { + this.mBrandID = mBrandID; + } + + public String getmCategoryName() { + return mCategoryName; + } + + public void setmCategoryName(String mCategoryName) { + this.mCategoryName = mCategoryName; + } + + public String getmBrandName() { + return mBrandName; + } + + public void setmBrandName(String mBrandName) { + this.mBrandName = mBrandName; + } + + public int getmRemoteID() { + return mRemoteID; + } + + public void setmRemoteID(int mRemoteID) { + this.mRemoteID = mRemoteID; + } + + public String getmRemoteName() { + return mRemoteName; + } + + public void setmRemoteName(String mRemoteName) { + this.mRemoteName = mRemoteName; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/Category.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/Category.java new file mode 100644 index 0000000..6cc6248 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/Category.java @@ -0,0 +1,77 @@ +/** + * Created by strawmanbobi + * 2015-07-18 + */ + +package com.yuekong.sirius.ircoderobot.model; + +public class Category { + + private int mCategoryID; + private int mKookongCategoryID; + private String mCategoryName; + private String mCategoryNameEn; + private String mCategoryNameTw; + + public Category(int mKookongCategoryID, String mCategoryName, String mCategoryNameEn, + String mCategoryNameTw) { + this.mKookongCategoryID = mKookongCategoryID; + this.mCategoryName = mCategoryName; + this.mCategoryNameEn = mCategoryNameEn; + this.mCategoryNameTw = mCategoryNameTw; + } + + public Category() { + + } + + public String toString() { + return "Category{" + + "mCategoryID=" + mCategoryID + + ", mKookongCategoryID=" + mKookongCategoryID + + ", mCategoryName='" + mCategoryName + '\'' + + ", mCategoryNameEn='" + mCategoryNameEn + '\'' + + ", mCategoryNameTw='" + mCategoryNameTw + '\'' + + '}'; + } + + public int getmCategoryID() { + return mCategoryID; + } + + public void setmCategoryID(int mCategoryID) { + this.mCategoryID = mCategoryID; + } + + public int getmKookongCategoryID() { + return mKookongCategoryID; + } + + public void setmKookongCategoryID(int mKookongCategoryID) { + this.mKookongCategoryID = mKookongCategoryID; + } + + public String getmCategoryName() { + return mCategoryName; + } + + public void setmCategoryName(String mCategoryName) { + this.mCategoryName = mCategoryName; + } + + public String getmCategoryNameEn() { + return mCategoryNameEn; + } + + public void setmCategoryNameEn(String mCategoryNameEn) { + this.mCategoryNameEn = mCategoryNameEn; + } + + public String getmCategoryNameTw() { + return mCategoryNameTw; + } + + public void setmCategoryNameTw(String mCategoryNameTw) { + this.mCategoryNameTw = mCategoryNameTw; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/City.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/City.java new file mode 100644 index 0000000..42f4d7c --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/City.java @@ -0,0 +1,100 @@ +/** + * Created by strawmanbobi + * 2016-07-18 + */ + +package com.yuekong.sirius.ircoderobot.model; + +public class City { + + private int mCityID; + private String mCityCode; + private String mCityName; + private String mCityNameTw; + private String mCityNameEn; + private double mLongitude; + private double mLatitude; + + public City(int mCityID, String mCityCode, String mCityName, String mCityNameTw, String mCityNameEn, + double mLongitude, double mLatitude) { + this.mCityID = mCityID; + this.mCityCode = mCityCode; + this.mCityName = mCityName; + this.mCityNameTw = mCityNameTw; + this.mCityNameEn = mCityNameEn; + this.mLongitude = mLongitude; + this.mLatitude = mLatitude; + } + + public City() { + + } + + public String toString() { + return "City{" + + "mCityID=" + mCityID + + ", mCityCode=" + mCityCode + + ", mCityName='" + mCityName + '\'' + + ", mCityNameTw='" + mCityNameTw + '\'' + + ", mCityNameEn='" + mCityNameEn + '\'' + + ", mLongitude=" + mLongitude + + ", mLatitude=" + mLatitude + + '}'; + } + + public int getmCityID() { + return mCityID; + } + + public void setmCityID(int mCityID) { + this.mCityID = mCityID; + } + + public String getmCityCode() { + return mCityCode; + } + + public void setmCityCode(String mCityCode) { + this.mCityCode = mCityCode; + } + + public String getmCityName() { + return mCityName; + } + + public void setmCityName(String mCityName) { + this.mCityName = mCityName; + } + + public String getmCityNameTw() { + return mCityNameTw; + } + + public void setmCityNameTw(String mCityNameTw) { + this.mCityNameTw = mCityNameTw; + } + + public String getmCityNameEn() { + return mCityNameEn; + } + + public void setmCityNameEn(String mCityNameEn) { + this.mCityNameEn = mCityNameEn; + } + + public double getmLongitude() { + return mLongitude; + } + + public void setmLongitude(double mLongitude) { + this.mLongitude = mLongitude; + } + + public double getmLatitude() { + return mLatitude; + } + + public void setmLatitude(double mLatitude) { + this.mLatitude = mLatitude; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/IPTV.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/IPTV.java new file mode 100644 index 0000000..b3511fc --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/IPTV.java @@ -0,0 +1,58 @@ +/** + * Created by strawmanbobi + * 2015-07-26 + */ + +package com.yuekong.sirius.ircoderobot.model; + +import java.util.List; + +public class IPTV { + + private int brandID; + private int mKookongBrandID; + private List mRemoteIDList; + + public IPTV(int brandID, int mKookongBrandID, List mRemoteIDList) { + this.brandID = brandID; + this.mKookongBrandID = mKookongBrandID; + this.mRemoteIDList = mRemoteIDList; + } + + public IPTV() { + + } + + @Override + public String toString() { + return "IPTV{" + + "brandID=" + brandID + + ", mKookongBrandID=" + mKookongBrandID + + ", mRemoteIDList=" + mRemoteIDList + + '}'; + } + + public int getBrandID() { + return brandID; + } + + public void setBrandID(int brandID) { + this.brandID = brandID; + } + + public int getmKookongBrandID() { + return mKookongBrandID; + } + + public void setmKookongBrandID(int mKookongBrandID) { + this.mKookongBrandID = mKookongBrandID; + } + + public List getmRemoteIDList() { + return mRemoteIDList; + } + + public void setmRemoteIDList(List mRemoteIDList) { + this.mRemoteIDList = mRemoteIDList; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/KeyInstance.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/KeyInstance.java new file mode 100644 index 0000000..42029a5 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/KeyInstance.java @@ -0,0 +1,59 @@ +/** + * Created by strawmanbobi + * 2016-08-05 + */ + +package com.yuekong.sirius.ircoderobot.model; + +public class KeyInstance { + + public static final int KEY_TYPE_GENERIC = 0; + public static final int KEY_TYPE_RC5 = 1; + + private int mKeyTemplateID; + private int mKeyType; + private String mKeyValue; + + public KeyInstance(int mKeyTemplateID, int mKeyType, String mKeyValue) { + this.mKeyTemplateID = mKeyTemplateID; + this.mKeyType = mKeyType; + this.mKeyValue = mKeyValue; + } + + public KeyInstance() { + + } + + @Override + public String toString() { + return "KeyInstance{" + + "mKeyTemplateID=" + mKeyTemplateID + + ", mKeyType=" + mKeyType + + ", mKeyValue='" + mKeyValue + '\'' + + '}'; + } + + public int getmKeyTemplateID() { + return mKeyTemplateID; + } + + public void setmKeyTemplateID(int mKeyTemplateID) { + this.mKeyTemplateID = mKeyTemplateID; + } + + public int getmKeyType() { + return mKeyType; + } + + public void setmKeyType(int mKeyType) { + this.mKeyType = mKeyType; + } + + public String getmKeyValue() { + return mKeyValue; + } + + public void setmKeyValue(String mKeyValue) { + this.mKeyValue = mKeyValue; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/KeyTemplate.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/KeyTemplate.java new file mode 100644 index 0000000..28bd581 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/KeyTemplate.java @@ -0,0 +1,81 @@ +/** + * Created by Strawmanbobi + * 2016-07-18 + */ + +package com.yuekong.sirius.ircoderobot.model; + +public class KeyTemplate { + + private int mKeyID; + private int mKookongKeyID; + private int mKeyHit; + private String mKeyName; + private String mKeyDisplayName; + + public KeyTemplate(int mKeyID, int mKookongKeyID, String mKeyName, String mKeyDisplayName) { + this.mKeyID = mKeyID; + this.mKookongKeyID = mKookongKeyID; + this.mKeyName = mKeyName; + this.mKeyDisplayName = mKeyDisplayName; + this.mKeyHit = 0; + } + + public KeyTemplate() { + this.mKeyHit = 0; + } + + @Override + public String toString() { + return "KeyTemplate{" + + "mKeyID=" + mKeyID + + ", mKookongKeyID=" + mKookongKeyID + + ", mKeyName='" + mKeyName + '\'' + + ", mKeyDisplayName='" + mKeyDisplayName + '\'' + + '}'; + } + + public int getmKeyID() { + return mKeyID; + } + + public void setmKeyID(int mKeyID) { + this.mKeyID = mKeyID; + } + + public int getmKookongKeyID() { + return mKookongKeyID; + } + + public void setmKookongKeyID(int mKookongKeyID) { + this.mKookongKeyID = mKookongKeyID; + } + + public String getmKeyName() { + return mKeyName; + } + + public void setmKeyName(String mKeyName) { + this.mKeyName = mKeyName; + } + + public String getmKeyDisplayName() { + return mKeyDisplayName; + } + + public void setmKeyDisplayName(String mKeyDisplayName) { + this.mKeyDisplayName = mKeyDisplayName; + } + + public void clearKeyHit() { + this.mKeyHit = 0; + } + + public void countKeyHit() { + this.mKeyHit++; + } + + public int getmKeyHit() { + return mKeyHit; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/Operator.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/Operator.java new file mode 100644 index 0000000..afec877 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/Operator.java @@ -0,0 +1,79 @@ +/** + * Created by strawmanbobi + * 2016-07-18 + */ + +package com.yuekong.sirius.ircoderobot.model; + +public class Operator { + + private int mOperatorID; + private int mOperatorType; + private String mKookongOperatorID; + private String mCityCode; + private String mOperatorName; + + public Operator(int mOperatorID, int mOperatorType, String mKookongOperatorID, String mCityCode, + String mOperatorName) { + this.mOperatorID = mOperatorID; + this.mOperatorType = mOperatorType; + this.mKookongOperatorID = mKookongOperatorID; + this.mCityCode = mCityCode; + this.mOperatorName = mOperatorName; + } + + public Operator() { + + } + + @Override + public String toString() { + return "Operator{" + + "mOperatorID=" + mOperatorID + + ", mOperatorType=" + mOperatorType + + ", mKookongOperatorID='" + mKookongOperatorID + '\'' + + ", mCityCode='" + mCityCode + '\'' + + ", mOperatorName='" + mOperatorName + '\'' + + '}'; + } + + public int getmOperatorID() { + return mOperatorID; + } + + public void setmOperatorID(int mOperatorID) { + this.mOperatorID = mOperatorID; + } + + public int getmOperatorType() { + return mOperatorType; + } + + public void setmOperatorType(int mOperatorType) { + this.mOperatorType = mOperatorType; + } + + public String getmKookongOperatorID() { + return mKookongOperatorID; + } + + public void setmKookongOperatorID(String mKookongOperatorID) { + this.mKookongOperatorID = mKookongOperatorID; + } + + public String getmCityCode() { + return mCityCode; + } + + public void setmCityCode(String mCityCode) { + this.mCityCode = mCityCode; + } + + public String getmOperatorName() { + return mOperatorName; + } + + public void setmOperatorName(String mOperatorName) { + this.mOperatorName = mOperatorName; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/RemoteIndex.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/RemoteIndex.java new file mode 100644 index 0000000..d969488 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/RemoteIndex.java @@ -0,0 +1,122 @@ +/** + * Created by Strawmanbobi + * 2016-07-20 + */ + +package com.yuekong.sirius.ircoderobot.model; + +public class RemoteIndex { + + private int mRemoteIndexID; + private int mKookongRemoteIndexID; + private int mFrequency; + private int mCodeLength; + private int mKookongCategoryID; + private int mKookongBrandID; + private int mCategoryID; + private int mBrandID; + private int mType; + + public RemoteIndex(int mRemoteIndexID, int mKookongRemoteIndexID, int mFrequency, int mCodeLength, + int mKookongCategoryID, int mKookongBrandID, int mCategoryID, int mBrandID, int mType) { + this.mRemoteIndexID = mRemoteIndexID; + this.mKookongRemoteIndexID = mKookongRemoteIndexID; + this.mFrequency = mFrequency; + this.mCodeLength = mCodeLength; + this.mKookongCategoryID = mKookongCategoryID; + this.mKookongBrandID = mKookongBrandID; + this.mCategoryID = mCategoryID; + this.mBrandID = mBrandID; + this.mType = mType; + } + + public RemoteIndex() { + + } + + @Override + public String toString() { + return "RemoteIndex{" + + "mRemoteIndexID=" + mRemoteIndexID + + ", mKookongRemoteIndexID=" + mKookongRemoteIndexID + + ", mFrequency=" + mFrequency + + ", mCodeLength=" + mCodeLength + + ", mKookongCategoryID=" + mKookongCategoryID + + ", mKookongBrandID=" + mKookongBrandID + + ", mCategoryID=" + mCategoryID + + ", mBrandID=" + mBrandID + + ", mType = " + mType; + } + + public int getmRemoteIndexID() { + return mRemoteIndexID; + } + + public void setmRemoteIndexID(int mRemoteIndexID) { + this.mRemoteIndexID = mRemoteIndexID; + } + + public int getmKookongRemoteIndexID() { + return mKookongRemoteIndexID; + } + + public void setmKookongRemoteIndexID(int mKookongRemoteIndexID) { + this.mKookongRemoteIndexID = mKookongRemoteIndexID; + } + + public int getmFrequency() { + return mFrequency; + } + + public void setmFrequency(int mFrequency) { + this.mFrequency = mFrequency; + } + + public int getmCodeLength() { + return mCodeLength; + } + + public void setmCodeLength(int mCodeLength) { + this.mCodeLength = mCodeLength; + } + + public int getmKookongCategoryID() { + return mKookongCategoryID; + } + + public void setmKookongCategoryID(int mKookongCategoryID) { + this.mKookongCategoryID = mKookongCategoryID; + } + + public int getmKookongBrandID() { + return mKookongBrandID; + } + + public void setmKookongBrandID(int mKookongBrandID) { + this.mKookongBrandID = mKookongBrandID; + } + + public int getmCategoryID() { + return mCategoryID; + } + + public void setmCategoryID(int mCategoryID) { + this.mCategoryID = mCategoryID; + } + + public int getmBrandID() { + return mBrandID; + } + + public void setmBrandID(int mBrandID) { + this.mBrandID = mBrandID; + } + + public int getmType() { + return mType; + } + + public void setmType(int mType) { + this.mType = mType; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/RemoteInstance.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/RemoteInstance.java new file mode 100644 index 0000000..028ff98 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/RemoteInstance.java @@ -0,0 +1,59 @@ +/** + * Created by strawmanbobi + * 2016-08-05 + */ + +package com.yuekong.sirius.ircoderobot.model; + +import java.util.List; + +public class RemoteInstance { + + // actually this is the name of remote binary + private int mRemoteTemplateID; + private int mRemoteInstanceType; + private List mKeyInstanceList; + + public RemoteInstance(int mTemplateID, int mRemoteInstanceType, List mKeyInstanceList) { + this.mRemoteTemplateID = mTemplateID; + this.mRemoteInstanceType = mRemoteInstanceType; + this.mKeyInstanceList = mKeyInstanceList; + } + + public RemoteInstance() { + + } + + @Override + public String toString() { + return "RemoteInstance{" + + "mRemoteTemplateID=" + mRemoteTemplateID + + ", mRemoteInstanceType=" + mRemoteInstanceType + + ", mKeyInstanceList=" + mKeyInstanceList + + '}'; + } + + public int getmRemoteTemplateID() { + return mRemoteTemplateID; + } + + public void setmRemoteTemplateID(int mRemoteTemplateID) { + this.mRemoteTemplateID = mRemoteTemplateID; + } + + public int getmRemoteInstanceType() { + return mRemoteInstanceType; + } + + public void setmRemoteInstanceType(int mRemoteInstanceType) { + this.mRemoteInstanceType = mRemoteInstanceType; + } + + public List getmKeyInstanceList() { + return mKeyInstanceList; + } + + public void setmKeyInstanceList(List mKeyInstanceList) { + this.mKeyInstanceList = mKeyInstanceList; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/RemoteTemplate.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/RemoteTemplate.java new file mode 100644 index 0000000..2034765 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/RemoteTemplate.java @@ -0,0 +1,69 @@ +/** + * Created by strawmanbobi + * 2016-07-22 + */ + +package com.yuekong.sirius.ircoderobot.model; + +import java.util.List; + +public class RemoteTemplate { + + private int mRemoteTemplateID; + private int mFrequency; + private int mType; + private List mKeyInstanceList; + + public RemoteTemplate(int mRemoteTemplateID, int mFrequency, int mType, List mKeyInstanceList) { + this.mRemoteTemplateID = mRemoteTemplateID; + this.mFrequency = mFrequency; + this.mType = mType; + this.mKeyInstanceList = mKeyInstanceList; + } + + public RemoteTemplate() { + + } + + @Override + public String toString() { + return "RemoteTemplate{" + + "mRemoteTemplateID=" + mRemoteTemplateID + + ", mFrequency=" + mFrequency + + ", mType=" + mType + + ", mKeyInstanceList=" + mKeyInstanceList + + '}'; + } + + public int getmRemoteTemplateID() { + return mRemoteTemplateID; + } + + public void setmRemoteTemplateID(int mRemoteTemplateID) { + this.mRemoteTemplateID = mRemoteTemplateID; + } + + public int getmFrequency() { + return mFrequency; + } + + public void setmFrequency(int mFrequency) { + this.mFrequency = mFrequency; + } + + public int getmType() { + return mType; + } + + public void setmType(int mType) { + this.mType = mType; + } + + public List getmKeyInstanceList() { + return mKeyInstanceList; + } + + public void setmKeyInstanceList(List mKeyInstanceList) { + this.mKeyInstanceList = mKeyInstanceList; + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/SPStbRel.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/SPStbRel.java new file mode 100644 index 0000000..9a3d14f --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/model/SPStbRel.java @@ -0,0 +1,67 @@ +/** + * Created by Strawmanbobi + * 2015-07-20 + */ + +package com.yuekong.sirius.ircoderobot.model; + +public class SPStbRel { + + private int mOperatorID; + private String mCityCode; + private int mKookongRemoteID; + private int mPriority; + + public SPStbRel(int mOperatorID, String mCityCode, int mKookongRemoteID, int mPriority) { + this.mOperatorID = mOperatorID; + this.mCityCode = mCityCode; + this.mKookongRemoteID = mKookongRemoteID; + this.mPriority = mPriority; + } + + public SPStbRel() { + + } + + @Override + public String toString() { + return "SPStbRel{" + + "mOperatorID=" + mOperatorID + + ", mCityCode=" + mCityCode + + ", mKookongRemoteID=" + mKookongRemoteID + + ", mPriority=" + mPriority + + '}'; + } + + public int getmOperatorID() { + return mOperatorID; + } + + public void setmOperatorID(int mOperatorID) { + this.mOperatorID = mOperatorID; + } + + public String getmCityCode() { + return mCityCode; + } + + public void setmCityCode(String mCityCode) { + this.mCityCode = mCityCode; + } + + public int getmKookongRemoteID() { + return mKookongRemoteID; + } + + public void setmKookongRemoteID(int mKookongRemoteID) { + this.mKookongRemoteID = mKookongRemoteID; + } + + public int getmPriority() { + return mPriority; + } + + public void setmPriority(int mPriority) { + this.mPriority = mPriority; + } +} \ No newline at end of file diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/robot/RemoteEncoder.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/robot/RemoteEncoder.java new file mode 100644 index 0000000..100a696 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/robot/RemoteEncoder.java @@ -0,0 +1,327 @@ +/** + * Created by strawmanbobi + * 2016-08-01 + */ + +package com.yuekong.sirius.ircoderobot.robot; + +import com.mysql.jdbc.Connection; +import com.mysql.jdbc.PreparedStatement; +import com.yuekong.sirius.ircoderobot.model.KeyInstance; +import com.yuekong.sirius.ircoderobot.model.RemoteInstance; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.*; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class RemoteEncoder { + + private static String driver = "com.mysql.jdbc.Driver"; + private static Connection mConnection = null; + + private static final String REMOTE_CONTROLLER_FILE = "/IrRemoteController.xml"; + + private static final int REMOTE_TYPE_COMMAND = 1; + private static final int REMOTE_TYPE_STATUS = 2; + + // xml descriptors + // remote controller descriptors + private static final String NODE_REMOTE_CONTROLLER = "remote_controller"; + private static final String NODE_REMOTE_ID = "id"; + private static final String NODE_REMOTE_FREQUENCY = "frequency"; + private static final String NODE_REMOTE_TYPE = "type"; + private static final String NODE_REMOTE_EXTS = "exts"; + private static final String NODE_REMOTE_EXT = "ext"; + private static final String NODE_REMOTE_KEYS = "keys"; + private static final String NODE_REMOTE_KEY = "key"; + private static final String NODE_REMOTE_KEY_ID = "id"; + private static final String NODE_REMOTE_KEY_PULSE = "pulse"; + + private static final String EX_NODE_UCON_DOCUMENT = "DOCUMENT"; + private static final String EX_NODE_UCON_REMOTE = "remote_controller"; + private static final String EX_NODE_UCON_ID = "id"; + private static final String EX_NODE_UCON_EXTS = "exts"; + private static final String EX_NODE_UCON_EXT = "ext"; + private static final String EX_NODE_UCON_TAG = "tag"; + private static final String EX_NODE_UCON_TAG_VALUE = "value"; + private static final String EX_NODE_UCON_TAG_TYPE = "type"; + + // connection and data source base + private String sourceXmlFileBasePath; + private String outputXmlFileBasePath; + private String encoderPythonFilePath; + private String encoderPythonBasePath; + private String outputBinFileBasePath; + private String dbHost; + private String dbName; + private String dbUser; + private String dbPassword; + private String dbURL; + + // intermediate objects + private List mRemoteInstanceList; + private List mRemoteXMLList; + + public RemoteEncoder(String sourceXmlFileBasePath, String outputXmlFileBasePath, + String encoderPythonFilePath, String encoderPythonBasePath, String outputBinFileBasePath, + String dbHost, String dbName, String dbUser, String dbPassword) { + this.sourceXmlFileBasePath = sourceXmlFileBasePath; + this.outputXmlFileBasePath = outputXmlFileBasePath; + this.encoderPythonFilePath = encoderPythonFilePath; + this.encoderPythonBasePath = encoderPythonBasePath; + this.outputBinFileBasePath = outputBinFileBasePath; + this.dbHost = dbHost; + this.dbName = dbName; + this.dbUser = dbUser; + this.dbPassword = dbPassword; + this.dbURL = "jdbc:mysql://" + dbHost + ":3306/" + dbName; + } + + public boolean encodeAllCommandRemote() { + InputStream input = null; + try { + ////////// step 0 - initialize DB connection ////////// + Class.forName(driver); + System.out.println("URL = " + dbURL + ", user = " + dbUser + ", password = " + dbPassword); + mConnection = (com.mysql.jdbc.Connection) DriverManager.getConnection(dbURL, dbUser, dbPassword); + + ////////// step 1 - initialize XML parser ////////// + Document doc = null; + Element root = null; + NodeList topNodes = null; + DocumentBuilder domBuilder = DocumentBuilderFactory.newInstance() + .newDocumentBuilder(); + + + ////////// step 2 - prepare lists ////////// + mRemoteInstanceList = new ArrayList(); + mRemoteXMLList = new ArrayList(); + + ////////// step 3 - traverse remote template (excluding AC) from remote controller xml file ////////// + String remoteControllerFile = sourceXmlFileBasePath + REMOTE_CONTROLLER_FILE; + System.out.println("traverse remote controller list file"); + if (null != input) { + input.close(); + input = null; + } + input = new FileInputStream(remoteControllerFile); + doc = domBuilder.parse(input); + root = doc.getDocumentElement(); + topNodes = root.getChildNodes(); + for (int topIndex = 0; topIndex < topNodes.getLength(); topIndex++) { + Node remoteItemNode = topNodes.item(topIndex); + if (remoteItemNode.getNodeType() == Node.ELEMENT_NODE + && remoteItemNode.getNodeName().equals(NODE_REMOTE_CONTROLLER)) { + RemoteInstance remoteInstance = new RemoteInstance(); + NodeList remoteInfoNodes = remoteItemNode.getChildNodes(); + for (int remoteInfoIndex = 0; remoteInfoIndex < remoteInfoNodes.getLength(); remoteInfoIndex++) { + Node remoteInfo = remoteInfoNodes.item(remoteInfoIndex); + if (remoteInfo.getNodeType() == Node.ELEMENT_NODE) { + if(remoteInfo.getNodeName().equals(NODE_REMOTE_ID)) { + remoteInstance.setmRemoteTemplateID(Integer.parseInt( + ((Element) remoteInfo).getTextContent())); + } else if (remoteInfo.getNodeName().equals(NODE_REMOTE_TYPE)) { + int remoteType = Integer.parseInt( + ((Element) remoteInfo).getTextContent()); + remoteInstance.setmRemoteInstanceType(Integer.parseInt( + ((Element) remoteInfo).getTextContent())); + } else if (remoteInfo.getNodeName().equals(NODE_REMOTE_KEYS)) { + // parse keys + // System.out.println("This remote index contains element of keys"); + List keys = new ArrayList(); + NodeList keysNodes = remoteInfo.getChildNodes(); + for (int keysInfoIndex = 0; keysInfoIndex < keysNodes.getLength(); keysInfoIndex++) { + Node keysInfo = keysNodes.item(keysInfoIndex); + if (keysInfo.getNodeType() == Node.ELEMENT_NODE) { + if (keysInfo.getNodeName().equals(NODE_REMOTE_KEY)) { + // parse key info + KeyInstance key = new KeyInstance(); + NodeList keyNodes = keysInfo.getChildNodes(); + for (int keyInfoIndex = 0; + keyInfoIndex < keyNodes.getLength(); + keyInfoIndex++) { + Node keyInfo = keyNodes.item(keyInfoIndex); + if (keyInfo.getNodeType() == Node.ELEMENT_NODE) { + if (keyInfo.getNodeName().equals(NODE_REMOTE_KEY_ID)) { + key.setmKeyTemplateID(Integer.parseInt( + ((Element) keyInfo).getTextContent())); + } else if (keyInfo.getNodeName().equals(NODE_REMOTE_KEY_PULSE)) { + String keyPulse = ((Element) keyInfo).getTextContent(); + String pattern = "/d+(,/d+)*"; + Pattern p = Pattern.compile(pattern); + Matcher m = p.matcher(keyPulse); + // NOTE: there are only 2 types of key value, one for + // generic key code, another one for RC-5 typed key code + if (m.matches() == false) { + key.setmKeyType(KeyInstance.KEY_TYPE_RC5); + } else { + key.setmKeyType(KeyInstance.KEY_TYPE_GENERIC); + } + key.setmKeyValue(keyPulse); + } + } + } + keys.add(key); + } + } + } + remoteInstance.setmKeyInstanceList(keys); + } + } + } + if (REMOTE_TYPE_COMMAND == remoteInstance.getmRemoteInstanceType()) { + mRemoteInstanceList.add(remoteInstance); + System.out.println("add remote instance " + remoteInstance.getmRemoteTemplateID()); + } else { + System.out.println("the type of remote instance " + + remoteInstance.getmRemoteTemplateID() + " is " + + REMOTE_TYPE_STATUS); + } + } + } + System.out.println(mRemoteInstanceList.size() + " remote instances are parsed"); + + ////////// step 4 - generate source key-tag xml file for each remote controller ////////// + for (RemoteInstance remoteInstance : mRemoteInstanceList) { + // actually , this is + String outputFilePath = outputXmlFileBasePath + "/yk_remote_" + + remoteInstance.getmRemoteTemplateID() + ".bin"; + + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document remoteDocument = builder.newDocument(); + remoteDocument.setXmlVersion("1.0"); + Element remoteRoot = remoteDocument.createElement(EX_NODE_UCON_DOCUMENT); + remoteDocument.appendChild(remoteRoot); + + Element remoteControllerElement = remoteDocument.createElement(EX_NODE_UCON_REMOTE); + remoteRoot.appendChild(remoteControllerElement); + + Element idElement = remoteDocument.createElement(EX_NODE_UCON_ID); + idElement.setTextContent(String.valueOf(remoteInstance.getmRemoteTemplateID())); + remoteControllerElement.appendChild(idElement); + + Element extsElement = remoteDocument.createElement(EX_NODE_UCON_EXTS); + remoteControllerElement.appendChild(extsElement); + + List keyInstanceList = remoteInstance.getmKeyInstanceList(); + if (null != keyInstanceList) { + System.out.println("Will add " + keyInstanceList.size() + " keys to this remote"); + for (KeyInstance keyInstance : keyInstanceList) { + Element extElement = remoteDocument.createElement(EX_NODE_UCON_EXT); + Element tagElement = remoteDocument.createElement(EX_NODE_UCON_TAG); + tagElement.setTextContent(String.valueOf(keyInstance.getmKeyTemplateID())); + Element tagValueElement = remoteDocument.createElement(EX_NODE_UCON_TAG_VALUE); + tagValueElement.setTextContent(String.valueOf(keyInstance.getmKeyValue())); + Element tagTypeElement = remoteDocument.createElement(EX_NODE_UCON_TAG_TYPE); + tagTypeElement.setTextContent(String.valueOf(keyInstance.getmKeyType())); + + extElement.appendChild(tagElement); + extElement.appendChild(tagValueElement); + extElement.appendChild(tagTypeElement); + + extsElement.appendChild(extElement); + } + } + + TransformerFactory transFactory = TransformerFactory.newInstance(); + Transformer transFormer = transFactory.newTransformer(); + DOMSource domSource = new DOMSource(remoteDocument); + File file = new File(outputFilePath); + if(!file.exists()) { + file.createNewFile(); + } + System.out.println("generating remote source file : " + "yk_remote_" + + remoteInstance.getmRemoteTemplateID() + ".bin"); + FileOutputStream out = new FileOutputStream(file); + StreamResult xmlResult = new StreamResult(out); + transFormer.transform(domSource, xmlResult); + out.close(); + } + System.out.println(mRemoteInstanceList.size() + " source xml files are generated in " + + outputXmlFileBasePath); + + ////////// step 5 - compress key-tag files into binary with dynamic python encoder ////////// + // collect output files + // NOTE: skip step 5 for UCON SIRIUS + /* + System.out.println("collecting output xml files..."); + getXMLSourceFiles(outputXmlFileBasePath); + System.out.println("collecting output xml files done"); + + for (String srcXMLFile : mRemoteXMLList) { + String pythonInputArg0 = srcXMLFile; + String pythonInputArg1 = outputBinFileBasePath + "\\"; + + // generate dynamic tag for python encoder according to remote template information + String remoteTemplateID = pythonInputArg0.substring(pythonInputArg0.lastIndexOf('_') + 1, + pythonInputArg0.lastIndexOf('.')); + + String keyString = ""; + + String sqlString = "SELECT * FROM remote_template WHERE remote_template_id = ?;"; + PreparedStatement statement = (PreparedStatement) mConnection.prepareStatement(sqlString); + statement.setInt(1, Integer.parseInt(remoteTemplateID)); + ResultSet resultSet = statement.executeQuery(); + if (resultSet.next()) { + keyString = resultSet.getString("related_keys"); + } + + // no auto-tags is allowed + String tagPythonFileName = encoderPythonBasePath + "\\tags.py"; + String pythonContent = "allTags = [" + keyString + "]"; + FileOutputStream fos = new FileOutputStream(tagPythonFileName); + fos.write(pythonContent.getBytes()); + fos.close(); + + // run python to encode xml files + Process p = Runtime.getRuntime().exec("python " + encoderPythonFilePath + " " + + pythonInputArg0 + " " + pythonInputArg1); + BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); + String s = null; + do { + s = br.readLine(); + if (null != s) { + System.out.println(s); + } else { + break; + } + } while(true); + p.waitFor(); + p.destroy(); + + Thread.sleep(500); + } + */ + } catch (Exception e) { + e.printStackTrace(); + } + + return true; + } + + // utils + private void getXMLSourceFiles(String filePath) { + File root = new File(filePath); + File[] files = root.listFiles(); + for (File file : files) { + if (!file.isDirectory() && file.getName().contains("yk_remote")) { + mRemoteXMLList.add(file.getAbsolutePath()); + } + } + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/robot/RemoteIndexGenerator.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/robot/RemoteIndexGenerator.java new file mode 100644 index 0000000..5c9bfd9 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/robot/RemoteIndexGenerator.java @@ -0,0 +1,1446 @@ +/** + * Created by strawmanbobi + * 2016-07-20 + */ + +package com.yuekong.sirius.ircoderobot.robot; + +import com.mysql.jdbc.Connection; +import com.mysql.jdbc.PreparedStatement; +import com.mysql.jdbc.ResultSet; +import com.yuekong.sirius.ircoderobot.model.*; +import org.w3c.dom.*; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.sql.DriverManager; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class RemoteIndexGenerator { + + private static String driver = "com.mysql.jdbc.Driver"; + private static Connection mConnection = null; + + private static final String KEY_DESCRIPTOR_FILE = "/IrKey.xml"; + private static final String DEVICE_TYPE_FILE = "/IrDeviceType.xml"; + private static final String BRAND_FILE = "/IrBrand.xml"; + private static final String CITY_FILE = "/IrCityArea.xml"; + private static final String BRAND_REMOTE_REL_FILE = "/IrBrandRemoteRel.xml"; + private static final String SP_REMOTE_REL_FILE = "/IrSpRemoteRel.xml"; + private static final String STB_OPERATOR_FILE = "/IrService_provider_CN.xml"; + private static final String IPTV_FILE = "/IrIPTV.xml"; + private static final String REMOTE_CONTROLLER_FILE = "/IrRemoteController.xml"; + + public static final int REMOTE_TYPE_COMMAND = 1; + public static final int REMOTE_TYPE_STATUS = 2; + + // xml descriptors + // key descriptors + private static final String NODE_KEY = "key"; + private static final String NODE_KEY_ID = "id"; + private static final String NODE_KEY_NAME = "name"; + private static final String NODE_KEY_DISPLAY_NAME = "display_name"; + + // device type descriptors + private static final String NODE_DEVICE_TYPE = "device_type"; + private static final String NODE_DEVICE_TYPE_ID = "id"; + private static final String NODE_DEVICE_TYPE_NAME = "name"; + + // brand descriptors + private static final String NODE_BRAND = "brand"; + private static final String NODE_BRAND_ID = "id"; + private static final String NODE_BRAND_NAME = "name"; + + // city descriptors + private static final String NODE_CITY = "city"; + private static final String NODE_CITY_ID = "id"; + private static final String NODE_CITY_NAME = "name"; + private static final String NODE_CITY_AREAS = "areas"; + private static final String NODE_CITY_AREA = "area"; + + // operator descriptors + private static final String NODE_OPERATOR = "service_provider"; + private static final String NODE_CITY_ID_IN_OPR = "city_id"; + private static final String NODE_OPERATOR_NAME = "provider_name"; + private static final String NODE_OPERATOR_TYPE = "type"; + + // brand-remote relationship descriptors + private static final String NODE_BRAND_REMOTE = "item"; + private static final String NODE_DEVICE_TYPE_ID_IN_BRR = "device_type_id"; + private static final String NODE_BRAND_ID_IN_BRR = "brand_id"; + private static final String NODE_REMOTE_ID_IN_BRR = "remote_id"; + private static final String NODE_RANK_IN_BRR = "rank"; + + // iptv descriptors + private static final String NODE_IPTV = "item"; + private static final String NODE_BRAND_ID_IN_IPTV = "brand_id"; + private static final String NODE_REMOTE_IDS = "remote_ids"; + + // operator-remote relationship descriptors + private static final String NODE_SP_STB_REL = "item"; + private static final String NODE_OPERATOR_ID_IN_SSR = "sp_id"; + private static final String NODE_CITY_ID_IN_SSR = "city_id"; + private static final String NODE_REMOTE_ID_IN_SSR = "remote_id"; + private static final String NODE_RANK_IN_SSR = "rank"; + + // remote controller descriptors + private static final String NODE_REMOTE_CONTROLLER = "remote_controller"; + private static final String NODE_REMOTE_ID = "id"; + private static final String NODE_REMOTE_FREQUENCY = "frequency"; + private static final String NODE_REMOTE_TYPE = "type"; + private static final String NODE_REMOTE_EXTS = "exts"; + private static final String NODE_REMOTE_EXT = "ext"; + private static final String NODE_REMOTE_KEYS = "keys"; + private static final String NODE_REMOTE_KEY = "key"; + private static final String NODE_REMOTE_KEY_ID = "id"; + private static final String NODE_REMOTE_KEY_PULSE = "pulse"; + + // kookong-ucon cateogry mapping + // the index of array indicates kookong device type ID while the value of array indicates UCONs' + // NOTE: IPTV in UCON remote index system is separated from STB, so it should not be in this table + private static final int[] catetoryMapping = { + 3, // STB + 5, // IPTV + 2, // TV + 4, // Net Box + 6, // DVD + 1, // AC + 8, // Projector + 9, // Stereo + 7, // Fan + 11, // SLR + 10, // Light + }; + + private static final String[] categoryNameMapping = { + "机顶盒", + "IPTV", + "电视机", + "网络盒子", + "DVD", + "空调", + "投影仪", + "音响", + "电风扇", + "单反相机", + "灯", + }; + + // connection and data source base + private String xmlFileBasePath; + private String acBinFileBasePath; + private String dbName; + private String dbUser; + private String dbPassword; + private String dbURL = ""; + + // sub function + private int subFunction = -1; + + // intermediate objects + private List mCategoryList; + private List mBrandList; + private List mProvinceList; + private List mCityList; + private List mOperatorList; + private List mCategoryBrandReList; + private List mOperatorStbRelList; + private List mBrandRemoteRelList; + private List mIPTVList; + private List mKeyTemplateList; + private List mRemoteTemplateList; + private ArrayList mACBinFileList; + private Map> mIntersectionKeysByCategory; + + public RemoteIndexGenerator(String xmlFileBasePath, String acBinFileBasePath, String dbHost, String dbName, + String dbUser, String dbPassword) { + this.xmlFileBasePath = xmlFileBasePath; + this.acBinFileBasePath = acBinFileBasePath; + this.dbName = dbName; + this.dbUser = dbUser; + this.dbPassword = dbPassword; + this.dbURL = "jdbc:mysql://" + dbHost + ":3306/" + dbName; + } + + public boolean generateAllRemoteIndexes() { + InputStream input = null; + try { + ////////// step 0 - initialize db connections ////////// + Class.forName(driver); + System.out.println("URL = " + dbURL + ", user = " + dbUser + ", password = " + dbPassword); + mConnection = (com.mysql.jdbc.Connection) DriverManager.getConnection(dbURL, dbUser, dbPassword); + + ////////// step 1 - initialize XML parser ////////// + Document doc = null; + Element root = null; + NodeList topNodes = null; + DocumentBuilder domBuilder = DocumentBuilderFactory.newInstance() + .newDocumentBuilder(); + + ////////// step 2 - prepare lists ////////// + mCategoryList = new ArrayList(); + mBrandList = new ArrayList(); + mProvinceList = new ArrayList(); + mCityList = new ArrayList(); + mOperatorList = new ArrayList(); + mCategoryBrandReList = new ArrayList(); + mOperatorStbRelList = new ArrayList(); + mBrandRemoteRelList = new ArrayList(); + mIPTVList = new ArrayList(); + mKeyTemplateList = new ArrayList(); + mRemoteTemplateList = new ArrayList(); + mACBinFileList = new ArrayList(); + mIntersectionKeysByCategory = new HashMap>(); + + ////////// step 3 - traverse key file and collect key template ////////// + String keyMapFile = xmlFileBasePath + KEY_DESCRIPTOR_FILE; + System.out.println("traverse KeyTemplate list file"); + if (null != input) { + input.close(); + input = null; + } + input = new FileInputStream(keyMapFile); + doc = domBuilder.parse(input); + root = doc.getDocumentElement(); + topNodes = root.getChildNodes(); + for (int topIndex = 0; topIndex < topNodes.getLength(); topIndex++) { + Node keyItemNode = topNodes.item(topIndex); + if (keyItemNode.getNodeType() == Node.ELEMENT_NODE + && keyItemNode.getNodeName().equals(NODE_KEY)) { + KeyTemplate scanKeyTemplate = new KeyTemplate(); + NodeList keyInfoNodes = keyItemNode.getChildNodes(); + for (int infoIndex = 0; infoIndex < keyInfoNodes.getLength(); infoIndex++) { + Node keyInfo = keyInfoNodes.item(infoIndex); + if (keyInfo.getNodeType() == Node.ELEMENT_NODE) { + if(keyInfo.getNodeName().equals(NODE_KEY_ID)) { + scanKeyTemplate.setmKeyID(Integer.parseInt(((Element) keyInfo).getTextContent())); + } else if (keyInfo.getNodeName().equals(NODE_KEY_NAME)) { + scanKeyTemplate.setmKeyName(((Element) keyInfo).getTextContent()); + } else if (keyInfo.getNodeName().equals(NODE_KEY_DISPLAY_NAME)) { + scanKeyTemplate.setmKeyDisplayName(((Element) keyInfo).getTextContent()); + } + } + } + mKeyTemplateList.add(scanKeyTemplate); + } + } + + // insert this key into db if not exist + int insertKeyCount = 0; + for (KeyTemplate keyTemplate : mKeyTemplateList) { + String sqlString = "SELECT * FROM key_template WHERE key_id = '" + keyTemplate.getmKeyID() + "'"; + PreparedStatement statement = (PreparedStatement) mConnection.prepareStatement(sqlString); + ResultSet resultSet = (ResultSet) statement.executeQuery(); + if(resultSet.next()) { + // this key already exists in template list, do nothing + System.out.println("key " + keyTemplate.getmKeyID() + + " (" + keyTemplate.getmKeyDisplayName() + ") already exists in key template table"); + } else { + // this key does not exist in template list, insert it + System.out.println("key " + keyTemplate.getmKeyID() + + " (" + keyTemplate.getmKeyDisplayName() + ") does not exist in key template table, add it"); + + String innerSqlString = "INSERT INTO key_template(key_id, key_name, key_display_name) " + + "VALUES (?, ?, ?)"; + PreparedStatement innerStatement = (PreparedStatement) mConnection.prepareStatement(innerSqlString); + innerStatement.setInt(1, keyTemplate.getmKeyID()); + innerStatement.setString(2, keyTemplate.getmKeyName()); + innerStatement.setString(3, keyTemplate.getmKeyDisplayName()); + innerStatement.executeUpdate(); + ResultSet innerResultSet = (ResultSet) innerStatement.getGeneratedKeys(); + if (innerResultSet.next()) { + Long gk = (Long) innerResultSet.getObject(1); + insertKeyCount++; + } + } + } + System.out.println(mKeyTemplateList.size() + " key templates are parsed, " + insertKeyCount + + " have been added"); + + // sort key ids and output the array for further use + int keyIDs[] = new int[mKeyTemplateList.size()]; + for (int i = 0; i < mKeyTemplateList.size(); i++) { + keyIDs[i] = mKeyTemplateList.get(i).getmKeyID(); + } + java.util.Arrays.sort(keyIDs); + + System.out.println("\r\n============ KEY list ============"); + for (int i = 0; i < keyIDs.length; i++) { + System.out.print(keyIDs[i] + ", "); + if (0 == i % 10) { + System.out.println(); + } + } + System.out.println("\r\n============ KEY list ============"); + + ////////// step 4 - traverse device type file and collect categories ////////// + + mCategoryList.add(new Category(0, "机顶盒", "", "")); + mCategoryList.add(new Category(1, "IPTV", "", "")); + mCategoryList.add(new Category(2, "电视机", "", "")); + mCategoryList.add(new Category(3, "网络盒子", "", "")); + mCategoryList.add(new Category(4, "DVD", "", "")); + mCategoryList.add(new Category(5, "空调", "", "")); + mCategoryList.add(new Category(6, "投影仪", "", "")); + mCategoryList.add(new Category(7, "音响", "", "")); + mCategoryList.add(new Category(8, "电风扇", "", "")); + mCategoryList.add(new Category(9, "单反相机", "", "")); + mCategoryList.add(new Category(10, "灯", "", "")); + + // have some debug + for (Category category : mCategoryList) { + System.out.println("category : " + category.getmKookongCategoryID() + ", " + + category.getmCategoryName()); + } + System.out.println(mCategoryList.size() + " categories are found"); + + ////////// step 5 - traverse city file and collect cites ////////// + // WARNING: per missing information from kookong original code table, + // we need to import city manually from external DB or SQL script. + + + String cityFile = xmlFileBasePath + CITY_FILE; + System.out.println("traverse city list file"); + if (null != input) { + input.close(); + input = null; + } + input = new FileInputStream(cityFile); + doc = domBuilder.parse(input); + root = doc.getDocumentElement(); + topNodes = root.getChildNodes(); + int insertProvinceCount = 0; + int insertCityCount = 0; + for (int topIndex = 0; topIndex < topNodes.getLength(); topIndex++) { + Node cityNode = topNodes.item(topIndex); + // get root node + if (cityNode.getNodeType() == Node.ELEMENT_NODE + && cityNode.getNodeName().equals(NODE_CITY)) { + // get city info node + City city = new City(); + NodeList cityInfoNodes = cityNode.getChildNodes(); + for(int infoIndex = 0; infoIndex < cityInfoNodes.getLength(); infoIndex++) { + Node cityInfo = cityInfoNodes.item(infoIndex); + if(cityInfo.getNodeType() == Node.ELEMENT_NODE) { + if(cityInfo.getNodeName().equals(NODE_CITY_ID)) { + city.setmCityCode(((Element) cityInfo).getTextContent()); + } else if(cityInfo.getNodeName().equals(NODE_CITY_NAME)) { + city.setmCityName(((Element)cityInfo).getTextContent()); + String sqlString = "SELECT * FROM city WHERE code = '"+ city.getmCityCode() +"';"; + PreparedStatement statement = (PreparedStatement) mConnection + .prepareStatement(sqlString); + ResultSet resultSet = (ResultSet) statement.executeQuery(); + if(resultSet.next()) { + System.out.println("city already exists : " + city.getmCityCode() + ", " + + city.getmCityName()); + } else { + System.out.println("city does not exist : " + city.getmCityCode() + ", " + + city.getmCityName() + " insert into db") ; + + String innerSqlString = "INSERT INTO city(code, name, status) " + + "VALUES (?, ?, '1')"; + PreparedStatement innerStatement = (PreparedStatement) mConnection + .prepareStatement(innerSqlString); + innerStatement.setString(1, city.getmCityCode()); + innerStatement.setString(2, city.getmCityName()); + innerStatement.executeUpdate(); + insertProvinceCount ++; + } + } else if(cityInfo.getNodeName().equals(NODE_CITY_AREAS)) { + NodeList areaNodes = cityInfo.getChildNodes(); + City cityArea = new City(); + for(int areaIndex = 0; areaIndex < areaNodes.getLength(); areaIndex ++) { + Node areaNode = areaNodes.item(areaIndex); + NodeList areaInfos = areaNode.getChildNodes(); + for(int areaInfoIndex = 0; areaInfoIndex < areaInfos.getLength(); areaInfoIndex++) { + Node areaInfo = areaInfos.item(areaInfoIndex); + if(areaInfo.getNodeName().equals(NODE_CITY_ID)) { + cityArea.setmCityCode(((Element) areaInfo).getTextContent()); + } else if(areaInfo.getNodeName().equals(NODE_CITY_NAME)) { + cityArea.setmCityName(((Element) areaInfo).getTextContent()); + + // Insert city area into city table if not exists + String sqlString = "SELECT * FROM city WHERE code = '"+ + cityArea.getmCityCode() +"';"; + PreparedStatement statement = (PreparedStatement) mConnection + .prepareStatement(sqlString); + ResultSet resultSet = (ResultSet) statement.executeQuery(); + if(resultSet.next()) { + System.out.println("city area already exists : " + + cityArea.getmCityCode() + ", " + cityArea.getmCityName()); + } else { + System.out.println("city area does not exist : " + + cityArea.getmCityCode() + ", " + cityArea.getmCityName() + + " insert into db"); + String innerSqlString = "INSERT INTO city(code, name, status) " + + "VALUES (?, ?, '1')"; + PreparedStatement innerStatement = (PreparedStatement) mConnection + .prepareStatement(innerSqlString); + innerStatement.setString(1, cityArea.getmCityCode()); + innerStatement.setString(2, cityArea.getmCityName()); + innerStatement.executeUpdate(); + insertCityCount ++; + } + } + } + } + } + } + } + System.out.println(mProvinceList.size() + " provinces have been parsed, " + insertProvinceCount + + " have been added"); + + System.out.println(mCityList.size() + " cities have been parsed, " + insertCityCount + + " have been added"); + } else { + // System.out.println("name of top node = " + ((Element)cityNode).getTextContent()); + } + } + + ////////// step 6 - traverse operator file and collect operators ////////// + String operatorFile = xmlFileBasePath + STB_OPERATOR_FILE; + System.out.println("traverse stb operator list file"); + if (null != input) { + input.close(); + input = null; + } + input = new FileInputStream(operatorFile); + doc = domBuilder.parse(input); + root = doc.getDocumentElement(); + topNodes = root.getChildNodes(); + for (int topIndex = 0; topIndex < topNodes.getLength(); topIndex++) { + Node operatorItemNode = topNodes.item(topIndex); + if (operatorItemNode.getNodeType() == Node.ELEMENT_NODE + && operatorItemNode.getNodeName().equals(NODE_OPERATOR)) { + Operator operator = new Operator(); + + // get id from attribute of node + NamedNodeMap attributes = operatorItemNode.getAttributes(); + Node attribute = attributes.item(0); + operator.setmKookongOperatorID(attribute.getNodeValue()); + + NodeList operatorInfoNodes = operatorItemNode.getChildNodes(); + for (int infoIndex = 0; infoIndex < operatorInfoNodes.getLength(); infoIndex++) { + Node operatorInfo = operatorInfoNodes.item(infoIndex); + if (operatorInfo.getNodeType() == Node.ELEMENT_NODE) { + if(operatorInfo.getNodeName().equals(NODE_CITY_ID_IN_OPR)) { + operator.setmCityCode(((Element) operatorInfo).getTextContent()); + } else if (operatorInfo.getNodeName().equals(NODE_OPERATOR_NAME)) { + operator.setmOperatorName(((Element) operatorInfo).getTextContent()); + } else if (operatorInfo.getNodeName().equals(NODE_OPERATOR_TYPE)) { + operator.setmOperatorType(Integer.parseInt( + ((Element) operatorInfo).getTextContent())); + } + } + } + mOperatorList.add(operator); + } + } + for(Operator op : mOperatorList) { + System.out.println("added op : " + op.toString()); + } + + int insertOperatorCount = 0; + for (Operator operator : mOperatorList) { + String sqlString = "SELECT * FROM stb_operator WHERE operator_id = '" + + operator.getmKookongOperatorID() + "' AND city_code = '" + operator.getmCityCode() + "'"; + PreparedStatement statement = (PreparedStatement) mConnection.prepareStatement(sqlString); + ResultSet resultSet = (ResultSet) statement.executeQuery(); + if(resultSet.next()) { + // this operator already exists in operator list, do nothing + System.out.println("operator " + operator.getmKookongOperatorID() + + " (" + operator.getmOperatorName() + ") already exists in operator table"); + } else { + // this operator does not exist in operator list, insert it + System.out.println("operator " + operator.getmKookongOperatorID() + + " (" + operator.getmOperatorName() + ") does not exist in key operator table, add it"); + + String cityName = ""; + String outerSqlString = "SELECT name FROM city WHERE code = '" + operator.getmCityCode() + "';"; + PreparedStatement outerStatement = (PreparedStatement) mConnection.prepareStatement(outerSqlString); + ResultSet outerResultSet = (ResultSet) outerStatement.executeQuery(); + if(outerResultSet.next()) { + cityName = outerResultSet.getString("name"); + } + + String innerSqlString = "INSERT INTO stb_operator(operator_id, operator_name, city_code," + + " city_name, operator_type) " + + "VALUES (?, ?, ?, ?, ?)"; + PreparedStatement innerStatement = (PreparedStatement) mConnection.prepareStatement(innerSqlString); + innerStatement.setString(1, operator.getmKookongOperatorID()); + innerStatement.setString(2, operator.getmOperatorName()); + innerStatement.setString(3, operator.getmCityCode()); + innerStatement.setString(4, cityName); + innerStatement.setInt(5, operator.getmOperatorType()); + innerStatement.executeUpdate(); + ResultSet innerResultSet = (ResultSet) innerStatement.getGeneratedKeys(); + if (innerResultSet.next()) { + Long gk = (Long) innerResultSet.getObject(1); + insertOperatorCount++; + } + } + } + + System.out.println(mOperatorList.size() + " operators are parsed, " + insertOperatorCount + + " have been added"); + + ////////// step 7 - traverse brand file and collect brands ////////// + String brandFile = xmlFileBasePath + BRAND_FILE; + System.out.println("traverse brand list file"); + if (null != input) { + input.close(); + input = null; + } + input = new FileInputStream(brandFile); + doc = domBuilder.parse(input); + root = doc.getDocumentElement(); + topNodes = root.getChildNodes(); + for (int topIndex = 0; topIndex < topNodes.getLength(); topIndex++) { + Node brandItemNode = topNodes.item(topIndex); + if (brandItemNode.getNodeType() == Node.ELEMENT_NODE + && brandItemNode.getNodeName().equals(NODE_BRAND)) { + Brand brand = new Brand(); + NodeList brandInfoNodes = brandItemNode.getChildNodes(); + for (int infoIndex = 0; infoIndex < brandInfoNodes.getLength(); infoIndex++) { + Node brandInfo = brandInfoNodes.item(infoIndex); + if (brandInfo.getNodeType() == Node.ELEMENT_NODE) { + if(brandInfo.getNodeName().equals(NODE_BRAND_ID)) { + brand.setmKookongBrandID(Integer.parseInt( + ((Element) brandInfo).getTextContent())); + } else if (brandInfo.getNodeName().equals(NODE_DEVICE_TYPE_NAME)) { + brand.setmBrandName(((Element) brandInfo).getTextContent()); + } + } + } + mBrandList.add(brand); + } + } + System.out.println(mBrandList.size() + " brands are parsed"); + + ////////// step 8 - traverse brand-remote file and collect brand-remote relationship ////////// + String brandRemoteRelFile = xmlFileBasePath + BRAND_REMOTE_REL_FILE; + System.out.println("traverse brand remote relationship list file"); + if (null != input) { + input.close(); + input = null; + } + input = new FileInputStream(brandRemoteRelFile); + doc = domBuilder.parse(input); + root = doc.getDocumentElement(); + topNodes = root.getChildNodes(); + + for (int topIndex = 0; topIndex < topNodes.getLength(); topIndex++) { + Node relItemNode = topNodes.item(topIndex); + if (relItemNode.getNodeType() == Node.ELEMENT_NODE + && relItemNode.getNodeName().equals(NODE_BRAND_REMOTE)) { + BrandRemoteRel brandRemoteRel = new BrandRemoteRel(); + NodeList relInfoNodes = relItemNode.getChildNodes(); + for (int infoIndex = 0; infoIndex < relInfoNodes.getLength(); infoIndex++) { + Node relInfo = relInfoNodes.item(infoIndex); + if (relInfo.getNodeType() == Node.ELEMENT_NODE) { + if(relInfo.getNodeName().equals(NODE_DEVICE_TYPE_ID_IN_BRR)) { + brandRemoteRel.setmKookongCategoryID(Integer.parseInt( + ((Element) relInfo).getTextContent())); + } else if (relInfo.getNodeName().equals(NODE_BRAND_ID_IN_BRR)) { + brandRemoteRel.setmKookongBrandID(Integer.parseInt( + ((Element) relInfo).getTextContent())); + } else if (relInfo.getNodeName().equals(NODE_REMOTE_ID_IN_BRR)) { + brandRemoteRel.setmKookongRemoteID(Integer.parseInt( + ((Element) relInfo).getTextContent())); + } else if (relInfo.getNodeName().equals(NODE_RANK_IN_BRR)) { + brandRemoteRel.setmPriority(Integer.parseInt( + ((Element) relInfo).getTextContent())); + } + } + } + mBrandRemoteRelList.add(brandRemoteRel); + } + } + System.out.println(mBrandRemoteRelList.size() + " brand-remote item parsed"); + + ////////// step 9 - traverse operator-remote relationship from spstbrel xml file ////////// + String operatorRemoteRelFile = xmlFileBasePath + SP_REMOTE_REL_FILE; + System.out.println("traverse SPStbRel list file"); + if (null != input) { + input.close(); + input = null; + } + input = new FileInputStream(operatorRemoteRelFile); + doc = domBuilder.parse(input); + root = doc.getDocumentElement(); + topNodes = root.getChildNodes(); + for (int topIndex = 0; topIndex < topNodes.getLength(); topIndex++) { + Node spStbRelItemNode = topNodes.item(topIndex); + if (spStbRelItemNode.getNodeType() == Node.ELEMENT_NODE + && spStbRelItemNode.getNodeName().equals(NODE_SP_STB_REL)) { + SPStbRel operatorRemoteRel = new SPStbRel(); + NodeList spStbRelInfoNodes = spStbRelItemNode.getChildNodes(); + for (int infoIndex = 0; infoIndex < spStbRelInfoNodes.getLength(); infoIndex++) { + Node spStbRelInfo = spStbRelInfoNodes.item(infoIndex); + if (spStbRelInfo.getNodeType() == Node.ELEMENT_NODE) { + if(spStbRelInfo.getNodeName().equals(NODE_OPERATOR_ID_IN_SSR)) { + operatorRemoteRel.setmOperatorID(Integer.parseInt( + ((Element) spStbRelInfo).getTextContent())); + } else if (spStbRelInfo.getNodeName().equals(NODE_CITY_ID_IN_SSR)) { + operatorRemoteRel.setmCityCode(((Element) spStbRelInfo).getTextContent()); + } else if (spStbRelInfo.getNodeName().equals(NODE_REMOTE_ID_IN_SSR)) { + operatorRemoteRel.setmKookongRemoteID(Integer.parseInt( + ((Element) spStbRelInfo).getTextContent())); + } else if (spStbRelInfo.getNodeName().equals(NODE_RANK_IN_SSR)) { + operatorRemoteRel.setmPriority(Integer.parseInt( + ((Element) spStbRelInfo).getTextContent())); + } + } + } + mOperatorStbRelList.add(operatorRemoteRel); + } + } + System.out.println(mOperatorStbRelList.size() + " operator-remote index relationship items are parsed"); + + ////////// step 10 - traverse brand-remote relationship from IPTV xml file ////////// + String iptvFile = xmlFileBasePath + IPTV_FILE; + System.out.println("traverse IPTV list file"); + if (null != input) { + input.close(); + input = null; + } + input = new FileInputStream(iptvFile); + doc = domBuilder.parse(input); + root = doc.getDocumentElement(); + topNodes = root.getChildNodes(); + for (int topIndex = 0; topIndex < topNodes.getLength(); topIndex++) { + Node iptvItemNode = topNodes.item(topIndex); + if (iptvItemNode.getNodeType() == Node.ELEMENT_NODE + && iptvItemNode.getNodeName().equals(NODE_IPTV)) { + IPTV iptv = new IPTV(); + NodeList iptvInfoNodes = iptvItemNode.getChildNodes(); + for (int infoIndex = 0; infoIndex < iptvInfoNodes.getLength(); infoIndex++) { + Node iptvInfo = iptvInfoNodes.item(infoIndex); + if (iptvInfo.getNodeType() == Node.ELEMENT_NODE) { + if(iptvInfo.getNodeName().equals(NODE_BRAND_ID_IN_IPTV)) { + iptv.setmKookongBrandID(Integer.parseInt( + ((Element) iptvInfo).getTextContent() + )); + } else if (iptvInfo.getNodeName().equals(NODE_REMOTE_IDS)) { + String remoteIdsStr = ((Element) iptvInfo).getTextContent(); + String []remoteIdsList = remoteIdsStr.split(","); + List remoteIds = new ArrayList(); + for (int remoteIdIndex = 0; remoteIdIndex < remoteIdsList.length; remoteIdIndex++) { + remoteIds.add(Integer.parseInt(remoteIdsList[remoteIdIndex])); + } + iptv.setmRemoteIDList(remoteIds); + } + } + } + mIPTVList.add(iptv); + } + } + System.out.println(mIPTVList.size() + " IPTV brands are parsed"); + + ////////// step 11 - traverse remote template (excluding AC) from remote controller xml file ////////// + int validKeys = 0; + int invalidKeys = 0; + String remoteControllerFile = xmlFileBasePath + REMOTE_CONTROLLER_FILE; + System.out.println("traverse remote controller list file"); + if (null != input) { + input.close(); + input = null; + } + input = new FileInputStream(remoteControllerFile); + doc = domBuilder.parse(input); + root = doc.getDocumentElement(); + topNodes = root.getChildNodes(); + for (int topIndex = 0; topIndex < topNodes.getLength(); topIndex++) { + Node remoteItemNode = topNodes.item(topIndex); + if (remoteItemNode.getNodeType() == Node.ELEMENT_NODE + && remoteItemNode.getNodeName().equals(NODE_REMOTE_CONTROLLER)) { + RemoteTemplate remoteTemplate = new RemoteTemplate(); + NodeList remoteInfoNodes = remoteItemNode.getChildNodes(); + for (int remoteInfoIndex = 0; remoteInfoIndex < remoteInfoNodes.getLength(); remoteInfoIndex++) { + Node remoteInfo = remoteInfoNodes.item(remoteInfoIndex); + if (remoteInfo.getNodeType() == Node.ELEMENT_NODE) { + if(remoteInfo.getNodeName().equals(NODE_REMOTE_ID)) { + remoteTemplate.setmRemoteTemplateID(Integer.parseInt( + ((Element) remoteInfo).getTextContent())); + } else if (remoteInfo.getNodeName().equals(NODE_REMOTE_FREQUENCY)) { + remoteTemplate.setmFrequency(Integer.parseInt( + ((Element) remoteInfo).getTextContent())); + } else if (remoteInfo.getNodeName().equals(NODE_REMOTE_TYPE)) { + remoteTemplate.setmType(Integer.parseInt( + ((Element) remoteInfo).getTextContent())); + } else if (remoteInfo.getNodeName().equals(NODE_REMOTE_KEYS)) { + // parse keys + // System.out.println("This remote index contains element of keys"); + List keys = new ArrayList(); + NodeList keysNodes = remoteInfo.getChildNodes(); + for (int keysInfoIndex = 0; keysInfoIndex < keysNodes.getLength(); keysInfoIndex++) { + Node keysInfo = keysNodes.item(keysInfoIndex); + if (keysInfo.getNodeType() == Node.ELEMENT_NODE) { + if (keysInfo.getNodeName().equals(NODE_REMOTE_KEY)) { + // parse key info + NodeList keyNodes = keysInfo.getChildNodes(); + for (int keyInfoIndex = 0; keyInfoIndex < keyNodes.getLength(); keyInfoIndex++) { + Node keyInfo = keyNodes.item(keyInfoIndex); + if (keyInfo.getNodeType() == Node.ELEMENT_NODE) { + if (keyInfo.getNodeName().equals(NODE_REMOTE_KEY_ID)) { + KeyTemplate key = new KeyTemplate(); + key.setmKeyID(Integer.parseInt( + ((Element) keyInfo).getTextContent())); + keys.add(key); + } else if (keyInfo.getNodeName().equals(NODE_REMOTE_KEY_PULSE)) { + String keyPulse = ((Element) keyInfo).getTextContent(); + String pattern = "\\d+(,\\d+)*"; + Pattern p = Pattern.compile(pattern); + Matcher m = p.matcher(keyPulse); + if (m.matches() == false) { + System.out.println("+++++ " + keyPulse); + invalidKeys ++; + } else { + validKeys ++; + } + } + } + } + } + } + } + remoteTemplate.setmKeyInstanceList(keys); + } + } + } + if (REMOTE_TYPE_COMMAND == remoteTemplate.getmType() && + 5 != getCategoryOfRemoteIndex(remoteTemplate.getmRemoteTemplateID())) { + mRemoteTemplateList.add(remoteTemplate); + } else { + // do nothing + } + // note, excluding AC, the left remote indexes added to the remoteIndexList includes: STB(category 0), + // TV, IPTV(category 1), BOX, DVD, FAN, STEREO, PROJECTOR, CAMERA and LIGHT + } + } + System.out.println("valid keys = " + validKeys + ", invalid keys = " + invalidKeys); + + ////////// step 12 - build, build, build, WTF. ////////// + + // build up remote template according to remote template list + int insertRemoteTemplateCount = 0; + for (RemoteTemplate remoteTemplate : mRemoteTemplateList) { + String sqlString = "SELECT * FROM remote_template WHERE remote_template_id = '" + + remoteTemplate.getmRemoteTemplateID() + "'"; + PreparedStatement statement = (PreparedStatement) mConnection.prepareStatement(sqlString); + ResultSet resultSet = (ResultSet) statement.executeQuery(); + if(resultSet.next()) { + // this remote template already exists in template list, do nothing + System.out.println("remote template " + remoteTemplate.getmRemoteTemplateID() + + " already exists in remote template table"); + } else { + // this remote template does not exist in template list, insert it + System.out.println("remote template " + remoteTemplate.getmRemoteTemplateID() + + " does not exist in key template table, add it"); + + String keys = ""; + List keysList = remoteTemplate.getmKeyInstanceList(); + + // sort key template list by key ID + Collections.sort(keysList, new SortByKeyID()); + for (int i = 0; i < keysList.size(); i++) { + KeyTemplate key = keysList.get(i); + + if (i != keysList.size() - 1) { + keys += key.getmKeyID() + ", "; + } else { + keys += key.getmKeyID(); + } + } + + String innerSqlString = "INSERT INTO remote_template(remote_template_id, frequency," + + " remote_template_type, related_keys) " + + "VALUES (?, ?, ?, ?);"; + PreparedStatement innerStatement = (PreparedStatement) mConnection.prepareStatement(innerSqlString); + innerStatement.setInt(1, remoteTemplate.getmRemoteTemplateID()); + innerStatement.setInt(2, remoteTemplate.getmFrequency()); + innerStatement.setInt(3, remoteTemplate.getmType()); + innerStatement.setString(4, keys); + + innerStatement.executeUpdate(); + ResultSet innerResultSet = (ResultSet) innerStatement.getGeneratedKeys(); + if (innerResultSet.next()) { + Long gk = (Long) innerResultSet.getObject(1); + insertRemoteTemplateCount++; + } + } + } + + System.out.println(mRemoteTemplateList.size() + " remote indexes have been parsed, " + + insertRemoteTemplateCount + " have been added"); + + // build up brand-category relationship according to IPTV list + int insertedIPTVBrands = 0; + for (IPTV iptv : mIPTVList) { + int kookongBrandID = iptv.getmKookongBrandID(); + Brand brand = getKookongBrandByKookongBrandID(kookongBrandID); + String sqlString = "SELECT * FROM brand WHERE brand_id = " + + "'" + iptv.getmKookongBrandID() + "' AND category_id = 5"; + PreparedStatement statement = (PreparedStatement) mConnection.prepareStatement(sqlString); + ResultSet resultSet = (ResultSet) statement.executeQuery(); + if(resultSet.next()) { + // this brand for IPTV already exists in brand list, do nothing + System.out.println("brand " + iptv.getmKookongBrandID() + ", " + + brand.getmBrandName() + " already exists in brand table"); + } else { + String innerSqlString = "INSERT INTO brand (brand_id, name, category_id, " + + "category_name, status, create_time, priority) VALUES (?, ?, ?, ?, ?, ?, ?);"; + PreparedStatement innerStatement = + (PreparedStatement) mConnection.prepareStatement(innerSqlString); + innerStatement.setInt(1, kookongBrandID); + innerStatement.setString(2, brand.getmBrandName()); + innerStatement.setInt(3, 5); + innerStatement.setString(4, "IPTV"); + innerStatement.setInt(5, 1); + innerStatement.setString(6, "2016-07-26 17:00:00"); + innerStatement.setInt(7, (insertedIPTVBrands + 1) * 10); + + innerStatement.executeUpdate(); + ResultSet innerResultSet = (ResultSet) innerStatement.getGeneratedKeys(); + if (innerResultSet.next()) { + Long gk = (Long) innerResultSet.getObject(1); + insertedIPTVBrands++; + } + } + } + System.out.println(insertedIPTVBrands + " have been added for category : IPTV"); + + // build up brand-category relationship according to brand list and brand-remote-rel list + // for each category + for (Category category: mCategoryList) { + if (1 == category.getmKookongCategoryID()) { + // skip IPTV since the brand-category relationship does not come from brand-remote-rel xml + continue; + } + // reset inserted brand count to 0 + int insertBrandCount = 0; + for (BrandRemoteRel brandRemoteRel : mBrandRemoteRelList) { + + // count on this relationship item only if the category matched the current category + if (brandRemoteRel.getmKookongCategoryID() == category.getmKookongCategoryID()) { + Brand brand = getKookongBrandByKookongBrandID(brandRemoteRel.getmKookongBrandID()); + + if (false == isInCategoryBrandRel(brandRemoteRel.getmKookongCategoryID(), + brandRemoteRel.getmKookongBrandID())) { + + // count this brand only if it hasn't been counted yet + int uconCategoryID = getUCONCategoryIDFromCategory(category.getmKookongCategoryID()); + String uconCategoryName = getUCONCategoryNameFromCategory(category.getmKookongCategoryID()); + System.out.println(uconCategoryID + ", " + uconCategoryName + ", " + + brand.getmBrandName() + ", rank = " + brandRemoteRel.getmPriority()); + + // insert this brand into brand table + String sqlString = "SELECT * FROM brand WHERE brand_id = " + + "'" + brand.getmKookongBrandID() + "' AND category_id = '" + uconCategoryID + "';"; + PreparedStatement statement = (PreparedStatement) mConnection.prepareStatement(sqlString); + ResultSet resultSet = (ResultSet) statement.executeQuery(); + if(resultSet.next()) { + // this brand already exists in brand list, do nothing + System.out.println("brand " + brand.getmKookongBrandID() + ", " + + brand.getmBrandName() + " already exists in brand table"); + } else { + // this brand does not exist in brand list, insert it + System.out.println("brand " + brand.getmKookongBrandID() + ", " + + brand.getmBrandName() + " does not exist in key brand table, add it"); + + String innerSqlString = "INSERT INTO brand (brand_id, name, category_id, " + + "category_name, status, create_time, priority) VALUES (?, ?, ?, ?, ?, ?, ?);"; + + PreparedStatement innerStatement = + (PreparedStatement) mConnection.prepareStatement(innerSqlString); + innerStatement.setInt(1, brand.getmKookongBrandID()); + innerStatement.setString(2, brand.getmBrandName()); + innerStatement.setInt(3, uconCategoryID); + innerStatement.setString(4, uconCategoryName); + innerStatement.setInt(5, 1); + innerStatement.setString(6, "2016-07-26 17:00:00"); + innerStatement.setInt(7, brandRemoteRel.getmPriority()); + + innerStatement.executeUpdate(); + ResultSet innerResultSet = (ResultSet) innerStatement.getGeneratedKeys(); + if (innerResultSet.next()) { + Long gk = (Long) innerResultSet.getObject(1); + insertBrandCount++; + } + insertBrandCount++; + } + mCategoryBrandReList.add(new CategoryBrandRel(brandRemoteRel.getmKookongCategoryID(), + brandRemoteRel.getmKookongBrandID())); + } + } + } + System.out.println(insertBrandCount + " have been added for category : " + category.getmCategoryName()); + } + + // build up remote index for STB according to city relationship + int insertStbRemoteIndexCount = 0; + for (SPStbRel spStbRel : mOperatorStbRelList) { + int categoryID = 3; + String categoryName = "机顶盒"; + String cityCode = spStbRel.getmCityCode(); + String cityName = ""; + + String outerSqlString = "SELECT name FROM city WHERE code = '" + cityCode + "';"; + PreparedStatement outerStatement = (PreparedStatement) mConnection.prepareStatement(outerSqlString); + ResultSet outerResultSet = (ResultSet) outerStatement.executeQuery(); + if(outerResultSet.next()) { + cityName = outerResultSet.getString("name"); + } + + int operatorID = spStbRel.getmOperatorID(); + String operatorName = ""; + outerSqlString = "SELECT operator_name FROM stb_operator WHERE operator_id = '" + operatorID + "';"; + outerStatement = (PreparedStatement) mConnection.prepareStatement(outerSqlString); + outerResultSet = (ResultSet) outerStatement.executeQuery(); + if(outerResultSet.next()) { + operatorName = outerResultSet.getString("operator_name"); + } + + int remoteTemplateID = spStbRel.getmKookongRemoteID(); + int radioType = 0; + int status = 1; + int priority = spStbRel.getmPriority(); + String appliedVersion = "V0.0.0"; + String bannedVersion = "V99.0.0"; + String inputSource = "CodeRobot_V1.0@ucon"; + + String sqlString = "SELECT * FROM remote_index WHERE category_id = 3 AND city_code = '" + cityCode + + "' AND operator_id = '" + operatorID + "' AND remote_template_id = '" + remoteTemplateID + "';"; + PreparedStatement statement = (PreparedStatement) mConnection.prepareStatement(sqlString); + ResultSet resultSet = (ResultSet) statement.executeQuery(); + if(resultSet.next()) { + // this stb remote index already exists, do nothing + System.out.println("stb remote index " + cityName + ", " + + operatorName + ", " + remoteTemplateID + " already exists"); + } else { + System.out.println("stb remote index " + cityName + ", " + + operatorName + ", " + remoteTemplateID + " does not exist, add it"); + String innerSqlString = "INSERT INTO remote_index(category_id, category_name, " + + "city_code, city_name, operator_id, operator_name, remote_template_id, " + + "radio_type, status, priority, applied_version, banned_version, input_source, update_time) VALUES" + + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; + PreparedStatement innerStatement = (PreparedStatement) mConnection.prepareStatement(innerSqlString); + innerStatement.setInt(1, categoryID); + innerStatement.setString(2, categoryName); + innerStatement.setString(3, cityCode); + innerStatement.setString(4, cityName); + innerStatement.setInt(5, operatorID); + innerStatement.setString(6, operatorName); + innerStatement.setInt(7, remoteTemplateID); + innerStatement.setInt(8, radioType); + innerStatement.setInt(9, status); + innerStatement.setInt(10, priority); + innerStatement.setString(11, appliedVersion); + innerStatement.setString(12, bannedVersion); + innerStatement.setString(13, inputSource); + innerStatement.setString(14, "2016-07-28 18:30:00"); + + innerStatement.executeUpdate(); + + ResultSet innerResultSet = (ResultSet) innerStatement.getGeneratedKeys(); + if (innerResultSet.next()) { + Long gk = (Long) innerResultSet.getObject(1); + insertStbRemoteIndexCount++; + } + } + } + + System.out.println(insertStbRemoteIndexCount + " stb remote index items have been added"); + + // build up remote index for IPTV according to IPTV list + for (IPTV iptv : mIPTVList) { + int categoryID = 5; + String categoryName = "IPTV"; + int kookongBrandID = iptv.getmKookongBrandID(); + String brandName = ""; + int brandID = 0; + + // NOTE: brandID in brand table indicates the id of 3rd party brand + String outerSqlString = "SELECT id, name FROM brand WHERE brand_id = '" + kookongBrandID + "' " + + "AND category_id = '" + categoryID + "';"; + PreparedStatement outerStatement = (PreparedStatement)mConnection.prepareStatement(outerSqlString); + ResultSet outerResultSet = (ResultSet) outerStatement.executeQuery(); + if (outerResultSet.next()) { + brandID = outerResultSet.getInt("id"); + brandName = outerResultSet.getString("name"); + } + + List remoteIDList = iptv.getmRemoteIDList(); + + int remoteIndexCountForIPTVperBrand = 0; + for (Integer i : remoteIDList) { + int remoteTemplateID = i; + int radioType = 0; + int status = 1; + int priority = (remoteIndexCountForIPTVperBrand + 1) * 10; + String appliedVersion = "V0.0.0"; + String bannedVersion = "V99.0.0"; + String inputSource = "CodeRobot_V1.0@ucon"; + + // NOTE: brandID in remote_index table indicates the id of UCON brand + String sqlString = "SELECT * FROM remote_index WHERE category_id = 5 AND brand_id = '" + brandID + + "' AND remote_template_id = '" + remoteTemplateID + "';"; + PreparedStatement statement = (PreparedStatement) mConnection.prepareStatement(sqlString); + ResultSet resultSet = (ResultSet) statement.executeQuery(); + if(resultSet.next()) { + // this iptv remote index already exists, do nothing + System.out.println("iptv remote index " + brandName + ", " + + remoteTemplateID + " already exists"); + } else { + System.out.println("iptv remote index " + brandName + ", " + + remoteTemplateID + " does not exist, add it"); + String innerSqlString = "INSERT INTO remote_index(category_id, category_name, " + + "brand_id, brand_name, remote_template_id, " + + "radio_type, status, priority, applied_version, banned_version, input_source, update_time) VALUES" + + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; + PreparedStatement innerStatement = + (PreparedStatement) mConnection.prepareStatement(innerSqlString); + innerStatement.setInt(1, categoryID); + innerStatement.setString(2, categoryName); + innerStatement.setInt(3, brandID); + innerStatement.setString(4, brandName); + innerStatement.setInt(5, remoteTemplateID); + innerStatement.setInt(6, radioType); + innerStatement.setInt(7, status); + innerStatement.setInt(8, priority); + innerStatement.setString(9, appliedVersion); + innerStatement.setString(10, bannedVersion); + innerStatement.setString(11, inputSource); + innerStatement.setString(12, "2016-07-28 18:30:00"); + + innerStatement.executeUpdate(); + + ResultSet innerResultSet = (ResultSet) innerStatement.getGeneratedKeys(); + if (innerResultSet.next()) { + Long gk = (Long) innerResultSet.getObject(1); + remoteIndexCountForIPTVperBrand++; + } + } + } + } + System.out.println(insertStbRemoteIndexCount + " iptv remote index items have been added"); + + // build up remote index for devices of other types according to previous parsed lists + + // prepare valid AC list + getACBinFiles(acBinFileBasePath); + int []mValidACIDList = new int[mACBinFileList.size()]; + for(int i = 0; i < mACBinFileList.size(); i++) { + String fileName = mACBinFileList.get(i); + mValidACIDList[i] = Integer.parseInt(fileName.substring(12, fileName.indexOf('.'))); + System.out.println("add index " + mValidACIDList[i] + " in list"); + } + + System.out.println("added " + mACBinFileList.size() + " valid AC remote in total"); + + // ready to process data + int insertRemoteIndexCount = 0; + for (BrandRemoteRel brandRemoteRel : mBrandRemoteRelList) { + int kookongCategoryID = brandRemoteRel.getmKookongCategoryID(); + if (0 == kookongCategoryID || 1 == kookongCategoryID) { + System.out.println("this category belongs to " + kookongCategoryID + " skip it"); + continue; + } + int remoteTemplateID = brandRemoteRel.getmKookongRemoteID(); + if (5 == kookongCategoryID) { + if (false == isInIntArray(mValidACIDList, remoteTemplateID, mValidACIDList.length)) { + System.out.println("This AC is invalid for UCON : " + remoteTemplateID); + continue; + } + } + int categoryID = getUCONCategoryIDFromCategory(kookongCategoryID); + String categoryName = getUCONCategoryNameFromCategory(kookongCategoryID); + int kookongBrandID = brandRemoteRel.getmKookongBrandID(); + String brandName = ""; + int brandID = 0; + + // NOTE: brandID in brand table indicates the id of 3rd party brand + String outerSqlString = "SELECT id, name FROM brand WHERE brand_id = '" + kookongBrandID + "' " + + "AND category_id = '" + categoryID + "';"; + PreparedStatement outerStatement = (PreparedStatement)mConnection.prepareStatement(outerSqlString); + ResultSet outerResultSet = (ResultSet) outerStatement.executeQuery(); + if (outerResultSet.next()) { + brandID = outerResultSet.getInt("id"); + brandName = outerResultSet.getString("name"); + } + int radioType = 0; + int status = 1; + int priority = brandRemoteRel.getmPriority(); + String appliedVersion = "V0.0.0"; + String bannedVersion = "V99.0.0"; + String inputSource = "CodeRobot_V1.0@ucon"; + + // NOTE: brandID in remote_index table indicates the id of UCON brand + String sqlString = "SELECT * FROM remote_index WHERE category_id = '" + categoryID +"'" + + " AND brand_id = '" + brandID + "' AND remote_template_id = '" + remoteTemplateID + "';"; + PreparedStatement statement = (PreparedStatement) mConnection.prepareStatement(sqlString); + ResultSet resultSet = (ResultSet) statement.executeQuery(); + if(resultSet.next()) { + // this remote index already exists, do nothing + System.out.println("remote index " + brandName + ", " + + remoteTemplateID + " already exists"); + } else { + System.out.println("remote index " + brandName + ", " + + remoteTemplateID + " does not exist, add it"); + String innerSqlString = "INSERT INTO remote_index(category_id, category_name, " + + "brand_id, brand_name, remote_template_id, " + + "radio_type, status, priority, applied_version, banned_version, input_source, update_time) VALUES" + + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"; + PreparedStatement innerStatement = + (PreparedStatement) mConnection.prepareStatement(innerSqlString); + innerStatement.setInt(1, categoryID); + innerStatement.setString(2, categoryName); + innerStatement.setInt(3, brandID); + innerStatement.setString(4, brandName); + innerStatement.setInt(5, remoteTemplateID); + innerStatement.setInt(6, radioType); + innerStatement.setInt(7, status); + innerStatement.setInt(8, priority); + innerStatement.setString(9, appliedVersion); + innerStatement.setString(10, bannedVersion); + innerStatement.setString(11, inputSource); + innerStatement.setString(12, "2016-07-28 18:30:00"); + + innerStatement.executeUpdate(); + + ResultSet innerResultSet = (ResultSet) innerStatement.getGeneratedKeys(); + if (innerResultSet.next()) { + Long gk = (Long) innerResultSet.getObject(1); + insertRemoteIndexCount++; + } + } + } + System.out.println(insertRemoteIndexCount + " remote indexes other than STB and IPTV are added"); + + ////////// step 13 - verify remote index tree ////////// + String categorySqlString = "SELECT id, name FROM category;"; + PreparedStatement categoryStatement = (PreparedStatement) mConnection.prepareStatement(categorySqlString); + ResultSet categoryResultSet = (ResultSet) categoryStatement.executeQuery(); + while (categoryResultSet.next()) { + int categoryID = categoryResultSet.getInt("id"); + String categoryName = categoryResultSet.getString("name"); + System.out.println("verifying category of " + categoryName); + if (3 != categoryID) { + String brandSqlString = "SELECT id, name FROM brand WHERE category_id = '" + categoryID + "';"; + PreparedStatement brandStatement = (PreparedStatement) mConnection.prepareStatement(brandSqlString); + ResultSet brandResultSet = (ResultSet) brandStatement.executeQuery(); + while (brandResultSet.next()) { + int brandID = brandResultSet.getInt("id"); + String brandName = brandResultSet.getString("name"); + + String remoteIndexSqlString = "SELECT id, remote_template_id FROM remote_index WHERE brand_id = '" + + brandID + "';"; + PreparedStatement remoteIndexStatement = + (PreparedStatement) mConnection.prepareStatement(remoteIndexSqlString); + ResultSet remoteIndexResultSet = (ResultSet) remoteIndexStatement.executeQuery(); + int remoteIndexCountPerBrand = 0; + while (remoteIndexResultSet.next()) { + int remoteIndexID = remoteIndexResultSet.getInt("id"); + int remoteTemplateID = remoteIndexResultSet.getInt("remote_template_id"); + String remoteTemplateSqlString = "SELECT * FROM remote_template WHERE " + + "remote_template_id = '" + remoteTemplateID + "';"; + + PreparedStatement remoteTemplateStatement = + (PreparedStatement) mConnection.prepareStatement(remoteTemplateSqlString); + + ResultSet remoteTemplateResultSet = (ResultSet) remoteTemplateStatement.executeQuery(); + + if (1 == categoryID) { + remoteIndexCountPerBrand++; + } else { + if (remoteTemplateResultSet.next()) { + remoteIndexCountPerBrand++; + } else { + System.out.println("remote index " + remoteIndexID + " does not have any matched " + + "template"); + } + } + } + if (0 == remoteIndexCountPerBrand) { + System.out.println("brand " + brandID + ", " + brandName + " does not have any matched " + + "remote index"); + } else { + System.out.println("brand " + brandID + ", " + brandName + " has " + + remoteIndexCountPerBrand + " valid remote indexes"); + } + } + } else { + String citySqlString = "SELECT code, name FROM city WHERE code LIKE '____00' AND code NOT LIKE " + + " '__0000'"; + PreparedStatement cityStatement = (PreparedStatement) mConnection.prepareStatement(citySqlString); + ResultSet cityResultSet = (ResultSet) cityStatement.executeQuery(); + while (cityResultSet.next()) { + String cityCode = cityResultSet.getString("code"); + String cityName = cityResultSet.getString("name"); + + List operatorIDList = new ArrayList(); + String operatorSqlString = "SELECT operator_id, operator_name FROM stb_operator WHERE " + + "city_code = '" + cityCode + "'"; + PreparedStatement operatorStatement = + (PreparedStatement) mConnection.prepareStatement(operatorSqlString); + ResultSet operatorResultSet = (ResultSet) operatorStatement.executeQuery(); + while(operatorResultSet.next()) { + String operatorID = operatorResultSet.getString("operator_id"); + String operatorName = operatorResultSet.getString("operator_name"); + operatorIDList.add(operatorID); + } + if (0 == operatorIDList.size()) { + System.out.println("city " + cityName + " does not have any STB operator"); + } + + String remoteIndexSqlString = "SELECT id, remote_template_id, operator_id FROM remote_index " + + "WHERE city_code = '" + cityCode + "';"; + PreparedStatement remoteIndexStatement = + (PreparedStatement) mConnection.prepareStatement(remoteIndexSqlString); + ResultSet remoteIndexResultSet = (ResultSet) remoteIndexStatement.executeQuery(); + int remoteIndexCountPerCity = 0; + while (remoteIndexResultSet.next()) { + int remoteIndexID = remoteIndexResultSet.getInt("id"); + int remoteTemplateID = remoteIndexResultSet.getInt("remote_template_id"); + String operatorID = remoteIndexResultSet.getString("operator_id"); + + // validate remote index - stb_operator relationship + if (null == operatorID || + operatorID.equals("") || + false == validateOperator(operatorIDList, operatorID)) { + System.out.println("this remote index does not match any stb operators " + + remoteIndexID); + } + + String remoteTemplateSqlString = "SELECT * FROM remote_template WHERE " + + "remote_template_id = '" + remoteTemplateID + "';"; + + PreparedStatement remoteTemplateStatement = + (PreparedStatement) mConnection.prepareStatement(remoteTemplateSqlString); + + ResultSet remoteTemplateResultSet = (ResultSet) remoteTemplateStatement.executeQuery(); + + if (remoteTemplateResultSet.next()) { + remoteIndexCountPerCity++; + } else { + System.out.println("remote index " + remoteIndexID + " does not have any matched " + + "template"); + } + } + if (0 == remoteIndexCountPerCity) { + System.out.println("city " + cityCode + ", " + cityName + " does not have any matched " + + "remote index"); + } else { + System.out.println("brand " + cityCode + ", " + cityName + " has " + + remoteIndexCountPerCity + " valid remote indexes"); + } + } + } + System.out.println("===== verify category done ====="); + } + + ////////// step 14 (optional) - analyze covered key code for each category ////////// + for (int categoryID = 0; categoryID <= 10; categoryID++) { + if (categoryID == 5) { + continue; + } + clearKeyHits(); + int remoteIndexCount = 0; + for (RemoteTemplate remoteTemplate : mRemoteTemplateList) { + // traverse remote index category by category + if (categoryID == getCategoryOfRemoteIndex(remoteTemplate.getmRemoteTemplateID())) { + List keyInstanceList = remoteTemplate.getmKeyInstanceList(); + for (KeyTemplate ki : keyInstanceList) { + // System.out.println("count key hit of key " + ki.getmKeyID()); + countKeyHits(ki.getmKeyID()); + } + remoteIndexCount++; + } + } + System.out.println(remoteIndexCount + " remote index found by category " + + getUCONCategoryNameFromCategory(categoryID)); + + // have some debug on key hits + for (KeyTemplate keyTemplate : mKeyTemplateList) { + if (keyTemplate.getmKeyHit() > 0) { + System.out.println("key : " + keyTemplate.getmKeyID() + ", " + keyTemplate.getmKeyName() + ", " + + keyTemplate.getmKeyDisplayName() + " HITS = " + keyTemplate.getmKeyHit()); + } + } + System.out.println("======================================"); + } + + System.out.println("==================================== All done ! ===================================="); + + } catch (Exception e) { + e.printStackTrace(); + } + + return true; + } + + // utils + private int getCategoryOfRemoteIndex(int remoteIndexID) { + if (null != mBrandRemoteRelList) { + for (BrandRemoteRel brr : mBrandRemoteRelList) { + if (remoteIndexID == brr.getmKookongRemoteID()) { + return brr.getmKookongCategoryID(); + } + } + } + return 0; + } + + private void clearKeyHits() { + if (null != mKeyTemplateList) { + for (KeyTemplate kt : mKeyTemplateList) { + kt.clearKeyHit(); + } + } + } + + private void countKeyHits(int keyID) { + if (null != mKeyTemplateList) { + for (KeyTemplate kt : mKeyTemplateList) { + if (kt.getmKeyID() == keyID) { + kt.countKeyHit(); + } + } + } + } + + private Category findParentCategoryForBrand(int brandID) { + if (null != mBrandRemoteRelList) { + for (BrandRemoteRel brandRemoteRel : mBrandRemoteRelList) { + if (brandRemoteRel.getmKookongBrandID() == brandID) { + Category category = new Category(); + category.setmCategoryName(brandRemoteRel.getmCategoryName()); + } + } + } + return null; + } + + private Brand getKookongBrandByKookongBrandID(int kookongBrandID) { + if (null != mBrandList) { + for (Brand brand : mBrandList) { + if (brand.getmKookongBrandID() == kookongBrandID) { + return brand; + } + } + } + return null; + } + + private City getCityFromCityCode(String cityCode) { + if (null != mCityList) { + for (City city : mCityList) { + if (city.getmCityCode().equals(cityCode)) { + return city; + } + } + } + return null; + } + + private Operator getOperatorFromOperatorID(String operatorID) { + if (null != mOperatorList) { + for (Operator operator : mOperatorList) { + if (operator.getmKookongOperatorID().equals(operatorID)) { + return operator; + } + } + } + return null; + } + + private boolean isInCategoryBrandRel(int kookongCategoryID, int kookongBrandID) { + if (null != mCategoryBrandReList) { + for (CategoryBrandRel categoryBrandRel : mCategoryBrandReList) { + if (categoryBrandRel.getKookongBrandID() == kookongBrandID && + categoryBrandRel.getKookongCategoryID() == kookongCategoryID) { + return true; + } + } + } + return false; + } + + private boolean validateOperator(List operatorList, String patten) { + for (String opStr : operatorList) { + if (opStr.equals(patten)) { + return true; + } + } + return false; + } + + private int getUCONCategoryIDFromCategory(int kookongCategoryID) { + return catetoryMapping[kookongCategoryID]; + } + + private String getUCONCategoryNameFromCategory(int kookongCategoryID) { + return categoryNameMapping[kookongCategoryID]; + } + + private void getACBinFiles(String filePath) { + File root = new File(filePath); + File[] files = root.listFiles(); + for (File file : files) { + if (!file.isDirectory() && file.getName().contains("ykir_new_ac")) { + mACBinFileList.add(file.getName()); + } + } + } + + private boolean isInIntArray(int []srcArray, int dest, int length) { + for(int i = 0; i < length; i++) { + if(srcArray[i] == dest) { + return true; + } + } + return false; + } + + // inner classes + // key sort comparator + private class SortByKeyID implements Comparator { + public int compare(Object o1, Object o2) { + KeyTemplate k1 = (KeyTemplate) o1; + KeyTemplate k2 = (KeyTemplate) o2; + return k1.getmKeyID() > k2.getmKeyID() ? 1 : 0; + } + } + + private class CategoryBrandRel { + + private int kookongCategoryID; + private int kookongBrandID; + + public CategoryBrandRel(int kookongCategoryID, int kookongBrandID) { + this.kookongCategoryID = kookongCategoryID; + this.kookongBrandID = kookongBrandID; + } + + public int getKookongCategoryID() { + return kookongCategoryID; + } + + public void setKookongCategoryID(int kookongCategoryID) { + this.kookongCategoryID = kookongCategoryID; + } + + public int getKookongBrandID() { + return kookongBrandID; + } + + public void setKookongBrandID(int kookongBrandID) { + this.kookongBrandID = kookongBrandID; + } + } +} diff --git a/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/utils/VeDate.java b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/utils/VeDate.java new file mode 100644 index 0000000..9be0110 --- /dev/null +++ b/src/ir_reverser/src/com/yuekong/sirius/ircoderobot/utils/VeDate.java @@ -0,0 +1,590 @@ +/** + * Created by Strawmanbobi on 2015-08-30. + */ + +package com.yuekong.sirius.ircoderobot.utils; + +import java.text.*; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.Random; + +public class VeDate { + + private static final int CAL_DAY_IN_MONTH = 42; + /** + * Get current time + * + * @return time in long format yyyy-MM-dd HH:mm:ss + */ + public static Date getNowDate() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateString = formatter.format(currentTime); + ParsePosition pos = new ParsePosition(8); + Date currentTime_2 = formatter.parse(dateString, pos); + return currentTime_2; + } + + /** + * Get current time + * + * @return time in short format yyyy-MM-dd HH:mm:ss + */ + public static Date getNowDateShort() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + String dateString = formatter.format(currentTime); + ParsePosition pos = new ParsePosition(8); + Date currentTime_2 = formatter.parse(dateString, pos); + return currentTime_2; + } + + /** + * Get current time + * + * @return time in string format + */ + public static String getStringDate() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateString = formatter.format(currentTime); + return dateString; + } + + /** + * Get current time + * + * @return time in string format + */ + public static String getStringDateShort() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + String dateString = formatter.format(currentTime); + return dateString; + } + + /** + * Get current time + * + * @return + */ + public static String getTimeShort() { + SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); + Date currentTime = new Date(); + String dateString = formatter.format(currentTime); + return dateString; + } + + /** + * Convert string format to long time format + * + * @param strDate + * @return + */ + public static Date strToDateLong(String strDate) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + ParsePosition pos = new ParsePosition(0); + Date strtodate = formatter.parse(strDate, pos); + return strtodate; + } + + /** + * Convert long time format to string format + * + * @param dateDate + * @return + */ + public static String dateToStrLong(Date dateDate) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateString = formatter.format(dateDate); + return dateString; + } + + /** + * Convert date format to string format + * + * @param dateDate + * @param k + * @return + */ + public static String dateToStr(Date dateDate) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + String dateString = formatter.format(dateDate); + return dateString; + } + + /** + * Convert string format to short time format + * + * @param strDate + * @return + */ + public static Date strToDate(String strDate) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + ParsePosition pos = new ParsePosition(0); + Date strtodate = formatter.parse(strDate, pos); + return strtodate; + } + + /** + * Get Now + * + * @return + */ + public static Date getNow() { + Date currentTime = new Date(); + return currentTime; + } + + /** + * Get last day of a month + * + * @param day + * @return + */ + public static Date getLastDate(long day) { + Date date = new Date(); + long date_3_hm = date.getTime() - 3600000 * 24 * day; + Date date_3_hm_date = new Date(date_3_hm); + return date_3_hm_date; + } + + /** + * Get current time + * + * @return time in format : yyyyMMdd HHmmss + */ + public static String getStringToday() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HHmmss"); + String dateString = formatter.format(currentTime); + return dateString; + } + + /** + * Get current hour + */ + public static String getHour() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateString = formatter.format(currentTime); + String hour; + hour = dateString.substring(11, 13); + return hour; + } + + /** + * Get current minute + * + * @return + */ + public static String getTime() { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String dateString = formatter.format(currentTime); + String min; + min = dateString.substring(14, 16); + return min; + } + + /** + * Get time format yyyyMMddhhmmss by user input + * + * @param sformat + * yyyyMMddhhmmss + * @return + */ + public static String getUserDate(String sformat) { + Date currentTime = new Date(); + SimpleDateFormat formatter = new SimpleDateFormat(sformat); + String dateString = formatter.format(currentTime); + return dateString; + } + + /** + * + */ + public static String getTwoHour(String st1, String st2) { + String[] kk = null; + String[] jj = null; + kk = st1.split(":"); + jj = st2.split(":"); + if (Integer.parseInt(kk[0]) < Integer.parseInt(jj[0])) + return "0"; + else { + double y = Double.parseDouble(kk[0]) + Double.parseDouble(kk[1]) + / 60; + double u = Double.parseDouble(jj[0]) + Double.parseDouble(jj[1]) + / 60; + if ((y - u) > 0) + return y - u + ""; + else + return "0"; + } + } + + /** + * + */ + public static String getTwoDay(String sj1, String sj2) { + SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd"); + long day = 0; + try { + Date date = myFormatter.parse(sj1); + Date mydate = myFormatter.parse(sj2); + day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000); + } catch (Exception e) { + return ""; + } + return day + ""; + } + + /** + * + */ + public static String getPreTime(String sj1, String jj) { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String mydate1 = ""; + try { + Date date1 = format.parse(sj1); + long Time = (date1.getTime() / 1000) + Integer.parseInt(jj) * 60; + date1.setTime(Time * 1000); + mydate1 = format.format(date1); + } catch (Exception e) { + } + return mydate1; + } + + /** + * + */ + public static String getNextDay(String nowdate, String delay) { + try { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + String mdate = ""; + Date d = strToDate(nowdate); + long myTime = (d.getTime() / 1000) + Integer.parseInt(delay) * 24 + * 60 * 60; + d.setTime(myTime * 1000); + mdate = format.format(d); + return mdate; + } catch (Exception e) { + return ""; + } + } + + /** + * + * + * @param ddate + * @return + */ + public static boolean isLeapYear(String ddate) { + Date d = strToDate(ddate); + GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance(); + gc.setTime(d); + int year = gc.get(Calendar.YEAR); + if ((year % 400) == 0) + return true; + else if ((year % 4) == 0) { + if ((year % 100) == 0) + return false; + else + return true; + } else + return false; + } + + /** + * + * + * @param str + * @return + */ + public static String getEDate(String str) { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + ParsePosition pos = new ParsePosition(0); + Date strtodate = formatter.parse(str, pos); + String j = strtodate.toString(); + String[] k = j.split(" "); + return k[2] + k[1].toUpperCase() + k[5].substring(2, 4); + } + + /** + * + * + * @param dat + * @return + */ + public static String getEndDateOfMonth(String dat) {// yyyy-MM-dd + String str = dat.substring(0, 8); + String month = dat.substring(5, 7); + int mon = Integer.parseInt(month); + if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 + || mon == 10 || mon == 12) { + str += "31"; + } else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) { + str += "30"; + } else { + if (isLeapYear(dat)) { + str += "29"; + } else { + str += "28"; + } + } + return str; + } + + /** + * + * + * @param date1 + * @param date2 + * @return + */ + public static boolean isSameWeekDates(Date date1, Date date2) { + Calendar cal1 = Calendar.getInstance(); + Calendar cal2 = Calendar.getInstance(); + cal1.setTime(date1); + cal2.setTime(date2); + int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR); + if (0 == subYear) { + if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2 + .get(Calendar.WEEK_OF_YEAR)) + return true; + } else if (1 == subYear && 11 == cal2.get(Calendar.MONTH)) { + if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2 + .get(Calendar.WEEK_OF_YEAR)) + return true; + } else if (-1 == subYear && 11 == cal1.get(Calendar.MONTH)) { + if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2 + .get(Calendar.WEEK_OF_YEAR)) + return true; + } + return false; + } + + /** + * + * + * @return + */ + public static String getSeqWeek() { + Calendar c = Calendar.getInstance(Locale.CHINA); + String week = Integer.toString(c.get(Calendar.WEEK_OF_YEAR)); + if (week.length() == 1) + week = "0" + week; + String year = Integer.toString(c.get(Calendar.YEAR)); + return year + week; + } + + /** + * + * + * @param sdate + * @param num + * @return + */ + public static String getWeek(String sdate, String num) { + Date dd = VeDate.strToDate(sdate); + Calendar c = Calendar.getInstance(); + c.setTime(dd); + if (num.equals("1")) + c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); + else if (num.equals("2")) + c.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY); + else if (num.equals("3")) + c.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY); + else if (num.equals("4")) + c.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY); + else if (num.equals("5")) + c.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); + else if (num.equals("6")) + c.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY); + else if (num.equals("0")) + c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); + return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime()); + } + + /** + * + * + * @param sdate + * @return + */ + public static String getWeek(String sdate) { + Date date = VeDate.strToDate(sdate); + Calendar c = Calendar.getInstance(); + c.setTime(date); + return new SimpleDateFormat("EEEE").format(c.getTime()); + } + + public static String getWeekStr(String sdate) { + String str = ""; + str = VeDate.getWeek(sdate); + if ("1".equals(str)) { + str = "星期日"; + } else if ("2".equals(str)) { + str = "星期一"; + } else if ("3".equals(str)) { + str = "星期二"; + } else if ("4".equals(str)) { + str = "星期三"; + } else if ("5".equals(str)) { + str = "星期四"; + } else if ("6".equals(str)) { + str = "星期五"; + } else if ("7".equals(str)) { + str = "星期六"; + } + return str; + } + + /** + * + * + * @param date1 + * @param date2 + * @return + */ + public static long getDays(String date1, String date2) { + if (date1 == null || date1.equals("")) + return 0; + if (date2 == null || date2.equals("")) + return 0; + SimpleDateFormat myFormatter = new SimpleDateFormat("yyyy-MM-dd"); + Date date = null; + Date mydate = null; + try { + date = myFormatter.parse(date1); + mydate = myFormatter.parse(date2); + } catch (Exception e) { + } + long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000); + return day; + } + + /** + * + * + * @param sdate + * @return + */ + public static String getNowMonth(String sdate) { + sdate = sdate.substring(0, 8) + "01"; + + Date date = VeDate.strToDate(sdate); + Calendar c = Calendar.getInstance(); + c.setTime(date); + int u = c.get(Calendar.DAY_OF_WEEK); + String newday = VeDate.getNextDay(sdate, (1 - u) + ""); + return newday; + } + + /* + * get the beginning date of a given month in calendar + */ + public static String getBeginDateinCal(String sdate) { + sdate = sdate.substring(0, 7) + "-01"; + Date date = VeDate.strToDate(sdate); + Calendar c = Calendar.getInstance(); + c.setTime(date); + int u = c.get(Calendar.DAY_OF_WEEK); + String newday = VeDate.getNextDay(sdate, (1 - u) + ""); + return newday; + } + + /* + * get the end date of a given month in calendar + */ + public static String getEndDateinCal(String sdate) { + sdate = sdate.substring(0, 7) + "-01"; + String edate = getEndDateOfMonth(sdate); + int dayOfMonth = getDayOfMonth(sdate); + + Date date = VeDate.strToDate(sdate); + Calendar c = Calendar.getInstance(); + c.setTime(date); + int u = c.get(Calendar.DAY_OF_WEEK); + int dayCountPrefix = u - 1; + + int dayCountSuffix = CAL_DAY_IN_MONTH - dayCountPrefix - dayOfMonth; + + String newday = VeDate.getNextDay(edate, dayCountSuffix + ""); + return newday; + } + + /** + * + * + * @param + */ + + public static String getNo(int k) { + + return getUserDate("yyyyMMddhhmmss") + getRandom(k); + } + + /** + * + * + * @param i + * @return + */ + public static String getRandom(int i) { + Random jjj = new Random(); + // int suiJiShu = jjj.nextInt(9); + if (i == 0) + return ""; + String jj = ""; + for (int k = 0; k < i; k++) { + jj = jj + jjj.nextInt(9); + } + return jj; + } + + /** + * + * @param + */ + public static boolean RightDate(String date) { + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + ; + if (date == null) + return false; + if (date.length() > 10) { + sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + } else { + sdf = new SimpleDateFormat("yyyy-MM-dd"); + } + try { + sdf.parse(date); + } catch (ParseException pe) { + return false; + } + return true; + } + /* + * get day of month for date string in format 'yyyy-MM-dd' + */ + public static int getDayOfMonth(String date) { + int mon = Integer.parseInt(date.substring(5, 7)); + if (mon == 1 || mon == 3 || mon == 5 || mon == 7 || mon == 8 + || mon == 10 || mon == 12) { + return 31; + } else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) { + return 30; + } else { + String comDate = date.substring(0, 7) + "-01"; + if (isLeapYear(comDate)) { + return 29; + } else { + return 28; + } + } + } +} diff --git a/src/ir_reverser/src/ire_test_main.c b/src/ir_reverser/src/ire_test_main.c deleted file mode 100644 index a78ffdb..0000000 --- a/src/ir_reverser/src/ire_test_main.c +++ /dev/null @@ -1,17 +0,0 @@ -/************************************************************************************** -Filename: -Revised: Date: 2017-01-09 -Revision: Revision: 1.0 - -Description: This file provides ir reverse test entry functions - -Revision log: -* 2017-01-09: created by strawmanbobi -**************************************************************************************/ - -#include - -int main() { - printf("Hello, World!\n"); - return 0; -} \ No newline at end of file