-
Notifications
You must be signed in to change notification settings - Fork 1
/
logging.js
151 lines (140 loc) · 5.37 KB
/
logging.js
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
// Generated by CoffeeScript 1.8.0
(function() {
var logging,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
logging = (function() {
function logging(physics) {
this.getLogfile = __bind(this.getLogfile, this);
this.logNewPosture = __bind(this.logNewPosture, this);
this.logTrajectoryData = __bind(this.logTrajectoryData, this);
this.errorHandler = __bind(this.errorHandler, this);
this.toggleRecorder = __bind(this.toggleRecorder, this);
this.physics = physics;
this.recordTrajectory = false;
this.startLog = true;
this.logged_data = [];
this.fileSystemSize = 100;
this.fileName = "trace.bin";
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
}
logging.prototype.toggleRecorder = function() {
this.recordTrajectory = !this.recordTrajectory;
return this.startLog = this.recordTrajectory;
};
logging.prototype.errorHandler = function(e) {
var msg;
msg = "";
switch (e.code) {
case FileError.QUOTA_EXCEEDED_ERR:
msg = "QUOTA_EXCEEDED_ERR";
break;
case FileError.NOT_FOUND_ERR:
msg = "NOT_FOUND_ERR";
break;
case FileError.SECURITY_ERR:
msg = "SECURITY_ERR";
break;
case FileError.INVALID_MODIFICATION_ERR:
msg = "INVALID_MODIFICATION_ERR";
break;
case FileError.INVALID_STATE_ERR:
msg = "INVALID_STATE_ERR";
break;
default:
msg = "Unknown Error";
}
return console.log("Error: " + msg);
};
logging.prototype.logTrajectoryData = function() {
var onInitFs, parent;
if (this.recordTrajectory) {
parent = this;
console.log(this.physics.upper_joint.GetJointAngle() + " " + this.physics.upper_joint.motor_control + " " + -this.physics.upper_joint.GetJointSpeed());
return onInitFs = function(fs) {
if (parent.startLog) {
fs.root.getFile(parent.fileName, {
create: false
}, (function(fileEntry) {
return fileEntry.remove((function() {
return parent.startLog = false;
}), parent.errorHandler);
}), parent.errorHandler);
}
return fs.root.getFile(parent.fileName, {
create: true
}, (function(fileEntry) {
parent.logfileURL = fileEntry.toURL();
return fileEntry.createWriter((function(fileWriter) {
var bb, buffer, floatView;
fileWriter.onerror = function(e) {
return console.log("Write failed: " + e.toString());
};
fileWriter.seek(fileWriter.length);
buffer = new ArrayBuffer(20);
floatView = new Float32Array(buffer);
floatView[0] = this.physics.body.GetAngle();
floatView[1] = this.physics.upper_joint.GetJointAngle();
floatView[2] = this.physics.lower_joint.GetJointAngle();
floatView[3] = this.physics.upper_joint.motor_control;
floatView[4] = this.physics.lower_joint.motor_control;
bb = new Blob([buffer], {
type: "application/octet-stream"
});
return fileWriter.write(bb);
}), parent.errorHandler);
}), parent.errorHandler);
};
}
};
logging.prototype.logNewPosture = function() {
var onInitFs, parent;
if (this.recordTrajectory) {
parent = this;
onInitFs = function(fs) {
return fs.root.getFile(parent.fileName, {
create: true
}, (function(fileEntry) {
parent.logfileURL = fileEntry.toURL();
return fileEntry.createWriter((function(fileWriter) {
var bb, buffer, floatView;
fileWriter.onerror = function(e) {
return console.log("Write failed: " + e.toString());
};
fileWriter.seek(fileWriter.length - 20);
buffer = new ArrayBuffer(20);
floatView = new Float32Array(buffer);
floatView[0] = Infinity;
floatView[1] = Infinity;
floatView[2] = Infinity;
floatView[3] = Infinity;
floatView[4] = Infinity;
bb = new Blob([buffer], {
type: "application/octet-stream"
});
return fileWriter.write(bb);
}), parent.errorHandler);
}), parent.errorHandler);
};
return window.requestFileSystem(TEMPORARY, parent.fileSystemSize * 1024 * 1024, onInitFs, this.errorHandler);
}
};
logging.prototype.getLogfile = function() {
var onInitFs, parent;
parent = this;
onInitFs = function(fs) {
return fs.root.getFile(parent.fileName, {
create: false
}, (function(fileEntry) {
console.log("downloading from " + fileEntry.toURL());
return fileEntry.file(function(file) {
return saveAs(file, parent.fileName);
}, parent.errorHandler);
}), parent.errorHandler);
};
return window.requestFileSystem(TEMPORARY, parent.fileSystemSize * 1024 * 1024, onInitFs, this.errorHandler);
};
return logging;
})();
window.simni.Logging = logging;
}).call(this);
//# sourceMappingURL=logging.js.map