Commit bd21bf061957cf272152ba4993eaaaf82262e75f
1 parent
698fd4e0
编译通过
Showing
3 changed files
with
330 additions
and
4 deletions
C5/xpadapi/src/main/java/com/sunvote/xpadapi/service/logic/RFMessageUploadModule.java
... | ... | @@ -3,6 +3,9 @@ package com.sunvote.xpadapi.service.logic; |
3 | 3 | import android.os.Handler; |
4 | 4 | import android.os.HandlerThread; |
5 | 5 | |
6 | +import com.sunvote.xpadapi.service.listener.IUploadListener; | |
7 | +import com.sunvote.xpadapi.util.LogUtil; | |
8 | + | |
6 | 9 | import java.io.UnsupportedEncodingException; |
7 | 10 | |
8 | 11 | /** |
... | ... | @@ -164,7 +167,7 @@ public class RFMessageUploadModule { |
164 | 167 | |
165 | 168 | @Override |
166 | 169 | public void run() { |
167 | - XPadApi.getInstance().applyFileUpload(this.length,this.filename,PACKTYPE,RFFileUploadModule.index); | |
170 | + XpadApiServiceInfoProxyManager.getInstance().getService().applyFileUpload(this.length,this.filename,PACKTYPE,RFFileUploadModule.index); | |
168 | 171 | } |
169 | 172 | } |
170 | 173 | |
... | ... | @@ -188,7 +191,7 @@ public class RFMessageUploadModule { |
188 | 191 | |
189 | 192 | @Override |
190 | 193 | public void run() { |
191 | - XPadApi.getInstance().packetConfirmation(this.keyid,this.packid,this.packH,this.packL,this.names,PACKTYPE); | |
194 | + XpadApiServiceInfoProxyManager.getInstance().getService().packetConfirmation(this.keyid,this.packid,this.packH,this.packL,this.names,PACKTYPE); | |
192 | 195 | times ++ ; |
193 | 196 | if(task != null && times < 5){ |
194 | 197 | handler.postDelayed(task,1000); |
... | ... | @@ -229,7 +232,7 @@ public class RFMessageUploadModule { |
229 | 232 | for(byte packL = 0 ;packL < 16 ;packL ++) { |
230 | 233 | if((packLsi & (1 << packL)) != 0){ |
231 | 234 | offset = ((packid * 65535) + (packH) * 256 + 16 * (packL)) & 0xFFFF; |
232 | - XPadApi.getInstance().uploadFileData(this.keyid, this.packid, this.packH, (byte)(packL), this.datas, offset, length,PACKTYPE); | |
235 | + XpadApiServiceInfoProxyManager.getInstance().getService().uploadFileData(this.keyid, this.packid, this.packH, (byte)(packL), this.datas, offset, length,PACKTYPE); | |
233 | 236 | try{ |
234 | 237 | Thread.sleep(50); |
235 | 238 | } catch (Exception e) { |
... | ... | @@ -259,7 +262,7 @@ public class RFMessageUploadModule { |
259 | 262 | |
260 | 263 | @Override |
261 | 264 | public void run() { |
262 | - XPadApi.getInstance().packetReceptionConfirmed(this.keyid,this.packid,this.packH,PACKTYPE); | |
265 | + XpadApiServiceInfoProxyManager.getInstance().getService().packetReceptionConfirmed(this.keyid,this.packid,this.packH,PACKTYPE); | |
263 | 266 | if(uploadListener != null){ |
264 | 267 | uploadListener.onUploadStop(); |
265 | 268 | } | ... | ... |
C5/xpadapi/src/main/java/com/sunvote/xpadapi/util/LogUtil.java
0 → 100644
1 | +package com.sunvote.xpadapi.util; | |
2 | + | |
3 | +import android.os.Environment; | |
4 | +import android.util.Log; | |
5 | + | |
6 | +import com.sunvote.util.ByteUtils; | |
7 | + | |
8 | +import java.io.File; | |
9 | +import java.io.FileWriter; | |
10 | +import java.io.IOException; | |
11 | +import java.text.SimpleDateFormat; | |
12 | +import java.util.Date; | |
13 | + | |
14 | +/** | |
15 | + * Created by Elvis on 2017/8/15 15:03 | |
16 | + * Email:Eluis@psunsky.com | |
17 | + * 版权所有:长沙中天电子设计开发有限公司 | |
18 | + * Description: 工具包 | |
19 | + */ | |
20 | +public class LogUtil { | |
21 | + | |
22 | + private static FileWriter fileWriter; | |
23 | + | |
24 | + public static final int VERBOSE_LEVER = 2; | |
25 | + public static final int DEBUG_LEVER = 3; | |
26 | + public static final int INFO_LEVER = 4; | |
27 | + public static final int WARN_LEVER = 5; | |
28 | + public static final int ERROR_LEVER = 6; | |
29 | + public static final int ASSERT_LEVER = 7; | |
30 | + | |
31 | + public static int lever = VERBOSE_LEVER - 1 ; | |
32 | + | |
33 | + private static boolean logToFile = false; | |
34 | + private static boolean logToLogcat = true ; | |
35 | + | |
36 | + public static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS"); | |
37 | + | |
38 | + LogUtil() { | |
39 | + throw new RuntimeException("Stub!"); | |
40 | + } | |
41 | + | |
42 | + public static int v(String tag, String msg) { | |
43 | + if (VERBOSE_LEVER > lever) { | |
44 | + if(logToLogcat){ | |
45 | + Log.v(tag, msg); | |
46 | + } | |
47 | + inputToFile("(V):" + msg ); | |
48 | + } | |
49 | + return -1; | |
50 | + } | |
51 | + | |
52 | + private static void init(){ | |
53 | + if(fileWriter == null){ | |
54 | + synchronized (LogUtil.class) { | |
55 | + if(fileWriter == null) { | |
56 | + try { | |
57 | + File path = new File(Environment.getExternalStorageDirectory().getPath() + "/Sunvote/"); | |
58 | + if (!path.exists()) { | |
59 | + path.mkdirs(); | |
60 | + } | |
61 | + File file = new File(Environment.getExternalStorageDirectory().getPath() | |
62 | + + "/Sunvote/log" + simpleDateFormat.format(new Date())+".txt"); | |
63 | + if (!file.exists()) { | |
64 | + file.createNewFile(); | |
65 | + } | |
66 | + fileWriter = new FileWriter(file, true); | |
67 | + | |
68 | + } catch (Exception ex) { | |
69 | + ex.printStackTrace(); | |
70 | + fileWriter = null; | |
71 | + } | |
72 | + } | |
73 | + } | |
74 | + } | |
75 | + } | |
76 | + | |
77 | + public static void enableLogToFile(){ | |
78 | + logToFile = true; | |
79 | + } | |
80 | + | |
81 | + public static void disabelLogToFile(){ | |
82 | + logToFile = false; | |
83 | + } | |
84 | + | |
85 | + public static void enableLogToLogcat(){ | |
86 | + logToLogcat = true; | |
87 | + } | |
88 | + | |
89 | + public static void disableLogToLogcat(){ | |
90 | + logToLogcat = false; | |
91 | + } | |
92 | + | |
93 | + public static void enableLog(){ | |
94 | + lever = VERBOSE_LEVER - 1; | |
95 | + } | |
96 | + | |
97 | + public static void disableLog(){ | |
98 | + lever = ASSERT_LEVER ; | |
99 | + } | |
100 | + | |
101 | + public static int v(String tag, String msg, Throwable tr) { | |
102 | + if(VERBOSE_LEVER > lever){ | |
103 | + if(logToLogcat) { | |
104 | + Log.v(tag, msg, tr); | |
105 | + } | |
106 | + inputToFile("(V):" + tag + " " + msg + Log.getStackTraceString(tr)); | |
107 | + } | |
108 | + return -1; | |
109 | + } | |
110 | + | |
111 | + public static int d(String tag, String msg) { | |
112 | + if(DEBUG_LEVER > lever){ | |
113 | + if(logToLogcat) { | |
114 | + Log.d(tag, msg); | |
115 | + } | |
116 | + inputToFile("(D):" + tag + " " + msg ); | |
117 | + } | |
118 | + return -1; | |
119 | + } | |
120 | + | |
121 | + public static int d(String tag, String msg, Throwable tr) { | |
122 | + if(DEBUG_LEVER > lever){ | |
123 | + if(logToLogcat){ | |
124 | + Log.d(tag,msg,tr); | |
125 | + } | |
126 | + inputToFile("(D):" + tag + " " + msg + Log.getStackTraceString(tr)); | |
127 | + } | |
128 | + return -1; | |
129 | + } | |
130 | + | |
131 | + public static int i(String tag, String msg) { | |
132 | + if(INFO_LEVER > lever){ | |
133 | + if(logToLogcat){ | |
134 | + Log.i(tag,msg); | |
135 | + } | |
136 | + inputToFile("(I):" + tag + " " + msg ); | |
137 | + } | |
138 | + return -1; | |
139 | + } | |
140 | + | |
141 | + public static int i(String tag, String msg, Throwable tr) { | |
142 | + if(INFO_LEVER > lever){ | |
143 | + if(logToLogcat){ | |
144 | + Log.i(tag,msg,tr); | |
145 | + } | |
146 | + inputToFile("(I):" + tag + " " + msg + Log.getStackTraceString(tr)); | |
147 | + } | |
148 | + return -1; | |
149 | + } | |
150 | + | |
151 | + public static int i(String tag,byte[] msg){ | |
152 | + String msgStr = ByteUtils.bytesToHexString(msg); | |
153 | + return i(tag,msgStr); | |
154 | + } | |
155 | + | |
156 | + public static int i(String tag,String msgTag, byte[] msg){ | |
157 | + String msgStr = ByteUtils.bytesToHexString(msg); | |
158 | + return i(tag,msgTag + ":\r\n" + msgStr); | |
159 | + } | |
160 | + | |
161 | + public static int v(String tag,String msgTag, byte[] msg){ | |
162 | + String msgStr = ByteUtils.bytesToHexString(msg); | |
163 | + return v(tag,msgTag + ":\r\n" + msgStr); | |
164 | + } | |
165 | + | |
166 | + public static int i(String tag,String msgTag, byte[] msg,int length){ | |
167 | + String msgStr = ByteUtils.bytesToHexString(msg,length); | |
168 | + return i(tag,msgTag + ":\r\n" + msgStr); | |
169 | + } | |
170 | + | |
171 | + public static int v(String tag,String msgTag, byte[] msg,int length){ | |
172 | + String msgStr = ByteUtils.bytesToHexString(msg,length); | |
173 | + return v(tag,msgTag + ":\r\n" + msgStr); | |
174 | + } | |
175 | + | |
176 | + public static int i(String tag,byte[] msg,Throwable tr){ | |
177 | + String msgStr = ByteUtils.bytesToHexString(msg); | |
178 | + return i(tag,msgStr,tr); | |
179 | + } | |
180 | + | |
181 | + public static int i(String tag,String msgTag,byte[] msg,Throwable tr){ | |
182 | + String msgStr = ByteUtils.bytesToHexString(msg); | |
183 | + return i(tag,msgTag + ":\r\n" + msgStr,tr); | |
184 | + } | |
185 | + | |
186 | + public static int w(String tag, String msg) { | |
187 | + if(WARN_LEVER > lever){ | |
188 | + if(logToLogcat){ | |
189 | + Log.w(tag,msg); | |
190 | + } | |
191 | + inputToFile("(V):" + msg); | |
192 | + } | |
193 | + return -1; | |
194 | + } | |
195 | + | |
196 | + public static int w(String tag, String msg, Throwable tr) { | |
197 | + if(WARN_LEVER > lever){ | |
198 | + if(logToLogcat){ | |
199 | + Log.w(tag,msg,tr); | |
200 | + } | |
201 | + inputToFile("(W):" + tag + " " + msg + Log.getStackTraceString(tr)); | |
202 | + } | |
203 | + return -1; | |
204 | + } | |
205 | + | |
206 | + public static boolean isLoggable(String s, int i){ | |
207 | + return Log.isLoggable(s,i); | |
208 | + } | |
209 | + | |
210 | + public static int w(String tag, Throwable tr) { | |
211 | + if(WARN_LEVER > lever){ | |
212 | + if(logToLogcat){ | |
213 | + Log.w(tag,tr); | |
214 | + } | |
215 | + inputToFile("(W):" + tag + " " + Log.getStackTraceString(tr)); | |
216 | + } | |
217 | + return -1; | |
218 | + } | |
219 | + | |
220 | + public static int e(String tag, String msg) { | |
221 | + if(ERROR_LEVER > lever){ | |
222 | + if(logToLogcat){ | |
223 | + Log.e(tag,msg); | |
224 | + } | |
225 | + inputToFile("(E):" + tag + " " + msg); | |
226 | + } | |
227 | + return -1; | |
228 | + } | |
229 | + | |
230 | + public static int e(String tag,Throwable tr){ | |
231 | + String message = "ERROR" ; | |
232 | + if(tr != null && tr.getMessage() != null){ | |
233 | + message = tr.getMessage(); | |
234 | + } | |
235 | + return e(tag,message,tr); | |
236 | + } | |
237 | + | |
238 | + public static int e(String tag, String msg, Throwable tr) { | |
239 | + if(ERROR_LEVER > lever){ | |
240 | + if(logToLogcat){ | |
241 | + Log.e(tag,msg,tr); | |
242 | + } | |
243 | + inputToFile("(E):" + tag + " " + msg + Log.getStackTraceString(tr)); | |
244 | + } | |
245 | + return -1; | |
246 | + } | |
247 | + | |
248 | + public static int wtf(String tag, String msg) { | |
249 | + if(ASSERT_LEVER > lever){ | |
250 | + if(logToLogcat){ | |
251 | + Log.wtf(tag,msg); | |
252 | + } | |
253 | + inputToFile("(WTF):" + tag + " " + msg); | |
254 | + } | |
255 | + return -1; | |
256 | + } | |
257 | + | |
258 | + public static int wtf(String tag, Throwable tr) { | |
259 | + if(ASSERT_LEVER > lever){ | |
260 | + if(logToLogcat){ | |
261 | + Log.wtf(tag,tr); | |
262 | + } | |
263 | + inputToFile("(WTF):" + tag + " " + Log.getStackTraceString(tr)); | |
264 | + } | |
265 | + return -1; | |
266 | + } | |
267 | + | |
268 | + public static int wtf(String tag, String msg, Throwable tr) { | |
269 | + if(ASSERT_LEVER > lever){ | |
270 | + if(logToLogcat){ | |
271 | + Log.wtf(tag,msg,tr); | |
272 | + } | |
273 | + inputToFile("(WTF):" + tag + " " + msg + Log.getStackTraceString(tr)); | |
274 | + } | |
275 | + return -1; | |
276 | + } | |
277 | + | |
278 | + public static String getStackTraceString(Throwable tr) { | |
279 | + return Log.getStackTraceString(tr); | |
280 | + } | |
281 | + | |
282 | + | |
283 | + public static void stack(){ | |
284 | + Throwable throwable = new Throwable(); | |
285 | + // 需要处理TAG 要读出上面class method的信息,后续添上 | |
286 | + i("STACK",getStackTraceString(throwable)); | |
287 | + } | |
288 | + | |
289 | + private synchronized static void inputToFile(String msg){ | |
290 | + if(logToFile) { | |
291 | + String time = simpleDateFormat.format(new Date()); | |
292 | + try { | |
293 | + init(); | |
294 | + String log = time + "(" + Thread.currentThread().getName() + ",id=" + Thread.currentThread().getId() + ")" + msg + "\r\n"; | |
295 | + if(onLogMessage != null){ | |
296 | + onLogMessage.onLog(time + ":" + msg + "\r\n"); | |
297 | + } | |
298 | + fileWriter.write(log); | |
299 | + fileWriter.flush(); | |
300 | + } catch (Exception ex) { | |
301 | + ex.printStackTrace(); | |
302 | + if(fileWriter != null){ | |
303 | + try { | |
304 | + fileWriter.close(); | |
305 | + } catch (IOException e) { | |
306 | + e.printStackTrace(); | |
307 | + } | |
308 | + } | |
309 | + fileWriter = null; | |
310 | + } | |
311 | + } | |
312 | + } | |
313 | + | |
314 | + private static OnLogMessage onLogMessage; | |
315 | + | |
316 | + public static void setOnLogMessage(OnLogMessage onLogMessage) { | |
317 | + LogUtil.onLogMessage = onLogMessage; | |
318 | + } | |
319 | + | |
320 | + public static interface OnLogMessage{ | |
321 | + void onLog(String log); | |
322 | + } | |
323 | +} | ... | ... |
C5/xpadprotocal/build/libs/xpadprotocal.jar
No preview for this file type