Commit 57bb5fe355ccf916f55327c139c023ea89c03f4c
1 parent
f5b409f9
version clazz update,open door connect with server
Showing
8 changed files
with
594 additions
and
19 deletions
| ... | ... | @@ -117,6 +117,7 @@ |
| 117 | 117 | <service |
| 118 | 118 | android:name="com.qnbar.smc.service.TelinkLightService" |
| 119 | 119 | android:enabled="true" /> |
| 120 | + <service android:name="com.qnbar.smc.service.SocketService"/> | |
| 120 | 121 | |
| 121 | 122 | <activity android:name="com.qnbar.smc.SimpleLightDemo"> |
| 122 | 123 | <!-- <intent-filter> | ... | ... |
| 1 | +package com.qnbar.smc.service; | |
| 2 | + | |
| 3 | +import java.util.List; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Created by wugian on 2017/3/11. | |
| 7 | + */ | |
| 8 | + | |
| 9 | +public class SocketResponse { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * code : 1001 | |
| 13 | + * msg : roomsn is registered!please use reconnect | |
| 14 | + * data : [] | |
| 15 | + * cmd : | |
| 16 | + */ | |
| 17 | + | |
| 18 | + private int code; | |
| 19 | + private String msg; | |
| 20 | + private String cmd; | |
| 21 | + private List<?> data; | |
| 22 | + | |
| 23 | + public int getCode() { | |
| 24 | + return code; | |
| 25 | + } | |
| 26 | + | |
| 27 | + public void setCode(int code) { | |
| 28 | + this.code = code; | |
| 29 | + } | |
| 30 | + | |
| 31 | + public String getMsg() { | |
| 32 | + return msg; | |
| 33 | + } | |
| 34 | + | |
| 35 | + public void setMsg(String msg) { | |
| 36 | + this.msg = msg; | |
| 37 | + } | |
| 38 | + | |
| 39 | + public String getCmd() { | |
| 40 | + return cmd; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public void setCmd(String cmd) { | |
| 44 | + this.cmd = cmd; | |
| 45 | + } | |
| 46 | + | |
| 47 | + public List<?> getData() { | |
| 48 | + return data; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void setData(List<?> data) { | |
| 52 | + this.data = data; | |
| 53 | + } | |
| 54 | +} | ... | ... |
| 1 | +package com.qnbar.smc.service; | |
| 2 | + | |
| 3 | +import android.app.Service; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.os.Handler; | |
| 6 | +import android.os.IBinder; | |
| 7 | +import android.util.Log; | |
| 8 | + | |
| 9 | +import com.gimi.common.cinema.model.MessageEvent; | |
| 10 | +import com.google.gson.Gson; | |
| 11 | +import com.google.gson.JsonSyntaxException; | |
| 12 | + | |
| 13 | +import org.greenrobot.eventbus.EventBus; | |
| 14 | + | |
| 15 | +import java.io.IOException; | |
| 16 | +import java.io.InputStream; | |
| 17 | +import java.io.OutputStream; | |
| 18 | +import java.lang.ref.WeakReference; | |
| 19 | +import java.net.Socket; | |
| 20 | +import java.net.UnknownHostException; | |
| 21 | +import java.util.Arrays; | |
| 22 | + | |
| 23 | +public class SocketService extends Service { | |
| 24 | + private static final String TAG = "BackService"; | |
| 25 | + private static final long HEART_BEAT_RATE = 30 * 1000; | |
| 26 | + | |
| 27 | + public static final String HOST = "121.43.189.162";// "192.168.1.21";// | |
| 28 | + public static final int PORT = 9501; | |
| 29 | + | |
| 30 | + public static final String MESSAGE_ACTION = "com.dingmore.terminal.socket"; | |
| 31 | + public static final String HEART_BEAT_ACTION = "com.dingmore.terminal.socket.heart"; | |
| 32 | + | |
| 33 | + public static final String HEART_BEAT_STRING = "00";//心跳包内容 | |
| 34 | + | |
| 35 | + private ReadThread mReadThread; | |
| 36 | + private Gson gson; | |
| 37 | + | |
| 38 | +// private LocalBroadcastManager mLocalBroadcastManager; | |
| 39 | + | |
| 40 | + private WeakReference<Socket> mSocket; | |
| 41 | + | |
| 42 | + // For heart Beat | |
| 43 | + private Handler mHandler = new Handler(); | |
| 44 | + private Runnable heartBeatRunnable = new Runnable() { | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public void run() { | |
| 48 | + if (System.currentTimeMillis() - sendTime >= HEART_BEAT_RATE) { | |
| 49 | + Log.d(TAG, "heart beat"); | |
| 50 | + boolean isSuccess = sendMsg(HEART_BEAT_STRING);//就发送一个HEART_BEAT_STRING过去 如果发送失败,就重新初始化一个socket | |
| 51 | + if (!isSuccess) { | |
| 52 | + Log.d(TAG, "heart beat error restart"); | |
| 53 | + mHandler.removeCallbacks(heartBeatRunnable); | |
| 54 | + mReadThread.release(); | |
| 55 | + releaseLastSocket(mSocket); | |
| 56 | + new InitSocketThread().start(); | |
| 57 | + } | |
| 58 | + } else { | |
| 59 | + Log.d(TAG, "heart beat less than beat rate"); | |
| 60 | + } | |
| 61 | + mHandler.postDelayed(this, HEART_BEAT_RATE); | |
| 62 | + } | |
| 63 | + }; | |
| 64 | + | |
| 65 | + private long sendTime = 0L; | |
| 66 | + | |
| 67 | + @Override | |
| 68 | + public IBinder onBind(Intent arg0) { | |
| 69 | + return null; | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public void onCreate() { | |
| 74 | + super.onCreate(); | |
| 75 | + gson = new Gson(); | |
| 76 | + new InitSocketThread().start(); | |
| 77 | + Log.d(TAG, "socket service onCreate"); | |
| 78 | +// mLocalBroadcastManager = LocalBroadcastManager.getInstance(this); | |
| 79 | + | |
| 80 | + } | |
| 81 | + | |
| 82 | + public boolean sendMsg(String msg) { | |
| 83 | + if (null == mSocket || null == mSocket.get()) { | |
| 84 | + return false; | |
| 85 | + } | |
| 86 | + Log.d(TAG, msg); | |
| 87 | + Socket soc = mSocket.get(); | |
| 88 | + try { | |
| 89 | + if (!soc.isClosed() && !soc.isOutputShutdown()) { | |
| 90 | + OutputStream os = soc.getOutputStream(); | |
| 91 | + String message = msg; | |
| 92 | + os.write(message.getBytes()); | |
| 93 | + os.flush(); | |
| 94 | + sendTime = System.currentTimeMillis();//每次发送成数据,就改一下最后成功发送的时间,节省心跳间隔时间 | |
| 95 | + } else { | |
| 96 | + return false; | |
| 97 | + } | |
| 98 | + } catch (IOException e) { | |
| 99 | + e.printStackTrace(); | |
| 100 | + return false; | |
| 101 | + } | |
| 102 | + return true; | |
| 103 | + } | |
| 104 | + | |
| 105 | + private void initSocket() {//初始化Socket | |
| 106 | + try { | |
| 107 | + Socket so = new Socket(HOST, PORT); | |
| 108 | + mSocket = new WeakReference<Socket>(so); | |
| 109 | + mReadThread = new ReadThread(so); | |
| 110 | + mReadThread.start(); | |
| 111 | +// new Thread(heartBeatRunnable).start(); | |
| 112 | +// mHandler.post(heartBeatRunnable);//初始化成功后,就准备发送心跳包 | |
| 113 | + new HeatBeat(so).start();//上面的 one plus 3t NetworkOnMainThreadException!!! | |
| 114 | + } catch (UnknownHostException e) { | |
| 115 | + e.printStackTrace(); | |
| 116 | + } catch (IOException e) { | |
| 117 | + e.printStackTrace(); | |
| 118 | + } | |
| 119 | + } | |
| 120 | + | |
| 121 | + private void releaseLastSocket(WeakReference<Socket> mSocket) { | |
| 122 | + try { | |
| 123 | + if (null != mSocket) { | |
| 124 | + Socket sk = mSocket.get(); | |
| 125 | + if (!sk.isClosed()) { | |
| 126 | + sk.close(); | |
| 127 | + } | |
| 128 | + sk = null; | |
| 129 | + mSocket = null; | |
| 130 | + } | |
| 131 | + } catch (IOException e) { | |
| 132 | + e.printStackTrace(); | |
| 133 | + } | |
| 134 | + } | |
| 135 | + | |
| 136 | + class InitSocketThread extends Thread { | |
| 137 | + @Override | |
| 138 | + public void run() { | |
| 139 | + super.run(); | |
| 140 | + initSocket(); | |
| 141 | + } | |
| 142 | + } | |
| 143 | + | |
| 144 | + // Thread to read content from Socket | |
| 145 | + class ReadThread extends Thread { | |
| 146 | + private WeakReference<Socket> mWeakSocket; | |
| 147 | + private boolean isStart = true; | |
| 148 | + | |
| 149 | + public ReadThread(Socket socket) { | |
| 150 | + mWeakSocket = new WeakReference<Socket>(socket); | |
| 151 | + } | |
| 152 | + | |
| 153 | + public void release() { | |
| 154 | + isStart = false; | |
| 155 | + releaseLastSocket(mWeakSocket); | |
| 156 | + } | |
| 157 | + | |
| 158 | + @Override | |
| 159 | + public void run() { | |
| 160 | + super.run(); | |
| 161 | + Socket socket = mWeakSocket.get(); | |
| 162 | + if (null != socket) { | |
| 163 | + try { | |
| 164 | + if (!sendRegister) { | |
| 165 | + Log.d(TAG, "send register mes"); | |
| 166 | + String msg = "{\"cmd\":\"register\",\"data\":{\"room_sn\":\"000002\"}}\\r\\n\\r\\n"; | |
| 167 | + sendMsg(msg); | |
| 168 | + Log.d(TAG, "" + msg); | |
| 169 | + sendRegister = true; | |
| 170 | + } | |
| 171 | + Log.d(TAG, "send register mes end"); | |
| 172 | + InputStream is = socket.getInputStream(); | |
| 173 | + byte[] buffer = new byte[1024 * 4]; | |
| 174 | + int length = 0; | |
| 175 | + while (!socket.isClosed() && !socket.isInputShutdown() | |
| 176 | + && isStart && ((length = is.read(buffer)) != -1)) { | |
| 177 | + if (length > 0) { | |
| 178 | + String message = new String(Arrays.copyOf(buffer, | |
| 179 | + length)).trim(); | |
| 180 | + Log.d(TAG, message); | |
| 181 | + try { | |
| 182 | + SocketResponse socketResponse = gson.fromJson(message.trim(), SocketResponse.class); | |
| 183 | + switch (socketResponse.getCode()) { | |
| 184 | + case 1001: | |
| 185 | + sendMsg("{\"cmd\":\"reconnect\",\"data\":{\"room_sn\":\"000002\"}}\\r\\n\\r\\n"); | |
| 186 | + Log.d(TAG, "send reconnect mes"); | |
| 187 | + break; | |
| 188 | + case 1002: | |
| 189 | + Log.d(TAG, "re init socket"); | |
| 190 | + // sendRegister = false; | |
| 191 | + releaseLastSocket(mWeakSocket); | |
| 192 | + initSocket(); | |
| 193 | + break; | |
| 194 | + } | |
| 195 | + if (("openDoor").equals(socketResponse.getCmd())) { | |
| 196 | + MessageEvent messageEvent = new MessageEvent(); | |
| 197 | + messageEvent.setEventId(1701); | |
| 198 | + messageEvent.setMessage("click item"); | |
| 199 | + EventBus.getDefault().post(messageEvent); | |
| 200 | + } | |
| 201 | + } catch (JsonSyntaxException e) { | |
| 202 | + Log.d(TAG, message); | |
| 203 | + e.printStackTrace(); | |
| 204 | + } | |
| 205 | + //收到服务器过来的消息,就通过Broadcast发送出去 | |
| 206 | +// if (message.equals(HEART_BEAT_STRING)) {//处理心跳回复 | |
| 207 | +// Intent intent = new Intent(HEART_BEAT_ACTION); | |
| 208 | +// mLocalBroadcastManager.sendBroadcast(intent); | |
| 209 | +// } else { | |
| 210 | +// //其他消息回复 | |
| 211 | +// Intent intent = new Intent(MESSAGE_ACTION); | |
| 212 | +// intent.putExtra("message", message); | |
| 213 | +// mLocalBroadcastManager.sendBroadcast(intent); | |
| 214 | +// } | |
| 215 | + } | |
| 216 | + } | |
| 217 | + } catch (IOException e) { | |
| 218 | + e.printStackTrace(); | |
| 219 | + } | |
| 220 | + } | |
| 221 | + } | |
| 222 | + } | |
| 223 | + | |
| 224 | + boolean sendRegister = false; | |
| 225 | + | |
| 226 | + | |
| 227 | + // Thread to read content from Socket | |
| 228 | + class HeatBeat extends Thread { | |
| 229 | + private WeakReference<Socket> mWeakSocket; | |
| 230 | + private boolean isStart = true; | |
| 231 | + | |
| 232 | + public HeatBeat(Socket socket) { | |
| 233 | + mWeakSocket = new WeakReference<Socket>(socket); | |
| 234 | + } | |
| 235 | + | |
| 236 | + @Override | |
| 237 | + public void run() { | |
| 238 | + super.run(); | |
| 239 | + Socket socket = mWeakSocket.get(); | |
| 240 | + if (null != socket) { | |
| 241 | + while (true) { | |
| 242 | + if (System.currentTimeMillis() - sendTime >= HEART_BEAT_RATE) { | |
| 243 | + Log.d(TAG, "heart beat"); | |
| 244 | + boolean isSuccess = sendMsg(HEART_BEAT_STRING);//就发送一个HEART_BEAT_STRING过去 如果发送失败,就重新初始化一个socket | |
| 245 | + if (!isSuccess) { | |
| 246 | + Log.d(TAG, "heart beat error restart"); | |
| 247 | +// mHandler.removeCallbacks(heartBeatRunnable); | |
| 248 | + mReadThread.release(); | |
| 249 | + releaseLastSocket(mSocket); | |
| 250 | + new InitSocketThread().start(); | |
| 251 | + } | |
| 252 | + } else { | |
| 253 | + Log.d(TAG, "heart beat less than beat rate"); | |
| 254 | + } | |
| 255 | + try { | |
| 256 | + Thread.sleep(HEART_BEAT_RATE); | |
| 257 | + } catch (InterruptedException e) { | |
| 258 | + e.printStackTrace(); | |
| 259 | + } | |
| 260 | + } | |
| 261 | + } | |
| 262 | + } | |
| 263 | + } | |
| 264 | + | |
| 265 | + @Override | |
| 266 | + public void onDestroy() { | |
| 267 | + super.onDestroy(); | |
| 268 | + Log.d(TAG, "socket service destroy"); | |
| 269 | + } | |
| 270 | +} | |
| \ No newline at end of file | ... | ... |
| ... | ... | @@ -52,6 +52,7 @@ import com.gimi.common.cinema.model.ClassificationItem; |
| 52 | 52 | import com.gimi.common.cinema.model.Constant; |
| 53 | 53 | import com.gimi.common.cinema.model.FolderItem; |
| 54 | 54 | import com.gimi.common.cinema.model.LocalMovieMessage; |
| 55 | +import com.gimi.common.cinema.model.MessageEvent; | |
| 55 | 56 | import com.gimi.common.cinema.utils.AuthUtils; |
| 56 | 57 | import com.gimi.common.cinema.utils.LeeImageLoader; |
| 57 | 58 | import com.gimi.common.cinema.utils.M1905Utils; |
| ... | ... | @@ -86,6 +87,10 @@ import com.xgimi.gimicinema.view.ClazzItem; |
| 86 | 87 | import com.xgimi.gimicinema.view.MovieItem; |
| 87 | 88 | import com.xgimi.gimicinema.view.OrderRecyclerView; |
| 88 | 89 | |
| 90 | +import org.greenrobot.eventbus.EventBus; | |
| 91 | +import org.greenrobot.eventbus.Subscribe; | |
| 92 | +import org.greenrobot.eventbus.ThreadMode; | |
| 93 | + | |
| 89 | 94 | import java.text.SimpleDateFormat; |
| 90 | 95 | import java.util.ArrayList; |
| 91 | 96 | import java.util.Date; |
| ... | ... | @@ -145,8 +150,10 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen |
| 145 | 150 | mApplication = (FangTangApplication) getApplication(); |
| 146 | 151 | mApplication.doInit(); |
| 147 | 152 | setContentView(R.layout.a_main); |
| 153 | + EventBus.getDefault().register(this); | |
| 154 | + | |
| 148 | 155 | initLight(); |
| 149 | - initLock(); | |
| 156 | +// initLock(); | |
| 150 | 157 | context = this; |
| 151 | 158 | mData = new ArrayList<>(); |
| 152 | 159 | clazzData = new ArrayList<>(); |
| ... | ... | @@ -595,6 +602,7 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen |
| 595 | 602 | super.onDestroy(); |
| 596 | 603 | presenter.umountSamba(); |
| 597 | 604 | unregisterReceiver(mReceiver); |
| 605 | + EventBus.getDefault().unregister(this); | |
| 598 | 606 | } |
| 599 | 607 | |
| 600 | 608 | |
| ... | ... | @@ -836,4 +844,20 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen |
| 836 | 844 | filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY - 1); |
| 837 | 845 | registerReceiver(mReceiver, filter); |
| 838 | 846 | } |
| 847 | + | |
| 848 | + @Subscribe(threadMode = ThreadMode.MAIN) | |
| 849 | + public void onMoonEvent(MessageEvent messageEvent) { | |
| 850 | + switch (messageEvent.getEventId()) { | |
| 851 | + case 0: | |
| 852 | + Log.d("event bus", messageEvent.getMessage()); | |
| 853 | + break; | |
| 854 | + case 1: | |
| 855 | + Log.d("event bus", messageEvent.getMessage()); | |
| 856 | + break; | |
| 857 | + case 1701: | |
| 858 | + initLock(); | |
| 859 | + Log.d("event bus", messageEvent.getMessage()); | |
| 860 | + break; | |
| 861 | + } | |
| 862 | + } | |
| 839 | 863 | } | ... | ... |
| ... | ... | @@ -36,8 +36,6 @@ import java.util.ArrayList; |
| 36 | 36 | import java.util.Collections; |
| 37 | 37 | import java.util.HashMap; |
| 38 | 38 | |
| 39 | -import static android.R.attr.path; | |
| 40 | - | |
| 41 | 39 | /** |
| 42 | 40 | * Created by wugian on 2016/9/28 |
| 43 | 41 | */ |
| ... | ... | @@ -73,15 +71,14 @@ public class OtherModelImpl implements IOtherModel { |
| 73 | 71 | |
| 74 | 72 | com.gimi.common.cinema.model.CinemaConfig cfgSmb = |
| 75 | 73 | FileReadUtils.readConfigBySamba(localPath + ".time"); |
| 76 | - if (cfgLocal == null || (cfgLocal.getClassArray() != null && | |
| 77 | - cfgLocal.getClassArray().length < 1)) { | |
| 74 | + if (cfgLocal == null /*|| (cfgLocal.getClassArray() != null && | |
| 75 | + cfgLocal.getClassArray().length < 1)*/) { | |
| 78 | 76 | return; |
| 79 | 77 | } |
| 80 | 78 | |
| 81 | 79 | if (cfgLocal.getClassVersion() < cfgSmb.getClassVersion()) { |
| 82 | - if (cfgSmb.getClassArray() != null | |
| 83 | - && cfgSmb.getClassArray().length > 0) { | |
| 84 | - StringBuilder stringBuilder = new StringBuilder(); | |
| 80 | + StringBuilder stringBuilder = new StringBuilder(); | |
| 81 | + if (cfgSmb.getClassArray() != null && cfgSmb.getClassArray().length > 0) { | |
| 85 | 82 | for (String trim : cfgSmb.getClassArray()) { |
| 86 | 83 | if (!trim.isEmpty()) { |
| 87 | 84 | if (stringBuilder.length() != 0) { |
| ... | ... | @@ -90,18 +87,18 @@ public class OtherModelImpl implements IOtherModel { |
| 90 | 87 | stringBuilder.append(trim); |
| 91 | 88 | } |
| 92 | 89 | } |
| 93 | - SharedPreferences.Editor edit = sp.edit(); | |
| 94 | - edit.putString("classifications", stringBuilder.toString()); | |
| 95 | - edit.putInt("classifications-version", | |
| 96 | - cfgSmb.getClassVersion()); | |
| 97 | - edit.apply(); | |
| 98 | - handler.post(new Runnable() { | |
| 99 | - @Override | |
| 100 | - public void run() { | |
| 101 | - l.onUpdateClazzSuccess(); | |
| 102 | - } | |
| 103 | - }); | |
| 104 | 90 | } |
| 91 | + SharedPreferences.Editor edit = sp.edit(); | |
| 92 | + edit.putString("classifications", stringBuilder.toString()); | |
| 93 | + edit.putInt("classifications-version", | |
| 94 | + cfgSmb.getClassVersion()); | |
| 95 | + edit.apply(); | |
| 96 | + handler.post(new Runnable() { | |
| 97 | + @Override | |
| 98 | + public void run() { | |
| 99 | + l.onUpdateClazzSuccess(); | |
| 100 | + } | |
| 101 | + }); | |
| 105 | 102 | } else if (cfgLocal.getClassVersion() > cfgSmb.getClassVersion()) { |
| 106 | 103 | String content = new Gson().toJson(cfgLocal); |
| 107 | 104 | FileReadUtils.writeDates(msg.getConfigPath(), content, false); | ... | ... |
| ... | ... | @@ -90,6 +90,9 @@ public class CinemaControlService extends Service { |
| 90 | 90 | currentState = state; |
| 91 | 91 | Log.d("aidl", "state change," + currentPath + "," + duration + "," + currentPosition); |
| 92 | 92 | Log.d("aidl", "state change cinemaSMC not null"); |
| 93 | + if (true) { | |
| 94 | + return; | |
| 95 | + } | |
| 93 | 96 | switch (state) { |
| 94 | 97 | case 0://空闲 |
| 95 | 98 | // open(); | ... | ... |
switchcontrol/src/main/java/com/adroplat/fist_switch/utils/protocol/one/FistProtocol.java
0 → 100644
| 1 | +package com.adroplat.fist_switch.utils.protocol.one; | |
| 2 | + | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * 协议类 | |
| 6 | + * Created by WLJ on 2015/11/13. | |
| 7 | + */ | |
| 8 | +public class FistProtocol { | |
| 9 | + /** | |
| 10 | + * 包头 | |
| 11 | + */ | |
| 12 | + public static final byte[] COMMOND_PACKAGE_HEADER = {(byte) 0x83, (byte) 0xb3, (byte) 0xa9}; | |
| 13 | + /** | |
| 14 | + * 协议版本 | |
| 15 | + */ | |
| 16 | + public static final byte[] COMMOND_PROTOCOL_VERSION = {0x01, 0x00, 0x00, 0x00}; | |
| 17 | + /** | |
| 18 | + * 版本角标 | |
| 19 | + */ | |
| 20 | + public static final int INDEXT_OF_VERSION = COMMOND_PACKAGE_HEADER.length; | |
| 21 | + /** | |
| 22 | + * 命令类型角标 | |
| 23 | + */ | |
| 24 | + public static final int INDEXT_OF_CMD = COMMOND_PACKAGE_HEADER.length + COMMOND_PROTOCOL_VERSION.length; | |
| 25 | + /** | |
| 26 | + * 命令类型长度 | |
| 27 | + */ | |
| 28 | + public static final int LENGTH_OF_CMD = 1; | |
| 29 | + /** | |
| 30 | + * 包长角标 | |
| 31 | + */ | |
| 32 | + public static final int INDEXT_OF_PACKAGE_LENGTH = INDEXT_OF_CMD + LENGTH_OF_CMD; | |
| 33 | + /** | |
| 34 | + * 包长长度 | |
| 35 | + */ | |
| 36 | + public static final int LENGTH_OF_PACKAGE_LENGTH = 2; | |
| 37 | + /** | |
| 38 | + * 随机数角标 | |
| 39 | + */ | |
| 40 | + public static final int INDEXT_OF_RANDOM = INDEXT_OF_PACKAGE_LENGTH + LENGTH_OF_PACKAGE_LENGTH; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * 随机数长度 | |
| 44 | + */ | |
| 45 | + public static final int LENGTH_OF_RANDOM = 2; | |
| 46 | + /** | |
| 47 | + * 设备类型长度 | |
| 48 | + */ | |
| 49 | + public static final int LENGTH_OF_DEVICE_TYPE = 2; | |
| 50 | + /** | |
| 51 | + * 设备号角标 | |
| 52 | + */ | |
| 53 | + public static final int INDEXT_OF_DEVICE_NUM = INDEXT_OF_RANDOM + LENGTH_OF_RANDOM + LENGTH_OF_DEVICE_TYPE; | |
| 54 | + /** | |
| 55 | + * 设备号长度 | |
| 56 | + */ | |
| 57 | + public static final int LENGTH_OF_DEVICE_NUM = 6; | |
| 58 | + /** | |
| 59 | + * 设备ip角标 | |
| 60 | + */ | |
| 61 | + public static final int INDEXT_OF_DEVICE_IP = INDEXT_OF_DEVICE_NUM + LENGTH_OF_DEVICE_NUM; | |
| 62 | + /** | |
| 63 | + * 设备IP长度 | |
| 64 | + */ | |
| 65 | + public static final int LENGTH_OF_DEVICE_IP = 4; | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * UDP搜索响应包长 | |
| 69 | + */ | |
| 70 | + public static final byte COMMOND_UDP_QUERY_RESPONSE_DATA_LENGTH = 0x18; | |
| 71 | + /** | |
| 72 | + * 超时 | |
| 73 | + */ | |
| 74 | + public static final byte ERROR_CODE_TIMEOUT = (byte) 0xFE; | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * 在线状态 | |
| 78 | + */ | |
| 79 | + | |
| 80 | + public class OnlineState { | |
| 81 | + /** | |
| 82 | + * 未知 | |
| 83 | + */ | |
| 84 | + public static final int UNKNOW = 0; | |
| 85 | + /** | |
| 86 | + * 掉线 | |
| 87 | + */ | |
| 88 | + public static final int OFFLINE = 0x1; | |
| 89 | + /** | |
| 90 | + * 在线 | |
| 91 | + */ | |
| 92 | + public static final int ONLINE = 0x2; | |
| 93 | + /** | |
| 94 | + * 不存在 | |
| 95 | + */ | |
| 96 | + public static final int NOTHINGNESS = 0x20; | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * 命令类型 | |
| 101 | + */ | |
| 102 | + public class CommondType { | |
| 103 | + /** | |
| 104 | + * 查询 | |
| 105 | + */ | |
| 106 | + public static final byte CMD_TYPE_QUERY = 0x10; | |
| 107 | + /** | |
| 108 | + * 查询反馈 | |
| 109 | + */ | |
| 110 | + public static final byte CMD_TYPE_QUERY_RESPONSE = 0x11; | |
| 111 | + /** | |
| 112 | + * 控制 | |
| 113 | + */ | |
| 114 | + public static final byte CMD_TYPE_CONTROL = 0x20; | |
| 115 | + /** | |
| 116 | + * 控制响应 | |
| 117 | + */ | |
| 118 | + public static final byte CMD_TYPE_CONTROL_RESPONSE = 0x21; | |
| 119 | + /** | |
| 120 | + * 子设备控制完毕响应包 | |
| 121 | + */ | |
| 122 | + public static final byte CMD_TYPE_CONTROL_DONE_RESPONSE = 0x22; | |
| 123 | + /** | |
| 124 | + * 命令控制完毕响应包: | |
| 125 | + */ | |
| 126 | + public static final byte CMD_TYPE_CONTROL_OVER = 0x23; | |
| 127 | + /** | |
| 128 | + * UDP搜索 | |
| 129 | + */ | |
| 130 | + public static final byte CMD_TYPE_SEARCH = 0x30; | |
| 131 | + /** | |
| 132 | + * UDP搜索响应 | |
| 133 | + */ | |
| 134 | + public static final byte CMD_TYPE_SEARCH_RESPONSE = 0x31; | |
| 135 | + /** | |
| 136 | + * 配置完成通知 | |
| 137 | + */ | |
| 138 | + public static final byte CMD_TYPE_CONFIG_DONE = 0x32; | |
| 139 | + /** | |
| 140 | + * 设备启动、网络重连通知包 | |
| 141 | + */ | |
| 142 | + public static final byte CMD_TYPE_ONLINE = 0x33; | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * 子设备入网申请 | |
| 146 | + */ | |
| 147 | + public static final byte CMD_TYPE_ADD = 0x40; | |
| 148 | + /** | |
| 149 | + * 子设备入网申请响应 | |
| 150 | + */ | |
| 151 | + public static final byte CMD_TYPE_ADD_RESPONSE = 0x41; | |
| 152 | + /** | |
| 153 | + * 子设备入网结束 | |
| 154 | + */ | |
| 155 | + public static final byte CMD_TYPE_ADD_OVER = 0x42; | |
| 156 | + /** | |
| 157 | + * 子设备入网结束响应 | |
| 158 | + */ | |
| 159 | + public static final byte CMD_TYPE_ADD_OVER_RESPONSE = 0x43; | |
| 160 | + /** | |
| 161 | + * 开关删除 | |
| 162 | + */ | |
| 163 | + public static final byte CMD_TYPE_DELETE = 0x50; | |
| 164 | + /** | |
| 165 | + * 开关删除响应 | |
| 166 | + */ | |
| 167 | + public static final byte CMD_TYPE_DELETE_RESPONSE = 0x51; | |
| 168 | + /** | |
| 169 | + * 网关工作模式查询包命令类型 | |
| 170 | + */ | |
| 171 | + public static final byte CMD_DEVICE_MODEL_REQUEST = 0x60; | |
| 172 | + /** | |
| 173 | + * 网关工作模式响应包命令类型 | |
| 174 | + */ | |
| 175 | + public static final byte CMD_DEVICE_MODEL_RESPONSE = 0x61; | |
| 176 | + /** | |
| 177 | + * 软件版本查询包命令类型 | |
| 178 | + */ | |
| 179 | + public static final byte CMD_SOFTWARE_VER_REQUEST = 0x70; | |
| 180 | + /** | |
| 181 | + * 软件版本响应包命令类型 | |
| 182 | + */ | |
| 183 | + public static final byte CMD_SOFTWARE_VER_RESPONSE = 0x71; | |
| 184 | + /** | |
| 185 | + * 链接路由器包命令类型 | |
| 186 | + */ | |
| 187 | + public static final byte CMD_LINK_REQUEST = (byte) 0x80; | |
| 188 | + /** | |
| 189 | + * 链接路由器响应包命令类型 | |
| 190 | + */ | |
| 191 | + public static final char CMD_LINK_RESPONSE = 0x81; | |
| 192 | + /** | |
| 193 | + * 修改SSID和密码包命令类型 | |
| 194 | + */ | |
| 195 | + public static final byte CMD_MODIFY_SSID_AND_PWD_REQUEST = (byte) 0x90; | |
| 196 | + /** | |
| 197 | + * 修改SSID和密码响应包命令类型 | |
| 198 | + */ | |
| 199 | + public static final char CMD_MODIFY_SSID_AND_PWD_RESPONSE = 0x91; | |
| 200 | + /** | |
| 201 | + * 修改控制密码包命令类型 | |
| 202 | + */ | |
| 203 | + public static final byte CMD_MODIFY_CTRL_AND_PWD_REQUEST = (byte) 0x92; | |
| 204 | + /** | |
| 205 | + * 修改控制密码响应包命令类型 | |
| 206 | + */ | |
| 207 | + public static final char CMD_MODIFY_CTRL_PWD_RESPONSE = 0x93; | |
| 208 | + /** | |
| 209 | + * 获取主机联网状态命令类型 | |
| 210 | + */ | |
| 211 | + public static final byte CMD_NET_LINK_STATUS = (byte) 0xA0; | |
| 212 | + /** | |
| 213 | + * 获取主机联网状态响应包命令类型 | |
| 214 | + */ | |
| 215 | + public static final char CMD_NET_LINK_STATUS_RESPONSE = 0xA1; | |
| 216 | + /** | |
| 217 | + * 获取主机联网状态命令类型 | |
| 218 | + */ | |
| 219 | + public static final byte CMD_ROUTER_LIST_REQUEST = (byte) 0xB0; | |
| 220 | + /** | |
| 221 | + * 获取主机联网状态响应包命令类型 | |
| 222 | + */ | |
| 223 | + public static final char CMD_ROUTER_LIST_RESPONSE = 0xB1; | |
| 224 | + } | |
| 225 | +} | ... | ... |
Please
register
or
login
to post a comment