@@ -37,6 +37,7 class CGSConfiguration(Configuration): | |||
|
37 | 37 | parameters = {} |
|
38 | 38 | |
|
39 | 39 | parameters['device_id'] = self.device.id |
|
40 | parameters['device_type'] = self.device.device_type.name | |
|
40 | 41 | |
|
41 | 42 | if self.freq0 == None or self.freq0 == '': |
|
42 | 43 | parameters['freq0'] = 0 |
@@ -74,6 +74,7 class DDSConfiguration(Configuration): | |||
|
74 | 74 | parameters = {} |
|
75 | 75 | |
|
76 | 76 | parameters['device_id'] = self.device.id |
|
77 | parameters['device_type'] = self.device.device_type.name | |
|
77 | 78 | |
|
78 | 79 | parameters['clock'] = float(self.clock) |
|
79 | 80 | parameters['multiplier'] = int(self.multiplier) |
@@ -155,18 +156,18 class DDSConfiguration(Configuration): | |||
|
155 | 156 | |
|
156 | 157 | try: |
|
157 | 158 | answer = api.status(ip = self.device.ip_address, |
|
158 |
port = self.device.port_address) |
|
|
159 |
if 'clock' in answer: |
|
|
159 | port = self.device.port_address) | |
|
160 | if 'clock' in answer: | |
|
160 | 161 | self.device.status = 1 |
|
161 | 162 | else: |
|
162 |
self.device.status = answer[0] |
|
|
163 |
self.message = 'DDS - {}'.format(answer[2:]) |
|
|
163 | self.device.status = answer[0] | |
|
164 | self.message = 'DDS - {}'.format(answer[2:]) | |
|
164 | 165 | except Exception as e: |
|
165 |
self.message = str(e) |
|
|
166 | self.message = str(e) | |
|
166 | 167 | self.device.status = 0 |
|
167 | ||
|
168 | ||
|
168 | 169 | self.device.save() |
|
169 | ||
|
170 | ||
|
170 | 171 | if self.device.status in (0, '0'): |
|
171 | 172 | return False |
|
172 | 173 | else: |
@@ -189,9 +190,9 class DDSConfiguration(Configuration): | |||
|
189 | 190 | try: |
|
190 | 191 | answer = api.disable_rf(ip = self.device.ip_address, |
|
191 | 192 | port = self.device.port_address) |
|
192 | ||
|
193 | ||
|
193 | 194 | return self.status_device() |
|
194 | ||
|
195 | ||
|
195 | 196 | except Exception as e: |
|
196 | 197 | self.message = str(e) |
|
197 | 198 | return False |
@@ -201,9 +202,9 class DDSConfiguration(Configuration): | |||
|
201 | 202 | try: |
|
202 | 203 | answer = api.enable_rf(ip = self.device.ip_address, |
|
203 | 204 | port = self.device.port_address) |
|
204 | ||
|
205 | ||
|
205 | 206 | return self.status_device() |
|
206 | ||
|
207 | ||
|
207 | 208 | except Exception as e: |
|
208 | 209 | self.message = str(e) |
|
209 | 210 | return False |
@@ -226,12 +227,12 class DDSConfiguration(Configuration): | |||
|
226 | 227 | answer = api.write_config(ip = self.device.ip_address, |
|
227 | 228 | port = self.device.port_address, |
|
228 | 229 | parms = self.parms_to_dict()) |
|
229 | ||
|
230 | ||
|
230 | 231 | return self.status_device() |
|
231 | ||
|
232 | ||
|
232 | 233 | except Exception as e: |
|
233 | 234 | self.message = str(e) |
|
234 |
return False |
|
|
235 | ||
|
235 | return False | |
|
236 | ||
|
236 | 237 | class Meta: |
|
237 | 238 | db_table = 'dds_configurations' |
@@ -112,6 +112,7 class JARSConfiguration(Configuration): | |||
|
112 | 112 | |
|
113 | 113 | parameters['device_id'] = self.device.id |
|
114 | 114 | parameters['name'] = self.name |
|
115 | parameters['device_type'] = self.device.device_type.name | |
|
115 | 116 | #parameters['rc'] = self.rc.name |
|
116 | 117 | parameters['exp_type'] = self.exp_type |
|
117 | 118 | parameters['exptype'] = EXPERIMENT_TYPE[self.exp_type][1] |
@@ -139,7 +139,7 class Device(models.Model): | |||
|
139 | 139 | def change_ip(self, ip_address, mask, gateway, **kwargs): |
|
140 | 140 | |
|
141 | 141 | if self.device_type.name=='dds': |
|
142 |
try: |
|
|
142 | try: | |
|
143 | 143 | answer = dds_api.change_ip(ip = self.ip_address, |
|
144 | 144 | port = self.port_address, |
|
145 | 145 | new_ip = ip_address, |
@@ -155,16 +155,16 class Device(models.Model): | |||
|
155 | 155 | except Exception as e: |
|
156 | 156 | self.message = '40|{}'.format(str(e)) |
|
157 | 157 | return False |
|
158 | ||
|
158 | ||
|
159 | 159 | elif self.device_type.name=='rc': |
|
160 | 160 | payload = {'ip': ip_address, |
|
161 | 161 | 'dns': kwargs.get('dns', '8.8.8.8'), |
|
162 | 162 | 'gateway': gateway, |
|
163 |
'subnet': mask} |
|
|
163 | 'subnet': mask} | |
|
164 | 164 | req = requests.post(self.url('changeip'), data=payload) |
|
165 | 165 | try: |
|
166 | 166 | answer = req.json() |
|
167 |
if answer['changeip']=='ok': |
|
|
167 | if answer['changeip']=='ok': | |
|
168 | 168 | self.message = '25|IP succesfully changed' |
|
169 | 169 | self.ip_address = ip_address |
|
170 | 170 | self.save() |
@@ -396,7 +396,7 class Experiment(models.Model): | |||
|
396 | 396 | result = 1 |
|
397 | 397 | |
|
398 | 398 | confs = Configuration.objects.filter(experiment=self).order_by('-device__device_type__sequence') |
|
399 |
for i in range(0,len(confs)): |
|
|
399 | for i in range(0,len(confs)): | |
|
400 | 400 | if i==0: |
|
401 | 401 | for conf in confs: |
|
402 | 402 | if conf.device.device_type.name == 'abs': |
@@ -431,10 +431,10 class Experiment(models.Model): | |||
|
431 | 431 | def get_status(self): |
|
432 | 432 | |
|
433 | 433 | confs = Configuration.objects.filter(experiment=self) |
|
434 | ||
|
434 | ||
|
435 | 435 | for conf in confs: |
|
436 | 436 | conf.status_device() |
|
437 | ||
|
437 | ||
|
438 | 438 | total = confs.aggregate(models.Sum('device__status'))['device__status__sum'] |
|
439 | 439 | |
|
440 | 440 | if total==2*confs.count(): |
@@ -465,23 +465,12 class Experiment(models.Model): | |||
|
465 | 465 | |
|
466 | 466 | import json |
|
467 | 467 | |
|
468 | configurations = Configuration.objects.filter(experiment=self) | |
|
468 | configurations = Configuration.objects.filter(experiment=self).filter(type=0) | |
|
469 | 469 | conf_parameters = {} |
|
470 | 470 | parameters={} |
|
471 | 471 | |
|
472 | 472 | for configuration in configurations: |
|
473 | if 'cgs' in configuration.device.device_type.name: | |
|
474 | conf_parameters['cgs'] = configuration.parms_to_dict() | |
|
475 | if 'dds' in configuration.device.device_type.name: | |
|
476 | conf_parameters['dds'] = configuration.parms_to_dict() | |
|
477 | if 'rc' in configuration.device.device_type.name: | |
|
478 | conf_parameters['rc'] = configuration.parms_to_dict() | |
|
479 | if 'jars' in configuration.device.device_type.name: | |
|
480 | conf_parameters['jars'] = configuration.parms_to_dict() | |
|
481 | if 'usrp' in configuration.device.device_type.name: | |
|
482 | conf_parameters['usrp'] = configuration.parms_to_dict() | |
|
483 | if 'abs' in configuration.device.device_type.name: | |
|
484 | conf_parameters['abs'] = configuration.parms_to_dict() | |
|
473 | conf_parameters[configuration.name] = configuration.parms_to_dict() | |
|
485 | 474 | |
|
486 | 475 | parameters['configurations'] = conf_parameters |
|
487 | 476 | parameters['end_time'] = self.end_time.strftime("%H:%M:%S") |
@@ -510,56 +499,37 class Experiment(models.Model): | |||
|
510 | 499 | configurations = Configuration.objects.filter(experiment=self) |
|
511 | 500 | |
|
512 | 501 | if configurations: |
|
513 |
|
|
|
514 |
|
|
|
515 | ||
|
516 |
for conf |
|
|
517 | #--For ABS Device: | |
|
518 | #--For USRP Device: | |
|
519 | #--For JARS Device: | |
|
520 | if conf_type == 'jars': | |
|
521 | device = get_object_or_404(Device, pk=parms['configurations']['jars']['device_id']) | |
|
522 | DevConfModel = CONF_MODELS[conf_type] | |
|
523 | confjars_form = DevConfModel( | |
|
524 | experiment = self, | |
|
525 | name = 'JARS', | |
|
526 | device=device, | |
|
527 | ) | |
|
528 | confjars_form.dict_to_parms(parms['configurations']['jars']) | |
|
529 | confjars_form.save() | |
|
530 | #--For RC Device: | |
|
531 | if conf_type == 'rc': | |
|
532 | device = get_object_or_404(Device, pk=parms['configurations']['rc']['device_id']) | |
|
533 | DevConfModel = CONF_MODELS[conf_type] | |
|
534 | confrc_form = DevConfModel( | |
|
535 | experiment = self, | |
|
536 | name = 'RC', | |
|
537 |
|
|
|
538 |
|
|
|
539 | confrc_form.dict_to_parms(parms['configurations']['rc']) | |
|
540 |
|
|
|
541 | #--For DDS Device: | |
|
542 | if conf_type == 'dds': | |
|
543 | device = get_object_or_404(Device, pk=parms['configurations']['dds']['device_id']) | |
|
544 | DevConfModel = CONF_MODELS[conf_type] | |
|
545 | confdds_form = DevConfModel( | |
|
546 | experiment = self, | |
|
547 | name = 'DDS', | |
|
548 | device=device, | |
|
549 | ) | |
|
550 | confdds_form.dict_to_parms(parms['configurations']['dds']) | |
|
551 | confdds_form.save() | |
|
552 | #--For CGS Device: | |
|
553 | if conf_type == 'cgs': | |
|
554 | device = get_object_or_404(Device, pk=parms['configurations']['cgs']['device_id']) | |
|
555 | DevConfModel = CONF_MODELS[conf_type] | |
|
556 | confcgs_form = DevConfModel( | |
|
557 | experiment = self, | |
|
558 | name = 'CGS', | |
|
559 | device=device, | |
|
560 | ) | |
|
561 | confcgs_form.dict_to_parms(parms['configurations']['cgs']) | |
|
562 | confcgs_form.save() | |
|
502 | for configuration in configurations: | |
|
503 | configuration.delete() | |
|
504 | #If device is missing. | |
|
505 | for configuration in parms['configurations']: | |
|
506 | try: | |
|
507 | device = Device.objects.filter(device_type__name=parms['configurations'][configuration]['device_type'])[0] | |
|
508 | except: | |
|
509 | return {'Error': 'Device is not in database. Please create new '+str(parms['configurations'][configuration]['device_type'])+ ' device.'} | |
|
510 | ||
|
511 | for configuration in parms['configurations']: | |
|
512 | device = Device.objects.filter(device_type__name=parms['configurations'][configuration]['device_type'])[0] | |
|
513 | if parms['configurations'][configuration]['device_type'] == 'rc': | |
|
514 | if bool(parms['configurations'][configuration]['mix']) == False: | |
|
515 | DevConfModel = CONF_MODELS[parms['configurations'][configuration]['device_type']] | |
|
516 | new_conf = DevConfModel( | |
|
517 | experiment = self, | |
|
518 | name = configuration, | |
|
519 | device = device, | |
|
520 | ) | |
|
521 | new_conf.dict_to_parms(parms['configurations'][configuration]) | |
|
522 | new_conf.save() | |
|
523 | else: | |
|
524 | DevConfModel = CONF_MODELS[parms['configurations'][configuration]['device_type']] | |
|
525 | new_conf = DevConfModel( | |
|
526 | experiment = self, | |
|
527 | name = configuration, | |
|
528 | device = device, | |
|
529 | ) | |
|
530 | new_conf.dict_to_parms(parms['configurations'][configuration]) | |
|
531 | new_conf.save() | |
|
532 | ||
|
563 | 533 | |
|
564 | 534 | location = Location.objects.get(name = parms['radar']) |
|
565 | 535 | self.name = parms['experiment'] |
@@ -1,1 +1,1 | |||
|
1 | {% extends "experiment_edit.html" %} No newline at end of file | |
|
1 | {% extends "experiment_edit.html" %} |
@@ -684,7 +684,7 def experiment_import(request, id_exp): | |||
|
684 | 684 | |
|
685 | 685 | if request.method == 'POST': |
|
686 | 686 | file_form = UploadFileForm(request.POST, request.FILES) |
|
687 | print 'aqui 1' | |
|
687 | ||
|
688 | 688 | if file_form.is_valid(): |
|
689 | 689 | |
|
690 | 690 | parms = experiment.import_from_file(request.FILES['file']) |
@@ -693,6 +693,10 def experiment_import(request, id_exp): | |||
|
693 | 693 | |
|
694 | 694 | new_exp = experiment.dict_to_parms(parms, CONF_MODELS) |
|
695 | 695 | |
|
696 | if new_exp.__class__.__name__=='dict': | |
|
697 | messages.error(request, new_exp['Error'] ) | |
|
698 | return redirect(experiment.get_absolute_url_import()) | |
|
699 | ||
|
696 | 700 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
697 | 701 | |
|
698 | 702 | return redirect(new_exp.get_absolute_url_edit()) |
@@ -135,8 +135,8 class RCConfiguration(Configuration): | |||
|
135 | 135 | ''' |
|
136 | 136 | ''' |
|
137 | 137 | |
|
138 |
ignored = ('parameters', 'type', |
|
|
139 | 'created_date', 'programmed_date') | |
|
138 | ignored = ('parameters', 'type','polymorphic_ctype', 'configuration_ptr', | |
|
139 | 'created_date', 'programmed_date', 'mix') | |
|
140 | 140 | |
|
141 | 141 | data = {} |
|
142 | 142 | for field in self._meta.fields: |
@@ -145,7 +145,9 class RCConfiguration(Configuration): | |||
|
145 | 145 | data[field.name] = '{}'.format(field.value_from_object(self)) |
|
146 | 146 | |
|
147 | 147 | data['device_id'] = data.pop('device') |
|
148 | data['device_type'] = self.device.device_type.name | |
|
148 | 149 | data['lines'] = [] |
|
150 | data['mix'] = self.mix | |
|
149 | 151 | |
|
150 | 152 | for line in self.get_lines(): |
|
151 | 153 | line_data = json.loads(line.params) |
@@ -237,36 +239,36 class RCConfiguration(Configuration): | |||
|
237 | 239 | |
|
238 | 240 | def get_pulses(self, binary=True): |
|
239 | 241 | |
|
240 | ||
|
241 |
pulses = [line.pulses_as_points() for line in self.get_lines()] |
|
|
242 |
tuples = [tup for tups in pulses for tup in tups] |
|
|
242 | ||
|
243 | pulses = [line.pulses_as_points() for line in self.get_lines()] | |
|
244 | tuples = [tup for tups in pulses for tup in tups] | |
|
243 | 245 | points = set([x for tup in tuples for x in tup]) |
|
244 | 246 | points = list(points) |
|
245 |
points.sort() |
|
|
247 | points.sort() | |
|
246 | 248 | states = [] |
|
247 | 249 | last = [0 for x in pulses] |
|
248 | ||
|
250 | ||
|
249 | 251 | for x in points: |
|
250 | 252 | dum = [] |
|
251 | 253 | for i,tups in enumerate(pulses): |
|
252 | 254 | ups = [tup[0] for tup in tups] |
|
253 |
dws = [tup[1] for tup in tups] |
|
|
255 | dws = [tup[1] for tup in tups] | |
|
254 | 256 | if x in ups: |
|
255 | 257 | dum.append(1) |
|
256 | 258 | elif x in dws: |
|
257 | 259 | dum.append(0) |
|
258 | 260 | else: |
|
259 |
dum.append(last[i]) |
|
|
261 | dum.append(last[i]) | |
|
260 | 262 | states.append(dum) |
|
261 |
last = dum |
|
|
263 | last = dum | |
|
262 | 264 | |
|
263 | 265 | if binary: |
|
264 | 266 | ret = [] |
|
265 | 267 | for flips in states: |
|
266 | 268 | flips.reverse() |
|
267 |
ret.append(int(''.join([str(x) for x in flips]), 2)) |
|
|
269 | ret.append(int(''.join([str(x) for x in flips]), 2)) | |
|
268 | 270 | states = ret |
|
269 | ||
|
271 | ||
|
270 | 272 | return states[:-1] |
|
271 | 273 | |
|
272 | 274 | def add_cmd(self, cmd): |
@@ -277,7 +279,7 class RCConfiguration(Configuration): | |||
|
277 | 279 | def add_data(self, value): |
|
278 | 280 | |
|
279 | 281 | return (254, value-1) |
|
280 | ||
|
282 | ||
|
281 | 283 | def parms_to_binary(self, dat=True): |
|
282 | 284 | ''' |
|
283 | 285 | Create "dat" stream to be send to CR |
@@ -321,9 +323,9 class RCConfiguration(Configuration): | |||
|
321 | 323 | |
|
322 | 324 | states = self.get_pulses(binary=True) |
|
323 | 325 | |
|
324 | ||
|
326 | ||
|
325 | 327 | last = 0 |
|
326 |
for flip, delay in zip(states, delays): |
|
|
328 | for flip, delay in zip(states, delays): | |
|
327 | 329 | data.extend(self.add_data((flip^last)+1)) |
|
328 | 330 | last = flip |
|
329 | 331 | while delay>252: |
@@ -344,7 +346,7 class RCConfiguration(Configuration): | |||
|
344 | 346 | data.extend(self.add_data(dh)) |
|
345 | 347 | |
|
346 | 348 | # write enable |
|
347 |
data.extend(self.add_cmd('ENABLE')) |
|
|
349 | data.extend(self.add_cmd('ENABLE')) | |
|
348 | 350 | |
|
349 | 351 | if not dat: |
|
350 | 352 | return data |
@@ -401,7 +403,7 class RCConfiguration(Configuration): | |||
|
401 | 403 | ax.set_yticks(range(len(labels))) |
|
402 | 404 | ax.set_yticklabels(labels) |
|
403 | 405 | ax.set_xlabel = 'Units' |
|
404 |
plot = to_bokeh(fig, use_pandas=False) |
|
|
406 | plot = to_bokeh(fig, use_pandas=False) | |
|
405 | 407 | plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), SaveTool()] |
|
406 | 408 | plot.toolbar_location="above" |
|
407 | 409 | |
@@ -417,36 +419,36 class RCConfiguration(Configuration): | |||
|
417 | 419 | from bokeh.models.sources import ColumnDataSource |
|
418 | 420 | |
|
419 | 421 | lines = self.get_lines().reverse() |
|
420 | ||
|
422 | ||
|
421 | 423 | N = len(lines) |
|
422 | 424 | npoints = self.total_units/self.km2unit if km else self.total_units |
|
423 | 425 | ipp = self.ipp if km else self.ipp*self.km2unit |
|
424 | ||
|
426 | ||
|
425 | 427 | hover = HoverTool(tooltips=[("Line", "@name"), |
|
426 | 428 | ("IPP", "@ipp"), |
|
427 | 429 | ("X", "@left")]) |
|
428 | ||
|
429 |
tools = [PanTool(dimensions=['width']), |
|
|
430 |
WheelZoomTool(dimensions=['width']), |
|
|
430 | ||
|
431 | tools = [PanTool(dimensions=['width']), | |
|
432 | WheelZoomTool(dimensions=['width']), | |
|
431 | 433 | hover, SaveTool()] |
|
432 | ||
|
433 |
plot = figure(width=1000, |
|
|
434 |
height=40+N*50, |
|
|
434 | ||
|
435 | plot = figure(width=1000, | |
|
436 | height=40+N*50, | |
|
435 | 437 | y_range = (0, N), |
|
436 |
tools=tools, |
|
|
438 | tools=tools, | |
|
437 | 439 | toolbar_location='above', |
|
438 |
toolbar_sticky=False,) |
|
|
439 | ||
|
440 | toolbar_sticky=False,) | |
|
441 | ||
|
440 | 442 | plot.xaxis.axis_label = 'Km' if km else 'Units' |
|
441 | 443 | plot.xaxis[0].formatter = PrintfTickFormatter(format='%d') |
|
442 |
plot.yaxis.axis_label = 'Pulses' |
|
|
444 | plot.yaxis.axis_label = 'Pulses' | |
|
443 | 445 | plot.yaxis[0].ticker=FixedTicker(ticks=list(range(N))) |
|
444 | 446 | plot.yaxis[0].formatter = PrintfTickFormatter(format='Line %d') |
|
445 | 447 | |
|
446 |
for i, line in enumerate(lines): |
|
|
447 | ||
|
448 | for i, line in enumerate(lines): | |
|
449 | ||
|
448 | 450 | points = [tup for tup in line.pulses_as_points(km=km) if tup!=(0,0)] |
|
449 | ||
|
451 | ||
|
450 | 452 | source = ColumnDataSource(data = dict( |
|
451 | 453 | bottom = [i for tup in points], |
|
452 | 454 | top = [i+0.5 for tup in points], |
@@ -455,7 +457,7 class RCConfiguration(Configuration): | |||
|
455 | 457 | ipp = [int(tup[0]/ipp) for tup in points], |
|
456 | 458 | name = [line.get_name() for tup in points] |
|
457 | 459 | )) |
|
458 | ||
|
460 | ||
|
459 | 461 | plot.quad( |
|
460 | 462 | bottom = 'bottom', |
|
461 | 463 | top = 'top', |
@@ -465,7 +467,7 class RCConfiguration(Configuration): | |||
|
465 | 467 | fill_alpha = 0, |
|
466 | 468 | #line_color = 'blue', |
|
467 | 469 | ) |
|
468 | ||
|
470 | ||
|
469 | 471 | plot.line([0, npoints], [i, i])#, color='blue') |
|
470 | 472 | |
|
471 | 473 | return components(plot, CDN) |
@@ -481,7 +483,7 class RCConfiguration(Configuration): | |||
|
481 | 483 | elif payload['status']=='disabled': |
|
482 | 484 | self.device.status = 2 |
|
483 | 485 | else: |
|
484 |
self.device.status = 1 |
|
|
486 | self.device.status = 1 | |
|
485 | 487 | self.device.save() |
|
486 | 488 | self.message = payload['status'] |
|
487 | 489 | return False |
@@ -491,32 +493,32 class RCConfiguration(Configuration): | |||
|
491 | 493 | self.device.save() |
|
492 | 494 | self.message = str(e) |
|
493 | 495 | return False |
|
494 | ||
|
495 |
self.device.save() |
|
|
496 |
return True |
|
|
496 | ||
|
497 | self.device.save() | |
|
498 | return True | |
|
497 | 499 | |
|
498 | 500 | def reset_device(self): |
|
499 | ||
|
501 | ||
|
500 | 502 | try: |
|
501 | 503 | req = requests.post(self.device.url('reset')) |
|
502 |
payload = req.json() |
|
|
504 | payload = req.json() | |
|
503 | 505 | if payload['reset']=='ok': |
|
504 | 506 | self.message = 'RC restarted' |
|
505 | 507 | else: |
|
506 |
self.message = 'RC restart not ok' |
|
|
508 | self.message = 'RC restart not ok' | |
|
507 | 509 | self.device.status = 4 |
|
508 | 510 | self.device.save() |
|
509 | 511 | except Exception as e: |
|
510 | 512 | self.message = str(e) |
|
511 | 513 | return False |
|
512 | ||
|
514 | ||
|
513 | 515 | return True |
|
514 | ||
|
516 | ||
|
515 | 517 | def stop_device(self): |
|
516 | 518 | |
|
517 | 519 | try: |
|
518 | 520 | req = requests.post(self.device.url('stop')) |
|
519 |
payload = req.json() |
|
|
521 | payload = req.json() | |
|
520 | 522 | if payload['stop']=='ok': |
|
521 | 523 | self.device.status = 2 |
|
522 | 524 | self.device.save() |
@@ -531,10 +533,10 class RCConfiguration(Configuration): | |||
|
531 | 533 | self.device.status = 4 |
|
532 | 534 | else: |
|
533 | 535 | self.device.status = 0 |
|
534 |
self.message = str(e) |
|
|
536 | self.message = str(e) | |
|
535 | 537 | self.device.save() |
|
536 |
return False |
|
|
537 | ||
|
538 | return False | |
|
539 | ||
|
538 | 540 | return True |
|
539 | 541 | |
|
540 | 542 | def start_device(self): |
@@ -554,39 +556,39 class RCConfiguration(Configuration): | |||
|
554 | 556 | self.device.status = 4 |
|
555 | 557 | else: |
|
556 | 558 | self.device.status = 0 |
|
557 |
self.message = str(e) |
|
|
559 | self.message = str(e) | |
|
558 | 560 | self.device.save() |
|
559 | 561 | return False |
|
560 | ||
|
562 | ||
|
561 | 563 | return True |
|
562 | 564 | |
|
563 | 565 | def write_device(self): |
|
564 | ||
|
565 |
values = zip(self.get_pulses(), |
|
|
566 | ||
|
567 | values = zip(self.get_pulses(), | |
|
566 | 568 | [x-1 for x in self.get_delays()]) |
|
567 | ||
|
569 | ||
|
568 | 570 | data = bytearray() |
|
569 |
#reset |
|
|
570 |
data.extend((128, 0)) |
|
|
571 |
#disable |
|
|
571 | #reset | |
|
572 | data.extend((128, 0)) | |
|
573 | #disable | |
|
572 | 574 | data.extend((129, 0)) |
|
573 |
#divider |
|
|
574 |
data.extend((131, self.clock_divider-1)) |
|
|
575 | #divider | |
|
576 | data.extend((131, self.clock_divider-1)) | |
|
575 | 577 | #enable writing |
|
576 | 578 | data.extend((139, 62)) |
|
577 | ||
|
579 | ||
|
578 | 580 | last = 0 |
|
579 |
for tup in values: |
|
|
580 |
vals = pack('<HH', last^tup[0], tup[1]) |
|
|
581 | for tup in values: | |
|
582 | vals = pack('<HH', last^tup[0], tup[1]) | |
|
581 | 583 | last = tup[0] |
|
582 |
data.extend((133, vals[1], 132, vals[0], 133, vals[3], 132, vals[2])) |
|
|
583 | ||
|
584 | data.extend((133, vals[1], 132, vals[0], 133, vals[3], 132, vals[2])) | |
|
585 | ||
|
584 | 586 | #enable |
|
585 | 587 | data.extend((129, 1)) |
|
586 | ||
|
588 | ||
|
587 | 589 | try: |
|
588 | 590 | req = requests.post(self.device.url('write'), data=b64encode(data)) |
|
589 |
payload = req.json() |
|
|
591 | payload = req.json() | |
|
590 | 592 | if payload['write']=='ok': |
|
591 | 593 | self.device.status = 2 |
|
592 | 594 | self.device.save() |
@@ -596,16 +598,16 class RCConfiguration(Configuration): | |||
|
596 | 598 | self.device.save() |
|
597 | 599 | self.message = 'RC write not ok' |
|
598 | 600 | return False |
|
599 | ||
|
601 | ||
|
600 | 602 | except Exception as e: |
|
601 | 603 | if 'No route to host' not in str(e): |
|
602 | 604 | self.device.status = 4 |
|
603 | 605 | else: |
|
604 | 606 | self.device.status = 0 |
|
605 |
self.message = str(e) |
|
|
607 | self.message = str(e) | |
|
606 | 608 | self.device.save() |
|
607 | 609 | return False |
|
608 | ||
|
610 | ||
|
609 | 611 | return True |
|
610 | 612 | |
|
611 | 613 | |
@@ -716,13 +718,13 class RCLine(models.Model): | |||
|
716 | 718 | codes = [line for line in self.get_lines(line_type__name='codes') if int(json.loads(line.params)['TX_ref'])==int(tx_id)] |
|
717 | 719 | |
|
718 | 720 | if codes: |
|
719 |
tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/len(json.loads(codes[0].params)['codes'][0]) |
|
|
721 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit/len(json.loads(codes[0].params)['codes'][0]) | |
|
720 | 722 | else: |
|
721 | 723 | tx_width = float(json.loads(RCLine.objects.get(pk=tx_id).params)['pulse_width'])*km2unit |
|
722 | ||
|
723 |
if ref=='first_baud': |
|
|
724 | ||
|
725 | if ref=='first_baud': | |
|
724 | 726 | return int(1 + round((tx_width + 1)/2 + params['first_height']*km2unit - params['resolution']*km2unit)) |
|
725 |
elif ref=='sub_baud': |
|
|
727 | elif ref=='sub_baud': | |
|
726 | 728 | return np.ceil(1 + params['first_height']*km2unit - params['resolution']*km2unit/2) |
|
727 | 729 | else: |
|
728 | 730 | return 0 |
@@ -810,20 +812,20 class RCLine(models.Model): | |||
|
810 | 812 | tx_params = json.loads(tx.params) |
|
811 | 813 | delays = [float(d)*km2unit for d in tx_params['delays'].split(',') if d] |
|
812 | 814 | f = int(float(tx_params['pulse_width'])*km2unit/len(params['codes'][0])) |
|
813 |
codes = [(np.fromstring(''.join([s*f for s in code]), dtype=np.uint8)-48).astype(np.int8) for code in params['codes']] |
|
|
814 |
codes = [self.array_to_points(code) for code in codes] |
|
|
815 | codes = [(np.fromstring(''.join([s*f for s in code]), dtype=np.uint8)-48).astype(np.int8) for code in params['codes']] | |
|
816 | codes = [self.array_to_points(code) for code in codes] | |
|
815 | 817 | n = len(codes) |
|
816 | ||
|
818 | ||
|
817 | 819 | ranges = tx_params['range'].split(',') |
|
818 | 820 | if len(ranges)>0 and ranges[0]!='0': |
|
819 | 821 | dum = self.mask_ranges(tx.pulses_as_points(), ranges) |
|
820 | 822 | else: |
|
821 |
dum = tx.pulses_as_points() |
|
|
822 | ||
|
823 | dum = tx.pulses_as_points() | |
|
824 | ||
|
823 | 825 | for i, tup in enumerate(dum): |
|
824 | 826 | if tup==(0,0): continue |
|
825 | 827 | code = codes[i%n] |
|
826 |
y.extend([(c[0]+tup[0], c[1]+tup[0]) for c in code]) |
|
|
828 | y.extend([(c[0]+tup[0], c[1]+tup[0]) for c in code]) | |
|
827 | 829 | |
|
828 | 830 | elif self.line_type.name=='sync': |
|
829 | 831 | params = json.loads(self.params) |
@@ -851,7 +853,7 class RCLine(models.Model): | |||
|
851 | 853 | y.extend(y_pp) |
|
852 | 854 | |
|
853 | 855 | elif self.line_type.name=='windows': |
|
854 |
params = json.loads(self.params) |
|
|
856 | params = json.loads(self.params) | |
|
855 | 857 | if 'params' in params and len(params['params'])>0: |
|
856 | 858 | tr_params = json.loads(self.get_lines(line_type__name='tr')[0].params) |
|
857 | 859 | tr_ranges = tr_params['range'].split(',') |
@@ -861,11 +863,11 class RCLine(models.Model): | |||
|
861 | 863 | before=int(self.rc_configuration.time_before*us2unit), |
|
862 | 864 | sync=self.rc_configuration.sync+self.get_win_ref(p, params['TX_ref'], km2unit)) |
|
863 | 865 | |
|
864 | ||
|
866 | ||
|
865 | 867 | if len(tr_ranges)>0 and tr_ranges[0]!='0': |
|
866 | 868 | y_win = self.mask_ranges(y_win, tr_ranges) |
|
867 | 869 | |
|
868 |
y.extend(y_win) |
|
|
870 | y.extend(y_win) | |
|
869 | 871 | |
|
870 | 872 | elif self.line_type.name=='mix': |
|
871 | 873 | values = self.rc_configuration.parameters.split('-') |
General Comments 0
You need to be logged in to leave comments.
Login now