@@ -2,15 +2,28 from django import forms | |||||
2 | from apps.main.models import Device |
|
2 | from apps.main.models import Device | |
3 | from .models import DDSConfiguration |
|
3 | from .models import DDSConfiguration | |
4 |
|
4 | |||
5 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
5 | # from django.core.validators import MinValueValidator, MaxValueValidator | |
6 |
|
6 | |||
7 | class DDSConfigurationForm(forms.ModelForm): |
|
7 | class DDSConfigurationForm(forms.ModelForm): | |
8 |
|
8 | |||
9 | frequency = forms.FloatField(label='Frequency (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)]) |
|
9 | # frequency_bin = forms.IntegerField(label='Frequency (Binary)', required=False) | |
10 | phase = forms.FloatField(label='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)]) |
|
10 | # phase_bin = forms.IntegerField(label='Phase (Binary)', required=False) | |
11 |
|
11 | |||
12 |
frequency_mod = forms. |
|
12 | # frequency_mod_bin = forms.IntegerField(label='Frequency Mod (Binary)', required=False) | |
13 | phase_mod = forms.FloatField(label='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], required=False) |
|
13 | # phase_mod_bin = forms.IntegerField(label='Phase Mod (Binary)', required=False) | |
|
14 | ||||
|
15 | field_order = ['experiment', 'device', | |||
|
16 | 'clock', 'multiplier', | |||
|
17 | 'frequency', | |||
|
18 | 'frequency_bin', | |||
|
19 | 'phase', | |||
|
20 | 'phase_bin', | |||
|
21 | 'amplitude_chA', 'amplitude_chB', | |||
|
22 | 'modulation', | |||
|
23 | 'frequency_mod', | |||
|
24 | 'frequency_mod_bin', | |||
|
25 | 'phase_mod', | |||
|
26 | 'phase_mod_bin'] | |||
14 |
|
27 | |||
15 | def __init__(self, *args, **kwargs): |
|
28 | def __init__(self, *args, **kwargs): | |
16 | #request = kwargs.pop('request') |
|
29 | #request = kwargs.pop('request') | |
@@ -21,10 +34,11 class DDSConfigurationForm(forms.ModelForm): | |||||
21 | if instance and instance.pk: |
|
34 | if instance and instance.pk: | |
22 |
|
35 | |||
23 | devices = Device.objects.filter(device_type__name='dds') |
|
36 | devices = Device.objects.filter(device_type__name='dds') | |
24 | items = devices.values('id', 'name', 'device_type__name', 'ip_address') |
|
|||
25 |
|
37 | |||
26 | self.fields['experiment'].widget.attrs['readonly'] = True |
|
38 | self.fields['experiment'].widget.attrs['readonly'] = True | |
27 | self.fields['device'].widget.choices = [(item['id'], '[%s]: %s | %s' % (item['device_type__name'], item['name'], item['ip_address'])) for item in items] |
|
39 | self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] | |
|
40 | ||||
|
41 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |||
28 |
|
42 | |||
29 |
|
43 | |||
30 | def clean(self): |
|
44 | def clean(self): | |
@@ -33,4 +47,4 class DDSConfigurationForm(forms.ModelForm): | |||||
33 |
|
47 | |||
34 | class Meta: |
|
48 | class Meta: | |
35 | model = DDSConfiguration |
|
49 | model = DDSConfiguration | |
36 | fields = ('experiment', 'device', 'clock', 'multiplier', 'modulation') |
|
50 | exclude = ('type','parameters') |
@@ -3,28 +3,74 from apps.main.models import Configuration | |||||
3 | # Create your models here. |
|
3 | # Create your models here. | |
4 |
|
4 | |||
5 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
5 | from django.core.validators import MinValueValidator, MaxValueValidator | |
|
6 | from django.core.exceptions import ValidationError | |||
6 |
|
7 | |||
7 | MOD_TYPES = ( |
|
8 | MOD_TYPES = ( | |
8 | (None, 'Select a modulation type'), |
|
9 | (None, 'Select a modulation type'), | |
9 |
(0, ' |
|
10 | (0, 'Single Tone'), | |
10 |
(1, ' |
|
11 | (1, 'FSK'), | |
11 | (2, 'FSK'), |
|
12 | (2, 'Ramped FSK'), | |
12 |
(3, ' |
|
13 | (3, 'Chirp'), | |
|
14 | (4, 'BPSK'), | |||
13 | ) |
|
15 | ) | |
14 |
|
16 | |||
15 | class DDSConfiguration(Configuration): |
|
17 | class DDSConfiguration(Configuration): | |
16 |
|
18 | |||
17 | clock = models.FloatField(verbose_name='Clock Master (MHz)',validators=[MinValueValidator(5), MaxValueValidator(50)], blank=True, null=True) |
|
19 | DDS_NBITS = 48 | |
|
20 | ||||
|
21 | clock = models.FloatField(verbose_name='Clock Master (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)]) | |||
18 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) |
|
22 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) | |
19 | freq_reg = models.PositiveIntegerField(verbose_name='Frequency (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**32-1)], blank=True, null=True) |
|
23 | ||
20 |
|
|
24 | frequency = models.DecimalField(verbose_name='Frequency (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=17, decimal_places=15) | |
|
25 | frequency_bin = models.BigIntegerField(verbose_name='Frequency (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)]) | |||
21 |
|
26 | |||
22 |
|
|
27 | phase = models.FloatField(verbose_name='Phase (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)]) | |
23 |
|
|
28 | # phase_binary = models.PositiveIntegerField(verbose_name='Phase (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**14-1)]) | |
|
29 | ||||
|
30 | amplitude_ch_A = models.PositiveIntegerField(verbose_name='Amplitude CHA',validators=[MinValueValidator(0), MaxValueValidator(2**10-1)], blank=True, null=True) | |||
|
31 | amplitude_ch_B = models.PositiveIntegerField(verbose_name='Amplitude CHB',validators=[MinValueValidator(0), MaxValueValidator(2**10-1)], blank=True, null=True) | |||
24 |
|
32 | |||
25 | modulation = models.PositiveIntegerField(choices = MOD_TYPES, default = 0) |
|
33 | modulation = models.PositiveIntegerField(choices = MOD_TYPES, default = 0) | |
26 | freq_reg_mod = models.PositiveIntegerField(verbose_name='Frequency Mod (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**32-1)], blank=True, null=True) |
|
34 | ||
27 |
|
|
35 | frequency_mod = models.DecimalField(verbose_name='Frequency Mod. (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=17, decimal_places=15, blank=True, null=True) | |
|
36 | frequency_mod_bin = models.BigIntegerField(verbose_name='Frequency Mod. (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) | |||
|
37 | ||||
|
38 | phase_mod = models.FloatField(verbose_name='Phase Mod. (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True) | |||
|
39 | # phase_binary_mod = models.PositiveIntegerField(verbose_name='Phase Mod (Binary)',validators=[MinValueValidator(0), MaxValueValidator(2**14-1)], blank=True, null=True) | |||
|
40 | ||||
|
41 | def get_nbits(self): | |||
|
42 | ||||
|
43 | return self.DDS_NBITS | |||
|
44 | ||||
|
45 | def clean(self): | |||
|
46 | ||||
|
47 | if self.modulation in [1,2,3]: | |||
|
48 | if self.frequency_mod is None or self.frequency_mod_bin is None: | |||
|
49 | raise ValidationError({ | |||
|
50 | 'frequency_mod': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected' | |||
|
51 | }) | |||
|
52 | ||||
|
53 | if self.modulation in [4,]: | |||
|
54 | if self.phase_mod is None: | |||
|
55 | raise ValidationError({ | |||
|
56 | 'phase_mod': 'Phase modulation has to be defined when BPSK modulation is selected' | |||
|
57 | }) | |||
|
58 | ||||
|
59 | def verify_frequencies(self): | |||
|
60 | ||||
|
61 | return True | |||
|
62 | ||||
|
63 | def freq2binary(self, freq, mclock): | |||
|
64 | ||||
|
65 | binary = (float(freq)/mclock)*(2**self.DDS_NBITS) | |||
|
66 | ||||
|
67 | return binary | |||
|
68 | ||||
|
69 | def binary2freq(self, binary, mclock): | |||
|
70 | ||||
|
71 | freq = (float(binary)/(2**self.DDS_NBITS))*mclock | |||
|
72 | ||||
|
73 | return freq | |||
28 |
|
74 | |||
29 | class Meta: |
|
75 | class Meta: | |
30 | db_table = 'dds_configurations' |
|
76 | db_table = 'dds_configurations' |
@@ -1,4 +1,53 | |||||
1 |
{% extends " |
|
1 | {% extends "base.html" %} | |
|
2 | {% load bootstrap3 %} | |||
|
3 | {% load static %} | |||
|
4 | {% load main_tags %} | |||
|
5 | ||||
|
6 | {% block conf-active %}active{% endblock %} | |||
|
7 | ||||
|
8 | {% block content-title %}{{title}}{% endblock %} | |||
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |||
|
10 | ||||
|
11 | {% block content %} | |||
|
12 | ||||
|
13 | <table class="table table-bordered"> | |||
|
14 | <tr><th>Status</th><td>{%if connected == True %} ☘ Connected {% else %} ⛔ Disconnected {% endif %}</td></tr> | |||
|
15 | {% for item in dev_conf_keys %} | |||
|
16 | <tr><th>{{item|title}}</th><td>{{dev_conf|attr:item}}</td></tr> | |||
|
17 | {% endfor %} | |||
|
18 | ||||
|
19 | <tr><th>{{form.modulation.label}}</th><td>{{form.modulation}}</td></tr> | |||
|
20 | ||||
|
21 | {% if form.modulation.value == 0 %} | |||
|
22 | {% endif %} | |||
|
23 | ||||
|
24 | {% if form.modulation.value == 1 %} | |||
|
25 | <tr><th>{{form.frequency_mod.label}}</th><td>{{form.frequency_mod.value}}</td></tr> | |||
|
26 | {% endif %} | |||
|
27 | ||||
|
28 | {% if form.modulation.value == 2 %} | |||
|
29 | <tr><th>{{form.frequency_mod.label}}</th><td>{{form.frequency_mod.value}}</td></tr> | |||
|
30 | {% endif %} | |||
|
31 | ||||
|
32 | {% if form.modulation.value == 3 %} | |||
|
33 | <tr><th>{{form.frequency_mod.label}}</th><td>{{form.frequency_mod.value}}</td></tr> | |||
|
34 | {% endif %} | |||
|
35 | ||||
|
36 | {% if form.modulation.value == 4 %} | |||
|
37 | <tr><th>{{form.phase_mod.label}}</th><td>{{form.phase_mod.value}}</td></tr> | |||
|
38 | {% endif %} | |||
|
39 | </table> | |||
|
40 | ||||
|
41 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_read">Read</button> | |||
|
42 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_write">Write</button> | |||
|
43 | <button class="btn btn-primary pull-left" style="margin-left: 10px" id="bt_export">Export</button> | |||
|
44 | <button class="btn btn-primary pull-left" style="margin-left: 10px" id="bt_edit">Edit</button> | |||
|
45 | <br></br> | |||
|
46 | {% endblock %} | |||
|
47 | ||||
|
48 | {% block sidebar%} | |||
|
49 | {% include "sidebar_devices.html" %} | |||
|
50 | {% endblock %} | |||
2 |
|
51 | |||
3 | {% block extra-js%} |
|
52 | {% block extra-js%} | |
4 | <script type="text/javascript"> |
|
53 | <script type="text/javascript"> | |
@@ -7,5 +56,13 | |||||
7 | document.location = "{% url 'url_edit_dds_conf' dev_conf.id%}"; |
|
56 | document.location = "{% url 'url_edit_dds_conf' dev_conf.id%}"; | |
8 | }); |
|
57 | }); | |
9 |
|
58 | |||
|
59 | $("#bt_write").click(function() { | |||
|
60 | document.location = "{% url 'url_dds_conf_write' dev_conf.id%}"; | |||
|
61 | }); | |||
|
62 | ||||
|
63 | $("#bt_read").click(function() { | |||
|
64 | document.location = "{% url 'url_dds_conf_read' dev_conf.id%}"; | |||
|
65 | }); | |||
|
66 | ||||
10 | </script> |
|
67 | </script> | |
11 | {% endblock %} No newline at end of file |
|
68 | {% endblock %} |
@@ -1,1 +1,90 | |||||
1 | {% extends "dev_conf_edit.html" %} No newline at end of file |
|
1 | {% extends "dev_conf_edit.html" %} | |
|
2 | {% load bootstrap3 %} | |||
|
3 | {% load static %} | |||
|
4 | {% load main_tags %} | |||
|
5 | ||||
|
6 | {% block extra-js%} | |||
|
7 | <script type="text/javascript"> | |||
|
8 | ||||
|
9 | $("#bt_cancel").click(function() { | |||
|
10 | document.location = "{% url 'url_dds_conf' id_dev%}"; | |||
|
11 | }); | |||
|
12 | ||||
|
13 | $("#bt_read").click(function() { | |||
|
14 | document.location = "{% url 'url_dds_conf_read' id_dev%}"; | |||
|
15 | }); | |||
|
16 | ||||
|
17 | $("#id_clock").on('change', function() { | |||
|
18 | updateFrequencies(); | |||
|
19 | }); | |||
|
20 | ||||
|
21 | $("#id_multiplier").on('change', function() { | |||
|
22 | updateFrequencies(); | |||
|
23 | }); | |||
|
24 | ||||
|
25 | $("#id_frequency").on('change', function() { | |||
|
26 | updateBinaryFrequencies(); | |||
|
27 | }); | |||
|
28 | ||||
|
29 | $("#id_frequency_bin").on('change', function() { | |||
|
30 | updateFrequencies(); | |||
|
31 | }); | |||
|
32 | ||||
|
33 | $("#id_frequency_mod").on('change', function() { | |||
|
34 | updateBinaryFrequencies(); | |||
|
35 | }); | |||
|
36 | ||||
|
37 | $("#id_frequency_mod_bin").on('change', function() { | |||
|
38 | updateFrequencies(); | |||
|
39 | }); | |||
|
40 | ||||
|
41 | function updateBinaryFrequencies() { | |||
|
42 | ||||
|
43 | var clock = $("#id_clock").val(); | |||
|
44 | var multiplier = $("#id_multiplier").val(); | |||
|
45 | var freq = $("#id_frequency").val(); | |||
|
46 | var freq_mod = $("#id_frequency_mod").val(); | |||
|
47 | ||||
|
48 | var mclock = clock*multiplier; | |||
|
49 | var k = Math.pow(2,48)/mclock; | |||
|
50 | ||||
|
51 | var freq_bin = parseInt(freq*k); | |||
|
52 | var freq_mod_bin = parseInt(freq_mod*k); | |||
|
53 | ||||
|
54 | $("#id_frequency_bin").val(freq_bin); | |||
|
55 | $("#id_frequency_mod_bin").val(freq_mod_bin); | |||
|
56 | ||||
|
57 | freq = freq_bin/k; | |||
|
58 | freq_mod = freq_mod_bin/k; | |||
|
59 | ||||
|
60 | $("#id_frequency").val(freq); | |||
|
61 | $("#id_frequency_mod").val(freq_mod); | |||
|
62 | ||||
|
63 | } | |||
|
64 | ||||
|
65 | function updateFrequencies() { | |||
|
66 | ||||
|
67 | var clock = $("#id_clock").val(); | |||
|
68 | var multiplier = $("#id_multiplier").val(); | |||
|
69 | var freq_bin = $("#id_frequency_bin").val(); | |||
|
70 | var freq_mod_bin = $("#id_frequency_mod_bin").val(); | |||
|
71 | ||||
|
72 | var mclock = clock*multiplier; | |||
|
73 | var k = Math.pow(2,48)/mclock; | |||
|
74 | ||||
|
75 | var freq = parseInt(freq_bin)/k; | |||
|
76 | var freq_mod = parseInt(freq_mod_bin)/k; | |||
|
77 | ||||
|
78 | $("#id_frequency").val(freq); | |||
|
79 | $("#id_frequency_mod").val(freq_mod); | |||
|
80 | ||||
|
81 | var freq_bin = parseInt(freq*k); | |||
|
82 | var freq_mod_bin = parseInt(freq_mod*k); | |||
|
83 | ||||
|
84 | $("#id_frequency_bin").val(freq_bin); | |||
|
85 | $("#id_frequency_mod_bin").val(freq_mod_bin); | |||
|
86 | ||||
|
87 | } | |||
|
88 | ||||
|
89 | </script> | |||
|
90 | {% endblock %} No newline at end of file |
@@ -2,5 +2,8 from django.conf.urls import url | |||||
2 |
|
2 | |||
3 | urlpatterns = ( |
|
3 | urlpatterns = ( | |
4 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.dds.views.dds_conf', name='url_dds_conf'), |
|
4 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.dds.views.dds_conf', name='url_dds_conf'), | |
|
5 | url(r'^(?P<id_conf>-?\d+)/(?P<message>-?\d+)/$', 'apps.dds.views.dds_conf', name='url_dds_conf'), | |||
5 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.dds.views.dds_conf_edit', name='url_edit_dds_conf'), |
|
6 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.dds.views.dds_conf_edit', name='url_edit_dds_conf'), | |
|
7 | url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.dds.views.dds_conf_write', name='url_dds_conf_write'), | |||
|
8 | url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.dds.views.dds_conf_read', name='url_dds_conf_read'), | |||
6 | ) |
|
9 | ) |
@@ -1,24 +1,42 | |||||
1 | # Create your views here. |
|
1 | # Create your views here. | |
2 |
|
2 | from django.contrib import messages | ||
3 | from django.shortcuts import redirect, render, get_object_or_404 |
|
3 | from django.shortcuts import redirect, render, get_object_or_404 | |
4 |
|
4 | |||
5 | from apps.main.models import Experiment, Configuration |
|
5 | from apps.main.models import Experiment, Configuration | |
|
6 | from apps.main.views import sidebar | |||
|
7 | ||||
6 | from .models import DDSConfiguration |
|
8 | from .models import DDSConfiguration | |
7 | from .forms import DDSConfigurationForm |
|
9 | from .forms import DDSConfigurationForm | |
8 | # Create your views here. |
|
10 | # Create your views here. | |
9 |
|
11 | |||
|
12 | from radarsys_api import jro_device, dds | |||
|
13 | ||||
10 | def dds_conf(request, id_conf): |
|
14 | def dds_conf(request, id_conf): | |
11 |
|
15 | |||
12 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
16 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
13 |
|
17 | |||
|
18 | if request.method=='GET': | |||
|
19 | form = DDSConfigurationForm(instance=conf) | |||
|
20 | ||||
|
21 | answer = dds.echo(ip=str(conf.device.ip_address), port=conf.device.port_address) | |||
|
22 | ||||
14 | kwargs = {} |
|
23 | kwargs = {} | |
|
24 | kwargs['connected'] = (answer[0] == "1") | |||
|
25 | kwargs['form'] = form | |||
|
26 | ||||
15 | kwargs['dev_conf'] = conf |
|
27 | kwargs['dev_conf'] = conf | |
16 | kwargs['dev_conf_keys'] = ['experiment', 'device', |
|
28 | kwargs['dev_conf_keys'] = ['experiment', 'device', | |
17 | 'clock', 'multiplier', |
|
29 | 'clock', 'multiplier', | |
18 |
'freq |
|
30 | 'frequency', | |
19 |
' |
|
31 | # 'frequency_bin', | |
20 |
' |
|
32 | 'phase', | |
21 |
' |
|
33 | # 'phase_binary', | |
|
34 | 'amplitude_ch_A', 'amplitude_ch_B'] | |||
|
35 | # 'modulation', | |||
|
36 | # 'frequency_mod', | |||
|
37 | # 'frequency_mod_bin', | |||
|
38 | # 'phase_mod'] | |||
|
39 | # 'phase_binary_mod'] | |||
22 |
|
40 | |||
23 | kwargs['title'] = 'DDS Configuration' |
|
41 | kwargs['title'] = 'DDS Configuration' | |
24 | kwargs['suptitle'] = 'Details' |
|
42 | kwargs['suptitle'] = 'Details' | |
@@ -26,17 +44,7 def dds_conf(request, id_conf): | |||||
26 | kwargs['button'] = 'Edit Configuration' |
|
44 | kwargs['button'] = 'Edit Configuration' | |
27 |
|
45 | |||
28 | ###### SIDEBAR ###### |
|
46 | ###### SIDEBAR ###### | |
29 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
47 | kwargs.update(sidebar(conf)) | |
30 | configurations = Configuration.objects.filter(experiment=conf.experiment) |
|
|||
31 |
|
||||
32 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
|||
33 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
|||
34 |
|
||||
35 | kwargs['experiment_keys'] = exp_keys[1:] |
|
|||
36 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
|||
37 |
|
||||
38 | kwargs['configuration_keys'] = conf_keys[1:] |
|
|||
39 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
|||
40 |
|
48 | |||
41 | return render(request, 'dds_conf.html', kwargs) |
|
49 | return render(request, 'dds_conf.html', kwargs) | |
42 |
|
50 | |||
@@ -51,13 +59,103 def dds_conf_edit(request, id_conf): | |||||
51 | form = DDSConfigurationForm(request.POST, instance=conf) |
|
59 | form = DDSConfigurationForm(request.POST, instance=conf) | |
52 |
|
60 | |||
53 | if form.is_valid(): |
|
61 | if form.is_valid(): | |
54 | form.save() |
|
62 | conf = form.save(commit=False) | |
55 | return redirect('url_dds_conf', id_conf=id_conf) |
|
63 | ||
|
64 | if conf.verify_frequencies(): | |||
|
65 | ||||
|
66 | conf.save() | |||
|
67 | return redirect('url_dds_conf', id_conf=conf.id) | |||
|
68 | ||||
|
69 | ##ERRORS | |||
56 |
|
70 | |||
57 | kwargs = {} |
|
71 | kwargs = {} | |
|
72 | kwargs['id_dev'] = conf.id | |||
58 | kwargs['form'] = form |
|
73 | kwargs['form'] = form | |
59 | kwargs['title'] = 'Device Configuration' |
|
74 | kwargs['title'] = 'Device Configuration' | |
60 | kwargs['suptitle'] = 'Edit' |
|
75 | kwargs['suptitle'] = 'Edit' | |
61 |
kwargs['button'] = ' |
|
76 | kwargs['button'] = 'Save' | |
|
77 | kwargs['dds_nbits'] = conf.get_nbits() | |||
|
78 | ||||
|
79 | ###### SIDEBAR ###### | |||
|
80 | kwargs.update(sidebar(conf)) | |||
|
81 | ||||
|
82 | return render(request, 'dds_conf_edit.html', kwargs) | |||
|
83 | ||||
|
84 | def dds_conf_write(request, id_conf): | |||
|
85 | ||||
|
86 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |||
|
87 | ||||
|
88 | answer = dds.write_config(ip=str(conf.device.ip_address), | |||
|
89 | port=conf.device.port_address, | |||
|
90 | clock=conf.clock, | |||
|
91 | multiplier=conf.multiplier, | |||
|
92 | freq_regA=conf.frequency_bin, | |||
|
93 | freq_regB=conf.frequency_mod_bin, | |||
|
94 | modulation=conf.modulation, | |||
|
95 | phaseA=conf.phase, | |||
|
96 | phaseB=conf.phase_mod, | |||
|
97 | amplitude0=conf.amplitude_ch_A, | |||
|
98 | amplitude1=conf.amplitude_ch_B) | |||
|
99 | ||||
|
100 | if answer[0] == "1": | |||
|
101 | messages.success(request, answer[2:]) | |||
|
102 | else: | |||
|
103 | messages.error(request, answer) | |||
|
104 | ||||
|
105 | return redirect('url_dds_conf', id_conf=conf.id) | |||
|
106 | ||||
|
107 | def dds_conf_read(request, id_conf): | |||
|
108 | ||||
|
109 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |||
|
110 | ||||
|
111 | if request.method=='POST': | |||
|
112 | form = DDSConfigurationForm(request.POST, instance=conf) | |||
|
113 | ||||
|
114 | if form.is_valid(): | |||
|
115 | dds_model = form.save(commit=False) | |||
|
116 | ||||
|
117 | if dds_model.verify_frequencies(): | |||
|
118 | ||||
|
119 | dds_model.save() | |||
|
120 | return redirect('url_dds_conf', id_conf=conf.id) | |||
|
121 | ||||
|
122 | parms = None | |||
|
123 | ||||
|
124 | if request.method=='GET': | |||
|
125 | ||||
|
126 | #mult, freqA, freqB, modulation, phaseA, phaseB, amp0, amp1 | |||
|
127 | parms = dds.read_config(ip=conf.device.ip_address, | |||
|
128 | port=conf.device.port_address) | |||
|
129 | ||||
|
130 | if parms is None: | |||
|
131 | return redirect('url_dds_conf', id_conf=conf.id) | |||
|
132 | ||||
|
133 | data = {'experiment' : conf.experiment.id, | |||
|
134 | 'device' : conf.device.id, | |||
|
135 | 'clock' : conf.clock, | |||
|
136 | 'multiplier' : parms[0], | |||
|
137 | 'frequency' : conf.binary2freq(parms[1], parms[0]*conf.clock), | |||
|
138 | 'frequency_bin' : parms[1], | |||
|
139 | 'phase' : parms[4], | |||
|
140 | 'amplitude_ch_A' : parms[6], | |||
|
141 | 'amplitude_ch_B' : parms[7], | |||
|
142 | 'modulation' : parms[3], | |||
|
143 | 'frequency_mod' : conf.binary2freq(parms[2], parms[0]*conf.clock), | |||
|
144 | 'frequency_mod_bin' : parms[2], | |||
|
145 | 'phase_mod' : parms[5], | |||
|
146 | } | |||
|
147 | ||||
|
148 | form = DDSConfigurationForm(data) | |||
|
149 | ||||
|
150 | kwargs = {} | |||
|
151 | kwargs['id_dev'] = conf.id | |||
|
152 | kwargs['form'] = form | |||
|
153 | kwargs['title'] = 'Device Configuration' | |||
|
154 | kwargs['suptitle'] = 'Parameters read from device' | |||
|
155 | kwargs['button'] = 'Save' | |||
|
156 | kwargs['dds_nbits'] = conf.get_nbits() | |||
|
157 | ||||
|
158 | ###### SIDEBAR ###### | |||
|
159 | kwargs.update(sidebar(conf)) | |||
62 |
|
160 | |||
63 | return render(request, 'dds_conf_edit.html', kwargs) No newline at end of file |
|
161 | return render(request, 'dds_conf_edit.html', kwargs) |
@@ -6,10 +6,15 class JARSConfigurationForm(forms.ModelForm): | |||||
6 | def __init__(self, *args, **kwargs): |
|
6 | def __init__(self, *args, **kwargs): | |
7 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) |
|
7 | super(JARSConfigurationForm, self).__init__(*args, **kwargs) | |
8 | instance = getattr(self, 'instance', None) |
|
8 | instance = getattr(self, 'instance', None) | |
|
9 | ||||
9 | if instance and instance.pk: |
|
10 | if instance and instance.pk: | |
10 | self.fields['experiment'].widget.attrs['disabled'] = True |
|
11 | devices = Device.objects.filter(device_type__name='jars') | |
11 | self.fields['device'].widget.choices = [(item['id'], '%s | %s' % (item['device_type__name'], item['ip_address'])) for item in Device.objects.filter(device_type__name='jars').values('id', 'device_type__name', 'ip_address')] |
|
12 | ||
12 |
|
13 | self.fields['experiment'].widget.attrs['readonly'] = True | ||
|
14 | self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] | |||
|
15 | ||||
|
16 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |||
|
17 | ||||
13 | class Meta: |
|
18 | class Meta: | |
14 | model = JARSConfiguration |
|
19 | model = JARSConfiguration | |
15 | exclude = ('parameters', 'status') |
|
20 | exclude = ('parameters', 'status') |
@@ -9,16 +9,18 | |||||
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
10 |
|
10 | |||
11 | {% block content %} |
|
11 | {% block content %} | |
|
12 | ||||
12 | <table class="table table-bordered"> |
|
13 | <table class="table table-bordered"> | |
|
14 | <tr><th>Status</th><td>{%if connected == True %} ☘ Connected {% else %} ⛔ Disconnected {% endif %}</td></tr> | |||
13 | {% for key in dev_conf_keys %} |
|
15 | {% for key in dev_conf_keys %} | |
14 | <tr><th>{{key|title}}</th><td>{{dev_conf|attr:key}}</td></tr> |
|
16 | <tr><th>{{key|title}}</th><td>{{dev_conf|attr:key}}</td></tr> | |
15 | {% endfor %} |
|
17 | {% endfor %} | |
16 | </table> |
|
18 | </table> | |
|
19 | ||||
17 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_send">Send</button> |
|
20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_send">Send</button> | |
18 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> | |
19 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
22 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
20 | <br></br> |
|
23 | <br></br> | |
21 | <br></br> |
|
|||
22 | {% endblock %} |
|
24 | {% endblock %} | |
23 |
|
25 | |||
24 | {% block sidebar%} |
|
26 | {% block sidebar%} |
@@ -465,6 +465,9 def sidebar(conf): | |||||
465 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
465 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
466 |
|
466 | |||
467 | kwargs = {} |
|
467 | kwargs = {} | |
|
468 | ||||
|
469 | kwargs['dev_conf'] = conf | |||
|
470 | ||||
468 | kwargs['experiment_keys'] = exp_keys[1:] |
|
471 | kwargs['experiment_keys'] = exp_keys[1:] | |
469 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
472 | kwargs['experiments'] = experiments.values(*exp_keys) | |
470 |
|
473 |
General Comments 0
You need to be logged in to leave comments.
Login now