17 // GetTRKVersion.cpp : Defines the entry point for the DLL application. |
17 // GetTRKVersion.cpp : Defines the entry point for the DLL application. |
18 // |
18 // |
19 |
19 |
20 #include "stdafx.h" |
20 #include "stdafx.h" |
21 #include "GetTRKVersion.h" |
21 #include "GetTRKVersion.h" |
22 #include "com_nokia_carbide_trk_support_onDeviceSetup_ui_CheckExistingTRKPage.h" |
|
23 #include "com_nokia_carbide_trk_support_service_TRKConnectedService.h" |
22 #include "com_nokia_carbide_trk_support_service_TRKConnectedService.h" |
24 |
23 |
25 |
24 |
26 BOOL APIENTRY DllMain( HANDLE hModule, |
25 BOOL APIENTRY DllMain( HANDLE hModule, |
27 DWORD ul_reason_for_call, |
26 DWORD ul_reason_for_call, |
238 return kNoPingError; |
237 return kNoPingError; |
239 |
238 |
240 return ERROR_SUCCESS; |
239 return ERROR_SUCCESS; |
241 } |
240 } |
242 |
241 |
|
242 static bool IsVersions3EnabledTRK(long major, long minor, long micro) |
|
243 { |
|
244 return major > 3 || (major == 3 && minor > 2) || (major == 3 && minor == 2 && micro >= 4); |
|
245 } |
|
246 |
243 |
247 |
244 __declspec(dllexport) |
248 __declspec(dllexport) |
245 DWORD GetTRKVersion(const char* inPortName, int baudIndex, int dataBits, int parity, int stopBits, int flowControl, long version[3]) |
249 DWORD GetTRKVersion(const char* inPortName, int baudIndex, int dataBits, int parity, int stopBits, int flowControl, long version[4]) |
246 { |
250 { |
247 // open the serial port |
251 // open the serial port |
248 HANDLE serialPortHandle = NULL; |
252 HANDLE serialPortHandle = NULL; |
249 DWORD error = OpenSerialPort(inPortName, baudIndex, dataBits, parity, stopBits, flowControl, serialPortHandle); |
253 DWORD error = OpenSerialPort(inPortName, baudIndex, dataBits, parity, stopBits, flowControl, serialPortHandle); |
250 if (error != ERROR_SUCCESS) |
254 if (error != ERROR_SUCCESS) |
259 } |
263 } |
260 |
264 |
261 // receive response |
265 // receive response |
262 unsigned char pingRxBuf[16]; |
266 unsigned char pingRxBuf[16]; |
263 unsigned long pingRxSize = 0; |
267 unsigned long pingRxSize = 0; |
264 error = ReceiveData(serialPortHandle, 2001, 16, pingRxBuf, pingRxSize); |
268 error = ReceiveData(serialPortHandle, 2001UL, 16, pingRxBuf, pingRxSize); |
265 if (error != ERROR_SUCCESS) { |
269 if (error != ERROR_SUCCESS) { |
266 Disconnect(serialPortHandle); |
270 Disconnect(serialPortHandle); |
267 return error; |
271 return error; |
268 } |
272 } |
269 |
273 |
276 } |
280 } |
277 |
281 |
278 // receive response |
282 // receive response |
279 unsigned char versRxBuf[16]; |
283 unsigned char versRxBuf[16]; |
280 unsigned long versRxSize = 0; |
284 unsigned long versRxSize = 0; |
281 error = ReceiveData(serialPortHandle, 2001, 16, versRxBuf, versRxSize); |
285 error = ReceiveData(serialPortHandle, 2001UL, 16, versRxBuf, versRxSize); |
282 if (error != ERROR_SUCCESS) { |
286 if (error != ERROR_SUCCESS) { |
283 Disconnect(serialPortHandle); |
287 Disconnect(serialPortHandle); |
284 if (error == kNoPingError) |
288 if (error == kNoPingError) |
285 return kNoVersionError; // ping ok, but no version |
289 return kNoVersionError; // ping ok, but no version |
286 return error; |
290 return error; |
287 } |
291 } |
288 |
292 |
289 if (versRxSize >= 9) |
293 if (versRxSize >= 9) { |
290 { |
|
291 version[0] = versRxBuf[4]; |
294 version[0] = versRxBuf[4]; |
292 version[1] = versRxBuf[5]; |
295 version[1] = versRxBuf[5]; |
293 version[2] = versRxBuf[8]; |
296 version[2] = versRxBuf[8]; |
294 } |
297 version[3] = 0; // unknown TRK |
|
298 |
|
299 if (IsVersions3EnabledTRK(version[0], version[1], version[2])) { |
|
300 // send versions3 command |
|
301 unsigned char vers3TxBuf[] = {0x7e, 0x51, 0x02, 0xac, 0x7e}; |
|
302 error = SendData(serialPortHandle, &vers3TxBuf, 5); |
|
303 if (error != ERROR_SUCCESS) { |
|
304 Disconnect(serialPortHandle); |
|
305 return error; |
|
306 } |
|
307 |
|
308 // receive response |
|
309 unsigned char vers3RxBuf[64]; |
|
310 unsigned long vers3RxSize = 0; |
|
311 error = ReceiveData(serialPortHandle, 2001UL, 64, vers3RxBuf, vers3RxSize); |
|
312 if (error != ERROR_SUCCESS) { |
|
313 Disconnect(serialPortHandle); |
|
314 return error; |
|
315 } |
|
316 |
|
317 version[3] = 1; // AppTRK |
|
318 unsigned char SYS_TRK_NAME[] = {0x0a, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x20, 0x54, 0x52, 0x4b}; |
|
319 unsigned long SYS_TRK_NAME_LEN = sizeof(SYS_TRK_NAME); |
|
320 const int SYS_TRK_NAME_OFFSET = 10; |
|
321 if (vers3RxSize >= (SYS_TRK_NAME_LEN + SYS_TRK_NAME_OFFSET)) { |
|
322 unsigned char nameBuf[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
|
323 memcpy(nameBuf, vers3RxBuf + SYS_TRK_NAME_OFFSET, SYS_TRK_NAME_LEN); |
|
324 if (memcmp(nameBuf, SYS_TRK_NAME, SYS_TRK_NAME_LEN) == 0) |
|
325 version[3] = 2; // SysTRK |
|
326 } |
|
327 } |
|
328 } |
|
329 |
295 |
330 |
296 Disconnect(serialPortHandle); |
331 Disconnect(serialPortHandle); |
297 return ERROR_SUCCESS; |
332 return ERROR_SUCCESS; |
298 } |
333 } |
299 |
334 |
321 return msg; |
356 return msg; |
322 } |
357 } |
323 |
358 |
324 |
359 |
325 /* |
360 /* |
326 * Class: com_nokia_carbide_trk_support_onDeviceSetup_ui_CheckExistingTRKPage |
|
327 * Method: getTRKVersion |
|
328 * Signature: (Ljava/lang/String;[I)V |
|
329 */ |
|
330 JNIEXPORT void JNICALL Java_com_nokia_carbide_trk_support_onDeviceSetup_ui_CheckExistingTRKPage_getTRKVersion |
|
331 (JNIEnv* env, jclass, jstring jPortName, jintArray jVersionInts) |
|
332 { |
|
333 const char* portName = env->GetStringUTFChars(jPortName, NULL); |
|
334 |
|
335 jint versionInts[3]; |
|
336 DWORD error = GetTRKVersion(portName, -1, 0, 0, 0, 0, versionInts); |
|
337 env->SetIntArrayRegion(jVersionInts, 0, 3, versionInts); |
|
338 |
|
339 env->ReleaseStringUTFChars(jPortName, portName); |
|
340 |
|
341 if (error > ERROR_SUCCESS) |
|
342 { |
|
343 |
|
344 jclass clazz = env->FindClass("Ljava/lang/Exception;"); |
|
345 env->ThrowNew(clazz, GetErrorText(error)); |
|
346 } |
|
347 |
|
348 } |
|
349 |
|
350 /* |
|
351 * Class: com_nokia_carbide_trk_support_service_TRKConnectedService |
361 * Class: com_nokia_carbide_trk_support_service_TRKConnectedService |
352 * Method: getTRKVersionFromSerial |
362 * Method: getTRKVersionFromSerial |
353 * Signature: (Ljava/lang/String;IIIII[I)V |
363 * Signature: (Ljava/lang/String;IIIII[I)V |
354 */ |
364 */ |
355 JNIEXPORT void JNICALL Java_com_nokia_carbide_trk_support_service_TRKConnectedService_getTRKVersionFromSerial |
365 JNIEXPORT void JNICALL Java_com_nokia_carbide_trk_support_service_TRKConnectedService_getTRKVersionFromSerial |
356 (JNIEnv* env, jclass, jstring jPortName, jint jBaud, jint jDataBits, jint jParity, jint jStopBits, jint jFlowControl, jintArray jVersionInts) |
366 (JNIEnv* env, jclass, jstring jPortName, jint jBaud, jint jDataBits, jint jParity, jint jStopBits, jint jFlowControl, jintArray jVersionInts) |
357 { |
367 { |
358 const char* portName = env->GetStringUTFChars(jPortName, NULL); |
368 const char* portName = env->GetStringUTFChars(jPortName, NULL); |
359 |
369 |
360 jint versionInts[3]; |
370 jint versionInts[4]; |
361 DWORD error = GetTRKVersion(portName, jBaud, jDataBits, jParity, jStopBits, jFlowControl, versionInts); |
371 DWORD error = GetTRKVersion(portName, jBaud, jDataBits, jParity, jStopBits, jFlowControl, versionInts); |
362 env->SetIntArrayRegion(jVersionInts, 0, 3, versionInts); |
372 env->SetIntArrayRegion(jVersionInts, 0, 4, versionInts); |
363 |
373 |
364 env->ReleaseStringUTFChars(jPortName, portName); |
374 env->ReleaseStringUTFChars(jPortName, portName); |
365 |
375 |
366 if (error > ERROR_SUCCESS) |
376 if (error > ERROR_SUCCESS) |
367 { |
377 { |