-
Notifications
You must be signed in to change notification settings - Fork 16
/
test.html
507 lines (436 loc) · 23.8 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
<!DOCTYPE html>
<html>
<head>
<title>Test Garmin Device Output</title>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/prototype/prototype.js"> </script>
<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/device/GarminDeviceDisplay.js"> </script>
<!--<script type="text/javascript" src="http://developer.garmin.com/web/communicator-api/garmin/device/GarminDeviceControl.js"> </script> -->
<style type="text/css">
.resultBox {
font-size: 14px;
border-style: solid;
border-color: black;
border-left-width: 1px;
border-right-width: 1px;
border-top-width: 1px;
border-bottom-width: 1px;
overflow:auto;
}
.tab {
font-family: verdana,sans-serif;
font-size: 14px;
width: 120px;
white-space: nowrap;
text-align: center;
border-style: solid;
border-color: black;
border-left-width: 1px;
border-right-width: 1px;
border-top-width: 1px;
border-bottom-width: 1px;
padding-top: 5px;
padding-bottom: 5px;
cursor: pointer;
}
.tabhold {
background-color: white;
color: black;
}
.tabfocus {
background-color: black;
color: white;
}
.tabcontent {
font-family: sans-serif;
font-size: 14px;
width: 800px;
height: 600px;
border-style: solid;
border-color: black;
border-width: 1px;
padding-top: 15px;
padding-left: 10px;
padding-right: 10px;
}
</style>
<script type="text/javascript">
function showDiv(id) {
var box = new Array();
box[0] = 'readDataFromDeviceDiv';
box[1] = 'getDeviceInfoDiv';
box[2] = 'onFinishReadFromDeviceDiv';
box[3] = 'writeDataToDeviceDiv';
var tabId = new Array();
tabId[0] = 'readDataFromDeviceDivTab';
tabId[1] = 'getDeviceInfoDivTab';
tabId[2] = 'onFinishReadFromDeviceDivTab';
tabId[3] = 'writeDataToDeviceDivTab';
for(i=0;i<box.length;i++) {
document.getElementById(tabId[i]).setAttribute("class", "tab tabhold");
document.getElementById(box[i]).style.display="none";
}
document.getElementById(id).style.display="block";
document.getElementById(id+"Tab").setAttribute("class", "tab tabfocus");
}
function xml2html(xmlText) {
xmlText = xmlText.replace(/</g, "<");
xmlText = xmlText.replace(/>/g, ">");
xmlText = xmlText.replace(/\n/g, "<br>");
return xmlText;
}
function getSupportedString(type,internaltype) {
var supStr=type + " = ";
if (globalGarminController.checkDeviceReadSupport(internaltype)) {
supStr = "<font color=\"#00AA00\">" + supStr + "Supported </font>| ";
} else {
supStr = "<font color=\"#FF0000\">" + supStr + "NOT Supported </font>| ";
}
return supStr;
}
function updateSupportedDiv(first,second) {
var supportedTypes = "";
supportedTypes = supportedTypes + getSupportedString("Gpx","GPSData");
supportedTypes = supportedTypes + getSupportedString("gpxDetail","GPSDataDetail");
supportedTypes = supportedTypes + getSupportedString("gpxDir","GPSDataDirectory");
supportedTypes = supportedTypes + getSupportedString("tcxDir","FitnessHistoryDirectory");
supportedTypes = supportedTypes + getSupportedString("crsDir","FitnessCoursesDirectory");
supportedTypes = supportedTypes + getSupportedString("fit","FITBinary");
supportedTypes = supportedTypes + getSupportedString("fitDir","FitDirectory");
supportedTypes = supportedTypes + getSupportedString("Tcx","FitnessHistory");
supportedTypes = supportedTypes + getSupportedString("Crs","FitnessCourses");
supportedTypes = supportedTypes + getSupportedString("Wkt","FitnessWorkouts");
supportedTypes = supportedTypes + getSupportedString("Goals","FitnessActivityGoals");
supportedTypes = supportedTypes + getSupportedString("TcxProfile","FitnessUserProfile");
document.getElementById("deviceSupportDiv").innerHTML = supportedTypes;
}
GarminPluginListener = Class.create();
GarminPluginListener.prototype = {
initialize: function() {
},
onFinishFindDevices: function(json) {
if(json.controller.numDevices > 0) {
var devices = json.controller.getDevices();
var selectHtml = "Devices found: <select name=\"garminDeviceId\" id=\"garminDeviceId\" onchange=\"globalGarminController.setDeviceNumber(this.value);updateSupportedDiv();\">";
for(i=0;i<json.controller.numDevices;i++) {
selectHtml = selectHtml + "<option value=\"" + devices[i].getNumber() + "\">" + devices[i].getDisplayName() +"</option>";
}
selectHtml = selectHtml + "</select>";
document.getElementById("garminDisplay").innerHTML = selectHtml;
updateSupportedDiv();
} else {
document.getElementById("garminDisplay").innerHTML = "<b>No devices found!</b>";
}
},
onProgressReadFromDevice: function(json) {
document.getElementById("pluginProgressState").innerHTML = "Progress: "+ json.progress.getPercentage();
},
onProgressWriteToDevice: function(json) {
document.getElementById("pluginProgressState").innerHTML = "Progress: "+ json.progress.getPercentage();
},
onFinishReadFromDevice: function(json) {
document.getElementById("pluginProgressState").innerHTML = "";
if (json.success) {
document.getElementById("statusOnFinishReadFromDevice").innerHTML = "<font color=\"#00AA00\">Status: Success</font>";
} else {
document.getElementById("statusOnFinishReadFromDevice").innerHTML = "<font color=\"#FF0000\">Status: Failed</font>";
}
document.getElementById("onFinishReadFromDeviceGpsXml").innerHTML = "";
document.getElementById("onFinishReadFromDeviceGpsXml").innerHTML = xml2html(json.controller.gpsDataString);
document.getElementById("onFinishReadFromDeviceGpsXmlCompressed").innerHTML = "";
document.getElementById("onFinishReadFromDeviceGpsXmlCompressed").innerHTML = xml2html(json.controller.gpsDataStringCompressed);
showDiv("onFinishReadFromDeviceDiv");
},
onFinishWriteToDevice: function(json) {
document.getElementById("pluginProgressState").innerHTML = "";
if (json.success) {
document.getElementById("statusWriteDataToDevice").innerHTML = "<font color=\"#00AA00\">Successfully written!</font>";
} else {
document.getElementById("statusWriteDataToDevice").innerHTML = "<font color=\"#FF0000\">Failed to write!</font>";
}
},
onWaitingWriteToDevice: function(json) {
if(confirm(json.message.getText())) {
json.controller.respondToMessageBox(true);
} else {
json.controller.respondToMessageBox(false);
}
},
onWaitingReadFromDevice: function(json) {
if(confirm(json.message.getText())) {
json.controller.respondToMessageBox(true);
} else {
json.controller.respondToMessageBox(false);
}
},
}
var globalGarminController;
function detectGarminDevice() {
try {
var pluginRequiredVersion = [2,2,0,1];
var pluginLatestVersion = [2,5,2,0];
globalGarminController = new Garmin.DeviceControl();
var listener = new GarminPluginListener();
globalGarminController.register(listener);
globalGarminController.setPluginRequiredVersion(pluginRequiredVersion);
globalGarminController.setPluginLatestVersion(pluginLatestVersion);
globalGarminController.validatePlugin();
var unlockKeyPair = ["file:///","cb1492ae040612408d87cc53e3f7ff3c"];
if(!globalGarminController.unlock(unlockKeyPair)) {
document.getElementById("garminDisplay").innerHTML = "<b>Unable to unlock device!</b>";
return;
}
if (!globalGarminController.isUnlocked()) {
document.getElementById("garminDisplay").innerHTML = "<b>Device was not unlocked!</b>";
return;
}
document.getElementById("garminDisplay").innerHTML = "Searching for devices...";
globalGarminController.findDevices();
} catch (e) {
alert(e);
}
}
function callGetDevicesXmlString() {
try {
document.getElementById("callGetDevicesXmlStringResult").innerHTML = xml2html(document.getElementById("GarminNetscapePlugin").DevicesXmlString());
} catch (e) {
alert(e);
}
}
function callGetDeviceDescription() {
try {
var number = globalGarminController.getDeviceNumber();
document.getElementById("callGetDeviceDescriptionResult").innerHTML = xml2html(document.getElementById("GarminNetscapePlugin").DeviceDescription(number));
} catch (e) {
alert(e);
}
}
function callReadDataFromDevice() {
try {
var fileType = document.getElementById("readDataFromDeviceDataType").value;
var fileListingOptions = [{dataTypeName: 'UserDataSync',
dataTypeID: 'http://www.topografix.com/GPX/1/1',
computeMD5: false}];
fileListingOptions[0].dataTypeName = document.getElementById("readDataFromDeviceDir").value;
fileListingOptions[0].dataTypeID = document.getElementById("readDataFromDeviceExtension").value;
if (document.getElementById("readDataFromDeviceCalcMd5").checked) {
fileListingOptions[0].computeMD5 = true;
}
globalGarminController.readDataFromDevice(fileType, fileListingOptions);
} catch (e) {
alert(e);
}
}
function callReadDetailFromDevice() {
try {
var fileType = document.getElementById("readDetailFromDeviceDataType").value;
var id = document.getElementById("readDetailFromDeviceId").value;
globalGarminController.readDetailFromDevice(fileType, id);
} catch (e) {
alert(e);
}
}
function readDataFromDeviceDataTypeOnClick() {
if (document.getElementById("readDataFromDeviceDataType").value == "ReadableFilesDirectory") {
document.getElementById("readDataFromDeviceExtension").disabled = false;
document.getElementById("readDataFromDeviceDir").disabled = false;
document.getElementById("readDataFromDeviceCalcMd5").disabled = false;
} else {
document.getElementById("readDataFromDeviceExtension").disabled = true;
document.getElementById("readDataFromDeviceDir").disabled = true;
document.getElementById("readDataFromDeviceCalcMd5").disabled = true;
}
}
function callWriteDataToDevice() {
try {
var fileType = document.getElementById("writeDataToDeviceFileType").value;
var fileName = document.getElementById("writeDataToDeviceFileName").value;
var fileContent = document.getElementById("writeDataToDeviceFileContent").value;
globalGarminController.writeDataToDevice(fileType, fileContent, fileName);
} catch (e) {
alert(e);
}
}
function callDownloadDataToDevice() {
try {
var fileUrl = document.getElementById("downloadDataToDeviceURL").value;
var fileDestination = document.getElementById("downloadDataToDeviceDestination").value;
var xml =
'<?xml version="1.0" encoding="UTF-8"?>\n' +
'<DeviceDownload xmlns="http://www.garmin.com/xmlschemas/PluginAPI/v1"\n' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n' +
' xsi:schemaLocation="http://www.garmin.com/xmlschemas/PluginAPI/v1 http://www.garmin.com/xmlschemas/GarminPluginAPIV1.xsd">\n';
xml += ' <File Source="'+fileUrl+'" Destination="'+fileDestination+'" RegionId="46" />\n';
xml += '</DeviceDownload>';
globalGarminController.downloadToDevice(xml);
} catch (e) {
alert(e);
}
}
function callGetBinaryFile() {
try {
var fileName = document.getElementById("getBinaryFilePath").value;
var number = globalGarminController.getDeviceNumber();
globalGarminController.getBinaryFile(number, fileName);
} catch (e) {
alert(e);
}
}
function callBytesAvailable() {
try {
var path = document.getElementById("bytesAvailablePath").value;
document.getElementById("resultBytesAvailable").innerHTML = globalGarminController.bytesAvailable(path) + " Bytes";
} catch (e) {
alert(e);
}
}
function callListDirectory() {
try {
var number = globalGarminController.getDeviceNumber();
document.getElementById("GarminNetscapePlugin").StartDirectoryListing(number, "", false);
} catch (e) {
alert(e);
}
}
function callGetListDirectory() {
try {
var number = globalGarminController.getDeviceNumber();
var status = document.getElementById("GarminNetscapePlugin").FinishDirectoryListing();
if (status == 3) {
var text = document.getElementById("GarminNetscapePlugin").DirectoryListingXml;
document.getElementById("onFinishReadFromDeviceGpsXml").innerHTML = xml2html(text);
alert("Done");
}
} catch (e) {
alert(e);
}
}
</script>
</head>
<body>
<!-- <object id="pluginobj" type="application/vnd-garmin.mygarmin">Plugin FAILED to load</object>-->
<h>Initialize Plugin</h>
<button onclick='detectGarminDevice()'>Detect Garmin Device</button>
<div id="garminDisplay"></div><div id="pluginProgressState"></div>
<div id="deviceSupportDiv" style="font-family:verdana,sans-serif;font-size: 8px;"></div>
<hr>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div id="getDeviceInfoDivTab" class="tab tabfocus" onclick="showDiv('getDeviceInfoDiv')">DeviceInfo</div></td>
<td><div id="readDataFromDeviceDivTab" class="tab tabhold" onclick="showDiv('readDataFromDeviceDiv')">ReadFromDev.</div></td>
<td><div id="onFinishReadFromDeviceDivTab" class="tab tabhold" onclick="showDiv('onFinishReadFromDeviceDiv')">OnFinishRead</div></td>
<td><div id="writeDataToDeviceDivTab" class="tab tabhold" onclick="showDiv('writeDataToDeviceDiv')">WriteToDev.</div></td>
</table>
<div id="onFinishReadFromDeviceDiv" class="tabcontent" style="display:none">
<div id="statusOnFinishReadFromDevice">Status: ?</div><br>
<div id="onFinishReadFromDeviceGpsXml" class="resultBox" style="width:750px;height:400px">Empty</div><br>
<div id="onFinishReadFromDeviceGpsXmlCompressed" class="resultBox" style="width:750px;height:400px">Empty</div><br>
</div>
<div id="getDeviceInfoDiv" class="tabcontent" style="display:block">
<button onclick='callGetDevicesXmlString()'>Get DevicesXmlString</button><br>
<div id="callGetDevicesXmlStringResult" class="resultBox" style="width:750px;height:200px">Empty</div><br><br>
<button onclick='callGetDeviceDescription()'>Get DeviceDescription</button><br>
<div id="callGetDeviceDescriptionResult" class="resultBox" style="width:750px;height:300px">Empty</div>
</div>
<div id="writeDataToDeviceDiv" class="tabcontent" style="display:none">
<div id="statusWriteDataToDevice"></div>
File Type:
<select name="writeDataToDeviceFileType" id="writeDataToDeviceFileType" >
<option value="GPSData">Gpx</option>
<option value="FitnessCourses">Crs</option>
<option value="FitnessWorkouts">Wkt</option>
<option value="FitnessActivityGoals">Goals</option>
<option value="FitnessUserProfile">TcxProfile</option>
<option value="GPSDataDetail">gpxDetail</option>
<option value="FITBinary">fit</option>
<option value="FitDirectory">fitDir</option>
<option value="FitnessNewLeaf">nlf</option>
</select>
Filename: <input type="text" length="20" name="writeDataToDeviceFileName" id="writeDataToDeviceFileName" value="filename.ext"><br>
<textarea name="writeDataToDeviceFileContent" id="writeDataToDeviceFileContent" style="width:750px;height:200px">Content</textarea><br>
<button onclick='callWriteDataToDevice()'>WriteDataToDevice</button><br><br>
<hr>
URL: <input type="text" name="downloadDataToDeviceURL" id="downloadDataToDeviceURL" value="http://www.domain.org/file.fit" length="40">
Destination: <input type="text" length="20" name="downloadDataToDeviceDestination" id="downloadDataToDeviceDestination" value="Garmin/filename.fit">
<button onclick='callDownloadDataToDevice()'>DownloadDataToDevice</button><br><br>
<hr>
Path: <input type="text" length="20" name="bytesAvailablePath" id="bytesAvailablePath" value="Garmin/">
<button onclick='callBytesAvailable()'>BytesAvailable</button><div id="resultBytesAvailable"></div><br><br>
</div>
<div id="readDataFromDeviceDiv" class="tabcontent" style="display:none">
Type: <select name="readDataFromDeviceDataType" id="readDataFromDeviceDataType" onchange="readDataFromDeviceDataTypeOnClick()">
<option value="GPSData">gpx</option>
<option value="GPSDataDetail">gpxDetail</option>
<option value="GPSDataDirectory">gpxDir</option>
<option value="FITBinary">fit</option>
<option value="FitDirectory">fitDir</option>
<option value="FitnessHistory">Tcx</option>
<option value="FitnessHistoryDirectory">TcxDir</option>
<option value="FitnessUserProfile">TcxProfile</option>
<option value="FitnessCourses">Crs</option>
<option value="FitnessCoursesDirectory">CrsDir</option>
<option value="FitnessWorkouts">Wkt</option>
<option value="FitnessActivityGoals">Goals</option>
<option value="ReadableFilesDirectory">ReadableDir</option>
</select>
Ext: <select name="readDataFromDeviceExtension" id="readDataFromDeviceExtension" disabled="disabled">
<option value="GPX">GPX</option>
<option value="TCX">TCX</option>
<option value="tcx">tcx</option>
<option value="FIT">FIT</option>
<option value="GCD">GCD</option>
<option value="IMG">IMG</option>
<option value="img">img</option>
<option value="ver">ver</option>
<option value="JNX">JNX</option>
<option value="NLF">NLF</option>
<option value="gtt">gtt</option>
</select>
Dir: <select name="readDataFromDeviceDir" id="readDataFromDeviceDir" disabled="disabled">
<option value="FitnessHistory">FitnessHistory</option>
<option value="GPSData">GPSData</option>
<option value="FITBinary">FITBinary</option>
<option value="FIT_TYPE_2">FIT_TYPE_2</option>
<option value="FIT_TYPE_3">FIT_TYPE_3</option>
<option value="FIT_TYPE_4">FIT_TYPE_4</option>
<option value="FIT_TYPE_5">FIT_TYPE_5</option>
<option value="FIT_TYPE_6">FIT_TYPE_6</option>
<option value="FIT_TYPE_7">FIT_TYPE_7</option>
<option value="FIT_TYPE_8">FIT_TYPE_8</option>
<option value="FIT_TYPE_9">FIT_TYPE_9</option>
<option value="FIT_TYPE_10">FIT_TYPE_10</option>
<option value="FIT_TYPE_MET_ZONES">FIT_TYPE_MET_ZONES</option>
<option value="FitnessWorkouts">FitnessWorkouts</option>
<option value="FitnessCourses">FitnessCourses</option>
<option value="FitnessNewLeaf">FitnessNewLeaf</option>
<option value="NMaps">NMaps</option>
<option value="BaseMaps">BaseMaps</option>
<option value="PreProgrammedMaps">PreProgrammedMaps</option>
<option value="SupplementalMaps">SupplementalMaps</option>
<option value="TimeZoneMaps">TimeZoneMaps</option>
<option value="TranslatedText">TranslatedText</option>
<option value="FTLImageVersion">FTLImageVersion</option>
<option value="CustomPOI">CustomPOI</option>
<option value="geocache_visits">geocache_visits</option>
<option value="FitnessUserProfile">FitnessUserProfile</option>
<option value="UnitSoftwareUpdate">UnitSoftwareUpdate</option>
<option value="UserDataSync">UserDataSync</option>
<option value="CustomMaps">CustomMaps</option>
<option value="BirdsEye">BirdsEye</option>
</select>
<input type="checkbox" id="readDataFromDeviceCalcMd5" name="readDataFromDeviceCalcMd5" value="1" disabled="disabled"> Calc MD5
<button onclick='callReadDataFromDevice()'>ReadDataFromDevice</button><br><br>
<hr>
Type: <select name="readDetailFromDeviceDataType" id="readDetailFromDeviceDataType">
<option value="FitnessHistoryDetail">TcxDetail</option>
<option value="FitnessCoursesDetail">CrsDetail</option>
</select>
ID: <input name="readDetailFromDeviceId" id="readDetailFromDeviceId" type="text" length="15" value="2009-06-24T14:17:39Z">
<button onclick='callReadDetailFromDevice()'>ReadDetailFromDevice</button><br><br>
<hr>
Relative File Path: <input name="getBinaryFilePath" id="getBinaryFilePath" type="text" length="30" value="Garmin/GPX/Current/current.gpx">
<button onclick='callGetBinaryFile()'>GetBinaryFile</button><button onclick='callGetBinaryFile()'>GetBinaryFile Compressed</button><br><br>
<button onclick='callListDirectory()'>ListDirectory</button><br><br>
<button onclick='callGetListDirectory()'>GetListDirectory</button><br><br>
</div>
</body>
</html>