@@ -0,0 +1,1 | |||||
|
1 | {% extends "dev_conf_edit.html" %} |
@@ -0,0 +1,145 | |||||
|
1 | {% extends "base.html" %} | |||
|
2 | {% load bootstrap3 %} | |||
|
3 | {% load static %} | |||
|
4 | {% load main_tags %} | |||
|
5 | {% block extra-head %} | |||
|
6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> | |||
|
7 | {% endblock %} | |||
|
8 | ||||
|
9 | {% block exp-active %}active{% endblock %} | |||
|
10 | ||||
|
11 | {% block content-title %}{{title}}{% endblock %} | |||
|
12 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |||
|
13 | ||||
|
14 | {% block content %} | |||
|
15 | ||||
|
16 | {% block menu-actions %} | |||
|
17 | ||||
|
18 | {% endblock %} | |||
|
19 | ||||
|
20 | ||||
|
21 | ||||
|
22 | <table class="table table-bordered" style="text-align:center;"> | |||
|
23 | <!--<h4 class="panel-title"> </h4>--> | |||
|
24 | <tr> | |||
|
25 | <th style="text-align:center;">Parameters</th> | |||
|
26 | <th style="text-align:center;">DDS</th> | |||
|
27 | <th style="text-align:center;">RC</th> | |||
|
28 | <th style="text-align:center;">JARS</th> | |||
|
29 | <th style="text-align:center;">=P</th> | |||
|
30 | </tr> | |||
|
31 | ||||
|
32 | <tr> | |||
|
33 | <th>Clock In</th> | |||
|
34 | <td id="dds_clock">{{ dds.clock }}</td> | |||
|
35 | <td id="rc_clock">{{ rc.clock_in }}</td> | |||
|
36 | <td id="filter_clock">{{ filter_parms.clock }}</td> | |||
|
37 | <td><input id="suggest_clock"></input></td> | |||
|
38 | </tr> | |||
|
39 | ||||
|
40 | <tr> | |||
|
41 | <th>Frequency A (Mhz)</th> | |||
|
42 | <td>{{ dds.frequencyA_Mhz }}</td> | |||
|
43 | <td>x</td> | |||
|
44 | <td>{{ filter_parms.fch }}</td> | |||
|
45 | <td><input></input></td> | |||
|
46 | </tr> | |||
|
47 | ||||
|
48 | <tr> | |||
|
49 | <th>Frequency A (Decimal)</th> | |||
|
50 | <td>{{ dds.frequencyA }}</td> | |||
|
51 | <td>x</td> | |||
|
52 | <td>{{ filter_parms.fch_decimal }}</td> | |||
|
53 | <td><input></input></td> | |||
|
54 | </tr> | |||
|
55 | ||||
|
56 | <tr> | |||
|
57 | <th>Sampling Frequency (MHz)</th> | |||
|
58 | <td id="dds_sampfreq">{{ dds.frequencyA }}</td> | |||
|
59 | <td id="rc_sampfreq">{{ samp_freq_rc }}</td> | |||
|
60 | <td id="jars_sampfreq">{{ samp_freq_jars }}</td> | |||
|
61 | <td><input id="suggest_sampfreq"></input></td> | |||
|
62 | </tr> | |||
|
63 | </table> | |||
|
64 | ||||
|
65 | ||||
|
66 | ||||
|
67 | <div class=""> | |||
|
68 | <h4 class="panel-title"><b> Extra Parameters </b></h4> | |||
|
69 | <br> | |||
|
70 | </div> | |||
|
71 | ||||
|
72 | <table class="table table-bordered" > | |||
|
73 | {% for configuration in configurations %} | |||
|
74 | {% if configuration.device.device_type.name == 'jars' %} | |||
|
75 | <tr><th>Rate(MB/h)</th><td>{{ rate }}</td></tr> | |||
|
76 | {% endif %} | |||
|
77 | {% endfor %} | |||
|
78 | </table> | |||
|
79 | ||||
|
80 | ||||
|
81 | <div class="pull-right"> | |||
|
82 | <button type="button" class="btn btn-primary" id="bt_back">Back</button> | |||
|
83 | <button type="button" class="btn btn-primary" id="bt_update">{{ button }}</button> | |||
|
84 | </div> | |||
|
85 | ||||
|
86 | {% endblock %} | |||
|
87 | ||||
|
88 | {% block sidebar%} | |||
|
89 | {% include "sidebar_devices.html" %} | |||
|
90 | {% endblock %} | |||
|
91 | ||||
|
92 | {% block extra-js%} | |||
|
93 | <script type="text/javascript"> | |||
|
94 | ||||
|
95 | {% if dds_conf %} | |||
|
96 | $(document).ready(function() { | |||
|
97 | $('#dds_clock').click(function(event) { | |||
|
98 | clock = $("#dds_clock").text(); | |||
|
99 | $("#suggest_clock").val(clock); | |||
|
100 | }); | |||
|
101 | $('#dds_sampfreq').click(function(event) { | |||
|
102 | sampfreq = $("#dds_sampfreq").text(); | |||
|
103 | $("#suggest_sampfreq").val(sampfreq); | |||
|
104 | }); | |||
|
105 | }); | |||
|
106 | {% endif %} | |||
|
107 | {% if rc_conf %} | |||
|
108 | $(document).ready(function() { | |||
|
109 | $('#rc_clock').click(function(event) { | |||
|
110 | clock = $("#rc_clock").text(); | |||
|
111 | $("#suggest_clock").val(clock); | |||
|
112 | }); | |||
|
113 | $('#rc_sampfreq').click(function(event) { | |||
|
114 | sampfreq = $("#rc_sampfreq").text(); | |||
|
115 | $("#suggest_sampfreq").val(sampfreq); | |||
|
116 | }); | |||
|
117 | }); | |||
|
118 | {% endif %} | |||
|
119 | {% if jars_conf %} | |||
|
120 | $(document).ready(function() { | |||
|
121 | $('#filter_clock').click(function(event) { | |||
|
122 | clock = $("#filter_clock").text(); | |||
|
123 | $("#suggest_clock").val(clock); | |||
|
124 | }); | |||
|
125 | $('#jars_sampfreq').click(function(event) { | |||
|
126 | sampfreq = $("#jars_sampfreq").text(); | |||
|
127 | $("#suggest_sampfreq").val(sampfreq); | |||
|
128 | }); | |||
|
129 | }); | |||
|
130 | {% endif %} | |||
|
131 | ||||
|
132 | ||||
|
133 | ||||
|
134 | ||||
|
135 | $(".clickable-row").click(function() { | |||
|
136 | document.location = $(this).data("href"); | |||
|
137 | }); | |||
|
138 | ||||
|
139 | $("#bt_back").click(function() { | |||
|
140 | document.location = "{% url 'url_experiment' experiment.id%}"; | |||
|
141 | }); | |||
|
142 | ||||
|
143 | ||||
|
144 | </script> | |||
|
145 | {% endblock %} No newline at end of file |
@@ -1,3 +1,5 | |||||
|
1 | import os | |||
|
2 | ||||
1 | from django import forms |
|
3 | from django import forms | |
2 | from apps.main.models import Device, Experiment |
|
4 | from apps.main.models import Device, Experiment | |
3 | from .models import JARSConfiguration, JARSfilter |
|
5 | from .models import JARSConfiguration, JARSfilter | |
@@ -42,4 +44,40 class JARSfilterForm(forms.ModelForm): | |||||
42 |
|
44 | |||
43 | class Meta: |
|
45 | class Meta: | |
44 | model = JARSfilter |
|
46 | model = JARSfilter | |
45 | exclude = ('type', 'parameters', 'status') No newline at end of file |
|
47 | exclude = ('type', 'parameters', 'status') | |
|
48 | ||||
|
49 | class ExtFileField(forms.FileField): | |||
|
50 | """ | |||
|
51 | Same as forms.FileField, but you can specify a file extension whitelist. | |||
|
52 | ||||
|
53 | >>> from django.core.files.uploadedfile import SimpleUploadedFile | |||
|
54 | >>> | |||
|
55 | >>> t = ExtFileField(ext_whitelist=(".pdf", ".txt")) | |||
|
56 | >>> | |||
|
57 | >>> t.clean(SimpleUploadedFile('filename.pdf', 'Some File Content')) | |||
|
58 | >>> t.clean(SimpleUploadedFile('filename.txt', 'Some File Content')) | |||
|
59 | >>> | |||
|
60 | >>> t.clean(SimpleUploadedFile('filename.exe', 'Some File Content')) | |||
|
61 | Traceback (most recent call last): | |||
|
62 | ... | |||
|
63 | ValidationError: [u'Not allowed filetype!'] | |||
|
64 | """ | |||
|
65 | def __init__(self, *args, **kwargs): | |||
|
66 | extensions = kwargs.pop("extensions") | |||
|
67 | self.extensions = [i.lower() for i in extensions] | |||
|
68 | ||||
|
69 | super(ExtFileField, self).__init__(*args, **kwargs) | |||
|
70 | ||||
|
71 | def clean(self, *args, **kwargs): | |||
|
72 | data = super(ExtFileField, self).clean(*args, **kwargs) | |||
|
73 | filename = data.name | |||
|
74 | ext = os.path.splitext(filename)[1] | |||
|
75 | ext = ext.lower() | |||
|
76 | if ext not in self.extensions: | |||
|
77 | raise forms.ValidationError('Not allowed file type: %s' % ext) | |||
|
78 | ||||
|
79 | ||||
|
80 | class JARSImportForm(forms.Form): | |||
|
81 | ||||
|
82 | #file_name = ExtFileField(extensions=['.racp', '.json', '.dat']) | |||
|
83 | file_name = ExtFileField(extensions=['.json']) No newline at end of file |
@@ -1,8 +1,12 | |||||
1 | from django.db import models |
|
1 | from django.db import models | |
2 | from apps.main.models import Configuration |
|
2 | from apps.main.models import Configuration | |
3 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
3 | from django.core.validators import MinValueValidator, MaxValueValidator | |
|
4 | from django.core.urlresolvers import reverse | |||
|
5 | from devices.jars import api | |||
4 |
|
6 | |||
5 | from apps.rc.models import RCConfiguration |
|
7 | from apps.rc.models import RCConfiguration | |
|
8 | ||||
|
9 | import json | |||
6 | # Create your models here. |
|
10 | # Create your models here. | |
7 |
|
11 | |||
8 | EXPERIMENT_TYPE = ( |
|
12 | EXPERIMENT_TYPE = ( | |
@@ -77,12 +81,15 class JARSConfiguration(Configuration): | |||||
77 | cards_number = models.PositiveIntegerField(verbose_name='Number of Cards', validators=[MinValueValidator(1), MaxValueValidator(4)], default = 1) |
|
81 | cards_number = models.PositiveIntegerField(verbose_name='Number of Cards', validators=[MinValueValidator(1), MaxValueValidator(4)], default = 1) | |
78 | channels_number = models.PositiveIntegerField(verbose_name='Number of Channels', validators=[MinValueValidator(1), MaxValueValidator(8)], default = 5) |
|
82 | channels_number = models.PositiveIntegerField(verbose_name='Number of Channels', validators=[MinValueValidator(1), MaxValueValidator(8)], default = 5) | |
79 | channels = models.CharField(verbose_name='Channels', max_length=15, default = '1,2,3,4,5') |
|
83 | channels = models.CharField(verbose_name='Channels', max_length=15, default = '1,2,3,4,5') | |
80 |
rd_directory = models.CharField(verbose_name='Raw Data Directory', max_length= |
|
84 | rd_directory = models.CharField(verbose_name='Raw Data Directory', max_length=200, default='', blank=True, null=True) | |
81 | raw_data_blocks = models.PositiveIntegerField(verbose_name='Raw Data Blocks', validators=[MaxValueValidator(5000)], default=120) |
|
85 | pd_directory = models.CharField(verbose_name='Process Data Directory', max_length=200, default='', blank=True, null=True) | |
|
86 | #raw_data_blocks = models.PositiveIntegerField(verbose_name='Raw Data Blocks', validators=[MaxValueValidator(5000)], default=120) | |||
82 | data_type = models.PositiveIntegerField(verbose_name='Data Type', choices=DATA_TYPE, default=0) |
|
87 | data_type = models.PositiveIntegerField(verbose_name='Data Type', choices=DATA_TYPE, default=0) | |
83 | acq_profiles = models.PositiveIntegerField(verbose_name='Acquired Profiles', validators=[MaxValueValidator(5000)], default=400) |
|
88 | acq_profiles = models.PositiveIntegerField(verbose_name='Acquired Profiles', validators=[MaxValueValidator(5000)], default=400) | |
84 | profiles_block = models.PositiveIntegerField(verbose_name='Profiles Per Block', validators=[MaxValueValidator(5000)], default=400) |
|
89 | profiles_block = models.PositiveIntegerField(verbose_name='Profiles Per Block', validators=[MaxValueValidator(5000)], default=400) | |
|
90 | ftp_interval = models.PositiveIntegerField(verbose_name='FTP Interval', default=60) | |||
85 | fftpoints = models.PositiveIntegerField(verbose_name='FFT Points',default=16) |
|
91 | fftpoints = models.PositiveIntegerField(verbose_name='FFT Points',default=16) | |
|
92 | cohe_integr_str = models.PositiveIntegerField(verbose_name='Coh. Int. Stride',validators=[MinValueValidator(1)], default=30) | |||
86 | cohe_integr = models.PositiveIntegerField(verbose_name='Coherent Integrations',validators=[MinValueValidator(1)], default=30) |
|
93 | cohe_integr = models.PositiveIntegerField(verbose_name='Coherent Integrations',validators=[MinValueValidator(1)], default=30) | |
87 | incohe_integr = models.PositiveIntegerField(verbose_name='Incoherent Integrations',validators=[MinValueValidator(1)], default=30) |
|
94 | incohe_integr = models.PositiveIntegerField(verbose_name='Incoherent Integrations',validators=[MinValueValidator(1)], default=30) | |
88 | filter = models.ForeignKey(JARSfilter, on_delete=models.CASCADE, null=True) |
|
95 | filter = models.ForeignKey(JARSfilter, on_delete=models.CASCADE, null=True) | |
@@ -90,9 +97,10 class JARSConfiguration(Configuration): | |||||
90 | spectral = models.CharField(verbose_name='Combinations', max_length=5000, default = '[0, 0],') |
|
97 | spectral = models.CharField(verbose_name='Combinations', max_length=5000, default = '[0, 0],') | |
91 | create_directory = models.BooleanField(verbose_name='Create Directory Per Day', default=True) |
|
98 | create_directory = models.BooleanField(verbose_name='Create Directory Per Day', default=True) | |
92 | include_expname = models.BooleanField(verbose_name='Experiment Name in Directory', default=True) |
|
99 | include_expname = models.BooleanField(verbose_name='Experiment Name in Directory', default=True) | |
93 | acq_link = models.BooleanField(verbose_name='Acquisition Link', default=True) |
|
100 | #acq_link = models.BooleanField(verbose_name='Acquisition Link', default=True) | |
94 | view_raw_data = models.BooleanField(verbose_name='View Raw Data', default=True) |
|
101 | #view_raw_data = models.BooleanField(verbose_name='View Raw Data', default=True) | |
95 | save_ch_dc = models.BooleanField(verbose_name='Save Channels DC', default=True) |
|
102 | save_ch_dc = models.BooleanField(verbose_name='Save Channels DC', default=True) | |
|
103 | save_data = models.BooleanField(verbose_name='Save Data', default=True) | |||
96 | filter_parms = models.CharField(max_length=10000, default='{}') |
|
104 | filter_parms = models.CharField(max_length=10000, default='{}') | |
97 |
|
105 | |||
98 | class Meta: |
|
106 | class Meta: | |
@@ -102,6 +110,7 class JARSConfiguration(Configuration): | |||||
102 |
|
110 | |||
103 | parameters = {} |
|
111 | parameters = {} | |
104 |
|
112 | |||
|
113 | parameters['device_id'] = self.device.id | |||
105 | parameters['name'] = self.name |
|
114 | parameters['name'] = self.name | |
106 | #parameters['rc'] = self.rc.name |
|
115 | #parameters['rc'] = self.rc.name | |
107 | parameters['exp_type'] = self.exp_type |
|
116 | parameters['exp_type'] = self.exp_type | |
@@ -110,26 +119,31 class JARSConfiguration(Configuration): | |||||
110 | parameters['channels_number'] = self.channels_number |
|
119 | parameters['channels_number'] = self.channels_number | |
111 | parameters['channels'] = self.channels |
|
120 | parameters['channels'] = self.channels | |
112 | parameters['rd_directory'] = self.rd_directory |
|
121 | parameters['rd_directory'] = self.rd_directory | |
113 | parameters['raw_data_blocks'] = self.raw_data_blocks |
|
122 | #parameters['raw_data_blocks'] = self.raw_data_blocks | |
114 | parameters['data_type'] = self.data_type |
|
123 | parameters['data_type'] = self.data_type | |
|
124 | parameters['cohe_integr_str'] = self.cohe_integr_str | |||
115 | parameters['acq_profiles'] = self.acq_profiles |
|
125 | parameters['acq_profiles'] = self.acq_profiles | |
116 | parameters['profiles_block'] = self.profiles_block |
|
126 | parameters['profiles_block'] = self.profiles_block | |
|
127 | parameters['ftp_interval'] = self.ftp_interval | |||
117 | parameters['fftpoints'] = self.fftpoints |
|
128 | parameters['fftpoints'] = self.fftpoints | |
118 | parameters['cohe_integr'] = self.cohe_integr |
|
129 | parameters['cohe_integr'] = self.cohe_integr | |
119 | #parameters['incohe_integr'] = self.incohe_integr |
|
130 | #parameters['incohe_integr'] = self.incohe_integr | |
120 | parameters['filter'] = self.filter.name |
|
131 | parameters['filter'] = self.filter.name | |
|
132 | parameters['filter_parms'] = self.filter_parms | |||
121 | #parameters['spectral_number'] = self.spectral_number |
|
133 | #parameters['spectral_number'] = self.spectral_number | |
122 | #parameters['spectral'] = self.spectral |
|
134 | #parameters['spectral'] = self.spectral | |
123 | parameters['create_directory'] = bool(self.create_directory) |
|
135 | parameters['create_directory'] = bool(self.create_directory) | |
124 | parameters['include_expname'] = bool(self.include_expname) |
|
136 | parameters['include_expname'] = bool(self.include_expname) | |
125 | parameters['acq_link'] = bool(self.acq_link) |
|
137 | #parameters['acq_link'] = bool(self.acq_link) | |
126 | parameters['view_raw_data'] = bool(self.view_raw_data) |
|
138 | #parameters['view_raw_data'] = bool(self.view_raw_data) | |
127 | parameters['save_ch_dc'] = bool(self.save_ch_dc) |
|
139 | parameters['save_ch_dc'] = bool(self.save_ch_dc) | |
|
140 | parameters['save_data'] = bool(self.save_data) | |||
128 |
|
141 | |||
129 | if parameters['exptype'] == 'PDATA': |
|
142 | if parameters['exptype'] == 'PDATA': | |
130 | parameters['incohe_integr'] = self.incohe_integr |
|
143 | parameters['incohe_integr'] = self.incohe_integr | |
131 | parameters['spectral_number'] = self.spectral_number |
|
144 | parameters['spectral_number'] = self.spectral_number | |
132 | parameters['spectral'] = self.spectral |
|
145 | parameters['spectral'] = self.spectral | |
|
146 | parameters['pd_directory'] = self.pd_directory | |||
133 |
|
147 | |||
134 | return parameters |
|
148 | return parameters | |
135 |
|
149 | |||
@@ -139,39 +153,116 class JARSConfiguration(Configuration): | |||||
139 |
|
153 | |||
140 | def dict_to_parms(self, parameters): |
|
154 | def dict_to_parms(self, parameters): | |
141 |
|
155 | |||
|
156 | self.name = parameters['name'] | |||
|
157 | self.device.id = int(parameters['device_id']) | |||
|
158 | ||||
142 | self.exp_type = int(parameters['exp_type']) |
|
159 | self.exp_type = int(parameters['exp_type']) | |
143 | if parameters['exptype'] == 'PDATA': |
|
160 | if parameters['exptype'] == 'PDATA': | |
144 | self.incohe_integr = parameters['incohe_integr'] |
|
161 | self.incohe_integr = parameters['incohe_integr'] | |
145 | self.spectral_number = parameters['spectral_number'] |
|
162 | self.spectral_number = parameters['spectral_number'] | |
146 |
self.spectral = |
|
163 | self.spectral = parameters['spectral'] | |
|
164 | self.pd_directory = parameters['pd_directory'] | |||
147 |
|
165 | |||
148 | self.cards_number = int(parameters['cards_number']) |
|
166 | self.cards_number = int(parameters['cards_number']) | |
149 | self.channels_number = int(parameters['channels_number']) |
|
167 | self.channels_number = int(parameters['channels_number']) | |
150 | self.channels = parameters['channels'] |
|
168 | self.channels = parameters['channels'] | |
151 | self.rd_directory = parameters['rd_directory'] |
|
169 | self.rd_directory = parameters['rd_directory'] | |
152 | self.raw_data_blocks = parameters['raw_data_blocks'] |
|
170 | #self.raw_data_blocks = parameters['raw_data_blocks'] | |
153 | self.data_type = parameters['data_type'] |
|
171 | self.data_type = parameters['data_type'] | |
|
172 | self.cohe_integr_str = parameters['cohe_integr_str'] | |||
154 | self.acq_profiles = parameters['acq_profiles'] |
|
173 | self.acq_profiles = parameters['acq_profiles'] | |
155 | self.profiles_block = parameters['profiles_block'] |
|
174 | self.profiles_block = parameters['profiles_block'] | |
|
175 | self.ftp_interval = parameters['ftp_interval'] | |||
156 | self.fftpoints = parameters['fftpoints'] |
|
176 | self.fftpoints = parameters['fftpoints'] | |
157 | self.cohe_integr = parameters['cohe_integr'] |
|
177 | self.cohe_integr = parameters['cohe_integr'] | |
158 |
|
178 | |||
159 | filter_name = parameters['filter'] |
|
179 | filter_name = parameters['filter'] | |
160 | self.filter = JARS.objects.get(name=filter_name) |
|
180 | self.filter = JARSfilter.objects.get(name=filter_name) | |
161 | self.save() |
|
|||
162 | self.add_parms_to_filter() |
|
181 | self.add_parms_to_filter() | |
|
182 | self.filter_parms = parameters['filter_parms'] | |||
163 |
|
183 | |||
164 | self.create_directory = bool(parameters['create_directory']) |
|
184 | self.create_directory = bool(parameters['create_directory']) | |
165 | self.include_expname = bool(parameters['include_expname']) |
|
185 | self.include_expname = bool(parameters['include_expname']) | |
166 | self.acq_link = bool(parameters['acq_link']) |
|
186 | #self.acq_link = bool(parameters['acq_link']) | |
167 | self.view_raw_data = bool(parameters['view_raw_data']) |
|
187 | #self.view_raw_data = bool(parameters['view_raw_data']) | |
168 | self.save_ch_dc = bool(parameters['save_ch_dc']) |
|
188 | self.save_ch_dc = bool(parameters['save_ch_dc']) | |
|
189 | self.save_data = bool(parameters['save_data']) | |||
169 |
|
190 | |||
170 | def status_device(self): |
|
191 | def status_device(self): | |
171 |
|
|
192 | ||
|
193 | answer = api.status(self.device.ip_address,self.device.port_address) | |||
|
194 | self.device.status = int(answer[0]) | |||
|
195 | self.message = answer[2:] | |||
|
196 | self.device.save() | |||
|
197 | ||||
|
198 | return self.device.status | |||
|
199 | ||||
|
200 | def stop_device(self): | |||
|
201 | ||||
|
202 | answer = api.stop(self.device.ip_address,self.device.port_address) | |||
|
203 | self.device.status = int(answer[0]) | |||
|
204 | self.message = answer[2:] | |||
|
205 | self.device.save() | |||
|
206 | ||||
|
207 | return self.device.status | |||
172 |
|
208 | |||
173 | def read_device(self): |
|
209 | def read_device(self): | |
174 |
|
|
210 | ||
|
211 | answer = api.read(self.device.ip_address,self.device.port_address) | |||
|
212 | self.device.status = int(answer[0]) | |||
|
213 | try: | |||
|
214 | data = json.loads(answer[2:]) | |||
|
215 | parms = data['configurations']['jars'] | |||
|
216 | except: | |||
|
217 | self.device.status = 0 | |||
|
218 | self.device.save() | |||
|
219 | self.message = 'Could not read JARS configuration.' | |||
|
220 | return '' | |||
|
221 | ||||
|
222 | #self.dict_to_parms(parms) | |||
|
223 | self.message = 'Current JARS configuration was read successfully.' | |||
|
224 | self.device.save() | |||
|
225 | return parms | |||
|
226 | ||||
175 |
|
227 | |||
176 | def write_device(self): |
|
228 | def write_device(self): | |
177 |
|
|
229 | ||
|
230 | data = self.experiment.parms_to_dict() | |||
|
231 | data = json.loads(data) | |||
|
232 | data['configurations']['dds'] ='' | |||
|
233 | data['configurations']['cgs'] ='' | |||
|
234 | data['configurations']['rc']['pulses']='' | |||
|
235 | data['configurations']['rc']['delays']='' | |||
|
236 | json_data = json.dumps(data) | |||
|
237 | ||||
|
238 | answer = api.configure(self.device.ip_address,self.device.port_address,json_data) | |||
|
239 | #print answer | |||
|
240 | self.device.status = int(answer[0]) | |||
|
241 | self.message = answer[2:] | |||
|
242 | ||||
|
243 | self.device.save() | |||
|
244 | ||||
|
245 | return self.device.status | |||
|
246 | ||||
|
247 | ||||
|
248 | def echo(self): | |||
|
249 | ||||
|
250 | answer = api.echo(self.device.ip_address,self.device.port_address,'(=') | |||
|
251 | #print answer | |||
|
252 | self.device.status = int(answer[0]) | |||
|
253 | self.message = answer[2:] | |||
|
254 | ||||
|
255 | self.device.save() | |||
|
256 | ||||
|
257 | return #self.device.status | |||
|
258 | ||||
|
259 | def update_from_file(self, parameters): | |||
|
260 | ||||
|
261 | self.dict_to_parms(parameters) | |||
|
262 | self.save() | |||
|
263 | ||||
|
264 | def get_absolute_url_import(self): | |||
|
265 | return reverse('url_import_jars_conf', args=[str(self.id)]) | |||
|
266 | ||||
|
267 | def get_absolute_url_read(self): | |||
|
268 | return reverse('url_read_jars_conf', args=[str(self.id)]) No newline at end of file |
@@ -6,4 +6,6 urlpatterns = ( | |||||
6 | url(r'^(?P<conf_id>-?\d+)/new_filter/$', 'apps.jars.views.new_filter', name='url_new_jars_filter'), |
|
6 | url(r'^(?P<conf_id>-?\d+)/new_filter/$', 'apps.jars.views.new_filter', name='url_new_jars_filter'), | |
7 | url(r'^(?P<conf_id>-?\d+)/view_filter/(?P<filter_id>-?\d+)/$', 'apps.jars.views.view_filter', name='url_jars_filter'), |
|
7 | url(r'^(?P<conf_id>-?\d+)/view_filter/(?P<filter_id>-?\d+)/$', 'apps.jars.views.view_filter', name='url_jars_filter'), | |
8 | url(r'^(?P<conf_id>-?\d+)/view_filter/(?P<filter_id>-?\d+)/edit$', 'apps.jars.views.edit_filter', name='url_edit_jars_filter'), |
|
8 | url(r'^(?P<conf_id>-?\d+)/view_filter/(?P<filter_id>-?\d+)/edit$', 'apps.jars.views.edit_filter', name='url_edit_jars_filter'), | |
|
9 | url(r'^(?P<conf_id>-?\d+)/import/$', 'apps.jars.views.import_file', name='url_import_jars_conf'), | |||
|
10 | url(r'^(?P<conf_id>-?\d+)/read/$', 'apps.jars.views.read_conf', name='url_read_jars_conf'), | |||
9 | ) |
|
11 | ) |
@@ -7,7 +7,7 from apps.main.models import Device | |||||
7 | from apps.main.views import sidebar |
|
7 | from apps.main.views import sidebar | |
8 |
|
8 | |||
9 | from .models import JARSConfiguration, JARSfilter |
|
9 | from .models import JARSConfiguration, JARSfilter | |
10 | from .forms import JARSConfigurationForm, JARSfilterForm |
|
10 | from .forms import JARSConfigurationForm, JARSfilterForm, JARSImportForm | |
11 | # Create your views here. |
|
11 | # Create your views here. | |
12 |
|
12 | |||
13 | def jars_conf(request, id_conf): |
|
13 | def jars_conf(request, id_conf): | |
@@ -24,18 +24,22 def jars_conf(request, id_conf): | |||||
24 | kwargs['dev_conf'] = conf |
|
24 | kwargs['dev_conf'] = conf | |
25 | kwargs['dev_conf_keys'] = ['name', |
|
25 | kwargs['dev_conf_keys'] = ['name', | |
26 | 'cards_number', 'channels_number', 'channels', |
|
26 | 'cards_number', 'channels_number', 'channels', | |
27 |
'rd_directory', ' |
|
27 | 'rd_directory', 'pd_directory', | |
28 |
' |
|
28 | 'data_type', | |
|
29 | 'acq_profiles', 'profiles_block', 'ftp_interval', 'fftpoints', | |||
|
30 | 'cohe_integr_str', | |||
29 | 'incohe_integr', 'cohe_integr', 'filter', 'spectral_number', |
|
31 | 'incohe_integr', 'cohe_integr', 'filter', 'spectral_number', | |
30 | 'spectral', 'create_directory', 'include_expname', |
|
32 | 'spectral', 'create_directory', 'include_expname', | |
31 |
' |
|
33 | 'save_ch_dc', 'save_data'] | |
32 |
|
34 | |||
33 | kwargs['title'] = 'JARS Configuration' |
|
35 | kwargs['title'] = 'JARS Configuration' | |
34 | kwargs['suptitle'] = 'Details' |
|
36 | kwargs['suptitle'] = 'Details' | |
35 |
|
37 | |||
36 | kwargs['button'] = 'Edit Configuration' |
|
38 | kwargs['button'] = 'Edit Configuration' | |
37 |
|
39 | |||
38 | kwargs['no_play'] = True |
|
40 | #kwargs['no_play'] = True | |
|
41 | ||||
|
42 | kwargs['only_stop'] = True | |||
39 |
|
43 | |||
40 | ###### SIDEBAR ###### |
|
44 | ###### SIDEBAR ###### | |
41 | kwargs.update(sidebar(conf=conf)) |
|
45 | kwargs.update(sidebar(conf=conf)) | |
@@ -70,6 +74,74 def jars_conf_edit(request, id_conf): | |||||
70 |
|
74 | |||
71 | return render(request, 'jars_conf_edit.html', kwargs) |
|
75 | return render(request, 'jars_conf_edit.html', kwargs) | |
72 |
|
76 | |||
|
77 | def import_file(request, conf_id): | |||
|
78 | ||||
|
79 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) | |||
|
80 | if request.method=='POST': | |||
|
81 | form = JARSImportForm(request.POST, request.FILES) | |||
|
82 | if form.is_valid(): | |||
|
83 | try: | |||
|
84 | parms = conf.import_from_file(request.FILES['file_name']) | |||
|
85 | ||||
|
86 | if parms: | |||
|
87 | conf.update_from_file(parms) | |||
|
88 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) | |||
|
89 | return redirect(conf.get_absolute_url_edit()) | |||
|
90 | ||||
|
91 | except Exception as e: | |||
|
92 | messages.error(request, 'Error parsing file: "%s" - %s' % (request.FILES['file_name'], e)) | |||
|
93 | ||||
|
94 | else: | |||
|
95 | messages.warning(request, 'Your current configuration will be replaced') | |||
|
96 | form = JARSImportForm() | |||
|
97 | ||||
|
98 | kwargs = {} | |||
|
99 | kwargs['form'] = form | |||
|
100 | kwargs['title'] = 'JARS Configuration' | |||
|
101 | kwargs['suptitle'] = 'Import file' | |||
|
102 | kwargs['button'] = 'Upload' | |||
|
103 | kwargs['previous'] = conf.get_absolute_url() | |||
|
104 | ||||
|
105 | return render(request, 'jars_import.html', kwargs) | |||
|
106 | ||||
|
107 | def read_conf(request, conf_id): | |||
|
108 | ||||
|
109 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) | |||
|
110 | #filter = get_object_or_404(JARSfilter, pk=filter_id) | |||
|
111 | ||||
|
112 | if request.method=='GET': | |||
|
113 | ||||
|
114 | parms = conf.read_device() | |||
|
115 | conf.status_device() | |||
|
116 | ||||
|
117 | if not parms: | |||
|
118 | messages.error(request, conf.message) | |||
|
119 | return redirect(conf.get_absolute_url()) | |||
|
120 | ||||
|
121 | form = JARSConfigurationForm(initial=parms, instance=conf) | |||
|
122 | ||||
|
123 | if request.method=='POST': | |||
|
124 | form = JARSConfigurationForm(request.POST, instance=conf) | |||
|
125 | ||||
|
126 | if form.is_valid(): | |||
|
127 | form.save() | |||
|
128 | return redirect(conf.get_absolute_url()) | |||
|
129 | ||||
|
130 | messages.error(request, "Parameters could not be saved") | |||
|
131 | ||||
|
132 | kwargs = {} | |||
|
133 | kwargs['id_dev'] = conf.id | |||
|
134 | kwargs['filter_id'] = conf.filter.id | |||
|
135 | kwargs['form'] = form | |||
|
136 | kwargs['title'] = 'Device Configuration' | |||
|
137 | kwargs['suptitle'] = 'Parameters read from device' | |||
|
138 | kwargs['button'] = 'Save' | |||
|
139 | ||||
|
140 | ###### SIDEBAR ###### | |||
|
141 | kwargs.update(sidebar(conf=conf)) | |||
|
142 | ||||
|
143 | return render(request, 'jars_conf_edit.html', kwargs) | |||
|
144 | ||||
73 | def view_filter(request, conf_id, filter_id): |
|
145 | def view_filter(request, conf_id, filter_id): | |
74 |
|
146 | |||
75 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) |
|
147 | conf = get_object_or_404(JARSConfiguration, pk=conf_id) |
@@ -376,6 +376,16 class Experiment(models.Model): | |||||
376 | #--For ABS Device: |
|
376 | #--For ABS Device: | |
377 | #--For USRP Device: |
|
377 | #--For USRP Device: | |
378 | #--For JARS Device: |
|
378 | #--For JARS Device: | |
|
379 | if conf_type == 'jars': | |||
|
380 | device = get_object_or_404(Device, pk=parms['configurations']['jars']['device_id']) | |||
|
381 | DevConfModel = CONF_MODELS[conf_type] | |||
|
382 | confjars_form = DevConfModel( | |||
|
383 | experiment = self, | |||
|
384 | name = 'JARS', | |||
|
385 | device=device, | |||
|
386 | ) | |||
|
387 | confjars_form.dict_to_parms(parms['configurations']['jars']) | |||
|
388 | confjars_form.save() | |||
379 | #--For RC Device: |
|
389 | #--For RC Device: | |
380 | if conf_type == 'rc': |
|
390 | if conf_type == 'rc': | |
381 | device = get_object_or_404(Device, pk=parms['configurations']['rc']['device_id']) |
|
391 | device = get_object_or_404(Device, pk=parms['configurations']['rc']['device_id']) |
@@ -23,7 +23,9 | |||||
23 | <li><a>----------------</a></li> |
|
23 | <li><a>----------------</a></li> | |
24 | <li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> |
|
24 | <li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> | |
25 | {% if not no_play %} |
|
25 | {% if not no_play %} | |
26 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> |
|
26 | {% if not only_stop %} | |
|
27 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> | |||
|
28 | {% endif %} | |||
27 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> |
|
29 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> | |
28 | {% endif %} |
|
30 | {% endif %} | |
29 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> |
|
31 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> |
@@ -38,67 +38,77 | |||||
38 | {% endfor %} |
|
38 | {% endfor %} | |
39 | </table> |
|
39 | </table> | |
40 |
|
40 | |||
41 | <div class=""> |
|
|||
42 | <h4 class="panel-title"><b> Parameters </b></h4> |
|
|||
43 | <br> |
|
|||
44 | </div> |
|
|||
45 |
|
41 | |||
46 | <table class="table table-bordered"> |
|
|||
47 | {% for configuration in configurations %} |
|
42 | {% for configuration in configurations %} | |
|
43 | ||||
48 | {% if configuration.device.device_type.name == 'dds' %} |
|
44 | {% if configuration.device.device_type.name == 'dds' %} | |
49 | <!--<h4 class="panel-title"> </h4>--> |
|
45 | <div class=""> | |
50 | <tr><th>dds</th><td>(=</td></tr> |
|
46 | <h4 class="panel-title"><b> DDS </b></h4> | |
|
47 | <br> | |||
|
48 | </div> | |||
|
49 | ||||
|
50 | <table class="table table-bordered"> | |||
|
51 | <!--<h4 class="panel-title"> </h4>--> | |||
|
52 | <tr><th>dds</th><td>(=</td></tr> | |||
|
53 | </table> | |||
51 | {% endif %} |
|
54 | {% endif %} | |
52 |
|
55 | |||
53 | {% if configuration.device.device_type.name == 'rc' %} |
|
56 | {% if configuration.device.device_type.name == 'rc' %} | |
54 | <!--<h4 class="panel-title"> </h4>--> |
|
57 | <div class=""> | |
55 | <tr><th>IPP(km)</th><td>{{experiment_data.configurations.rc.ipp}}</td></tr> |
|
58 | <h4 class="panel-title"><b> CR </b></h4> | |
56 | <tr><th>NTX</th><td>{{experiment_data.configurations.rc.ntx}}</td></tr> |
|
59 | <br> | |
57 | <tr><th>TX</th><td>{{tx}}</td></tr> |
|
60 | </div> | |
58 | <tr><th>Code</th><td>{{code}}</td></tr> |
|
|||
59 | <tr><th>Sampling Window</th><td>{{window|linebreaks}}</td></tr> |
|
|||
60 | {% endif %} |
|
|||
61 |
|
61 | |||
62 | {% if configuration.device.device_type.name == 'rc_mix' %} |
|
62 | <table class="table table-bordered"> | |
63 | <!--<h4 class="panel-title"> </h4>--> |
|
63 | <!--<h4 class="panel-title"> </h4>--> | |
64 | <tr><th>rc_mix</th><td>(=</td></tr> |
|
64 | <tr><th>IPP(km)</th><td>{{experiment_data.configurations.rc.ipp}}</td></tr> | |
|
65 | <tr><th>NTX</th><td>{{experiment_data.configurations.rc.ntx}}</td></tr> | |||
|
66 | <tr><th>TX</th><td>{{tx}}</td></tr> | |||
|
67 | <tr><th>Code</th><td>{{code}}</td></tr> | |||
|
68 | <tr><th>Sampling Window</th><td>{{window|linebreaks}}</td></tr> | |||
|
69 | </table> | |||
65 | {% endif %} |
|
70 | {% endif %} | |
66 |
|
71 | |||
67 | {% if configuration.device.device_type.name == 'jars' %} |
|
72 | {% if configuration.device.device_type.name == 'jars' %} | |
68 | <!--<h4 class="panel-title"> JARS </h4>--> |
|
73 | <div class=""> | |
69 | <tr><th>Data Type</th><td>{{exp_type}}</td></tr> |
|
74 | <h4 class="panel-title"><b> JARS </b></h4> | |
70 | <tr><th># Channels</th><td>{{configuration.channels_number}}</td></tr> |
|
75 | <br> | |
71 | <tr><th>Coh Int</th><td>{{configuration.cohe_integr}}</td></tr> |
|
76 | </div> | |
72 | <tr><th>FFT Points</th><td>{{configuration.fftpoints}}</td></tr> |
|
|||
73 | {% if exp_type == 'PDATA'%} |
|
|||
74 | <tr><th>Inc Int</th><td>{{configuration.incohe_integr}}</td></tr> |
|
|||
75 | <tr><th>Spec. Comb.</th><td>{{configuration.spectral}}</td></tr> |
|
|||
76 | {% endif %} |
|
|||
77 | <tr><th>Acq Prof</th><td>{{configuration.acq_profiles}}</td></tr> |
|
|||
78 | <tr><th>Prof x Block</th><td>{{configuration.profiles_block}}</td></tr> |
|
|||
79 | <tr><th>Block x File</th><td>(=</td></tr> |
|
|||
80 | {% endif %} |
|
|||
81 |
|
||||
82 | {% if configuration.device.device_type.name == 'usrp' %} |
|
|||
83 | <!--<h4 class="panel-title"> </h4>--> |
|
|||
84 | <tr><th>usrp</th><td>(=</td></tr> |
|
|||
85 | {% endif %} |
|
|||
86 |
|
||||
87 | {% if configuration.device.device_type.name == 'cgs' %} |
|
|||
88 | <!--<h4 class="panel-title"> CGS </h4>--> |
|
|||
89 | <!--<tr><th>Frequency 0</th><td>{{configuration.freq0}}</td></tr>--> |
|
|||
90 | <!--<tr><th>Frequency 1</th><td>{{configuration.freq1}}</td></tr>--> |
|
|||
91 | <!--<tr><th>Frequency 2</th><td>{{configuration.freq2}}</td></tr>--> |
|
|||
92 | <!--<tr><th>Frequency 3</th><td>{{configuration.freq3}}</td></tr>--> |
|
|||
93 | {% endif %} |
|
|||
94 |
|
77 | |||
95 | {% if configuration.device.device_type.name == 'abs' %} |
|
78 | <table class="table table-bordered"> | |
96 | <!--<h4 class="panel-title"> </h4>--> |
|
79 | <!--<h4 class="panel-title"> JARS </h4>--> | |
97 |
<tr><th> |
|
80 | <tr><th>Data Type</th><td>{{exp_type}}</td></tr> | |
|
81 | <tr><th># Channels</th><td>{{configuration.channels_number}}</td></tr> | |||
|
82 | <tr><th>Coh Int</th><td>{{configuration.cohe_integr}}</td></tr> | |||
|
83 | <tr><th>FFT Points</th><td>{{configuration.fftpoints}}</td></tr> | |||
|
84 | {% if exp_type == 'PDATA'%} | |||
|
85 | <tr><th>Inc Int</th><td>{{configuration.incohe_integr}}</td></tr> | |||
|
86 | <tr><th>Spec. Comb.</th><td>{{configuration.spectral}}</td></tr> | |||
|
87 | {% endif %} | |||
|
88 | <tr><th>Acq Prof</th><td>{{configuration.acq_profiles}}</td></tr> | |||
|
89 | <tr><th>Prof x Block</th><td>{{configuration.profiles_block}}</td></tr> | |||
|
90 | <tr><th>Block x File</th><td>{{ configuration.raw_data_blocks }}</td></tr> | |||
|
91 | </table> | |||
98 | {% endif %} |
|
92 | {% endif %} | |
|
93 | ||||
99 | {% endfor %} |
|
94 | {% endfor %} | |
|
95 | ||||
|
96 | ||||
|
97 | <div class=""> | |||
|
98 | <h4 class="panel-title"><b> Extra Parameters </b></h4> | |||
|
99 | <br> | |||
|
100 | </div> | |||
|
101 | ||||
|
102 | <table class="table table-bordered"> | |||
|
103 | {% if jars_conf %} | |||
|
104 | <tr><th>Rate (MB/h)</th><td>{{ rate }}</td></tr> | |||
|
105 | {% endif %} | |||
|
106 | {% if dds_conf %} | |||
|
107 | <tr><th>Vmax (m/s)</th><td>{{ rate }}</td></tr> | |||
|
108 | {% endif %} | |||
100 | </table> |
|
109 | </table> | |
101 |
|
110 | |||
|
111 | ||||
102 | <div class="pull-right"> |
|
112 | <div class="pull-right"> | |
103 | <button type="button" class="btn btn-primary" id="bt_back">Back</button> |
|
113 | <button type="button" class="btn btn-primary" id="bt_back">Back</button> | |
104 | <button type="button" class="btn btn-primary" id="bt_verify">Verify Parameters</button> |
|
114 | <button type="button" class="btn btn-primary" id="bt_verify">Verify Parameters</button> | |
@@ -121,5 +131,9 | |||||
121 | document.location = "{% url 'url_experiment' experiment.id%}"; |
|
131 | document.location = "{% url 'url_experiment' experiment.id%}"; | |
122 | }); |
|
132 | }); | |
123 |
|
133 | |||
|
134 | $("#bt_verify").click(function() { | |||
|
135 | document.location = "{% url 'url_verify_experiment' experiment.id%}"; | |||
|
136 | }); | |||
|
137 | ||||
124 | </script> |
|
138 | </script> | |
125 | {% endblock %} No newline at end of file |
|
139 | {% endblock %} |
@@ -31,6 +31,7 urlpatterns = ( | |||||
31 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/$', 'apps.main.views.experiment_mix', name='url_mix_experiment'), |
|
31 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/$', 'apps.main.views.experiment_mix', name='url_mix_experiment'), | |
32 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/delete/$', 'apps.main.views.experiment_mix_delete', name='url_delete_mix_experiment'), |
|
32 | url(r'^experiment/(?P<id_exp>-?\d+)/mix/delete/$', 'apps.main.views.experiment_mix_delete', name='url_delete_mix_experiment'), | |
33 | url(r'^experiment/(?P<id_exp>-?\d+)/summary/$', 'apps.main.views.experiment_summary', name='url_sum_experiment'), |
|
33 | url(r'^experiment/(?P<id_exp>-?\d+)/summary/$', 'apps.main.views.experiment_summary', name='url_sum_experiment'), | |
|
34 | url(r'^experiment/(?P<id_exp>-?\d+)/verify/$', 'apps.main.views.experiment_verify', name='url_verify_experiment'), | |||
34 |
|
35 | |||
35 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
36 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), | |
36 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
37 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
@@ -25,6 +25,7 from apps.abs.models import ABSConfiguration | |||||
25 | from apps.rc.models import RCConfiguration, RCLine, RCLineType |
|
25 | from apps.rc.models import RCConfiguration, RCLine, RCLineType | |
26 | from apps.dds.models import DDSConfiguration |
|
26 | from apps.dds.models import DDSConfiguration | |
27 | from django.http.request import QueryDict |
|
27 | from django.http.request import QueryDict | |
|
28 | #from __builtin__ import False | |||
28 |
|
29 | |||
29 | # Create your views here. |
|
30 | # Create your views here. | |
30 |
|
31 | |||
@@ -756,6 +757,7 def experiment_mix_delete(request, id_exp): | |||||
756 | def experiment_summary(request, id_exp): |
|
757 | def experiment_summary(request, id_exp): | |
757 |
|
758 | |||
758 | import json |
|
759 | import json | |
|
760 | import ast | |||
759 |
|
761 | |||
760 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
762 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
761 | experiment_data = json.loads(experiment.parms_to_dict()) |
|
763 | experiment_data = json.loads(experiment.parms_to_dict()) | |
@@ -775,12 +777,28 def experiment_summary(request, id_exp): | |||||
775 |
|
777 | |||
776 | kwargs['button'] = 'Verify Parameters' |
|
778 | kwargs['button'] = 'Verify Parameters' | |
777 |
|
779 | |||
|
780 | jars_conf = False | |||
|
781 | rc_conf = False | |||
|
782 | ||||
778 | for configuration in configurations: |
|
783 | for configuration in configurations: | |
|
784 | #-------------------- JARS -----------------------: | |||
779 | if configuration.device.device_type.name == 'jars': |
|
785 | if configuration.device.device_type.name == 'jars': | |
780 | kwargs['exp_type'] = EXPERIMENT_TYPE[configuration.exp_type][1] |
|
786 | jars_conf = True | |
781 |
|
787 | kwargs['jars_conf'] = jars_conf | ||
|
788 | kwargs['exp_type'] = EXPERIMENT_TYPE[configuration.exp_type][1] | |||
|
789 | channels_number = configuration.channels_number | |||
|
790 | exp_type = configuration.exp_type | |||
|
791 | fftpoints = configuration.fftpoints | |||
|
792 | filter_parms = configuration.filter_parms | |||
|
793 | filter_parms = ast.literal_eval(filter_parms) | |||
|
794 | spectral_number = configuration.spectral_number | |||
|
795 | ||||
|
796 | #--------------------- RC ----------------------: | |||
782 | if configuration.device.device_type.name == 'rc': |
|
797 | if configuration.device.device_type.name == 'rc': | |
|
798 | rc_conf = True | |||
|
799 | kwargs['rc_conf'] = rc_conf | |||
783 | rc_lines = experiment_data['configurations']['rc']['lines'] |
|
800 | rc_lines = experiment_data['configurations']['rc']['lines'] | |
|
801 | ipp = configuration.ipp | |||
784 | if experiment_data['configurations']['rc']['mix'] == 'True': |
|
802 | if experiment_data['configurations']['rc']['mix'] == 'True': | |
785 | tx = '' |
|
803 | tx = '' | |
786 | code = '' |
|
804 | code = '' | |
@@ -805,12 +823,136 def experiment_summary(request, id_exp): | |||||
805 | kwargs['tx'] = tx |
|
823 | kwargs['tx'] = tx | |
806 | kwargs['code'] = code |
|
824 | kwargs['code'] = code | |
807 | kwargs['window'] = window |
|
825 | kwargs['window'] = window | |
808 |
|
826 | |||
|
827 | #-------------------- DDS -----------------------: | |||
|
828 | if configuration.device.device_type.name == 'dds': | |||
|
829 | dds_conf = True | |||
|
830 | kwargs['dds_conf'] = dds_conf | |||
|
831 | ||||
|
832 | #------ RC & JARS ------: | |||
|
833 | ipp = 937.5 # | |||
|
834 | nsa = 200# | |||
|
835 | dh = 1.5 # | |||
|
836 | channels_number = 5 # | |||
|
837 | ||||
|
838 | if rc_conf and jars_conf: | |||
|
839 | if exp_type == 0: #Short | |||
|
840 | bytes = 2 | |||
|
841 | b = nsa*2*bytes*channels_number | |||
|
842 | else: #Float | |||
|
843 | bytes = 4 | |||
|
844 | channels = channels_number + spectral_number | |||
|
845 | b = nsa*2*bytes*fftpoints*channels | |||
|
846 | ||||
|
847 | ipps = (ipp*pow(10,-6))/0.15 | |||
|
848 | GB = 1048576.0*1024.0 | |||
|
849 | Hour = 3600 | |||
|
850 | rate = b/ipps | |||
|
851 | rate = rate *(1/GB)*(Hour) | |||
|
852 | kwargs['rate'] = str(rate)+" GB/h" | |||
|
853 | else: | |||
|
854 | kwargs['rate'] = '' | |||
|
855 | ||||
809 | ###### SIDEBAR ###### |
|
856 | ###### SIDEBAR ###### | |
810 | kwargs.update(sidebar(experiment=experiment)) |
|
857 | kwargs.update(sidebar(experiment=experiment)) | |
811 |
|
858 | |||
812 | return render(request, 'experiment_summary.html', kwargs) |
|
859 | return render(request, 'experiment_summary.html', kwargs) | |
813 |
|
860 | |||
|
861 | def experiment_verify(request, id_exp): | |||
|
862 | ||||
|
863 | import json | |||
|
864 | import ast | |||
|
865 | ||||
|
866 | experiment = get_object_or_404(Experiment, pk=id_exp) | |||
|
867 | experiment_data = json.loads(experiment.parms_to_dict()) | |||
|
868 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |||
|
869 | ||||
|
870 | kwargs = {} | |||
|
871 | ||||
|
872 | kwargs['experiment_keys'] = ['template', 'radar_system', 'name', 'start_time', 'end_time'] | |||
|
873 | kwargs['experiment'] = experiment | |||
|
874 | ||||
|
875 | kwargs['configuration_keys'] = ['name', 'device__ip_address', 'device__port_address', 'device__status'] | |||
|
876 | kwargs['configurations'] = configurations | |||
|
877 | kwargs['experiment_data'] = experiment_data | |||
|
878 | ||||
|
879 | kwargs['title'] = 'Verify Experiment' | |||
|
880 | kwargs['suptitle'] = 'Parameters' | |||
|
881 | ||||
|
882 | kwargs['button'] = 'Update' | |||
|
883 | ||||
|
884 | jars_conf = False | |||
|
885 | rc_conf = False | |||
|
886 | dds_conf = False | |||
|
887 | ||||
|
888 | for configuration in configurations: | |||
|
889 | #-------------------- JARS -----------------------: | |||
|
890 | if configuration.device.device_type.name == 'jars': | |||
|
891 | jars_conf = True | |||
|
892 | kwargs['jars_conf'] = jars_conf | |||
|
893 | filter_parms = configuration.filter_parms | |||
|
894 | filter_parms = ast.literal_eval(filter_parms) | |||
|
895 | kwargs['filter_parms'] = filter_parms | |||
|
896 | #--Sampling Frequency | |||
|
897 | clock = filter_parms['clock'] | |||
|
898 | filter_2 = filter_parms['filter_2'] | |||
|
899 | filter_5 = filter_parms['filter_5'] | |||
|
900 | filter_fir = filter_parms['filter_fir'] | |||
|
901 | samp_freq_jars = clock/filter_2/filter_5/filter_fir | |||
|
902 | ||||
|
903 | kwargs['samp_freq_jars'] = samp_freq_jars | |||
|
904 | kwargs['jars'] = configuration | |||
|
905 | ||||
|
906 | #--------------------- RC ----------------------: | |||
|
907 | if configuration.device.device_type.name == 'rc': | |||
|
908 | rc_conf = True | |||
|
909 | rc_parms = configuration.parms_to_dict() | |||
|
910 | if rc_parms['mix'] == 'True': | |||
|
911 | pass | |||
|
912 | else: | |||
|
913 | rc_lines = rc_parms['lines'] | |||
|
914 | dh = rc_lines[6]['params'][0]['resolution'] | |||
|
915 | #--Sampling Frequency | |||
|
916 | samp_freq_rc = 0.15/dh | |||
|
917 | kwargs['samp_freq_rc'] = samp_freq_rc | |||
|
918 | ||||
|
919 | kwargs['rc_conf'] = rc_conf | |||
|
920 | kwargs['rc'] = configuration | |||
|
921 | ||||
|
922 | #-------------------- DDS ----------------------: | |||
|
923 | if configuration.device.device_type.name == 'dds': | |||
|
924 | dds_conf = True | |||
|
925 | dds_parms = configuration.parms_to_dict() | |||
|
926 | ||||
|
927 | kwargs['dds_conf'] = dds_conf | |||
|
928 | kwargs['dds'] = configuration | |||
|
929 | ||||
|
930 | ||||
|
931 | #------------Validation------------: | |||
|
932 | #Clock | |||
|
933 | if dds_conf and rc_conf and jars_conf: | |||
|
934 | if filter_parms['clock'] != rc_parms['clock_in'] and rc_parms['clock_in'] != dds_parms['clock']: | |||
|
935 | messages.warning(request, "Devices don't have the same clock.") | |||
|
936 | elif rc_conf and jars_conf: | |||
|
937 | if filter_parms['clock'] != rc_parms['clock_in']: | |||
|
938 | messages.warning(request, "Devices don't have the same clock.") | |||
|
939 | elif rc_conf and dds_conf: | |||
|
940 | if rc_parms['clock_in'] != dds_parms['clock']: | |||
|
941 | messages.warning(request, "Devices don't have the same clock.") | |||
|
942 | if float(samp_freq_rc) != float(dds_parms['frequencyA']): | |||
|
943 | messages.warning(request, "Devices don't have the same Frequency A.") | |||
|
944 | ||||
|
945 | ||||
|
946 | ||||
|
947 | ###### SIDEBAR ###### | |||
|
948 | kwargs.update(sidebar(experiment=experiment)) | |||
|
949 | ||||
|
950 | ||||
|
951 | ||||
|
952 | ||||
|
953 | ||||
|
954 | return render(request, 'experiment_verify.html', kwargs) | |||
|
955 | ||||
814 |
|
956 | |||
815 | def parse_mix_result(s): |
|
957 | def parse_mix_result(s): | |
816 |
|
958 | |||
@@ -1055,7 +1197,7 def dev_conf_write(request, id_conf): | |||||
1055 | messages.success(request, conf.message) |
|
1197 | messages.success(request, conf.message) | |
1056 |
|
1198 | |||
1057 | #Creating a historical configuration |
|
1199 | #Creating a historical configuration | |
1058 |
conf.clone(type= |
|
1200 | conf.clone(type=1, template=False) | |
1059 |
|
1201 | |||
1060 | #Original configuration |
|
1202 | #Original configuration | |
1061 | conf = DevConfModel.objects.get(pk=id_conf) |
|
1203 | conf = DevConfModel.objects.get(pk=id_conf) |
@@ -20,7 +20,7 | |||||
20 | {"fields": {"params": "{\"TX_ref\": {\"model\": \"RCLine\", \"value\": \"\"}, \"range\": { \"value\": 0, \"help\": \"Frame numbers or frame ranges separated by commas, use 0 for all frames eg: 1,2,10-15\"}}", "name": "tr", "description": ""}, "model": "rc.rclinetype", "pk": 1}, |
|
20 | {"fields": {"params": "{\"TX_ref\": {\"model\": \"RCLine\", \"value\": \"\"}, \"range\": { \"value\": 0, \"help\": \"Frame numbers or frame ranges separated by commas, use 0 for all frames eg: 1,2,10-15\"}}", "name": "tr", "description": ""}, "model": "rc.rclinetype", "pk": 1}, | |
21 | {"fields": {"params": "{\"pulse_width\":{\"value\": 0, \"widget\":\"dc\"},\r\n \"delays\":{\"value\": \"\", \"widget\":\"km\", \"help\": \"Delay entries separated by commas (TAUs)\"},\r\n \"range\":{\"value\": 0, \"help\": \"Frame numbers or frame ranges separated by commas, use 0 for all frames eg: 1,2,10-15\"}}", "name": "tx", "description": ""}, "model": "rc.rclinetype", "pk": 2}, |
|
21 | {"fields": {"params": "{\"pulse_width\":{\"value\": 0, \"widget\":\"dc\"},\r\n \"delays\":{\"value\": \"\", \"widget\":\"km\", \"help\": \"Delay entries separated by commas (TAUs)\"},\r\n \"range\":{\"value\": 0, \"help\": \"Frame numbers or frame ranges separated by commas, use 0 for all frames eg: 1,2,10-15\"}}", "name": "tx", "description": ""}, "model": "rc.rclinetype", "pk": 2}, | |
22 | {"fields": {"params": "{\"TX_ref\": {\"model\": \"RCLine\", \"value\": \"\"}, \"code\": {\"model\":\"RCLineCode\",\"value\": \"\"}, \"codes\":{\"value\":\"\", \"widget\":\"codes\"}}", "name": "codes", "description": ""}, "model": "rc.rclinetype", "pk": 3}, |
|
22 | {"fields": {"params": "{\"TX_ref\": {\"model\": \"RCLine\", \"value\": \"\"}, \"code\": {\"model\":\"RCLineCode\",\"value\": \"\"}, \"codes\":{\"value\":\"\", \"widget\":\"codes\"}}", "name": "codes", "description": ""}, "model": "rc.rclinetype", "pk": 3}, | |
23 | {"fields": {"params": "{ \"TX_ref\":{\"model\": \"RCLine\", \"value\": \"\"}, \"params\": {\"first_height\":{ \"value\": 0, \"widget\":\"km\"},\"resolution\": {\"value\": 0, \"widget\":\"km\"}, \"number_of_samples\": { \"value\": 0, \"help\":\"number of samples (NSA)\"}}}", "name": "windows", "description": ""}, "model": "rc.rclinetype", "pk": 4}, |
|
23 | {"fields": {"params": "{ \"TX_ref\":{\"model\": \"RCLine\", \"value\": \"\"}, \"params\": {\"first_height\":{ \"value\": 0, \"widget\":\"km\"},\"resolution\": {\"value\": 0, \"widget\":\"km\"}, \"number_of_samples\": { \"value\": 0, \"help\":\"number of samples (NSA)\"}, \"last_height\": { \"value\": 0}}}", "name": "windows", "description": ""}, "model": "rc.rclinetype", "pk": 4}, | |
24 | {"fields": {"params": "{\"invert\":{\"value\": 0, \"help\": \"Set to 1 for synchro pulse at the end\"}}", "name": "sync", "description": ""}, "model": "rc.rclinetype", "pk": 5}, |
|
24 | {"fields": {"params": "{\"invert\":{\"value\": 0, \"help\": \"Set to 1 for synchro pulse at the end\"}}", "name": "sync", "description": ""}, "model": "rc.rclinetype", "pk": 5}, | |
25 | {"fields": {"params": "{ \"periodic\": { \"value\": 0, \"help\": \"Set to 1 for IPP periodic\"}, \"params\": {\"begin\": { \"value\": 0, \"widget\":\"unit\"}, \"end\": {\"value\": 0, \"widget\":\"unit\"}}}", "name": "prog_pulses", "description": ""}, "model": "rc.rclinetype", "pk": 6}, |
|
25 | {"fields": {"params": "{ \"periodic\": { \"value\": 0, \"help\": \"Set to 1 for IPP periodic\"}, \"params\": {\"begin\": { \"value\": 0, \"widget\":\"unit\"}, \"end\": {\"value\": 0, \"widget\":\"unit\"}}}", "name": "prog_pulses", "description": ""}, "model": "rc.rclinetype", "pk": 6}, | |
26 | {"fields": {"params": "{\"number_of_flips\": {\"value\": 0}}", "name": "flip", "description": ""}, "model": "rc.rclinetype", "pk": 7}, |
|
26 | {"fields": {"params": "{\"number_of_flips\": {\"value\": 0}}", "name": "flip", "description": ""}, "model": "rc.rclinetype", "pk": 7}, |
@@ -30,6 +30,7 LINE_TYPES = ( | |||||
30 |
|
30 | |||
31 | SAMPLING_REFS = ( |
|
31 | SAMPLING_REFS = ( | |
32 | ('none', 'No Reference'), |
|
32 | ('none', 'No Reference'), | |
|
33 | ('begin_baud', 'Begin of the first baud'), | |||
33 | ('first_baud', 'Middle of the first baud'), |
|
34 | ('first_baud', 'Middle of the first baud'), | |
34 | ('sub_baud', 'Middle of the sub-baud') |
|
35 | ('sub_baud', 'Middle of the sub-baud') | |
35 | ) |
|
36 | ) | |
@@ -145,12 +146,13 class RCConfiguration(Configuration): | |||||
145 | data['lines'] = [] |
|
146 | data['lines'] = [] | |
146 |
|
147 | |||
147 | for line in self.get_lines(): |
|
148 | for line in self.get_lines(): | |
148 | line_data = json.loads(line.params) |
|
149 | line_data = json.loads(line.params) | |
149 | if 'TX_ref' in line_data and line_data['TX_ref'] not in (0, '0'): |
|
150 | if 'TX_ref' in line_data and line_data['TX_ref'] not in (0, '0'): | |
150 |
line_data['TX_ref'] = |
|
151 | line_data['TX_ref'] = line.get_name() | |
151 | if 'code' in line_data: |
|
152 | if 'code' in line_data: | |
152 | line_data['code'] = RCLineCode.objects.get(pk=line_data['code']).name |
|
153 | line_data['code'] = RCLineCode.objects.get(pk=line_data['code']).name | |
153 | line_data['type'] = line.line_type.name |
|
154 | line_data['type'] = line.line_type.name | |
|
155 | line_data['name'] = line.get_name() | |||
154 | data['lines'].append(line_data) |
|
156 | data['lines'].append(line_data) | |
155 |
|
157 | |||
156 | data['delays'] = self.get_delays() |
|
158 | data['delays'] = self.get_delays() | |
@@ -341,7 +343,7 class RCConfiguration(Configuration): | |||||
341 | for line in self.get_lines(): |
|
343 | for line in self.get_lines(): | |
342 | line.update_pulses() |
|
344 | line.update_pulses() | |
343 |
|
345 | |||
344 | def plot_pulses(self): |
|
346 | def plot_pulses(self, km=False): | |
345 |
|
347 | |||
346 | import matplotlib.pyplot as plt |
|
348 | import matplotlib.pyplot as plt | |
347 | from bokeh.resources import CDN |
|
349 | from bokeh.resources import CDN | |
@@ -352,19 +354,29 class RCConfiguration(Configuration): | |||||
352 | lines = self.get_lines() |
|
354 | lines = self.get_lines() | |
353 |
|
355 | |||
354 | N = len(lines) |
|
356 | N = len(lines) | |
|
357 | npoints = self.total_units/self.km2unit if km else self.total_units | |||
355 | fig = plt.figure(figsize=(10, 2+N*0.5)) |
|
358 | fig = plt.figure(figsize=(10, 2+N*0.5)) | |
356 | ax = fig.add_subplot(111) |
|
359 | ax = fig.add_subplot(111) | |
357 | labels = [] |
|
360 | labels = ['IPP'] | |
358 |
|
361 | |||
359 | for i, line in enumerate(lines): |
|
362 | for i, line in enumerate(lines): | |
360 | labels.append(line.get_name()) |
|
363 | labels.append(line.get_name(channel=True)) | |
361 |
l = ax.plot((0, |
|
364 | l = ax.plot((0, npoints),(N-i-1, N-i-1)) | |
362 | points = [(tup[0], tup[1]-tup[0]) for tup in line.pulses_as_points() if tup<>(0,0)] |
|
365 | points = [(tup[0], tup[1]-tup[0]) for tup in line.pulses_as_points(km=km) if tup<>(0,0)] | |
363 | ax.broken_barh(points, (N-i-1, 0.5), |
|
366 | ax.broken_barh(points, (N-i-1, 0.5), | |
364 | edgecolor=l[0].get_color(), facecolor='none') |
|
367 | edgecolor=l[0].get_color(), facecolor='none') | |
365 |
|
368 | |||
|
369 | n = 0 | |||
|
370 | f = ((self.ntx+50)/100)*5 if ((self.ntx+50)/100)*10>0 else 2 | |||
|
371 | for x in np.arange(0, npoints, self.ipp if km else self.ipp*self.km2unit): | |||
|
372 | if n%f==0: | |||
|
373 | ax.text(x, N, '%s' % n, size=10) | |||
|
374 | n += 1 | |||
|
375 | ||||
|
376 | ||||
366 | labels.reverse() |
|
377 | labels.reverse() | |
367 | ax.set_yticklabels(labels) |
|
378 | ax.set_yticklabels(labels) | |
|
379 | ||||
368 | ax.set_xlabel = 'Units' |
|
380 | ax.set_xlabel = 'Units' | |
369 | plot = to_bokeh(fig, use_pandas=False) |
|
381 | plot = to_bokeh(fig, use_pandas=False) | |
370 | plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), PreviewSaveTool()] |
|
382 | plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), PreviewSaveTool()] | |
@@ -468,7 +480,7 class RCLine(models.Model): | |||||
468 |
|
480 | |||
469 | return self |
|
481 | return self | |
470 |
|
482 | |||
471 | def get_name(self): |
|
483 | def get_name(self, channel=False): | |
472 |
|
484 | |||
473 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
485 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
474 | s = '' |
|
486 | s = '' | |
@@ -484,10 +496,13 class RCLine(models.Model): | |||||
484 | ref = RCLine.objects.get(pk=pk) |
|
496 | ref = RCLine.objects.get(pk=pk) | |
485 | s = chars[ref.position] |
|
497 | s = chars[ref.position] | |
486 | s = '({})'.format(s) |
|
498 | s = '({})'.format(s) | |
487 |
|
|
499 | ||
488 |
|
|
500 | s = '{}{}'.format(self.line_type.name.upper(), s) | |
|
501 | ||||
|
502 | if channel: | |||
|
503 | return '{} {}'.format(s, self.channel) | |||
489 | else: |
|
504 | else: | |
490 | return '{} {}'.format(self.line_type.name.upper(), self.channel) |
|
505 | return s | |
491 |
|
506 | |||
492 | def get_lines(self, **kwargs): |
|
507 | def get_lines(self, **kwargs): | |
493 |
|
508 | |||
@@ -502,9 +517,13 class RCLine(models.Model): | |||||
502 |
|
517 | |||
503 | return y.astype(np.int8) |
|
518 | return y.astype(np.int8) | |
504 |
|
519 | |||
505 | def pulses_as_points(self): |
|
520 | def pulses_as_points(self, km=False): | |
506 |
|
521 | |||
507 | return ast.literal_eval(self.pulses) |
|
522 | if km: | |
|
523 | unit2km = 1/self.rc_configuration.km2unit | |||
|
524 | return [(tup[0]*unit2km, tup[1]*unit2km) for tup in ast.literal_eval(self.pulses)] | |||
|
525 | else: | |||
|
526 | return ast.literal_eval(self.pulses) | |||
508 |
|
527 | |||
509 | def get_win_ref(self, params, tx_id, km2unit): |
|
528 | def get_win_ref(self, params, tx_id, km2unit): | |
510 |
|
529 |
@@ -14,7 +14,18 function str2unit(s){ | |||||
14 | var ret = ""; |
|
14 | var ret = ""; | |
15 | values = s.split(","); |
|
15 | values = s.split(","); | |
16 | for (i=0; i<values.length; i++) { |
|
16 | for (i=0; i<values.length; i++) { | |
17 |
ret += Math.round(parseFloat(values[i]) |
|
17 | ret += Math.round(parseFloat(values[i])*km2unit); | |
|
18 | ret += ","; | |||
|
19 | } | |||
|
20 | return ret.substring(0, ret.length-1); | |||
|
21 | } | |||
|
22 | ||||
|
23 | ||||
|
24 | function str2int(s){ | |||
|
25 | var ret = ""; | |||
|
26 | values = s.split(","); | |||
|
27 | for (i=0; i<values.length; i++) { | |||
|
28 | ret += Math.round(parseFloat(values[i])); | |||
18 | ret += ","; |
|
29 | ret += ","; | |
19 | } |
|
30 | } | |
20 | return ret.substring(0, ret.length-1); |
|
31 | return ret.substring(0, ret.length-1); | |
@@ -58,6 +69,44 function updateDc() { | |||||
58 | } |
|
69 | } | |
59 |
|
70 | |||
60 |
|
71 | |||
|
72 | function updateWindows(label) { | |||
|
73 | ||||
|
74 | if (label.indexOf("first_height")>0){ | |||
|
75 | llabel = label.replace("first_height", "last_height"); | |||
|
76 | rlabel = label.replace("first_height", "resolution"); | |||
|
77 | nlabel = label.replace("first_height", "number_of_samples"); | |||
|
78 | value = parseFloat($(label).val())+parseFloat($(rlabel).val())*(parseInt($(nlabel).val())-1); | |||
|
79 | $(llabel).val(value); | |||
|
80 | } | |||
|
81 | ||||
|
82 | if (label.indexOf("resolution")>0){ | |||
|
83 | llabel = label.replace("resolution", "last_height"); | |||
|
84 | flabel = label.replace("resolution", "first_height"); | |||
|
85 | nlabel = label.replace("resolution", "number_of_samples"); | |||
|
86 | value = parseFloat($(flabel).val())+parseFloat($(label).val())*(parseInt($(nlabel).val())-1); | |||
|
87 | $(llabel).val(value); | |||
|
88 | } | |||
|
89 | ||||
|
90 | if (label.indexOf("number_of_samples")>0){ | |||
|
91 | llabel = label.replace("number_of_samples", "last_height"); | |||
|
92 | rlabel = label.replace("number_of_samples", "resolution"); | |||
|
93 | flabel = label.replace("number_of_samples", "first_height"); | |||
|
94 | value = parseFloat($(flabel).val())+parseFloat($(rlabel).val())*(parseInt($(label).val())-1); | |||
|
95 | $(llabel).val(value); | |||
|
96 | } | |||
|
97 | ||||
|
98 | if (label.indexOf("last_height")>0){ | |||
|
99 | flabel = label.replace("last_height", "first_height"); | |||
|
100 | rlabel = label.replace("last_height", "resolution"); | |||
|
101 | nlabel = label.replace("last_height", "number_of_samples"); | |||
|
102 | ||||
|
103 | nvalue = Math.round((parseFloat($(label).val())-parseFloat($(flabel).val()))/parseFloat($(rlabel).val()))+1; | |||
|
104 | $(nlabel).val(nvalue); | |||
|
105 | value = parseFloat($(flabel).val())+parseFloat($(rlabel).val())*(nvalue-1); | |||
|
106 | $(label).val(value); | |||
|
107 | } | |||
|
108 | ||||
|
109 | } | |||
61 |
|
110 | |||
62 | $("#id_clock_in").change(function() { |
|
111 | $("#id_clock_in").change(function() { | |
63 | $("#id_clock").val(parseFloat($('#id_clock_in').val())/parseFloat($('#id_clock_divider').val())); |
|
112 | $("#id_clock").val(parseFloat($('#id_clock_in').val())/parseFloat($('#id_clock_divider').val())); |
@@ -10,9 +10,18 | |||||
10 | {% block extra-content %} |
|
10 | {% block extra-content %} | |
11 |
|
11 | |||
12 | <div class="clearfix"></div> |
|
12 | <div class="clearfix"></div> | |
13 |
<h2>RC Lines</h2> |
|
13 | <h2>RC Lines</h2> | |
|
14 | <hr> | |||
14 | <div class="panel-group" id="div_lines" role="tablist" aria-multiselectable="true"> |
|
15 | <div class="panel-group" id="div_lines" role="tablist" aria-multiselectable="true"> | |
15 | {% include "rc_lines.html" %} |
|
16 | {% include "rc_lines.html" %} | |
16 | </div> |
|
17 | </div> | |
17 |
|
18 | |||
18 | {% endblock extra-content%} |
|
19 | {% endblock extra-content%} | |
|
20 | ||||
|
21 | {% block extra-js%} | |||
|
22 | <script type="text/javascript"> | |||
|
23 | $("#bt_toggle").click(function() { | |||
|
24 | $(".panel-collapse").collapse('toggle') | |||
|
25 | }); | |||
|
26 | </script> | |||
|
27 | {% endblock %} No newline at end of file |
@@ -68,6 +68,10 | |||||
68 | } |
|
68 | } | |
69 | }); |
|
69 | }); | |
70 |
|
70 | |||
|
71 | $("#bt_toggle").click(function() { | |||
|
72 | $(".panel-collapse").collapse('toggle') | |||
|
73 | }); | |||
|
74 | ||||
71 | </script> |
|
75 | </script> | |
72 | {% endblock %} |
|
76 | {% endblock %} | |
73 | No newline at end of file |
|
77 |
@@ -1,5 +1,7 | |||||
1 | {% load bootstrap3 %} |
|
1 | {% load bootstrap3 %} | |
2 |
|
2 | <div class="pull-right"><button id="bt_toggle" type="button" class="btn btn-default btn-sm" > | ||
|
3 | Expand/Collapse | |||
|
4 | </button></div><br><br> | |||
3 | {% for line in rc_lines %} |
|
5 | {% for line in rc_lines %} | |
4 | <div class="panel panel-default" id="panel-{{line.id}}"> |
|
6 | <div class="panel panel-default" id="panel-{{line.id}}"> | |
5 | <div class="panel-heading" role="tab" id="heading{{line.id}}"> |
|
7 | <div class="panel-heading" role="tab" id="heading{{line.id}}"> |
@@ -8,17 +8,55 | |||||
8 | {% endblock %} |
|
8 | {% endblock %} | |
9 |
|
9 | |||
10 | {% block content %} |
|
10 | {% block content %} | |
|
11 | ||||
11 | <div id="div_plot">{{div}}</div> |
|
12 | <div id="div_plot">{{div}}</div> | |
12 | <br> |
|
13 | <br> | |
13 | <div class="col-md-2">1 Km =</div><div class="col-md-3">{{units}} Units</div> |
|
14 | ||
14 | <br> |
|
15 | <form class="form-horizontal"> | |
15 | <div class="col-md-2">1 Unit=</div><div class="col-md-3">{{kms}} Km</div> |
|
16 | <div class="form-group"> | |
|
17 | <label class="col-sm-2 control-label">Axis</label> | |||
|
18 | <div class="col-sm-4"> | |||
|
19 | <select class="form-control" id='id_axis'> | |||
|
20 | <option value=0>Units</option> | |||
|
21 | {%if km_selected %} | |||
|
22 | <option value=1 selected>Km</option> | |||
|
23 | {%else%} | |||
|
24 | <option value=1>Km</option> | |||
|
25 | {%endif%} | |||
|
26 | </select> | |||
|
27 | </div> | |||
|
28 | </div> | |||
|
29 | <div class="form-group"> | |||
|
30 | <label class="col-sm-2 control-label">1 Km</label> | |||
|
31 | <div class="col-sm-4"> | |||
|
32 | <p class="form-control-static">{{units}} Units</p> | |||
|
33 | </div> | |||
|
34 | </div> | |||
|
35 | <div class="form-group"> | |||
|
36 | <label class="col-sm-2 control-label">1 Unit</label> | |||
|
37 | <div class="col-sm-4"> | |||
|
38 | <p class="form-control-static">{{kms}} Km</p> | |||
|
39 | </div> | |||
|
40 | </div> | |||
|
41 | </form> | |||
|
42 | ||||
16 | {% endblock %} |
|
43 | {% endblock %} | |
17 |
|
44 | |||
18 | {% block extra-js%} |
|
45 | {% block extra-js%} | |
19 |
|
46 | |||
20 | <script src="{% static 'js/bokeh-0.11.1.min.js' %}"></script> |
|
47 | <script src="{% static 'js/bokeh-0.11.1.min.js' %}"></script> | |
21 |
|
48 | |||
|
49 | <script type="text/javascript"> | |||
|
50 | ||||
|
51 | $("#id_axis").change(function() { | |||
|
52 | if($(this).val()=='0'){ | |||
|
53 | document.location = '?unit'; | |||
|
54 | }else{ | |||
|
55 | document.location = '?km' | |||
|
56 | } | |||
|
57 | }); | |||
|
58 | ||||
|
59 | </script> | |||
22 | {{script}} |
|
60 | {{script}} | |
23 |
|
61 | |||
24 | {% endblock %} No newline at end of file |
|
62 | {% endblock %} |
@@ -145,8 +145,10 class RCFile(object): | |||||
145 | windows = [] |
|
145 | windows = [] | |
146 | for w in range(int(data['Sampling Windows (Line %d)' % n])): |
|
146 | for w in range(int(data['Sampling Windows (Line %d)' % n])): | |
147 | windows.append({'first_height':float(data['L%d_H0(%d)' % (n, w)]), |
|
147 | windows.append({'first_height':float(data['L%d_H0(%d)' % (n, w)]), | |
|
148 | 'resolution':float(data['L%d_DH(%d)' % (n, w)]), | |||
148 | 'number_of_samples':int(data['L%d_NSA(%d)' % (n, w)]), |
|
149 | 'number_of_samples':int(data['L%d_NSA(%d)' % (n, w)]), | |
149 | 'resolution':float(data['L%d_DH(%d)' % (n, w)])} |
|
150 | 'last_height':float(data['L%d_DH(%d)' % (n, w)])*(int(data['L%d_NSA(%d)' % (n, w)])-1)+float(data['L%d_H0(%d)' % (n, w)]) | |
|
151 | } | |||
150 | ) |
|
152 | ) | |
151 | line['params'] = windows |
|
153 | line['params'] = windows | |
152 | elif 'Line%d' % n in labels and data['Line%d' % n]=='Synchro': |
|
154 | elif 'Line%d' % n in labels and data['Line%d' % n]=='Synchro': | |
@@ -184,7 +186,8 class RCFile(object): | |||||
184 | dh = raw_data[x+3+3*w].split('=')[-1] |
|
186 | dh = raw_data[x+3+3*w].split('=')[-1] | |
185 | windows.append({'first_height':float(h0), |
|
187 | windows.append({'first_height':float(h0), | |
186 | 'number_of_samples':int(nsa), |
|
188 | 'number_of_samples':int(nsa), | |
187 |
'resolution':float(dh) |
|
189 | 'resolution':float(dh), | |
|
190 | 'last_height':float(h0)+float(dh)*(int(nsa)-1)} | |||
188 | ) |
|
191 | ) | |
189 | line['params'] = windows |
|
192 | line['params'] = windows | |
190 | self.data['lines'].append(line) |
|
193 | self.data['lines'].append(line) |
@@ -330,6 +330,7 def import_file(request, conf_id): | |||||
330 | form = RCImportForm(request.POST, request.FILES) |
|
330 | form = RCImportForm(request.POST, request.FILES) | |
331 | if form.is_valid(): |
|
331 | if form.is_valid(): | |
332 | try: |
|
332 | try: | |
|
333 | #if True: | |||
333 | conf.update_from_file(request.FILES['file_name']) |
|
334 | conf.update_from_file(request.FILES['file_name']) | |
334 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) |
|
335 | messages.success(request, 'Configuration "%s" loaded succesfully' % request.FILES['file_name']) | |
335 | return redirect(conf.get_absolute_url_edit()) |
|
336 | return redirect(conf.get_absolute_url_edit()) | |
@@ -354,18 +355,22 def import_file(request, conf_id): | |||||
354 | def plot_pulses(request, conf_id): |
|
355 | def plot_pulses(request, conf_id): | |
355 |
|
356 | |||
356 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
357 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
357 |
|
358 | km = True if 'km' in request.GET else False | ||
358 | script, div = conf.plot_pulses() |
|
359 | ||
|
360 | script, div = conf.plot_pulses(km=km) | |||
359 |
|
361 | |||
360 | kwargs = {} |
|
362 | kwargs = {} | |
361 |
|
363 | |||
362 | kwargs['title'] = 'RC Pulses' |
|
364 | kwargs['title'] = 'RC Pulses' | |
363 | kwargs['suptitle'] = conf.name |
|
365 | kwargs['suptitle'] = conf.name | |
364 | kwargs['div'] = mark_safe(div) |
|
366 | kwargs['div'] = mark_safe(div) | |
365 | kwargs['script'] = mark_safe(script) |
|
367 | kwargs['script'] = mark_safe(script) | |
366 | kwargs['units'] = conf.km2unit |
|
368 | kwargs['units'] = conf.km2unit | |
367 | kwargs['kms'] = 1/conf.km2unit |
|
369 | kwargs['kms'] = 1/conf.km2unit | |
368 |
|
370 | |||
|
371 | if km: | |||
|
372 | kwargs['km_selected'] = True | |||
|
373 | ||||
369 | if 'json' in request.GET: |
|
374 | if 'json' in request.GET: | |
370 | return HttpResponse(json.dumps({'div':mark_safe(div), 'script':mark_safe(script)}), content_type="application/json") |
|
375 | return HttpResponse(json.dumps({'div':mark_safe(div), 'script':mark_safe(script)}), content_type="application/json") | |
371 | else: |
|
376 | else: |
@@ -31,7 +31,7 class KmUnitWidget(forms.widgets.TextInput): | |||||
31 | input_type = 'number' |
|
31 | input_type = 'number' | |
32 |
|
32 | |||
33 | if 'line' in attrs: |
|
33 | if 'line' in attrs: | |
34 | label += '_{0}'.format(attrs['line'].pk) |
|
34 | label += '_{0}_{1}'.format(attrs['line'].pk, name.split('|')[0]) | |
35 |
|
35 | |||
36 | html = '''<div class="col-md-12 col-no-padding"> |
|
36 | html = '''<div class="col-md-12 col-no-padding"> | |
37 | <div class="col-md-5 col-no-padding"><input type="{0}" step="any" {1} class="form-control" id="id_{2}" name="{3}" value="{4}"></div> |
|
37 | <div class="col-md-5 col-no-padding"><input type="{0}" step="any" {1} class="form-control" id="id_{2}" name="{3}" value="{4}"></div> | |
@@ -48,13 +48,15 class KmUnitWidget(forms.widgets.TextInput): | |||||
48 | $("#id_{label}").change(function() {{ |
|
48 | $("#id_{label}").change(function() {{ | |
49 | $("#id_{label}_unit").val(str2unit($(this).val())); |
|
49 | $("#id_{label}_unit").val(str2unit($(this).val())); | |
50 | $("#id_{label}").val(str2km($("#id_{label}_unit").val())); |
|
50 | $("#id_{label}").val(str2km($("#id_{label}_unit").val())); | |
|
51 | updateWindows("#id_{label}"); | |||
51 | }}); |
|
52 | }}); | |
52 | $("#id_{label}_unit").change(function() {{ |
|
53 | $("#id_{label}_unit").change(function() {{ | |
53 |
$(this).val( |
|
54 | $(this).val(str2int($(this).val())); | |
54 | $("#id_{label}").val(str2km($(this).val())); |
|
55 | $("#id_{label}").val(str2km($(this).val())); | |
|
56 | updateWindows("#id_{label}"); | |||
55 | }}); |
|
57 | }}); | |
56 | }}); |
|
58 | }}); | |
57 | </script>'''.format(label=label) |
|
59 | </script>'''.format(label=label) | |
58 |
|
60 | |||
59 | if disabled: |
|
61 | if disabled: | |
60 | return mark_safe(html) |
|
62 | return mark_safe(html) | |
@@ -80,7 +82,7 class UnitKmWidget(forms.widgets.TextInput): | |||||
80 | name = attrs.get('name', label) |
|
82 | name = attrs.get('name', label) | |
81 |
|
83 | |||
82 | if 'line' in attrs: |
|
84 | if 'line' in attrs: | |
83 | label += '_{0}'.format(attrs['line'].pk) |
|
85 | label += '_{0}_{1}'.format(attrs['line'].pk, name.split('|')[0]) | |
84 |
|
86 | |||
85 | html = '''<div class="col-md-12 col-no-padding"> |
|
87 | html = '''<div class="col-md-12 col-no-padding"> | |
86 | <div class="col-md-5 col-no-padding"><input type="number" {0} class="form-control" id="id_{1}_unit" name="{2}" value="{3}"></div> |
|
88 | <div class="col-md-5 col-no-padding"><input type="number" {0} class="form-control" id="id_{1}_unit" name="{2}" value="{3}"></div> | |
@@ -139,6 +141,7 class KmUnitHzWidget(forms.widgets.TextInput): | |||||
139 | unit_fields.push("id_{label}_unit"); |
|
141 | unit_fields.push("id_{label}_unit"); | |
140 | $("#id_{label}").change(function() {{ |
|
142 | $("#id_{label}").change(function() {{ | |
141 | $("#id_{label}_unit").val(str2unit($(this).val())); |
|
143 | $("#id_{label}_unit").val(str2unit($(this).val())); | |
|
144 | $("#id_{label}").val(str2km($("#id_{label}_unit").val())); | |||
142 | $("#id_{label}_hz").val(str2hz($(this).val())); |
|
145 | $("#id_{label}_hz").val(str2hz($(this).val())); | |
143 | updateDc(); |
|
146 | updateDc(); | |
144 | }}); |
|
147 | }}); | |
@@ -191,6 +194,7 class KmUnitDcWidget(forms.widgets.TextInput): | |||||
191 | dc_fields.push("id_{label}"); |
|
194 | dc_fields.push("id_{label}"); | |
192 | $("#id_{label}").change(function() {{ |
|
195 | $("#id_{label}").change(function() {{ | |
193 | $("#id_{label}_unit").val(str2unit($(this).val())); |
|
196 | $("#id_{label}_unit").val(str2unit($(this).val())); | |
|
197 | $("#id_{label}").val(str2km($("#id_{label}_unit").val())); | |||
194 | $("#id_{label}_dc").val(str2dc($("#id_{label}").val())); |
|
198 | $("#id_{label}_dc").val(str2dc($("#id_{label}").val())); | |
195 | }}); |
|
199 | }}); | |
196 | $("#id_{label}_unit").change(function() {{ |
|
200 | $("#id_{label}_unit").change(function() {{ | |
@@ -216,9 +220,31 class DefaultWidget(forms.widgets.TextInput): | |||||
216 | def render(self, label, value, attrs=None): |
|
220 | def render(self, label, value, attrs=None): | |
217 |
|
221 | |||
218 | disabled = 'disabled' if attrs.get('disabled', False) else '' |
|
222 | disabled = 'disabled' if attrs.get('disabled', False) else '' | |
|
223 | itype = 'number' if label in ('number_of_samples', 'last_height') else 'text' | |||
219 | name = attrs.get('name', label) |
|
224 | name = attrs.get('name', label) | |
|
225 | if 'line' in attrs: | |||
|
226 | label += '_{0}_{1}'.format(attrs['line'].pk, name.split('|')[0]) | |||
|
227 | html = '<div class="col-md-12 col-no-padding"><div class="col-md-5 col-no-padding"><input {0} type="{1}" class="form-control" id="id_{2}" name="{3}" value="{4}"></div></div>'.format(disabled, itype, label, name, value) | |||
|
228 | ||||
|
229 | if 'last_height' in label or 'number_of_samples' in label: | |||
|
230 | script = '''<script type="text/javascript"> | |||
|
231 | $(document).ready(function () {{ | |||
|
232 | ||||
|
233 | $("#id_{label}").change(function() {{ | |||
|
234 | updateWindows("#id_{label}"); | |||
|
235 | }}); | |||
|
236 | ||||
|
237 | }}); | |||
|
238 | </script>'''.format(label=label) | |||
|
239 | else: | |||
|
240 | script = '' | |||
|
241 | ||||
|
242 | if disabled: | |||
|
243 | return mark_safe(html) | |||
|
244 | else: | |||
|
245 | return mark_safe(html+script) | |||
|
246 | ||||
220 |
|
247 | |||
221 | html = '<div class="col-md-12 col-no-padding"><div class="col-md-5 col-no-padding"><input {0} type="text" class="form-control" id="id_{1}" name="{2}" value="{3}"></div></div>'.format(disabled, label, name, value) |
|
|||
222 |
|
248 | |||
223 | return mark_safe(html) |
|
249 | return mark_safe(html) | |
224 |
|
250 |
@@ -35,6 +35,8 CMD_ECHO =0XFE | |||||
35 | RC_CMD_RESET =0X10 |
|
35 | RC_CMD_RESET =0X10 | |
36 | RC_CMD_WRITE =0x50 |
|
36 | RC_CMD_WRITE =0x50 | |
37 | RC_CMD_READ =0x8000 |
|
37 | RC_CMD_READ =0x8000 | |
|
38 | RC_CMD_ENABLE =0X24 | |||
|
39 | RC_CMD_DISABLE =0X00 | |||
38 |
|
40 | |||
39 | @eth_device(ID_CLASS) |
|
41 | @eth_device(ID_CLASS) | |
40 | def reset(): |
|
42 | def reset(): | |
@@ -69,16 +71,32 def echo(): | |||||
69 | return cmd, payload |
|
71 | return cmd, payload | |
70 |
|
72 | |||
71 | @eth_device(ID_CLASS) |
|
73 | @eth_device(ID_CLASS) | |
|
74 | def enable(): | |||
|
75 | ||||
|
76 | cmd = RC_CMD_ENABLE | |||
|
77 | payload = chr(0x01) | |||
|
78 | ||||
|
79 | return cmd, payload | |||
|
80 | ||||
|
81 | @eth_device(ID_CLASS) | |||
|
82 | def disable(): | |||
|
83 | ||||
|
84 | cmd = RC_CMD_DISABLE | |||
|
85 | payload = chr(0x00) | |||
|
86 | ||||
|
87 | return cmd, payload | |||
|
88 | ||||
|
89 | @eth_device(ID_CLASS) | |||
72 | def read_all_device(): |
|
90 | def read_all_device(): | |
73 |
|
91 | |||
74 | payload = "" |
|
92 | payload = "" | |
75 |
|
93 | |||
76 |
return |
|
94 | return RC_CMD_READ, payload | |
77 |
|
95 | |||
78 | @eth_device(ID_CLASS) |
|
96 | @eth_device(ID_CLASS) | |
79 | def write_all_device(payload): |
|
97 | def write_all_device(payload): | |
80 |
|
98 | |||
81 |
return |
|
99 | return RC_CMD_WRITE, payload | |
82 |
|
100 | |||
83 | def read_config(ip, port): |
|
101 | def read_config(ip, port): | |
84 | """ |
|
102 | """ | |
@@ -99,7 +117,7 def write_config(ip, port, parms): | |||||
99 |
|
117 | |||
100 | """ |
|
118 | """ | |
101 |
|
119 | |||
102 | payload = data.dict_to_rc_str(parms) |
|
120 | payload = write_ram_memory(parms['pulses'], parms['delays']) | |
103 |
|
121 | |||
104 | answer = write_all_device(ip, port, payload) |
|
122 | answer = write_all_device(ip, port, payload) | |
105 |
|
123 | |||
@@ -107,13 +125,13 def write_config(ip, port, parms): | |||||
107 |
|
125 | |||
108 | def __get_low_byte(valor): |
|
126 | def __get_low_byte(valor): | |
109 |
|
127 | |||
110 | return ord(valor & 0x00FF) |
|
128 | return ord(valor & 0x00FF) | |
111 |
|
129 | |||
112 | def __get_high_byte(valor): |
|
130 | def __get_high_byte(valor): | |
113 |
|
131 | |||
114 | return ord((valor & 0xFF00) >> 8) |
|
132 | return ord((valor & 0xFF00) >> 8) | |
|
133 | ||||
115 |
|
134 | |||
116 | @eth_device(ID_CLASS) |
|
|||
117 | def write_ram_memory(vector_valores, vector_tiempos): |
|
135 | def write_ram_memory(vector_valores, vector_tiempos): | |
118 |
|
136 | |||
119 | l1 = len(vector_valores) |
|
137 | l1 = len(vector_valores) | |
@@ -122,10 +140,10 def write_ram_memory(vector_valores, vector_tiempos): | |||||
122 | cad = "" |
|
140 | cad = "" | |
123 |
|
141 | |||
124 | for i in range(l1): |
|
142 | for i in range(l1): | |
125 | cad += ord(84) + __get_low_byte(vector_valores[i]) + ord(85) + __get_high_byte(vector_valores[i]) + \ |
|
143 | cad += ord(84) + __get_low_byte(vector_valores[i]) + ord(85) + __get_high_byte(vector_valores[i]) + \ | |
126 | ord(84) + __get_low_byte(vector_tiempos[i]) + ord(85) + __get_high_byte(vector_tiempos[i]) |
|
144 | ord(84) + __get_low_byte(vector_tiempos[i]) + ord(85) + __get_high_byte(vector_tiempos[i]) | |
127 |
|
145 | |||
128 |
return |
|
146 | return cad | |
129 |
|
147 | |||
130 | if __name__ == '__main__': |
|
148 | if __name__ == '__main__': | |
131 | ip = "10.10.20.150" |
|
149 | ip = "10.10.20.150" |
General Comments 0
You need to be logged in to leave comments.
Login now