DataSenderService.java 150 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199
  1. package kr.co.icontrols.wallpadmulticontrolservice;
  2. import android.annotation.SuppressLint;
  3. import android.app.Service;
  4. import android.content.BroadcastReceiver;
  5. import android.content.Context;
  6. import android.content.Intent;
  7. import android.content.IntentFilter;
  8. import android.os.Handler;
  9. import android.os.IBinder;
  10. import android.os.Message;
  11. import android.util.Log;
  12. import com.artncore.WallPadDataMgr.WallpadDeviceSet;
  13. import com.artncore.WallPadDataMgr.WallpadStatusData;
  14. import com.artncore.WallPadDataMgr.wallpaddbmgr;
  15. import com.artncore.commons.API_Menu;
  16. import com.artncore.commons.DataClasses;
  17. import com.artncore.commons.KNX_DataClasses;
  18. import com.artncore.commons.define;
  19. import com.artncore.wallpadapi.CooktopAPI;
  20. import com.artncore.wallpadapi.EnergyMeterAPI;
  21. import com.artncore.wallpadapi.GasAPI;
  22. import com.artncore.wallpadapi.HeatingV2API;
  23. import com.artncore.wallpadapi.IGW300API;
  24. import com.artncore.wallpadapi.KnxAPI;
  25. import com.artncore.wallpadapi.KnxSystemAirconAPI;
  26. import com.artncore.wallpadapi.RealTimeMeterAPI;
  27. import com.artncore.wallpadapi.SdbAPI;
  28. import com.artncore.wallpadapi.Sdb_LivingRoomLightAPI;
  29. import com.artncore.wallpadapi.SystemAirconAPI;
  30. import com.artncore.wallpadapi.VentiAPI;
  31. import com.artncore.wallpadapi.WallPadAPI;
  32. import com.google.gson.Gson;
  33. import com.util.LogUtil;
  34. import org.json.JSONArray;
  35. import org.json.JSONException;
  36. import org.json.JSONObject;
  37. import java.io.ObjectInputStream;
  38. import java.io.ObjectOutputStream;
  39. import java.net.ServerSocket;
  40. import java.net.Socket;
  41. import java.sql.Timestamp;
  42. import java.text.SimpleDateFormat;
  43. import java.util.Random;
  44. import kr.co.icontrols.wallpadmulticontrolservice.control.AirconControl;
  45. import kr.co.icontrols.wallpadmulticontrolservice.control.HeatingControl;
  46. import kr.co.icontrols.wallpadmulticontrolservice.control.KnxAirconControl;
  47. import kr.co.icontrols.wallpadmulticontrolservice.control.LightControl;
  48. import kr.co.icontrols.wallpadmulticontrolservice.control.VentiControl;
  49. import kr.co.icontrols.wallpadmulticontrolservice.data.BasicData;
  50. import kr.co.icontrols.wallpadmulticontrolservice.data.RequestData;
  51. import kr.co.icontrols.wallpadmulticontrolservice.Common.JSON;
  52. import kr.co.icontrols.wallpadsupport.Version;
  53. import kr.co.icontrols.wallpadsupport.WpadSound;
  54. public class DataSenderService extends Service {
  55. String TAG = this.getClass().getSimpleName();
  56. private void DebugLogOutput(String s) {
  57. if (Common.DEBUG_LOG_ON) Log.d(TAG, s);
  58. }
  59. protected Context mContext = null;
  60. public Context getContext() {
  61. return mContext;
  62. }
  63. private WallPadAPI mWallPadAPI = null;
  64. private WallpadStatusData wdb = null;
  65. WallpadStatusData DBMGR = null;
  66. ServerThread thread;
  67. int roomNumber = 0;
  68. String myIP = "NONE";
  69. String myDong = "NONE";
  70. String myHo = "NONE";
  71. private final String JSON_SOURCE = "wallpad";
  72. public static final String SENSOR_BR_NAME = "kr.co.icontrols.wallpadmulticontrolservice.BR_IGW300_SENSOR_ALARM";
  73. // 제어 디바이스 드라이버 요청을 위한 BR 정의
  74. public static final class BrID {
  75. private final static String BR_ACTION_BASE = "kr.co.icontrols.wallpadmulticontrolservice.BR_";
  76. private final static int BASE = 9999;
  77. public final static String BR_LIVING_LIGHT = BR_ACTION_BASE + "LIVING_LIGHT_HDC" + "(" + BASE + ")";
  78. public final static String BR_ENERGY_METER = BR_ACTION_BASE + "ENERGY_METER_HDC" + "(" + BASE + ")";
  79. public final static String BR_BATCH_LIGHT = BR_ACTION_BASE + "BATCH_LIGHT_HDC" + "(" + BASE + ")";
  80. public final static String BR_GAS = BR_ACTION_BASE + "GAS_HDC" + "(" + BASE + ")";
  81. public final static String BR_VENTIL = BR_ACTION_BASE + "VENTIL_HDC" + "(" + BASE + ")";
  82. public final static String BR_HEATING = BR_ACTION_BASE + "HEATING_HDC" + "(" + BASE + ")";
  83. public final static String BR_AIRCON = BR_ACTION_BASE + "AIRCON_HDC" + "(" + BASE + ")";
  84. public final static String BR_SDB_LIVING_EVENT = BR_ACTION_BASE + "LIVING_SDB_HDC" + "(" + BASE + ")";
  85. public final static String BR_SDB_EVENT = BR_ACTION_BASE + "SDB_HDC" + "(" + BASE + ")";
  86. public final static String BR_KNX_EVENT = BR_ACTION_BASE + "KNX_HDC" + "(" + BASE + ")";
  87. }
  88. public static boolean bDeviceInitComplete = false; // 월패드 제어기기들의 드라이버의 초기화가 완료된 상태 저장
  89. // 가스
  90. private GasAPI mGasAPI = null;
  91. private CooktopAPI cooktopAPI; // 쿡탑 API
  92. private CooktopAPI.Data mCookTopData = null;
  93. private int nGasCnt = 1;
  94. //최대 3대
  95. public byte[] haGasStatus = new byte[]{GasAPI.GASSTATUS.Close, GasAPI.GASSTATUS.Close, GasAPI.GASSTATUS.Close};
  96. // 환기
  97. private VentiAPI mVentiAPI = null;
  98. private VentiControl mVentiControl;
  99. public Ventilation mVentilation = new Ventilation();
  100. private VentilData mVentilData = null;
  101. private class VentilData {
  102. DataClasses.Venti VentilStatus;
  103. int Type; // 현산,LH,후드
  104. int[] TimerTable;
  105. public VentilData(int nType) {
  106. VentilStatus = new DataClasses.Venti();
  107. Type = nType;
  108. if (Type == API_Menu.SubMenuCtrl.ChangAir_LH) TimerTable = new int[]{0, 30, 60, 90};
  109. else TimerTable = new int[]{0, 10, 20, 30, 60, 120, 180, 240};
  110. }
  111. }
  112. public static class Ventilation {
  113. /**
  114. * ON/OFF 상태
  115. */
  116. public boolean OnOff;
  117. /**
  118. * 바람세기 상태
  119. */
  120. public byte Wind;
  121. }
  122. //난방
  123. private HeatingV2API mHeatingV2API = null;
  124. private Heating mHeating = new Heating();
  125. private HeatingControl mHeatingControl;
  126. public class Heating {
  127. public HeatingRoom[] eachRoom = new HeatingRoom[10];
  128. public Heating() {
  129. for (int i = 0; i < 10; i++) {
  130. eachRoom[i] = new HeatingRoom();
  131. }
  132. }
  133. }
  134. //에어컨
  135. private SystemAirconAPI mSystemAirconAPI;
  136. private AirconData mAirconData = new AirconData();
  137. private AirconControl mAirconControl;
  138. private class AirconData {
  139. private SystemAirconAPI.Data systemAircon;
  140. public AirconData() {
  141. systemAircon = new SystemAirconAPI.Data();
  142. }
  143. }
  144. //KNX 에어컨
  145. private KnxSystemAirconAPI mKnxSystemAirconAPI;
  146. private KnxAirconData mKnxAirconData = new KnxAirconData();
  147. private KnxAirconControl mKnxAirconControl;
  148. private class KnxAirconData {
  149. private KnxSystemAirconAPI.Data systemAircon;
  150. public KnxAirconData() {
  151. systemAircon = new KnxSystemAirconAPI.Data();
  152. }
  153. }
  154. //조명(KNX 분전반)
  155. private KnxAPI mKnxAPI = null;
  156. private LightControl mLightControl;
  157. private Data_KnxLiv mKnxData = null;
  158. /**
  159. * KNX 에너지미터 데이터
  160. **/
  161. private class Data_KnxLiv {
  162. /**
  163. * 침실에너지미터 개수
  164. */
  165. public byte BadRoom_Em_Count = 0;
  166. /**
  167. * [마스터 컨트롤러] 데이터
  168. */
  169. public KNX_DataClasses.MasterControllerClass MasterController = null;
  170. /**
  171. * [거실 에너지미터] 데이터
  172. */
  173. public KNX_DataClasses.EnergyMeterClass LivingRoom_EnergyMeter = null;
  174. /**
  175. * [침실 에너지미터] 데이터
  176. */
  177. public KNX_DataClasses.EnergyMeterClass[] BadRoom_EnergyMeter = null;
  178. /**
  179. * [조명 스위치] 데이터
  180. */
  181. public KNX_DataClasses.LightSwithcClass[] Light_Switch = null;
  182. boolean ControlType; //false:밝기, true:색상
  183. public Data_KnxLiv() {
  184. ControlType = false;
  185. MasterController = new KNX_DataClasses.MasterControllerClass();
  186. LivingRoom_EnergyMeter = new KNX_DataClasses.EnergyMeterClass();
  187. }
  188. }
  189. // 현산향 에너지미터 ( 각방 조명 , 콘센트 )
  190. private EnergyMeterAPI mEnergyMeterAPI = null;
  191. // 조그 월패드
  192. private Sdb_LivingRoomLightAPI mSdb_LivingRoomLightAPI; // 거실 조명
  193. private SdbAPI mSdbAPI; // 각방 조명/콘센트
  194. //센서 저장 값
  195. boolean bIn_Motion = false;
  196. boolean bOut_Motion = false;
  197. boolean bMagnetic_Motion = false;
  198. // 에너지 미터
  199. public EMeter mEMeter = null;
  200. public class EMeter {
  201. public EachRoom[] eachRoom = new EachRoom[6];
  202. public EMeter() {
  203. for (int i = 0; i < 2; i++)
  204. eachRoom[i] = new EachRoom();
  205. }
  206. }
  207. public class EachRoom {
  208. public boolean[] lampStatus = new boolean[]{false, false, false, false, false, false};
  209. public boolean[] concentStatus = new boolean[]{false, false, false, false};
  210. public boolean[] ConMode = new boolean[]{false, false, false, false};
  211. }
  212. // 에너지 미터의 조명/콘센트 값을 저장한다.
  213. public SDBEMInfo mSDBEMInfo = null;
  214. public class SDBEMInfo {
  215. int nEachRoomCnt = 6;
  216. public SpaceInfo LivingRoom;
  217. public SpaceInfo[] EachRoom = new SpaceInfo[nEachRoomCnt];
  218. public SDBEMInfo() {
  219. LivingRoom = new SpaceInfo();
  220. for (int i = 0; i < nEachRoomCnt; i++)
  221. EachRoom[i] = new SpaceInfo();
  222. }
  223. }
  224. public class SpaceInfo {
  225. public boolean[] Light_bOnOff = new boolean[]{false, false, false, false, false, false};
  226. public byte[] Light_hDim = new byte[]{(byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A};
  227. public byte[] Light_hColor = new byte[]{(byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A, (byte) 0x0A};
  228. public byte[] Outlet_hOnOff = new byte[]{DataClasses.MultiSwitch.OUTLET_STATUS.Off, DataClasses.MultiSwitch.OUTLET_STATUS.Off, DataClasses.MultiSwitch.OUTLET_STATUS.Off, DataClasses.MultiSwitch.OUTLET_STATUS.Off};
  229. public byte[] Outlet_hCutoff = new byte[]{DataClasses.MultiSwitch.OUTLET_MODE.Always, DataClasses.MultiSwitch.OUTLET_MODE.Always, DataClasses.MultiSwitch.OUTLET_MODE.Always, DataClasses.MultiSwitch.OUTLET_MODE.Always};
  230. }
  231. public static class HeatingRoom {
  232. public byte mode;
  233. public double curTemper;
  234. public double setTemper;
  235. }
  236. public DataSenderService() {
  237. }
  238. public static final String INTENT_ACTION = "com.icontrols.service.data.IDataSenderService";
  239. private static final int MSG_WORK = 1;
  240. @Override
  241. public IBinder onBind(Intent intent) {
  242. return null;
  243. }
  244. class ServerThread extends Thread {
  245. @Override
  246. public void run() {
  247. int port = 9998;
  248. try {
  249. ServerSocket server = new ServerSocket(port);
  250. Log.d("ServerThread", "서버가 실행됨.");
  251. while (true) {
  252. Socket socket = server.accept(); // server 대기상태. 클라이언트 접속 시 소켓 객체 리턴
  253. ObjectInputStream inputStream = new ObjectInputStream(socket.getInputStream()); // 들어오는 데이터 처리
  254. ObjectOutputStream outputStream = new ObjectOutputStream(socket.getOutputStream());
  255. String data = null;
  256. try {
  257. socket.setSoTimeout(5000);
  258. data = (String) inputStream.readObject();
  259. if (data == null) {
  260. inputStream.close();
  261. continue;
  262. }
  263. Log.d("ServerThread", "data=" + data);
  264. } catch (Exception e) {
  265. Log.d("ServerThread_error", "e : " + e);
  266. inputStream.close();
  267. continue;
  268. }
  269. Gson gson = new Gson();
  270. JSONObject allObject = null;
  271. BasicData basicData = null;
  272. try {
  273. allObject = new JSONObject(data);
  274. basicData = gson.fromJson(allObject.toString(), BasicData.class);
  275. } catch (JSONException e) {
  276. e.printStackTrace();
  277. } catch (Exception e) {
  278. e.printStackTrace();
  279. }
  280. if (data != null && !data.trim().equals("") && basicData.getType().equalsIgnoreCase("request") && basicData.getReason() == JSON.REASON.Control) {
  281. //제어 요청
  282. int result = controlRequest(allObject, basicData.getMenu(), basicData.getKind(), basicData.getPosition());
  283. String json = "";
  284. String resultStr = "ok";
  285. if (result == 0) {
  286. resultStr = "ok";
  287. } else if (result == -100) {
  288. resultStr = "service not supported";
  289. } else if (result == -2) {
  290. resultStr = "internal server error";
  291. } else if (result == -1000) {
  292. resultStr = "invalid syntax";
  293. } else if (result == -1111) {
  294. resultStr = "service not supported";
  295. }
  296. resultStr = "ok";
  297. // build jsonObject
  298. JSONObject jsonObject = new JSONObject();
  299. JSONObject dataJsonObject = new JSONObject();
  300. try {
  301. jsonObject.accumulate("type", "controlResponse");
  302. jsonObject.accumulate("timestamp", millToDate(System.currentTimeMillis()));
  303. jsonObject.accumulate("ip", myIP);
  304. jsonObject.accumulate("menu", basicData.getMenu());
  305. jsonObject.accumulate("result", resultStr);
  306. } catch (JSONException e) {
  307. resultStr = "invalid syntax";
  308. jsonObject.accumulate("result", resultStr);
  309. e.printStackTrace();
  310. }
  311. //jsonObject.accumulate("data", dataJsonObject);
  312. // convert JSONObject to JSON to String
  313. json = jsonObject.toString();
  314. outputStream.writeObject(json);
  315. outputStream.close();
  316. Log.d("ServerThread", "result 보냄 : " + result);
  317. } else if (data != null && !data.trim().equals("") && basicData.getType().equalsIgnoreCase("request") && basicData.getReason() == JSON.REASON.Status) {
  318. try {
  319. JSONObject result = updateRequest(basicData.getMenu(), basicData.getKind(), basicData.getPosition());
  320. Random rand = new Random();
  321. int iValue = rand.nextInt(4); // 0 <= iValue < 10
  322. int menu = basicData.getMenu();
  323. String sampleAirconResult = "{\"type\" : \"updateResponse\", " +
  324. "\"timestamp\" : \"2020-09-08T03:03:04\", " +
  325. "\"ip\" : \"52.33.222.11\", " +
  326. "\"menu\" : 1004, " +
  327. "\"aircon_status\" : 3, " +
  328. "\"support_auto\" : true, " +
  329. "\"support_cooling\" : true, " +
  330. "\"support_dehumidify\" : true, " +
  331. "\"support_fan\" : true, " +
  332. "\"support_heating\" : true, " +
  333. "\"data_array\" : [" +
  334. "{ \"roomNumber\" : 1, \"power\" : 1, \"mode\" : " + iValue + ", \"airvol\" : 1,\"setTemp\" : 10,\"nowTemp\" : 20 }," +
  335. "{ \"roomNumber\" : 2, \"power\" : 1, \"mode\" : " + iValue + ", \"airvol\" : 1,\"setTemp\" : 10,\"nowTemp\" : 20 }," +
  336. "{ \"roomNumber\" : 3, \"power\" : 2, \"mode\" : " + iValue + ", \"airvol\" : 1,\"setTemp\" : 10,\"nowTemp\" : 20 }," +
  337. "{ \"roomNumber\" : 4, \"power\" : 2, \"mode\" : " + iValue + ", \"airvol\" : 1,\"setTemp\" : 10,\"nowTemp\" : 20 } ]" +
  338. "}";
  339. iValue = rand.nextInt(30); // 0 <= iValue < 10
  340. String sampleHeatingResult = "{\"type\" : \"updateResponse\", " +
  341. "\"timestamp\" : \"2020-09-08T03:03:04\", " +
  342. "\"ip\" : \"52.33.222.11\", " +
  343. "\"menu\" : 1002, " +
  344. "\"support_setpoint05\" : true, " +
  345. "\"support_outing\" : true, " +
  346. "\"support_sleep\" : true, " +
  347. "\"support_reservation\" : true, " +
  348. "\"support_pause\" : true, " +
  349. "\"support_ai\" : true, " +
  350. "\"support_outsidetempuse\" : true, " +
  351. "\"support_boiler\" : true, " +
  352. "\"boiler_heatwater_temp\" : 60, " +
  353. "\"boiler_hotwater_temp\" : 50, " +
  354. "\"boiler_frost_protect\" : true, " +
  355. "\"boiler_error_code\" : 0, " +
  356. "\"data_array\" : [" +
  357. "{ \"roomNumber\" : 1, \"mode\" : " + 1 + ", \"setTemp\" : " + iValue + ",\"nowTemp\" : 20, \"reservationArray\" : [0,1,2,3,20], \"sleepTemp\" : 1, \"sleepTime\" : 1 }," +
  358. "{ \"roomNumber\" : 2, \"mode\" : " + 2 + ", \"setTemp\" : " + iValue + ",\"nowTemp\" : 21, \"reservationArray\" : [0,1,2,3,21], \"sleepTemp\" : 2, \"sleepTime\" : 2 }," +
  359. "{ \"roomNumber\" : 3, \"mode\" : " + 5 + ", \"setTemp\" : " + iValue + ",\"nowTemp\" : 22, \"reservationArray\" : [0,1,2,3,22], \"sleepTemp\" : 3, \"sleepTime\" : 3 }," +
  360. "{ \"roomNumber\" : 4, \"mode\" : " + 6 + ", \"setTemp\" : " + iValue + ",\"nowTemp\" : 23, \"reservationArray\" : [0,1,2,3,23], \"sleepTemp\" : 1, \"sleepTime\" : 4 } ]" +
  361. "}";
  362. iValue = rand.nextInt(2);
  363. boolean onoff = false;
  364. if (iValue == 1) onoff = true;
  365. String sampleLightResult;
  366. if (myIP.equals("10.1.1.2")) {
  367. sampleLightResult = "{\"type\" : \"updateResponse\", " +
  368. "\"timestamp\" : \"2020-09-08T03:03:04\", " +
  369. "\"ip\" : " + myIP + ", " +
  370. "\"menu\" : 1001, " +
  371. "\"master_info_fault\" : true, " +
  372. "\"master_data_batch\" : " + iValue + ", " +
  373. "\"master_info_liv_count\" : 1, " +
  374. "\"master_info_bad_count\" : 3, " +
  375. "\"master_info_switch_count\" : 3, " +
  376. "\"liv_info_install\" : true, " +
  377. "\"liv_info_lightcount\" : 2, " +
  378. "\"liv_data_array\" : [" +
  379. "{ \"info_install\" : true, \"info_type\" : 2, \"data_onoff\" : " + onoff + ", \"data_dimming\" : 1 }," +
  380. "{ \"info_install\" : true, \"info_type\" : 2, \"data_onoff\" : " + onoff + ", \"data_dimming\" : 1 } ]," +
  381. "\"bed_data_array\" : [" +
  382. "{ \"info_install\" : true, \"info_lightcount\" : 2, \"info_light_type1\" : 1,\"info_light_type2\" : 15,\"info_light_type3\" : 1,\"info_light_type4\" : 1,\"lightArray\" : [true, true] }," +
  383. "{ \"info_install\" : true, \"info_lightcount\" : 2, \"info_light_type1\" : 1,\"info_light_type2\" : 15,\"info_light_type3\" : 1,\"info_light_type4\" : 1,\"lightArray\" : [true, true] }," +
  384. "{ \"info_install\" : true, \"info_lightcount\" : 2, \"info_light_type1\" : 1,\"info_light_type2\" : 15,\"info_light_type3\" : 1,\"info_light_type4\" : 1,\"lightArray\" : [true, true] } ]," +
  385. "\"switch_data_array\" : [" +
  386. "{ \"info_install\" : true, \"info_lightcount\" : 2, \"info_light_type1\" : 1,\"info_light_type2\" : 14,\"info_light_type3\" : 1,\"info_light_type4\" : 1,\"switchArray\" : [true, true] }," +
  387. "{ \"info_install\" : true, \"info_lightcount\" : 2, \"info_light_type1\" : 1,\"info_light_type2\" : 14,\"info_light_type3\" : 1,\"info_light_type4\" : 1,\"switchArray\" : [true, true] }," +
  388. "{ \"info_install\" : true, \"info_lightcount\" : 2, \"info_light_type1\" : 1,\"info_light_type2\" : 15,\"info_light_type3\" : 1,\"info_light_type4\" : 1,\"switchArray\" : [true, true] } ]" +
  389. "}";
  390. } else {
  391. sampleLightResult = "{\"type\" : \"updateResponse\", " +
  392. "\"timestamp\" : \"2020-09-08T03:03:04\", " +
  393. "\"ip\" : " + myIP + ", " +
  394. "\"menu\" : 1001, " +
  395. "\"master_info_fault\" : true, " +
  396. "\"master_data_batch\" : " + iValue + ", " +
  397. "\"master_info_liv_count\" : 1, " +
  398. "\"master_info_bad_count\" : 2, " +
  399. "\"master_info_switch_count\" : 2, " +
  400. "\"liv_info_install\" : true, " +
  401. "\"liv_info_lightcount\" : 2, " +
  402. "\"liv_data_array\" : [" +
  403. "{ \"info_install\" : true, \"info_type\" : 2, \"data_onoff\" : " + onoff + ", \"data_dimming\" : 1 }," +
  404. "{ \"info_install\" : true, \"info_type\" : 2, \"data_onoff\" : " + onoff + ", \"data_dimming\" : 1 } ]," +
  405. "\"bed_data_array\" : [" +
  406. "{ \"info_install\" : true, \"info_lightcount\" : 2, \"info_light_type1\" : 1,\"info_light_type2\" : 15,\"info_light_type3\" : 1,\"info_light_type4\" : 1,\"lightArray\" : [true, true] }," +
  407. "{ \"info_install\" : true, \"info_lightcount\" : 2, \"info_light_type1\" : 1,\"info_light_type2\" : 15,\"info_light_type3\" : 1,\"info_light_type4\" : 1,\"lightArray\" : [true, true] } ]," +
  408. "\"switch_data_array\" : [" +
  409. "{ \"info_install\" : true, \"info_lightcount\" : 2, \"info_light_type1\" : 1,\"info_light_type2\" : 14,\"info_light_type3\" : 1,\"info_light_type4\" : 1,\"switchArray\" : [true, true] }," +
  410. "{ \"info_install\" : true, \"info_lightcount\" : 2, \"info_light_type1\" : 1,\"info_light_type2\" : 15,\"info_light_type3\" : 1,\"info_light_type4\" : 1,\"switchArray\" : [true, true] } ]" +
  411. "}";
  412. }
  413. iValue = rand.nextInt(2);
  414. String sampleCookTopResult = "{\"type\" : \"updateResponse\", " +
  415. "\"timestamp\" : \"2020-09-08T03:03:04\", " +
  416. "\"ip\" : \"52.33.222.11\", " +
  417. "\"menu\" : 1004, " +
  418. "\"device_count\" : 3, " +
  419. "\"data_array\" : [" +
  420. "{ \"hID\" : 1, \"hStatus\" : 3, \"hType\" : " + iValue + ", \"hErrorStatus\" : 0}," +
  421. "{ \"hID\" : 2, \"hStatus\" : 3, \"hType\" : " + iValue + ", \"hErrorStatus\" : 0}," +
  422. "{ \"hID\" : 3, \"hStatus\" : 2, \"hType\" : " + iValue + ", \"hErrorStatus\" : 0} ]" +
  423. "}";
  424. outputStream.writeObject(result.toString());
  425. String resultTemp;
  426. if (menu == 1003) resultTemp = sampleHeatingResult;
  427. else if (menu == 1001) resultTemp = sampleLightResult;
  428. else if (menu == 1006) resultTemp = sampleCookTopResult;
  429. else resultTemp = sampleAirconResult;
  430. //outputStream.writeObject(resultTemp);
  431. outputStream.close();
  432. Log.d("ServerThread", "result 보냄 : " + resultTemp);
  433. } catch (Exception e) {
  434. outputStream.close();
  435. e.printStackTrace();
  436. }
  437. } else if (data != null && !data.trim().equals("") && basicData.getType().equalsIgnoreCase("request") && basicData.getReason() == JSON.REASON.PassWordChange) {
  438. //제어 요청
  439. int result = passwordChangeRequest(basicData.getNumber());
  440. String json = "";
  441. String resultStr = "ok";
  442. if (result == 0) {
  443. resultStr = "ok";
  444. } else if (result == JSON.ERROR.Exception) {
  445. resultStr = "internal server error";
  446. }
  447. // build jsonObject
  448. JSONObject jsonObject = new JSONObject();
  449. try {
  450. jsonObject.accumulate("type", "controlResponse");
  451. jsonObject.accumulate("timestamp", millToDate(System.currentTimeMillis()));
  452. jsonObject.accumulate("ip", myIP);
  453. jsonObject.accumulate("menu", basicData.getMenu());
  454. jsonObject.accumulate("result", resultStr);
  455. } catch (JSONException e) {
  456. resultStr = "invalid syntax";
  457. jsonObject.accumulate("result", resultStr);
  458. e.printStackTrace();
  459. }
  460. json = jsonObject.toString();
  461. outputStream.writeObject(json);
  462. outputStream.close();
  463. Log.d("ServerThread", "result 보냄 : " + result);
  464. }
  465. inputStream.close();
  466. socket.close(); // 연결을 유지할 필요 없으면 끊어줌.
  467. }
  468. } catch (Exception e) {
  469. e.printStackTrace();
  470. }
  471. }
  472. }
  473. /**
  474. * 개별 에어컨 전원 제어 (개별 항목 제어)
  475. *
  476. * @return true: 성공, false: 실패
  477. */
  478. private int ctrlPowerToggle(byte roomIndex) {
  479. try {
  480. byte hPower = mAirconData.systemAircon.Device.Aircon[roomIndex].hPower;
  481. DebugLogOutput("[ctrlPowerToggle] Current hPower [" + hPower + "]");
  482. if (hPower == DataClasses.SystemAircon.POWER.On)
  483. hPower = DataClasses.SystemAircon.POWER.Off;
  484. else hPower = DataClasses.SystemAircon.POWER.On;
  485. int nResult = -100;
  486. if (mAirconData.systemAircon.Device.info.Support.bV2CMDUsage) {
  487. nResult = mAirconControl.ctrlUnitAirconPowerV2((byte) roomIndex, hPower);
  488. } else {
  489. byte hMode = mAirconData.systemAircon.Device.Aircon[roomIndex].hMode;
  490. byte hAirVol = mAirconData.systemAircon.Device.Aircon[roomIndex].hAirVol;
  491. byte hSetTemper = mAirconData.systemAircon.Device.Aircon[roomIndex].hSetTemper;
  492. boolean bAirSwing = mAirconData.systemAircon.Device.Aircon[roomIndex].bAirSwing;
  493. nResult = mAirconControl.ctrlUnitAircon((byte) roomIndex, hPower, hMode, hAirVol, hSetTemper, bAirSwing);
  494. }
  495. return nResult;
  496. } catch (RuntimeException re) {
  497. LogUtil.errorLogInfo("", TAG, re);
  498. return JSON.ERROR.RuntimeException;
  499. } catch (Exception e) {
  500. Log.e(TAG, "[Exception] ctrlPowerToggle()");
  501. LogUtil.errorLogInfo("", TAG, e);
  502. return JSON.ERROR.Exception;
  503. }
  504. }
  505. /**
  506. * 에어컨 전원 제어
  507. */
  508. private int ctrlPowerToggle() {
  509. try {
  510. int nResult = -100;
  511. boolean bCurrentAllOnOff = false;
  512. // 전체제어 영역 상태 갱신을 위해
  513. for (int i = 0; i < mAirconData.systemAircon.Device.info.hInsideAirconCnt; i++) {
  514. if (mAirconData.systemAircon.Device.Aircon[i].hPower == DataClasses.SystemAircon.POWER.On) {
  515. bCurrentAllOnOff = true;
  516. break;
  517. }
  518. }
  519. byte onoff = DataClasses.SystemAircon.POWER.On;
  520. if (bCurrentAllOnOff) {
  521. onoff = DataClasses.SystemAircon.POWER.Off;
  522. }
  523. if (mAirconData.systemAircon.Device.info.Support.bV2CMDUsage) {
  524. nResult = mAirconControl.ctrlEntireAirconPowerV2((byte) onoff);
  525. } else {
  526. nResult = mAirconControl.ctrlEntireAirconPower((byte) onoff);
  527. }
  528. return nResult;
  529. } catch (RuntimeException re) {
  530. LogUtil.errorLogInfo("", TAG, re);
  531. return JSON.ERROR.RuntimeException;
  532. } catch (Exception e) {
  533. Log.e(TAG, "[Exception] ctrlPowerToggle()");
  534. //e.printStackTrace();
  535. LogUtil.errorLogInfo("", TAG, e);
  536. return JSON.ERROR.Exception;
  537. }
  538. }
  539. /**
  540. * 개별 에어컨 운전모드 제어 (개별 항목 제어)
  541. */
  542. private int ctrlMode(byte roomIdx, byte hMode) {
  543. try {
  544. DebugLogOutput("[ctrlMode] hMode [" + hMode + "]");
  545. int nResult = -100;
  546. if (mAirconData.systemAircon.Device.info.Support.bV2CMDUsage) {
  547. nResult = mAirconControl.ctrlUnitAirconModeV2((byte) roomIdx, hMode);
  548. } else {
  549. byte hPower = mAirconData.systemAircon.Device.Aircon[roomIdx].hPower;
  550. byte hAirVol = mAirconData.systemAircon.Device.Aircon[roomIdx].hAirVol;
  551. byte hSetTemper = mAirconData.systemAircon.Device.Aircon[roomIdx].hSetTemper;
  552. boolean bAirSwing = mAirconData.systemAircon.Device.Aircon[roomIdx].bAirSwing;
  553. nResult = mAirconControl.ctrlUnitAircon((byte) roomIdx, hPower, hMode, hAirVol, hSetTemper, bAirSwing);
  554. }
  555. return nResult;
  556. } catch (RuntimeException re) {
  557. LogUtil.errorLogInfo("", TAG, re);
  558. return JSON.ERROR.RuntimeException;
  559. } catch (Exception e) {
  560. LogUtil.errorLogInfo("", TAG, e);
  561. return JSON.ERROR.Exception;
  562. }
  563. }
  564. /**
  565. * 전체 에어컨 운전모드 제어 (전체 항목 제어)
  566. */
  567. private int ctrlMode(byte hMode) {
  568. try {
  569. DebugLogOutput("[ctrlMode] hMode [" + hMode + "]");
  570. int nResult = -100;
  571. if (mAirconData.systemAircon.Device.info.Support.bV2CMDUsage) {
  572. nResult = mAirconControl.ctrlEntireAirconModeV2((byte) hMode);
  573. } else {
  574. nResult = mAirconControl.ctrlEntireAirconMode((byte) hMode);
  575. }
  576. return nResult;
  577. } catch (RuntimeException re) {
  578. LogUtil.errorLogInfo("", TAG, re);
  579. return JSON.ERROR.RuntimeException;
  580. } catch (Exception e) {
  581. LogUtil.errorLogInfo("", TAG, e);
  582. return JSON.ERROR.Exception;
  583. }
  584. }
  585. /**
  586. * 개별 에어컨 풍량 제어 (개별 항목 제어)
  587. */
  588. private int ctrlAirVol(byte roomIdx, byte hAirVol) {
  589. try {
  590. DebugLogOutput("[ctrlAirVol] hAirVol [" + hAirVol + "]");
  591. int nResult = -100;
  592. if (mAirconData.systemAircon.Device.info.Support.bV2CMDUsage) {
  593. nResult = mAirconControl.ctrlUnitAirconAirVolV2((byte) roomIdx, hAirVol);
  594. } else {
  595. byte hPower = mAirconData.systemAircon.Device.Aircon[roomIdx].hPower;
  596. byte hMode = mAirconData.systemAircon.Device.Aircon[roomIdx].hMode;
  597. byte hSetTemper = mAirconData.systemAircon.Device.Aircon[roomIdx].hSetTemper;
  598. boolean bAirSwing = mAirconData.systemAircon.Device.Aircon[roomIdx].bAirSwing;
  599. nResult = mAirconControl.ctrlUnitAircon((byte) roomIdx, hPower, hMode, hAirVol, hSetTemper, bAirSwing);
  600. }
  601. return nResult;
  602. } catch (RuntimeException re) {
  603. LogUtil.errorLogInfo("", TAG, re);
  604. return JSON.ERROR.RuntimeException;
  605. } catch (Exception e) {
  606. Log.e(TAG, "[Exception] ctrlAirVol(byte hAirVol)");
  607. LogUtil.errorLogInfo("", TAG, e);
  608. return JSON.ERROR.Exception;
  609. }
  610. }
  611. /**
  612. * 전체 에어컨 풍량 제어 (전체 항목 제어)
  613. */
  614. private int ctrlAirVol(byte hAirVol) {
  615. try {
  616. DebugLogOutput("[ctrlAirVol] hAirVol [" + hAirVol + "]");
  617. int nResult = -100;
  618. if (mAirconData.systemAircon.Device.info.Support.bV2CMDUsage) {
  619. nResult = mAirconControl.ctrlEntireAirconAirVolV2((byte) hAirVol);
  620. } else {
  621. nResult = mAirconControl.ctrlEntireAirconAirVol((byte) hAirVol);
  622. }
  623. return nResult;
  624. } catch (RuntimeException re) {
  625. LogUtil.errorLogInfo("", TAG, re);
  626. return JSON.ERROR.RuntimeException;
  627. } catch (Exception e) {
  628. Log.e(TAG, "[Exception] ctrlAirVol(byte hAirVol)");
  629. LogUtil.errorLogInfo("", TAG, e);
  630. return JSON.ERROR.Exception;
  631. }
  632. }
  633. /**
  634. * 풍량 데이터를 증가 또는 감소 시킨다.
  635. */
  636. private int ctrlAirVolUpDown(byte roomIndex, int bUp) {
  637. try {
  638. if (mAirconData == null) return JSON.ERROR.NotReady;
  639. if (mAirconData.systemAircon.Device.Aircon == null) return JSON.ERROR.NotReady;
  640. byte hAirVol = mAirconData.systemAircon.Device.Aircon[roomIndex].hAirVol;
  641. byte hMode = mAirconData.systemAircon.Device.Aircon[roomIndex].hMode;
  642. byte VolumeRange = 0x01;
  643. if (bUp == 1) {
  644. hAirVol += VolumeRange;
  645. //송풍인 경우와 이외의 경우의 풍량 모드가 다르다. (풍량 자동이 없음)
  646. if ((hAirVol > DataClasses.SystemAircon.AIRVOLUME.High) && !(hMode == DataClasses.SystemAircon.MODE.Fan))
  647. hAirVol = DataClasses.SystemAircon.AIRVOLUME.Auto;
  648. else if ((hAirVol > DataClasses.SystemAircon.AIRVOLUME.High) && (hMode == DataClasses.SystemAircon.MODE.Fan))
  649. hAirVol = DataClasses.SystemAircon.AIRVOLUME.Low;
  650. } else {
  651. hAirVol -= VolumeRange;
  652. //송풍인 경우와 이외의 경우의 풍량 모드가 다르다. (풍량 자동이 없음)
  653. if ((hAirVol < DataClasses.SystemAircon.AIRVOLUME.Auto) && !(hMode == DataClasses.SystemAircon.MODE.Fan))
  654. hAirVol = DataClasses.SystemAircon.AIRVOLUME.High;
  655. else if ((hAirVol < DataClasses.SystemAircon.AIRVOLUME.Low) && (hMode == DataClasses.SystemAircon.MODE.Fan))
  656. hAirVol = DataClasses.SystemAircon.AIRVOLUME.High;
  657. }
  658. return ctrlAirVol(roomIndex, hAirVol);
  659. } catch (RuntimeException re) {
  660. LogUtil.errorLogInfo("", TAG, re);
  661. return JSON.ERROR.RuntimeException;
  662. } catch (Exception e) {
  663. Log.e(TAG, "[Exception] ctrlAirVolUpDown(boolean bUp)");
  664. //e.printStackTrace();
  665. LogUtil.errorLogInfo("", TAG, e);
  666. return JSON.ERROR.Exception;
  667. }
  668. }
  669. /**
  670. * 개별 에어컨 풍량 제어 (개별 항목 제어)
  671. *
  672. * @return true: 성공, false: 실패
  673. */
  674. private int ctrlAirSwingToggle(byte roomIndex) {
  675. try {
  676. boolean bAirSwing = mAirconData.systemAircon.Device.Aircon[roomIndex].bAirSwing;
  677. DebugLogOutput("[ctrlAirSwingToggle] Current bAirSwing [" + bAirSwing + "]");
  678. int nResult = -100;
  679. if (mAirconData.systemAircon.Device.info.Support.bV2CMDUsage) {
  680. nResult = mAirconControl.ctrlUnitAirconAirSwingV2((byte) roomIndex, !bAirSwing);
  681. } else {
  682. byte hPower = mAirconData.systemAircon.Device.Aircon[roomIndex].hPower;
  683. byte hMode = mAirconData.systemAircon.Device.Aircon[roomIndex].hMode;
  684. byte hAirVol = mAirconData.systemAircon.Device.Aircon[roomIndex].hAirVol;
  685. byte hSetTemper = mAirconData.systemAircon.Device.Aircon[roomIndex].hSetTemper;
  686. nResult = mAirconControl.ctrlUnitAircon((byte) roomIndex, hPower, hMode, hAirVol, hSetTemper, !bAirSwing);
  687. }
  688. return nResult;
  689. } catch (RuntimeException re) {
  690. LogUtil.errorLogInfo("", TAG, re);
  691. return JSON.ERROR.RuntimeException;
  692. } catch (Exception e) {
  693. Log.e(TAG, "[Exception] ctrlAirSwingToggle()");
  694. //e.printStackTrace();
  695. LogUtil.errorLogInfo("", TAG, e);
  696. return JSON.ERROR.Exception;
  697. }
  698. }
  699. /**
  700. * 개별 에어컨 풍량 제어 (개별 항목 제어)
  701. *
  702. * @return true: 성공, false: 실패
  703. */
  704. private int ctrlSetTemper(byte roomIndex, byte hSetTemper) {
  705. try {
  706. DebugLogOutput("[ctrlSetTemper] hSetTemper [" + hSetTemper + "]");
  707. int nResult = -100;
  708. if (mAirconData.systemAircon.Device.info.Support.bV2CMDUsage) {
  709. nResult = mAirconControl.ctrlUnitAirconSetTemperV2((byte) roomIndex, hSetTemper);
  710. } else {
  711. byte hPower = mAirconData.systemAircon.Device.Aircon[roomIndex].hPower;
  712. byte hMode = mAirconData.systemAircon.Device.Aircon[roomIndex].hMode;
  713. byte hAirVol = mAirconData.systemAircon.Device.Aircon[roomIndex].hAirVol;
  714. boolean bAirSwing = mAirconData.systemAircon.Device.Aircon[roomIndex].bAirSwing;
  715. nResult = mAirconControl.ctrlUnitAircon((byte) roomIndex, hPower, hMode, hAirVol, hSetTemper, bAirSwing);
  716. }
  717. return nResult;
  718. } catch (RuntimeException re) {
  719. LogUtil.errorLogInfo("", TAG, re);
  720. return JSON.ERROR.RuntimeException;
  721. } catch (Exception e) {
  722. Log.e(TAG, "[Exception] ctrlSetTemper(byte hSetTemper)");
  723. LogUtil.errorLogInfo("", TAG, e);
  724. return JSON.ERROR.Exception;
  725. }
  726. }
  727. /**
  728. * 설정온도 데이터를 증가 또는 감소 시킨다.
  729. */
  730. private int ctrlSetTemperUpDown(byte roomIndex, int bUp) {
  731. try {
  732. if (mAirconData == null) return JSON.ERROR.NotReady;
  733. if (mAirconData.systemAircon.Device.Aircon == null) return JSON.ERROR.NotReady;
  734. DataClasses.SystemAircon.Info info = mAirconData.systemAircon.Device.info;
  735. byte hSetTemper = mAirconData.systemAircon.Device.Aircon[roomIndex].hSetTemper;
  736. byte hMode = mAirconData.systemAircon.Device.Aircon[roomIndex].hMode;
  737. byte TempRange = 0x01;
  738. if (bUp == 1) {
  739. // UP
  740. if (hMode == DataClasses.SystemAircon.MODE.Cooling) {
  741. hSetTemper += TempRange;
  742. if (hSetTemper >= info.Support.hMaxCoolSetTemper)
  743. hSetTemper = info.Support.hMaxCoolSetTemper;
  744. } else if (hMode == DataClasses.SystemAircon.MODE.Heating) {
  745. hSetTemper += TempRange;
  746. if (hSetTemper >= info.Support.hMaxHeatSetTemper)
  747. hSetTemper = info.Support.hMaxHeatSetTemper;
  748. } else if (hMode == DataClasses.SystemAircon.MODE.Auto) {
  749. hSetTemper += TempRange;
  750. byte hMaxTemper = (byte) Math.max(info.Support.hMaxHeatSetTemper, info.Support.hMaxCoolSetTemper);
  751. if (hSetTemper > hMaxTemper) hSetTemper = hMaxTemper;
  752. } else {
  753. // 냉방/난방/자동이 아닌경우에는 온도조절 불가
  754. Log.w(TAG, "[ctrlSetTemperUpDown] SetTemper setting not supported!!! hMode -> " + hMode);
  755. return JSON.ERROR.NotSupported;
  756. }
  757. } else {
  758. // DOWN
  759. if (hMode == DataClasses.SystemAircon.MODE.Cooling) {
  760. hSetTemper -= TempRange;
  761. if (hSetTemper <= info.Support.hMinCoolSetTemper)
  762. hSetTemper = info.Support.hMinCoolSetTemper;
  763. } else if (hMode == DataClasses.SystemAircon.MODE.Heating) {
  764. hSetTemper -= TempRange;
  765. if (hSetTemper <= info.Support.hMinHeatSetTemper)
  766. hSetTemper = info.Support.hMinHeatSetTemper;
  767. } else if (hMode == DataClasses.SystemAircon.MODE.Auto) {
  768. hSetTemper -= TempRange;
  769. byte hMinTemper = (byte) Math.min(info.Support.hMinHeatSetTemper, info.Support.hMinCoolSetTemper);
  770. if (hSetTemper < hMinTemper) hSetTemper = hMinTemper;
  771. } else {
  772. // 냉방/난방/자동이 아닌경우에는 온도조절 불가
  773. Log.w(TAG, "[ctrlSetTemperUpDown] SetTemper setting not supported!!! hMode -> " + hMode);
  774. return JSON.ERROR.NotSupported;
  775. }
  776. }
  777. return ctrlSetTemper(roomIndex, hSetTemper);
  778. } catch (RuntimeException re) {
  779. LogUtil.errorLogInfo("", TAG, re);
  780. return JSON.ERROR.RuntimeException;
  781. } catch (Exception e) {
  782. Log.e(TAG, "[Exception] ctrlSetTemperUpDown(boolean bUp)");
  783. LogUtil.errorLogInfo("", TAG, e);
  784. return JSON.ERROR.Exception;
  785. }
  786. }
  787. /**
  788. * 난방제어기 V2의 운전모드를 제어한다.
  789. *
  790. * @param RoomIdx - (byte) 제어할 방 인덱스 (0~5)
  791. * @param DeiveMode - (byte) 변경할 운전모드 (지원 타입별로 범위 상이함) HeatingAPI.V2DRIVEMODE_NONE 은 변경하지않음
  792. * @return (int) - >=0 : 성공, <0 : 실패
  793. */
  794. private int ctrlDeviceMode(byte RoomIdx, byte DeiveMode) {
  795. DebugLogOutput("[ctrlDeviceMode] - (RoomIdx:" + RoomIdx + ", DeiveMode:" + String.format("%02x", DeiveMode) + ")");
  796. return mHeatingControl.ctrlDeviceUnitStatus(RoomIdx, DeiveMode, 0);
  797. }
  798. private WpadSound mSound;
  799. private int setOnOff_BadRoom_EnergyMeter(int index) {
  800. boolean OnOff = false;
  801. for (int i = 0; i < mKnxData.BadRoom_EnergyMeter[index].Info.LightCount; i++) {
  802. if (mKnxData.BadRoom_EnergyMeter[index].Info.Install) {
  803. if (mKnxData.BadRoom_EnergyMeter[index].Data.BadLight[i].Data.OnOff == true) {
  804. OnOff = false;
  805. break;
  806. }
  807. if (i == mKnxData.BadRoom_EnergyMeter[index].Info.LightCount - 1) {
  808. OnOff = true;
  809. }
  810. }
  811. }
  812. int ret = mKnxAPI.SetLightOnOff((byte) (index), define.DEVICE_ALL_OR_NOTHING, OnOff);
  813. if (ret >= 0) mSound.Play(WpadSound.SND.effect.TOUCH_LATCHED);
  814. else mSound.Play(WpadSound.SND.effect.TOUCH_UNLATCHED);
  815. return ret;
  816. }
  817. private int setOnOff_Light_Switch(int index) {
  818. boolean OnOff = false;
  819. for (int i = 0; i < mKnxData.Light_Switch[index].Info.LightCount; i++) {
  820. if (mKnxData.Light_Switch[index].Info.Install) {
  821. if (mKnxData.Light_Switch[index].Data.LightSwitch[i].Data.OnOff == true) {
  822. OnOff = false;
  823. break;
  824. }
  825. if (i == mKnxData.Light_Switch[index].Info.LightCount - 1) {
  826. OnOff = true;
  827. }
  828. }
  829. }
  830. int ret = mKnxAPI.SetLightSwitchOnOff((byte) (index), define.DEVICE_ALL_OR_NOTHING, OnOff);
  831. if (ret >= 0) mSound.Play(WpadSound.SND.effect.TOUCH_LATCHED);
  832. else mSound.Play(WpadSound.SND.effect.TOUCH_UNLATCHED);
  833. return ret;
  834. }
  835. /**
  836. * 각방 전체 조명제어기를 켜고 끈다.
  837. *
  838. * @param RoomIdx - (byte) 제어할 기기 인덱스 (0~5 각방인덱스, 0xFF 전체방)
  839. * @param OnOff - true : ON / false : OFF
  840. * @return (int) - >=0 : 성공, <0 : 실패
  841. */
  842. private int Device_LightOnOffAll(byte RoomIdx, boolean OnOff) {
  843. DebugLogOutput("[Device_LightOnOff] - Start (RoomIdx : " + RoomIdx + " / OnOff : " + OnOff + ")");
  844. int ret = 0;
  845. // 1. Api Load Check
  846. if (mKnxAPI == null) {
  847. Log.e(TAG, "[Device_LightOnOff] multiSwitchAPI unload !!!");
  848. ret = JSON.ERROR.ApiNull;
  849. }
  850. // 2. Param Range Check
  851. if ((RoomIdx < 0) || (RoomIdx >= AllEMcount)) {
  852. Log.w(TAG, "[Device_LightOnOff] Param (RoomIdx) Out of range!!! (" + RoomIdx + ")");
  853. ret = JSON.ERROR.OutOfRange;
  854. }
  855. // 3. Light Control
  856. try {
  857. if (ret == 0) {
  858. int emCount = 0;
  859. emCount = mKnxData.MasterController.Info.Liv_EnergyMeterCount + mKnxData.MasterController.Info.Bad_EnergyMeterCount;
  860. if (mKnxData.LivingRoom_EnergyMeter.Info.Install) {
  861. if (RoomIdx == 0)
  862. ret = mKnxAPI.SetLivingLightOnOff(define.DEVICE_ALL_OR_NOTHING, OnOff);
  863. else if (RoomIdx > 0 && RoomIdx < emCount) {
  864. ret = mKnxAPI.SetLightOnOff((byte) (RoomIdx - 1), define.DEVICE_ALL_OR_NOTHING, OnOff);
  865. } else {
  866. ret = mKnxAPI.SetLightSwitchOnOff((byte) (RoomIdx - emCount), define.DEVICE_ALL_OR_NOTHING, OnOff);
  867. }
  868. } else {
  869. if (RoomIdx < emCount) {
  870. ret = mKnxAPI.SetLightOnOff(RoomIdx, define.DEVICE_ALL_OR_NOTHING, OnOff);
  871. } else {
  872. ret = mKnxAPI.SetLightSwitchOnOff((byte) (RoomIdx - emCount), define.DEVICE_ALL_OR_NOTHING, OnOff);
  873. }
  874. }
  875. if (ret < 0) {
  876. Log.e(TAG, "[Device_LightOnOff] - [Return Error] multiSwitchAPI.SetLightOnOff(Index:" + RoomIdx + ", OnOff:" + OnOff + ")");
  877. Log.e(TAG, "[Device_LightOnOff] - Error (" + ret + ") ErrorCode = " + mKnxAPI.ErrorCode.ErrStr());
  878. }
  879. }
  880. if (ret >= 0) mSound.Play(WpadSound.SND.effect.TOUCH_LATCHED);
  881. else mSound.Play(WpadSound.SND.effect.TOUCH_UNLATCHED);
  882. } catch (RuntimeException re) {
  883. LogUtil.errorLogInfo("", TAG, re);
  884. ret = JSON.ERROR.RuntimeException;
  885. ;
  886. } catch (Exception e) {
  887. Log.e(TAG, "[Device_LightOnOff] - [Exception Error] multiSwitchAPI.SetLightOnOff(Index:" + RoomIdx + ",OnOff:" + OnOff + ")");
  888. //e.printStackTrace();
  889. LogUtil.errorLogInfo("", TAG, e);
  890. ret = JSON.ERROR.Exception;
  891. }
  892. DebugLogOutput("[Device_LightOnOff] - OK");
  893. return ret;
  894. }
  895. /**
  896. * 각방 개별 조명제어기를 켜고 끈다.
  897. *
  898. * @param RoomIdx - (byte) 제어할 기기 인덱스 (0~5 각방인덱스, 0xFF 전체방)
  899. * @param LightIdx - (byte) 제어할 조명 인덱스
  900. * @return (int) - >=0 : 성공, <0 : 실패
  901. */
  902. private int Device_LightOnOffIndividual(byte RoomIdx, byte LightIdx) {
  903. DebugLogOutput("[Device_LightOnOffIndividual] - Start (RoomIdx : " + RoomIdx + " / LightIdx : " + LightIdx + ")");
  904. int ret = 0;
  905. // 1. Api Load Check
  906. if (mKnxAPI == null) {
  907. Log.e(TAG, "[Device_LightOnOff] multiSwitchAPI unload !!!");
  908. ret = JSON.ERROR.ApiNull;
  909. }
  910. // 2. Param Range Check
  911. if ((RoomIdx < 0) || (RoomIdx >= AllEMcount)) {
  912. Log.w(TAG, "[Device_LightOnOff] Param (RoomIdx) Out of range!!! (" + RoomIdx + ")");
  913. ret = JSON.ERROR.OutOfRange;
  914. }
  915. boolean OnOff = true;
  916. // 3. Light Control
  917. try {
  918. if (ret == 0) {
  919. int emCount = 0;
  920. emCount = mKnxData.MasterController.Info.Liv_EnergyMeterCount + mKnxData.MasterController.Info.Bad_EnergyMeterCount;
  921. if (mKnxData.LivingRoom_EnergyMeter.Info.Install) {
  922. if (RoomIdx == 0) {
  923. if (mKnxData.LivingRoom_EnergyMeter.Data.LivingLight[LightIdx].Data.OnOff)
  924. OnOff = false;
  925. ret = mKnxAPI.SetLivingLightOnOff(LightIdx, OnOff);
  926. } else if (RoomIdx > 0 && RoomIdx < emCount) {
  927. if (mKnxData.BadRoom_EnergyMeter[RoomIdx - 1].Data.BadLight[LightIdx].Data.OnOff)
  928. OnOff = false;
  929. ret = mKnxAPI.SetLightOnOff((byte) (RoomIdx - 1), LightIdx, OnOff);
  930. } else {
  931. if (mKnxData.Light_Switch[RoomIdx - emCount].Data.LightSwitch[LightIdx].Data.OnOff)
  932. OnOff = false;
  933. ret = mKnxAPI.SetLightSwitchOnOff((byte) (RoomIdx - emCount), LightIdx, OnOff);
  934. }
  935. } else {
  936. if (RoomIdx < emCount) {
  937. if (mKnxData.BadRoom_EnergyMeter[RoomIdx].Data.BadLight[LightIdx].Data.OnOff)
  938. OnOff = false;
  939. ret = mKnxAPI.SetLightOnOff(RoomIdx, LightIdx, OnOff);
  940. } else {
  941. if (mKnxData.Light_Switch[RoomIdx - emCount].Data.LightSwitch[LightIdx].Data.OnOff)
  942. OnOff = false;
  943. ret = mKnxAPI.SetLightSwitchOnOff((byte) (RoomIdx - emCount), LightIdx, OnOff);
  944. }
  945. }
  946. if (ret < 0) {
  947. Log.e(TAG, "[Device_LightOnOff] - [Return Error] multiSwitchAPI.SetLightOnOff(Index:" + RoomIdx + ", LightIdx:" + LightIdx + ", OnOff:" + OnOff + ")");
  948. Log.e(TAG, "[Device_LightOnOff] - Error (" + ret + ") ErrorCode = " + mKnxAPI.ErrorCode.ErrStr());
  949. }
  950. }
  951. if (ret >= 0) mSound.Play(WpadSound.SND.effect.TOUCH_LATCHED);
  952. else mSound.Play(WpadSound.SND.effect.TOUCH_UNLATCHED);
  953. } catch (RuntimeException re) {
  954. LogUtil.errorLogInfo("", TAG, re);
  955. ret = JSON.ERROR.RuntimeException;
  956. ;
  957. } catch (Exception e) {
  958. Log.e(TAG, "[Device_LightOnOff] - [Exception Error] multiSwitchAPI.SetLightOnOff(Index:" + RoomIdx + ", LightIdx:" + LightIdx + ", OnOff:" + OnOff + ")");
  959. //e.printStackTrace();
  960. LogUtil.errorLogInfo("", TAG, e);
  961. ret = JSON.ERROR.Exception;
  962. }
  963. DebugLogOutput("[Device_LightOnOff] - OK");
  964. return ret;
  965. }
  966. /**
  967. * 가스 밸브를 닫는다.
  968. *
  969. * @return (int) - >=0 : 성공, <0 : 실패
  970. */
  971. private int Device_GasClose() {
  972. int result;
  973. if (mGasAPI == null) {
  974. Log.e(TAG, "[Device_GasClose] - gasApi unload !!!");
  975. return JSON.ERROR.ApiNull;
  976. }
  977. byte b0 = 0;
  978. result = mGasAPI.SetClose(b0);
  979. if (result < 0) {
  980. Log.e(TAG, "[Device_GasClose] - SetClose (" + result + ") ErrorCode = " + mGasAPI.ErrorCode.ErrStr());
  981. }
  982. return result;
  983. }
  984. private int controlLight(int kind, int pos, RequestData reqData) {
  985. int result = JSON.ERROR.ResultFail;
  986. String category = reqData.getCategory();
  987. if (kind == 0) {
  988. //전체 제어
  989. int state = reqData.getState();
  990. if (category.equalsIgnoreCase("all_execution_release")) {
  991. result = mLightControl.Device_All_Excecution_Release(state == 1 ? true : false);
  992. } else if (category.equalsIgnoreCase("set_light_dimming")) {
  993. result = mLightControl.SetLightDimming((byte) state);
  994. }
  995. } else if (kind == 1) {
  996. //개별 제어
  997. int state = reqData.getState();
  998. int lightNum = reqData.getNumber();
  999. if (category.equalsIgnoreCase("switch_liv")) {
  1000. boolean onoff = state == 0 ? true : false;
  1001. result = mLightControl.SetLivingLightOnOff(onoff);
  1002. } else if (category.equalsIgnoreCase("switch_bed")) {
  1003. result = setOnOff_BadRoom_EnergyMeter(pos);
  1004. } else if (category.equalsIgnoreCase("switch_light_switch")) {
  1005. result = setOnOff_Light_Switch(pos);
  1006. } else if (category.equalsIgnoreCase("switch_light_switch_individual")) {
  1007. result = Device_LightOnOffIndividual((byte) pos, (byte) lightNum);
  1008. } else if (category.equalsIgnoreCase("switch_light_switch_all")) {
  1009. result = Device_LightOnOffAll((byte) pos, state == 0 ? true : false);
  1010. }
  1011. }
  1012. return result;
  1013. }
  1014. private int controlConcent(int kind, RequestData reqData) {
  1015. int result = JSON.ERROR.ResultFail;
  1016. String category = reqData.getCategory();
  1017. if (kind == 0) {
  1018. //전체 제어
  1019. } else if (kind == 1) {
  1020. //개별 제어
  1021. if (category.equalsIgnoreCase("switch")) {
  1022. return result;
  1023. } else if (category.equalsIgnoreCase("temperature")) {
  1024. } else if (category.equalsIgnoreCase("dimming")) {
  1025. }
  1026. }
  1027. return result;
  1028. }
  1029. private int controlHeating(int kind, int pos, RequestData reqData) {
  1030. int result = JSON.ERROR.ResultFail;
  1031. String category = reqData.getCategory();
  1032. if (kind == 0) {
  1033. //전체 제어
  1034. int state = reqData.getState();
  1035. int temp = reqData.getNumber();
  1036. if (category.equalsIgnoreCase("set_all_execution")) { //pause on/off
  1037. result = mHeatingControl.ctrlDeviceEntireMode((byte) state);
  1038. } else if (category.equalsIgnoreCase("set_all_release")) { //pause on/off
  1039. result = mHeatingControl.ctrlDeviceEntireMode((byte) state);
  1040. } else if (category.equalsIgnoreCase("set_boiler")) { //pause on/off
  1041. result = mHeatingControl.Device_SetBoiler((byte) temp, (byte) state);
  1042. }
  1043. } else if (kind == 1) {
  1044. //개별 제어
  1045. int state = reqData.getState();
  1046. int time = reqData.getNumber();
  1047. if (category.equalsIgnoreCase("set_mode")) {
  1048. //switch on/off
  1049. result = ctrlDeviceMode((byte) pos, (byte) state);
  1050. } else if (category.equalsIgnoreCase("set_temp")) {
  1051. //설정온도
  1052. result = mHeatingControl.Device_SetEachRoomStatus((byte) pos, DataClasses.HeatingV2.MODE.Idle, reqData.getDoubleState());
  1053. } else if (category.equalsIgnoreCase("set_reservation")) {
  1054. //예약 스케줄 저장
  1055. result = mHeatingControl.Device_SetReservation((byte) pos, state);
  1056. } else if (category.equalsIgnoreCase("set_sleep")) {
  1057. //취침 설정 저장
  1058. result = mHeatingControl.Device_SetSleep((byte) pos, (byte) state, (byte) time);
  1059. }
  1060. }
  1061. return result;
  1062. }
  1063. private int controlAircon(int kind, int pos, RequestData reqData) {
  1064. int result = JSON.ERROR.ResultFail;
  1065. String category = reqData.getCategory();
  1066. int state = reqData.getState();
  1067. if (kind == 0) { //전체 제어
  1068. if (category.equalsIgnoreCase("switch")) {
  1069. result = ctrlPowerToggle();
  1070. } else if (category.equalsIgnoreCase("set_all_mode")) {
  1071. result = ctrlMode((byte) state);
  1072. } else if (category.equalsIgnoreCase("set_all_airvol")) {
  1073. result = ctrlAirVol((byte) state);
  1074. }
  1075. } else if (kind == 1) {//개별 제어
  1076. if (category.equalsIgnoreCase("switch")) {
  1077. result = ctrlPowerToggle((byte) pos);
  1078. } else if (category.equalsIgnoreCase("set_mode")) {
  1079. result = ctrlMode((byte) pos, (byte) state);
  1080. } else if (category.equalsIgnoreCase("set_airvol")) {
  1081. result = ctrlAirVolUpDown((byte) pos, (byte) state);
  1082. } else if (category.equalsIgnoreCase("set_airswing")) {
  1083. result = ctrlAirSwingToggle((byte) pos);
  1084. } else if (category.equalsIgnoreCase("set_temp")) {
  1085. result = ctrlSetTemperUpDown((byte) pos, (byte) state);
  1086. }
  1087. }
  1088. return result;
  1089. }
  1090. private int controlKnxAircon(int kind, int pos, RequestData reqData) {
  1091. int result = JSON.ERROR.ResultFail;
  1092. String category = reqData.getCategory();
  1093. int state = reqData.getState();
  1094. int mode = reqData.getNumber();
  1095. if (kind == 0) { //전체 제어
  1096. if (category.equalsIgnoreCase("switch")) {
  1097. result = mKnxAirconControl.Device_AllControl((byte)state);
  1098. }
  1099. } else if (kind == 1) {//개별 제어
  1100. if (category.equalsIgnoreCase("switch")) {
  1101. Double doubleState = reqData.getDoubleState();
  1102. result = mKnxAirconControl.Device_SetEachRoomStatus((byte) pos, mode, doubleState);
  1103. }
  1104. }
  1105. return result;
  1106. }
  1107. private int controlPurity(int kind, RequestData reqData) {
  1108. int result = JSON.ERROR.ResultFail;
  1109. String category = reqData.getCategory();
  1110. if (kind == 0) {
  1111. //전체 제어
  1112. int state = reqData.getState();
  1113. if (category.equalsIgnoreCase("switch")) {
  1114. boolean onoff = state == 0 ? true : false;
  1115. result = mVentiControl.ctrlDevicePower(onoff);
  1116. } else if (category.equalsIgnoreCase("auto_air_clean")) {
  1117. boolean onoff = state == 0 ? true : false;
  1118. result = mVentiControl.ctrlDeviceAutoAirClean(onoff);
  1119. } else if (category.equalsIgnoreCase("reservation")) {
  1120. boolean onoff = state == 0 ? true : false;
  1121. result = mVentiControl.ctrlDeviceReservation(onoff);
  1122. } else if (category.equalsIgnoreCase("wind")) {
  1123. result = mVentiControl.ctrlDeviceWindType((byte) state);
  1124. } else if (category.equalsIgnoreCase("natural_ventil")) {
  1125. boolean onoff = state == 0 ? true : false;
  1126. result = mVentiControl.ctrlDeviceNaturalVentil(onoff);
  1127. } else if (category.equalsIgnoreCase("auto_ventil")) {
  1128. boolean onoff = state == 0 ? true : false;
  1129. result = mVentiControl.ctrlDeviceAutoVentil(onoff);
  1130. } else if (category.equalsIgnoreCase("internal_ventil")) {
  1131. boolean onoff = state == 0 ? true : false;
  1132. result = mVentiControl.ctrlDeviceInternalVentil(onoff);
  1133. } else if (category.equalsIgnoreCase("outair_clean")) {
  1134. boolean onoff = state == 0 ? true : false;
  1135. result = mVentiControl.ctrlDeviceOutAirClean(onoff);
  1136. } else if (category.equalsIgnoreCase("heater")) {
  1137. boolean onoff = state == 0 ? true : false;
  1138. result = mVentiControl.ctrlDeviceHeater(onoff);
  1139. } else if (category.equalsIgnoreCase("sleep_mode")) {
  1140. boolean onoff = state == 0 ? true : false;
  1141. result = mVentiControl.ctrlDeviceSleepMode(onoff);
  1142. } else if (category.equalsIgnoreCase("timer")) {
  1143. result = mVentiControl.ctrlDeviceTimer(state);
  1144. } else if (category.equalsIgnoreCase("reset_filter")) {
  1145. result = mVentiControl.ctrlDeviceResetFilter();
  1146. } else if (category.equalsIgnoreCase("save_shedule")) {
  1147. result = mVentiControl.Device_SaveSchedule(reqData.getArrayState());
  1148. }
  1149. } else if (kind == 1) {
  1150. //개별 제어
  1151. if (category.equalsIgnoreCase("switch")) {
  1152. } else if (category.equalsIgnoreCase("temperature")) {
  1153. } else if (category.equalsIgnoreCase("dimming")) {
  1154. }
  1155. }
  1156. return result;
  1157. }
  1158. private int controlGas(int kind, RequestData reqData) {
  1159. int result = JSON.ERROR.ResultFail;
  1160. String category = reqData.getCategory();
  1161. if (kind == 0) {
  1162. //전체 제어
  1163. if (category.equalsIgnoreCase("close")) {
  1164. //gas close
  1165. int close = reqData.getState();
  1166. roomNumber = reqData.getNumber() - 1;
  1167. result = Device_GasClose();
  1168. return result;
  1169. }
  1170. } else if (kind == 1) {
  1171. //개별 제어
  1172. if (category.equalsIgnoreCase("close")) {
  1173. //gas close
  1174. int close = reqData.getState();
  1175. roomNumber = reqData.getNumber() - 1;
  1176. result = Device_GasClose();
  1177. return result;
  1178. }
  1179. }
  1180. return result;
  1181. }
  1182. private int controlCurtain(int kind, RequestData reqData) {
  1183. int result = JSON.ERROR.ResultFail;
  1184. String category = reqData.getCategory();
  1185. if (kind == 0) {
  1186. //전체 제어
  1187. } else if (kind == 1) {
  1188. //개별 제어
  1189. if (category.equalsIgnoreCase("switch")) {
  1190. } else if (category.equalsIgnoreCase("temperature")) {
  1191. } else if (category.equalsIgnoreCase("dimming")) {
  1192. }
  1193. }
  1194. return result;
  1195. }
  1196. private int controlRequest(JSONObject requestData, int menu, int kind, int pos) {
  1197. Gson gson = new Gson();
  1198. try {
  1199. JSONObject dataObject = requestData.getJSONObject("data");
  1200. RequestData reqData = gson.fromJson(dataObject.toString(), RequestData.class);
  1201. if (menu == JSON.MENU.LIGHT) {
  1202. //조명 상태, 제어
  1203. return controlLight(kind, pos, reqData);
  1204. } else if (menu == JSON.MENU.HEATING) {
  1205. //난방 상태, 제어
  1206. return controlHeating(kind, pos, reqData);
  1207. } else if (menu == JSON.MENU.AIRCON) {
  1208. //에어컨 상태, 제어
  1209. //return controlAircon(kind, pos, reqData);
  1210. return controlKnxAircon(kind, pos, reqData);
  1211. } else if (menu == JSON.MENU.VENTI) {
  1212. //환기 상태, 제어
  1213. return controlPurity(kind, reqData);
  1214. } else if (menu == JSON.MENU.GAS) {
  1215. //가스 상태, 제어
  1216. return controlGas(kind, reqData);
  1217. }
  1218. } catch (JSONException e) {
  1219. e.printStackTrace();
  1220. return JSON.ERROR.JsonException;
  1221. } catch (Exception e) {
  1222. e.printStackTrace();
  1223. return JSON.ERROR.Exception;
  1224. }
  1225. return -1;
  1226. }
  1227. private JSONObject updateLight(int kind, int position) {
  1228. if (mKnxData == null) {
  1229. deviceApiLoadLight();
  1230. return null;
  1231. }
  1232. int livDataCount = mKnxData.LivingRoom_EnergyMeter.Info.LightCount;
  1233. int bedDataCount = mKnxData.MasterController.Info.Bad_EnergyMeterCount;
  1234. int switchDataCount = mKnxData.MasterController.Info.Light_SwitchCount;
  1235. if ((livDataCount + bedDataCount + switchDataCount) == 0) {
  1236. deviceApiLoadLight();
  1237. return null;
  1238. }
  1239. JSONObject responseObject = new JSONObject();
  1240. try {
  1241. responseObject.accumulate("type", "updateResponse");
  1242. responseObject.accumulate("timestamp", millToDate(System.currentTimeMillis()));
  1243. responseObject.accumulate("ip", myIP);
  1244. responseObject.accumulate("menu", JSON.MENU.LIGHT);
  1245. responseObject.accumulate("master_info_fault", mKnxData.MasterController.Info.Fault_KnxGwSet);
  1246. responseObject.accumulate("master_data_batch", mKnxData.MasterController.Data.BatchOffStatus);
  1247. responseObject.accumulate("master_info_liv_count", mKnxData.MasterController.Info.Liv_EnergyMeterCount);
  1248. responseObject.accumulate("master_info_bad_count", bedDataCount);
  1249. responseObject.accumulate("master_info_switch_count", switchDataCount);
  1250. responseObject.accumulate("liv_info_install", mKnxData.LivingRoom_EnergyMeter.Info.Install);
  1251. responseObject.accumulate("liv_info_lightcount", livDataCount);
  1252. JSONArray livDataArray = new JSONArray();
  1253. for (int i = 0; i < livDataCount; i++) {
  1254. // build jsonObject
  1255. JSONObject livDataObject = new JSONObject();
  1256. livDataObject.accumulate("info_install", mKnxData.LivingRoom_EnergyMeter.Data.LivingLight[i].Info.Install);
  1257. livDataObject.accumulate("info_type", mKnxData.LivingRoom_EnergyMeter.Data.LivingLight[i].Info.Type);
  1258. livDataObject.accumulate("data_onoff", mKnxData.LivingRoom_EnergyMeter.Data.LivingLight[i].Data.OnOff);
  1259. livDataObject.accumulate("data_dimming", mKnxData.LivingRoom_EnergyMeter.Data.LivingLight[i].Data.Dimming);
  1260. livDataArray.put(livDataObject);
  1261. }
  1262. responseObject.accumulate("liv_data_array", livDataArray);
  1263. JSONArray bedDataArray = new JSONArray();
  1264. for (int j = 0; j < bedDataCount; j++) {
  1265. // build jsonObject
  1266. JSONObject bedDataObject = new JSONObject();
  1267. bedDataObject.accumulate("info_install", mKnxData.BadRoom_EnergyMeter[j].Info.Install);
  1268. bedDataObject.accumulate("info_lightcount", mKnxData.BadRoom_EnergyMeter[j].Info.LightCount);
  1269. bedDataObject.accumulate("info_light_type1", mKnxData.BadRoom_EnergyMeter[j].Info.LightType_1);
  1270. bedDataObject.accumulate("info_light_type2", mKnxData.BadRoom_EnergyMeter[j].Info.LightType_2);
  1271. bedDataObject.accumulate("info_light_type3", mKnxData.BadRoom_EnergyMeter[j].Info.LightType_3);
  1272. bedDataObject.accumulate("info_light_type4", mKnxData.BadRoom_EnergyMeter[j].Info.LightType_4);
  1273. JSONArray lightArray = new JSONArray();
  1274. for (int k = 0; k < mKnxData.BadRoom_EnergyMeter[j].Info.LightCount; k++) {
  1275. lightArray.put(mKnxData.BadRoom_EnergyMeter[j].Data.BadLight[k].Data.OnOff);
  1276. }
  1277. bedDataObject.accumulate("lightArray", lightArray);
  1278. bedDataArray.put(bedDataObject);
  1279. }
  1280. responseObject.accumulate("bed_data_array", bedDataArray);
  1281. JSONArray switchDataArray = new JSONArray();
  1282. for (int j = 0; j < switchDataCount; j++) {
  1283. // build jsonObject
  1284. JSONObject switchDataObject = new JSONObject();
  1285. switchDataObject.accumulate("info_install", mKnxData.Light_Switch[j].Info.Install);
  1286. switchDataObject.accumulate("info_lightcount", mKnxData.Light_Switch[j].Info.LightCount);
  1287. switchDataObject.accumulate("info_light_type1", mKnxData.Light_Switch[j].Info.LightType_1);
  1288. switchDataObject.accumulate("info_light_type2", mKnxData.Light_Switch[j].Info.LightType_2);
  1289. switchDataObject.accumulate("info_light_type3", mKnxData.Light_Switch[j].Info.LightType_3);
  1290. switchDataObject.accumulate("info_light_type4", mKnxData.Light_Switch[j].Info.LightType_4);
  1291. JSONArray switchArray = new JSONArray();
  1292. for (int k = 0; k < mKnxData.Light_Switch[j].Info.LightCount; k++) {
  1293. switchArray.put(mKnxData.Light_Switch[j].Data.LightSwitch[k].Data.OnOff);
  1294. }
  1295. switchDataObject.accumulate("switchArray", switchArray);
  1296. switchDataArray.put(switchDataObject);
  1297. }
  1298. responseObject.accumulate("switch_data_array", switchDataArray);
  1299. } catch (JSONException e) {
  1300. e.printStackTrace();
  1301. } catch (Exception e) {
  1302. e.printStackTrace();
  1303. }
  1304. return responseObject;
  1305. }
  1306. private JSONObject updateConcent(int kind, int position) {
  1307. int roomCount = mHeatingV2API.data.Device.info.RoomCount;
  1308. JSONObject jsonObject = new JSONObject();
  1309. return jsonObject;
  1310. }
  1311. private JSONObject updateHeating(int kind, int pos) {
  1312. int roomCount = mHeatingV2API.data.Device.info.RoomCount;
  1313. JSONObject jsonObject = new JSONObject();
  1314. try {
  1315. jsonObject.accumulate("type", "updateResponse");
  1316. jsonObject.accumulate("timestamp", millToDate(System.currentTimeMillis()));
  1317. jsonObject.accumulate("ip", myIP);
  1318. jsonObject.accumulate("menu", JSON.MENU.HEATING);
  1319. jsonObject.accumulate("support_setpoint05", mHeatingV2API.data.Device.info.Support.SetTempPoint05);
  1320. jsonObject.accumulate("support_outing", mHeatingV2API.data.Device.info.Support.Outing);
  1321. jsonObject.accumulate("support_sleep", mHeatingV2API.data.Device.info.Support.Sleep);
  1322. jsonObject.accumulate("support_reservation", mHeatingV2API.data.Device.info.Support.Reservation);
  1323. jsonObject.accumulate("support_pause", mHeatingV2API.data.Device.info.Support.Pause);
  1324. jsonObject.accumulate("support_ai", mHeatingV2API.data.Device.info.Support.AI);
  1325. jsonObject.accumulate("support_outsidetempuse", mHeatingV2API.data.Device.info.Support.OutsideTempUse);
  1326. jsonObject.accumulate("support_boiler", mHeatingV2API.data.Device.info.Support.Boiler);
  1327. jsonObject.accumulate("boiler_heatwater_temp", mHeatingV2API.data.Boiler.HeatingWater.SetTemp);
  1328. jsonObject.accumulate("boiler_hotwater_temp", mHeatingV2API.data.Boiler.HotWater.SetTemp);
  1329. jsonObject.accumulate("boiler_frost_protect", mHeatingV2API.data.Boiler.bFrostProtectMode);
  1330. jsonObject.accumulate("boiler_error_code", mHeatingV2API.data.Boiler.ErrorCode);
  1331. JSONArray dataArray = new JSONArray();
  1332. if (kind == 0) { //전체 응답
  1333. for (int i = 0; i < roomCount; i++) {
  1334. // build jsonObject
  1335. JSONObject dataObject = new JSONObject();
  1336. dataObject.accumulate("roomNumber", i);
  1337. dataObject.accumulate("mode", mHeatingV2API.data.Device.Room[i].Mode);
  1338. dataObject.accumulate("setTemp", mHeatingV2API.data.Device.Room[i].SetTemp);
  1339. dataObject.accumulate("nowTemp", mHeatingV2API.data.Device.Room[i].NowTemp);
  1340. JSONArray reserveArray = new JSONArray();
  1341. for (int j = 0; j < 24; j++) {
  1342. if (mHeatingV2API.data.Device.Room[i].Reservation.getSchedule(j)) {
  1343. reserveArray.put(j);
  1344. }
  1345. }
  1346. dataObject.accumulate("reservationArray", reserveArray);
  1347. dataObject.accumulate("sleepTemp", mHeatingV2API.data.Device.Room[i].Sleep.getTemp());
  1348. dataObject.accumulate("sleepTime", mHeatingV2API.data.Device.Room[i].Sleep.getTime());
  1349. dataArray.put(dataObject);
  1350. }
  1351. } else if (kind == 1) {
  1352. // 데이터 전송
  1353. String mode = "off";
  1354. switch (mHeatingV2API.data.Device.Room[pos].Mode) {
  1355. case MODE.HeatingON:
  1356. mode = "on";
  1357. break;
  1358. case MODE.HeatingOFF:
  1359. mode = "off";
  1360. break;
  1361. case MODE.Outing:
  1362. mode = "away";
  1363. break;
  1364. case MODE.Sleep:
  1365. mode = "sleep";
  1366. break;
  1367. case MODE.Reservation:
  1368. mode = "schedule";
  1369. break;
  1370. case MODE.Pause:
  1371. mode = "pause";
  1372. break;
  1373. default:
  1374. break;
  1375. }
  1376. // build jsonObject
  1377. JSONObject dataObject = new JSONObject();
  1378. dataObject.accumulate("roomNumber", pos);
  1379. dataObject.accumulate("mode", mode);
  1380. dataObject.accumulate("setTemp", mHeatingV2API.data.Device.Room[pos].SetTemp);
  1381. dataObject.accumulate("NowTemp", mHeatingV2API.data.Device.Room[pos].NowTemp);
  1382. dataArray.put(dataObject);
  1383. }
  1384. jsonObject.accumulate("data_array", dataArray);
  1385. } catch (JSONException e) {
  1386. e.printStackTrace();
  1387. } catch (Exception e) {
  1388. e.printStackTrace();
  1389. }
  1390. return jsonObject;
  1391. }
  1392. private JSONObject updateAircon(int kind, int pos) {
  1393. int roomCount = mSystemAirconAPI.data.Device.info.hInsideAirconCnt;
  1394. JSONObject jsonObject = new JSONObject();
  1395. try {
  1396. jsonObject.accumulate("type", "updateResponse");
  1397. jsonObject.accumulate("timestamp", millToDate(System.currentTimeMillis()));
  1398. jsonObject.accumulate("ip", myIP);
  1399. jsonObject.accumulate("menu", JSON.MENU.AIRCON);
  1400. jsonObject.accumulate("support_auto", mSystemAirconAPI.data.Device.info.Support.bModeAuto);
  1401. jsonObject.accumulate("support_cooling", mSystemAirconAPI.data.Device.info.Support.bModeCooling);
  1402. jsonObject.accumulate("support_dehumidify", mSystemAirconAPI.data.Device.info.Support.bModeDehumidify);
  1403. jsonObject.accumulate("support_fan", mSystemAirconAPI.data.Device.info.Support.bModeFan);
  1404. jsonObject.accumulate("support_heating", mSystemAirconAPI.data.Device.info.Support.bModeHeating);
  1405. JSONArray dataArray = new JSONArray();
  1406. if (kind == 0) { //전체 응답
  1407. for (int i = 0; i < roomCount; i++) {
  1408. // build jsonObject
  1409. JSONObject dataObject = new JSONObject();
  1410. dataObject.accumulate("roomNumber", i);
  1411. dataObject.accumulate("mode", mSystemAirconAPI.data.Device.Aircon[i].hMode);
  1412. dataObject.accumulate("airvol", mSystemAirconAPI.data.Device.Aircon[i].hAirVol);
  1413. dataObject.accumulate("setTemp", mSystemAirconAPI.data.Device.Aircon[i].hSetTemper);
  1414. dataObject.accumulate("NowTemp", mSystemAirconAPI.data.Device.Aircon[i].hCurrentTemper);
  1415. dataArray.put(dataObject);
  1416. }
  1417. } else if (kind == 1) {
  1418. // build jsonObject
  1419. JSONObject dataObject = new JSONObject();
  1420. dataObject.accumulate("roomNumber", pos);
  1421. dataObject.accumulate("mode", mSystemAirconAPI.data.Device.Aircon[pos].hMode);
  1422. dataObject.accumulate("airvol", mSystemAirconAPI.data.Device.Aircon[pos].hAirVol);
  1423. dataObject.accumulate("setTemp", mSystemAirconAPI.data.Device.Aircon[pos].hSetTemper);
  1424. dataObject.accumulate("NowTemp", mSystemAirconAPI.data.Device.Aircon[pos].hCurrentTemper);
  1425. dataArray.put(dataObject);
  1426. }
  1427. jsonObject.accumulate("data_array", dataArray);
  1428. } catch (JSONException e) {
  1429. e.printStackTrace();
  1430. } catch (Exception e) {
  1431. e.printStackTrace();
  1432. }
  1433. return jsonObject;
  1434. }
  1435. private JSONObject updateKnxAircon(int kind, int pos) {
  1436. int roomCount = mKnxSystemAirconAPI.data.Device.info.InsideAirconCount;
  1437. JSONObject jsonObject = new JSONObject();
  1438. try {
  1439. jsonObject.accumulate("type", "updateResponse");
  1440. jsonObject.accumulate("timestamp", millToDate(System.currentTimeMillis()));
  1441. jsonObject.accumulate("ip", myIP);
  1442. jsonObject.accumulate("menu", JSON.MENU.AIRCON);
  1443. JSONArray dataArray = new JSONArray();
  1444. if (kind == 0) { //전체 응답
  1445. for (int i = 0; i < roomCount; i++) {
  1446. // build jsonObject
  1447. JSONObject dataObject = new JSONObject();
  1448. dataObject.accumulate("roomNumber", i);
  1449. dataObject.accumulate("power", mKnxSystemAirconAPI.data.Device.Aircon[i].OnOff);
  1450. dataObject.accumulate("mode", mKnxSystemAirconAPI.data.Device.Aircon[i].Mode);
  1451. dataObject.accumulate("airvol", mKnxSystemAirconAPI.data.Device.Aircon[i].Volume);
  1452. dataObject.accumulate("setTemp", mKnxSystemAirconAPI.data.Device.Aircon[i].SetTemp);
  1453. dataObject.accumulate("NowTemp", mKnxSystemAirconAPI.data.Device.Aircon[i].NowTemp);
  1454. dataArray.put(dataObject);
  1455. }
  1456. } else if (kind == 1) {
  1457. // build jsonObject
  1458. JSONObject dataObject = new JSONObject();
  1459. dataObject.accumulate("roomNumber", pos);
  1460. dataObject.accumulate("power", mKnxSystemAirconAPI.data.Device.Aircon[pos].OnOff);
  1461. dataObject.accumulate("mode", mKnxSystemAirconAPI.data.Device.Aircon[pos].Mode);
  1462. dataObject.accumulate("airvol", mKnxSystemAirconAPI.data.Device.Aircon[pos].Volume);
  1463. dataObject.accumulate("setTemp", mKnxSystemAirconAPI.data.Device.Aircon[pos].SetTemp);
  1464. dataObject.accumulate("NowTemp", mKnxSystemAirconAPI.data.Device.Aircon[pos].NowTemp);
  1465. dataArray.put(dataObject);
  1466. }
  1467. jsonObject.accumulate("data_array", dataArray);
  1468. } catch (JSONException e) {
  1469. e.printStackTrace();
  1470. } catch (Exception e) {
  1471. e.printStackTrace();
  1472. }
  1473. return jsonObject;
  1474. }
  1475. private JSONObject updateVenti(int kind, int position) {
  1476. JSONObject jsonObject = new JSONObject();
  1477. try {
  1478. jsonObject.accumulate("type", "updateResponse");
  1479. jsonObject.accumulate("timestamp", millToDate(System.currentTimeMillis()));
  1480. jsonObject.accumulate("ip", myIP);
  1481. jsonObject.accumulate("menu", JSON.MENU.VENTI);
  1482. jsonObject.accumulate("support_heater", mVentiAPI.data.Support.Heater);
  1483. jsonObject.accumulate("support_innercycle", mVentiAPI.data.Support.InnerCycle);
  1484. jsonObject.accumulate("support_outairclean", mVentiAPI.data.Support.OutAirClean);
  1485. jsonObject.accumulate("support_autodriving", mVentiAPI.data.Support.AutoDriving);
  1486. jsonObject.accumulate("support_bypass", mVentiAPI.data.Support.ByPass);
  1487. jsonObject.accumulate("support_filterreset", mVentiAPI.data.Support.FilterReset);
  1488. jsonObject.accumulate("support_bathroom", mVentiAPI.data.Support.BathRoom);
  1489. jsonObject.accumulate("support2_windowventi", mVentiAPI.data.Support2.WindowVenti);
  1490. jsonObject.accumulate("support2_sleepmode", mVentiAPI.data.Support2.SleepMode);
  1491. jsonObject.accumulate("fault_motorerror", mVentiAPI.data.Fault.MotorError);
  1492. jsonObject.accumulate("fault_tempsensorerror", mVentiAPI.data.Fault.TempSensorError);
  1493. jsonObject.accumulate("fault_supplyfanerror", mVentiAPI.data.Fault.SupplyFanError);
  1494. jsonObject.accumulate("fault_exhaustfanerror", mVentiAPI.data.Fault.ExhaustFanError);
  1495. jsonObject.accumulate("fault_filterchangefree", mVentiAPI.data.Fault.FilterChangeFree);
  1496. jsonObject.accumulate("fault_filterchangemedium", mVentiAPI.data.Fault.FilterChangeMedium);
  1497. jsonObject.accumulate("fault_safemode", mVentiAPI.data.Fault.SafeMode);
  1498. jsonObject.accumulate("OnOff", mVentiAPI.data.OnOff);
  1499. jsonObject.accumulate("Reservation", mVentiAPI.data.Reservation);
  1500. jsonObject.accumulate("Wind", mVentiAPI.data.Wind);
  1501. jsonObject.accumulate("Sleep", mVentiAPI.data.Sleep);
  1502. jsonObject.accumulate("Timer", mVentiAPI.data.Timer);
  1503. jsonObject.accumulate("ByPass", mVentiAPI.data.ByPass);
  1504. jsonObject.accumulate("HeaterTimeRemaining", mVentiAPI.data.HeaterTimeRemaining);
  1505. jsonObject.accumulate("HeaterStatus", mVentiAPI.data.HeaterStatus);
  1506. jsonObject.accumulate("AutoDriving", mVentiAPI.data.AutoDriving);
  1507. jsonObject.accumulate("BathRoom", mVentiAPI.data.BathRoom);
  1508. jsonObject.accumulate("InnerCycle", mVentiAPI.data.InnerCycle);
  1509. jsonObject.accumulate("OutAirClean", mVentiAPI.data.OutAirClean);
  1510. jsonObject.accumulate("AirCleanAuto", mVentiAPI.data.AirCleanAuto);
  1511. jsonObject.accumulate("HDCAutoAirClean", mVentiAPI.data.HDCAutoAirClean);
  1512. JSONArray reserveArray = new JSONArray();
  1513. byte[] ReserveList = mVentiAPI.GetReservationSchedule();
  1514. for (int j = 0; j < ReserveList.length; j++) {
  1515. reserveArray.put(ReserveList[j]);
  1516. }
  1517. jsonObject.accumulate("reservationArray", reserveArray);
  1518. } catch (JSONException e) {
  1519. e.printStackTrace();
  1520. } catch (Exception e) {
  1521. e.printStackTrace();
  1522. }
  1523. return jsonObject;
  1524. }
  1525. private JSONObject updateGas(int kind, int position) {
  1526. int nGasCnt = (int) mGasAPI.data.DeviceCnt;
  1527. JSONObject jsonObject = new JSONObject();
  1528. try {
  1529. jsonObject.accumulate("type", "updateResponse");
  1530. jsonObject.accumulate("timestamp", millToDate(System.currentTimeMillis()));
  1531. jsonObject.accumulate("ip", myIP);
  1532. jsonObject.accumulate("menu", "gas");
  1533. JSONArray dataArray = new JSONArray();
  1534. if (kind == 0) {
  1535. for (int j = 0; j < nGasCnt; j++) {
  1536. // 데이터 전송
  1537. String status = "close";
  1538. if (mGasAPI.data.Device[j].GasStatus == GasAPI.GASSTATUS.Close)
  1539. status = "close";
  1540. else if (mGasAPI.data.Device[j].GasStatus == GasAPI.GASSTATUS.Open)
  1541. status = "open";
  1542. else if (mGasAPI.data.Device[j].GasStatus == GasAPI.GASSTATUS.Operation)
  1543. status = "working";
  1544. JSONObject dataObject = new JSONObject();
  1545. String roomName;
  1546. if (j == 0) {
  1547. roomName = "living_room";
  1548. } else {
  1549. roomName = "room" + j;
  1550. }
  1551. dataObject.accumulate("roomNumber", roomName);
  1552. jsonObject.accumulate("state", status);
  1553. dataArray.put(dataObject);
  1554. }
  1555. } else if (kind == 1) {
  1556. }
  1557. jsonObject.accumulate("data_array", dataArray);
  1558. } catch (JSONException e) {
  1559. e.printStackTrace();
  1560. } catch (Exception e) {
  1561. e.printStackTrace();
  1562. }
  1563. return jsonObject;
  1564. }
  1565. private JSONObject updateCookTop(int kind, int pos) {
  1566. int nCookTopCnt = mCookTopData.DeviceCnt;
  1567. JSONObject jsonObject = new JSONObject();
  1568. try {
  1569. jsonObject.accumulate("type", "updateResponse");
  1570. jsonObject.accumulate("timestamp", millToDate(System.currentTimeMillis()));
  1571. jsonObject.accumulate("ip", myIP);
  1572. jsonObject.accumulate("menu", JSON.MENU.COOKTOP);
  1573. jsonObject.accumulate("device_count", nCookTopCnt);
  1574. JSONArray dataArray = new JSONArray();
  1575. if (kind == 0) { //전체 응답
  1576. for (int i = 0; i < nCookTopCnt; i++) {
  1577. // build jsonObject
  1578. JSONObject dataObject = new JSONObject();
  1579. dataObject.accumulate("hID", mCookTopData.Device[0].circuit[i].hID);
  1580. dataObject.accumulate("hStatus", mCookTopData.Device[0].circuit[i].hStatus);
  1581. dataObject.accumulate("hType", mCookTopData.Device[0].circuit[i].hType);
  1582. dataObject.accumulate("hErrorStatus", mCookTopData.Device[0].circuit[i].hErrorStatus);
  1583. dataArray.put(dataObject);
  1584. }
  1585. }
  1586. jsonObject.accumulate("data_array", dataArray);
  1587. } catch (JSONException e) {
  1588. e.printStackTrace();
  1589. } catch (Exception e) {
  1590. e.printStackTrace();
  1591. }
  1592. return jsonObject;
  1593. }
  1594. private JSONObject updateCurtain(int kind, int position) {
  1595. int roomCount = mHeatingV2API.data.Device.info.RoomCount;
  1596. JSONObject jsonObject = new JSONObject();
  1597. return jsonObject;
  1598. }
  1599. private JSONObject updateRequest(int menu, int kind, int position) {
  1600. try {
  1601. if (menu == JSON.MENU.LIGHT) {
  1602. return updateLight(kind, position);
  1603. } else if (menu == JSON.MENU.CONCENT) {
  1604. return updateConcent(kind, position);
  1605. } else if (menu == JSON.MENU.HEATING) {
  1606. return updateHeating(kind, position);
  1607. } else if (menu == JSON.MENU.AIRCON) {
  1608. return updateKnxAircon(kind, position);
  1609. //return updateAircon(kind, position);
  1610. } else if (menu == JSON.MENU.VENTI) {
  1611. return updateVenti(kind, position);
  1612. } else if (menu == JSON.MENU.GAS) {
  1613. return updateGas(kind, position);
  1614. } else if (menu == JSON.MENU.COOKTOP) {
  1615. return updateCookTop(kind, position);
  1616. }
  1617. } catch (Exception e) {
  1618. e.printStackTrace();
  1619. return null;
  1620. }
  1621. return null;
  1622. }
  1623. private int passwordChangeRequest(String passwordNumber) {
  1624. //패스워드 변경
  1625. try {
  1626. WallpadStatusData wd = new WallpadStatusData(this.getContext());
  1627. if (wd != null) {
  1628. wd.SetUserPW(passwordNumber);
  1629. Log.d(TAG, "[passwordNumber]" + passwordNumber);
  1630. wd.closeDB();
  1631. }
  1632. return 0;
  1633. } catch (Exception e) {
  1634. e.printStackTrace();
  1635. return JSON.ERROR.Exception;
  1636. }
  1637. }
  1638. @Override
  1639. public void onCreate() {
  1640. //handler.sendEmptyMessage(MSG_WORK);
  1641. super.onCreate();
  1642. mContext = this;
  1643. this.mSound = new WpadSound(this);
  1644. // 3.1. mWallPadAPI 생성
  1645. int OPERATION_MODE = Common.MODE;
  1646. if (OPERATION_MODE == Common.MODE_NOMAL) {
  1647. Log.d(TAG, "OperationMode = MODE_NOMAL");
  1648. try {
  1649. mWallPadAPI = new WallPadAPI(this);
  1650. } catch (Exception e) {
  1651. Log.e(TAG, "[ExceptionError] - new WallPadAPI : " + e);
  1652. }
  1653. } else if (OPERATION_MODE == Common.MODE_BUSINESS_SAMPLE) {
  1654. Log.d(TAG, "OperationMode = MODE_BUSINESS_SAMPLE");
  1655. myDong = "101";
  1656. myHo = "102";
  1657. }
  1658. registerEventAlarmBr();
  1659. mKnxData = new Data_KnxLiv();
  1660. mSDBEMInfo = new SDBEMInfo();
  1661. deviceApiLoad();
  1662. setIPInfo();
  1663. thread = new ServerThread();
  1664. thread.start();
  1665. }
  1666. private void setIPInfo() {
  1667. DBMGR = new WallpadStatusData(mContext);
  1668. wallpaddbmgr.AddressSet addc = DBMGR.getAddressMGR();
  1669. DBMGR.closeDB();
  1670. myIP = addc.IPAddress;
  1671. myDong = addc.Dong;
  1672. myHo = addc.Ho;
  1673. }
  1674. @Override
  1675. public int onStartCommand(Intent intent, int flags, int startId) {
  1676. Log.d("StartService", "onStartCommand()");
  1677. return super.onStartCommand(intent, flags, startId);
  1678. }
  1679. @Override
  1680. public void onDestroy() {
  1681. //handler.removeMessages(MSG_WORK);
  1682. super.onDestroy();
  1683. }
  1684. int AllEMcount;
  1685. public void deviceApiLoadLight() {
  1686. WallpadDeviceSet wds = new WallpadDeviceSet(mContext);
  1687. int nDPType = wds.Get_DistributionPannelType_Info();
  1688. wds.closeDB();
  1689. try {
  1690. if (mWallPadAPI.Check_Connect()) {
  1691. if (Version.getModelType() == Version.MODEL_TYPE.IHN_D101 || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I
  1692. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K_I
  1693. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I_OCF) {
  1694. if (nDPType == Version.DISTRIBUTION_MODEL.SMART_DIST) {
  1695. // 스마트 분전반
  1696. mSdb_LivingRoomLightAPI = mWallPadAPI.Get_Sdb_LivingRoomLightAPI();
  1697. mSdb_LivingRoomLightAPI.Refresh();
  1698. mSdbAPI = mWallPadAPI.Get_SdbController();
  1699. for (int i = 0; i < mSdbAPI.data.BadRoom_Em_Count; i++) {
  1700. mSdbAPI.Refresh((byte) 0x00, (byte) i);
  1701. }
  1702. } else if (nDPType == Version.DISTRIBUTION_MODEL.KNX_DIST) {
  1703. // KNX 분전반
  1704. mKnxAPI = mWallPadAPI.Get_KnxController();
  1705. if (mKnxAPI != null) {
  1706. mLightControl = new LightControl(mKnxAPI, mContext);
  1707. mKnxAPI.Refresh(KnxAPI.DEVICE_INDEX.ALL, (byte) define.DEVICE_ALL_OR_NOTHING);
  1708. // 4. Data Copy
  1709. mKnxData.MasterController = mKnxAPI.data.MasterController;
  1710. mKnxData.LivingRoom_EnergyMeter = mKnxAPI.data.LivingRoom_EnergyMeter;
  1711. mKnxData.BadRoom_EnergyMeter = mKnxAPI.data.BadRoom_EnergyMeter;
  1712. mKnxData.Light_Switch = mKnxAPI.data.Light_Switch;
  1713. AllEMcount = mKnxData.MasterController.Info.Light_SwitchCount + mKnxData.MasterController.Info.Bad_EnergyMeterCount + mKnxData.MasterController.Info.Liv_EnergyMeterCount;
  1714. }
  1715. }
  1716. }
  1717. }
  1718. } catch (Exception e) {
  1719. Log.e(TAG, "[Exception] deviceApiLoadLight()");
  1720. e.printStackTrace();
  1721. }
  1722. }
  1723. public void deviceApiLoad() {
  1724. WallpadDeviceSet wds = new WallpadDeviceSet(mContext);
  1725. int nDPType = wds.Get_DistributionPannelType_Info();
  1726. wds.closeDB();
  1727. try {
  1728. if (mWallPadAPI.Check_Connect()) {
  1729. if (Version.getModelType() == Version.MODEL_TYPE.IHN_D101 || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I
  1730. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K_I
  1731. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I_OCF) {
  1732. deviceApiLoadLight();
  1733. }
  1734. iGW300API = mWallPadAPI.Get_IGW300Controller();
  1735. if (iGW300API == null) {
  1736. Log.w(TAG, "[onCreate] iGW300API is null!!");
  1737. }
  1738. mIGW300Data = getIGW300UpdateData();
  1739. //가스
  1740. mGasAPI = mWallPadAPI.Get_GasController();
  1741. cooktopAPI = mWallPadAPI.Get_CookTopController();
  1742. if (mGasAPI != null) {
  1743. mGasAPI.Refresh((byte) 0, false);
  1744. nGasCnt = (int) mGasAPI.data.DeviceCnt;
  1745. for (int j = 0; j < nGasCnt; j++) {
  1746. mGasAPI.Refresh((byte) j, false);
  1747. haGasStatus[j] = mGasAPI.data.Device[j].GasStatus;
  1748. }
  1749. }
  1750. if (cooktopAPI != null) {
  1751. cooktopAPI.Refresh(SystemAirconAPI.REFRESH_IDX.ALL, false);
  1752. // 4. Data Copy
  1753. mCookTopData = cooktopAPI.data;
  1754. }
  1755. WallpadDeviceSet mWallpadDeviceSet = new WallpadDeviceSet(getApplicationContext());
  1756. int[] BatchInfo = mWallpadDeviceSet.Get_BatchSW_Info();
  1757. int[] retVentil = mWallpadDeviceSet.Get_Ventil_Info();
  1758. mWallpadDeviceSet.closeDB();
  1759. //환기
  1760. if (retVentil != null && retVentil[0] == 1) {
  1761. mVentiAPI = mWallPadAPI.Get_VentiController();
  1762. if (mVentiAPI != null) {
  1763. mVentiControl = new VentiControl(mVentiAPI, mContext);
  1764. mVentiAPI.Refresh(false);
  1765. // 3. Data Copy
  1766. //mVentilData.VentilStatus = mVentiAPI.data;
  1767. mVentilation.OnOff = mVentiAPI.data.OnOff;
  1768. mVentilation.Wind = mVentiAPI.data.Wind;
  1769. }
  1770. }
  1771. //난방
  1772. mHeatingV2API = mWallPadAPI.Get_HeatingV2Controller();
  1773. if (mHeatingV2API != null) {
  1774. mHeatingControl = new HeatingControl(mHeatingV2API, mContext);
  1775. mHeatingV2API.Refresh(HeatingV2API.REFRESH_IDX.ALL, false);
  1776. int roomCount = mHeatingV2API.data.Device.info.RoomCount;
  1777. for (int i = 0; i < roomCount; i++) {
  1778. mHeating.eachRoom[i].mode = mHeatingV2API.data.Device.Room[i].Mode;
  1779. mHeating.eachRoom[i].curTemper = mHeatingV2API.data.Device.Room[i].NowTemp;
  1780. mHeating.eachRoom[i].setTemper = mHeatingV2API.data.Device.Room[i].SetTemp;
  1781. }
  1782. }
  1783. if (nDPType == Version.DISTRIBUTION_MODEL.KNX_DIST) {
  1784. //에어컨
  1785. mKnxSystemAirconAPI = mWallPadAPI.Get_KnxAirconController();
  1786. if (mKnxSystemAirconAPI != null) {
  1787. mKnxAirconControl = new KnxAirconControl(mKnxSystemAirconAPI);
  1788. mKnxSystemAirconAPI.Refresh(SystemAirconAPI.REFRESH_IDX.ALL, false);
  1789. // 4. Data Copy
  1790. mKnxAirconData.systemAircon = mKnxSystemAirconAPI.data;
  1791. }
  1792. }else{
  1793. //에어컨
  1794. mSystemAirconAPI = mWallPadAPI.Get_AirconController();
  1795. if (mSystemAirconAPI != null) {
  1796. mAirconControl = new AirconControl(mSystemAirconAPI);
  1797. mSystemAirconAPI.Refresh(SystemAirconAPI.REFRESH_IDX.ALL, false);
  1798. // 4. Data Copy
  1799. mAirconData.systemAircon = mSystemAirconAPI.data;
  1800. }
  1801. }
  1802. startRealtimemeterInfo(); // 실시간 검침기 전송 스타트
  1803. // 각각의 디바이스 컨트롤러를 가져온다음에 맨 마직막에 디바이스쪽에 BR을 등록 시킨다.
  1804. registerDeviceBR();
  1805. }
  1806. } catch (Exception e) {
  1807. Log.e(TAG, "[Exception] deviceApiLoad()");
  1808. e.printStackTrace();
  1809. }
  1810. }
  1811. public String SendData(String ui, String type, String menu, String function, Object value, int valueType) {
  1812. String ret = null;
  1813. String strValue = null;
  1814. if (thread == null) {
  1815. thread = new ServerThread();
  1816. thread.start();
  1817. }
  1818. if (valueType == 0) {
  1819. strValue = String.valueOf(value);
  1820. } else if (valueType == 1) {
  1821. strValue = String.valueOf(value);
  1822. } else if (valueType == 2) {
  1823. strValue = value.toString();
  1824. } else if (valueType == 3) {
  1825. strValue = value.toString();
  1826. }
  1827. String addData = String.format("%s;%s;%s;%s;%s;%s;%s", String.valueOf(valueType), ui, type, menu, function, strValue, "param4");
  1828. Log.d("AIDLTEST", "addData : " + addData);
  1829. try {
  1830. //this.mBinder.sendEventData(addData);
  1831. return "Success";
  1832. } catch (Exception var7) {
  1833. Log.e("AIDLTEST", "Catch Exception Afer Send Data to Service");
  1834. return "EXCEPTION";
  1835. }
  1836. }
  1837. public void saveChangedEnergyMeterStatus() {
  1838. try {
  1839. for (int i = 0; i < mEnergyMeterAPI.data.RoomCnt; i++) {
  1840. // 각 에너지미터에 대한 조명 갯수
  1841. for (int j = 0; j < mEnergyMeterAPI.data.Em.eachRoom[i].LightCnt; j++) {
  1842. mSDBEMInfo.EachRoom[i].Light_bOnOff[j] = mEnergyMeterAPI.data.Em.eachRoom[i].LightOnOff[j];
  1843. }
  1844. Log.d(TAG, "mEnergyMeterAPI.data.Em.EachRoom[i].ConCnt : " + mEnergyMeterAPI.data.Em.eachRoom[i].ConCnt);
  1845. // 각 에너지미터에 대한 콘센트 갯수
  1846. int concentCount = mEnergyMeterAPI.data.Em.eachRoom[i].ConCnt;
  1847. // 상시 콘센트는 상태를 저장하지 않기 때문에 에러..
  1848. // 상시 콘센트는 제어되지 않으므로 3번에 대한건 처러 하지 않는다.
  1849. if (mEnergyMeterAPI.data.Em.eachRoom[i].ConCnt >= 3) {
  1850. concentCount = 2;
  1851. }
  1852. for (int j = 0; j < concentCount; j++) {
  1853. mEMeter.eachRoom[i].concentStatus[j] = mEnergyMeterAPI.data.Em.eachRoom[i].ConOnOff[j];
  1854. mEMeter.eachRoom[i].ConMode[j] = mEnergyMeterAPI.data.Em.eachRoom[i].ConMode;
  1855. }
  1856. }
  1857. } catch (Exception e) {
  1858. Log.e(TAG, "[Exception] saveChangedEnergyMeterStatus()");
  1859. e.printStackTrace();
  1860. }
  1861. }
  1862. public void saveChangedSdbStatus_EachOutlet() {
  1863. try {
  1864. for (int i = 0; i < mSdbAPI.data.BadRoom_Em_Count; i++) {
  1865. mSdbAPI.Refresh(SdbAPI.DEVICE_INDEX.ENERGY_METER, (byte) i);
  1866. for (int j = 0; j < mSdbAPI.data.BadRoom_EnergyMeter[i].Info.ConcentCount; j++) {
  1867. // 각방 EM 콘센트 상태 업데이트
  1868. mSDBEMInfo.EachRoom[i].Outlet_hOnOff[j] = mSdbAPI.data.BadRoom_EnergyMeter[i].Data.Concent[j].Data.CutOffConcent.Status;
  1869. mSDBEMInfo.EachRoom[i].Outlet_hCutoff[j] = mSdbAPI.data.BadRoom_EnergyMeter[i].Data.Concent[j].Data.CutOffConcent.Mode;
  1870. }
  1871. }
  1872. } catch (Exception e) {
  1873. Log.e(TAG, "[Exception] saveChangedSdbStatus_EachOutlet()");
  1874. e.printStackTrace();
  1875. }
  1876. }
  1877. public void saveChangedSdbStatus_LivingOutlet() {
  1878. try {
  1879. mSdbAPI.Refresh(SdbAPI.DEVICE_INDEX.ENERGY_METER, EM_INDEX_LIVING);
  1880. for (int i = 0; i < mSdbAPI.data.LivingRoom_EnergyMeter.Info.ConcentCount; i++) {
  1881. // 거실 EM 콘센트 상태 업데이트
  1882. mSDBEMInfo.LivingRoom.Outlet_hOnOff[i] = mSdbAPI.data.LivingRoom_EnergyMeter.Data.Concent[i].Data.CutOffConcent.Status;
  1883. mSDBEMInfo.LivingRoom.Outlet_hCutoff[i] = mSdbAPI.data.LivingRoom_EnergyMeter.Data.Concent[i].Data.CutOffConcent.Mode;
  1884. }
  1885. for (int i = 0; i < mSdbAPI.data.LivingRoom_EnergyMeter.Info.LightCount; i++) {
  1886. // 거실 EM 콘센트 상태 업데이트
  1887. mSDBEMInfo.LivingRoom.Light_hDim[i] = mSdbAPI.data.LivingRoom_EnergyMeter.Data.LedLight[i].Data.Dimming;
  1888. mSDBEMInfo.LivingRoom.Light_hColor[i] = mSdbAPI.data.LivingRoom_EnergyMeter.Data.LedLight[i].Data.Color;
  1889. mSDBEMInfo.LivingRoom.Light_bOnOff[i] = mSdbAPI.data.LivingRoom_EnergyMeter.Data.LedLight[i].Data.OnOff;
  1890. }
  1891. } catch (Exception e) {
  1892. Log.e(TAG, "[Exception] saveChangedSdbStatus_LivingOutlet()");
  1893. e.printStackTrace();
  1894. }
  1895. }
  1896. public void saveChangedSdbStatus_EachLight() {
  1897. try {
  1898. for (int i = 0; i < mSdbAPI.data.BadRoom_Em_Count; i++) {
  1899. mSdbAPI.Refresh(SdbAPI.DEVICE_INDEX.ENERGY_METER, (byte) i);
  1900. for (int j = 0; j < mSdbAPI.data.BadRoom_EnergyMeter[i].Info.LightCount; j++) {
  1901. // 조명상태 업데이트
  1902. mSDBEMInfo.EachRoom[i].Light_bOnOff[j] = mSdbAPI.data.BadRoom_EnergyMeter[i].Data.LedLight[j].Data.OnOff;
  1903. mSDBEMInfo.EachRoom[i].Light_hDim[j] = mSdbAPI.data.BadRoom_EnergyMeter[i].Data.LedLight[j].Data.Dimming;
  1904. mSDBEMInfo.EachRoom[i].Light_hColor[j] = mSdbAPI.data.BadRoom_EnergyMeter[i].Data.LedLight[j].Data.Color;
  1905. }
  1906. }
  1907. } catch (Exception e) {
  1908. Log.e(TAG, "[Exception] saveChangedSdbStatus_EachLight()");
  1909. e.printStackTrace();
  1910. }
  1911. }
  1912. /*
  1913. * 거실 조명 제어기기의 상태를 비교하여 데이터 수집 연동 서버로 전송한다.
  1914. * 변경된 상태는 백업한다.
  1915. */
  1916. public void checkChangedSdbLivingLight() {
  1917. try {
  1918. if (mSdb_LivingRoomLightAPI != null) {
  1919. mSdb_LivingRoomLightAPI.Refresh();
  1920. boolean bChangeState = false;
  1921. for (int i = 0; i < mSdb_LivingRoomLightAPI.data.Info.LightCount; i++) {
  1922. Log.d(TAG, "[checkChangedSdbLivingLight] mSdb_LivingRoomLightAPI.data.Data.LedLight[" + i + "].Data.OnOff = " + mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.OnOff + ", mSDBEMInfo.LivingRoom.Light_bOnOff[" + i + "] = " + mSDBEMInfo.LivingRoom.Light_bOnOff[i]);
  1923. Log.d(TAG, "[checkChangedSdbLivingLight] mSdb_LivingRoomLightAPI.data.Data.LedLight[" + i + "].Data.Dimming = " + mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.Dimming + ", mSDBEMInfo.LivingRoom.Light_hDim[" + i + "] = " + mSDBEMInfo.LivingRoom.Light_hDim[i]);
  1924. Log.d(TAG, "[checkChangedSdbLivingLight] mSdb_LivingRoomLightAPI.data.Data.LedLight[" + i + "].Data.Color = " + mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.Color + ", mSDBEMInfo.LivingRoom.Light_hColor[" + i + "] = " + mSDBEMInfo.LivingRoom.Light_hColor[i]);
  1925. if (mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.OnOff != mSDBEMInfo.LivingRoom.Light_bOnOff[i]
  1926. || mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.Dimming != mSDBEMInfo.LivingRoom.Light_hDim[i]
  1927. || mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.Color != mSDBEMInfo.LivingRoom.Light_hColor[i]) {
  1928. // 조명값이 변경된 경우
  1929. String status_power = "off";
  1930. int status_dim = 0, status_color = 0;
  1931. if (mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Info.Support.OnOff) {
  1932. status_power = (mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.OnOff) ? "on" : "off";
  1933. } else {
  1934. status_power = "null";
  1935. }
  1936. if (mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Info.Support.Dimming) {
  1937. status_dim = mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.Dimming;
  1938. } else {
  1939. status_dim = 0;
  1940. }
  1941. if (mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Info.Support.Color) {
  1942. status_color = mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.Color;
  1943. } else {
  1944. status_color = 0;
  1945. }
  1946. bChangeState = true;
  1947. JSONObject jsonObject = new JSONObject();
  1948. try {
  1949. if (i == 0) {
  1950. jsonObject.accumulate("category", "livingroom");
  1951. } else {
  1952. jsonObject.accumulate("category", "hall");
  1953. }
  1954. jsonObject.accumulate("state", status_power);
  1955. jsonObject.accumulate("dimming", status_dim);
  1956. jsonObject.accumulate("colorTemperature", status_color);
  1957. } catch (JSONException e) {
  1958. e.printStackTrace();
  1959. }
  1960. SendData("icon", "device", "light", "each_control", jsonObject, 2);
  1961. }
  1962. }
  1963. if (bChangeState == true) {
  1964. for (int i = 0; i < mSdb_LivingRoomLightAPI.data.Info.LightCount; i++) {
  1965. mSDBEMInfo.LivingRoom.Light_bOnOff[i] = mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.OnOff;
  1966. mSDBEMInfo.LivingRoom.Light_hDim[i] = mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.Dimming;
  1967. mSDBEMInfo.LivingRoom.Light_hColor[i] = mSdb_LivingRoomLightAPI.data.Data.LedLight[i].Data.Color;
  1968. }
  1969. }
  1970. } else {
  1971. mSdb_LivingRoomLightAPI = mWallPadAPI.Get_Sdb_LivingRoomLightAPI();
  1972. Log.d(TAG, "[checkChangedSdbLivingLight] mSdb_LivingRoomLightAPI == null");
  1973. }
  1974. } catch (Exception e) {
  1975. Log.e(TAG, "[Exception] checkChangedSdbLivingLight()");
  1976. e.printStackTrace();
  1977. }
  1978. }
  1979. /*
  1980. * 환기 제어기기의 상태를 비교하여 데이터 수집 연동 서버로 전송한다.
  1981. * 변경된 상태는 백업한다.
  1982. */
  1983. public void checkChangedVentilation() {
  1984. try {
  1985. Log.i(TAG, "[checkChangedVentilation] ===== START =====");
  1986. if (mVentiAPI != null) {
  1987. mVentiAPI.Refresh(false);
  1988. // 4. Data Copy
  1989. //mVentilData.VentilStatus = mVentiAPI.data;
  1990. } else {
  1991. mVentiAPI = mWallPadAPI.Get_VentiController();
  1992. }
  1993. } catch (Exception e) {
  1994. Log.e(TAG, "[Exception] checkChangedVentilation()");
  1995. e.printStackTrace();
  1996. }
  1997. }
  1998. /*
  1999. * 조명 제어기기의 상태를 비교하여 데이터 수집 연동 서버로 전송한다.
  2000. * 변경된 상태는 백업한다.
  2001. */
  2002. /**
  2003. * 거실에너지미터 INDEX
  2004. */
  2005. public static byte EM_INDEX_LIVING = (byte) 14;
  2006. long before;
  2007. boolean bSending = true;
  2008. public void checkChangedSdb(boolean bForce) {
  2009. try {
  2010. //추후 필요하면 추가.
  2011. } catch (Exception e) {
  2012. Log.e(TAG, "[Exception] checkChangedSdb()");
  2013. e.printStackTrace();
  2014. }
  2015. }
  2016. /*
  2017. * 난방 제어기기의 상태를 비교하여 데이터 수집 연동 서버로 전송한다.
  2018. * 변경된 상태는 백업한다.
  2019. */
  2020. /**
  2021. * 운전상태 정의
  2022. */
  2023. public static class MODE {
  2024. /**
  2025. * 미설정 ( * 설정전용 : 읽기시 해당없음)
  2026. */
  2027. public static final byte Idle = 0x00;
  2028. /**
  2029. * 난방 ON
  2030. */
  2031. public static final byte HeatingON = 0x01;
  2032. /**
  2033. * 난방 OFF
  2034. */
  2035. public static final byte HeatingOFF = 0x02;
  2036. /**
  2037. * 외출
  2038. */
  2039. public static final byte Outing = 0x03;
  2040. /**
  2041. * 외출해제 ( * 설정전용 : 읽기시 해당없음)
  2042. */
  2043. public static final byte OutingRelease = 0x04;
  2044. /**
  2045. * 취침
  2046. */
  2047. public static final byte Sleep = 0x05;
  2048. /**
  2049. * 예약
  2050. */
  2051. public static final byte Reservation = 0x06;
  2052. /**
  2053. * 일시정지
  2054. */
  2055. public static final byte Pause = 0x07;
  2056. /**
  2057. * 일시정지 해제 ( * 설정전용 : 읽기시 해당없음)
  2058. */
  2059. public static final byte PauseRelease = 0x08;
  2060. }
  2061. public String getTimeData(int Time) {
  2062. String[] str = new String[]
  2063. {"0", "3:00", "3:30", "4:00", "4:30", "5:00", "5:30", "6:00", "6:30",
  2064. "7:00", "7:30", "8:00", "8:30", "9:00", "9:30", "10:00", "10:30",
  2065. "11:00", "11:30", "12:00"};
  2066. try {
  2067. return str[Time];
  2068. } catch (Exception e) {
  2069. Log.e("DataClasses", "[getTimeStr]");
  2070. e.printStackTrace();
  2071. }
  2072. return null;
  2073. }
  2074. public void checkChangedAircon() {
  2075. try {
  2076. Log.i(TAG, "[checkChangedAircon] ===== START =====");
  2077. if (mSystemAirconAPI != null) {
  2078. mSystemAirconAPI.Refresh(SystemAirconAPI.REFRESH_IDX.ALL, false);
  2079. // 4. Data Copy
  2080. mAirconData.systemAircon = mSystemAirconAPI.data;
  2081. } else {
  2082. mHeatingV2API = mWallPadAPI.Get_HeatingV2Controller();
  2083. }
  2084. } catch (Exception e) {
  2085. Log.e(TAG, "[Exception] checkChangedAircon()");
  2086. e.printStackTrace();
  2087. }
  2088. }
  2089. public void checkChangedHeating() {
  2090. try {
  2091. Log.i(TAG, "[checkChangedHeating] ===== START =====");
  2092. if (mHeatingV2API != null) {
  2093. mHeatingV2API.Refresh(HeatingV2API.REFRESH_IDX.ALL, false);
  2094. boolean bChangeUnitState = false;
  2095. boolean bChangeTotalState = false;
  2096. int roomCount = mHeatingV2API.data.Device.info.RoomCount;
  2097. for (int i = 0; i < roomCount; i++) {
  2098. bChangeUnitState = false;
  2099. // 전원 상태 변화 확인
  2100. if (mHeating.eachRoom[i].mode != mHeatingV2API.data.Device.Room[i].Mode) {
  2101. bChangeUnitState = true;
  2102. }
  2103. // 0.5 도 단위로 전송
  2104. double old_temer = mHeating.eachRoom[i].curTemper;
  2105. double new_temer = mHeatingV2API.data.Device.Room[i].NowTemp;
  2106. double diff = old_temer - new_temer;
  2107. // 현재온도 변화 확인
  2108. if (diff > 0.5 || diff < -0.5) {
  2109. bChangeTotalState = true;
  2110. }
  2111. // 설정온도 변화 확인
  2112. if (mHeating.eachRoom[i].setTemper != mHeatingV2API.data.Device.Room[i].SetTemp) {
  2113. bChangeUnitState = true;
  2114. }
  2115. if (bChangeUnitState == true) {
  2116. Log.d(TAG, "[checkChangedHeating] temper old_mode : " + mHeating.eachRoom[i].mode + " , new_mode : " + mHeatingV2API.data.Device.Room[i].Mode);
  2117. Log.d(TAG, "[checkChangedHeating] temper old_set : " + mHeating.eachRoom[i].setTemper + " , new_set : " + mHeatingV2API.data.Device.Room[i].SetTemp);
  2118. Log.d(TAG, "[checkChangedHeating] temper old_temer : " + old_temer + " , new_temer : " + new_temer);
  2119. // 데이터 전송
  2120. String mode = "";
  2121. switch (mHeatingV2API.data.Device.Room[i].Mode) {
  2122. case MODE.HeatingON:
  2123. mode = "on";
  2124. break;
  2125. case MODE.HeatingOFF:
  2126. mode = "off";
  2127. break;
  2128. case MODE.Outing:
  2129. mode = "away";
  2130. break;
  2131. case MODE.Sleep:
  2132. mode = "sleep";
  2133. break;
  2134. case MODE.Reservation:
  2135. mode = "schedule";
  2136. break;
  2137. case MODE.Pause:
  2138. mode = "pause";
  2139. break;
  2140. default:
  2141. break;
  2142. }
  2143. if (bChangeUnitState) {
  2144. Log.i(TAG, "[checkChangedHeating] room[" + i + "] temper changed!!!");
  2145. bChangeTotalState = true;
  2146. } else {
  2147. Log.w(TAG, "[checkChangedHeating] room[" + i + "] temper is not changed!!!");
  2148. }
  2149. JSONArray errorArray = new JSONArray();
  2150. if (mHeatingV2API.data.Device.Room[i].Error.bRoomComm) {
  2151. errorArray.put("thermostat_comm_fail");
  2152. }
  2153. if (mHeatingV2API.data.Device.Room[i].Error.bRoomTempSensor) {
  2154. errorArray.put("thermostat_thermo_sensor_error");
  2155. }
  2156. if (mHeatingV2API.data.Device.Room[i].Error.bRoomSystem) {
  2157. errorArray.put("thermostat_system_error");
  2158. }
  2159. if (mHeatingV2API.data.Device.Room[i].Error.bMainTempSensor) {
  2160. errorArray.put("valve_thermo_sensor_error");
  2161. }
  2162. if (mHeatingV2API.data.Device.Room[i].Error.bMainSystem) {
  2163. errorArray.put("valve_system_error");
  2164. }
  2165. if (mHeatingV2API.data.Device.Room[i].Error.bBoiler) {
  2166. errorArray.put("boiler_error");
  2167. }
  2168. if (mHeatingV2API.data.Device.Room[i].Error.bLeak) {
  2169. errorArray.put("water_leakage_detection");
  2170. }
  2171. if (mHeatingV2API.data.Device.Room[i].Error.bEtc) {
  2172. errorArray.put("etc_error");
  2173. }
  2174. JSONArray reserveArray = new JSONArray();
  2175. for (int j = 0; j < 24; j++) {
  2176. if (mHeatingV2API.data.Device.Room[i].Reservation.getSchedule(j)) {
  2177. reserveArray.put(j);
  2178. }
  2179. }
  2180. // build jsonObject
  2181. JSONObject jsonObject = new JSONObject();
  2182. try {
  2183. String roomName;
  2184. if (i == 0) {
  2185. roomName = "living_room";
  2186. } else {
  2187. roomName = "room" + i;
  2188. }
  2189. jsonObject.accumulate("roomNumber", roomName);
  2190. jsonObject.accumulate("mode", mode);
  2191. jsonObject.accumulate("valveState", mHeatingV2API.data.Device.Room[i].bValveStatus == true ? "on" : "off");
  2192. jsonObject.accumulate("setTemperature", mHeatingV2API.data.Device.Room[i].SetTemp);
  2193. jsonObject.accumulate("setUnit", "0.5");
  2194. jsonObject.accumulate("currentTemperature", mHeatingV2API.data.Device.Room[i].NowTemp);
  2195. jsonObject.accumulate("sleepDuration", getTimeData(mHeatingV2API.data.Device.Room[i].Sleep.getTime()));
  2196. jsonObject.accumulate("sleepTemperature", mHeatingV2API.data.Device.Room[i].Sleep.getTempDouble());
  2197. jsonObject.accumulate("reservation", reserveArray);
  2198. if (errorArray.length() > 0) {
  2199. jsonObject.accumulate("errorCode", errorArray);
  2200. } else {
  2201. jsonObject.accumulate("errorCode", JSONObject.NULL);
  2202. }
  2203. } catch (JSONException e) {
  2204. e.printStackTrace();
  2205. }
  2206. SendData("icon", "controller", "heating", "each_control", jsonObject, 2);
  2207. }
  2208. }
  2209. //데이터 저장
  2210. if (bChangeTotalState == true) {
  2211. for (int i = 0; i < roomCount; i++) {
  2212. mHeating.eachRoom[i].mode = mHeatingV2API.data.Device.Room[i].Mode;
  2213. mHeating.eachRoom[i].curTemper = mHeatingV2API.data.Device.Room[i].NowTemp;
  2214. mHeating.eachRoom[i].setTemper = mHeatingV2API.data.Device.Room[i].SetTemp;
  2215. }
  2216. }
  2217. } else {
  2218. mHeatingV2API = mWallPadAPI.Get_HeatingV2Controller();
  2219. }
  2220. } catch (Exception e) {
  2221. Log.e(TAG, "[Exception] checkChangedHeating()");
  2222. e.printStackTrace();
  2223. }
  2224. }
  2225. /*
  2226. * 에너지미터의 조명과 콘센트의 상태를 비교하여 변경되었으면 데이터 수집 연동 서버로 메세지를 전송한다.
  2227. * 변경된 상태는 백업한다.
  2228. */
  2229. public void checkChangedEnergyMeter() {
  2230. String installed, comm, relay;
  2231. String constantOutlet;
  2232. int lightCount;
  2233. try {
  2234. if (mEnergyMeterAPI != null) {
  2235. mEnergyMeterAPI.Refresh((byte) 0xFF, false);
  2236. boolean bChangeState = false;
  2237. for (int i = 0; i < mEnergyMeterAPI.data.RoomCnt; i++) {
  2238. JSONArray state = new JSONArray();
  2239. JSONArray lightState = new JSONArray();
  2240. JSONArray outletState = new JSONArray();
  2241. //installed
  2242. if (mEnergyMeterAPI.data.Em.eachRoom[i].Install) {
  2243. installed = "installed";
  2244. } else {
  2245. installed = "not_installed";
  2246. }
  2247. if (mEnergyMeterAPI.data.Em.eachRoom[i].CommStatus) {
  2248. comm = "comm_ok";
  2249. } else {
  2250. comm = "comm_error";
  2251. }
  2252. if (mEnergyMeterAPI.data.Em.eachRoom[i].AllLightRelay_Use) {
  2253. if (mEnergyMeterAPI.data.Em.eachRoom[i].AllLightRelay_OnOff) {
  2254. relay = "relay_on";
  2255. } else {
  2256. relay = "relay_off";
  2257. }
  2258. } else {
  2259. relay = "relay_not_supported";
  2260. }
  2261. state.put(installed);
  2262. state.put(comm);
  2263. state.put(relay);
  2264. lightCount = mEnergyMeterAPI.data.Em.eachRoom[i].LightCnt;
  2265. // 각 에너지미터에 대한 조명 갯수
  2266. for (int j = 0; j < mEnergyMeterAPI.data.Em.eachRoom[i].LightCnt; j++) {
  2267. if (mSDBEMInfo.EachRoom[i].Light_bOnOff[j] != mEnergyMeterAPI.data.Em.eachRoom[i].LightOnOff[j]) {
  2268. // 같지 않다면 각각에 대해서 상태 메세지를 보낸다.
  2269. bChangeState = true;
  2270. String status = "off";
  2271. if (mEnergyMeterAPI.data.Em.eachRoom[i].LightOnOff[j] == true)
  2272. status = "on";
  2273. lightState.put(status);
  2274. }
  2275. }
  2276. if (mEnergyMeterAPI.data.Em.eachRoom[i].ConMode) {
  2277. constantOutlet = "disable";
  2278. } else {
  2279. constantOutlet = "enable";
  2280. }
  2281. // 각 에너지미터에 대한 콘센트 갯수
  2282. int concentCount = mEnergyMeterAPI.data.Em.eachRoom[i].ConCnt;
  2283. if (concentCount >= 3) concentCount = 2;
  2284. for (int j = 0; j < concentCount; j++) {
  2285. String conMode = "set/";
  2286. if (mEnergyMeterAPI.data.Em.eachRoom[i].ConMode == false)
  2287. conMode = "unset/";
  2288. Log.d(TAG, "before => room number : " + i + ", switch : " + j + ", status : " + mEMeter.eachRoom[i].concentStatus[j]);
  2289. Log.d(TAG, "current => room number : " + i + ", switch : " + j + ", status : " + mEnergyMeterAPI.data.Em.eachRoom[i].ConOnOff[j]);
  2290. // 콘센트 자동/수동에 대한 변경 이벤트도 보내달라 함
  2291. /** 콘센트 모드상태 (true : 자동 ,false : 상시) C1, C2에 일괄적용 */
  2292. //boolean ConMode;
  2293. if (mEMeter.eachRoom[i].concentStatus[j] != mEnergyMeterAPI.data.Em.eachRoom[i].ConOnOff[j] || mEMeter.eachRoom[i].ConMode[j] != mEnergyMeterAPI.data.Em.eachRoom[i].ConMode) {
  2294. // 같지 않다면 각각에 대해서 상태 메세지를 보낸다.
  2295. bChangeState = true;
  2296. String status = "off";
  2297. if (mEnergyMeterAPI.data.Em.eachRoom[i].ConOnOff[j] == true)
  2298. status = "on";
  2299. outletState.put(status);
  2300. }
  2301. }
  2302. JSONObject jsonObject = new JSONObject();
  2303. try {
  2304. jsonObject.accumulate("roomNumber", (i + 1));
  2305. jsonObject.accumulate("state", state);
  2306. jsonObject.accumulate("lightCount", lightCount);
  2307. jsonObject.accumulate("lightState", lightState);
  2308. jsonObject.accumulate("constantOutlet", constantOutlet);
  2309. jsonObject.accumulate("outletState", outletState);
  2310. } catch (JSONException e) {
  2311. e.printStackTrace();
  2312. }
  2313. SendData("icon", "meter", "energyMeter", "each_control", jsonObject, 2);
  2314. }
  2315. if (bChangeState == true) saveChangedEnergyMeterStatus();
  2316. }
  2317. } catch (Exception e) {
  2318. Log.e(TAG, "[Exception] checkChangedEnergyMeter()");
  2319. e.printStackTrace();
  2320. }
  2321. }
  2322. /**
  2323. * 디바이스 API 를 Load 한다.
  2324. *
  2325. * @param wpapi - 생성시 전달받은 WallPadAPI
  2326. * @return (int) - >=0 : 성공, <0 : 실패
  2327. */
  2328. private int loadRealtimemeterAPI(WallPadAPI wpapi) {
  2329. Log.i(TAG, "[loadRealtimemeterAPI] - Start");
  2330. // 2. wpapi Check
  2331. if (wpapi == null) {
  2332. Log.e(TAG, "[loadRealtimemeterAPI] - wpapi is null");
  2333. return -2;
  2334. }
  2335. // 3. Load API
  2336. Log.i(TAG, "[loadRealtimemeterAPI] - Step1 : RemoteMeter API Load...");
  2337. try {
  2338. mRealTimeMeterAPI = wpapi.Get_RealTimeMeterController();
  2339. } catch (Exception e) {
  2340. Log.e(TAG, "[loadRealtimemeterAPI] - [Exception Error] wpapi.Get_RealTimeMeterController");
  2341. e.printStackTrace();
  2342. return -100;
  2343. }
  2344. if (mRealTimeMeterAPI == null) {
  2345. Log.e(TAG, "[loadRealtimemeterAPI] - mRealTimeMeterAPI is null");
  2346. return -4;
  2347. }
  2348. Log.i(TAG, "[loadRealtimemeterAPI] - OK");
  2349. return 0;
  2350. }
  2351. /**
  2352. * 제어기 상태를 가져온다.
  2353. *
  2354. * @param real - (boolean) true : 실시간 , false : 가장최근
  2355. * @return (int) - >=0 : 성공, <0 : 실패
  2356. */
  2357. @SuppressWarnings("unused")
  2358. private int updateRealtimemeterData(boolean real) {
  2359. try {
  2360. // 1. Api Load Check
  2361. if (mRealTimeMeterAPI == null) {
  2362. Log.e(TAG, "[updateRealtimemeterData] - remoteMeterApi unload !!!");
  2363. return -1;
  2364. }
  2365. // 2. reflash
  2366. try {
  2367. int ret = mRealTimeMeterAPI.Refresh(real);
  2368. if (ret < 0) {
  2369. Log.e(TAG, "[updateRealtimemeterData] - mRealTimeMeterAPI.Refresh - ret (" + ret + ")" + mRealTimeMeterAPI.ErrorCode.ErrStr());
  2370. return -2;
  2371. }
  2372. } catch (Exception e) {
  2373. e.printStackTrace();
  2374. return -100;
  2375. }
  2376. // 3. Range Check
  2377. if (mRealTimeMeterAPI.data == null) {
  2378. Log.e(TAG, "[updateRealtimemeterData] - mRealTimeMeterAPI.mRealTimeMeterData is null !!!");
  2379. return -9;
  2380. }
  2381. if (mRealTimeMeterAPI.data.Elec.Now >= 1000000) {
  2382. return -10;
  2383. }
  2384. if (mRealTimeMeterAPI.data.Water.Now >= 1000) {
  2385. return -11;
  2386. }
  2387. if (mRealTimeMeterAPI.data.HotWater.Now >= 1000) {
  2388. return -12;
  2389. }
  2390. if (mRealTimeMeterAPI.data.Gas.Now >= 1000) {
  2391. return -13;
  2392. }
  2393. if (mRealTimeMeterAPI.data.Calorie.Now >= 1000) {
  2394. return -14;
  2395. }
  2396. // 4. Data Copy
  2397. mRealTimeMeterData = mRealTimeMeterAPI.data;
  2398. // 5. Debug msg
  2399. if (DEBUG_REALMETER_DATA_LOG_ON) {
  2400. Log.i(TAG, mRealTimeMeterData.ToDebugString());
  2401. }
  2402. return 0;
  2403. } catch (Exception e) {
  2404. e.printStackTrace();
  2405. return -99;
  2406. }
  2407. }
  2408. /**
  2409. * 실시간검침 데이터를 서버에 전송하는 쓰레드. <br>
  2410. * 10분에 한번씩 저장
  2411. */
  2412. @SuppressLint("UseValueOf")
  2413. class saveRealmeterData extends Thread {
  2414. @Override
  2415. public void run() {
  2416. super.run();
  2417. Log.i(TAG, "[saveRealmeterData] ========== START ==========");
  2418. int ret;
  2419. wallpaddbmgr WallpadDBMGRforThread = null;
  2420. while (true) {
  2421. try {
  2422. Thread.sleep(1000 * 60); //1분마다, 이 시간 설정은 같이 논의 할 필요가 있음.
  2423. if (mRealTimeMeterAPI != null) {
  2424. ret = mRealTimeMeterAPI.Refresh(false);
  2425. if (ret == 0) {
  2426. Log.i(TAG, "[saveRealmeterData] mRealTimeMeterAPI.Refresh is success");
  2427. Log.i(TAG, "[saveRealmeterData] mRealTimeMeterAPI.ElecAccrued :" + mRealTimeMeterAPI.data.Elec.Acc);
  2428. double electricNow = mRealTimeMeterAPI.data.Elec.Now;
  2429. double electricAcc = mRealTimeMeterAPI.data.Elec.Acc;
  2430. double waterNow = mRealTimeMeterAPI.data.Water.Now;
  2431. double waterAcc = mRealTimeMeterAPI.data.Water.Acc;
  2432. double gasNow = mRealTimeMeterAPI.data.Gas.Now;
  2433. double gasAcc = mRealTimeMeterAPI.data.Gas.Acc;
  2434. double hotwaterNow = mRealTimeMeterAPI.data.HotWater.Now;
  2435. double hotwaterAcc = mRealTimeMeterAPI.data.HotWater.Acc;
  2436. double heatNow = mRealTimeMeterAPI.data.Calorie.Now;
  2437. double heatAcc = mRealTimeMeterAPI.data.Calorie.Acc;
  2438. JSONArray errorArray = new JSONArray();
  2439. if (mRealTimeMeterAPI.data.nElecErrorCnt > 0) {
  2440. errorArray.put("electric");
  2441. }
  2442. if (mRealTimeMeterAPI.data.nGasErrorCnt > 0) {
  2443. errorArray.put("gas");
  2444. }
  2445. if (mRealTimeMeterAPI.data.nHeatingErrorCnt > 0) {
  2446. errorArray.put("heat");
  2447. }
  2448. if (mRealTimeMeterAPI.data.nHotWaterErrorCnt > 0) {
  2449. errorArray.put("hotwater");
  2450. }
  2451. if (mRealTimeMeterAPI.data.nWaterErrorCnt > 0) {
  2452. errorArray.put("water");
  2453. }
  2454. JSONArray electricArray = new JSONArray();
  2455. JSONArray gasArray = new JSONArray();
  2456. JSONArray heatArray = new JSONArray();
  2457. JSONArray hotwaterArray = new JSONArray();
  2458. JSONArray waterArray = new JSONArray();
  2459. try {
  2460. electricArray.put(electricNow);
  2461. electricArray.put(electricAcc);
  2462. gasArray.put(gasNow);
  2463. gasArray.put(gasAcc);
  2464. heatArray.put(heatNow);
  2465. heatArray.put(heatAcc);
  2466. hotwaterArray.put(hotwaterNow);
  2467. hotwaterArray.put(hotwaterAcc);
  2468. waterArray.put(waterNow);
  2469. waterArray.put(waterAcc);
  2470. } catch (JSONException e) {
  2471. e.printStackTrace();
  2472. }
  2473. JSONObject jsonObject = new JSONObject();
  2474. try {
  2475. jsonObject.accumulate("error", errorArray);
  2476. jsonObject.accumulate("electric", electricArray);
  2477. jsonObject.accumulate("water", waterArray);
  2478. jsonObject.accumulate("hotwater", hotwaterArray);
  2479. jsonObject.accumulate("gas", gasArray);
  2480. jsonObject.accumulate("heating", heatArray);
  2481. } catch (JSONException e) {
  2482. e.printStackTrace();
  2483. }
  2484. SendData("icon", "meter", "amr", "metering", jsonObject, 2);
  2485. } else {
  2486. Log.i(TAG, "[saveRealmeterData] mRealTimeMeterAPI.Refresh is fail");
  2487. }
  2488. } else {
  2489. Log.i(TAG, "[saveRealmeterData] mRealTimeMeterAPI is null");
  2490. }
  2491. //난방 현재 온도도 같이 보내준다.
  2492. if (bSending && mHeatingV2API != null) {
  2493. int roomCount = mHeatingV2API.data.Device.info.RoomCount;
  2494. JSONObject jsonTempObject = new JSONObject();
  2495. for (int ii = 0; ii < roomCount; ii++) {
  2496. // build jsonObject
  2497. try {
  2498. jsonTempObject.accumulate("room" + (ii + 1), mHeatingV2API.data.Device.Room[ii].NowTemp);
  2499. } catch (JSONException e) {
  2500. e.printStackTrace();
  2501. }
  2502. }
  2503. SendData("icon", "controller", "heating", "current_temperture", jsonTempObject, 2);
  2504. } else {
  2505. mHeatingV2API = mWallPadAPI.Get_HeatingV2Controller();
  2506. }
  2507. //주기적으로 에너지 미터 체크
  2508. checkChangedSdb(true);
  2509. } catch (InterruptedException e1) {
  2510. // TODO Auto-generated catch block
  2511. if (WallpadDBMGRforThread != null) {
  2512. WallpadDBMGRforThread.closeDB();
  2513. }
  2514. Log.i(TAG, "saveRealmeterData extends Thread occurs exception Error");
  2515. e1.printStackTrace();
  2516. }
  2517. }
  2518. }
  2519. }
  2520. /**
  2521. * 실시간검침기 드라이버 초기생성시 Connect 에 시간이 걸리며, <br>
  2522. * 실시간검침기 드라이버 초기화후 바로 API 를 가져올수 없기에, <br>
  2523. * 본 딜레이 코드를 임시로 적용한다.
  2524. */
  2525. @SuppressLint("HandlerLeak")
  2526. protected Handler initRealtimemeterFunctionHandler = new Handler() {
  2527. @SuppressLint("HandlerLeak")
  2528. @Override
  2529. public void handleMessage(Message msg) {
  2530. Log.i(TAG, "[initRealtimemeterFunctionHandler] msg.what [" + msg.what + "]");
  2531. if (msg.what == 0) {
  2532. if (loadRealtimemeterAPI(mWallPadAPI) >= 0) {
  2533. if (updateRealtimemeterData(false) == 0) {
  2534. initRealtimemeterFunctionHandler.sendEmptyMessageDelayed(1, 10);
  2535. } else {
  2536. initRealtimemeterFunctionHandler.sendEmptyMessageDelayed(0, 30000);
  2537. }
  2538. } else {
  2539. Log.i(TAG, "mInitDriverCheckHandler --> mRealTimeMeterAPI == null");
  2540. initRealtimemeterFunctionHandler.sendEmptyMessageDelayed(0, 10000);
  2541. }
  2542. } else if (msg.what == 1) {
  2543. Log.i(TAG, "[initRealtimemeterFunctionHandler] succes addBrActionName");
  2544. if (mRealTimeMeterAPI != null) {
  2545. WallpadDeviceSet mWallpadDeviceSet = new WallpadDeviceSet(getApplicationContext());
  2546. int[] setdata = mWallpadDeviceSet.Get_RealTimeMetor_Info();
  2547. mWallpadDeviceSet.closeDB();
  2548. if ((saveRealmeterDataThread == null) && (setdata[0] == 1)) {
  2549. saveRealmeterDataThread = new saveRealmeterData();
  2550. saveRealmeterDataThread.start();
  2551. }
  2552. }
  2553. }
  2554. }
  2555. };
  2556. /*
  2557. 실시간 검침기 정보 전송 관리
  2558. */
  2559. private RealTimeMeterAPI mRealTimeMeterAPI;
  2560. private DataClasses.RealTimeMeter mRealTimeMeterData = null;
  2561. private boolean DEBUG_REALMETER_DATA_LOG_ON = false;
  2562. public Thread saveRealmeterDataThread = null;
  2563. private void startRealtimemeterInfo() {
  2564. try {
  2565. Log.w(TAG, "[startRealtimemeterInfo] Normal working mode!!!");
  2566. // 실시간 검침기 사용유무 판단
  2567. WallpadDeviceSet mWallpadDeviceSet = new WallpadDeviceSet(getApplicationContext());
  2568. int[] naRealtimemtInfo = mWallpadDeviceSet.Get_RealTimeMetor_Info();
  2569. mWallpadDeviceSet.closeDB();
  2570. boolean bRealtimemeterUsage = false;
  2571. int nRealtimemeterCntDB = -99;
  2572. if (naRealtimemtInfo[0] == WallpadDeviceSet.DO_USE) {
  2573. // 실시간 검침 사용함
  2574. bRealtimemeterUsage = true;
  2575. nRealtimemeterCntDB = naRealtimemtInfo[1];
  2576. initRealtimemeterFunctionHandler.sendEmptyMessage(0);
  2577. } else {
  2578. // 실시간 검침 사용하지 않음
  2579. bRealtimemeterUsage = false;
  2580. }
  2581. Log.i(TAG, "[startRealtimemeterInfo] bRealtimemeterUsage [" + bRealtimemeterUsage + "], nRealtimemeterCntDB [" + nRealtimemeterCntDB + "]");
  2582. } catch (Exception e) {
  2583. Log.e(TAG, "[Exception] startRealtimemeterInfo()");
  2584. e.printStackTrace();
  2585. }
  2586. }
  2587. BroadcastReceiver mSendDataEventBR = new BroadcastReceiver() {
  2588. @Override
  2589. public void onReceive(Context context, Intent intent) {
  2590. String strActionName = intent.getAction();
  2591. if (strActionName.equals(BrID.BR_GAS)) {
  2592. try {
  2593. if (mGasAPI != null) {
  2594. for (int j = 0; j < nGasCnt; j++) {
  2595. mGasAPI.Refresh((byte) j, false);
  2596. Log.d(TAG, " j : " + j + " , haGasStatus[j] : " + haGasStatus[j] + " mGasAPI.data.Device[j].GasStatus : " + mGasAPI.data.Device[j].GasStatus);
  2597. if (mGasAPI.data.Device[j].GasStatus != GasAPI.GASSTATUS.Operation && haGasStatus[j] != mGasAPI.data.Device[j].GasStatus) {
  2598. String status = "close";
  2599. if (mGasAPI.data.Device[j].GasStatus == GasAPI.GASSTATUS.Close)
  2600. status = "close";
  2601. else if (mGasAPI.data.Device[j].GasStatus == GasAPI.GASSTATUS.Open)
  2602. status = "open";
  2603. else if (mGasAPI.data.Device[j].GasStatus == GasAPI.GASSTATUS.Operation)
  2604. status = "working";
  2605. //JSONArray errorArray = new JSONArray();
  2606. String fault = "no";
  2607. if (mGasAPI.data.Device[j].Fault > 0) {
  2608. //errorArray.put("gas_sensor");
  2609. fault = "yes";
  2610. }
  2611. JSONObject jsonObject = new JSONObject();
  2612. try {
  2613. jsonObject.accumulate("state", status);
  2614. jsonObject.accumulate("fault", fault);
  2615. } catch (JSONException e) {
  2616. e.printStackTrace();
  2617. }
  2618. // 상태가 변경되었기 때문에 이전 상태를 백업한다.
  2619. haGasStatus[j] = mGasAPI.data.Device[j].GasStatus;
  2620. }
  2621. }
  2622. } else {
  2623. mGasAPI = mWallPadAPI.Get_GasController();
  2624. }
  2625. } catch (Exception e) {
  2626. e.printStackTrace();
  2627. }
  2628. } else if (strActionName.equals(BrID.BR_HEATING)) {
  2629. // Log.d(TAG, "********************* BR DataSenderService BR_HEATING ********************");
  2630. checkChangedHeating();
  2631. } else if (strActionName.equals(BrID.BR_AIRCON)) {
  2632. // Log.d(TAG, "********************* BR DataSenderService BR_AIRCON ********************");
  2633. checkChangedAircon();
  2634. } else if (strActionName.equals(BrID.BR_SDB_EVENT)) {
  2635. // Log.d(TAG, "********************* DataSenderService BR_SDB_EVENT ********************");
  2636. checkChangedSdb(false);
  2637. } else if (strActionName.equals(BrID.BR_KNX_EVENT)) {
  2638. // Log.d(TAG, "********************* DataSenderService BR_KNX_EVENT ********************");
  2639. deviceApiLoadLight();
  2640. } else if (strActionName.equals(BrID.BR_SDB_LIVING_EVENT)) {
  2641. // Log.d(TAG, "********************* DataSenderService.BR_SDB_LIVING_EVENT ******************** -> bDeviceInitComplete [" + bDeviceInitComplete + "]");
  2642. //checkChangedSdbLivingLight();
  2643. } else if (strActionName.equals(BrID.BR_ENERGY_METER)) {
  2644. // Log.d(TAG, "********************* BR DataSenderService.BR_ENERGY_METER ********************");
  2645. if (bDeviceInitComplete) {
  2646. checkChangedEnergyMeter();
  2647. }
  2648. } else if (strActionName.equals(BrID.BR_VENTIL)) {
  2649. // Log.d(TAG, "********************* BR DataSenderService.BR_VENTIL ********************");
  2650. checkChangedVentilation();
  2651. } else if (strActionName.equals(define.NOTIFY_ACNAME)) {
  2652. int kind = intent.getIntExtra(define.NOTIBR_KIND, 0);
  2653. Log.d(TAG, "[mSendDataEventBR] NOTIFY_ACNAME -> kind [" + kind + "]");
  2654. switch (kind) {
  2655. // 일괄소등 상태 업데이트
  2656. case define.NOTIFY_ALL_LIGHT_OFF:
  2657. Log.i(TAG, "[mSendDataEventBR] define.NOTIFY_ALL_LIGHT_OFF");
  2658. SendData("icon", "switch", "smart_switch", "turnoffalllight", "on", 1);
  2659. break;
  2660. // 일괄소등 해제 (조명 ON)
  2661. case define.NOTIFY_ALL_LIGHT_ON:
  2662. Log.i(TAG, "[mSendDataEventBR] define.NOTIFY_ALL_LIGHT_ON");
  2663. SendData("icon", "switch", "smart_switch", "turnoffalllight", "off", 1);
  2664. break;
  2665. case define.NOTIFY_DEVICE_ELE_CALL_UP:
  2666. // 제어기기 엘리베이터 상향 호출 요청
  2667. Log.i(TAG, "[mWallPadNotifyBR] define.NOTIFY_DEVICE_ELE_CALL_UP");
  2668. SendData("icon", "switch", "elevator", "call", "up", 1);
  2669. break;
  2670. case define.NOTIFY_DEVICE_ELE_CALL_DOWN:
  2671. // 제어기기에서 엘리베이터 하향 호출 요청
  2672. Log.i(TAG, "[mWallPadNotifyBR] define.NOTIFY_DEVICE_ELE_CALL_DOWN");
  2673. SendData("icon", "switch", "elevator", "call", "down", 1);
  2674. break;
  2675. // 방범상태 변경
  2676. case define.NOTIFY_ALARM_CHANGE:
  2677. break;
  2678. // 디바이스 종류 및 갯수 파악
  2679. case define.NOTIFY_DEVICE_INIT_COMPLETION:
  2680. Log.d(TAG, "[mMobileEventBR] ========== DeviceService Complite!! ==========");
  2681. bDeviceInitComplete = true;
  2682. deviceApiLoad();
  2683. break;
  2684. // 디바이스 연결
  2685. case define.NOTIFY_DEVICECONNECTED:
  2686. Log.d(TAG, "[mMobileEventBR] ========== DeviceService Complite!! ==========");
  2687. deviceApiLoad();
  2688. break;
  2689. // 도어락 문열림
  2690. case define.NOTIFY_RFDOORLOCK_OPEN:
  2691. // Log.d(TAG, "********************* NOTIFY_RFDOORLOCK_OPEN ********************");
  2692. if (bDeviceInitComplete) {
  2693. // sendMsgDeviceEvent_DoorLock(true);
  2694. }
  2695. break;
  2696. case define.NOTIFY_SMARTSW_SET_OUTING:
  2697. // 485 대외향 스마트스위치 외출모드
  2698. Log.i(TAG, "[mSendDataEventBR] define.NOTIFY_SMARTSW_SET_OUTING");
  2699. SendData("icon", "switch", "smart_switch", "awaymode", "on", 1);
  2700. break;
  2701. case define.NOTIFY_SMARTSW_FREE_OUTING:
  2702. //대외향 485 스마트스위치 외출모드 해제
  2703. Log.i(TAG, "[mSendDataEventBR] define.NOTIFY_SMARTSW_FREE_OUTING");
  2704. SendData("icon", "switch", "smart_switch", "awaymode", "off", 1);
  2705. break;
  2706. }
  2707. } else if (strActionName.equals(Common.BR_MAIN_NOTI.ACNAME_MAIN_NOTI)) {
  2708. int nKind = intent.getIntExtra(Common.BR_MAIN_NOTI.KIND, 0);
  2709. Log.d(TAG, "[mSendDataEventBR] nKind =" + nKind);
  2710. if (nKind == Common.BR_MAIN_NOTI.RET_ELEVATOR_CALL_STATE) {
  2711. //엘리베이터 월패드 이벤트는 터치만 적용.
  2712. /*
  2713. String strElevatorFloor = intent.getStringExtra("ElevatorFloor");
  2714. Log.d(TAG, "[mSendDataEventBR] RET_ELEVATOR_CALL_STATE -> strElevatorFloor [" + strElevatorFloor + "]");
  2715. Common.ELEV_STATUS eElevCallStatus = Common.ELEV_STATUS.getEnum(intent.getStringExtra("ElevatorFloor"));
  2716. Log.d(TAG, "[mSendDataEventBR] RET_ELEVATOR_CALL_STATE -> eElevCallStatus [" + eElevCallStatus + "]");
  2717. try {
  2718. if (eElevCallStatus == Common.ELEV_STATUS.DOWN) {
  2719. SendData("null", "control", "elevator", "call", "down", 1);
  2720. } else if (eElevCallStatus == Common.ELEV_STATUS.UP) {
  2721. SendData("null", "control", "elevator", "call", "up", 1);
  2722. } else if (eElevCallStatus == Common.ELEV_STATUS.UP_DOWN) {
  2723. SendData("null", "control", "elevator", "call", "updown", 1);
  2724. } else {
  2725. //SendData("null", "switch", "elevator", "call", "none", 1);
  2726. }
  2727. } catch (Exception e) {
  2728. Log.e(TAG, "[Exception] displayElevCallStatus(ELEV_STATUS ElevStatus)");
  2729. e.printStackTrace();
  2730. }
  2731. */
  2732. }
  2733. }
  2734. }
  2735. };
  2736. private IGW300API iGW300API = null;
  2737. private IGW300API.Data mIGW300Data;
  2738. public IGW300API.Data getIGW300UpdateData() {
  2739. if (iGW300API == null) {
  2740. Log.e(TAG, "[Device_Update] - iGW300API unload !!!");
  2741. iGW300API = mWallPadAPI.Get_IGW300Controller();
  2742. if (iGW300API == null) {
  2743. Log.w(TAG, "[Device_Update] iGW300API is null!!");
  2744. }
  2745. return null;
  2746. }
  2747. // 2. Reflash
  2748. try {
  2749. int ret = iGW300API.Refresh(false);
  2750. if (ret < 0) {
  2751. Log.e(TAG, "[Device_Update] getState - ret (" + ret + ") ErrorCode = " + iGW300API.ErrorCode.ErrStr());
  2752. return null;
  2753. }
  2754. } catch (Exception e) {
  2755. Log.e(TAG, "[Device_Update] - " + e.toString());
  2756. e.printStackTrace();
  2757. return null;
  2758. }
  2759. return iGW300API.data;
  2760. }
  2761. private void checkGWSensorEvent() {
  2762. try {
  2763. if (mWallPadAPI.getGatewayType() == Version.GATEWAY_MODEL.IGW_300) {
  2764. if (iGW300API == null) {
  2765. Log.w(TAG, "[checkGWSensorEvent] iGW300API is null!!");
  2766. return;
  2767. }
  2768. if (iGW300API.data == null) {
  2769. Log.w(TAG, "[checkGWSensorEvent] iGW300API.data is null!!");
  2770. return;
  2771. }
  2772. // 내부 동체 (동체감지기 2) 2
  2773. if (bIn_Motion != iGW300API.data.senIn.In_Motion) {
  2774. Log.w(TAG, "[checkGWSensorEvent] iGW300API.iGW300API.data.senIn.In_Motion is check!!");
  2775. bIn_Motion = iGW300API.data.senIn.In_Motion;
  2776. SendData("icon", "sensor", "motion", bIn_Motion == true ? "detection" : "release", (String) null, 1);
  2777. }
  2778. // 외부 동체 (동체감지기 1) 1
  2779. if (bOut_Motion != iGW300API.data.senIn.Out_Motion) {
  2780. Log.w(TAG, "[checkGWSensorEvent] iGW300API.iGW300API.data.senIn.Out_Motion is check!!");
  2781. bOut_Motion = iGW300API.data.senIn.Out_Motion;
  2782. SendData("icon", "sensor", "motion", bOut_Motion == true ? "detection" : "release", (String) null, 1);
  2783. }
  2784. // 마그네틱 0
  2785. if (bMagnetic_Motion != iGW300API.data.senIn.Magnetic == true) {
  2786. Log.w(TAG, "[checkGWSensorEvent] iGW300API.iGW300API.data.senIn.Magnetic is check!!");
  2787. bMagnetic_Motion = iGW300API.data.senIn.Magnetic;
  2788. SendData("icon", "sensor", "magnetic", bMagnetic_Motion == true ? "detection" : "release", (String) null, 1);
  2789. }
  2790. } else {
  2791. Log.w(TAG, "[checkGWSensorEvent] Not supported gateway model -> " + mWallPadAPI.getGatewayType());
  2792. }
  2793. } catch (Exception e) {
  2794. Log.e(TAG, "[Exception] checkGWSensorEvent()");
  2795. e.printStackTrace();
  2796. }
  2797. }
  2798. BroadcastReceiver mSendDataSensorBR = new BroadcastReceiver() {
  2799. @Override
  2800. public void onReceive(Context context, Intent intent) {
  2801. String strActionName = intent.getAction();
  2802. Log.i(TAG, "[IGW300InterfaceBR.onReceive] strActionName [" + strActionName + "]");
  2803. if (strActionName.equals(IGW300API.SENSOR_BR_NAME)) {
  2804. getIGW300UpdateData();
  2805. checkGWSensorEvent();
  2806. }
  2807. }
  2808. };
  2809. private void registerEventAlarmBr() {
  2810. try {
  2811. Log.d(TAG, "[registerEventAlarmBr] ========== START ==========");
  2812. WallpadDeviceSet wds = new WallpadDeviceSet(mContext);
  2813. int nDPType = wds.Get_DistributionPannelType_Info();
  2814. wds.closeDB();
  2815. IntentFilter mIntentFilter = new IntentFilter();
  2816. mIntentFilter.addAction(define.NOTIFY_ACNAME);
  2817. mIntentFilter.addAction(Common.BR_MAIN_NOTI.ACNAME_MAIN_NOTI);
  2818. if (Version.getModelType() == Version.MODEL_TYPE.IHN_D101 || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I
  2819. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K_I) {
  2820. if (nDPType == Version.DISTRIBUTION_MODEL.SMART_DIST) {
  2821. // 스마트 분전반
  2822. mIntentFilter.addAction(BrID.BR_SDB_LIVING_EVENT);
  2823. mIntentFilter.addAction(BrID.BR_SDB_EVENT);
  2824. } else if (nDPType == Version.DISTRIBUTION_MODEL.KNX_DIST) {
  2825. // KNX 분전반
  2826. mIntentFilter.addAction(BrID.BR_KNX_EVENT);
  2827. }
  2828. } else if (Version.getModelType() == Version.MODEL_TYPE.IHN_1020GL
  2829. || Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL
  2830. || Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I) {
  2831. mIntentFilter.addAction(BrID.BR_LIVING_LIGHT);
  2832. mIntentFilter.addAction(BrID.BR_ENERGY_METER);
  2833. }
  2834. mIntentFilter.addAction(BrID.BR_GAS);
  2835. mIntentFilter.addAction(BrID.BR_VENTIL);
  2836. mIntentFilter.addAction(BrID.BR_HEATING);
  2837. getApplicationContext().registerReceiver(mSendDataEventBR, mIntentFilter);
  2838. mIntentFilter = new IntentFilter();
  2839. mIntentFilter.addAction(SENSOR_BR_NAME);
  2840. registerReceiver(mSendDataSensorBR, mIntentFilter);
  2841. Log.d(TAG, "[registerEventAlarmBr] ========== END ==========");
  2842. } catch (Exception e) {
  2843. Log.e(TAG, "[Exception] registerEventAlarmBr()");
  2844. e.printStackTrace();
  2845. }
  2846. }
  2847. private void registerDeviceBR() {
  2848. try {
  2849. Log.d(TAG, "[registerSubcriptionDeviceBR] ========== START ==========");
  2850. WallpadDeviceSet wds = new WallpadDeviceSet(mContext);
  2851. int nDPType = wds.Get_DistributionPannelType_Info();
  2852. wds.closeDB();
  2853. if (Version.getModelType() == Version.MODEL_TYPE.IHN_1020GL
  2854. || Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL
  2855. || Version.getModelType() == Version.MODEL_TYPE.IHN_1010GL_I) {
  2856. if (mEnergyMeterAPI != null) mEnergyMeterAPI.regChangedBR(BrID.BR_ENERGY_METER);
  2857. } else if (Version.getModelType() == Version.MODEL_TYPE.IHN_D101 || Version.getModelType() == Version.MODEL_TYPE.IHN_D101_I
  2858. || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K || Version.getModelType() == Version.MODEL_TYPE.IHN_D101K_I) {
  2859. if (nDPType == Version.DISTRIBUTION_MODEL.SMART_DIST) {
  2860. // 스마트 분전반
  2861. if (mSdb_LivingRoomLightAPI != null)
  2862. mSdb_LivingRoomLightAPI.regChangedBR(BrID.BR_SDB_LIVING_EVENT);
  2863. if (mSdbAPI != null) mSdbAPI.regChangedBR(BrID.BR_SDB_EVENT);
  2864. if (mAirconData != null) mSystemAirconAPI.regChangedBR(BrID.BR_AIRCON);
  2865. } else if (nDPType == Version.DISTRIBUTION_MODEL.KNX_DIST) {
  2866. // KNX 분전반
  2867. if (mKnxAPI != null) mKnxAPI.regChangedBR(BrID.BR_KNX_EVENT);
  2868. if (mKnxAirconData != null) mKnxSystemAirconAPI.regChangedBR(BrID.BR_AIRCON);
  2869. }
  2870. } else {
  2871. }
  2872. if (mGasAPI != null) mGasAPI.regChangedBR(BrID.BR_GAS);
  2873. if (mVentiAPI != null) mVentiAPI.regChangedBR(BrID.BR_VENTIL);
  2874. if (mHeatingV2API != null) mHeatingV2API.regChangedBR(BrID.BR_HEATING);
  2875. } catch (Exception e) {
  2876. Log.e(TAG, "[Exception] registerSubcriptionDeviceBR()");
  2877. e.printStackTrace();
  2878. }
  2879. }
  2880. public String millToDate(long mills) {
  2881. String pattern = "yyyy-MM-dd'T'HH:mm:ss";
  2882. SimpleDateFormat formatter = new SimpleDateFormat(pattern);
  2883. String date = (String) formatter.format(new Timestamp(mills));
  2884. return date;
  2885. }
  2886. }