· 8 years ago · Jul 28, 2018, 03:52 PM
1"""SmartScan interrogator definitions."""
2
3from __future__ import print_function, unicode_literals, absolute_import,\
4 division
5
6import logging
7import copy
8import re
9import datetime
10import time
11import binascii
12import socket
13import struct
14
15from six.moves import configparser as cp
16
17from .messages import Diag_8, Maint_8, MaintRfc_8, Peak_8, Spectrum_8
18from .exception import ConfigError
19from .connection import ConnectionHandler_8
20
21LOG = logging.getLogger("smartfibres.smartscan_8")
22
23
24class SmartScan_8(object):
25
26 """UDP communication object for the SmartFibres SmartScan interrogator."""
27
28 DIAG = 0
29 MAINT = 1
30 PEAK = 2
31 SPECTRUM = 3
32
33 MSGTYPES = [Diag_8, Maint_8, Peak_8, Spectrum_8 ]
34 WORK_MODE = 8 # 8 Port Scanner !!!
35
36 def __init__(self, remoteip, newip, subnet, gateway):
37 """Create an instance of a SmartScan interrogator.
38
39 Parameters
40 ==========
41 remoteip: string
42 IP address of the SmartScan interrogator to represent.
43 """
44 self._remoteip = remoteip
45 self._newtosetip = newip
46 self._subnet = subnet
47 self._gateway = gateway
48 self._workMode = 8 # for 8 ... 4 port scans
49 self._config = None
50 self._cfg_speedCode = 0
51
52 LOG.info("SmartScan_8 remote IP = %s", remoteip)
53 self._handler = ConnectionHandler_8(remoteip)
54 handler = self._handler
55 for msgtype in self.MSGTYPES:
56 handler.add_recv_connection(msgtype)
57
58
59 @property
60 def config(self):
61 """Return a copy of the SmartScan configuration"""
62 return copy.copy(self._config)
63
64 def configure(self, filename):
65 """Read configuration from ini-file and send it to SmartScan.
66
67 Parameters
68 ==========
69 filename: string
70 full path of ini-file to read
71
72 Result
73 ======
74 boolean:
75 configuration was successful
76 """
77 if self.read_config(filename):
78
79 self._handler.set_conn_hndl_active()
80
81 # be sure, to get the communication with the smartfibre
82 # set the real connect mode <operational> to the smartscan !!!
83
84 # set transmission rate
85 self.send_config()
86 #self.set_diag_start_mode()
87 return True
88 return False
89
90 def send_message(self, message):
91 """Send a message to the interrogator"""
92 self._handler.sendto(message)
93
94 def get_maint(self):
95 """Return a maintenance message."""
96 return self._handler.get_message(Maint_8)
97
98 def get_diag(self):
99 """Return a diagnostic message."""
100 return self._handler.get_message(Diag_8)
101
102 def get_spectrum(self):
103 """Return a spectrum message."""
104 return self._handler.get_message(Spectrum_8)
105
106 def get_peak(self):
107 """Return a peak message."""
108 return self._handler.get_message(Peak_8)
109
110 def add_message_handler(self, messagehandler):
111 """Add handler for specific message type."""
112 self._handler.add_message_handler(messagehandler)
113
114 def remove_message_handler(self, messagehandler):
115 """Remove handler for specific message type."""
116 self._handler.remove_message_handler(messagehandler)
117
118 def close(self):
119 """Close sockets and handlers."""
120 self._handler.close()
121
122 def read_config(self, filename):
123 """Read configuration of SmartScan from ini-file.
124
125 Parameters
126 ==========
127 filename: string
128 complete path of the ini-file
129
130 Result
131 ======
132 boolean:
133 reading configuration was successful.
134 """
135 configsection = 'GBL-SettingsV2.vi'
136 configparser = cp.ConfigParser()
137 read_files = configparser.read(filename)
138 if filename in read_files:
139 LOG.debug("Configuration read...")
140 self._config = dict(configparser.items(configsection))
141 config = {}
142 config['avgsamplesize'] = int(
143 self._config['sample size'].strip("\""))
144 LOG.info("Read sample size = %s", self._config['sample size'].strip("\""))
145 config['averaging'] = (
146 self._config['apply averaging'].strip("\"") == 'TRUE')
147 LOG.info("Read apply averaging = %s", self._config['apply averaging'].strip("\""))
148 config['tof'] = (
149 self._config['enable tof'].strip("\"") == 'TRUE')
150 LOG.info("Enable TOF = %s", self._config['enable tof'].strip("\""))
151
152 config['laser offset'] = int(
153 self._config['laser offset'].strip("\""))
154 LOG.info("Laser Offset = %s", self._config['laser offset'].strip("\""))
155
156 config['gratings'] = int(
157 self._config['gratings'].strip("\""))
158 LOG.info("Gratings = %s", self._config['gratings'].strip("\""))
159
160 config['slot_mode'] = int(
161 self._config['slot mode'].strip("\""))
162 LOG.info("Slot Mode = %s", self._config['slot mode'].strip("\""))
163
164 iHlp = 0
165 iHlp = int(self._config['freq steps/scan'].strip("\""))
166 if (self._workMode == 4):
167 config['freq steps/scan'] = iHlp
168 else: # WorkMode == 8 channels
169 if (iHlp <= 0): iHlp = 1
170 config['freq steps/scan'] = iHlp - 1
171 LOG.info("Freq Steps/Scan = %s", config['freq steps/scan'])
172 fCycleTime = float(self._config['cycle time (us)'].strip("\"").replace(',', '.'))
173 self._config['cycle time (us)'] = fCycleTime
174 LOG.info("Cycle time: %f", self._config['cycle time (us)'])
175 # define a special variable for SetSpeedCode for 8 channel workmode
176 if (self._workMode == 8):
177 if (fCycleTime >= 100.0):
178 self._cfg_speedCode = 6
179 elif (fCycleTime >= 50.0):
180 self._cfg_speedCode = 5
181 elif (fCycleTime >= 20.0):
182 self._cfg_speedCode = 4
183 elif (fCycleTime >= 10.0):
184 self._cfg_speedCode = 3
185 elif (fCycleTime >= 5.0):
186 self._cfg_speedCode = 2
187 elif (fCycleTime >= 2.0):
188 self._cfg_speedCode = 1
189 else:
190 self._cfg_speedCode = 0
191
192 config['channelno'] = int(self._config['channels'].strip("\""))
193 LOG.info("Channels : %s", self._config['channels'].strip("\""))
194
195 config['sensors/channel'] = int(
196 self._config['sensors/channel'].strip("\""))
197 LOG.info("Sensors / Channels : %s", self._config['sensors/channel'].strip("\""))
198
199 config['datarate'] = int(
200 self._config['data rate'].strip("\""))
201 LOG.info("Datarate : %s", self._config['data rate'].strip("\""))
202
203 iTypeSet = int(self._config['source type'].strip("\""))
204 config['source_type'] = iTypeSet
205 LOG.info(" ##### SOURCE TYPE IS = <%d>", iTypeSet)
206 if iTypeSet == 0:
207 print("SOURCE NAME IS = <channel photo-diodes>")
208 elif iTypeSet == 1:
209 print("SOURCE NAME IS = <receiver test ramps>")
210 elif iTypeSet == 2:
211 print("SOURCE NAME IS = <slots>")
212 elif iTypeSet == 3:
213 print("SOURCE NAME IS = <gains>")
214 elif iTypeSet == 4:
215 print("SOURCE NAME IS = <dsp test arrays>")
216 elif iTypeSet == 5:
217 print("SOURCE NAME IS = <photo-diode baseline levels>")
218 elif iTypeSet == 6:
219 print("SOURCE NAME IS = <etalon photo diodes>")
220 elif iTypeSet == 7:
221 print("SOURCE NAME IS = <laser test ramps>")
222 elif iTypeSet == 8:
223 print("SOURCE NAME IS = <laser luts>")
224 elif iTypeSet == 8:
225 print("SOURCE NAME IS = <thermistors>")
226 else:
227 print("SOURCE NAME IS = <UNDEF OR WRONG>")
228 iTypeSet = -1
229
230 config['spectrarate'] = int(
231 self._config['spectra rate'].strip("\""))
232 LOG.info("Spectral Rate : %s", self._config['spectra rate'].strip("\""))
233 LOG.info("Gain is set to : %s", self._config['gain'].strip("\""))
234
235 if self._config['gain'].strip("\"") != 'Manual':
236 config['AGC'] = 0
237 else:
238 config['AGC'] = int(config['cycle time (us)'] * 2)
239
240 # set slots
241 # <size(s)=4 16> 48 ...
242 LOG.info(self._config['slots'])
243 result = re.search(r"(?i)(?:\"<size\(s\)=)(?P<channels>\d+)\s+"
244 r"(?P<fbgs>\d+)(?:>)\s*(?P<slots>(\d+(\s+\d+)*))"
245 r"\s*\"",
246 self._config['slots'])
247 # self._config['slot table'])
248 # result: dict with channels, fbgs, slots
249 result = result.groupdict()
250 config['slots'] = [int(x) for x in result['slots'].split(' ')]
251
252 config['active_channels'] = config['channelno']
253 config['channels_available'] = int(result['channels'])
254 if config['active_channels'] > config['channels_available']:
255 raise ConfigError("More channels configured than exist: "
256 "%d > %d" % (config['active_channels'],
257 config['channelavailable']))
258 config['fbgs'] = int(result['fbgs'])
259 LOG.debug("%i of %i sensors per channel active", config['sensors/channel'], config['fbgs'])
260 # set gains
261 LOG.info("Set gains %s", self._config['gains'])
262 # Gain table = "<size(s)=4 16> 8 7 ...
263 result = re.search(r"(?i)(?:\"<size\(s\)=)(?P<channels>\d+)\s+"
264 r"(?P<fbgs>\d+)(?:>)\s*"
265 r"(?P<gains>(\d+(\s+\d+)*))"
266 r"\s*\"",
267 self._config['gains'])
268 result = result.groupdict()
269 config['gains'] = [int(x) for x in result['gains'].split(' ')]
270 channels = int(result['channels'])
271 fbgs = int(result['fbgs'])
272
273 if config['channels_available'] != channels or config['fbgs'] != fbgs:
274 raise ConfigError("Configuration options don't match:"
275 " channel/fbgs: %d (%d), %d (%d)" % (
276 channels, config['active_channels'],
277 fbgs, config['fbgs']))
278
279 if len(config['gains']) != len(config['slots']):
280 raise ConfigError("Gains/Slots length does not match %d:%d" %
281 (len(config['gains']), len(config['slots'])))
282
283 datalen = config['fbgs'] * config['channels_available']
284 if len(config['gains']) != datalen:
285 raise ConfigError("Gain field does not match fbgs * channel:"
286 " %d != %d * %d" %
287 (len(config['gains']), config['fbgs'],
288 config['active_channels']))
289
290 if len(config['slots']) != datalen:
291 raise ConfigError("Slot field does not match fbgs * channel:"
292 " %d != %d * %d" %
293 (len(config['slots']), config['fbgs'],
294 config['active_channels']))
295 # set thresholds
296 # like: Threshold = "<size(s)=4> 15 15 15 15"
297
298 result = re.search(r"(?i)(?:\"<size\(s\)=)(?P<channels>\d+)(?:>)\s*"
299 r"(?P<thresholds>(\d+(\s+\d+)*))"
300 r"\s*\"",
301 self._config['threshold'])
302 result = result.groupdict()
303 channels = int(result['channels'])
304 config['threshold'] = [int(65535 / 100 * int(x))
305 for x in result['thresholds'].split(' ')]
306 if config['channels_available'] != channels:
307 raise ConfigError("ChannelNo in configuration differs: "
308 "%d (%d)" % (channels,
309 config['channels_available']))
310
311 self._config = config
312 # set channel format
313 return True
314 return False
315
316 def send_config(self):
317 """Send configuration to the remote SmartScan."""
318 self._set_pre_config()
319 self._set_slots()
320 self._set_post_config()
321 if self._config['averaging']:
322 self._handler.averaging = self._config['avgsamplesize']
323 else:
324 self._handler.averaging = 1
325 return True
326
327 def sync_time(self):
328 """Sync time on SmartScan."""
329 # On a SmartScan time can be set only by the precision of seconds
330 # So we need to wait for the next full second until we can send
331 # the packet on it's way to the scanner.
332 # It's not perfect, but the error should be more or less constant.
333
334 LOG.debug("Sync Time Transfer")
335 message = Maint_8()
336 message.state = message.OP_NO_CHANGE
337 # message.state = message.OP_MAINTENANCE
338
339 now = datetime.datetime.now()
340 epoch = datetime.datetime(1970, 1, 1)
341
342 # int and datetime objects
343 seconds = int((now - epoch).total_seconds()) + 1 # + sync second
344 utctime = datetime.datetime.utcfromtimestamp(seconds)
345
346 # wait until next full second
347 # works only on Linux with good accuracy
348 # Windows needs another approach
349 time.sleep((utctime - datetime.datetime.now()).total_seconds())
350
351 command = MaintRfc_8()
352 command.command = command.SET_CLOCK
353 command.data = (seconds, )
354 message.add_message(command)
355 self._handler.sendto(message)
356 LOG.debug("Time set to: %d = %s", seconds, utctime)
357
358 def set_diag_start_mode(self):
359 """
360 return: Set SmartFibre into the Operational Mode
361 """
362 # In Operatinal mode, you can use the maintenance and the data
363 # transfer messages. For 8 port scan this must be the first
364 # command
365 # The struct is not identical with the maintenance struct
366 # So the struct looks like this:
367 # typedef struct S_SAMH_DEF
368 # {
369 # u32 ultimestamp; // set act time
370 # u8 ucDamage; // For future use
371 # u8 ucState; // set the USED mode
372 # u8 ucv_level1_damage[8] // For future use
373 # u8 ucv_level2_damage[8] // For future use
374 # u8 ucv_spare // For future use
375 # }
376 LOG.debug("set_diag_start_mode")
377 message = Diag_8()
378
379 # int and datetime objects
380 now = datetime.datetime.utcnow()
381 epoch = datetime.datetime(1970, 1, 1)
382 seconds = int((now - epoch).total_seconds()) + 1 # + sync second
383 utctime = datetime.datetime.utcfromtimestamp(seconds)
384 time.sleep((utctime - datetime.datetime.utcnow()).total_seconds())
385 message.utc_timestamp = seconds
386 message.operational_state = message.OP_OPERATIONAL
387 self._handler.sendto(message)
388 LOG.debug("INIT DIAGNOSTIC MESSAGE DONE Time = : %d = %s", seconds, utctime)
389
390 def set_new_ip_adress(self):
391 """ Set new IP Adress """
392 # On a SmartScan time can be set only by the precision of seconds
393 # So we need to wait for the next full second until we can send
394 # the packet on it's way to the scanner.
395 # It's not perfect, but the error should be more or less constant.
396
397 self.set_diag_start_mode()
398
399 LOG.debug("Set new IP Adress, Subnet, Gateway")
400 message = Maint_8()
401 message.state = message.OP_MAINTENANCE
402 ip_adr_in_hex = binascii.hexlify(socket.inet_aton(self._newtosetip)).upper()
403 LOG.debug("Calculateed HEX Value for IP = [%s]", ip_adr_in_hex)
404 command = MaintRfc_8()
405 command.command = command.SET_IP
406 b = bytearray(binascii.a2b_hex(ip_adr_in_hex))
407 command.data = (((int(b[0]))<<24) + ((int(b[1]))<<16) + ((int(b[2]))<<8) + (int(b[3])),)
408 message.add_message(command)
409 self._handler.sendto(message)
410 LOG.debug("*** IP Adress is changed to [%s]", self._newtosetip)
411
412 msgData = None
413 while (msgData == None):
414 msgData = self._handler.get_message(Diag_8)
415 time.sleep(.1)
416 #print (msgData)
417
418 # Be careful !!! MODE was lost !!! So set
419 LOG.debug("Set state IMPORTANT")
420 message = Maint_8()
421 message.state = message.OP_OPERATIONAL
422 command = MaintRfc_8()
423 command.command = command.SET_STATE
424 command.data = (command.OP_MAINTENANCE,)
425 message.add_message(command)
426 self._handler.sendto(message)
427
428 LOG.debug("Set new Subnet Adress")
429 message = Maint_8()
430 message.state = message.OP_MAINTENANCE
431
432 subnet_adr_in_hex = binascii.hexlify(socket.inet_aton(self._subnet)).upper()
433 command = MaintRfc_8()
434 LOG.debug("Calculateed HEX Value for SUBNET = [%s]", subnet_adr_in_hex)
435 command.command = command.SET_SUBNET_MASK
436 b = bytearray(binascii.a2b_hex(subnet_adr_in_hex))
437 command.data = (((int(b[0]))<<24) + ((int(b[1]))<<16) + ((int(b[2]))<<8) + (int(b[3])),)
438 message.add_message(command)
439 self._handler.sendto(message)
440 LOG.debug("*** Subnet Adress is changed to [%s]", self._subnet)
441
442 # Be careful !!! MODE was lost !!! So set
443 message = Maint_8()
444 message.state = message.OP_OPERATIONAL
445 command = MaintRfc_8()
446 command.command = command.SET_STATE
447 command.data = (command.OP_MAINTENANCE,)
448 message.add_message(command)
449 self._handler.sendto(message)
450
451 LOG.debug("Set new Gateway Adress")
452 message = Maint_8()
453 message.state = message.OP_MAINTENANCE
454 gateway_adr_in_hex = binascii.hexlify(socket.inet_aton(self._gateway)).upper()
455 command = MaintRfc_8()
456 LOG.debug("Calculateed HEX Value for GATEWAY = [%s]", gateway_adr_in_hex)
457 b = bytearray(binascii.a2b_hex(gateway_adr_in_hex))
458 command.data = (((int(b[0]))<<24) + ((int(b[1]))<<16) + ((int(b[2]))<<8) + (int(b[3])),)
459 command.command = command.SET_GATEWAY_IP
460 message.add_message(command)
461 self._handler.sendto(message)
462 LOG.debug("*** Gateway Adress is changed to [%s]", self._gateway)
463
464 message = Maint_8()
465 message.state = message.OP_OPERATIONAL
466 command = MaintRfc_8()
467 command.command = command.SET_STATE
468 command.data = (command.OP_MAINTENANCE,)
469 message.add_message(command)
470 self._handler.sendto(message)
471
472 def _set_slots(self):
473 # set slots
474 message = Maint_8()
475 message.state = message.OP_MAINTENANCE
476
477 #LOG.debug("============")
478 #LOG.debug("GAIN SETTING")
479 #LOG.debug("============")
480
481 gains = enumerate(self._config['gains'])
482 for num, gain in gains:
483 channel, slotno = divmod(num, 127)
484 command = MaintRfc_8()
485 command.command = command.SET_GENERIC_SLOT_TBL_ENTRY
486 command.data = (channel * 2**12 +
487 slotno * 2**8 +
488 gain,)
489 message.add_message(command)
490 #LOG.debug("Added gain: %d/%d: Gain: %d", channel, slotno, gain) # only the last
491 #self._handler.sendto(message)
492
493 message = Maint_8()
494 message.state = message.OP_MAINTENANCE
495
496 slots = enumerate(self._config['slots'])
497 oldchannel = -1
498 #time.sleep(.1)
499
500 for num, slotpos in slots:
501 channel = num // 8
502 slotno = num % 16
503 command.command = command.SET_SLOT_POSITION # CMD = 27, 0x1B
504 if oldchannel != channel:
505 oldslot = 0
506 if oldchannel == channel and oldslot > slotpos:
507 slotpos = 0
508 command.data = (channel * 2**20 +
509 slotno * 2**16 +
510 slotpos, )
511 message.add_message(command)
512 oldchannel = channel
513 oldslot = slotpos
514 LOG.debug("Added slot: %d/%d: Slotpos: %d", channel, slotno, slotpos)
515 self._handler.sendto(message)
516
517
518 # set AGC
519 #LOG.info ("!!! AGC value is %d", self._config['AGC'])
520 if self._config['AGC'] != 0:
521 return
522
523 def _set_pre_config(self):
524 #LOG.debug("IN _set_pre_config")
525 message = Maint_8()
526 message.state = message.OP_MAINTENANCE
527
528 # transmission rate
529 command = MaintRfc_8()
530 command.command = command.SET_AGC_RATE
531 command.data = (self._config['AGC'],)
532 #LOG.debug("SENDED AGC COMMAND: %d:", self._config['AGC'])
533 message.add_message(command)
534 self._handler.sendto(message)
535 # print(message.payload.hex())
536
537 # Set Raw scan type
538 # Aviable types:
539 # yyyy xxxx
540 # where yyyy: =
541 # 0 : channel diodes
542 # 1 : Receiver test ramps
543 # 2 : Slots
544 # 3 : Gains
545 # 4 : Dsp test Arrays
546 # 5 : Photo-Diode baseline levels
547 # 6 : Etalon photo-diodes
548 # 7 : Laser Test ramps
549 # 8 : Laser LUT's
550 # 9 : Thermistors
551 #
552 # and xxxx: = channels 0..7
553
554 message = Maint_8()
555 message.state = message.OP_MAINTENANCE
556
557 # set all channels to 0011cccc [GAINS]
558 iTypeSet = self._config['source_type']
559 if iTypeSet != -1:
560 for channel in range(0, 8):
561 command = MaintRfc_8()
562 command.command = command.SET_RAW_SCAN_SOURCE
563 command.data = (iTypeSet * 2**4 + channel,)
564 #LOG.debug("Set channel <%d> to %x", channel, iTypeSet * 2**4 + channel)
565 #command.data = ((self._config["source_type"] * 2 ** 4) + channel,)
566 #LOG.debug("Set raw scan source ndx = <%d> for : channel %d", iTypeSet, channel)
567 message.add_message(command)
568 else:
569 print("SET RAW SCAN SOURCE (CMD=2) !!! NOT SET !!!")
570
571 # spectrum rate
572 command = MaintRfc_8()
573 command.command = command.SET_SPECTRUM_TRANSMISSION_RATE
574 command.data = (self._config['spectrarate'],)
575 message.add_message(command)
576 #LOG.debug("Set spectrum rate: %d", self._config['spectrarate'])
577
578 # transmission rate
579 command = MaintRfc_8()
580 command.command = command.SET_DATA_TRANSMISSION_RATE
581 command.data = (self._config['datarate'],)
582 message.add_message(command)
583 #LOG.debug("Set datarate: %d", self._config['datarate'])
584
585 # set channel_format 0Dxx xxxx gggg chan
586 # ==================
587 # b[15] :: unused
588 # b[14] (D) :: DSP write mode 0 = SLOT ADDRESS 1 = CONTIGUOUS
589 # b[13..9] :: unused
590 # b[ 8..4] :: number of gratings - 1 [0..15]
591 # b[ 3..0] :: number of channels - 1 [0..7]
592 # command = MaintRfc_8()
593 # command.command = command.SET_CHANNEL_FORMAT
594 # command.data = ((1 * 2**14) + self._config['freq steps/scan'],)
595 # LOG.debug("Set channel format: Cycle step time = [12..10] [%d] :: Scan numbers of step = [9..0] [%d]",
596 # self._cfg_speedCode, self._config['freq steps/scan'])
597 # message.add_message(command)
598 # self._handler.sendto(message)
599
600
601 # channel threshold
602 # LOG.info("WORK in Threshold with num = %d and val = %d", num, val)
603 for num, val in enumerate(self._config['threshold']):
604 command = MaintRfc_8()
605 command.command = command.SET_THRESHOLD
606 # channel Threshold
607 command.data = (num * 2**16 + val,)
608 #LOG.debug("Set threshold entry: [%d] %s %s", num, val, command.data)
609 message.add_message(command)
610 print(message.payload.hex())
611 # set speed code 09::02 0xxx
612 # ==============
613 # b[ 9.. 0] :: Scan Nr of steps - 1
614 # b[12..10] :: Cycle (step) code (time in uS)
615 # 0 = 1 uS :: 1 = 2 uS :: 2 = 5 uS :: 3 = 10 uS :: 4 = 20 uS :: 5 = 50 uS :: 6 = 100 uS
616 # Be careful: On 4 Port scanner exists two methods
617 #
618 # NEW GH 26.06.2018
619 #
620 command = MaintRfc_8()
621 command.command = command.SET_ACQUISITION_RATE
622 modify_steps_per_scan = self._config['freq steps/scan'] - 1
623 command.data = ((self._cfg_speedCode * 2**10) + modify_steps_per_scan,)
624 #LOG.debug("Set speed code: Cycle step time = [12..10] [%d] :: Modify (-1) Scan numbers of step = [9..0] [%d]",
625 #### self._cfg_speedCode, modify_steps_per_scan)
626 message.add_message(command)
627
628 # set first laser step
629 command = MaintRfc_8()
630 command.command = command.SET_FIRST_LASER_STEP
631 command.data = (self._config['laser offset'],)
632 message.add_message(command)
633 #LOG.debug("Set first laser step: %d", self._config['laser offset'])
634 # send data
635 self._handler.sendto(message)
636
637 # set State :: for 8 channel set always the state
638 message.state = message.OP_MAINTENANCE
639
640 def _set_acquisition_rate(self, message):
641 # set acquisition rate cycle time (us)
642 rate = self._config['Cycle time (us)']
643 if rate > 1.9:
644 if rate > 4.9:
645 if rate > 9.9:
646 if rate > 19.9:
647 if rate > 49.9:
648 laserperiod = 5
649 else:
650 laserperiod = 4
651 else:
652 laserperiod = 3
653 else:
654 laserperiod = 2
655 else:
656 laserperiod = 1
657 else:
658 laserperiod = 0
659 command = MaintRfc_8()
660 command.command = command.SET_ACQUISITION_RATE
661 command.data = (2**15 + # method 2
662 laserperiod * 2**10 + # laser period
663 self._config['freq steps/scan'], )
664 message.add_message(command)
665 LOG.debug("Set acquisition rate to: laserperiod %d"
666 " freq steps per scan: %d, ALL: 0x%x", laserperiod, self._config['freq steps/scan'], command.data[0])
667
668 def _set_post_config(self):
669 message = Maint_8()
670 message.state = message.OP_OPERATIONAL
671
672 # Set slot before this
673 # command = MaintRfc()
674 # command.command = command.SET_CHANNEL_FORMAT
675 # command.data = (int('1000000100000100', 2), )
676 # message.add_message(command)
677 # LOG.debug("Channel format set to 0x%x", command.data[0])
678
679 # Set slot before this NEW GHE
680 command = MaintRfc_8()
681 command.command = command.SET_CHANNEL_FORMAT
682 # bit (15) unused
683 # bit (14) set DSP write method 0 = slot address 1 _= continuous
684 # bits (13..9) unused
685 # bits (8..4) set number of gratings == 16 - 1 :: grating 1 == [0], 2 == [1],..
686 # bits (3..0) set number of gratings == 8 - 1 :: channel 1 == [0] .. channel 8 = [7]
687 #print ("PARAMETER SETTING FOR SET_CHANNEL_FORMAT")
688 setChannels = self._config['channelno'] - 1
689 #print ("SET CHANNELS = " + repr(setChannels) )
690 setGratings = self._config['gratings'] - 1
691 #print ("SET GRATINGS = " + repr(setGratings) )
692 setSlotMode = self._config['slot_mode']
693 #print ("SET SLOT MODE = " + repr(setSlotMode) )
694 command.data = ((setSlotMode * 2 ** 14) + (setGratings * 2 ** 4) + setChannels,)
695 message.add_message(command)
696 LOG.debug("Channel format set to 0x%x", command.data[0])
697
698 self._handler.sendto(message)
699
700 time.sleep(3)
701 self.sync_time()
702 # Set OPERATIONAL
703 message = Maint_8()
704 message.state = message.OP_OPERATIONAL
705 command = MaintRfc_8()
706 command.command = command.SET_STATE
707 command.data = (command.OP_OPERATIONAL,)
708 message.add_message(command)
709 LOG.debug("Setting operational")
710
711 self._handler.sendto(message)