OSDN Git Service

48599cbab6ae4bc169af8259661d730de45869c4
[vem/vem.git] / test / view / mds2 / js / service.js
1 // サーバ処理
2 console.log("service");
3 var service = {
4   // パラメータ取得
5   getAllParams: function () {
6                   var promise = Promise.resolve($.ajax({
7                     type: "GET",
8                   url: "http://"+config.ipAddress+":"+config.httpPort+"/"+config.inst+"/get"
9                   }));
10
11                   return promise;
12                 },
13   // ステージ移動
14   controlStageR: function (x, y, z) {
15                    var promise = Promise.resolve($.ajax({
16                      type: "GET",
17                    url: "http://"+config.ipAddress+":"+config.httpPort+"/"+config.inst+"/set/stager?x="+x+"&&y="+y+"&&z="+z
18                    }));
19
20                    return promise;
21                  },
22   // 倍率
23   controlMag: function (mag) {
24                 var promise = Promise.resolve($.ajax({
25                   type: "GET",
26                 url: "http://"+config.ipAddress+":"+config.httpPort+"/"+config.inst+"/set/magnificationa?mag="+mag
27                 }));
28
29                 return promise;
30               },
31   // スポットサイズ
32   controlSpotsize: function (spotsize) {
33                      var promise = Promise.resolve($.ajax({
34                        type: "GET",
35                      url: "http://"+config.ipAddress+":"+config.httpPort+"/"+config.inst+"/set/spotsizea?sps="+spotsize
36                      }));
37
38                      return promise;
39                    },
40   // ビームシフト
41   controlBeamShift: function (beamshift) {
42                       var promise = Promise.resolve($.ajax({
43                         type: "GET",
44                       url: "http://"+config.ipAddress+":"+config.httpPort+"/"+config.inst+"/set/beamshift?x="+x+"&&y="+y
45                       }));
46
47                       return promise;
48                     },
49   // デフォーカス
50   controlDefocus: function (defocus) {
51                     var promise = Promise.resolve($.ajax({
52                       type: "GET",
53                     url: "http://"+config.ipAddress+":"+config.httpPort+"/"+config.inst+"/set/defocusr?defocus="+defocus
54                     }));
55
56                     return promise;
57                   },
58   // リセットデフォーカス
59   resetDefocus: function () {
60                   var promise = Promise.resolve($.ajax({
61                     type: "GET",
62                   url: "http://"+config.ipAddress+":"+config.httpPort+"/"+config.inst+"/set/reset_defocus"
63                   }));
64
65                   return promise;
66                 },
67   // カメラ設定
68   controlCameraParams: function (binning, exptime, imagesize) {
69                          var promise = Promise.resolve($.ajax({
70                            type: "GET",
71                          url: "http://"+config.ipAddress+":"+config.httpPort+"/"+config.inst+"/set/acq_init?bng="+binning+"&&exp="+exptime+"&&size="+imagesize
72                          }));
73
74                          return promise;
75                        },
76   // 撮影  
77   acq: function () {
78          var promise = Promise.resolve($.ajax({
79            type: "GET",
80          url: "http://"+config.ipAddress+":"+config.httpPort+"/"+config.inst+"/acq"
81          }));
82
83          return promise;
84        },
85   startCameraWebSocket: function(){
86                           model.webSocket = new WebSocket("ws://"+config.ipAddress+":"+config.wsPort);
87                         },
88   stopCameraWebSocket: function(){
89                          model.webSocket.close(1000, 'close');
90                        },
91   acqFromWebSocket: function(){
92                       var ws = model.webSocket;
93                       ws.onopen = function(){
94                         ws.onmessage = function( event ){
95                           console.timeEnd('time');
96                           data = JSON.parse(event.data)
97                             if(data["type"]=="connection"){
98                               if(data["data"]=="open"){
99                                 ws.send('{"type": "req", "data": "img"}');
100                               }
101                             }else if(data["type"]=="img"){
102                               view.renderImage(data["data"]);
103                               ws.send('{"type": "req", "data": "img"}');
104                             }
105                           console.time('time');
106                         }
107                       }
108                     }
109 }