1 if (Garmin == undefined) var Garmin = {}; 2 /** 3 * Copyright © 2007-2010 Garmin Ltd. or its subsidiaries. 4 * 5 * Licensed under the Apache License, Version 2.0 (the 'License') 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an 'AS IS' BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 * @fileoverview Garmin.File A data structure representing a file 18 * @version 1.9 19 */ 20 /**A data structure for storing data commonly found in file 21 * formats supported by various gps devices. 22 * @class Garmin.File 23 * @constructor 24 */ 25 Garmin.File = function(){}; 26 Garmin.File = Class.create(); 27 Garmin.File.prototype = { 28 29 initialize: function() { 30 this.attributes = new Hash(); 31 this.id = new Garmin.FileId(); 32 }, 33 34 getAttributes: function() { 35 return this.attributes; 36 }, 37 38 getAttribute: function(aKey) { 39 return this.attributes[aKey]; 40 }, 41 42 setAttribute: function(aKey, aValue) { 43 this.attributes[aKey] = aValue; 44 }, 45 46 getId: function() { 47 return this.id; 48 }, 49 50 getIdValue: function(iKey) { 51 return this.id.getValue(iKey); 52 }, 53 54 setIdValue: function(iKey, iValue) { 55 this.id.setValue(iKey, iValue); 56 }, 57 58 setId: function(id) { 59 this.id = id; 60 }, 61 62 getCreationTime: function() { 63 return this.getAttribute(Garmin.File.ATTRIBUTE_KEYS.creationTime); 64 }, 65 66 getIdString: function() { 67 return this.getIdValue(Garmin.FileId.KEYS.id).getValue(); 68 }, 69 70 printMe: function(tabs) { 71 var output = ""; 72 output += tabs + "\n\n[File]\n"; 73 74 output += tabs + " attributes:\n"; 75 var attKeys = this.attributes.keys(); 76 for (var i = 0; i < attKeys.length; i++) { 77 output += tabs + " " + attKeys[i] + ": " + this.attributes[attKeys[i]] + "\n"; 78 } 79 80 output += tabs + " id:\n"; 81 output += this.id.printMe(tabs + " "); 82 83 return output; 84 }, 85 86 toString: function() { 87 return "[Garmin.File]" 88 } 89 }; 90 91 Garmin.File.ATTRIBUTE_KEYS = { 92 isDirectory: "IsDirectory", // 5/7/09 this guy isn't used by the API yet 93 path: "Path", 94 type: "Type", 95 creationTime: "CreationTime", 96 dom: "documentObjectModel", 97 size: "Size", //bytes. unsigned long, optional 98 md5Checksum: "MD5Sum" //hex string, optional, not present if IsDirectory == true 99 }; 100 101 Garmin.FileId = function(){}; 102 Garmin.FileId = Class.create(); 103 Garmin.FileId.prototype = { 104 105 initialize: function() { 106 this.values = new Hash(); 107 }, 108 109 getValue: function(key) { 110 return this.values[key]; 111 }, 112 113 setValue: function(key, value){ 114 this.values[key] = value; 115 }, 116 117 toString: function() { 118 return "[Garmin.FileId]" 119 } 120 }; 121 122 Garmin.FileId.KEYS = { 123 id: "Id", 124 fileType: "FileType", 125 manufacturer: "Manufacturer", 126 product: "Product", 127 serialNumber: "SerialNumber" 128 }; 129 130 /** 131 * Mapping of fitness file type to FIT identifier, provided by dynastream. 132 */ 133 Garmin.FileId.FILE_TYPE_MAP = { 134 activities: "4", 135 goals: "11", 136 locations: "8", 137 monitoring: "9", 138 profiles: "2", 139 schedules: "7", 140 sports: "3", 141 totals: "10" 142 };