Created
March 30, 2012 01:48
-
-
Save adamvr/2245688 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var rest = require('restler'); | |
| var path = require('path'); | |
| exports.type = 'photonics'; | |
| var template = { | |
| piezo: { | |
| required: true, | |
| allowed: ['in', 'out'] | |
| }, | |
| waveform: { | |
| required: true, | |
| allowed: ['dc', 'sine', 'square', 'triangle', 'ramp'] | |
| }, | |
| frequency: { | |
| required: true, | |
| min: 0, | |
| max: 100000 | |
| }, | |
| amplitude: { | |
| required: true, | |
| min: 0, | |
| max: 10 | |
| }, | |
| offset: { | |
| required: true, | |
| }, | |
| disc_speed: { | |
| required: true, | |
| min: 0, | |
| max: 1 | |
| }, | |
| laser_current: { | |
| required: true, | |
| min: 0, | |
| max: 10 | |
| }, | |
| focus_point: { | |
| required: true, | |
| allowed: ['collimated', 'disc', 'piezo'] | |
| }, | |
| filter: { | |
| required: true, | |
| allowed: [ 'none', '10dB', '5dB', '3dB', '2dB', '1dB' ] | |
| }, | |
| num_avg: { | |
| required: true, | |
| min: 1, | |
| max: 32 | |
| } | |
| }; | |
| var piezo = { 'in': '1', 'out':'0'}; | |
| var waveform = { | |
| 'dc': '0', | |
| 'sine': '1', | |
| 'square': '2', | |
| 'triangle': '3', | |
| 'ramp': '4' | |
| }; | |
| var focus_point = { | |
| 'collimated': '0', | |
| 'disc': '1', | |
| 'piezo', '2' | |
| }; | |
| var filter = { | |
| 'none': '0', | |
| '10dB': '1', | |
| '5dB': '2', | |
| '3dB': '3', | |
| '2dB': '4', | |
| '1dB': '5' | |
| }; | |
| exports.validate = function(params, cb) { | |
| for (var param in template) { | |
| var spec = template[param] | |
| , supplied = params[param]; | |
| if (spec.required && typeof params[param] === 'undefined') | |
| return cb('Required parameter "' + param + '" not present'); | |
| if (spec.allowed && spec.allowed.indexOf(supplied) === -1) | |
| return cb('Value "' + supplied + '" not permitted for parameter "' + param + '"'); | |
| if (supplied < spec.min || supplied > spec.max) | |
| return cb('Value "' + supplied + '" out of range for parameter "' + param + '"'); | |
| } | |
| cb(null); | |
| } | |
| exports.run = function(params, progress, done) { | |
| var url = 'http://10.240.132.231:8081/WebService/' | |
| url += piezo[params.piezo] + '/'; | |
| url += waveform[params.waveform] + '/'; | |
| url += params.frequency + '/'; | |
| url += params.amp + '/'; | |
| url += params.offset + '/'; | |
| url += params.disc_speed + '/'; | |
| url += params.laser_current + '/'; | |
| url += focus_point[params.focus_point] + '/'; | |
| url += filter[params.filter] + '/'; | |
| url += params.num_avg; | |
| rest.get(url).on('complete', function(result) { | |
| if (result instanceof Error) { | |
| done(result); | |
| } else { | |
| done(null, result); | |
| } | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment