##// END OF EJS Templates
add cgs_status command to rc/models.py to program cgs
jrojas -
r417:bd23d85743d8
parent child
Show More
@@ -80,7 +80,6 class RCConfiguration(Configuration):
80 80 time_before = models.PositiveIntegerField(verbose_name='Time before [μS]', default=12)
81 81 time_after = models.PositiveIntegerField(verbose_name='Time after [μS]', default=1)
82 82 sync = models.PositiveIntegerField(verbose_name='Synchro delay', default=0)
83 ch_monitor = models.PositiveIntegerField(verbose_name='Channel Monitor', validators=[MinValueValidator(0), MaxValueValidator(15)], default=6)
84 83 sampling_reference = models.CharField(verbose_name='Sampling Reference', choices=SAMPLING_REFS, default='none', max_length=40)
85 84 control_tx = models.BooleanField(verbose_name='Control Switch TX', default=False)
86 85 control_sw = models.BooleanField(verbose_name='Control Switch SW', default=False)
@@ -253,10 +252,11 class RCConfiguration(Configuration):
253 252 #print('ups_arr', ups_arr)
254 253 #print('dws_arr', dws_arr)
255 254
255 #####################Code for load configuration#########################
256 256 for x in points:
257 257 dum = []
258 258 print('loading', x*100/max(points))
259
259
260 260 for i in range(n_pulses):
261 261 if x in ups_arr[i]:
262 262 dum.append(1)
@@ -267,6 +267,8 class RCConfiguration(Configuration):
267 267 #print(dum)
268 268 states.append(dum)
269 269 last = dum
270 print("Finish loading")
271 #########################################################################
270 272
271 273 if binary:
272 274 ret = []
@@ -577,39 +579,49 class RCConfiguration(Configuration):
577 579
578 580 def write_device(self, raw=False):
579 581 print("write device")
582 ##############Comando status a CGS para hacer programacion ############
583 try:
584 self.device.status = 0
585 cgs = self.request('status_cgs')
586 print('CGS status ok') # solo para depurar lo que devuelve CGS
587 except Exception as e:
588 cgs = {'multiplier': 60, 'divider': 10, 'reference_clk': 1} # simulando parametros devueltos por el cgs
589 if 'No route to host' not in str(e):
590 self.device.status = 4
591 self.device.save()
592 self.message = 'CGS status: {}'.format(str(e))
593 print('not cgs status')
580 594
581 if not raw:
582
583
595 print(cgs)
584 596
597 if not raw:
585 598 clock = RCClock.objects.get(rc_configuration=self)
599 print('clock_freq', clock.frequency)
600 print('clock_mult', clock.multiplier)
601 print('clock_div', clock.divisor)
602 print('clock_ref', clock.reference)
603 print('cgs', cgs)
586 604 if clock.mode:
587 data = {'default': clock.frequency}
605 data = {'default': clock.frequency} # mult=72, div=12
588 606 else:
589 607 data = {'manual': [clock.multiplier, clock.divisor, clock.reference]}
590 payload = self.request('setfreq', 'post', data=json.dumps(data))
591 #if payload['setfreq'] != 'ok':
592 if payload['command'] != 'ok':
593 #self.message = 'RC write: {}'.format(payload['setfreq'])
594 self.message = 'RC write: {}'.format(payload['command'])
595 else:
596 #self.message = payload['setfreq']
597 self.message = payload['programming']
598 #if payload['setfreq'] == 'fail':
599 if payload['programming'] == 'fail':
600 self.message = 'RC write: error programming CGS chip'
601
602 ##############################################################
603 data = {'setwindow': self.ch_monitor}
604 print(data)
605 payload = self.request('setwin', 'post', data=json.dumps(data))
606
607 if payload['setwindow'] == 'ok':
608 self.message = 'RC write: {}'.format(payload['setwindow'])
608 print('data', data)
609 int_cgs_multiplier=int(cgs['multiplier'])
610 int_cgs_divisor=int(cgs['divider'])
611 int_cgs_reference=int(cgs['reference_clk'])
612 print(cgs['divider'])
613
614 if clock.multiplier != int_cgs_multiplier or clock.divisor != int_cgs_divisor or clock.reference != int_cgs_reference:
615 print("Program CGS...")
616 payload = self.request('setfreq', 'post', data=json.dumps(data))#data=data)#data=json.dumps(data))
617 if payload['command'] != 'ok':
618 self.message = 'RC write: {}'.format(payload['command'])
619 else:
620 self.message = payload['programming']
621 if payload['programming'] == 'fail':
622 self.message = 'RC write: error programming CGS chip'
609 623 else:
610 if payload['command'] != 'wrong format or key':
611 self.message = 'Error RC monitor channel: {}'.format(payload['command'])
612 ##############################################################
624 print("Not program CGS...")
613 625
614 626 values = []
615 627 print('wait delay values...')
@@ -660,8 +672,8 class RCConfiguration(Configuration):
660 672 cnt = 0
661 673 while x < n:
662 674 print('writing...', cnt)
663 payload = self.request('write', 'post', data=b64encode(data[x:x+3072]))#(data))#
664 x += 3072
675 payload = self.request('write', 'post', data=b64encode(data[x:x+16384]))#(data))#
676 x += 16384
665 677 cnt += 1#time.sleep(1)
666 678 print('writing...', x*100/n)
667 679
General Comments 0
You need to be logged in to leave comments. Login now