@@ -1,36 +1,31 | |||||
1 | from django import forms |
|
1 | 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 | EXT_TYPES = ( |
|
|||
8 | ('dds', '.dds'), |
|
|||
9 | ('json', '.json'), |
|
|||
10 | ) |
|
|||
11 |
|
||||
12 | class DDSConfigurationForm(forms.ModelForm): |
|
7 | class DDSConfigurationForm(forms.ModelForm): | |
13 |
|
8 | |||
14 | def __init__(self, *args, **kwargs): |
|
9 | def __init__(self, *args, **kwargs): | |
15 | #request = kwargs.pop('request') |
|
10 | #request = kwargs.pop('request') | |
16 | super(DDSConfigurationForm, self).__init__(*args, **kwargs) |
|
11 | super(DDSConfigurationForm, self).__init__(*args, **kwargs) | |
17 |
|
12 | |||
18 | instance = getattr(self, 'instance', None) |
|
13 | instance = getattr(self, 'instance', None) | |
19 |
|
14 | |||
20 | if instance and instance.pk: |
|
15 | if instance and instance.pk: | |
21 |
|
16 | |||
22 | devices = Device.objects.filter(device_type__name='dds') |
|
17 | devices = Device.objects.filter(device_type__name='dds') | |
23 |
|
18 | |||
24 | self.fields['experiment'].widget.attrs['readonly'] = True |
|
19 | self.fields['experiment'].widget.attrs['readonly'] = True | |
25 | self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] |
|
20 | self.fields['experiment'].widget.choices = [(instance.experiment.id, instance.experiment)] | |
26 |
|
21 | |||
27 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
22 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |
28 |
|
23 | |||
29 |
|
24 | # | ||
30 | def clean(self): |
|
25 | # def clean(self): | |
31 | # Custom validation to force an integer when type of unit = "Unit" |
|
26 | # # Custom validation to force an integer when type of unit = "Unit" | |
32 | return |
|
27 | # return | |
33 |
|
28 | |||
34 | class Meta: |
|
29 | class Meta: | |
35 | model = DDSConfiguration |
|
30 | model = DDSConfiguration | |
36 | exclude = ('type', 'parameters', 'status') No newline at end of file |
|
31 | exclude = ('type', 'parameters', 'status') |
@@ -1,203 +1,228 | |||||
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 | # 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 | from django.core.exceptions import ValidationError | |
7 |
|
7 | |||
8 |
from devices.dds import api, data |
|
8 | from devices.dds import api, data | |
9 |
|
9 | |||
10 | ENABLE_TYPE = ( |
|
10 | ENABLE_TYPE = ( | |
11 | (False, 'Disabled'), |
|
11 | (False, 'Disabled'), | |
12 | (True, 'Enabled'), |
|
12 | (True, 'Enabled'), | |
13 | ) |
|
13 | ) | |
14 | MOD_TYPES = ( |
|
14 | MOD_TYPES = ( | |
15 | (0, 'Single Tone'), |
|
15 | (0, 'Single Tone'), | |
16 | (1, 'FSK'), |
|
16 | (1, 'FSK'), | |
17 | (2, 'Ramped FSK'), |
|
17 | (2, 'Ramped FSK'), | |
18 | (3, 'Chirp'), |
|
18 | (3, 'Chirp'), | |
19 | (4, 'BPSK'), |
|
19 | (4, 'BPSK'), | |
20 | ) |
|
20 | ) | |
21 |
|
21 | |||
22 | class DDSConfiguration(Configuration): |
|
22 | class DDSConfiguration(Configuration): | |
23 |
|
23 | |||
24 | DDS_NBITS = 48 |
|
24 | DDS_NBITS = 48 | |
25 |
|
25 | |||
26 | clock = models.FloatField(verbose_name='Clock Input (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True) |
|
26 | clock = models.FloatField(verbose_name='Clock Input (MHz)',validators=[MinValueValidator(5), MaxValueValidator(75)], null=True) | |
27 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) |
|
27 | multiplier = models.PositiveIntegerField(verbose_name='Multiplier',validators=[MinValueValidator(1), MaxValueValidator(20)], default=4) | |
28 |
|
28 | |||
29 | frequencyA_Mhz = models.DecimalField(verbose_name='Frequency A (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, null=True) |
|
29 | frequencyA_Mhz = models.DecimalField(verbose_name='Frequency A (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, null=True) | |
30 | frequencyA = models.BigIntegerField(verbose_name='Frequency A (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], null=True) |
|
30 | frequencyA = models.BigIntegerField(verbose_name='Frequency A (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], null=True) | |
31 |
|
31 | |||
32 | frequencyB_Mhz = models.DecimalField(verbose_name='Frequency B (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, blank=True, null=True) |
|
32 | frequencyB_Mhz = models.DecimalField(verbose_name='Frequency B (MHz)', validators=[MinValueValidator(0), MaxValueValidator(150)], max_digits=19, decimal_places=16, blank=True, null=True) | |
33 | frequencyB = models.BigIntegerField(verbose_name='Frequency B (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) |
|
33 | frequencyB = models.BigIntegerField(verbose_name='Frequency B (Decimal)',validators=[MinValueValidator(0), MaxValueValidator(2**DDS_NBITS-1)], blank=True, null=True) | |
34 |
|
34 | |||
35 | phaseB_degrees = models.FloatField(verbose_name='Phase B (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True) |
|
|||
36 |
|
||||
37 | phaseA_degrees = models.FloatField(verbose_name='Phase A (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], default=0) |
|
35 | phaseA_degrees = models.FloatField(verbose_name='Phase A (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], default=0) | |
38 |
|
36 | |||
|
37 | phaseB_degrees = models.FloatField(verbose_name='Phase B (Degrees)', validators=[MinValueValidator(0), MaxValueValidator(360)], blank=True, null=True) | |||
|
38 | ||||
39 | modulation = models.PositiveIntegerField(verbose_name='Modulation Type', choices = MOD_TYPES, default = 0) |
|
39 | modulation = models.PositiveIntegerField(verbose_name='Modulation Type', choices = MOD_TYPES, default = 0) | |
40 |
|
40 | |||
41 | amplitude_enabled = models.BooleanField(verbose_name='Amplitude Control', choices=ENABLE_TYPE, default=False) |
|
41 | amplitude_enabled = models.BooleanField(verbose_name='Amplitude Control', choices=ENABLE_TYPE, default=False) | |
42 |
|
42 | |||
43 | amplitudeI = models.PositiveIntegerField(verbose_name='Amplitude CH1',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) |
|
43 | amplitudeI = models.PositiveIntegerField(verbose_name='Amplitude CH1',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) | |
44 | amplitudeQ = models.PositiveIntegerField(verbose_name='Amplitude CH2',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) |
|
44 | amplitudeQ = models.PositiveIntegerField(verbose_name='Amplitude CH2',validators=[MinValueValidator(0), MaxValueValidator(2**12-1)], blank=True, null=True) | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | def get_nbits(self): |
|
47 | def get_nbits(self): | |
48 |
|
48 | |||
49 | return self.DDS_NBITS |
|
49 | return self.DDS_NBITS | |
50 |
|
50 | |||
51 | def clean(self): |
|
51 | def clean(self): | |
52 |
|
52 | |||
53 | if self.modulation in [1,2,3]: |
|
53 | if self.modulation in [1,2,3]: | |
54 | if self.frequencyB is None or self.frequencyB_Mhz is None: |
|
54 | if self.frequencyB is None or self.frequencyB_Mhz is None: | |
55 | raise ValidationError({ |
|
55 | raise ValidationError({ | |
56 | 'frequencyB': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected' |
|
56 | 'frequencyB': 'Frequency modulation has to be defined when FSK or Chirp modulation is selected' | |
57 | }) |
|
57 | }) | |
58 |
|
58 | |||
59 | if self.modulation in [4,]: |
|
59 | if self.modulation in [4,]: | |
60 | if self.phaseB_degrees is None: |
|
60 | if self.phaseB_degrees is None: | |
61 | raise ValidationError({ |
|
61 | raise ValidationError({ | |
62 | 'phaseB': 'Phase modulation has to be defined when BPSK modulation is selected' |
|
62 | 'phaseB': 'Phase modulation has to be defined when BPSK modulation is selected' | |
63 | }) |
|
63 | }) | |
64 |
|
64 | |||
|
65 | self.frequencyA_Mhz = data.binary_to_freq(self.frequencyA, self.clock*self.multiplier) | |||
|
66 | self.frequencyB_Mhz = data.binary_to_freq(self.frequencyB, self.clock*self.multiplier) | |||
|
67 | ||||
65 | def verify_frequencies(self): |
|
68 | def verify_frequencies(self): | |
66 |
|
69 | |||
67 | return True |
|
70 | return True | |
68 |
|
71 | |||
69 | def parms_to_dict(self): |
|
72 | def parms_to_dict(self): | |
70 |
|
73 | |||
71 | parameters = {} |
|
74 | parameters = {} | |
72 |
|
75 | |||
73 | parameters['clock'] = float(self.clock) |
|
76 | parameters['clock'] = float(self.clock) | |
74 | parameters['multiplier'] = int(self.multiplier) |
|
77 | parameters['multiplier'] = int(self.multiplier) | |
|
78 | ||||
75 | parameters['frequencyA'] = int(self.frequencyA) |
|
79 | parameters['frequencyA'] = int(self.frequencyA) | |
76 |
parameters['frequency |
|
80 | parameters['frequencyA_Mhz'] = float(self.frequencyA_Mhz) | |
|
81 | ||||
77 | parameters['phaseA'] = data.phase_to_binary(self.phaseA_degrees) |
|
82 | parameters['phaseA'] = data.phase_to_binary(self.phaseA_degrees) | |
78 | parameters['phaseB'] = data.phase_to_binary(self.phaseB_degrees) |
|
|||
79 | parameters['frequencyA_Mhz'] = int(self.frequencyA_Mhz) |
|
|||
80 | parameters['frequencyB_Mhz'] = int(self.frequencyB_Mhz) |
|
|||
81 | parameters['phaseA_degrees'] = float(self.phaseA_degrees) |
|
83 | parameters['phaseA_degrees'] = float(self.phaseA_degrees) | |
82 | parameters['phaseB_degrees'] = float(self.phaseB_degrees) |
|
84 | ||
83 | parameters['modulation'] = int(self.modulation) |
|
85 | parameters['modulation'] = int(self.modulation) | |
84 |
parameters['amplitude_enabled'] = |
|
86 | parameters['amplitude_enabled'] = bool(self.amplitude_enabled) | |
|
87 | ||||
|
88 | if self.frequencyB: | |||
|
89 | parameters['frequencyB'] = int(self.frequencyB) | |||
|
90 | parameters['frequencyB_Mhz'] = float(self.frequencyB_Mhz) | |||
|
91 | else: | |||
|
92 | parameters['frequencyB'] = 0 | |||
|
93 | parameters['frequencyB_Mhz'] = 0 | |||
85 |
|
94 | |||
|
95 | if self.phaseB_degrees: | |||
|
96 | parameters['phaseB_degrees'] = float(self.phaseB_degrees) | |||
|
97 | parameters['phaseB'] = data.phase_to_binary(self.phaseB_degrees) | |||
|
98 | else: | |||
|
99 | parameters['phaseB_degrees'] = 0 | |||
|
100 | parameters['phaseB'] = 0 | |||
|
101 | ||||
86 | if self.amplitudeI: |
|
102 | if self.amplitudeI: | |
87 | parameters['amplitudeI'] = int(self.amplitudeI) |
|
103 | parameters['amplitudeI'] = int(self.amplitudeI) | |
88 | else: |
|
104 | else: | |
89 | parameters['amplitudeI'] = 0 |
|
105 | parameters['amplitudeI'] = 0 | |
90 |
|
106 | |||
91 | if self.amplitudeQ: |
|
107 | if self.amplitudeQ: | |
92 | parameters['amplitudeQ'] = int(self.amplitudeQ) |
|
108 | parameters['amplitudeQ'] = int(self.amplitudeQ) | |
93 | else: |
|
109 | else: | |
94 | parameters['amplitudeQ'] = 0 |
|
110 | parameters['amplitudeQ'] = 0 | |
95 |
|
111 | |||
96 | return parameters |
|
112 | return parameters | |
97 |
|
113 | |||
|
114 | def parms_to_text(self): | |||
|
115 | ||||
|
116 | my_dict = self.parms_to_dict() | |||
|
117 | ||||
|
118 | text = data.dict_to_text(my_dict) | |||
|
119 | ||||
|
120 | return text | |||
|
121 | ||||
98 | def dict_to_parms(self, parameters): |
|
122 | def dict_to_parms(self, parameters): | |
99 |
|
123 | |||
100 | self.clock = parameters['clock'] |
|
124 | self.clock = parameters['clock'] | |
101 | self.multiplier = parameters['multiplier'] |
|
125 | self.multiplier = parameters['multiplier'] | |
102 | self.frequencyA = parameters['frequencyA'] |
|
126 | self.frequencyA = parameters['frequencyA'] | |
103 | self.frequencyB = parameters['frequencyB'] |
|
127 | self.frequencyB = parameters['frequencyB'] | |
104 | self.frequencyA_Mhz = parameters['frequencyA_Mhz'] |
|
128 | self.frequencyA_Mhz = parameters['frequencyA_Mhz'] | |
105 | self.frequencyB_Mhz = parameters['frequencyB_Mhz'] |
|
129 | self.frequencyB_Mhz = parameters['frequencyB_Mhz'] | |
106 | self.phaseA_degrees = parameters['phaseA_degrees'] |
|
130 | self.phaseA_degrees = parameters['phaseA_degrees'] | |
107 | self.phaseB_degrees = parameters['phaseB_degrees'] |
|
131 | self.phaseB_degrees = parameters['phaseB_degrees'] | |
108 | self.modulation = parameters['modulation'] |
|
132 | self.modulation = parameters['modulation'] | |
109 | self.amplitude_enabled = parameters['amplitude_enabled'] |
|
133 | self.amplitude_enabled = parameters['amplitude_enabled'] | |
110 |
|
134 | |||
111 | def import_from_file(self, fp): |
|
135 | def import_from_file(self, fp): | |
112 |
|
136 | |||
113 | import os |
|
137 | import os, json | |
114 |
|
138 | |||
115 | parms = {} |
|
139 | parms = {} | |
116 |
|
140 | |||
117 | path, ext = os.path.splitext(fp) |
|
141 | path, ext = os.path.splitext(fp.name) | |
118 |
|
142 | |||
119 | if ext == '.json': |
|
143 | if ext == '.json': | |
120 |
parms = |
|
144 | parms = json.load(fp) | |
121 |
|
145 | |||
122 | if ext == '.dds': |
|
146 | if ext == '.dds': | |
123 |
|
|
147 | lines = fp.readlines() | |
|
148 | parms = data.text_to_dict(lines) | |||
124 |
|
149 | |||
125 | return parms |
|
150 | return parms | |
126 |
|
151 | |||
127 | def status_device(self): |
|
152 | def status_device(self): | |
128 |
|
153 | |||
129 | answer = api.status(ip = self.device.ip_address, |
|
154 | answer = api.status(ip = self.device.ip_address, | |
130 | port = self.device.port_address) |
|
155 | port = self.device.port_address) | |
131 |
|
156 | |||
132 | self.device.status = int(answer[0]) |
|
157 | self.device.status = int(answer[0]) | |
133 | self.message = answer[2:] |
|
158 | self.message = answer[2:] | |
134 |
|
159 | |||
135 | self.device.save() |
|
160 | self.device.save() | |
136 |
|
161 | |||
137 | return self.device.status |
|
162 | return self.device.status | |
138 |
|
163 | |||
139 | def reset_device(self): |
|
164 | def reset_device(self): | |
140 |
|
165 | |||
141 | answer = api.reset(ip = self.device.ip_address, |
|
166 | answer = api.reset(ip = self.device.ip_address, | |
142 | port = self.device.port_address) |
|
167 | port = self.device.port_address) | |
143 |
|
168 | |||
144 | if answer[0] != "1": |
|
169 | if answer[0] != "1": | |
145 | self.message = answer[0:] |
|
170 | self.message = answer[0:] | |
146 | return 0 |
|
171 | return 0 | |
147 |
|
172 | |||
148 | self.message = answer[2:] |
|
173 | self.message = answer[2:] | |
149 | return 1 |
|
174 | return 1 | |
150 |
|
175 | |||
151 | def stop_device(self): |
|
176 | def stop_device(self): | |
152 |
|
177 | |||
153 | answer = api.disable_rf(ip = self.device.ip_address, |
|
178 | answer = api.disable_rf(ip = self.device.ip_address, | |
154 | port = self.device.port_address) |
|
179 | port = self.device.port_address) | |
155 |
|
180 | |||
156 | if answer[0] != "1": |
|
181 | if answer[0] != "1": | |
157 | self.message = answer[0:] |
|
182 | self.message = answer[0:] | |
158 | return 0 |
|
183 | return 0 | |
159 |
|
184 | |||
160 | self.message = answer[2:] |
|
185 | self.message = answer[2:] | |
161 | return 1 |
|
186 | return 1 | |
162 |
|
187 | |||
163 | def start_device(self): |
|
188 | def start_device(self): | |
164 |
|
189 | |||
165 | answer = api.enable_rf(ip = self.device.ip_address, |
|
190 | answer = api.enable_rf(ip = self.device.ip_address, | |
166 | port = self.device.port_address) |
|
191 | port = self.device.port_address) | |
167 |
|
192 | |||
168 | if answer[0] != "1": |
|
193 | if answer[0] != "1": | |
169 | self.message = answer[0:] |
|
194 | self.message = answer[0:] | |
170 | return 0 |
|
195 | return 0 | |
171 |
|
196 | |||
172 | self.message = answer[2:] |
|
197 | self.message = answer[2:] | |
173 | return 1 |
|
198 | return 1 | |
174 |
|
199 | |||
175 | def read_device(self): |
|
200 | def read_device(self): | |
176 |
|
201 | |||
177 | parms = api.read_config(ip = self.device.ip_address, |
|
202 | parms = api.read_config(ip = self.device.ip_address, | |
178 | port = self.device.port_address) |
|
203 | port = self.device.port_address) | |
179 |
|
204 | |||
180 | if not parms: |
|
205 | if not parms: | |
181 | self.message = "Could not read DDS parameters from this device" |
|
206 | self.message = "Could not read DDS parameters from this device" | |
182 | return parms |
|
207 | return parms | |
183 |
|
208 | |||
184 | self.message = "" |
|
209 | self.message = "" | |
185 | return parms |
|
210 | return parms | |
186 |
|
211 | |||
187 |
|
212 | |||
188 | def write_device(self): |
|
213 | def write_device(self): | |
189 |
|
214 | |||
190 | answer = api.write_config(ip = self.device.ip_address, |
|
215 | answer = api.write_config(ip = self.device.ip_address, | |
191 | port = self.device.port_address, |
|
216 | port = self.device.port_address, | |
192 | parms = self.parms_to_dict()) |
|
217 | parms = self.parms_to_dict()) | |
193 |
|
218 | |||
194 | if answer[0] != "1": |
|
219 | if answer[0] != "1": | |
195 | self.message = answer[0:] |
|
220 | self.message = answer[0:] | |
196 | return 0 |
|
221 | return 0 | |
197 |
|
222 | |||
198 | self.message = answer[2:] |
|
223 | self.message = answer[2:] | |
199 | return 1 |
|
224 | return 1 | |
200 |
|
225 | |||
201 | class Meta: |
|
226 | class Meta: | |
202 | db_table = 'dds_configurations' |
|
227 | db_table = 'dds_configurations' | |
203 | No newline at end of file |
|
228 |
@@ -1,234 +1,234 | |||||
1 | # Create your views here. |
|
1 | # Create your views here. | |
2 | from django.shortcuts import redirect, render, get_object_or_404 |
|
2 | from django.shortcuts import redirect, render, get_object_or_404 | |
3 |
|
3 | |||
4 | # from apps.main.models import Experiment, Configuration |
|
4 | # from apps.main.models import Experiment, Configuration | |
5 | from apps.main.views import sidebar |
|
5 | from apps.main.views import sidebar | |
6 |
|
6 | |||
7 | from .models import DDSConfiguration |
|
7 | from .models import DDSConfiguration | |
8 | from .forms import DDSConfigurationForm |
|
8 | from .forms import DDSConfigurationForm | |
9 | # Create your views here. |
|
9 | # Create your views here. | |
10 |
|
10 | |||
11 | def dds_conf(request, id_conf): |
|
11 | def dds_conf(request, id_conf): | |
12 |
|
12 | |||
13 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
13 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
14 |
|
14 | |||
15 | kwargs = {} |
|
15 | kwargs = {} | |
16 |
|
16 | |||
17 | kwargs['status'] = conf.device.status |
|
17 | kwargs['status'] = conf.device.get_status_display() | |
18 |
|
18 | |||
19 | # if not kwargs['connected']: |
|
19 | # if not kwargs['connected']: | |
20 | # messages.error(request, message=answer) |
|
20 | # messages.error(request, message=answer) | |
21 |
|
21 | |||
22 | kwargs['dev_conf'] = conf |
|
22 | kwargs['dev_conf'] = conf | |
23 | kwargs['dev_conf_keys'] = ['name', |
|
23 | kwargs['dev_conf_keys'] = ['name', | |
24 | 'experiment', |
|
24 | 'experiment', | |
25 | 'device', |
|
25 | 'device', | |
26 | 'clock', |
|
26 | 'clock', | |
27 | 'multiplier', |
|
27 | 'multiplier', | |
28 | 'frequencyA_Mhz', |
|
28 | 'frequencyA_Mhz', | |
29 | 'frequencyA', |
|
29 | 'frequencyA', | |
30 | 'frequencyB_Mhz', |
|
30 | 'frequencyB_Mhz', | |
31 | 'frequencyB', |
|
31 | 'frequencyB', | |
32 | 'phaseA_degrees', |
|
32 | 'phaseA_degrees', | |
33 | 'phaseB_degrees', |
|
33 | 'phaseB_degrees', | |
34 | 'modulation', |
|
34 | 'modulation', | |
35 | 'amplitude_enabled', |
|
35 | 'amplitude_enabled', | |
36 | 'amplitudeI', |
|
36 | 'amplitudeI', | |
37 | 'amplitudeQ'] |
|
37 | 'amplitudeQ'] | |
38 |
|
38 | |||
39 | kwargs['title'] = 'DDS Configuration' |
|
39 | kwargs['title'] = 'DDS Configuration' | |
40 | kwargs['suptitle'] = 'Details' |
|
40 | kwargs['suptitle'] = 'Details' | |
41 |
|
41 | |||
42 | kwargs['button'] = 'Edit Configuration' |
|
42 | kwargs['button'] = 'Edit Configuration' | |
43 |
|
43 | |||
44 | ###### SIDEBAR ###### |
|
44 | ###### SIDEBAR ###### | |
45 | kwargs.update(sidebar(conf)) |
|
45 | kwargs.update(sidebar(conf)) | |
46 |
|
46 | |||
47 | return render(request, 'dds_conf.html', kwargs) |
|
47 | return render(request, 'dds_conf.html', kwargs) | |
48 |
|
48 | |||
49 | def dds_conf_edit(request, id_conf): |
|
49 | def dds_conf_edit(request, id_conf): | |
50 |
|
50 | |||
51 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
51 | conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
52 |
|
52 | |||
53 | if request.method=='GET': |
|
53 | if request.method=='GET': | |
54 | form = DDSConfigurationForm(instance=conf) |
|
54 | form = DDSConfigurationForm(instance=conf) | |
55 |
|
55 | |||
56 | if request.method=='POST': |
|
56 | if request.method=='POST': | |
57 | form = DDSConfigurationForm(request.POST, instance=conf) |
|
57 | form = DDSConfigurationForm(request.POST, instance=conf) | |
58 |
|
58 | |||
59 | if form.is_valid(): |
|
59 | if form.is_valid(): | |
60 | conf = form.save(commit=False) |
|
60 | conf = form.save(commit=False) | |
61 |
|
61 | |||
62 | if conf.verify_frequencies(): |
|
62 | if conf.verify_frequencies(): | |
63 |
|
63 | |||
64 | conf.save() |
|
64 | conf.save() | |
65 | return redirect('url_dds_conf', id_conf=conf.id) |
|
65 | return redirect('url_dds_conf', id_conf=conf.id) | |
66 |
|
66 | |||
67 | ##ERRORS |
|
67 | ##ERRORS | |
68 |
|
|
68 | ||
69 | kwargs = {} |
|
69 | kwargs = {} | |
70 | kwargs['id_dev'] = conf.id |
|
70 | kwargs['id_dev'] = conf.id | |
71 | kwargs['form'] = form |
|
71 | kwargs['form'] = form | |
72 | kwargs['title'] = 'Device Configuration' |
|
72 | kwargs['title'] = 'Device Configuration' | |
73 | kwargs['suptitle'] = 'Edit' |
|
73 | kwargs['suptitle'] = 'Edit' | |
74 | kwargs['button'] = 'Save' |
|
74 | kwargs['button'] = 'Save' | |
75 |
|
75 | |||
76 | ###### SIDEBAR ###### |
|
76 | ###### SIDEBAR ###### | |
77 | kwargs.update(sidebar(conf)) |
|
77 | kwargs.update(sidebar(conf)) | |
78 |
|
78 | |||
79 | return render(request, 'dds_conf_edit.html', kwargs) |
|
79 | return render(request, 'dds_conf_edit.html', kwargs) | |
80 |
|
80 | |||
81 | # def dds_conf_import(request, id_conf): |
|
81 | # def dds_conf_import(request, id_conf): | |
82 | # |
|
82 | # | |
83 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
83 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
84 | # |
|
84 | # | |
85 | # if request.method == 'GET': |
|
85 | # if request.method == 'GET': | |
86 | # file_form = UploadFileForm() |
|
86 | # file_form = UploadFileForm() | |
87 | # |
|
87 | # | |
88 | # if request.method == 'POST': |
|
88 | # if request.method == 'POST': | |
89 | # file_form = UploadFileForm(request.POST, request.FILES) |
|
89 | # file_form = UploadFileForm(request.POST, request.FILES) | |
90 | # |
|
90 | # | |
91 | # if file_form.is_valid(): |
|
91 | # if file_form.is_valid(): | |
92 | # |
|
92 | # | |
93 | # parms = files.read_dds_file(request.FILES['file']) |
|
93 | # parms = files.read_dds_file(request.FILES['file']) | |
94 | # |
|
94 | # | |
95 | # if parms: |
|
95 | # if parms: | |
96 | # |
|
96 | # | |
97 | # if not parms['clock']: |
|
97 | # if not parms['clock']: | |
98 | # messages.warning(request, "Clock Input could not be imported from '%s'. Please fill it out." %request.FILES['file'].name) |
|
98 | # messages.warning(request, "Clock Input could not be imported from '%s'. Please fill it out." %request.FILES['file'].name) | |
99 | # else: |
|
99 | # else: | |
100 | # messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
100 | # messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
101 | # |
|
101 | # | |
102 | # form = DDSConfigurationForm(initial=parms, instance=conf) |
|
102 | # form = DDSConfigurationForm(initial=parms, instance=conf) | |
103 | # |
|
103 | # | |
104 | # kwargs = {} |
|
104 | # kwargs = {} | |
105 | # kwargs['id_dev'] = conf.id |
|
105 | # kwargs['id_dev'] = conf.id | |
106 | # kwargs['form'] = form |
|
106 | # kwargs['form'] = form | |
107 | # kwargs['title'] = 'Device Configuration' |
|
107 | # kwargs['title'] = 'Device Configuration' | |
108 | # kwargs['suptitle'] = 'Parameters imported' |
|
108 | # kwargs['suptitle'] = 'Parameters imported' | |
109 | # kwargs['button'] = 'Save' |
|
109 | # kwargs['button'] = 'Save' | |
110 | # kwargs['action'] = conf.get_absolute_url_edit() |
|
110 | # kwargs['action'] = conf.get_absolute_url_edit() | |
111 | # kwargs['previous'] = conf.get_absolute_url() |
|
111 | # kwargs['previous'] = conf.get_absolute_url() | |
112 | # |
|
112 | # | |
113 | # ###### SIDEBAR ###### |
|
113 | # ###### SIDEBAR ###### | |
114 | # kwargs.update(sidebar(conf)) |
|
114 | # kwargs.update(sidebar(conf)) | |
115 | # |
|
115 | # | |
116 | # return render(request, 'dds_conf_edit.html', kwargs) |
|
116 | # return render(request, 'dds_conf_edit.html', kwargs) | |
117 | # |
|
117 | # | |
118 | # messages.error(request, "Could not import parameters from file") |
|
118 | # messages.error(request, "Could not import parameters from file") | |
119 | # |
|
119 | # | |
120 | # kwargs = {} |
|
120 | # kwargs = {} | |
121 | # kwargs['id_dev'] = conf.id |
|
121 | # kwargs['id_dev'] = conf.id | |
122 | # kwargs['title'] = 'Device Configuration' |
|
122 | # kwargs['title'] = 'Device Configuration' | |
123 | # kwargs['form'] = file_form |
|
123 | # kwargs['form'] = file_form | |
124 | # kwargs['suptitle'] = 'Importing file' |
|
124 | # kwargs['suptitle'] = 'Importing file' | |
125 | # kwargs['button'] = 'Import' |
|
125 | # kwargs['button'] = 'Import' | |
126 | # |
|
126 | # | |
127 | # kwargs.update(sidebar(conf)) |
|
127 | # kwargs.update(sidebar(conf)) | |
128 | # |
|
128 | # | |
129 | # return render(request, 'dds_conf_import.html', kwargs) |
|
129 | # return render(request, 'dds_conf_import.html', kwargs) | |
130 | # |
|
130 | # | |
131 | # def dds_conf_export(request, id_conf): |
|
131 | # def dds_conf_export(request, id_conf): | |
132 | # |
|
132 | # | |
133 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
133 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
134 | # |
|
134 | # | |
135 | # response = HttpResponse(content_type='text/plain') |
|
135 | # response = HttpResponse(content_type='text/plain') | |
136 | # response['Content-Disposition'] = 'attachment; filename="%s.dds"' %conf.name |
|
136 | # response['Content-Disposition'] = 'attachment; filename="%s.dds"' %conf.name | |
137 | # response.write(conf.export_parms_to_dict()) |
|
137 | # response.write(conf.export_parms_to_dict()) | |
138 | # |
|
138 | # | |
139 | # return response |
|
139 | # return response | |
140 | # |
|
140 | # | |
141 | # def dds_conf_start(request, id_conf): |
|
141 | # def dds_conf_start(request, id_conf): | |
142 | # |
|
142 | # | |
143 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
143 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
144 | # |
|
144 | # | |
145 | # if conf.start_device(): |
|
145 | # if conf.start_device(): | |
146 | # messages.success(request, conf.message) |
|
146 | # messages.success(request, conf.message) | |
147 | # else: |
|
147 | # else: | |
148 | # messages.error(request, conf.message) |
|
148 | # messages.error(request, conf.message) | |
149 | # |
|
149 | # | |
150 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
150 | # return redirect('url_dds_conf', id_conf=conf.id) | |
151 | # |
|
151 | # | |
152 | # def dds_conf_stop(request, id_conf): |
|
152 | # def dds_conf_stop(request, id_conf): | |
153 | # |
|
153 | # | |
154 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
154 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
155 | # |
|
155 | # | |
156 | # if conf.stop_device(): |
|
156 | # if conf.stop_device(): | |
157 | # messages.success(request, conf.message) |
|
157 | # messages.success(request, conf.message) | |
158 | # else: |
|
158 | # else: | |
159 | # messages.error(request, conf.message) |
|
159 | # messages.error(request, conf.message) | |
160 | # |
|
160 | # | |
161 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
161 | # return redirect('url_dds_conf', id_conf=conf.id) | |
162 | # |
|
162 | # | |
163 | # def dds_conf_status(request, id_conf): |
|
163 | # def dds_conf_status(request, id_conf): | |
164 | # |
|
164 | # | |
165 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
165 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
166 | # |
|
166 | # | |
167 | # if conf.status_device(): |
|
167 | # if conf.status_device(): | |
168 | # messages.success(request, conf.message) |
|
168 | # messages.success(request, conf.message) | |
169 | # else: |
|
169 | # else: | |
170 | # messages.error(request, conf.message) |
|
170 | # messages.error(request, conf.message) | |
171 | # |
|
171 | # | |
172 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
172 | # return redirect('url_dds_conf', id_conf=conf.id) | |
173 | # |
|
173 | # | |
174 | # |
|
174 | # | |
175 | # def dds_conf_write(request, id_conf): |
|
175 | # def dds_conf_write(request, id_conf): | |
176 | # |
|
176 | # | |
177 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
177 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
178 | # |
|
178 | # | |
179 | # answer = conf.write_device() |
|
179 | # answer = conf.write_device() | |
180 | # |
|
180 | # | |
181 | # if answer: |
|
181 | # if answer: | |
182 | # messages.success(request, conf.message) |
|
182 | # messages.success(request, conf.message) | |
183 | # |
|
183 | # | |
184 | # conf.pk = None |
|
184 | # conf.pk = None | |
185 | # conf.id = None |
|
185 | # conf.id = None | |
186 | # conf.type = 1 |
|
186 | # conf.type = 1 | |
187 | # conf.template = 0 |
|
187 | # conf.template = 0 | |
188 | # conf.save() |
|
188 | # conf.save() | |
189 | # |
|
189 | # | |
190 | # else: |
|
190 | # else: | |
191 | # messages.error(request, conf.message) |
|
191 | # messages.error(request, conf.message) | |
192 | # |
|
192 | # | |
193 | # return redirect('url_dds_conf', id_conf=id_conf) |
|
193 | # return redirect('url_dds_conf', id_conf=id_conf) | |
194 | # |
|
194 | # | |
195 | # def dds_conf_read(request, id_conf): |
|
195 | # def dds_conf_read(request, id_conf): | |
196 | # |
|
196 | # | |
197 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) |
|
197 | # conf = get_object_or_404(DDSConfiguration, pk=id_conf) | |
198 | # |
|
198 | # | |
199 | # if request.method=='GET': |
|
199 | # if request.method=='GET': | |
200 | # |
|
200 | # | |
201 | # parms = conf.read_device() |
|
201 | # parms = conf.read_device() | |
202 | # |
|
202 | # | |
203 | # if not parms: |
|
203 | # if not parms: | |
204 | # messages.error(request, conf.message) |
|
204 | # messages.error(request, conf.message) | |
205 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
205 | # return redirect('url_dds_conf', id_conf=conf.id) | |
206 | # |
|
206 | # | |
207 | # messages.warning(request, "Clock Input cannot be read from device. Please fill it out.") |
|
207 | # messages.warning(request, "Clock Input cannot be read from device. Please fill it out.") | |
208 | # |
|
208 | # | |
209 | # form = DDSConfigurationForm(initial=parms, instance=conf) |
|
209 | # form = DDSConfigurationForm(initial=parms, instance=conf) | |
210 | # |
|
210 | # | |
211 | # if request.method=='POST': |
|
211 | # if request.method=='POST': | |
212 | # form = DDSConfigurationForm(request.POST, instance=conf) |
|
212 | # form = DDSConfigurationForm(request.POST, instance=conf) | |
213 | # |
|
213 | # | |
214 | # if form.is_valid(): |
|
214 | # if form.is_valid(): | |
215 | # dds_model = form.save(commit=False) |
|
215 | # dds_model = form.save(commit=False) | |
216 | # |
|
216 | # | |
217 | # if dds_model.verify_frequencies(): |
|
217 | # if dds_model.verify_frequencies(): | |
218 | # |
|
218 | # | |
219 | # dds_model.save() |
|
219 | # dds_model.save() | |
220 | # return redirect('url_dds_conf', id_conf=conf.id) |
|
220 | # return redirect('url_dds_conf', id_conf=conf.id) | |
221 | # |
|
221 | # | |
222 | # messages.error(request, "DDS parameters could not be saved") |
|
222 | # messages.error(request, "DDS parameters could not be saved") | |
223 | # |
|
223 | # | |
224 | # kwargs = {} |
|
224 | # kwargs = {} | |
225 | # kwargs['id_dev'] = conf.id |
|
225 | # kwargs['id_dev'] = conf.id | |
226 | # kwargs['form'] = form |
|
226 | # kwargs['form'] = form | |
227 | # kwargs['title'] = 'Device Configuration' |
|
227 | # kwargs['title'] = 'Device Configuration' | |
228 | # kwargs['suptitle'] = 'Parameters read from device' |
|
228 | # kwargs['suptitle'] = 'Parameters read from device' | |
229 | # kwargs['button'] = 'Save' |
|
229 | # kwargs['button'] = 'Save' | |
230 | # |
|
230 | # | |
231 | # ###### SIDEBAR ###### |
|
231 | # ###### SIDEBAR ###### | |
232 | # kwargs.update(sidebar(conf)) |
|
232 | # kwargs.update(sidebar(conf)) | |
233 | # |
|
233 | # | |
234 | # return render(request, 'dds_conf_edit.html', kwargs) No newline at end of file |
|
234 | # return render(request, 'dds_conf_edit.html', kwargs) |
@@ -1,80 +1,106 | |||||
1 | from django import forms |
|
1 | from django import forms | |
2 | from django.utils.safestring import mark_safe |
|
2 | from django.utils.safestring import mark_safe | |
3 |
|
3 | |||
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location |
|
4 | from .models import DeviceType, Device, Experiment, Campaign, Configuration, Location | |
5 |
|
5 | |||
|
6 | FILE_FORMAT = ( | |||
|
7 | ('json', 'json'), | |||
|
8 | ) | |||
|
9 | ||||
|
10 | DDS_FILE_FORMAT = ( | |||
|
11 | ('json', 'json'), | |||
|
12 | ('text', 'dds') | |||
|
13 | ) | |||
|
14 | ||||
|
15 | RC_FILE_FORMAT = ( | |||
|
16 | ('json', 'json'), | |||
|
17 | ('text', 'rc') | |||
|
18 | ) | |||
|
19 | ||||
6 | def add_empty_choice(choices, pos=0, label='-----'): |
|
20 | def add_empty_choice(choices, pos=0, label='-----'): | |
7 | if len(choices)>0: |
|
21 | if len(choices)>0: | |
8 | choices = list(choices) |
|
22 | choices = list(choices) | |
9 | choices.insert(0, (0, label)) |
|
23 | choices.insert(0, (0, label)) | |
10 | return choices |
|
24 | return choices | |
11 | else: |
|
25 | else: | |
12 | return [(0, label)] |
|
26 | return [(0, label)] | |
13 |
|
27 | |||
14 | class DatepickerWidget(forms.widgets.TextInput): |
|
28 | class DatepickerWidget(forms.widgets.TextInput): | |
15 | def render(self, name, value, attrs=None): |
|
29 | def render(self, name, value, attrs=None): | |
16 | input_html = super(DatepickerWidget, self).render(name, value, attrs) |
|
30 | input_html = super(DatepickerWidget, self).render(name, value, attrs) | |
17 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' |
|
31 | html = '<div class="input-group date">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></span></div>' | |
18 | return mark_safe(html) |
|
32 | return mark_safe(html) | |
19 |
|
33 | |||
20 | class TimepickerWidget(forms.widgets.TextInput): |
|
34 | class TimepickerWidget(forms.widgets.TextInput): | |
21 | def render(self, name, value, attrs=None): |
|
35 | def render(self, name, value, attrs=None): | |
22 | input_html = super(TimepickerWidget, self).render(name, value, attrs) |
|
36 | input_html = super(TimepickerWidget, self).render(name, value, attrs) | |
23 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' |
|
37 | html = '<div class="input-group time">'+input_html+'<span class="input-group-addon"><i class="glyphicon glyphicon-time"></i></span></div>' | |
24 | return mark_safe(html) |
|
38 | return mark_safe(html) | |
25 |
|
39 | |||
26 | class CampaignForm(forms.ModelForm): |
|
40 | class CampaignForm(forms.ModelForm): | |
27 | def __init__(self, *args, **kwargs): |
|
41 | def __init__(self, *args, **kwargs): | |
28 | super(CampaignForm, self).__init__(*args, **kwargs) |
|
42 | super(CampaignForm, self).__init__(*args, **kwargs) | |
29 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) |
|
43 | self.fields['start_date'].widget = DatepickerWidget(self.fields['start_date'].widget.attrs) | |
30 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) |
|
44 | self.fields['end_date'].widget = DatepickerWidget(self.fields['end_date'].widget.attrs) | |
31 |
|
45 | |||
32 | class Meta: |
|
46 | class Meta: | |
33 | model = Campaign |
|
47 | model = Campaign | |
34 | exclude = [''] |
|
48 | exclude = [''] | |
35 |
|
49 | |||
36 | class ExperimentForm(forms.ModelForm): |
|
50 | class ExperimentForm(forms.ModelForm): | |
37 |
|
51 | |||
38 | def __init__(self, *args, **kwargs): |
|
52 | def __init__(self, *args, **kwargs): | |
39 | super(ExperimentForm, self).__init__(*args, **kwargs) |
|
53 | super(ExperimentForm, self).__init__(*args, **kwargs) | |
40 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) |
|
54 | self.fields['start_time'].widget = TimepickerWidget(self.fields['start_time'].widget.attrs) | |
41 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) |
|
55 | self.fields['end_time'].widget = TimepickerWidget(self.fields['end_time'].widget.attrs) | |
42 |
|
56 | |||
43 | self.fields['campaign'].widget.attrs['readonly'] = True |
|
57 | self.fields['campaign'].widget.attrs['readonly'] = True | |
44 |
|
58 | |||
45 | class Meta: |
|
59 | class Meta: | |
46 | model = Experiment |
|
60 | model = Experiment | |
47 | exclude = [''] |
|
61 | exclude = [''] | |
48 |
|
62 | |||
49 | class LocationForm(forms.ModelForm): |
|
63 | class LocationForm(forms.ModelForm): | |
50 | class Meta: |
|
64 | class Meta: | |
51 | model = Location |
|
65 | model = Location | |
52 | exclude = [''] |
|
66 | exclude = [''] | |
53 |
|
67 | |||
54 | class DeviceForm(forms.ModelForm): |
|
68 | class DeviceForm(forms.ModelForm): | |
55 | class Meta: |
|
69 | class Meta: | |
56 | model = Device |
|
70 | model = Device | |
57 | exclude = ['status'] |
|
71 | exclude = ['status'] | |
58 |
|
72 | |||
59 | class ConfigurationForm(forms.ModelForm): |
|
73 | class ConfigurationForm(forms.ModelForm): | |
60 | class Meta: |
|
74 | class Meta: | |
61 | model = Configuration |
|
75 | model = Configuration | |
62 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] |
|
76 | exclude = ['type', 'created_date', 'programmed_date', 'parameters'] | |
63 |
|
77 | |||
64 | class DeviceTypeForm(forms.Form): |
|
78 | class DeviceTypeForm(forms.Form): | |
65 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) |
|
79 | device_type = forms.ChoiceField(choices=add_empty_choice(DeviceType.objects.all().order_by('name').values_list('id', 'name'))) | |
66 |
|
80 | |||
67 |
|
81 | |||
68 | class UploadFileForm(forms.Form): |
|
82 | class UploadFileForm(forms.Form): | |
69 |
|
83 | |||
70 | file = forms.FileField() |
|
84 | file = forms.FileField() | |
71 |
|
85 | |||
72 | class DownloadFileForm(forms.Form): |
|
86 | class DownloadFileForm(forms.Form): | |
73 |
|
87 | |||
74 |
format = forms.C |
|
88 | format = forms.ChoiceField(choices= ((0, 'json'),) ) | |
|
89 | ||||
|
90 | def __init__(self, device_type, *args, **kwargs): | |||
|
91 | ||||
|
92 | super(DownloadFileForm, self).__init__(*args, **kwargs) | |||
|
93 | ||||
|
94 | self.fields['format'].choices = FILE_FORMAT | |||
|
95 | ||||
|
96 | if device_type == 'dds': | |||
|
97 | self.fields['format'].choices = DDS_FILE_FORMAT | |||
|
98 | ||||
|
99 | if device_type == 'rc': | |||
|
100 | self.fields['format'].choices = RC_FILE_FORMAT | |||
75 |
|
101 | |||
76 | class OperationForm(forms.Form): |
|
102 | class OperationForm(forms.Form): | |
77 | # today = datetime.today() |
|
103 | # today = datetime.today() | |
78 | # -----Campaigns from this month------ |
|
104 | # -----Campaigns from this month------ | |
79 | campaign = forms.ChoiceField(choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:5], label="Campaign") |
|
105 | campaign = forms.ChoiceField(choices=Campaign.objects.all().order_by('-start_date').values_list('id', 'name')[:5], label="Campaign") | |
80 | No newline at end of file |
|
106 |
@@ -1,273 +1,295 | |||||
1 | from django.db import models |
|
1 | from django.db import models | |
2 | from polymorphic import PolymorphicModel |
|
2 | from polymorphic import PolymorphicModel | |
3 |
|
3 | |||
4 | from django.core.urlresolvers import reverse |
|
4 | from django.core.urlresolvers import reverse | |
5 |
|
5 | |||
6 | CONF_STATES = ( |
|
6 | CONF_STATES = ( | |
7 | (0, 'Disconnected'), |
|
7 | (0, 'Disconnected'), | |
8 | (1, 'Connected'), |
|
8 | (1, 'Connected'), | |
9 | (1, 'Running'), |
|
9 | (1, 'Running'), | |
10 | ) |
|
10 | ) | |
11 |
|
11 | |||
12 | CONF_TYPES = ( |
|
12 | CONF_TYPES = ( | |
13 | (0, 'Active'), |
|
13 | (0, 'Active'), | |
14 | (1, 'Historical'), |
|
14 | (1, 'Historical'), | |
15 | ) |
|
15 | ) | |
16 |
|
16 | |||
17 | DEV_STATES = ( |
|
17 | DEV_STATES = ( | |
18 | (0, 'No connected'), |
|
18 | (0, 'No connected'), | |
19 | (1, 'Connected'), |
|
19 | (1, 'Connected'), | |
20 | (2, 'Configured'), |
|
20 | (2, 'Configured'), | |
21 | (3, 'Running'), |
|
21 | (3, 'Running'), | |
22 | ) |
|
22 | ) | |
23 |
|
23 | |||
24 | DEV_TYPES = ( |
|
24 | DEV_TYPES = ( | |
25 | ('', 'Select a device type'), |
|
25 | ('', 'Select a device type'), | |
26 | ('rc', 'Radar Controller'), |
|
26 | ('rc', 'Radar Controller'), | |
27 | ('dds', 'Direct Digital Synthesizer'), |
|
27 | ('dds', 'Direct Digital Synthesizer'), | |
28 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
28 | ('jars', 'Jicamarca Radar Acquisition System'), | |
29 | ('usrp', 'Universal Software Radio Peripheral'), |
|
29 | ('usrp', 'Universal Software Radio Peripheral'), | |
30 | ('cgs', 'Clock Generator System'), |
|
30 | ('cgs', 'Clock Generator System'), | |
31 | ('abs', 'Automatic Beam Switching'), |
|
31 | ('abs', 'Automatic Beam Switching'), | |
32 | ) |
|
32 | ) | |
33 |
|
33 | |||
34 | DEV_PORTS = { |
|
34 | DEV_PORTS = { | |
35 | 'rc' : 2000, |
|
35 | 'rc' : 2000, | |
36 | 'dds' : 2000, |
|
36 | 'dds' : 2000, | |
37 | 'jars' : 2000, |
|
37 | 'jars' : 2000, | |
38 | 'usrp' : 2000, |
|
38 | 'usrp' : 2000, | |
39 | 'cgs' : 8080, |
|
39 | 'cgs' : 8080, | |
40 | 'abs' : 8080 |
|
40 | 'abs' : 8080 | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | RADAR_STATES = ( |
|
43 | RADAR_STATES = ( | |
44 | (0, 'No connected'), |
|
44 | (0, 'No connected'), | |
45 | (1, 'Connnected'), |
|
45 | (1, 'Connnected'), | |
46 | (2, 'Configured'), |
|
46 | (2, 'Configured'), | |
47 | (3, 'Running'), |
|
47 | (3, 'Running'), | |
48 | (4, 'Scheduled'), |
|
48 | (4, 'Scheduled'), | |
49 | ) |
|
49 | ) | |
50 | # Create your models here. |
|
50 | # Create your models here. | |
51 |
|
51 | |||
52 |
|
52 | |||
53 | class Location(models.Model): |
|
53 | class Location(models.Model): | |
54 |
|
54 | |||
55 | name = models.CharField(max_length = 30) |
|
55 | name = models.CharField(max_length = 30) | |
56 | description = models.TextField(blank=True, null=True) |
|
56 | description = models.TextField(blank=True, null=True) | |
57 |
|
57 | |||
58 | class Meta: |
|
58 | class Meta: | |
59 | db_table = 'db_location' |
|
59 | db_table = 'db_location' | |
60 |
|
60 | |||
61 | def __unicode__(self): |
|
61 | def __unicode__(self): | |
62 | return u'%s' % self.name |
|
62 | return u'%s' % self.name | |
63 |
|
63 | |||
64 | class DeviceType(models.Model): |
|
64 | class DeviceType(models.Model): | |
65 |
|
65 | |||
66 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
66 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') | |
67 | description = models.TextField(blank=True, null=True) |
|
67 | description = models.TextField(blank=True, null=True) | |
68 |
|
68 | |||
69 | class Meta: |
|
69 | class Meta: | |
70 | db_table = 'db_device_types' |
|
70 | db_table = 'db_device_types' | |
71 |
|
71 | |||
72 | def __unicode__(self): |
|
72 | def __unicode__(self): | |
73 | return u'%s' % self.get_name_display() |
|
73 | return u'%s' % self.get_name_display() | |
74 |
|
74 | |||
75 | class Device(models.Model): |
|
75 | class Device(models.Model): | |
76 |
|
76 | |||
77 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) |
|
77 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) | |
78 | location = models.ForeignKey(Location, on_delete=models.CASCADE) |
|
78 | location = models.ForeignKey(Location, on_delete=models.CASCADE) | |
79 |
|
79 | |||
80 | name = models.CharField(max_length=40, default='') |
|
80 | name = models.CharField(max_length=40, default='') | |
81 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
81 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') | |
82 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
82 | port_address = models.PositiveSmallIntegerField(default=2000) | |
83 | description = models.TextField(blank=True, null=True) |
|
83 | description = models.TextField(blank=True, null=True) | |
84 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
84 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) | |
85 |
|
85 | |||
86 | class Meta: |
|
86 | class Meta: | |
87 | db_table = 'db_devices' |
|
87 | db_table = 'db_devices' | |
88 |
|
88 | |||
89 | def __unicode__(self): |
|
89 | def __unicode__(self): | |
90 | return u'%s | %s' % (self.name, self.ip_address) |
|
90 | return u'%s | %s' % (self.name, self.ip_address) | |
91 |
|
91 | |||
92 | def get_status(self): |
|
92 | def get_status(self): | |
93 |
|
93 | |||
94 | return self.status |
|
94 | return self.status | |
95 |
|
95 | |||
96 |
|
96 | |||
97 | class Campaign(models.Model): |
|
97 | class Campaign(models.Model): | |
98 |
|
98 | |||
99 | template = models.BooleanField(default=False) |
|
99 | template = models.BooleanField(default=False) | |
100 |
|
100 | |||
101 | name = models.CharField(max_length=40, unique=True) |
|
101 | name = models.CharField(max_length=40, unique=True) | |
102 | start_date = models.DateTimeField(blank=True, null=True) |
|
102 | start_date = models.DateTimeField(blank=True, null=True) | |
103 | end_date = models.DateTimeField(blank=True, null=True) |
|
103 | end_date = models.DateTimeField(blank=True, null=True) | |
104 | tags = models.CharField(max_length=40) |
|
104 | tags = models.CharField(max_length=40) | |
105 | description = models.TextField(blank=True, null=True) |
|
105 | description = models.TextField(blank=True, null=True) | |
106 |
|
106 | |||
107 | class Meta: |
|
107 | class Meta: | |
108 | db_table = 'db_campaigns' |
|
108 | db_table = 'db_campaigns' | |
109 |
|
109 | |||
110 | def __unicode__(self): |
|
110 | def __unicode__(self): | |
111 | return u'%s' % (self.name) |
|
111 | return u'%s' % (self.name) | |
112 |
|
112 | |||
113 | # class Radar(models.Model): |
|
113 | # class Radar(models.Model): | |
114 | # |
|
114 | # | |
115 | # # name = models.CharField(max_length = 30) |
|
115 | # # name = models.CharField(max_length = 30) | |
116 | # experiment = models.ForeignKey('Experiment', on_delete=models.CASCADE) |
|
116 | # experiment = models.ForeignKey('Experiment', on_delete=models.CASCADE) | |
117 | # location = models.OneToOneField('Location', on_delete=models.CASCADE) |
|
117 | # location = models.OneToOneField('Location', on_delete=models.CASCADE) | |
118 | # status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
118 | # status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) | |
119 | # |
|
119 | # | |
120 | # class Meta: |
|
120 | # class Meta: | |
121 | # db_table = 'db_radar' |
|
121 | # db_table = 'db_radar' | |
122 | # |
|
122 | # | |
123 | # def __unicode__(self): |
|
123 | # def __unicode__(self): | |
124 | # return u'%s' % self.location |
|
124 | # return u'%s' % self.location | |
125 |
|
125 | |||
126 |
|
126 | |||
127 | class Experiment(models.Model): |
|
127 | class Experiment(models.Model): | |
128 |
|
128 | |||
129 | template = models.BooleanField(default=False) |
|
129 | template = models.BooleanField(default=False) | |
130 |
|
130 | |||
131 | campaign = models.ForeignKey('Campaign', null=True, blank=True, on_delete=models.CASCADE) |
|
131 | campaign = models.ForeignKey('Campaign', null=True, blank=True, on_delete=models.CASCADE) | |
132 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
132 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) | |
133 |
|
133 | |||
134 | name = models.CharField(max_length=40, default='') |
|
134 | name = models.CharField(max_length=40, default='') | |
135 | start_time = models.TimeField(default='00:00:00') |
|
135 | start_time = models.TimeField(default='00:00:00') | |
136 | end_time = models.TimeField(default='23:59:59') |
|
136 | end_time = models.TimeField(default='23:59:59') | |
137 |
|
137 | |||
138 | class Meta: |
|
138 | class Meta: | |
139 | db_table = 'db_experiments' |
|
139 | db_table = 'db_experiments' | |
140 |
|
140 | |||
141 | def __unicode__(self): |
|
141 | def __unicode__(self): | |
142 | return u'%s' % (self.name) |
|
142 | return u'%s' % (self.name) | |
143 |
|
143 | |||
144 | class Configuration(PolymorphicModel): |
|
144 | class Configuration(PolymorphicModel): | |
145 |
|
145 | |||
146 | template = models.BooleanField(default=False) |
|
146 | template = models.BooleanField(default=False) | |
147 |
|
147 | |||
148 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
148 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') | |
149 |
|
149 | |||
150 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
150 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) | |
151 | device = models.ForeignKey(Device, on_delete=models.CASCADE) |
|
151 | device = models.ForeignKey(Device, on_delete=models.CASCADE) | |
152 |
|
152 | |||
153 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
153 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) | |
154 |
|
154 | |||
155 | created_date = models.DateTimeField(auto_now_add=True) |
|
155 | created_date = models.DateTimeField(auto_now_add=True) | |
156 | programmed_date = models.DateTimeField(auto_now=True) |
|
156 | programmed_date = models.DateTimeField(auto_now=True) | |
157 |
|
157 | |||
158 | parameters = models.TextField(default='{}') |
|
158 | parameters = models.TextField(default='{}') | |
159 |
|
159 | |||
160 | message = "" |
|
160 | message = "" | |
161 |
|
161 | |||
162 | class Meta: |
|
162 | class Meta: | |
163 | db_table = 'db_configurations' |
|
163 | db_table = 'db_configurations' | |
164 |
|
164 | |||
165 | def __unicode__(self): |
|
165 | def __unicode__(self): | |
166 |
return u'[%s |
|
166 | return u'[%s, %s]: %s' % (self.experiment.name, | |
167 |
self. |
|
167 | self.device.name, | |
168 |
self. |
|
168 | self.name) | |
169 |
|
169 | |||
170 | def parms_to_dict(self): |
|
170 | def parms_to_dict(self): | |
171 |
|
171 | |||
172 | parameters = {} |
|
172 | parameters = {} | |
173 |
|
173 | |||
174 | for key in self.__dict__.keys(): |
|
174 | for key in self.__dict__.keys(): | |
175 | parameters[key] = getattr(self, key) |
|
175 | parameters[key] = getattr(self, key) | |
176 |
|
176 | |||
177 | return parameters |
|
177 | return parameters | |
178 |
|
178 | |||
|
179 | def parms_to_text(self): | |||
|
180 | ||||
|
181 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |||
|
182 | ||||
|
183 | return '' | |||
|
184 | ||||
|
185 | def parms_to_binary(self): | |||
|
186 | ||||
|
187 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |||
|
188 | ||||
|
189 | return '' | |||
|
190 | ||||
179 | def dict_to_parms(self, parameters): |
|
191 | def dict_to_parms(self, parameters): | |
180 |
|
192 | |||
181 | if type(parameters) != type({}): |
|
193 | if type(parameters) != type({}): | |
182 | return |
|
194 | return | |
183 |
|
195 | |||
184 | for key in parameters.keys(): |
|
196 | for key in parameters.keys(): | |
185 | setattr(self, key, parameters[key]) |
|
197 | setattr(self, key, parameters[key]) | |
186 |
|
198 | |||
187 | def export_to_file(self, format="json"): |
|
199 | def export_to_file(self, format="json"): | |
188 |
|
200 | |||
189 | import json |
|
201 | import json | |
190 |
|
202 | |||
191 |
content_type = ' |
|
203 | content_type = '' | |
192 | filename = '%s.json' %self.name |
|
|||
193 | content = json.dumps(self.params_to_dict()) |
|
|||
194 |
|
204 | |||
195 | if format == 'text': |
|
205 | if format == 'text': | |
196 | content_type = 'text/plain' |
|
206 | content_type = 'text/plain' | |
197 | filename = '%s.%s' %(self.name, self.device.device_type.name) |
|
207 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) | |
198 |
content = self.par |
|
208 | content = self.parms_to_text() | |
199 |
|
209 | |||
200 | if format == 'binary': |
|
210 | if format == 'binary': | |
201 | content_type = 'application/octet-stream' |
|
211 | content_type = 'application/octet-stream' | |
202 | filename = '%s.bin' %self.name |
|
212 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) | |
203 |
content = self.par |
|
213 | content = self.parms_to_binary() | |
|
214 | ||||
|
215 | if not content_type: | |||
|
216 | content_type = 'application/json' | |||
|
217 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) | |||
|
218 | content = json.dumps(self.parms_to_dict()) | |||
204 |
|
219 | |||
205 | fields = {'content_type':content_type, |
|
220 | fields = {'content_type':content_type, | |
206 | 'filename':filename, |
|
221 | 'filename':filename, | |
207 | 'content':content |
|
222 | 'content':content | |
208 | } |
|
223 | } | |
209 |
|
224 | |||
210 | return fields |
|
225 | return fields | |
211 |
|
226 | |||
212 |
def import_from_file(self, f |
|
227 | def import_from_file(self, fp): | |
|
228 | ||||
|
229 | import os, json | |||
|
230 | ||||
|
231 | parms = {} | |||
|
232 | ||||
|
233 | path, ext = os.path.splitext(fp.name) | |||
213 |
|
234 | |||
214 | raise NotImplementedError, "This method should be implemented in each Configuration model" |
|
235 | if ext == '.json': | |
|
236 | parms = json.load(fp) | |||
215 |
|
237 | |||
216 |
return |
|
238 | return parms | |
217 |
|
239 | |||
218 | def status_device(self): |
|
240 | def status_device(self): | |
219 |
|
241 | |||
220 |
raise NotImplementedError, "This method should be implemented in |
|
242 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
221 |
|
243 | |||
222 | return None |
|
244 | return None | |
223 |
|
245 | |||
224 | def stop_device(self): |
|
246 | def stop_device(self): | |
225 |
|
247 | |||
226 |
raise NotImplementedError, "This method should be implemented in |
|
248 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
227 |
|
249 | |||
228 | return None |
|
250 | return None | |
229 |
|
251 | |||
230 | def start_device(self): |
|
252 | def start_device(self): | |
231 |
|
253 | |||
232 |
raise NotImplementedError, "This method should be implemented in |
|
254 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
233 |
|
255 | |||
234 | return None |
|
256 | return None | |
235 |
|
257 | |||
236 | def write_device(self, parms): |
|
258 | def write_device(self, parms): | |
237 |
|
259 | |||
238 |
raise NotImplementedError, "This method should be implemented in |
|
260 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
239 |
|
261 | |||
240 | return None |
|
262 | return None | |
241 |
|
263 | |||
242 | def read_device(self): |
|
264 | def read_device(self): | |
243 |
|
265 | |||
244 |
raise NotImplementedError, "This method should be implemented in |
|
266 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() | |
245 |
|
267 | |||
246 | return None |
|
268 | return None | |
247 |
|
269 | |||
248 | def get_absolute_url(self): |
|
270 | def get_absolute_url(self): | |
249 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
271 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
250 |
|
272 | |||
251 | def get_absolute_url_edit(self): |
|
273 | def get_absolute_url_edit(self): | |
252 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
274 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) | |
253 |
|
275 | |||
254 | def get_absolute_url_import(self): |
|
276 | def get_absolute_url_import(self): | |
255 | return reverse('url_import_dev_conf', args=[str(self.id)]) |
|
277 | return reverse('url_import_dev_conf', args=[str(self.id)]) | |
256 |
|
278 | |||
257 | def get_absolute_url_export(self): |
|
279 | def get_absolute_url_export(self): | |
258 | return reverse('url_export_dev_conf', args=[str(self.id)]) |
|
280 | return reverse('url_export_dev_conf', args=[str(self.id)]) | |
259 |
|
281 | |||
260 | def get_absolute_url_write(self): |
|
282 | def get_absolute_url_write(self): | |
261 | return reverse('url_write_dev_conf', args=[str(self.id)]) |
|
283 | return reverse('url_write_dev_conf', args=[str(self.id)]) | |
262 |
|
284 | |||
263 | def get_absolute_url_read(self): |
|
285 | def get_absolute_url_read(self): | |
264 | return reverse('url_read_dev_conf', args=[str(self.id)]) |
|
286 | return reverse('url_read_dev_conf', args=[str(self.id)]) | |
265 |
|
287 | |||
266 | def get_absolute_url_start(self): |
|
288 | def get_absolute_url_start(self): | |
267 | return reverse('url_start_dev_conf', args=[str(self.id)]) |
|
289 | return reverse('url_start_dev_conf', args=[str(self.id)]) | |
268 |
|
290 | |||
269 | def get_absolute_url_stop(self): |
|
291 | def get_absolute_url_stop(self): | |
270 | return reverse('url_stop_dev_conf', args=[str(self.id)]) |
|
292 | return reverse('url_stop_dev_conf', args=[str(self.id)]) | |
271 |
|
293 | |||
272 | def get_absolute_url_status(self): |
|
294 | def get_absolute_url_status(self): | |
273 | return reverse('url_status_dev_conf', args=[str(self.id)]) No newline at end of file |
|
295 | return reverse('url_status_dev_conf', args=[str(self.id)]) |
@@ -1,141 +1,143 | |||||
1 | <!DOCTYPE html> |
|
1 | <!DOCTYPE html> | |
2 | {% load static %} |
|
2 | {% load static %} | |
3 | <html lang="en"> |
|
3 | <html lang="en"> | |
4 | <head> |
|
4 | <head> | |
5 | <meta charset="utf-8"> |
|
5 | <meta charset="utf-8"> | |
6 | <title>{% block title %}Jicamarca Integrated Radar System:::::{% endblock %}</title> |
|
6 | <title>{% block title %}Jicamarca Integrated Radar System:::::{% endblock %}</title> | |
7 | <meta name="description" content=""> |
|
7 | <meta name="description" content=""> | |
8 | <meta name="author" content=""> |
|
8 | <meta name="author" content=""> | |
9 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
|
9 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
10 | {# bootstrap_css #} |
|
10 | {# bootstrap_css #} | |
11 | <link href="{% static 'css/bootstrap-flatly.min.css' %}" media="all" rel="stylesheet"> |
|
11 | <link href="{% static 'css/bootstrap-flatly.min.css' %}" media="all" rel="stylesheet"> | |
12 | <style type="text/css"> |
|
12 | <style type="text/css"> | |
13 | body {padding-top: 60px} |
|
13 | body {padding-top: 60px} | |
14 | .logo {padding-top: 5px; height: 50px} |
|
14 | .logo {padding-top: 5px; height: 50px} | |
15 | .clickable-row {cursor: pointer;} |
|
15 | .clickable-row {cursor: pointer;} | |
16 | .col-no-padding { padding-left:0; } |
|
16 | .col-no-padding { padding-left:0; } | |
17 | </style> |
|
17 | </style> | |
18 | <!--[if lt IE 9]> |
|
18 | <!--[if lt IE 9]> | |
19 | <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> |
|
19 | <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
20 | <![endif]--> |
|
20 | <![endif]--> | |
21 | {% block extra-head %} |
|
21 | {% block extra-head %} | |
22 | {% endblock %} |
|
22 | {% endblock %} | |
23 | </head> |
|
23 | </head> | |
24 |
|
24 | |||
25 | <body> |
|
25 | <body> | |
26 |
|
26 | |||
27 | {% block main_menu %} |
|
27 | {% block main_menu %} | |
28 | <nav class="navbar navbar-default navbar-fixed-top" role="banner"> |
|
28 | <nav class="navbar navbar-default navbar-fixed-top" role="banner"> | |
29 | <div class="container-fluid"> |
|
29 | <div class="container-fluid"> | |
30 | <div class="navbar-header"> |
|
30 | <div class="navbar-header"> | |
31 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar"> |
|
31 | <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigationbar"> | |
32 | <span class="sr-only">Toggle navigation</span> |
|
32 | <span class="sr-only">Toggle navigation</span> | |
33 | <span class="icon-bar"></span> |
|
33 | <span class="icon-bar"></span> | |
34 | <span class="icon-bar"></span> |
|
34 | <span class="icon-bar"></span> | |
35 | <span class="icon-bar"></span> |
|
35 | <span class="icon-bar"></span> | |
36 | </button> |
|
36 | </button> | |
37 | <a class="navbar-brand" href="{% url 'index' %}" style="padding-top:1px"><img class="logo" alt="JRO" src="{% static "images/logo-jro-white-trans.png" %}"></a> |
|
37 | <a class="navbar-brand" href="{% url 'index' %}" style="padding-top:1px"><img class="logo" alt="JRO" src="{% static "images/logo-jro-white-trans.png" %}"></a> | |
38 | </div> |
|
38 | </div> | |
39 | <div class="collapse navbar-collapse" id="navigationbar"> |
|
39 | <div class="collapse navbar-collapse" id="navigationbar"> | |
40 | <ul class="nav navbar-nav"> |
|
40 | <ul class="nav navbar-nav"> | |
41 | <li class=" dropdown {% block operation-active %}{% endblock %}"><a href="{% url 'url_operation'%}">Operation</a> |
|
41 | <li class=" dropdown {% block operation-active %}{% endblock %}"><a href="{% url 'url_operation'%}">Operation</a> | |
42 | </li> |
|
42 | </li> | |
43 | <li class=" dropdown {% block conf-active %}{% endblock %}"> |
|
43 | <li class=" dropdown {% block conf-active %}{% endblock %}"> | |
44 |
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> |
|
44 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">New<span class="caret"></span></a> | |
45 | <ul class="dropdown-menu" role="menu"> |
|
45 | <ul class="dropdown-menu" role="menu"> | |
46 |
<li><a href=" |
|
46 | <li><a href="{% url 'url_add_campaign' %}">Campaign</a></li> | |
47 |
<li><a href=" |
|
47 | <li><a href="{% url 'url_add_experiment' 0%}">Experiment</a></li> | |
48 |
<li><a href=" |
|
48 | <li><a href="{% url 'url_add_dev_conf' 0%}">Device Configuration</a></li> | |
|
49 | <li><a href="{% url 'url_add_device'%}">Radar/Device</a></li> | |||
|
50 | ||||
49 | </ul> |
|
51 | </ul> | |
50 | </li> |
|
52 | </li> | |
51 | <li class=" dropdown {% block test-active %}{% endblock %}"> |
|
53 | <li class=" dropdown {% block test-active %}{% endblock %}"> | |
52 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Test<span class="caret"></span></a> |
|
54 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Test<span class="caret"></span></a> | |
53 | <ul class="dropdown-menu" role="menu"> |
|
55 | <ul class="dropdown-menu" role="menu"> | |
54 | <li><a href="{% url 'url_experiments' %}">Experiments</a></li> |
|
56 | <li><a href="{% url 'url_experiments' %}">Experiments</a></li> | |
55 | <li><a href="{% url 'url_devices' %}">Devices</a></li> |
|
57 | <li><a href="{% url 'url_devices' %}">Devices</a></li> | |
56 | </ul> |
|
58 | </ul> | |
57 | </li> |
|
59 | </li> | |
58 | <li class=" dropdown {% block search-active %}{% endblock %}"> |
|
60 | <li class=" dropdown {% block search-active %}{% endblock %}"> | |
59 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Search<span class="caret"></span></a> |
|
61 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Search<span class="caret"></span></a> | |
60 | <ul class="dropdown-menu" role="menu"> |
|
62 | <ul class="dropdown-menu" role="menu"> | |
61 | <li><a href="{% url 'url_campaigns' %}">Campaigns</a></li> |
|
63 | <li><a href="{% url 'url_campaigns' %}">Campaigns</a></li> | |
62 | <li><a href="{% url 'url_experiments' %}">Experiments</a></li> |
|
64 | <li><a href="{% url 'url_experiments' %}">Experiments</a></li> | |
63 | <li><a href="{% url 'url_dev_confs' %}">Configurations</a></li> |
|
65 | <li><a href="{% url 'url_dev_confs' %}">Configurations</a></li> | |
64 | </ul> |
|
66 | </ul> | |
65 | </li> |
|
67 | </li> | |
66 | </ul> |
|
68 | </ul> | |
67 | <ul class="nav navbar-nav navbar-right"> |
|
69 | <ul class="nav navbar-nav navbar-right"> | |
68 | <li class="nav-divider"></li> |
|
70 | <li class="nav-divider"></li> | |
69 | {% if user.is_authenticated %} |
|
71 | {% if user.is_authenticated %} | |
70 | <li class="dropdown"> |
|
72 | <li class="dropdown"> | |
71 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a> |
|
73 | <a href="#" class="dropdown-toggle" data-toggle="dropdown">Hi {{ user.username }}<span class="caret"></span></a> | |
72 | <ul class="dropdown-menu" role="menu"> |
|
74 | <ul class="dropdown-menu" role="menu"> | |
73 | <li><a href="#">Control Panel</a></li> |
|
75 | <li><a href="#">Control Panel</a></li> | |
74 | <li><a href="{% url 'django.contrib.auth.views.logout' %}">Logout</a></li> |
|
76 | <li><a href="{% url 'django.contrib.auth.views.logout' %}">Logout</a></li> | |
75 | </ul> |
|
77 | </ul> | |
76 | </li> |
|
78 | </li> | |
77 | {% else %} |
|
79 | {% else %} | |
78 | <li><a href="{% url 'django.contrib.auth.views.login' %}?next={{request.get_full_path}}">Login</a></li> |
|
80 | <li><a href="{% url 'django.contrib.auth.views.login' %}?next={{request.get_full_path}}">Login</a></li> | |
79 | {% endif %} |
|
81 | {% endif %} | |
80 | </ul> |
|
82 | </ul> | |
81 | </div> |
|
83 | </div> | |
82 | </div> |
|
84 | </div> | |
83 | </nav> |
|
85 | </nav> | |
84 | <div style="clear: both;"></div> |
|
86 | <div style="clear: both;"></div> | |
85 | {% endblock %} |
|
87 | {% endblock %} | |
86 |
|
88 | |||
87 | <div class="container"> |
|
89 | <div class="container"> | |
88 | <div id="page" class="row" style="min-height:600px"> |
|
90 | <div id="page" class="row" style="min-height:600px"> | |
89 |
|
91 | |||
90 | <div class="col-md-3 hidden-xs hidden-sm" role="complementary"> |
|
92 | <div class="col-md-3 hidden-xs hidden-sm" role="complementary"> | |
91 | <br><br> |
|
93 | <br><br> | |
92 | <div id="sidebar"> |
|
94 | <div id="sidebar"> | |
93 | {% block sidebar%} |
|
95 | {% block sidebar%} | |
94 | {% endblock %} |
|
96 | {% endblock %} | |
95 | </div> |
|
97 | </div> | |
96 | </div> |
|
98 | </div> | |
97 |
|
99 | |||
98 | <div class="col-md-9 col-xs-12" role="main"> |
|
100 | <div class="col-md-9 col-xs-12" role="main"> | |
99 | <div class="page-header"> |
|
101 | <div class="page-header"> | |
100 | <h1>{% block content-title %}{% endblock %} <small>{% block content-suptitle %}{% endblock %}</small></h1> |
|
102 | <h1>{% block content-title %}{% endblock %} <small>{% block content-suptitle %}{% endblock %}</small></h1> | |
101 | </div> |
|
103 | </div> | |
102 | {% block messages %} |
|
104 | {% block messages %} | |
103 | {% if messages %} |
|
105 | {% if messages %} | |
104 | {% for message in messages %} |
|
106 | {% for message in messages %} | |
105 | <div class="alert alert-{% if message.tags %}{% if 'error' in message.tags %}danger{% else %}{{ message.tags }}{% endif %}{% else %}info{% endif %} alert-dismissible" role="alert"> |
|
107 | <div class="alert alert-{% if message.tags %}{% if 'error' in message.tags %}danger{% else %}{{ message.tags }}{% endif %}{% else %}info{% endif %} alert-dismissible" role="alert"> | |
106 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> |
|
108 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> | |
107 | <strong>{{message.tags|title}}!</strong> {{ message }} |
|
109 | <strong>{{message.tags|title}}!</strong> {{ message }} | |
108 | </div> |
|
110 | </div> | |
109 | {% endfor %} |
|
111 | {% endfor %} | |
110 | {% endif %} |
|
112 | {% endif %} | |
111 | {% endblock %} |
|
113 | {% endblock %} | |
112 |
|
114 | |||
113 | {% block content %} |
|
115 | {% block content %} | |
114 | {% endblock %} |
|
116 | {% endblock %} | |
115 |
|
117 | |||
116 | </div> |
|
118 | </div> | |
117 |
|
119 | |||
118 | </div><!--/row--> |
|
120 | </div><!--/row--> | |
119 | </div> <!-- container --> |
|
121 | </div> <!-- container --> | |
120 |
|
122 | |||
121 | <div id="debug">{{debug}}</div> |
|
123 | <div id="debug">{{debug}}</div> | |
122 |
|
124 | |||
123 | {% block footer %} |
|
125 | {% block footer %} | |
124 | <footer class="footer"> |
|
126 | <footer class="footer"> | |
125 | <div class="container"> |
|
127 | <div class="container"> | |
126 | <p><hr></p> |
|
128 | <p><hr></p> | |
127 | <p> |
|
129 | <p> | |
128 | © <a href="http://jro.igp.gob.pe">Jicamarca Radio Observatory</a> - {% now "Y" %} |
|
130 | © <a href="http://jro.igp.gob.pe">Jicamarca Radio Observatory</a> - {% now "Y" %} | |
129 | </p> |
|
131 | </p> | |
130 | </div> |
|
132 | </div> | |
131 | </footer> |
|
133 | </footer> | |
132 | {% endblock %} |
|
134 | {% endblock %} | |
133 |
|
135 | |||
134 | {# bootstrap_javascript jquery=True #} |
|
136 | {# bootstrap_javascript jquery=True #} | |
135 | <script src="{% static 'js/jquery.min.js' %}"></script> |
|
137 | <script src="{% static 'js/jquery.min.js' %}"></script> | |
136 | <script src="{% static 'js/bootstrap.min.js' %}"></script> |
|
138 | <script src="{% static 'js/bootstrap.min.js' %}"></script> | |
137 | {% block extra-js %} |
|
139 | {% block extra-js %} | |
138 | {% endblock%} |
|
140 | {% endblock%} | |
139 | </body> |
|
141 | </body> | |
140 | </html> |
|
142 | </html> | |
141 |
|
143 |
@@ -1,72 +1,72 | |||||
1 | {% extends "base.html" %} |
|
1 | {% extends "base.html" %} | |
2 | {% load bootstrap3 %} |
|
2 | {% load bootstrap3 %} | |
3 | {% load static %} |
|
3 | {% load static %} | |
4 | {% load main_tags %} |
|
4 | {% load main_tags %} | |
5 |
|
5 | |||
6 | {% block conf-active %}active{% endblock %} |
|
6 | {% block conf-active %}active{% endblock %} | |
7 |
|
7 | |||
8 | {% block content-title %}{{title}}{% endblock %} |
|
8 | {% block content-title %}{{title}}{% endblock %} | |
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
9 | {% block content-suptitle %}{{suptitle}}{% endblock %} | |
10 |
|
10 | |||
11 | {% block content %} |
|
11 | {% block content %} | |
12 |
|
12 | |||
13 | <span class=" dropdown pull-right"> |
|
13 | <span class=" dropdown pull-right"> | |
14 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger" aria-hidden="true"></span> <span class="caret"></span></a> |
|
14 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger" aria-hidden="true"></span> <span class="caret"></span></a> | |
15 | <ul class="dropdown-menu" role="menu"> |
|
15 | <ul class="dropdown-menu" role="menu"> | |
16 | <li><a href="{{ dev_conf.get_absolute_url_edit }}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> |
|
16 | <li><a href="{{ dev_conf.get_absolute_url_edit }}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
17 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> |
|
17 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
18 | <li><a href="{{ dev_conf.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> |
|
18 | <li><a href="{{ dev_conf.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
19 | <li><a>----------------</a></li> |
|
19 | <li><a>----------------</a></li> | |
20 | <li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> |
|
20 | <li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> | |
21 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> |
|
21 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> | |
22 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> |
|
22 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> | |
23 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> |
|
23 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> | |
24 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li> |
|
24 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li> | |
25 | </ul> |
|
25 | </ul> | |
26 | </span> |
|
26 | </span> | |
27 |
|
27 | |||
28 | <table class="table table-bordered"> |
|
28 | <table class="table table-bordered"> | |
29 | <tr> |
|
29 | <tr> | |
30 | <th>Status</th> |
|
30 | <th>Status</th> | |
31 |
<td>{%if status %} <span class="glyphicon glyphicon-ok-circle text-success" aria-hidden="true"></span> {{status}} {% else %} <span class="glyphicon glyphicon-remove-circle text-danger" aria-hidden="true"></span> |
|
31 | <td>{%if status != "No connected" %} <span class="glyphicon glyphicon-ok-circle text-success" aria-hidden="true"></span> {{status}} {% else %} <span class="glyphicon glyphicon-remove-circle text-danger" aria-hidden="true"></span> {{status}} {% endif %}</td> | |
32 | </tr> |
|
32 | </tr> | |
33 |
|
33 | |||
34 | {% for key in dev_conf_keys %} |
|
34 | {% for key in dev_conf_keys %} | |
35 | <tr> |
|
35 | <tr> | |
36 | <th>{% get_verbose_field_name dev_conf key %}</th> |
|
36 | <th>{% get_verbose_field_name dev_conf key %}</th> | |
37 | <td>{{dev_conf|attr:key}}</td> |
|
37 | <td>{{dev_conf|attr:key}}</td> | |
38 | </tr> |
|
38 | </tr> | |
39 | {% endfor %} |
|
39 | {% endfor %} | |
40 | </table> |
|
40 | </table> | |
41 |
|
41 | |||
42 | {% endblock %} |
|
42 | {% endblock %} | |
43 |
|
43 | |||
44 | {% block sidebar%} |
|
44 | {% block sidebar%} | |
45 | {% include "sidebar_devices.html" %} |
|
45 | {% include "sidebar_devices.html" %} | |
46 | {% endblock %} |
|
46 | {% endblock %} | |
47 |
|
47 | |||
48 | {% block extra-js%} |
|
48 | {% block extra-js%} | |
49 | <script type="text/javascript"> |
|
49 | <script type="text/javascript"> | |
50 |
|
50 | |||
51 | $("#bt_edit").click(function() { |
|
51 | $("#bt_edit").click(function() { | |
52 | document.location = "{{ dev_conf.get_absolute_url_edit }}"; |
|
52 | document.location = "{{ dev_conf.get_absolute_url_edit }}"; | |
53 | }); |
|
53 | }); | |
54 |
|
54 | |||
55 | $("#bt_read").click(function() { |
|
55 | $("#bt_read").click(function() { | |
56 | document.location = "{{ dev_conf.get_absolute_url_read }}"; |
|
56 | document.location = "{{ dev_conf.get_absolute_url_read }}"; | |
57 | }); |
|
57 | }); | |
58 |
|
58 | |||
59 | $("#bt_write").click(function() { |
|
59 | $("#bt_write").click(function() { | |
60 | document.location = "{{ dev_conf.get_absolute_url_write }}"; |
|
60 | document.location = "{{ dev_conf.get_absolute_url_write }}"; | |
61 | }); |
|
61 | }); | |
62 |
|
62 | |||
63 | $("#bt_import").click(function() { |
|
63 | $("#bt_import").click(function() { | |
64 | document.location = "{{ dev_conf.get_absolute_url_import }}"; |
|
64 | document.location = "{{ dev_conf.get_absolute_url_import }}"; | |
65 | }); |
|
65 | }); | |
66 |
|
66 | |||
67 | $("#bt_export").click(function() { |
|
67 | $("#bt_export").click(function() { | |
68 | document.location = "{{ dev_conf.get_absolute_url_export }}"; |
|
68 | document.location = "{{ dev_conf.get_absolute_url_export }}"; | |
69 | }); |
|
69 | }); | |
70 |
|
70 | |||
71 | </script> |
|
71 | </script> | |
72 | {% endblock %} No newline at end of file |
|
72 | {% endblock %} |
@@ -1,799 +1,805 | |||||
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
2 | from django.contrib import messages |
|
2 | from django.contrib import messages | |
3 |
|
3 | |||
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm |
|
4 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm | |
5 | from apps.cgs.forms import CGSConfigurationForm |
|
5 | from apps.cgs.forms import CGSConfigurationForm | |
6 | from apps.jars.forms import JARSConfigurationForm |
|
6 | from apps.jars.forms import JARSConfigurationForm | |
7 | from apps.usrp.forms import USRPConfigurationForm |
|
7 | from apps.usrp.forms import USRPConfigurationForm | |
8 | from apps.abs.forms import ABSConfigurationForm |
|
8 | from apps.abs.forms import ABSConfigurationForm | |
9 | from apps.rc.forms import RCConfigurationForm |
|
9 | from apps.rc.forms import RCConfigurationForm | |
10 | from apps.dds.forms import DDSConfigurationForm |
|
10 | from apps.dds.forms import DDSConfigurationForm | |
11 |
|
11 | |||
12 | from .models import Campaign, Experiment, Device, Configuration, Location |
|
12 | from .models import Campaign, Experiment, Device, Configuration, Location | |
13 | from apps.cgs.models import CGSConfiguration |
|
13 | from apps.cgs.models import CGSConfiguration | |
14 | from apps.jars.models import JARSConfiguration |
|
14 | from apps.jars.models import JARSConfiguration | |
15 | from apps.usrp.models import USRPConfiguration |
|
15 | from apps.usrp.models import USRPConfiguration | |
16 | from apps.abs.models import ABSConfiguration |
|
16 | from apps.abs.models import ABSConfiguration | |
17 | from apps.rc.models import RCConfiguration |
|
17 | from apps.rc.models import RCConfiguration | |
18 | from apps.dds.models import DDSConfiguration |
|
18 | from apps.dds.models import DDSConfiguration | |
19 |
|
19 | |||
20 | # Create your views here. |
|
20 | # Create your views here. | |
21 |
|
21 | |||
22 | CONF_FORMS = { |
|
22 | CONF_FORMS = { | |
23 | 'rc': RCConfigurationForm, |
|
23 | 'rc': RCConfigurationForm, | |
24 | 'dds': DDSConfigurationForm, |
|
24 | 'dds': DDSConfigurationForm, | |
25 | 'jars': JARSConfigurationForm, |
|
25 | 'jars': JARSConfigurationForm, | |
26 | 'cgs': CGSConfigurationForm, |
|
26 | 'cgs': CGSConfigurationForm, | |
27 | 'abs': ABSConfigurationForm, |
|
27 | 'abs': ABSConfigurationForm, | |
28 | 'usrp': USRPConfigurationForm, |
|
28 | 'usrp': USRPConfigurationForm, | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | CONF_MODELS = { |
|
31 | CONF_MODELS = { | |
32 | 'rc': RCConfiguration, |
|
32 | 'rc': RCConfiguration, | |
33 | 'dds': DDSConfiguration, |
|
33 | 'dds': DDSConfiguration, | |
34 | 'jars': JARSConfiguration, |
|
34 | 'jars': JARSConfiguration, | |
35 | 'cgs': CGSConfiguration, |
|
35 | 'cgs': CGSConfiguration, | |
36 | 'abs': ABSConfiguration, |
|
36 | 'abs': ABSConfiguration, | |
37 | 'usrp': USRPConfiguration, |
|
37 | 'usrp': USRPConfiguration, | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | def index(request): |
|
40 | def index(request): | |
41 | kwargs = {} |
|
41 | kwargs = {} | |
42 |
|
42 | |||
43 | return render(request, 'index.html', kwargs) |
|
43 | return render(request, 'index.html', kwargs) | |
44 |
|
44 | |||
45 | def locations(request): |
|
45 | def locations(request): | |
46 |
|
46 | |||
47 | locations = Location.objects.all().order_by('name') |
|
47 | locations = Location.objects.all().order_by('name') | |
48 |
|
48 | |||
49 | keys = ['id', 'name', 'description'] |
|
49 | keys = ['id', 'name', 'description'] | |
50 |
|
50 | |||
51 | kwargs = {} |
|
51 | kwargs = {} | |
52 | kwargs['location_keys'] = keys[1:] |
|
52 | kwargs['location_keys'] = keys[1:] | |
53 | kwargs['locations'] = locations |
|
53 | kwargs['locations'] = locations | |
54 | kwargs['title'] = 'Location' |
|
54 | kwargs['title'] = 'Location' | |
55 | kwargs['suptitle'] = 'List' |
|
55 | kwargs['suptitle'] = 'List' | |
56 | kwargs['button'] = 'New Location' |
|
56 | kwargs['button'] = 'New Location' | |
57 |
|
57 | |||
58 | return render(request, 'locations.html', kwargs) |
|
58 | return render(request, 'locations.html', kwargs) | |
59 |
|
59 | |||
60 | def location(request, id_loc): |
|
60 | def location(request, id_loc): | |
61 |
|
61 | |||
62 | location = get_object_or_404(Location, pk=id_loc) |
|
62 | location = get_object_or_404(Location, pk=id_loc) | |
63 |
|
63 | |||
64 | kwargs = {} |
|
64 | kwargs = {} | |
65 | kwargs['location'] = location |
|
65 | kwargs['location'] = location | |
66 | kwargs['location_keys'] = ['name', 'description'] |
|
66 | kwargs['location_keys'] = ['name', 'description'] | |
67 |
|
67 | |||
68 | kwargs['title'] = 'Location' |
|
68 | kwargs['title'] = 'Location' | |
69 | kwargs['suptitle'] = 'Details' |
|
69 | kwargs['suptitle'] = 'Details' | |
70 |
|
70 | |||
71 | return render(request, 'location.html', kwargs) |
|
71 | return render(request, 'location.html', kwargs) | |
72 |
|
72 | |||
73 | def location_new(request): |
|
73 | def location_new(request): | |
74 |
|
74 | |||
75 | if request.method == 'GET': |
|
75 | if request.method == 'GET': | |
76 | form = LocationForm() |
|
76 | form = LocationForm() | |
77 |
|
77 | |||
78 | if request.method == 'POST': |
|
78 | if request.method == 'POST': | |
79 | form = LocationForm(request.POST) |
|
79 | form = LocationForm(request.POST) | |
80 |
|
80 | |||
81 | if form.is_valid(): |
|
81 | if form.is_valid(): | |
82 | form.save() |
|
82 | form.save() | |
83 | return redirect('url_locations') |
|
83 | return redirect('url_locations') | |
84 |
|
84 | |||
85 | kwargs = {} |
|
85 | kwargs = {} | |
86 | kwargs['form'] = form |
|
86 | kwargs['form'] = form | |
87 | kwargs['title'] = 'Location' |
|
87 | kwargs['title'] = 'Location' | |
88 | kwargs['suptitle'] = 'New' |
|
88 | kwargs['suptitle'] = 'New' | |
89 | kwargs['button'] = 'Create' |
|
89 | kwargs['button'] = 'Create' | |
90 |
|
90 | |||
91 | return render(request, 'location_edit.html', kwargs) |
|
91 | return render(request, 'location_edit.html', kwargs) | |
92 |
|
92 | |||
93 | def location_edit(request, id_loc): |
|
93 | def location_edit(request, id_loc): | |
94 |
|
94 | |||
95 | location = get_object_or_404(Location, pk=id_loc) |
|
95 | location = get_object_or_404(Location, pk=id_loc) | |
96 |
|
96 | |||
97 | if request.method=='GET': |
|
97 | if request.method=='GET': | |
98 | form = LocationForm(instance=location) |
|
98 | form = LocationForm(instance=location) | |
99 |
|
99 | |||
100 | if request.method=='POST': |
|
100 | if request.method=='POST': | |
101 | form = LocationForm(request.POST, instance=location) |
|
101 | form = LocationForm(request.POST, instance=location) | |
102 |
|
102 | |||
103 | if form.is_valid(): |
|
103 | if form.is_valid(): | |
104 | form.save() |
|
104 | form.save() | |
105 | return redirect('url_locations') |
|
105 | return redirect('url_locations') | |
106 |
|
106 | |||
107 | kwargs = {} |
|
107 | kwargs = {} | |
108 | kwargs['form'] = form |
|
108 | kwargs['form'] = form | |
109 | kwargs['title'] = 'Location' |
|
109 | kwargs['title'] = 'Location' | |
110 | kwargs['suptitle'] = 'Edit' |
|
110 | kwargs['suptitle'] = 'Edit' | |
111 | kwargs['button'] = 'Update' |
|
111 | kwargs['button'] = 'Update' | |
112 |
|
112 | |||
113 | return render(request, 'location_edit.html', kwargs) |
|
113 | return render(request, 'location_edit.html', kwargs) | |
114 |
|
114 | |||
115 | def location_delete(request, id_loc): |
|
115 | def location_delete(request, id_loc): | |
116 |
|
116 | |||
117 | location = get_object_or_404(Location, pk=id_loc) |
|
117 | location = get_object_or_404(Location, pk=id_loc) | |
118 |
|
118 | |||
119 | if request.method=='POST': |
|
119 | if request.method=='POST': | |
120 |
|
120 | |||
121 | if request.user.is_staff: |
|
121 | if request.user.is_staff: | |
122 | location.delete() |
|
122 | location.delete() | |
123 | return redirect('url_locations') |
|
123 | return redirect('url_locations') | |
124 |
|
124 | |||
125 | return HttpResponse("Not enough permission to delete this object") |
|
125 | return HttpResponse("Not enough permission to delete this object") | |
126 |
|
126 | |||
127 | kwargs = {'object':location, 'loc_active':'active', |
|
127 | kwargs = {'object':location, 'loc_active':'active', | |
128 | 'url_cancel':'url_location', 'id_item':id_loc} |
|
128 | 'url_cancel':'url_location', 'id_item':id_loc} | |
129 |
|
129 | |||
130 | return render(request, 'item_delete.html', kwargs) |
|
130 | return render(request, 'item_delete.html', kwargs) | |
131 |
|
131 | |||
132 | def devices(request): |
|
132 | def devices(request): | |
133 |
|
133 | |||
134 | devices = Device.objects.all().order_by('device_type__name') |
|
134 | devices = Device.objects.all().order_by('device_type__name') | |
135 |
|
135 | |||
136 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
136 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] | |
137 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
137 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] | |
138 |
|
138 | |||
139 | kwargs = {} |
|
139 | kwargs = {} | |
140 | kwargs['device_keys'] = keys[1:] |
|
140 | kwargs['device_keys'] = keys[1:] | |
141 | kwargs['devices'] = devices#.values(*keys) |
|
141 | kwargs['devices'] = devices#.values(*keys) | |
142 | kwargs['title'] = 'Device' |
|
142 | kwargs['title'] = 'Device' | |
143 | kwargs['suptitle'] = 'List' |
|
143 | kwargs['suptitle'] = 'List' | |
144 | kwargs['button'] = 'New Device' |
|
144 | kwargs['button'] = 'New Device' | |
145 |
|
145 | |||
146 | return render(request, 'devices.html', kwargs) |
|
146 | return render(request, 'devices.html', kwargs) | |
147 |
|
147 | |||
148 | def device(request, id_dev): |
|
148 | def device(request, id_dev): | |
149 |
|
149 | |||
150 | device = get_object_or_404(Device, pk=id_dev) |
|
150 | device = get_object_or_404(Device, pk=id_dev) | |
151 |
|
151 | |||
152 | kwargs = {} |
|
152 | kwargs = {} | |
153 | kwargs['device'] = device |
|
153 | kwargs['device'] = device | |
154 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
154 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] | |
155 |
|
155 | |||
156 | kwargs['title'] = 'Device' |
|
156 | kwargs['title'] = 'Device' | |
157 | kwargs['suptitle'] = 'Details' |
|
157 | kwargs['suptitle'] = 'Details' | |
158 |
|
158 | |||
159 | return render(request, 'device.html', kwargs) |
|
159 | return render(request, 'device.html', kwargs) | |
160 |
|
160 | |||
161 | def device_new(request): |
|
161 | def device_new(request): | |
162 |
|
162 | |||
163 | if request.method == 'GET': |
|
163 | if request.method == 'GET': | |
164 | form = DeviceForm() |
|
164 | form = DeviceForm() | |
165 |
|
165 | |||
166 | if request.method == 'POST': |
|
166 | if request.method == 'POST': | |
167 | form = DeviceForm(request.POST) |
|
167 | form = DeviceForm(request.POST) | |
168 |
|
168 | |||
169 | if form.is_valid(): |
|
169 | if form.is_valid(): | |
170 | form.save() |
|
170 | form.save() | |
171 | return redirect('url_devices') |
|
171 | return redirect('url_devices') | |
172 |
|
172 | |||
173 | kwargs = {} |
|
173 | kwargs = {} | |
174 | kwargs['form'] = form |
|
174 | kwargs['form'] = form | |
175 | kwargs['title'] = 'Device' |
|
175 | kwargs['title'] = 'Device' | |
176 | kwargs['suptitle'] = 'New' |
|
176 | kwargs['suptitle'] = 'New' | |
177 | kwargs['button'] = 'Create' |
|
177 | kwargs['button'] = 'Create' | |
178 |
|
178 | |||
179 | return render(request, 'device_edit.html', kwargs) |
|
179 | return render(request, 'device_edit.html', kwargs) | |
180 |
|
180 | |||
181 | def device_edit(request, id_dev): |
|
181 | def device_edit(request, id_dev): | |
182 |
|
182 | |||
183 | device = get_object_or_404(Device, pk=id_dev) |
|
183 | device = get_object_or_404(Device, pk=id_dev) | |
184 |
|
184 | |||
185 | if request.method=='GET': |
|
185 | if request.method=='GET': | |
186 | form = DeviceForm(instance=device) |
|
186 | form = DeviceForm(instance=device) | |
187 |
|
187 | |||
188 | if request.method=='POST': |
|
188 | if request.method=='POST': | |
189 | form = DeviceForm(request.POST, instance=device) |
|
189 | form = DeviceForm(request.POST, instance=device) | |
190 |
|
190 | |||
191 | if form.is_valid(): |
|
191 | if form.is_valid(): | |
192 | form.save() |
|
192 | form.save() | |
193 | return redirect('url_devices') |
|
193 | return redirect('url_devices') | |
194 |
|
194 | |||
195 | kwargs = {} |
|
195 | kwargs = {} | |
196 | kwargs['form'] = form |
|
196 | kwargs['form'] = form | |
197 | kwargs['title'] = 'Device' |
|
197 | kwargs['title'] = 'Device' | |
198 | kwargs['suptitle'] = 'Edit' |
|
198 | kwargs['suptitle'] = 'Edit' | |
199 | kwargs['button'] = 'Update' |
|
199 | kwargs['button'] = 'Update' | |
200 |
|
200 | |||
201 | return render(request, 'device_edit.html', kwargs) |
|
201 | return render(request, 'device_edit.html', kwargs) | |
202 |
|
202 | |||
203 | def device_delete(request, id_dev): |
|
203 | def device_delete(request, id_dev): | |
204 |
|
204 | |||
205 | device = get_object_or_404(Device, pk=id_dev) |
|
205 | device = get_object_or_404(Device, pk=id_dev) | |
206 |
|
206 | |||
207 | if request.method=='POST': |
|
207 | if request.method=='POST': | |
208 |
|
208 | |||
209 | if request.user.is_staff: |
|
209 | if request.user.is_staff: | |
210 | device.delete() |
|
210 | device.delete() | |
211 | return redirect('url_devices') |
|
211 | return redirect('url_devices') | |
212 |
|
212 | |||
213 | return HttpResponse("Not enough permission to delete this object") |
|
213 | return HttpResponse("Not enough permission to delete this object") | |
214 |
|
214 | |||
215 | kwargs = {'object':device, 'dev_active':'active', |
|
215 | kwargs = {'object':device, 'dev_active':'active', | |
216 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
216 | 'url_cancel':'url_device', 'id_item':id_dev} | |
217 |
|
217 | |||
218 | return render(request, 'item_delete.html', kwargs) |
|
218 | return render(request, 'item_delete.html', kwargs) | |
219 |
|
219 | |||
220 | def campaigns(request): |
|
220 | def campaigns(request): | |
221 |
|
221 | |||
222 | campaigns = Campaign.objects.all().order_by('start_date') |
|
222 | campaigns = Campaign.objects.all().order_by('start_date') | |
223 |
|
223 | |||
224 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
224 | keys = ['id', 'name', 'start_date', 'end_date'] | |
225 |
|
225 | |||
226 | kwargs = {} |
|
226 | kwargs = {} | |
227 | kwargs['campaign_keys'] = keys[1:] |
|
227 | kwargs['campaign_keys'] = keys[1:] | |
228 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
228 | kwargs['campaigns'] = campaigns#.values(*keys) | |
229 | kwargs['title'] = 'Campaign' |
|
229 | kwargs['title'] = 'Campaign' | |
230 | kwargs['suptitle'] = 'List' |
|
230 | kwargs['suptitle'] = 'List' | |
231 | kwargs['button'] = 'New Campaign' |
|
231 | kwargs['button'] = 'New Campaign' | |
232 |
|
232 | |||
233 | return render(request, 'campaigns.html', kwargs) |
|
233 | return render(request, 'campaigns.html', kwargs) | |
234 |
|
234 | |||
235 | def campaign(request, id_camp): |
|
235 | def campaign(request, id_camp): | |
236 |
|
236 | |||
237 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
237 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
238 | experiments = Experiment.objects.filter(campaign=campaign) |
|
238 | experiments = Experiment.objects.filter(campaign=campaign) | |
239 |
|
239 | |||
240 | form = CampaignForm(instance=campaign) |
|
240 | form = CampaignForm(instance=campaign) | |
241 |
|
241 | |||
242 | kwargs = {} |
|
242 | kwargs = {} | |
243 | kwargs['campaign'] = campaign |
|
243 | kwargs['campaign'] = campaign | |
244 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
244 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
245 |
|
245 | |||
246 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
246 | keys = ['id', 'name', 'start_time', 'end_time'] | |
247 |
|
247 | |||
248 | kwargs['experiment_keys'] = keys[1:] |
|
248 | kwargs['experiment_keys'] = keys[1:] | |
249 | kwargs['experiments'] = experiments.values(*keys) |
|
249 | kwargs['experiments'] = experiments.values(*keys) | |
250 |
|
250 | |||
251 | kwargs['title'] = 'Campaign' |
|
251 | kwargs['title'] = 'Campaign' | |
252 | kwargs['suptitle'] = 'Details' |
|
252 | kwargs['suptitle'] = 'Details' | |
253 |
|
253 | |||
254 | kwargs['form'] = form |
|
254 | kwargs['form'] = form | |
255 | kwargs['button'] = 'Add Experiment' |
|
255 | kwargs['button'] = 'Add Experiment' | |
256 |
|
256 | |||
257 | return render(request, 'campaign.html', kwargs) |
|
257 | return render(request, 'campaign.html', kwargs) | |
258 |
|
258 | |||
259 | def campaign_new(request): |
|
259 | def campaign_new(request): | |
260 |
|
260 | |||
261 | if request.method == 'GET': |
|
261 | if request.method == 'GET': | |
262 | form = CampaignForm() |
|
262 | form = CampaignForm() | |
263 |
|
263 | |||
264 | if request.method == 'POST': |
|
264 | if request.method == 'POST': | |
265 | form = CampaignForm(request.POST) |
|
265 | form = CampaignForm(request.POST) | |
266 |
|
266 | |||
267 | if form.is_valid(): |
|
267 | if form.is_valid(): | |
268 | campaign = form.save() |
|
268 | campaign = form.save() | |
269 | return redirect('url_campaign', id_camp=campaign.id) |
|
269 | return redirect('url_campaign', id_camp=campaign.id) | |
270 |
|
270 | |||
271 | kwargs = {} |
|
271 | kwargs = {} | |
272 | kwargs['form'] = form |
|
272 | kwargs['form'] = form | |
273 | kwargs['title'] = 'Campaign' |
|
273 | kwargs['title'] = 'Campaign' | |
274 | kwargs['suptitle'] = 'New' |
|
274 | kwargs['suptitle'] = 'New' | |
275 | kwargs['button'] = 'Create' |
|
275 | kwargs['button'] = 'Create' | |
276 |
|
276 | |||
277 | return render(request, 'campaign_edit.html', kwargs) |
|
277 | return render(request, 'campaign_edit.html', kwargs) | |
278 |
|
278 | |||
279 | def campaign_edit(request, id_camp): |
|
279 | def campaign_edit(request, id_camp): | |
280 |
|
280 | |||
281 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
281 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
282 |
|
282 | |||
283 | if request.method=='GET': |
|
283 | if request.method=='GET': | |
284 | form = CampaignForm(instance=campaign) |
|
284 | form = CampaignForm(instance=campaign) | |
285 |
|
285 | |||
286 | if request.method=='POST': |
|
286 | if request.method=='POST': | |
287 | form = CampaignForm(request.POST, instance=campaign) |
|
287 | form = CampaignForm(request.POST, instance=campaign) | |
288 |
|
288 | |||
289 | if form.is_valid(): |
|
289 | if form.is_valid(): | |
290 | form.save() |
|
290 | form.save() | |
291 | return redirect('url_campaign', id_camp=id_camp) |
|
291 | return redirect('url_campaign', id_camp=id_camp) | |
292 |
|
292 | |||
293 | kwargs = {} |
|
293 | kwargs = {} | |
294 | kwargs['form'] = form |
|
294 | kwargs['form'] = form | |
295 | kwargs['title'] = 'Campaign' |
|
295 | kwargs['title'] = 'Campaign' | |
296 | kwargs['suptitle'] = 'Edit' |
|
296 | kwargs['suptitle'] = 'Edit' | |
297 | kwargs['button'] = 'Update' |
|
297 | kwargs['button'] = 'Update' | |
298 |
|
298 | |||
299 | return render(request, 'campaign_edit.html', kwargs) |
|
299 | return render(request, 'campaign_edit.html', kwargs) | |
300 |
|
300 | |||
301 | def campaign_delete(request, id_camp): |
|
301 | def campaign_delete(request, id_camp): | |
302 |
|
302 | |||
303 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
303 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
304 |
|
304 | |||
305 | if request.method=='POST': |
|
305 | if request.method=='POST': | |
306 | if request.user.is_staff: |
|
306 | if request.user.is_staff: | |
307 | campaign.delete() |
|
307 | campaign.delete() | |
308 | return redirect('url_campaigns') |
|
308 | return redirect('url_campaigns') | |
309 |
|
309 | |||
310 | return HttpResponse("Not enough permission to delete this object") |
|
310 | return HttpResponse("Not enough permission to delete this object") | |
311 |
|
311 | |||
312 | kwargs = {'object':campaign, 'camp_active':'active', |
|
312 | kwargs = {'object':campaign, 'camp_active':'active', | |
313 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
313 | 'url_cancel':'url_campaign', 'id_item':id_camp} | |
314 |
|
314 | |||
315 | return render(request, 'item_delete.html', kwargs) |
|
315 | return render(request, 'item_delete.html', kwargs) | |
316 |
|
316 | |||
317 | def experiments(request): |
|
317 | def experiments(request): | |
318 |
|
318 | |||
319 | experiment_list = Experiment.objects.all().order_by('campaign') |
|
319 | experiment_list = Experiment.objects.all().order_by('campaign') | |
320 |
|
320 | |||
321 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] |
|
321 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] | |
322 |
|
322 | |||
323 | kwargs = {} |
|
323 | kwargs = {} | |
324 |
|
324 | |||
325 | kwargs['experiment_keys'] = keys[1:] |
|
325 | kwargs['experiment_keys'] = keys[1:] | |
326 | kwargs['experiments'] = experiment_list#.values(*keys) |
|
326 | kwargs['experiments'] = experiment_list#.values(*keys) | |
327 |
|
327 | |||
328 | kwargs['title'] = 'Experiment' |
|
328 | kwargs['title'] = 'Experiment' | |
329 | kwargs['suptitle'] = 'List' |
|
329 | kwargs['suptitle'] = 'List' | |
330 | kwargs['button'] = 'New Experiment' |
|
330 | kwargs['button'] = 'New Experiment' | |
331 |
|
331 | |||
332 | return render(request, 'experiments.html', kwargs) |
|
332 | return render(request, 'experiments.html', kwargs) | |
333 |
|
333 | |||
334 | def experiment(request, id_exp): |
|
334 | def experiment(request, id_exp): | |
335 |
|
335 | |||
336 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
336 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
337 |
|
337 | |||
338 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
338 | experiments = Experiment.objects.filter(campaign=experiment.campaign) | |
339 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
339 | configurations = Configuration.objects.filter(experiment=experiment, type=0) | |
340 |
|
340 | |||
341 | kwargs = {} |
|
341 | kwargs = {} | |
342 |
|
342 | |||
343 | exp_keys = ['id', 'campaign', 'location', 'name', 'start_time', 'end_time'] |
|
343 | exp_keys = ['id', 'campaign', 'location', 'name', 'start_time', 'end_time'] | |
344 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] |
|
344 | conf_keys = ['id', 'device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] | |
345 |
|
345 | |||
346 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] |
|
346 | conf_labels = ['id', 'device__name', 'device_type', 'ip_address', 'port_address'] | |
347 |
|
347 | |||
348 | kwargs['experiment_keys'] = exp_keys[1:] |
|
348 | kwargs['experiment_keys'] = exp_keys[1:] | |
349 | kwargs['experiment'] = experiment |
|
349 | kwargs['experiment'] = experiment | |
350 |
|
350 | |||
351 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
351 | kwargs['experiments'] = experiments.values(*exp_keys) | |
352 |
|
352 | |||
353 | kwargs['configuration_labels'] = conf_labels[1:] |
|
353 | kwargs['configuration_labels'] = conf_labels[1:] | |
354 | kwargs['configuration_keys'] = conf_keys[1:] |
|
354 | kwargs['configuration_keys'] = conf_keys[1:] | |
355 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
355 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
356 |
|
356 | |||
357 | kwargs['title'] = 'Experiment' |
|
357 | kwargs['title'] = 'Experiment' | |
358 | kwargs['suptitle'] = 'Details' |
|
358 | kwargs['suptitle'] = 'Details' | |
359 |
|
359 | |||
360 | kwargs['button'] = 'Add Configuration' |
|
360 | kwargs['button'] = 'Add Configuration' | |
361 |
|
361 | |||
362 | return render(request, 'experiment.html', kwargs) |
|
362 | return render(request, 'experiment.html', kwargs) | |
363 |
|
363 | |||
364 | def experiment_new(request, id_camp=0): |
|
364 | def experiment_new(request, id_camp=0): | |
365 |
|
365 | |||
366 | if request.method == 'GET': |
|
366 | if request.method == 'GET': | |
367 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
367 | form = ExperimentForm(initial={'campaign':id_camp}) | |
368 |
|
368 | |||
369 | if request.method == 'POST': |
|
369 | if request.method == 'POST': | |
370 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
370 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) | |
371 |
|
371 | |||
372 | if form.is_valid(): |
|
372 | if form.is_valid(): | |
373 | experiment = form.save() |
|
373 | experiment = form.save() | |
374 | return redirect('url_experiment', id_exp=experiment.id) |
|
374 | return redirect('url_experiment', id_exp=experiment.id) | |
375 |
|
375 | |||
376 | kwargs = {} |
|
376 | kwargs = {} | |
377 | kwargs['form'] = form |
|
377 | kwargs['form'] = form | |
378 | kwargs['title'] = 'Experiment' |
|
378 | kwargs['title'] = 'Experiment' | |
379 | kwargs['suptitle'] = 'New' |
|
379 | kwargs['suptitle'] = 'New' | |
380 | kwargs['button'] = 'Create' |
|
380 | kwargs['button'] = 'Create' | |
381 |
|
381 | |||
382 | return render(request, 'experiment_edit.html', kwargs) |
|
382 | return render(request, 'experiment_edit.html', kwargs) | |
383 |
|
383 | |||
384 | def experiment_edit(request, id_exp): |
|
384 | def experiment_edit(request, id_exp): | |
385 |
|
385 | |||
386 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
386 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
387 |
|
387 | |||
388 | if request.method == 'GET': |
|
388 | if request.method == 'GET': | |
389 | form = ExperimentForm(instance=experiment) |
|
389 | form = ExperimentForm(instance=experiment) | |
390 |
|
390 | |||
391 | if request.method=='POST': |
|
391 | if request.method=='POST': | |
392 | form = ExperimentForm(request.POST, instance=experiment) |
|
392 | form = ExperimentForm(request.POST, instance=experiment) | |
393 |
|
393 | |||
394 | if form.is_valid(): |
|
394 | if form.is_valid(): | |
395 | experiment = form.save() |
|
395 | experiment = form.save() | |
396 | return redirect('url_experiment', id_exp=experiment.id) |
|
396 | return redirect('url_experiment', id_exp=experiment.id) | |
397 |
|
397 | |||
398 | kwargs = {} |
|
398 | kwargs = {} | |
399 | kwargs['form'] = form |
|
399 | kwargs['form'] = form | |
400 | kwargs['title'] = 'Experiment' |
|
400 | kwargs['title'] = 'Experiment' | |
401 | kwargs['suptitle'] = 'Edit' |
|
401 | kwargs['suptitle'] = 'Edit' | |
402 | kwargs['button'] = 'Update' |
|
402 | kwargs['button'] = 'Update' | |
403 |
|
403 | |||
404 | return render(request, 'experiment_edit.html', kwargs) |
|
404 | return render(request, 'experiment_edit.html', kwargs) | |
405 |
|
405 | |||
406 | def experiment_delete(request, id_exp): |
|
406 | def experiment_delete(request, id_exp): | |
407 |
|
407 | |||
408 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
408 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
409 |
|
409 | |||
410 | if request.method=='POST': |
|
410 | if request.method=='POST': | |
411 | if request.user.is_staff: |
|
411 | if request.user.is_staff: | |
412 | id_camp = experiment.campaign.id |
|
412 | id_camp = experiment.campaign.id | |
413 | experiment.delete() |
|
413 | experiment.delete() | |
414 | return redirect('url_campaign', id_camp=id_camp) |
|
414 | return redirect('url_campaign', id_camp=id_camp) | |
415 |
|
415 | |||
416 | return HttpResponse("Not enough permission to delete this object") |
|
416 | return HttpResponse("Not enough permission to delete this object") | |
417 |
|
417 | |||
418 | kwargs = {'object':experiment, 'exp_active':'active', |
|
418 | kwargs = {'object':experiment, 'exp_active':'active', | |
419 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
419 | 'url_cancel':'url_experiment', 'id_item':id_exp} | |
420 |
|
420 | |||
421 | return render(request, 'item_delete.html', kwargs) |
|
421 | return render(request, 'item_delete.html', kwargs) | |
422 |
|
422 | |||
423 | def dev_confs(request): |
|
423 | def dev_confs(request): | |
424 |
|
424 | |||
425 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
425 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') | |
426 |
|
426 | |||
427 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
427 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] | |
428 |
|
428 | |||
429 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] |
|
429 | keys = ['id', 'device', 'experiment', 'type', 'programmed_date'] | |
430 |
|
430 | |||
431 | kwargs = {} |
|
431 | kwargs = {} | |
432 |
|
432 | |||
433 | kwargs['configuration_keys'] = keys[1:] |
|
433 | kwargs['configuration_keys'] = keys[1:] | |
434 | kwargs['configurations'] = configurations#.values(*keys) |
|
434 | kwargs['configurations'] = configurations#.values(*keys) | |
435 |
|
435 | |||
436 | kwargs['title'] = 'Configuration' |
|
436 | kwargs['title'] = 'Configuration' | |
437 | kwargs['suptitle'] = 'List' |
|
437 | kwargs['suptitle'] = 'List' | |
438 | kwargs['button'] = 'New Configuration' |
|
438 | kwargs['button'] = 'New Configuration' | |
439 |
|
439 | |||
440 | return render(request, 'dev_confs.html', kwargs) |
|
440 | return render(request, 'dev_confs.html', kwargs) | |
441 |
|
441 | |||
442 | def dev_conf(request, id_conf): |
|
442 | def dev_conf(request, id_conf): | |
443 |
|
443 | |||
444 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
444 | conf = get_object_or_404(Configuration, pk=id_conf) | |
445 |
|
445 | |||
446 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
446 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
447 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
447 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
448 |
|
448 | |||
449 | kwargs = {} |
|
449 | kwargs = {} | |
450 | kwargs['dev_conf'] = dev_conf |
|
450 | kwargs['dev_conf'] = dev_conf | |
451 | kwargs['dev_conf_keys'] = ['name', 'experiment', 'device'] |
|
451 | kwargs['dev_conf_keys'] = ['name', 'experiment', 'device'] | |
452 |
|
452 | |||
453 | kwargs['title'] = 'Configuration' |
|
453 | kwargs['title'] = 'Configuration' | |
454 | kwargs['suptitle'] = 'Details' |
|
454 | kwargs['suptitle'] = 'Details' | |
455 |
|
455 | |||
456 | kwargs['button'] = 'Edit Configuration' |
|
456 | kwargs['button'] = 'Edit Configuration' | |
457 |
|
457 | |||
458 | ###### SIDEBAR ###### |
|
458 | ###### SIDEBAR ###### | |
459 | kwargs.update(sidebar(conf)) |
|
459 | kwargs.update(sidebar(conf)) | |
460 |
|
460 | |||
461 | return render(request, 'dev_conf.html', kwargs) |
|
461 | return render(request, 'dev_conf.html', kwargs) | |
462 |
|
462 | |||
463 | def dev_conf_new(request, id_exp=0): |
|
463 | def dev_conf_new(request, id_exp=0): | |
464 |
|
464 | |||
465 | if request.method == 'GET': |
|
465 | if request.method == 'GET': | |
466 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
466 | form = ConfigurationForm(initial={'experiment':id_exp}) | |
467 |
|
467 | |||
468 | if request.method == 'POST': |
|
468 | if request.method == 'POST': | |
469 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
469 | experiment = Experiment.objects.get(pk=request.POST['experiment']) | |
470 | device = Device.objects.get(pk=request.POST['device']) |
|
470 | device = Device.objects.get(pk=request.POST['device']) | |
471 |
|
471 | |||
472 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
472 | DevConfForm = CONF_FORMS[device.device_type.name] | |
473 |
|
473 | |||
474 | form = DevConfForm(request.POST, initial={'experiment':experiment.id}) |
|
474 | form = DevConfForm(request.POST, initial={'experiment':experiment.id}) | |
475 |
|
475 | |||
476 | if form.is_valid(): |
|
476 | if form.is_valid(): | |
477 | dev_conf = form.save() |
|
477 | dev_conf = form.save() | |
478 |
|
478 | |||
479 | return redirect('url_experiment', id_exp=experiment.id) |
|
479 | return redirect('url_experiment', id_exp=experiment.id) | |
480 |
|
480 | |||
481 | kwargs = {} |
|
481 | kwargs = {} | |
482 | kwargs['form'] = form |
|
482 | kwargs['form'] = form | |
483 | kwargs['title'] = 'Configuration' |
|
483 | kwargs['title'] = 'Configuration' | |
484 | kwargs['suptitle'] = 'New' |
|
484 | kwargs['suptitle'] = 'New' | |
485 | kwargs['button'] = 'Create' |
|
485 | kwargs['button'] = 'Create' | |
486 |
|
486 | |||
487 | return render(request, 'dev_conf_edit.html', kwargs) |
|
487 | return render(request, 'dev_conf_edit.html', kwargs) | |
488 |
|
488 | |||
489 | def dev_conf_edit(request, id_conf): |
|
489 | def dev_conf_edit(request, id_conf): | |
490 |
|
490 | |||
491 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
491 | conf = get_object_or_404(Configuration, pk=id_conf) | |
492 |
|
492 | |||
493 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
493 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
494 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
494 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
495 |
|
495 | |||
496 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
496 | dev_conf = DevConfModel.objects.get(pk=id_conf) | |
497 |
|
497 | |||
498 | if request.method=='GET': |
|
498 | if request.method=='GET': | |
499 | form = DevConfForm(instance=dev_conf) |
|
499 | form = DevConfForm(instance=dev_conf) | |
500 |
|
500 | |||
501 | if request.method=='POST': |
|
501 | if request.method=='POST': | |
502 | form = DevConfForm(request.POST, instance=dev_conf) |
|
502 | form = DevConfForm(request.POST, instance=dev_conf) | |
503 |
|
503 | |||
504 | if form.is_valid(): |
|
504 | if form.is_valid(): | |
505 | form.save() |
|
505 | form.save() | |
506 | return redirect('url_dev_conf', id_conf=id_conf) |
|
506 | return redirect('url_dev_conf', id_conf=id_conf) | |
507 |
|
507 | |||
508 | kwargs = {} |
|
508 | kwargs = {} | |
509 | kwargs['form'] = form |
|
509 | kwargs['form'] = form | |
510 | kwargs['title'] = 'Device Configuration' |
|
510 | kwargs['title'] = 'Device Configuration' | |
511 | kwargs['suptitle'] = 'Edit' |
|
511 | kwargs['suptitle'] = 'Edit' | |
512 | kwargs['button'] = 'Update' |
|
512 | kwargs['button'] = 'Update' | |
513 |
|
513 | |||
514 | ###### SIDEBAR ###### |
|
514 | ###### SIDEBAR ###### | |
515 | kwargs.update(sidebar(conf)) |
|
515 | kwargs.update(sidebar(conf)) | |
516 |
|
516 | |||
517 |
return render(request, ' |
|
517 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
518 |
|
518 | |||
519 | def dev_conf_start(request, id_conf): |
|
519 | def dev_conf_start(request, id_conf): | |
520 |
|
520 | |||
521 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
521 | conf = get_object_or_404(Configuration, pk=id_conf) | |
522 |
|
522 | |||
523 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
523 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
524 |
|
524 | |||
525 | conf = DevConfModel.objects.get(pk=id_conf) |
|
525 | conf = DevConfModel.objects.get(pk=id_conf) | |
526 |
|
526 | |||
527 | if conf.start_device(): |
|
527 | if conf.start_device(): | |
528 | messages.success(request, conf.message) |
|
528 | messages.success(request, conf.message) | |
529 | else: |
|
529 | else: | |
530 | messages.error(request, conf.message) |
|
530 | messages.error(request, conf.message) | |
531 |
|
|
531 | ||
|
532 | conf.status_device() | |||
|
533 | ||||
532 | return redirect(conf.get_absolute_url()) |
|
534 | return redirect(conf.get_absolute_url()) | |
533 |
|
535 | |||
534 | def dev_conf_stop(request, id_conf): |
|
536 | def dev_conf_stop(request, id_conf): | |
535 |
|
537 | |||
536 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
538 | conf = get_object_or_404(Configuration, pk=id_conf) | |
537 |
|
539 | |||
538 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
540 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
539 |
|
541 | |||
540 | conf = DevConfModel.objects.get(pk=id_conf) |
|
542 | conf = DevConfModel.objects.get(pk=id_conf) | |
541 |
|
543 | |||
542 | if conf.stop_device(): |
|
544 | if conf.stop_device(): | |
543 | messages.success(request, conf.message) |
|
545 | messages.success(request, conf.message) | |
544 | else: |
|
546 | else: | |
545 | messages.error(request, conf.message) |
|
547 | messages.error(request, conf.message) | |
546 |
|
548 | |||
|
549 | conf.status_device() | |||
|
550 | ||||
547 | return redirect(conf.get_absolute_url()) |
|
551 | return redirect(conf.get_absolute_url()) | |
548 |
|
552 | |||
549 | def dev_conf_status(request, id_conf): |
|
553 | def dev_conf_status(request, id_conf): | |
550 |
|
554 | |||
551 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
555 | conf = get_object_or_404(Configuration, pk=id_conf) | |
552 |
|
556 | |||
553 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
557 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
554 |
|
558 | |||
555 | conf = DevConfModel.objects.get(pk=id_conf) |
|
559 | conf = DevConfModel.objects.get(pk=id_conf) | |
556 |
|
560 | |||
557 | if conf.status_device(): |
|
561 | if conf.status_device(): | |
558 | messages.success(request, conf.message) |
|
562 | messages.success(request, conf.message) | |
559 | else: |
|
563 | else: | |
560 | messages.error(request, conf.message) |
|
564 | messages.error(request, conf.message) | |
561 |
|
565 | |||
562 | return redirect(conf.get_absolute_url()) |
|
566 | return redirect(conf.get_absolute_url()) | |
563 |
|
567 | |||
564 |
|
568 | |||
565 | def dev_conf_write(request, id_conf): |
|
569 | def dev_conf_write(request, id_conf): | |
566 |
|
570 | |||
567 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
571 | conf = get_object_or_404(Configuration, pk=id_conf) | |
568 |
|
572 | |||
569 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
573 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
570 |
|
574 | |||
571 | conf = DevConfModel.objects.get(pk=id_conf) |
|
575 | conf = DevConfModel.objects.get(pk=id_conf) | |
572 |
|
576 | |||
573 | answer = conf.write_device() |
|
577 | answer = conf.write_device() | |
|
578 | conf.status_device() | |||
574 |
|
579 | |||
575 | if answer: |
|
580 | if answer: | |
576 | messages.success(request, conf.message) |
|
581 | messages.success(request, conf.message) | |
577 |
|
582 | |||
|
583 | #Creating a historical configuration | |||
578 | conf.pk = None |
|
584 | conf.pk = None | |
579 | conf.id = None |
|
585 | conf.id = None | |
580 | conf.type = 1 |
|
586 | conf.type = 1 | |
581 | conf.template = 0 |
|
587 | conf.template = 0 | |
582 | conf.save() |
|
588 | conf.save() | |
583 |
|
589 | |||
|
590 | #Original configuration | |||
|
591 | conf = DevConfModel.objects.get(pk=id_conf) | |||
584 | else: |
|
592 | else: | |
585 | messages.error(request, conf.message) |
|
593 | messages.error(request, conf.message) | |
586 |
|
594 | |||
587 | return redirect(conf.get_absolute_url()) |
|
595 | return redirect(conf.get_absolute_url()) | |
588 |
|
596 | |||
589 | def dev_conf_read(request, id_conf): |
|
597 | def dev_conf_read(request, id_conf): | |
590 |
|
598 | |||
591 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
599 | conf = get_object_or_404(Configuration, pk=id_conf) | |
592 |
|
600 | |||
593 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
601 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
594 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
602 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
595 |
|
603 | |||
596 | conf = DevConfModel.objects.get(pk=id_conf) |
|
604 | conf = DevConfModel.objects.get(pk=id_conf) | |
597 |
|
605 | |||
598 | if request.method=='GET': |
|
606 | if request.method=='GET': | |
599 |
|
607 | |||
600 | parms = conf.read_device() |
|
608 | parms = conf.read_device() | |
|
609 | conf.status_device() | |||
601 |
|
610 | |||
602 | if not parms: |
|
611 | if not parms: | |
603 | messages.error(request, conf.message) |
|
612 | messages.error(request, conf.message) | |
604 | return redirect(conf.get_absolute_url()) |
|
613 | return redirect(conf.get_absolute_url()) | |
605 |
|
614 | |||
606 | form = DevConfForm(initial=parms, instance=conf) |
|
615 | form = DevConfForm(initial=parms, instance=conf) | |
607 |
|
616 | |||
608 | if request.method=='POST': |
|
617 | if request.method=='POST': | |
609 | form = DevConfForm(request.POST, instance=conf) |
|
618 | form = DevConfForm(request.POST, instance=conf) | |
610 |
|
619 | |||
611 | if form.is_valid(): |
|
620 | if form.is_valid(): | |
612 |
|
|
621 | form.save() | |
613 |
|
622 | return redirect(conf.get_absolute_url()) | ||
614 | if dev_model.save(): |
|
|||
615 | return redirect(conf.get_absolute_url()) |
|
|||
616 |
|
623 | |||
617 | messages.error(request, "Parameters could not be saved") |
|
624 | messages.error(request, "Parameters could not be saved") | |
618 |
|
625 | |||
619 | kwargs = {} |
|
626 | kwargs = {} | |
620 | kwargs['id_dev'] = conf.id |
|
627 | kwargs['id_dev'] = conf.id | |
621 | kwargs['form'] = form |
|
628 | kwargs['form'] = form | |
622 | kwargs['title'] = 'Device Configuration' |
|
629 | kwargs['title'] = 'Device Configuration' | |
623 | kwargs['suptitle'] = 'Parameters read from device' |
|
630 | kwargs['suptitle'] = 'Parameters read from device' | |
624 | kwargs['button'] = 'Save' |
|
631 | kwargs['button'] = 'Save' | |
625 |
|
632 | |||
626 | ###### SIDEBAR ###### |
|
633 | ###### SIDEBAR ###### | |
627 | kwargs.update(sidebar(conf)) |
|
634 | kwargs.update(sidebar(conf)) | |
628 |
|
635 | |||
629 | return render(conf.get_absolute_url_edit()) |
|
636 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
630 |
|
637 | |||
631 | def dev_conf_import(request, id_conf): |
|
638 | def dev_conf_import(request, id_conf): | |
632 |
|
639 | |||
633 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
640 | conf = get_object_or_404(Configuration, pk=id_conf) | |
634 |
|
641 | |||
635 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
642 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
636 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
643 | DevConfForm = CONF_FORMS[conf.device.device_type.name] | |
637 |
|
644 | |||
638 | conf = DevConfModel.objects.get(pk=id_conf) |
|
645 | conf = DevConfModel.objects.get(pk=id_conf) | |
639 |
|
646 | |||
640 | if request.method == 'GET': |
|
647 | if request.method == 'GET': | |
641 | file_form = UploadFileForm() |
|
648 | file_form = UploadFileForm() | |
642 |
|
649 | |||
643 | if request.method == 'POST': |
|
650 | if request.method == 'POST': | |
644 | file_form = UploadFileForm(request.POST, request.FILES) |
|
651 | file_form = UploadFileForm(request.POST, request.FILES) | |
645 |
|
652 | |||
646 | if file_form.is_valid(): |
|
653 | if file_form.is_valid(): | |
647 |
|
654 | |||
648 | parms = conf.import_from_file(request.FILES['file']) |
|
655 | parms = conf.import_from_file(request.FILES['file']) | |
649 |
|
656 | |||
650 | if parms: |
|
657 | if parms: | |
651 |
|
||||
652 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
658 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) | |
653 |
|
659 | print parms | ||
654 | form = DevConfForm(initial=parms, instance=conf) |
|
660 | form = DevConfForm(initial=parms, instance=conf) | |
655 |
|
661 | |||
656 | kwargs = {} |
|
662 | kwargs = {} | |
657 | kwargs['id_dev'] = conf.id |
|
663 | kwargs['id_dev'] = conf.id | |
658 | kwargs['form'] = form |
|
664 | kwargs['form'] = form | |
659 | kwargs['title'] = 'Device Configuration' |
|
665 | kwargs['title'] = 'Device Configuration' | |
660 | kwargs['suptitle'] = 'Parameters imported' |
|
666 | kwargs['suptitle'] = 'Parameters imported' | |
661 | kwargs['button'] = 'Save' |
|
667 | kwargs['button'] = 'Save' | |
662 | kwargs['action'] = conf.get_absolute_url_edit() |
|
668 | kwargs['action'] = conf.get_absolute_url_edit() | |
663 | kwargs['previous'] = conf.get_absolute_url() |
|
669 | kwargs['previous'] = conf.get_absolute_url() | |
664 |
|
670 | |||
665 | ###### SIDEBAR ###### |
|
671 | ###### SIDEBAR ###### | |
666 | kwargs.update(sidebar(conf)) |
|
672 | kwargs.update(sidebar(conf)) | |
667 |
|
673 | |||
668 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
674 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) | |
669 |
|
675 | |||
670 | messages.error(request, "Could not import parameters from file") |
|
676 | messages.error(request, "Could not import parameters from file") | |
671 |
|
677 | |||
672 | kwargs = {} |
|
678 | kwargs = {} | |
673 | kwargs['id_dev'] = conf.id |
|
679 | kwargs['id_dev'] = conf.id | |
674 | kwargs['title'] = 'Device Configuration' |
|
680 | kwargs['title'] = 'Device Configuration' | |
675 | kwargs['form'] = file_form |
|
681 | kwargs['form'] = file_form | |
676 | kwargs['suptitle'] = 'Importing file' |
|
682 | kwargs['suptitle'] = 'Importing file' | |
677 | kwargs['button'] = 'Import' |
|
683 | kwargs['button'] = 'Import' | |
678 |
|
684 | |||
679 | kwargs.update(sidebar(conf)) |
|
685 | kwargs.update(sidebar(conf)) | |
680 |
|
686 | |||
681 | return render(request, 'dev_conf_import.html', kwargs) |
|
687 | return render(request, 'dev_conf_import.html', kwargs) | |
682 |
|
688 | |||
683 | def dev_conf_export(request, id_conf): |
|
689 | def dev_conf_export(request, id_conf): | |
684 |
|
690 | |||
685 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
691 | conf = get_object_or_404(Configuration, pk=id_conf) | |
686 |
|
692 | |||
687 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
693 | DevConfModel = CONF_MODELS[conf.device.device_type.name] | |
688 |
|
694 | |||
689 | conf = DevConfModel.objects.get(pk=id_conf) |
|
695 | conf = DevConfModel.objects.get(pk=id_conf) | |
690 |
|
696 | |||
691 | if request.method == 'GET': |
|
697 | if request.method == 'GET': | |
692 | file_form = DownloadFileForm() |
|
698 | file_form = DownloadFileForm(conf.device.device_type.name) | |
693 |
|
699 | |||
694 | if request.method == 'POST': |
|
700 | if request.method == 'POST': | |
695 | file_form = DownloadFileForm(request.POST) |
|
701 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) | |
696 |
|
702 | |||
697 | if file_form.is_valid(): |
|
703 | if file_form.is_valid(): | |
698 | fields = conf.export_to_file(format = file_form.format) |
|
704 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) | |
699 |
|
705 | |||
700 | response = HttpResponse(content_type=fields['content_type']) |
|
706 | response = HttpResponse(content_type=fields['content_type']) | |
701 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
707 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] | |
702 | response.write(fields['content']) |
|
708 | response.write(fields['content']) | |
703 |
|
709 | |||
704 | return response |
|
710 | return response | |
705 |
|
711 | |||
706 | messages.error(request, "Could not export parameters") |
|
712 | messages.error(request, "Could not export parameters") | |
707 |
|
713 | |||
708 | kwargs = {} |
|
714 | kwargs = {} | |
709 | kwargs['id_dev'] = conf.id |
|
715 | kwargs['id_dev'] = conf.id | |
710 | kwargs['title'] = 'Device Configuration' |
|
716 | kwargs['title'] = 'Device Configuration' | |
711 | kwargs['form'] = file_form |
|
717 | kwargs['form'] = file_form | |
712 | kwargs['suptitle'] = 'Exporting file' |
|
718 | kwargs['suptitle'] = 'Exporting file' | |
713 | kwargs['button'] = 'Export' |
|
719 | kwargs['button'] = 'Export' | |
714 |
|
720 | |||
715 | return render(request, 'dev_conf_export.html', kwargs) |
|
721 | return render(request, 'dev_conf_export.html', kwargs) | |
716 |
|
722 | |||
717 | def dev_conf_delete(request, id_conf): |
|
723 | def dev_conf_delete(request, id_conf): | |
718 |
|
724 | |||
719 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
725 | conf = get_object_or_404(Configuration, pk=id_conf) | |
720 |
|
726 | |||
721 | if request.method=='POST': |
|
727 | if request.method=='POST': | |
722 | if request.user.is_staff: |
|
728 | if request.user.is_staff: | |
723 | id_exp = conf.experiment.id |
|
729 | id_exp = conf.experiment.id | |
724 | conf.delete() |
|
730 | conf.delete() | |
725 | return redirect('url_experiment', id_exp=id_exp) |
|
731 | return redirect('url_experiment', id_exp=id_exp) | |
726 |
|
732 | |||
727 | return HttpResponse("Not enough permission to delete this object") |
|
733 | return HttpResponse("Not enough permission to delete this object") | |
728 |
|
734 | |||
729 | kwargs = {'object':conf, 'conf_active':'active', |
|
735 | kwargs = {'object':conf, 'conf_active':'active', | |
730 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
736 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} | |
731 |
|
737 | |||
732 | ###### SIDEBAR ###### |
|
738 | ###### SIDEBAR ###### | |
733 | kwargs.update(sidebar(conf)) |
|
739 | kwargs.update(sidebar(conf)) | |
734 |
|
740 | |||
735 | return render(request, 'item_delete.html', kwargs) |
|
741 | return render(request, 'item_delete.html', kwargs) | |
736 |
|
742 | |||
737 | def sidebar(conf): |
|
743 | def sidebar(conf): | |
738 |
|
744 | |||
739 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
745 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
740 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) |
|
746 | configurations = Configuration.objects.filter(experiment=conf.experiment, type=0) | |
741 |
|
747 | |||
742 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
748 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
743 | conf_keys = ['id', 'device'] |
|
749 | conf_keys = ['id', 'device'] | |
744 |
|
750 | |||
745 | kwargs = {} |
|
751 | kwargs = {} | |
746 |
|
752 | |||
747 | kwargs['dev_conf'] = conf |
|
753 | kwargs['dev_conf'] = conf | |
748 |
|
754 | |||
749 | kwargs['experiment_keys'] = exp_keys[1:] |
|
755 | kwargs['experiment_keys'] = exp_keys[1:] | |
750 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
756 | kwargs['experiments'] = experiments.values(*exp_keys) | |
751 |
|
757 | |||
752 | kwargs['configuration_keys'] = conf_keys[1:] |
|
758 | kwargs['configuration_keys'] = conf_keys[1:] | |
753 | kwargs['configurations'] = configurations #.values(*conf_keys) |
|
759 | kwargs['configurations'] = configurations #.values(*conf_keys) | |
754 |
|
760 | |||
755 | return kwargs |
|
761 | return kwargs | |
756 |
|
762 | |||
757 |
|
763 | |||
758 | def operation(request, id_camp=None): |
|
764 | def operation(request, id_camp=None): | |
759 |
|
765 | |||
760 | if not id_camp: |
|
766 | if not id_camp: | |
761 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
767 | campaigns = Campaign.objects.all().order_by('-start_date') | |
762 |
|
768 | |||
763 | if not campaigns: |
|
769 | if not campaigns: | |
764 | return render(request, 'operation.html', {}) |
|
770 | return render(request, 'operation.html', {}) | |
765 |
|
771 | |||
766 | id_camp = campaigns[0].id |
|
772 | id_camp = campaigns[0].id | |
767 |
|
773 | |||
768 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
774 | campaign = get_object_or_404(Campaign, pk = id_camp) | |
769 |
|
775 | |||
770 | if request.method=='GET': |
|
776 | if request.method=='GET': | |
771 | form = OperationForm(initial={'campaign': id_camp}) |
|
777 | form = OperationForm(initial={'campaign': id_camp}) | |
772 |
|
778 | |||
773 | if request.method=='POST': |
|
779 | if request.method=='POST': | |
774 | form = OperationForm(request.POST, initial={'campaign':campaign.id}) |
|
780 | form = OperationForm(request.POST, initial={'campaign':campaign.id}) | |
775 |
|
781 | |||
776 | if form.is_valid(): |
|
782 | if form.is_valid(): | |
777 | return redirect('url_operation', id_camp=campaign.id) |
|
783 | return redirect('url_operation', id_camp=campaign.id) | |
778 |
|
784 | |||
779 | locations = Location.objects.filter(experiment__campaign__pk = campaign.id) |
|
785 | locations = Location.objects.filter(experiment__campaign__pk = campaign.id) | |
780 | experiments = Experiment.objects.filter(campaign=campaign) |
|
786 | experiments = Experiment.objects.filter(campaign=campaign) | |
781 | experiments = [Experiment.objects.filter(location__pk=location.id) for location in locations] |
|
787 | experiments = [Experiment.objects.filter(location__pk=location.id) for location in locations] | |
782 |
|
788 | |||
783 | kwargs = {} |
|
789 | kwargs = {} | |
784 | #---Campaign |
|
790 | #---Campaign | |
785 | kwargs['campaign'] = campaign |
|
791 | kwargs['campaign'] = campaign | |
786 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
792 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] | |
787 | #---Experimet |
|
793 | #---Experimet | |
788 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
794 | keys = ['id', 'name', 'start_time', 'end_time'] | |
789 | kwargs['experiment_keys'] = keys[1:] |
|
795 | kwargs['experiment_keys'] = keys[1:] | |
790 | kwargs['experiments'] = experiments |
|
796 | kwargs['experiments'] = experiments | |
791 | #---Radar |
|
797 | #---Radar | |
792 | kwargs['locations'] = locations |
|
798 | kwargs['locations'] = locations | |
793 | #---Else |
|
799 | #---Else | |
794 | kwargs['title'] = 'Campaign' |
|
800 | kwargs['title'] = 'Campaign' | |
795 | kwargs['suptitle'] = campaign.name |
|
801 | kwargs['suptitle'] = campaign.name | |
796 | kwargs['form'] = form |
|
802 | kwargs['form'] = form | |
797 | kwargs['button'] = 'Apply' |
|
803 | kwargs['button'] = 'Apply' | |
798 |
|
804 | |||
799 | return render(request, 'operation.html', kwargs) No newline at end of file |
|
805 | return render(request, 'operation.html', kwargs) |
@@ -1,926 +1,926 | |||||
1 | import ast |
|
1 | import ast | |
2 | import json |
|
2 | import json | |
3 | import numpy as np |
|
3 | # import numpy as np | |
4 | import matplotlib.pyplot as plt |
|
4 | # import matplotlib.pyplot as plt | |
5 | from matplotlib import cm |
|
5 | # from matplotlib import cm | |
6 |
|
6 | |||
7 | class Pulse_Design_Racp: |
|
7 | class Pulse_Design_Racp: | |
8 | """A class to define the .racp output from Pulse Design """ |
|
8 | """A class to define the .racp output from Pulse Design """ | |
9 | def __init__(self): |
|
9 | def __init__(self): | |
10 | self.header = {'version': '1103', 'data':[]} |
|
10 | self.header = {'version': '1103', 'data':[]} | |
11 | self.radar_param = {'header': '*****Radar Controller Parameters**********', 'data':[]} |
|
11 | self.radar_param = {'header': '*****Radar Controller Parameters**********', 'data':[]} | |
12 | self.system_param1 = {'header': '******System Parameters*******************', 'data':[]} |
|
12 | self.system_param1 = {'header': '******System Parameters*******************', 'data':[]} | |
13 | self.system_param2 = {'header': '******System Parameters*******************', 'data':[]} |
|
13 | self.system_param2 = {'header': '******System Parameters*******************', 'data':[]} | |
14 | self.process_param = {'header': '******Process Parameters******************', 'data':[]} |
|
14 | self.process_param = {'header': '******Process Parameters******************', 'data':[]} | |
15 | self.xml = None |
|
15 | self.xml = None | |
16 |
|
16 | |||
17 | self.header_fields = [ |
|
17 | self.header_fields = [ | |
18 | {'name': 'EXPERIMENT TYPE', 'xml': 'Experiment/Process/Signal_pre_processing/Type_of_experiment'}, |
|
18 | {'name': 'EXPERIMENT TYPE', 'xml': 'Experiment/Process/Signal_pre_processing/Type_of_experiment'}, | |
19 | {'name': 'EXPERIMENT NAME', 'xml': 'Experiment', 'xml_attr_value':'name'}] |
|
19 | {'name': 'EXPERIMENT NAME', 'xml': 'Experiment', 'xml_attr_value':'name'}] | |
20 | self.radar_param_fields = [ |
|
20 | self.radar_param_fields = [ | |
21 | {'name': 'IPP', 'xml': 'Experiment/Controller/IPP/Width'}, |
|
21 | {'name': 'IPP', 'xml': 'Experiment/Controller/IPP/Width'}, | |
22 | {'name': 'NTX', 'xml': 'Experiment/Controller/NTX'}, |
|
22 | {'name': 'NTX', 'xml': 'Experiment/Controller/NTX'}, | |
23 | {'name': 'TXA', 'xml': 'Experiment/Controller/Transmitters/TX', 'xml_attr':'id', 'xml_attr_find':'txa', 'xml_sub_pattern':'Width'}, |
|
23 | {'name': 'TXA', 'xml': 'Experiment/Controller/Transmitters/TX', 'xml_attr':'id', 'xml_attr_find':'txa', 'xml_sub_pattern':'Width'}, | |
24 | {'name': 'TXB', 'xml': 'Experiment/Controller/Transmitters/TX', 'xml_attr':'id', 'xml_attr_find':'txb', 'xml_sub_pattern':'Width'}, |
|
24 | {'name': 'TXB', 'xml': 'Experiment/Controller/Transmitters/TX', 'xml_attr':'id', 'xml_attr_find':'txb', 'xml_sub_pattern':'Width'}, | |
25 | {'name': '***', 'xml':'', 'type':'pulse_enable'}, |
|
25 | {'name': '***', 'xml':'', 'type':'pulse_enable'}, | |
26 | {'name': '***', 'xml':'', 'type': 'Line4'}, |
|
26 | {'name': '***', 'xml':'', 'type': 'Line4'}, | |
27 | {'name': '***', 'xml':'', 'type': 'Line5'}, |
|
27 | {'name': '***', 'xml':'', 'type': 'Line5'}, | |
28 | {'name': '***', 'xml':'', 'type': 'Line6'}, |
|
28 | {'name': '***', 'xml':'', 'type': 'Line6'}, | |
29 | {'name': '***', 'xml':'', 'type':'txb_delays_info'}, |
|
29 | {'name': '***', 'xml':'', 'type':'txb_delays_info'}, | |
30 | {'name': '***', 'xml':'', 'type': 'Line7'}, |
|
30 | {'name': '***', 'xml':'', 'type': 'Line7'}, | |
31 | {'name': 'SAMPLING REFERENCE', 'xml':'Experiment/Controller/Ctl_Setting/Sampling_reference'}, |
|
31 | {'name': 'SAMPLING REFERENCE', 'xml':'Experiment/Controller/Ctl_Setting/Sampling_reference'}, | |
32 | {'name': 'RELOJ', 'xml':'Experiment/Controller/Clock/Clock_final'}, |
|
32 | {'name': 'RELOJ', 'xml':'Experiment/Controller/Clock/Clock_final'}, | |
33 | {'name': 'CLOCK DIVIDER', 'xml':'Experiment/Controller/Clock/Clock_div', 'hide':['1']}, |
|
33 | {'name': 'CLOCK DIVIDER', 'xml':'Experiment/Controller/Clock/Clock_div', 'hide':['1']}, | |
34 | {'name': 'TR_BEFORE', 'xml':'Experiment/Controller/Spc_Setting/Time_before'}, |
|
34 | {'name': 'TR_BEFORE', 'xml':'Experiment/Controller/Spc_Setting/Time_before'}, | |
35 | {'name': 'TR_AFTER', 'xml':'Experiment/Controller/Spc_Setting/Time_after'}, |
|
35 | {'name': 'TR_AFTER', 'xml':'Experiment/Controller/Spc_Setting/Time_after'}, | |
36 | {'name': 'WINDOW IN LINE 5&6', 'xml':'', 'value':'NO'}, |
|
36 | {'name': 'WINDOW IN LINE 5&6', 'xml':'', 'value':'NO'}, | |
37 | {'name': 'SYNCHRO DELAY', 'xml':'Experiment/Controller/Spc_Setting/Sync_delay', 'hide':['0']}] |
|
37 | {'name': 'SYNCHRO DELAY', 'xml':'Experiment/Controller/Spc_Setting/Sync_delay', 'hide':['0']}] | |
38 | self.system_param1_fields = [ |
|
38 | self.system_param1_fields = [ | |
39 | {'name': 'Number of Cards', 'xml':'Experiment/Process/JARS/Number_of_cards', 'hide':['0']}, |
|
39 | {'name': 'Number of Cards', 'xml':'Experiment/Process/JARS/Number_of_cards', 'hide':['0']}, | |
40 | {'name': '***', 'xml':'', 'type':'cards_info'}, |
|
40 | {'name': '***', 'xml':'', 'type':'cards_info'}, | |
41 | {'name': '***', 'xml':'', 'type':'channels_info'}, |
|
41 | {'name': '***', 'xml':'', 'type':'channels_info'}, | |
42 | {'name': 'RAW DATA DIRECTORY', 'xml':'Experiment/Process/Data_storage/Directory'}, |
|
42 | {'name': 'RAW DATA DIRECTORY', 'xml':'Experiment/Process/Data_storage/Directory'}, | |
43 | {'name': 'CREATE DIRECTORY PER DAY', 'xml':'Experiment/Process/Data_storage/Directory_per_day', 'type':'checkbox_YES_NO'}, |
|
43 | {'name': 'CREATE DIRECTORY PER DAY', 'xml':'Experiment/Process/Data_storage/Directory_per_day', 'type':'checkbox_YES_NO'}, | |
44 | {'name': 'INCLUDE EXPNAME IN DIRECTORY', 'xml':'Experiment/Process/Data_storage/Expname_in_directory', 'type':'checkbox_YES_NO'}] |
|
44 | {'name': 'INCLUDE EXPNAME IN DIRECTORY', 'xml':'Experiment/Process/Data_storage/Expname_in_directory', 'type':'checkbox_YES_NO'}] | |
45 | self.system_param2_fields = [ |
|
45 | self.system_param2_fields = [ | |
46 | {'name': 'ADC Resolution', 'xml':'', 'value':'12'}, # Default is 8, JARS is 12 |
|
46 | {'name': 'ADC Resolution', 'xml':'', 'value':'12'}, # Default is 8, JARS is 12 | |
47 | {'name': 'PCI DIO BusWidth', 'xml':'', 'value':'32'}, # Default for JARS |
|
47 | {'name': 'PCI DIO BusWidth', 'xml':'', 'value':'32'}, # Default for JARS | |
48 | {'name': 'RAW DATA BLOCKS', 'xml':'Experiment/Process/Data_arrangement/Data_blocks'}] |
|
48 | {'name': 'RAW DATA BLOCKS', 'xml':'Experiment/Process/Data_arrangement/Data_blocks'}] | |
49 | self.process_param_fields = [ |
|
49 | self.process_param_fields = [ | |
50 | {'name': 'DATATYPE', 'xml': 'Experiment/Process/Signal_pre_processing/Type_of_data'}, |
|
50 | {'name': 'DATATYPE', 'xml': 'Experiment/Process/Signal_pre_processing/Type_of_data'}, | |
51 | {'name': 'DATA ARRANGE', 'xml':'', 'value':'CONTIGUOUS_CH'}, #TODO |
|
51 | {'name': 'DATA ARRANGE', 'xml':'', 'value':'CONTIGUOUS_CH'}, #TODO | |
52 | {'name': 'COHERENT INTEGRATION STRIDE', 'xml':'Experiment/Process/Signal_pre_processing/Integration_stride'}, |
|
52 | {'name': 'COHERENT INTEGRATION STRIDE', 'xml':'Experiment/Process/Signal_pre_processing/Integration_stride'}, | |
53 | {'name': '------------------', 'xml':'', 'type':'separator'}, |
|
53 | {'name': '------------------', 'xml':'', 'type':'separator'}, | |
54 | {'name': 'ACQUIRED PROFILES', 'xml':'Experiment/Process/Data_arrangement/Acquired_profiles'}, |
|
54 | {'name': 'ACQUIRED PROFILES', 'xml':'Experiment/Process/Data_arrangement/Acquired_profiles'}, | |
55 | {'name': 'PROFILES PER BLOCK', 'xml':'Experiment/Process/Data_arrangement/Profiles_per_block'}, |
|
55 | {'name': 'PROFILES PER BLOCK', 'xml':'Experiment/Process/Data_arrangement/Profiles_per_block'}, | |
56 | {'name': '------------------', 'xml':'', 'type':'separator'}, |
|
56 | {'name': '------------------', 'xml':'', 'type':'separator'}, | |
57 | {'name': 'BEGIN ON START', 'xml':'Experiment/Process/Schedule/Begin_on_Start', 'type': 'checkbox_YES_NO'}, |
|
57 | {'name': 'BEGIN ON START', 'xml':'Experiment/Process/Schedule/Begin_on_Start', 'type': 'checkbox_YES_NO'}, | |
58 | {'name': 'BEGIN_TIME', 'xml':'Experiment/Process/Schedule/Start', 'hide':['']}, |
|
58 | {'name': 'BEGIN_TIME', 'xml':'Experiment/Process/Schedule/Start', 'hide':['']}, | |
59 | {'name': 'END_TIME', 'xml':'Experiment/Process/Schedule/End', 'hide':['']}, |
|
59 | {'name': 'END_TIME', 'xml':'Experiment/Process/Schedule/End', 'hide':['']}, | |
60 | {'name': 'VIEW RAW DATA', 'xml':'Experiment/Process/Data_arrangement/View_raw_data', 'type': 'checkbox_YES_NO'}, |
|
60 | {'name': 'VIEW RAW DATA', 'xml':'Experiment/Process/Data_arrangement/View_raw_data', 'type': 'checkbox_YES_NO'}, | |
61 | {'name': 'REFRESH RATE', 'xml':'', 'value':'1'}, #TODO |
|
61 | {'name': 'REFRESH RATE', 'xml':'', 'value':'1'}, #TODO | |
62 | {'name': '------------------', 'xml':'', 'type':'separator'}, |
|
62 | {'name': '------------------', 'xml':'', 'type':'separator'}, | |
63 | {'name': 'SEND STATUS TO FTP', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}, #TODO |
|
63 | {'name': 'SEND STATUS TO FTP', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}, #TODO | |
64 | {'name': 'FTP SERVER', 'xml':'', 'hide':[None, '']}, #TODO |
|
64 | {'name': 'FTP SERVER', 'xml':'', 'hide':[None, '']}, #TODO | |
65 | {'name': 'FTP USER', 'xml':'', 'hide':[None, '']}, #TODO |
|
65 | {'name': 'FTP USER', 'xml':'', 'hide':[None, '']}, #TODO | |
66 | {'name': 'FTP PASSWD', 'xml':'', 'hide':[None, '']}, #TODO |
|
66 | {'name': 'FTP PASSWD', 'xml':'', 'hide':[None, '']}, #TODO | |
67 | {'name': 'FTP DIR', 'xml':'', 'hide':[None, '']}, #TODO |
|
67 | {'name': 'FTP DIR', 'xml':'', 'hide':[None, '']}, #TODO | |
68 | {'name': 'FTP FILE', 'xml':'', 'hide':[None, '']}, #TODO |
|
68 | {'name': 'FTP FILE', 'xml':'', 'hide':[None, '']}, #TODO | |
69 | {'name': 'FTP INTERVAL', 'xml':'', 'hide':[None, '']}, #TODO |
|
69 | {'name': 'FTP INTERVAL', 'xml':'', 'hide':[None, '']}, #TODO | |
70 | {'name': 'SAVE STATUS AND BLOCK', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}, #TODO |
|
70 | {'name': 'SAVE STATUS AND BLOCK', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}, #TODO | |
71 | {'name': 'GENERATE RTI', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}, #TODO |
|
71 | {'name': 'GENERATE RTI', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}, #TODO | |
72 | {'name': 'SEND RTI AND BLOCK', 'xml':'Process_acquired_profiles', 'type':'checkbox_YES_NO'}, #TODO |
|
72 | {'name': 'SEND RTI AND BLOCK', 'xml':'Process_acquired_profiles', 'type':'checkbox_YES_NO'}, #TODO | |
73 | {'name': 'FTP INTERVAL', 'xml':'', 'value':'60'}, #TODO |
|
73 | {'name': 'FTP INTERVAL', 'xml':'', 'value':'60'}, #TODO | |
74 | {'name': '------------------', 'xml':'', 'type':'separator'}, |
|
74 | {'name': '------------------', 'xml':'', 'type':'separator'}, | |
75 | {'name': 'COMPORT CONFIG', 'xml':'', 'value':'Com1 CBR_9600 TWOSTOPBITS NOPARITY'}, #TODO |
|
75 | {'name': 'COMPORT CONFIG', 'xml':'', 'value':'Com1 CBR_9600 TWOSTOPBITS NOPARITY'}, #TODO | |
76 | {'name': 'JAM CONFIGURE FILE', 'xml':'', 'value':''}, #TODO |
|
76 | {'name': 'JAM CONFIGURE FILE', 'xml':'', 'value':''}, #TODO | |
77 | {'name': 'ACQUISITION SYSTEM', 'xml':'', 'value':'JARS'}, #TODO |
|
77 | {'name': 'ACQUISITION SYSTEM', 'xml':'', 'value':'JARS'}, #TODO | |
78 | {'name': '******************', 'xml':'', 'type':'acq_system_config_params'}, |
|
78 | {'name': '******************', 'xml':'', 'type':'acq_system_config_params'}, | |
79 | {'name': 'SAVE DATA', 'xml':'', 'value':'YES'}, #TODO |
|
79 | {'name': 'SAVE DATA', 'xml':'', 'value':'YES'}, #TODO | |
80 | {'name': '******************', 'xml':'', 'type':'rc_seq_config_params'}, |
|
80 | {'name': '******************', 'xml':'', 'type':'rc_seq_config_params'}, | |
81 | {'name': 'RC_STOP_SEQUENCE', 'xml':'', 'value':'255,0,255,8'}, |
|
81 | {'name': 'RC_STOP_SEQUENCE', 'xml':'', 'value':'255,0,255,8'}, | |
82 | {'name': 'RC_START_SEQUENCE', 'xml':'', 'value':'255,24'}] |
|
82 | {'name': 'RC_START_SEQUENCE', 'xml':'', 'value':'255,24'}] | |
83 |
|
83 | |||
84 | def get_field_value(self, field, user_value): |
|
84 | def get_field_value(self, field, user_value): | |
85 | if 'type' in field and field['type'] == 'checkbox_YES_NO': # Check for existence of value |
|
85 | if 'type' in field and field['type'] == 'checkbox_YES_NO': # Check for existence of value | |
86 | if (user_value is None) or (user_value == 'None'): |
|
86 | if (user_value is None) or (user_value == 'None'): | |
87 | user_value = 'NO' |
|
87 | user_value = 'NO' | |
88 | elif user_value == 'on': |
|
88 | elif user_value == 'on': | |
89 | user_value = 'YES' |
|
89 | user_value = 'YES' | |
90 | if 'value' in field and not(user_value): # Replace by default value |
|
90 | if 'value' in field and not(user_value): # Replace by default value | |
91 | user_value = field['value'] |
|
91 | user_value = field['value'] | |
92 | if 'extra' in field and field['extra'] == 'upper': # Uppercase values |
|
92 | if 'extra' in field and field['extra'] == 'upper': # Uppercase values | |
93 | user_value = user_value.upper() |
|
93 | user_value = user_value.upper() | |
94 | return str(user_value) |
|
94 | return str(user_value) | |
95 |
|
95 | |||
96 | def load_xml(self, xml): |
|
96 | def load_xml(self, xml): | |
97 | self.xml = xml |
|
97 | self.xml = xml | |
98 | for field in self.header_fields: |
|
98 | for field in self.header_fields: | |
99 | self.add_line_output(self.header['data'], field) |
|
99 | self.add_line_output(self.header['data'], field) | |
100 | for field in self.radar_param_fields: |
|
100 | for field in self.radar_param_fields: | |
101 | self.add_line_output(self.radar_param['data'], field) |
|
101 | self.add_line_output(self.radar_param['data'], field) | |
102 | for field in self.system_param1_fields: |
|
102 | for field in self.system_param1_fields: | |
103 | self.add_line_output(self.system_param1['data'], field) |
|
103 | self.add_line_output(self.system_param1['data'], field) | |
104 | for field in self.system_param2_fields: |
|
104 | for field in self.system_param2_fields: | |
105 | self.add_line_output(self.system_param2['data'], field) |
|
105 | self.add_line_output(self.system_param2['data'], field) | |
106 | for field in self.process_param_fields: |
|
106 | for field in self.process_param_fields: | |
107 | self.add_line_output(self.process_param['data'], field) |
|
107 | self.add_line_output(self.process_param['data'], field) | |
108 |
|
108 | |||
109 |
|
109 | |||
110 |
|
110 | |||
111 | def add_line_output(self, text_array, param_field): |
|
111 | def add_line_output(self, text_array, param_field): | |
112 | name = param_field['name'] |
|
112 | name = param_field['name'] | |
113 | xml_l = param_field['xml'] |
|
113 | xml_l = param_field['xml'] | |
114 | acq_number_of_cards = int(self.xml.find('Experiment/Process/JARS/Number_of_cards').text) |
|
114 | acq_number_of_cards = int(self.xml.find('Experiment/Process/JARS/Number_of_cards').text) | |
115 | acq_channels_per_card = int(self.xml.find('Experiment/Process/JARS/Channels_per_card').text) |
|
115 | acq_channels_per_card = int(self.xml.find('Experiment/Process/JARS/Channels_per_card').text) | |
116 | number_of_acq_channels = acq_number_of_cards * acq_channels_per_card |
|
116 | number_of_acq_channels = acq_number_of_cards * acq_channels_per_card | |
117 |
|
117 | |||
118 | if 'xml_attr' in param_field and 'xml_attr_find' in param_field: |
|
118 | if 'xml_attr' in param_field and 'xml_attr_find' in param_field: | |
119 | sub_pattern = False |
|
119 | sub_pattern = False | |
120 | if 'xml_sub_pattern' in param_field: |
|
120 | if 'xml_sub_pattern' in param_field: | |
121 | sub_pattern = param_field['xml_sub_pattern'] |
|
121 | sub_pattern = param_field['xml_sub_pattern'] | |
122 | element = self.xml.find_by_attribute_value(xml_l, param_field['xml_attr'], param_field['xml_attr_find'],sub_pattern) |
|
122 | element = self.xml.find_by_attribute_value(xml_l, param_field['xml_attr'], param_field['xml_attr_find'],sub_pattern) | |
123 | else: |
|
123 | else: | |
124 | element = self.xml.find(xml_l) |
|
124 | element = self.xml.find(xml_l) | |
125 |
|
125 | |||
126 | if 'xml_attr_value' in param_field: |
|
126 | if 'xml_attr_value' in param_field: | |
127 | value = element.get(param_field['xml_attr_value']) |
|
127 | value = element.get(param_field['xml_attr_value']) | |
128 | else: |
|
128 | else: | |
129 | value = '' |
|
129 | value = '' | |
130 | if xml_l == '' and 'value' in param_field: |
|
130 | if xml_l == '' and 'value' in param_field: | |
131 | value = param_field['value'] |
|
131 | value = param_field['value'] | |
132 | elif hasattr(element, 'text'): |
|
132 | elif hasattr(element, 'text'): | |
133 | value = element.text |
|
133 | value = element.text | |
134 |
|
134 | |||
135 | if 'type' in param_field and param_field['type'] == 'separator': # Check for existence of value |
|
135 | if 'type' in param_field and param_field['type'] == 'separator': # Check for existence of value | |
136 | text_array.append('------------------------------------------') |
|
136 | text_array.append('------------------------------------------') | |
137 | return |
|
137 | return | |
138 | if 'type' in param_field and param_field['type'] == 'acq_system_config_params': # Get Acquisition System Parameters and add them |
|
138 | if 'type' in param_field and param_field['type'] == 'acq_system_config_params': # Get Acquisition System Parameters and add them | |
139 | text_array.append("************JARS CONFIGURATION PARAMETERS************") |
|
139 | text_array.append("************JARS CONFIGURATION PARAMETERS************") | |
140 | if self.xml.find('Experiment/Process/JARS/Filter').text: |
|
140 | if self.xml.find('Experiment/Process/JARS/Filter').text: | |
141 | # Notice that we need to use backslashes for the filter path |
|
141 | # Notice that we need to use backslashes for the filter path | |
142 | text_array.append("Jars_Filter="+self.xml.find('Experiment/Process/JARS/Filter_dir').text +'\\'+ self.xml.find('Experiment/Process/JARS/Filter').text) |
|
142 | text_array.append("Jars_Filter="+self.xml.find('Experiment/Process/JARS/Filter_dir').text +'\\'+ self.xml.find('Experiment/Process/JARS/Filter').text) | |
143 | else: |
|
143 | else: | |
144 | text_array.append("Jars_Filter=") |
|
144 | text_array.append("Jars_Filter=") | |
145 | text_array.append("JARS_Collection_Mode="+self.xml.find('Experiment/Process/JARS/JARS_Collection_Mode').text) |
|
145 | text_array.append("JARS_Collection_Mode="+self.xml.find('Experiment/Process/JARS/JARS_Collection_Mode').text) | |
146 | text_array.append("SAVE_DATA=YES") |
|
146 | text_array.append("SAVE_DATA=YES") | |
147 | text_array.append("*****************************************************") |
|
147 | text_array.append("*****************************************************") | |
148 | return |
|
148 | return | |
149 | if 'type' in param_field and param_field['type'] == 'rc_seq_config_params': # Get Acquisition System Parameters and add them |
|
149 | if 'type' in param_field and param_field['type'] == 'rc_seq_config_params': # Get Acquisition System Parameters and add them | |
150 | text_array.append("****************RC SEQUENCES******************") |
|
150 | text_array.append("****************RC SEQUENCES******************") | |
151 | return |
|
151 | return | |
152 | if 'type' in param_field: |
|
152 | if 'type' in param_field: | |
153 | if param_field['type'] == 'pulse_enable': |
|
153 | if param_field['type'] == 'pulse_enable': | |
154 | txa_enable = self.xml.find_by_attribute_value('Experiment/Controller/Transmitters/TX', 'id', 'txa', 'Pulses') |
|
154 | txa_enable = self.xml.find_by_attribute_value('Experiment/Controller/Transmitters/TX', 'id', 'txa', 'Pulses') | |
155 | if txa_enable.text is not None: |
|
155 | if txa_enable.text is not None: | |
156 | text_array.append('Pulse selection_TXA='+txa_enable.text) |
|
156 | text_array.append('Pulse selection_TXA='+txa_enable.text) | |
157 | txb_enable = self.xml.find_by_attribute_value('Experiment/Controller/Transmitters/TX', 'id', 'txb', 'Pulses') |
|
157 | txb_enable = self.xml.find_by_attribute_value('Experiment/Controller/Transmitters/TX', 'id', 'txb', 'Pulses') | |
158 | if txb_enable.text is not None: |
|
158 | if txb_enable.text is not None: | |
159 | text_array.append('Pulse selection_TXB='+txb_enable.text) |
|
159 | text_array.append('Pulse selection_TXB='+txb_enable.text) | |
160 | tr_enable = self.xml.find('Experiment/Controller/IPP/Pulses') |
|
160 | tr_enable = self.xml.find('Experiment/Controller/IPP/Pulses') | |
161 | if tr_enable.text is not None: |
|
161 | if tr_enable.text is not None: | |
162 | text_array.append('Pulse selection_TR='+tr_enable.text) |
|
162 | text_array.append('Pulse selection_TR='+tr_enable.text) | |
163 | return |
|
163 | return | |
164 | elif param_field['type'] == 'Line4' or param_field['type'] == 'Line5' or param_field['type'] == 'Line6' or param_field['type'] == 'Line7': |
|
164 | elif param_field['type'] == 'Line4' or param_field['type'] == 'Line5' or param_field['type'] == 'Line6' or param_field['type'] == 'Line7': | |
165 | code_name = 'Code_A' |
|
165 | code_name = 'Code_A' | |
166 | line_number = '4' |
|
166 | line_number = '4' | |
167 | line_parenthesis = '' |
|
167 | line_parenthesis = '' | |
168 | line_prepend = '' |
|
168 | line_prepend = '' | |
169 |
|
169 | |||
170 | if param_field['type'] == 'Line5': |
|
170 | if param_field['type'] == 'Line5': | |
171 | code_name = 'Code_B' |
|
171 | code_name = 'Code_B' | |
172 | line_number = '5' |
|
172 | line_number = '5' | |
173 | line_parenthesis = ' (Line 5)' |
|
173 | line_parenthesis = ' (Line 5)' | |
174 | line_prepend = 'L5_' |
|
174 | line_prepend = 'L5_' | |
175 | elif param_field['type'] == 'Line6': |
|
175 | elif param_field['type'] == 'Line6': | |
176 | code_name = 'Code_C' |
|
176 | code_name = 'Code_C' | |
177 | line_number = '6' |
|
177 | line_number = '6' | |
178 | line_parenthesis = ' (Line 6)' |
|
178 | line_parenthesis = ' (Line 6)' | |
179 | line_prepend = 'L6_' |
|
179 | line_prepend = 'L6_' | |
180 | elif param_field['type'] == 'Line7': |
|
180 | elif param_field['type'] == 'Line7': | |
181 | code_name = 'Code_D' |
|
181 | code_name = 'Code_D' | |
182 | line_number = '7' |
|
182 | line_number = '7' | |
183 | line_parenthesis = ' (Line 7)' |
|
183 | line_parenthesis = ' (Line 7)' | |
184 | line_prepend = 'L7_' |
|
184 | line_prepend = 'L7_' | |
185 |
|
185 | |||
186 | code_channel = self.xml.find_by_attribute_value('Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Mode').text |
|
186 | code_channel = self.xml.find_by_attribute_value('Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Mode').text | |
187 | if code_channel == 'FLIP': |
|
187 | if code_channel == 'FLIP': | |
188 | value = self.xml.find_by_attribute_value('Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Flip').text |
|
188 | value = self.xml.find_by_attribute_value('Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Flip').text | |
189 | flip_name = 'L'+line_number+'_FLIP' + line_parenthesis |
|
189 | flip_name = 'L'+line_number+'_FLIP' + line_parenthesis | |
190 | if param_field['type'] == 'Line5': |
|
190 | if param_field['type'] == 'Line5': | |
191 | flip_name = 'FLIP1' |
|
191 | flip_name = 'FLIP1' | |
192 | elif param_field['type'] == 'Line6': |
|
192 | elif param_field['type'] == 'Line6': | |
193 | flip_name = 'FLIP2' |
|
193 | flip_name = 'FLIP2' | |
194 | text_array.append(flip_name + '='+value) |
|
194 | text_array.append(flip_name + '='+value) | |
195 | elif code_channel == 'CODE': |
|
195 | elif code_channel == 'CODE': | |
196 | code_data = self.xml.find_by_attribute_value('Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Code') |
|
196 | code_data = self.xml.find_by_attribute_value('Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Code') | |
197 | Code_reference = code_data.find('Code_reference').text |
|
197 | Code_reference = code_data.find('Code_reference').text | |
198 | Code_select = code_data.find('Code_select').text |
|
198 | Code_select = code_data.find('Code_select').text | |
199 | Code_number = code_data.find('Code_number').text |
|
199 | Code_number = code_data.find('Code_number').text | |
200 | Code_bits = code_data.find('Code_bits').text |
|
200 | Code_bits = code_data.find('Code_bits').text | |
201 | custom_codes = get_custom_code_data(Code_select, int(Code_number), int(Code_bits)) |
|
201 | custom_codes = get_custom_code_data(Code_select, int(Code_number), int(Code_bits)) | |
202 | text_array.append('Code Type' + line_parenthesis + '='+Code_select) |
|
202 | text_array.append('Code Type' + line_parenthesis + '='+Code_select) | |
203 | text_array.append('Number of Codes' + line_parenthesis + '='+Code_number) |
|
203 | text_array.append('Number of Codes' + line_parenthesis + '='+Code_number) | |
204 | text_array.append('Code Width' + line_parenthesis + '='+Code_bits) |
|
204 | text_array.append('Code Width' + line_parenthesis + '='+Code_bits) | |
205 | for zero_idx, custom_code in enumerate(custom_codes): |
|
205 | for zero_idx, custom_code in enumerate(custom_codes): | |
206 | text_array.append(line_prepend+'COD('+str(zero_idx)+')='+custom_code) |
|
206 | text_array.append(line_prepend+'COD('+str(zero_idx)+')='+custom_code) | |
207 | # Calculate Codes |
|
207 | # Calculate Codes | |
208 | text_array.append('L'+line_number+'_REFERENCE='+Code_reference.upper()) |
|
208 | text_array.append('L'+line_number+'_REFERENCE='+Code_reference.upper()) | |
209 | elif code_channel == 'Sampling': |
|
209 | elif code_channel == 'Sampling': | |
210 | sampling_name = 'Sampling Windows (Line ' + line_number + ')' |
|
210 | sampling_name = 'Sampling Windows (Line ' + line_number + ')' | |
211 | prepend = 'L'+line_number+'_' |
|
211 | prepend = 'L'+line_number+'_' | |
212 | if param_field['type'] == 'Line7': |
|
212 | if param_field['type'] == 'Line7': | |
213 | sampling_name = 'Sampling Windows' |
|
213 | sampling_name = 'Sampling Windows' | |
214 | prepend = '' |
|
214 | prepend = '' | |
215 | sampling_data = self.xml.find_by_attribute_value('Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Sampling') |
|
215 | sampling_data = self.xml.find_by_attribute_value('Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Sampling') | |
216 | Code_reference = sampling_data.find('Code_reference').text.upper() |
|
216 | Code_reference = sampling_data.find('Code_reference').text.upper() | |
217 | samples = sampling_data.find('Samples') |
|
217 | samples = sampling_data.find('Samples') | |
218 | text_array.append(sampling_name+'='+str(len(samples))) |
|
218 | text_array.append(sampling_name+'='+str(len(samples))) | |
219 | for zero_idx, sample in enumerate(samples): |
|
219 | for zero_idx, sample in enumerate(samples): | |
220 | text_array.append(prepend+'H0('+str(zero_idx)+')='+sample.find('FH').text) |
|
220 | text_array.append(prepend+'H0('+str(zero_idx)+')='+sample.find('FH').text) | |
221 | text_array.append(prepend+'NSA('+str(zero_idx)+')='+sample.find('NSA').text) |
|
221 | text_array.append(prepend+'NSA('+str(zero_idx)+')='+sample.find('NSA').text) | |
222 | text_array.append(prepend+'DH('+str(zero_idx)+')='+sample.find('DH').text) |
|
222 | text_array.append(prepend+'DH('+str(zero_idx)+')='+sample.find('DH').text) | |
223 | text_array.append('L'+line_number+'_REFERENCE='+Code_reference.upper()) |
|
223 | text_array.append('L'+line_number+'_REFERENCE='+Code_reference.upper()) | |
224 | elif code_channel == 'Synchro': |
|
224 | elif code_channel == 'Synchro': | |
225 | text_array.append('Line'+line_number+'=Synchro') |
|
225 | text_array.append('Line'+line_number+'=Synchro') | |
226 | elif code_channel == 'Portion_Spec': |
|
226 | elif code_channel == 'Portion_Spec': | |
227 | portion_data = self.xml.find_by_attribute_value('Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'PortionSpec') |
|
227 | portion_data = self.xml.find_by_attribute_value('Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'PortionSpec') | |
228 | periodic = portion_data.find('Periodic').text |
|
228 | periodic = portion_data.find('Periodic').text | |
229 | portions = portion_data.find('Portions') |
|
229 | portions = portion_data.find('Portions') | |
230 | text_array.append('L'+line_number+' Number Of Portions='+str(len(portions))) |
|
230 | text_array.append('L'+line_number+' Number Of Portions='+str(len(portions))) | |
231 | for zero_idx, portion in enumerate(portions): |
|
231 | for zero_idx, portion in enumerate(portions): | |
232 | text_array.append('PORTION_BEGIN('+str(zero_idx)+')='+portion.find('Begin_units').text) |
|
232 | text_array.append('PORTION_BEGIN('+str(zero_idx)+')='+portion.find('Begin_units').text) | |
233 | text_array.append('PORTION_END('+str(zero_idx)+')='+portion.find('End_units').text) |
|
233 | text_array.append('PORTION_END('+str(zero_idx)+')='+portion.find('End_units').text) | |
234 | if periodic == '1': |
|
234 | if periodic == '1': | |
235 | text_array.append('L'+line_number+' Portions IPP Periodic=YES') |
|
235 | text_array.append('L'+line_number+' Portions IPP Periodic=YES') | |
236 | else: |
|
236 | else: | |
237 | text_array.append('L'+line_number+' Portions IPP Periodic=NO') |
|
237 | text_array.append('L'+line_number+' Portions IPP Periodic=NO') | |
238 | return |
|
238 | return | |
239 | elif param_field['type'] == 'txb_delays_info': |
|
239 | elif param_field['type'] == 'txb_delays_info': | |
240 | txb_delays = self.xml.find_by_attribute_value('Experiment/Controller/Transmitters/TX', 'id', 'txb', 'Delays') |
|
240 | txb_delays = self.xml.find_by_attribute_value('Experiment/Controller/Transmitters/TX', 'id', 'txb', 'Delays') | |
241 | text_array.append("Number of Taus="+str(len(txb_delays))) |
|
241 | text_array.append("Number of Taus="+str(len(txb_delays))) | |
242 | for zero_index, txb_delay in enumerate(txb_delays): |
|
242 | for zero_index, txb_delay in enumerate(txb_delays): | |
243 | text_array.append('TAU('+str(zero_index)+')='+str(txb_delay.text)) |
|
243 | text_array.append('TAU('+str(zero_index)+')='+str(txb_delay.text)) | |
244 | return |
|
244 | return | |
245 | elif param_field['type'] == 'cards_info': # Get Cards info |
|
245 | elif param_field['type'] == 'cards_info': # Get Cards info | |
246 | if not(acq_number_of_cards == '0'): |
|
246 | if not(acq_number_of_cards == '0'): | |
247 | for card in range(acq_number_of_cards): |
|
247 | for card in range(acq_number_of_cards): | |
248 | name = 'Card('+str(card)+')' |
|
248 | name = 'Card('+str(card)+')' | |
249 | text_array.append(name + "=" + str(card)) |
|
249 | text_array.append(name + "=" + str(card)) | |
250 | return |
|
250 | return | |
251 | elif param_field['type'] == 'channels_info': # Get Channel info |
|
251 | elif param_field['type'] == 'channels_info': # Get Channel info | |
252 | text_array.append("Number of Channels="+str(number_of_acq_channels)) |
|
252 | text_array.append("Number of Channels="+str(number_of_acq_channels)) | |
253 | if not(number_of_acq_channels == '0'): |
|
253 | if not(number_of_acq_channels == '0'): | |
254 | acq_channels = self.xml.find('Experiment/Process/Acq_channel_selection') |
|
254 | acq_channels = self.xml.find('Experiment/Process/Acq_channel_selection') | |
255 | enabled_channels = [] |
|
255 | enabled_channels = [] | |
256 | channel_names =[] |
|
256 | channel_names =[] | |
257 | for acq_channel in acq_channels: |
|
257 | for acq_channel in acq_channels: | |
258 | acq_channel_number = acq_channel.get('id') |
|
258 | acq_channel_number = acq_channel.get('id') | |
259 | acq_channel_name = acq_channel.find('Name').text |
|
259 | acq_channel_name = acq_channel.find('Name').text | |
260 | enabled = False |
|
260 | enabled = False | |
261 | if hasattr(acq_channel.find('Enabled'), 'text'): |
|
261 | if hasattr(acq_channel.find('Enabled'), 'text'): | |
262 | enabled = acq_channel.find('Enabled').text |
|
262 | enabled = acq_channel.find('Enabled').text | |
263 | if enabled == 'on': |
|
263 | if enabled == 'on': | |
264 | text_array.append("Channel("+acq_channel_number+")=" + str(int(acq_channel_number)+1)) |
|
264 | text_array.append("Channel("+acq_channel_number+")=" + str(int(acq_channel_number)+1)) | |
265 | enabled_channels.append(acq_channel_number) |
|
265 | enabled_channels.append(acq_channel_number) | |
266 | channel_names.append(acq_channel_name) |
|
266 | channel_names.append(acq_channel_name) | |
267 | text_array.append("Antennas_Names="+str(len(enabled_channels))) |
|
267 | text_array.append("Antennas_Names="+str(len(enabled_channels))) | |
268 | for index, channel in enumerate(enabled_channels): |
|
268 | for index, channel in enumerate(enabled_channels): | |
269 | text_array.append("AntennaName(" + str(int(channel)+1) + ")="+str(channel_names[index])) |
|
269 | text_array.append("AntennaName(" + str(int(channel)+1) + ")="+str(channel_names[index])) | |
270 | return |
|
270 | return | |
271 | if 'hide' in param_field and value in param_field['hide']: # Check to see if value should be written |
|
271 | if 'hide' in param_field and value in param_field['hide']: # Check to see if value should be written | |
272 | return |
|
272 | return | |
273 | text_array.append(name + "=" + self.get_field_value(param_field, value)) |
|
273 | text_array.append(name + "=" + self.get_field_value(param_field, value)) | |
274 |
|
274 | |||
275 | def convert_to_racp(self): |
|
275 | def convert_to_racp(self): | |
276 | output = [] |
|
276 | output = [] | |
277 | # HEADER |
|
277 | # HEADER | |
278 | for line in self.header['data']: |
|
278 | for line in self.header['data']: | |
279 | output.append(line) |
|
279 | output.append(line) | |
280 | output.append('HEADER VERSION='+self.header['version']) |
|
280 | output.append('HEADER VERSION='+self.header['version']) | |
281 | # RADAR PARAMETERS |
|
281 | # RADAR PARAMETERS | |
282 | output.append(self.radar_param['header']) |
|
282 | output.append(self.radar_param['header']) | |
283 | for line in self.radar_param['data']: |
|
283 | for line in self.radar_param['data']: | |
284 | output.append(line) |
|
284 | output.append(line) | |
285 | # SYSTEM PARAMETERS |
|
285 | # SYSTEM PARAMETERS | |
286 | output.append(self.system_param1['header']) |
|
286 | output.append(self.system_param1['header']) | |
287 | for line in self.system_param1['data']: |
|
287 | for line in self.system_param1['data']: | |
288 | output.append(line) |
|
288 | output.append(line) | |
289 | output.append(self.system_param2['header']) |
|
289 | output.append(self.system_param2['header']) | |
290 | for line in self.system_param2['data']: |
|
290 | for line in self.system_param2['data']: | |
291 | output.append(line) |
|
291 | output.append(line) | |
292 | # PROCESS PARAMETERS |
|
292 | # PROCESS PARAMETERS | |
293 | output.append(self.process_param['header']) |
|
293 | output.append(self.process_param['header']) | |
294 | for line in self.process_param['data']: |
|
294 | for line in self.process_param['data']: | |
295 | output.append(line) |
|
295 | output.append(line) | |
296 |
|
296 | |||
297 | racp_content = "\n".join([str(x) for x in output]) |
|
297 | racp_content = "\n".join([str(x) for x in output]) | |
298 | return racp_content |
|
298 | return racp_content | |
299 |
|
299 | |||
300 | def reduce_code_bits(code_bits, bits_per_code): |
|
300 | def reduce_code_bits(code_bits, bits_per_code): | |
301 | return code_bits[:bits_per_code] |
|
301 | return code_bits[:bits_per_code] | |
302 |
|
302 | |||
303 | def zeropad_code_bits(code_bits, custom_bits_per_code): |
|
303 | def zeropad_code_bits(code_bits, custom_bits_per_code): | |
304 | return code_bits.ljust(custom_bits_per_code, "0") |
|
304 | return code_bits.ljust(custom_bits_per_code, "0") | |
305 |
|
305 | |||
306 |
|
306 | |||
307 | def get_custom_code_data(codename, number_of_codes, bits_per_code): |
|
307 | def get_custom_code_data(codename, number_of_codes, bits_per_code): | |
308 | import json |
|
308 | import json | |
309 | import copy |
|
309 | import copy | |
310 | json_data=open('../js/pulse_code_values.json') |
|
310 | json_data=open('../js/pulse_code_values.json') | |
311 | PD_pulse_codes = json.load(json_data) |
|
311 | PD_pulse_codes = json.load(json_data) | |
312 | selected_code = copy.copy(PD_pulse_codes[codename]) |
|
312 | selected_code = copy.copy(PD_pulse_codes[codename]) | |
313 |
|
313 | |||
314 | modified_binary_codes = [] |
|
314 | modified_binary_codes = [] | |
315 | for i in range (number_of_codes): |
|
315 | for i in range (number_of_codes): | |
316 | if (i >= selected_code['number_of_codes']): |
|
316 | if (i >= selected_code['number_of_codes']): | |
317 | # We just repeat the first code. |
|
317 | # We just repeat the first code. | |
318 | modified_binary_codes.append(selected_code['binary_codes'][0]) |
|
318 | modified_binary_codes.append(selected_code['binary_codes'][0]) | |
319 | else: |
|
319 | else: | |
320 | modified_binary_codes.append(selected_code['binary_codes'][i]) |
|
320 | modified_binary_codes.append(selected_code['binary_codes'][i]) | |
321 | # Now adjust the width |
|
321 | # Now adjust the width | |
322 | if (bits_per_code <= selected_code['bits_per_code']): |
|
322 | if (bits_per_code <= selected_code['bits_per_code']): | |
323 | modified_binary_codes = [reduce_code_bits(x, bits_per_code) for x in modified_binary_codes] |
|
323 | modified_binary_codes = [reduce_code_bits(x, bits_per_code) for x in modified_binary_codes] | |
324 | else: # Zero pad to the right |
|
324 | else: # Zero pad to the right | |
325 | modified_binary_codes = [zeropad_code_bits(x, bits_per_code) for x in modified_binary_codes] |
|
325 | modified_binary_codes = [zeropad_code_bits(x, bits_per_code) for x in modified_binary_codes] | |
326 | return modified_binary_codes |
|
326 | return modified_binary_codes | |
327 |
|
327 | |||
328 | class Pulse_Design_Mixed_Racp: |
|
328 | class Pulse_Design_Mixed_Racp: | |
329 | """A class to define the .racp output from Pulse Design """ |
|
329 | """A class to define the .racp output from Pulse Design """ | |
330 | def __init__(self, number_of_experiments): |
|
330 | def __init__(self, number_of_experiments): | |
331 | self.header = {'version': '1103'} |
|
331 | self.header = {'version': '1103'} | |
332 | self.radar_param = {'header': '*****Radar Controller Parameters**********'} |
|
332 | self.radar_param = {'header': '*****Radar Controller Parameters**********'} | |
333 | self.system_param1 = {'header': '******System Parameters*******************'} |
|
333 | self.system_param1 = {'header': '******System Parameters*******************'} | |
334 | self.system_param2 = {'header': '******System Parameters*******************'} |
|
334 | self.system_param2 = {'header': '******System Parameters*******************'} | |
335 | self.process_param = {'header': '******Process Parameters******************'} |
|
335 | self.process_param = {'header': '******Process Parameters******************'} | |
336 | self.xml = None |
|
336 | self.xml = None | |
337 | self.number_of_experiments = number_of_experiments |
|
337 | self.number_of_experiments = number_of_experiments | |
338 | self.header_fields = {} |
|
338 | self.header_fields = {} | |
339 | self.radar_param_fields = {} |
|
339 | self.radar_param_fields = {} | |
340 | self.system_param1_fields = {} |
|
340 | self.system_param1_fields = {} | |
341 | self.system_param2_fields = {} |
|
341 | self.system_param2_fields = {} | |
342 | self.process_param_fields = {} |
|
342 | self.process_param_fields = {} | |
343 |
|
343 | |||
344 | for i in range(self.number_of_experiments): |
|
344 | for i in range(self.number_of_experiments): | |
345 | self.header['data_experiment_number_'+str(i)] = [] |
|
345 | self.header['data_experiment_number_'+str(i)] = [] | |
346 | self.radar_param['data_experiment_number_'+str(i)] = [] |
|
346 | self.radar_param['data_experiment_number_'+str(i)] = [] | |
347 | self.system_param1['data_experiment_number_'+str(i)] = [] |
|
347 | self.system_param1['data_experiment_number_'+str(i)] = [] | |
348 | self.system_param2['data_experiment_number_'+str(i)] = [] |
|
348 | self.system_param2['data_experiment_number_'+str(i)] = [] | |
349 | self.process_param['data_experiment_number_'+str(i)] = [] |
|
349 | self.process_param['data_experiment_number_'+str(i)] = [] | |
350 |
|
350 | |||
351 | self.header_fields['indices_experiment_number_'+str(i)] = [] |
|
351 | self.header_fields['indices_experiment_number_'+str(i)] = [] | |
352 | self.radar_param_fields['indices_experiment_number_'+str(i)] = [] |
|
352 | self.radar_param_fields['indices_experiment_number_'+str(i)] = [] | |
353 | self.system_param1_fields['indices_experiment_number_'+str(i)] = [] |
|
353 | self.system_param1_fields['indices_experiment_number_'+str(i)] = [] | |
354 | self.system_param2_fields['indices_experiment_number_'+str(i)] = [] |
|
354 | self.system_param2_fields['indices_experiment_number_'+str(i)] = [] | |
355 | self.process_param_fields['indices_experiment_number_'+str(i)] = [] |
|
355 | self.process_param_fields['indices_experiment_number_'+str(i)] = [] | |
356 |
|
356 | |||
357 | self.header_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'EXPERIMENT TYPE', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Signal_pre_processing/Type_of_experiment'}) |
|
357 | self.header_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'EXPERIMENT TYPE', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Signal_pre_processing/Type_of_experiment'}) | |
358 | self.header_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'EXPERIMENT NAME', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment', 'xml_attr_value':'name'}) |
|
358 | self.header_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'EXPERIMENT NAME', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment', 'xml_attr_value':'name'}) | |
359 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'IPP', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/IPP/Width'}) |
|
359 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'IPP', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/IPP/Width'}) | |
360 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'NTX', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/NTX'}) |
|
360 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'NTX', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/NTX'}) | |
361 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'TXA', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Transmitters/TX', 'xml_attr':'id', 'xml_attr_find':'txa', 'xml_sub_pattern':'Width'}) |
|
361 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'TXA', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Transmitters/TX', 'xml_attr':'id', 'xml_attr_find':'txa', 'xml_sub_pattern':'Width'}) | |
362 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'TXB', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Transmitters/TX', 'xml_attr':'id', 'xml_attr_find':'txb', 'xml_sub_pattern':'Width'}) |
|
362 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'TXB', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Transmitters/TX', 'xml_attr':'id', 'xml_attr_find':'txb', 'xml_sub_pattern':'Width'}) | |
363 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type':'pulse_enable'}) |
|
363 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type':'pulse_enable'}) | |
364 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type': 'Line4'}) |
|
364 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type': 'Line4'}) | |
365 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type': 'Line5'}) |
|
365 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type': 'Line5'}) | |
366 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type': 'Line6'}) |
|
366 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type': 'Line6'}) | |
367 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type':'txb_delays_info'}) |
|
367 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type':'txb_delays_info'}) | |
368 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type': 'Line7'}) |
|
368 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type': 'Line7'}) | |
369 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SAMPLING REFERENCE', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Ctl_Setting/Sampling_reference'}) |
|
369 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SAMPLING REFERENCE', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Ctl_Setting/Sampling_reference'}) | |
370 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'RELOJ', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Clock/Clock_final'}) |
|
370 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'RELOJ', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Clock/Clock_final'}) | |
371 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'CLOCK DIVIDER', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Clock/Clock_div', 'hide':['1']}) |
|
371 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'CLOCK DIVIDER', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Clock/Clock_div', 'hide':['1']}) | |
372 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'TR_BEFORE', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Spc_Setting/Time_before'}) |
|
372 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'TR_BEFORE', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Spc_Setting/Time_before'}) | |
373 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'TR_AFTER', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Spc_Setting/Time_after'}) |
|
373 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'TR_AFTER', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Spc_Setting/Time_after'}) | |
374 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'WINDOW IN LINE 5&6', 'xml':'', 'value':'NO'}) |
|
374 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'WINDOW IN LINE 5&6', 'xml':'', 'value':'NO'}) | |
375 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SYNCHRO DELAY', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Spc_Setting/Sync_delay', 'hide':['0']}) |
|
375 | self.radar_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SYNCHRO DELAY', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Controller/Spc_Setting/Sync_delay', 'hide':['0']}) | |
376 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'Number of Cards', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Number_of_cards', 'hide':['0']}) |
|
376 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'Number of Cards', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Number_of_cards', 'hide':['0']}) | |
377 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type':'cards_info'}) |
|
377 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type':'cards_info'}) | |
378 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type':'channels_info'}) |
|
378 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '***', 'xml':'', 'type':'channels_info'}) | |
379 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'RAW DATA DIRECTORY', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_storage/Directory'}) |
|
379 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'RAW DATA DIRECTORY', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_storage/Directory'}) | |
380 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'CREATE DIRECTORY PER DAY', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_storage/Directory_per_day', 'type':'checkbox_YES_NO'}) |
|
380 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'CREATE DIRECTORY PER DAY', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_storage/Directory_per_day', 'type':'checkbox_YES_NO'}) | |
381 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'INCLUDE EXPNAME IN DIRECTORY', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_storage/Expname_in_directory', 'type':'checkbox_YES_NO'}) |
|
381 | self.system_param1_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'INCLUDE EXPNAME IN DIRECTORY', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_storage/Expname_in_directory', 'type':'checkbox_YES_NO'}) | |
382 | self.system_param2_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'ADC Resolution', 'xml':'', 'value':'12'})# Default is 8, JARS is 12 |
|
382 | self.system_param2_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'ADC Resolution', 'xml':'', 'value':'12'})# Default is 8, JARS is 12 | |
383 | self.system_param2_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'PCI DIO BusWidth', 'xml':'', 'value':'32'}) # Default for JARS |
|
383 | self.system_param2_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'PCI DIO BusWidth', 'xml':'', 'value':'32'}) # Default for JARS | |
384 | self.system_param2_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'RAW DATA BLOCKS', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_arrangement/Data_blocks'}) |
|
384 | self.system_param2_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'RAW DATA BLOCKS', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_arrangement/Data_blocks'}) | |
385 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'DATATYPE', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Signal_pre_processing/Type_of_data'}) |
|
385 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'DATATYPE', 'xml': 'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Signal_pre_processing/Type_of_data'}) | |
386 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'DATA ARRANGE', 'xml':'', 'value':'CONTIGUOUS_CH'}) |
|
386 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'DATA ARRANGE', 'xml':'', 'value':'CONTIGUOUS_CH'}) | |
387 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'COHERENT INTEGRATION STRIDE', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Signal_pre_processing/Integration_stride'}) |
|
387 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'COHERENT INTEGRATION STRIDE', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Signal_pre_processing/Integration_stride'}) | |
388 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '------------------', 'xml':'', 'type':'separator'}) |
|
388 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '------------------', 'xml':'', 'type':'separator'}) | |
389 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'ACQUIRED PROFILES', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_arrangement/Acquired_profiles'}) |
|
389 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'ACQUIRED PROFILES', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_arrangement/Acquired_profiles'}) | |
390 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'PROFILES PER BLOCK', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_arrangement/Profiles_per_block'}) |
|
390 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'PROFILES PER BLOCK', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_arrangement/Profiles_per_block'}) | |
391 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '------------------', 'xml':'', 'type':'separator'}) |
|
391 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '------------------', 'xml':'', 'type':'separator'}) | |
392 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'BEGIN ON START', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Schedule/Begin_on_Start', 'type': 'checkbox_YES_NO'}) |
|
392 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'BEGIN ON START', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Schedule/Begin_on_Start', 'type': 'checkbox_YES_NO'}) | |
393 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'BEGIN_TIME', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Schedule/Start', 'hide':['']}) |
|
393 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'BEGIN_TIME', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Schedule/Start', 'hide':['']}) | |
394 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'END_TIME', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Schedule/End', 'hide':['']}) |
|
394 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'END_TIME', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Schedule/End', 'hide':['']}) | |
395 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'VIEW RAW DATA', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_arrangement/View_raw_data', 'type': 'checkbox_YES_NO'}) |
|
395 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'VIEW RAW DATA', 'xml':'Experiments/List/Experiment['+str(i)+']/XML_contents/Pulse_Design/Experiment/Process/Data_arrangement/View_raw_data', 'type': 'checkbox_YES_NO'}) | |
396 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'REFRESH RATE', 'xml':'', 'value':'1'}) |
|
396 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'REFRESH RATE', 'xml':'', 'value':'1'}) | |
397 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '------------------', 'xml':'', 'type':'separator'}) |
|
397 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '------------------', 'xml':'', 'type':'separator'}) | |
398 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SEND STATUS TO FTP', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}) |
|
398 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SEND STATUS TO FTP', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}) | |
399 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP SERVER', 'xml':'', 'hide':[None, '']}) |
|
399 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP SERVER', 'xml':'', 'hide':[None, '']}) | |
400 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP USER', 'xml':'', 'hide':[None, '']}) |
|
400 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP USER', 'xml':'', 'hide':[None, '']}) | |
401 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP PASSWD', 'xml':'', 'hide':[None, '']}) |
|
401 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP PASSWD', 'xml':'', 'hide':[None, '']}) | |
402 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP DIR', 'xml':'', 'hide':[None, '']}) |
|
402 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP DIR', 'xml':'', 'hide':[None, '']}) | |
403 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP FILE', 'xml':'', 'hide':[None, '']}) |
|
403 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP FILE', 'xml':'', 'hide':[None, '']}) | |
404 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP INTERVAL', 'xml':'', 'hide':[None, '']}) |
|
404 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP INTERVAL', 'xml':'', 'hide':[None, '']}) | |
405 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SAVE STATUS AND BLOCK', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}) |
|
405 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SAVE STATUS AND BLOCK', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}) | |
406 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'GENERATE RTI', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}) |
|
406 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'GENERATE RTI', 'xml':'', 'type':'checkbox_YES_NO', 'value':'NO'}) | |
407 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SEND RTI AND BLOCK', 'xml':'Process_acquired_profiles', 'type':'checkbox_YES_NO'}) |
|
407 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SEND RTI AND BLOCK', 'xml':'Process_acquired_profiles', 'type':'checkbox_YES_NO'}) | |
408 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP INTERVAL', 'xml':'', 'value':'60'}) |
|
408 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'FTP INTERVAL', 'xml':'', 'value':'60'}) | |
409 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '------------------', 'xml':'', 'type':'separator'}) |
|
409 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '------------------', 'xml':'', 'type':'separator'}) | |
410 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'COMPORT CONFIG', 'xml':'', 'value':'Com1 CBR_9600 TWOSTOPBITS NOPARITY'}) |
|
410 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'COMPORT CONFIG', 'xml':'', 'value':'Com1 CBR_9600 TWOSTOPBITS NOPARITY'}) | |
411 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'JAM CONFIGURE FILE', 'xml':'', 'value':''}) |
|
411 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'JAM CONFIGURE FILE', 'xml':'', 'value':''}) | |
412 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'ACQUISITION SYSTEM', 'xml':'', 'value':'JARS'}) |
|
412 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'ACQUISITION SYSTEM', 'xml':'', 'value':'JARS'}) | |
413 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '******************', 'xml':'', 'type':'acq_system_config_params'}) |
|
413 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '******************', 'xml':'', 'type':'acq_system_config_params'}) | |
414 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SAVE DATA', 'xml':'', 'value':'YES'}) |
|
414 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'SAVE DATA', 'xml':'', 'value':'YES'}) | |
415 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '******************', 'xml':'', 'type':'rc_seq_config_params'}) |
|
415 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': '******************', 'xml':'', 'type':'rc_seq_config_params'}) | |
416 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'RC_STOP_SEQUENCE', 'xml':'', 'value':'255,0,255,8'}) |
|
416 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'RC_STOP_SEQUENCE', 'xml':'', 'value':'255,0,255,8'}) | |
417 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'RC_START_SEQUENCE', 'xml':'', 'value':'255,24'}) |
|
417 | self.process_param_fields['indices_experiment_number_'+str(i)].append({'number_experiment': i,'name': 'RC_START_SEQUENCE', 'xml':'', 'value':'255,24'}) | |
418 | def get_field_value(self, field, user_value): |
|
418 | def get_field_value(self, field, user_value): | |
419 | if 'type' in field and field['type'] == 'checkbox_YES_NO': # Check for existence of value |
|
419 | if 'type' in field and field['type'] == 'checkbox_YES_NO': # Check for existence of value | |
420 | if (user_value is None) or (user_value == 'None'): |
|
420 | if (user_value is None) or (user_value == 'None'): | |
421 | user_value = 'NO' |
|
421 | user_value = 'NO' | |
422 | elif user_value == 'on': |
|
422 | elif user_value == 'on': | |
423 | user_value = 'YES' |
|
423 | user_value = 'YES' | |
424 | if 'value' in field and not(user_value): # Replace by default value |
|
424 | if 'value' in field and not(user_value): # Replace by default value | |
425 | user_value = field['value'] |
|
425 | user_value = field['value'] | |
426 | if 'extra' in field and field['extra'] == 'upper': # Uppercase values |
|
426 | if 'extra' in field and field['extra'] == 'upper': # Uppercase values | |
427 | user_value = user_value.upper() |
|
427 | user_value = user_value.upper() | |
428 | return str(user_value) |
|
428 | return str(user_value) | |
429 |
|
429 | |||
430 | def load_xml(self, xml): |
|
430 | def load_xml(self, xml): | |
431 | self.xml = xml |
|
431 | self.xml = xml | |
432 | for i in range(self.number_of_experiments): |
|
432 | for i in range(self.number_of_experiments): | |
433 | for field in self.header_fields['indices_experiment_number_'+str(i)]: |
|
433 | for field in self.header_fields['indices_experiment_number_'+str(i)]: | |
434 | self.add_line_output(self.header['data_experiment_number_'+str(i)], field) |
|
434 | self.add_line_output(self.header['data_experiment_number_'+str(i)], field) | |
435 | for field in self.radar_param_fields['indices_experiment_number_'+str(i)]: |
|
435 | for field in self.radar_param_fields['indices_experiment_number_'+str(i)]: | |
436 | self.add_line_output(self.radar_param['data_experiment_number_'+str(i)], field) |
|
436 | self.add_line_output(self.radar_param['data_experiment_number_'+str(i)], field) | |
437 | for field in self.system_param1_fields['indices_experiment_number_'+str(i)]: |
|
437 | for field in self.system_param1_fields['indices_experiment_number_'+str(i)]: | |
438 | self.add_line_output(self.system_param1['data_experiment_number_'+str(i)], field) |
|
438 | self.add_line_output(self.system_param1['data_experiment_number_'+str(i)], field) | |
439 | for field in self.system_param2_fields['indices_experiment_number_'+str(i)]: |
|
439 | for field in self.system_param2_fields['indices_experiment_number_'+str(i)]: | |
440 | self.add_line_output(self.system_param2['data_experiment_number_'+str(i)], field) |
|
440 | self.add_line_output(self.system_param2['data_experiment_number_'+str(i)], field) | |
441 | for field in self.process_param_fields['indices_experiment_number_'+str(i)]: |
|
441 | for field in self.process_param_fields['indices_experiment_number_'+str(i)]: | |
442 | self.add_line_output(self.process_param['data_experiment_number_'+str(i)], field) |
|
442 | self.add_line_output(self.process_param['data_experiment_number_'+str(i)], field) | |
443 |
|
443 | |||
444 |
|
444 | |||
445 |
|
445 | |||
446 | def add_line_output(self, text_array, param_field): |
|
446 | def add_line_output(self, text_array, param_field): | |
447 |
|
447 | |||
448 |
|
448 | |||
449 | name = param_field['name'] |
|
449 | name = param_field['name'] | |
450 | xml_l = param_field['xml'] |
|
450 | xml_l = param_field['xml'] | |
451 | id = str(param_field['number_experiment']) |
|
451 | id = str(param_field['number_experiment']) | |
452 | acq_number_of_cards = int(self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Number_of_cards').text) |
|
452 | acq_number_of_cards = int(self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Number_of_cards').text) | |
453 | acq_channels_per_card = int(self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Channels_per_card').text) |
|
453 | acq_channels_per_card = int(self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Channels_per_card').text) | |
454 | number_of_acq_channels = acq_number_of_cards * acq_channels_per_card |
|
454 | number_of_acq_channels = acq_number_of_cards * acq_channels_per_card | |
455 |
|
455 | |||
456 |
|
456 | |||
457 |
|
457 | |||
458 | if 'xml_attr' in param_field and 'xml_attr_find' in param_field: |
|
458 | if 'xml_attr' in param_field and 'xml_attr_find' in param_field: | |
459 | sub_pattern = False |
|
459 | sub_pattern = False | |
460 | if 'xml_sub_pattern' in param_field: |
|
460 | if 'xml_sub_pattern' in param_field: | |
461 | sub_pattern = param_field['xml_sub_pattern'] |
|
461 | sub_pattern = param_field['xml_sub_pattern'] | |
462 | element = self.xml.find_by_attribute_value(xml_l, param_field['xml_attr'], param_field['xml_attr_find'],sub_pattern) |
|
462 | element = self.xml.find_by_attribute_value(xml_l, param_field['xml_attr'], param_field['xml_attr_find'],sub_pattern) | |
463 | else: |
|
463 | else: | |
464 | element = self.xml.find(xml_l) |
|
464 | element = self.xml.find(xml_l) | |
465 |
|
465 | |||
466 | if 'xml_attr_value' in param_field: |
|
466 | if 'xml_attr_value' in param_field: | |
467 | value = element.get(param_field['xml_attr_value']) |
|
467 | value = element.get(param_field['xml_attr_value']) | |
468 | else: |
|
468 | else: | |
469 | value = '' |
|
469 | value = '' | |
470 | if xml_l == '' and 'value' in param_field: |
|
470 | if xml_l == '' and 'value' in param_field: | |
471 | value = param_field['value'] |
|
471 | value = param_field['value'] | |
472 | elif hasattr(element, 'text'): |
|
472 | elif hasattr(element, 'text'): | |
473 | value = element.text |
|
473 | value = element.text | |
474 |
|
474 | |||
475 | if 'type' in param_field and param_field['type'] == 'separator': # Check for existence of value |
|
475 | if 'type' in param_field and param_field['type'] == 'separator': # Check for existence of value | |
476 | text_array.append('------------------------------------------') |
|
476 | text_array.append('------------------------------------------') | |
477 | return |
|
477 | return | |
478 | if 'type' in param_field and param_field['type'] == 'acq_system_config_params': # Get Acquisition System Parameters and add them |
|
478 | if 'type' in param_field and param_field['type'] == 'acq_system_config_params': # Get Acquisition System Parameters and add them | |
479 | text_array.append("************JARS CONFIGURATION PARAMETERS************") |
|
479 | text_array.append("************JARS CONFIGURATION PARAMETERS************") | |
480 | if self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Filter').text: |
|
480 | if self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Filter').text: | |
481 | # Notice that we need to use backslashes for the filter path |
|
481 | # Notice that we need to use backslashes for the filter path | |
482 | text_array.append("Jars_Filter="+self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Filter_dir').text +'\\'+ self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Filter').text) |
|
482 | text_array.append("Jars_Filter="+self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Filter_dir').text +'\\'+ self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/Filter').text) | |
483 | else: |
|
483 | else: | |
484 | text_array.append("Jars_Filter=") |
|
484 | text_array.append("Jars_Filter=") | |
485 | text_array.append("JARS_Collection_Mode="+self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/JARS_Collection_Mode').text) |
|
485 | text_array.append("JARS_Collection_Mode="+self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/JARS/JARS_Collection_Mode').text) | |
486 | text_array.append("SAVE_DATA=YES") |
|
486 | text_array.append("SAVE_DATA=YES") | |
487 | text_array.append("*****************************************************") |
|
487 | text_array.append("*****************************************************") | |
488 | return |
|
488 | return | |
489 | if 'type' in param_field and param_field['type'] == 'rc_seq_config_params': # Get Acquisition System Parameters and add them |
|
489 | if 'type' in param_field and param_field['type'] == 'rc_seq_config_params': # Get Acquisition System Parameters and add them | |
490 | text_array.append("****************RC SEQUENCES******************") |
|
490 | text_array.append("****************RC SEQUENCES******************") | |
491 | return |
|
491 | return | |
492 | ##{'name': '***', 'xml':'', 'type':'pulse_enable'}, |
|
492 | ##{'name': '***', 'xml':'', 'type':'pulse_enable'}, | |
493 | if 'type' in param_field: |
|
493 | if 'type' in param_field: | |
494 | if param_field['type'] == 'pulse_enable': |
|
494 | if param_field['type'] == 'pulse_enable': | |
495 | txa_enable = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Transmitters/TX', 'id', 'txa', 'Pulses') |
|
495 | txa_enable = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Transmitters/TX', 'id', 'txa', 'Pulses') | |
496 | if txa_enable.text is not None: |
|
496 | if txa_enable.text is not None: | |
497 | text_array.append('Pulse selection_TXA='+txa_enable.text) |
|
497 | text_array.append('Pulse selection_TXA='+txa_enable.text) | |
498 | txb_enable = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Transmitters/TX', 'id', 'txb', 'Pulses') |
|
498 | txb_enable = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Transmitters/TX', 'id', 'txb', 'Pulses') | |
499 | if txb_enable.text is not None: |
|
499 | if txb_enable.text is not None: | |
500 | text_array.append('Pulse selection_TXB='+txb_enable.text) |
|
500 | text_array.append('Pulse selection_TXB='+txb_enable.text) | |
501 | tr_enable = self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/IPP/Pulses') |
|
501 | tr_enable = self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/IPP/Pulses') | |
502 | if tr_enable.text is not None: |
|
502 | if tr_enable.text is not None: | |
503 | text_array.append('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Pulse selection_TR='+tr_enable.text) |
|
503 | text_array.append('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Pulse selection_TR='+tr_enable.text) | |
504 | return |
|
504 | return | |
505 | elif param_field['type'] == 'Line4' or param_field['type'] == 'Line5' or param_field['type'] == 'Line6' or param_field['type'] == 'Line7': |
|
505 | elif param_field['type'] == 'Line4' or param_field['type'] == 'Line5' or param_field['type'] == 'Line6' or param_field['type'] == 'Line7': | |
506 | code_name = 'Code_A' |
|
506 | code_name = 'Code_A' | |
507 | line_number = '4' |
|
507 | line_number = '4' | |
508 | line_parenthesis = '' |
|
508 | line_parenthesis = '' | |
509 | line_prepend = '' |
|
509 | line_prepend = '' | |
510 |
|
510 | |||
511 | if param_field['type'] == 'Line5': |
|
511 | if param_field['type'] == 'Line5': | |
512 | code_name = 'Code_B' |
|
512 | code_name = 'Code_B' | |
513 | line_number = '5' |
|
513 | line_number = '5' | |
514 | line_parenthesis = ' (Line 5)' |
|
514 | line_parenthesis = ' (Line 5)' | |
515 | line_prepend = 'L5_' |
|
515 | line_prepend = 'L5_' | |
516 | elif param_field['type'] == 'Line6': |
|
516 | elif param_field['type'] == 'Line6': | |
517 | code_name = 'Code_C' |
|
517 | code_name = 'Code_C' | |
518 | line_number = '6' |
|
518 | line_number = '6' | |
519 | line_parenthesis = ' (Line 6)' |
|
519 | line_parenthesis = ' (Line 6)' | |
520 | line_prepend = 'L6_' |
|
520 | line_prepend = 'L6_' | |
521 | elif param_field['type'] == 'Line7': |
|
521 | elif param_field['type'] == 'Line7': | |
522 | code_name = 'Code_D' |
|
522 | code_name = 'Code_D' | |
523 | line_number = '7' |
|
523 | line_number = '7' | |
524 | line_parenthesis = ' (Line 7)' |
|
524 | line_parenthesis = ' (Line 7)' | |
525 | line_prepend = 'L7_' |
|
525 | line_prepend = 'L7_' | |
526 |
|
526 | |||
527 | code_channel = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Mode').text |
|
527 | code_channel = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Mode').text | |
528 | if code_channel == 'FLIP': |
|
528 | if code_channel == 'FLIP': | |
529 | value = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Flip').text |
|
529 | value = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Flip').text | |
530 | flip_name = 'L'+line_number+'_FLIP' + line_parenthesis |
|
530 | flip_name = 'L'+line_number+'_FLIP' + line_parenthesis | |
531 | if param_field['type'] == 'Line5': |
|
531 | if param_field['type'] == 'Line5': | |
532 | flip_name = 'FLIP1' |
|
532 | flip_name = 'FLIP1' | |
533 | elif param_field['type'] == 'Line6': |
|
533 | elif param_field['type'] == 'Line6': | |
534 | flip_name = 'FLIP2' |
|
534 | flip_name = 'FLIP2' | |
535 | text_array.append(flip_name + '='+value) |
|
535 | text_array.append(flip_name + '='+value) | |
536 | elif code_channel == 'CODE': |
|
536 | elif code_channel == 'CODE': | |
537 | code_data = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Code') |
|
537 | code_data = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Code') | |
538 | Code_reference = code_data.find('Code_reference').text |
|
538 | Code_reference = code_data.find('Code_reference').text | |
539 | Code_select = code_data.find('Code_select').text |
|
539 | Code_select = code_data.find('Code_select').text | |
540 | Code_number = code_data.find('Code_number').text |
|
540 | Code_number = code_data.find('Code_number').text | |
541 | Code_bits = code_data.find('Code_bits').text |
|
541 | Code_bits = code_data.find('Code_bits').text | |
542 | custom_codes = get_custom_code_data(Code_select, int(Code_number), int(Code_bits)) |
|
542 | custom_codes = get_custom_code_data(Code_select, int(Code_number), int(Code_bits)) | |
543 | text_array.append('Code Type' + line_parenthesis + '='+Code_select) |
|
543 | text_array.append('Code Type' + line_parenthesis + '='+Code_select) | |
544 | text_array.append('Number of Codes' + line_parenthesis + '='+Code_number) |
|
544 | text_array.append('Number of Codes' + line_parenthesis + '='+Code_number) | |
545 | text_array.append('Code Width' + line_parenthesis + '='+Code_bits) |
|
545 | text_array.append('Code Width' + line_parenthesis + '='+Code_bits) | |
546 | for zero_idx, custom_code in enumerate(custom_codes): |
|
546 | for zero_idx, custom_code in enumerate(custom_codes): | |
547 | text_array.append(line_prepend+'COD('+str(zero_idx)+')='+custom_code) |
|
547 | text_array.append(line_prepend+'COD('+str(zero_idx)+')='+custom_code) | |
548 | # Calculate Codes |
|
548 | # Calculate Codes | |
549 | text_array.append('L'+line_number+'_REFERENCE='+Code_reference.upper()) |
|
549 | text_array.append('L'+line_number+'_REFERENCE='+Code_reference.upper()) | |
550 | elif code_channel == 'Sampling': |
|
550 | elif code_channel == 'Sampling': | |
551 | sampling_name = 'Sampling Windows (Line ' + line_number + ')' |
|
551 | sampling_name = 'Sampling Windows (Line ' + line_number + ')' | |
552 | prepend = 'L'+line_number+'_' |
|
552 | prepend = 'L'+line_number+'_' | |
553 | if param_field['type'] == 'Line7': |
|
553 | if param_field['type'] == 'Line7': | |
554 | sampling_name = 'Sampling Windows' |
|
554 | sampling_name = 'Sampling Windows' | |
555 | prepend = '' |
|
555 | prepend = '' | |
556 | sampling_data = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Sampling') |
|
556 | sampling_data = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'Sampling') | |
557 | Code_reference = sampling_data.find('Code_reference').text.upper() |
|
557 | Code_reference = sampling_data.find('Code_reference').text.upper() | |
558 | samples = sampling_data.find('Samples') |
|
558 | samples = sampling_data.find('Samples') | |
559 | text_array.append(sampling_name+'='+str(len(samples))) |
|
559 | text_array.append(sampling_name+'='+str(len(samples))) | |
560 | for zero_idx, sample in enumerate(samples): |
|
560 | for zero_idx, sample in enumerate(samples): | |
561 | text_array.append(prepend+'H0('+str(zero_idx)+')='+sample.find('FH').text) |
|
561 | text_array.append(prepend+'H0('+str(zero_idx)+')='+sample.find('FH').text) | |
562 | text_array.append(prepend+'NSA('+str(zero_idx)+')='+sample.find('NSA').text) |
|
562 | text_array.append(prepend+'NSA('+str(zero_idx)+')='+sample.find('NSA').text) | |
563 | text_array.append(prepend+'DH('+str(zero_idx)+')='+sample.find('DH').text) |
|
563 | text_array.append(prepend+'DH('+str(zero_idx)+')='+sample.find('DH').text) | |
564 | text_array.append('L'+line_number+'_REFERENCE='+Code_reference.upper()) |
|
564 | text_array.append('L'+line_number+'_REFERENCE='+Code_reference.upper()) | |
565 | elif code_channel == 'Synchro': |
|
565 | elif code_channel == 'Synchro': | |
566 | text_array.append('Line'+line_number+'=Synchro') |
|
566 | text_array.append('Line'+line_number+'=Synchro') | |
567 | elif code_channel == 'Portion_Spec': |
|
567 | elif code_channel == 'Portion_Spec': | |
568 | portion_data = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'PortionSpec') |
|
568 | portion_data = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Code_channels/Code_channel', 'id', code_name, 'PortionSpec') | |
569 | periodic = portion_data.find('Periodic').text |
|
569 | periodic = portion_data.find('Periodic').text | |
570 | portions = portion_data.find('Portions') |
|
570 | portions = portion_data.find('Portions') | |
571 | text_array.append('L'+line_number+' Number Of Portions='+str(len(portions))) |
|
571 | text_array.append('L'+line_number+' Number Of Portions='+str(len(portions))) | |
572 | for zero_idx, portion in enumerate(portions): |
|
572 | for zero_idx, portion in enumerate(portions): | |
573 | text_array.append('PORTION_BEGIN('+str(zero_idx)+')='+portion.find('Begin_units').text) |
|
573 | text_array.append('PORTION_BEGIN('+str(zero_idx)+')='+portion.find('Begin_units').text) | |
574 | text_array.append('PORTION_END('+str(zero_idx)+')='+portion.find('End_units').text) |
|
574 | text_array.append('PORTION_END('+str(zero_idx)+')='+portion.find('End_units').text) | |
575 | if periodic == '1': |
|
575 | if periodic == '1': | |
576 | text_array.append('L'+line_number+' Portions IPP Periodic=YES') |
|
576 | text_array.append('L'+line_number+' Portions IPP Periodic=YES') | |
577 | else: |
|
577 | else: | |
578 | text_array.append('L'+line_number+' Portions IPP Periodic=NO') |
|
578 | text_array.append('L'+line_number+' Portions IPP Periodic=NO') | |
579 | return |
|
579 | return | |
580 | elif param_field['type'] == 'txb_delays_info': |
|
580 | elif param_field['type'] == 'txb_delays_info': | |
581 | txb_delays = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Transmitters/TX', 'id', 'txb', 'Delays') |
|
581 | txb_delays = self.xml.find_by_attribute_value('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Controller/Transmitters/TX', 'id', 'txb', 'Delays') | |
582 | text_array.append("Number of Taus="+str(len(txb_delays))) |
|
582 | text_array.append("Number of Taus="+str(len(txb_delays))) | |
583 | for zero_index, txb_delay in enumerate(txb_delays): |
|
583 | for zero_index, txb_delay in enumerate(txb_delays): | |
584 | text_array.append('TAU('+str(zero_index)+')='+str(txb_delay.text)) |
|
584 | text_array.append('TAU('+str(zero_index)+')='+str(txb_delay.text)) | |
585 | return |
|
585 | return | |
586 | elif param_field['type'] == 'cards_info': # Get Cards info |
|
586 | elif param_field['type'] == 'cards_info': # Get Cards info | |
587 | if not(acq_number_of_cards == '0'): |
|
587 | if not(acq_number_of_cards == '0'): | |
588 | for card in range(acq_number_of_cards): |
|
588 | for card in range(acq_number_of_cards): | |
589 | name = 'Card('+str(card)+')' |
|
589 | name = 'Card('+str(card)+')' | |
590 | text_array.append(name + "=" + str(card)) |
|
590 | text_array.append(name + "=" + str(card)) | |
591 | return |
|
591 | return | |
592 | elif param_field['type'] == 'channels_info': # Get Channel info |
|
592 | elif param_field['type'] == 'channels_info': # Get Channel info | |
593 | text_array.append("Number of Channels="+str(number_of_acq_channels)) |
|
593 | text_array.append("Number of Channels="+str(number_of_acq_channels)) | |
594 | if not(number_of_acq_channels == '0'): |
|
594 | if not(number_of_acq_channels == '0'): | |
595 | acq_channels = self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/Acq_channel_selection') |
|
595 | acq_channels = self.xml.find('Experiments/List/Experiment['+id+']/XML_contents/Pulse_Design/Experiment/Process/Acq_channel_selection') | |
596 | enabled_channels = [] |
|
596 | enabled_channels = [] | |
597 | channel_names =[] |
|
597 | channel_names =[] | |
598 | for acq_channel in acq_channels: |
|
598 | for acq_channel in acq_channels: | |
599 | acq_channel_number = acq_channel.get('id') |
|
599 | acq_channel_number = acq_channel.get('id') | |
600 | acq_channel_name = acq_channel.find('Name').text |
|
600 | acq_channel_name = acq_channel.find('Name').text | |
601 | enabled = False |
|
601 | enabled = False | |
602 | if hasattr(acq_channel.find('Enabled'), 'text'): |
|
602 | if hasattr(acq_channel.find('Enabled'), 'text'): | |
603 | enabled = acq_channel.find('Enabled').text |
|
603 | enabled = acq_channel.find('Enabled').text | |
604 | if enabled == 'on': |
|
604 | if enabled == 'on': | |
605 | text_array.append("Channel("+acq_channel_number+")=" + str(int(acq_channel_number)+1)) |
|
605 | text_array.append("Channel("+acq_channel_number+")=" + str(int(acq_channel_number)+1)) | |
606 | enabled_channels.append(acq_channel_number) |
|
606 | enabled_channels.append(acq_channel_number) | |
607 | channel_names.append(acq_channel_name) |
|
607 | channel_names.append(acq_channel_name) | |
608 | text_array.append("Antennas_Names="+str(len(enabled_channels))) |
|
608 | text_array.append("Antennas_Names="+str(len(enabled_channels))) | |
609 | for index, channel in enumerate(enabled_channels): |
|
609 | for index, channel in enumerate(enabled_channels): | |
610 | text_array.append("AntennaName(" + str(int(channel)+1) + ")="+str(channel_names[index])) |
|
610 | text_array.append("AntennaName(" + str(int(channel)+1) + ")="+str(channel_names[index])) | |
611 | return |
|
611 | return | |
612 | if 'hide' in param_field and value in param_field['hide']: # Check to see if value should be written |
|
612 | if 'hide' in param_field and value in param_field['hide']: # Check to see if value should be written | |
613 | return |
|
613 | return | |
614 | text_array.append(name + "=" + self.get_field_value(param_field, value)) |
|
614 | text_array.append(name + "=" + self.get_field_value(param_field, value)) | |
615 |
|
615 | |||
616 | def convert_to_racp(self): |
|
616 | def convert_to_racp(self): | |
617 | output = [] |
|
617 | output = [] | |
618 | # HEADER |
|
618 | # HEADER | |
619 | for i in range(self.number_of_experiments): |
|
619 | for i in range(self.number_of_experiments): | |
620 | for line in self.header['data_experiment_number_'+str(i)]: |
|
620 | for line in self.header['data_experiment_number_'+str(i)]: | |
621 | output.append(line) |
|
621 | output.append(line) | |
622 | output.append('HEADER VERSION='+self.header['version']) |
|
622 | output.append('HEADER VERSION='+self.header['version']) | |
623 | # RADAR PARAMETERS |
|
623 | # RADAR PARAMETERS | |
624 | output.append(self.radar_param['header']) |
|
624 | output.append(self.radar_param['header']) | |
625 | for line in self.radar_param['data_experiment_number_'+str(i)]: |
|
625 | for line in self.radar_param['data_experiment_number_'+str(i)]: | |
626 | output.append(line) |
|
626 | output.append(line) | |
627 | # SYSTEM PARAMETERS |
|
627 | # SYSTEM PARAMETERS | |
628 | output.append(self.system_param1['header']) |
|
628 | output.append(self.system_param1['header']) | |
629 | for line in self.system_param1['data_experiment_number_'+str(i)]: |
|
629 | for line in self.system_param1['data_experiment_number_'+str(i)]: | |
630 | output.append(line) |
|
630 | output.append(line) | |
631 | output.append(self.system_param2['header']) |
|
631 | output.append(self.system_param2['header']) | |
632 | for line in self.system_param2['data_experiment_number_'+str(i)]: |
|
632 | for line in self.system_param2['data_experiment_number_'+str(i)]: | |
633 | output.append(line) |
|
633 | output.append(line) | |
634 | # PROCESS PARAMETERS |
|
634 | # PROCESS PARAMETERS | |
635 | output.append(self.process_param['header']) |
|
635 | output.append(self.process_param['header']) | |
636 | for line in self.process_param['data_experiment_number_'+str(i)]: |
|
636 | for line in self.process_param['data_experiment_number_'+str(i)]: | |
637 | output.append(line) |
|
637 | output.append(line) | |
638 | output.append("\n") |
|
638 | output.append("\n") | |
639 |
|
639 | |||
640 | racp_content = "\n".join([str(x) for x in output]) |
|
640 | racp_content = "\n".join([str(x) for x in output]) | |
641 | return racp_content |
|
641 | return racp_content | |
642 |
|
642 | |||
643 | class RCFile(object): |
|
643 | class RCFile(object): | |
644 |
|
644 | |||
645 | def __init__(self, f=None): |
|
645 | def __init__(self, f=None): | |
646 |
|
646 | |||
647 | self.data = {} |
|
647 | self.data = {} | |
648 | if isinstance(f, str): |
|
648 | if isinstance(f, str): | |
649 | self.f = open(f) |
|
649 | self.f = open(f) | |
650 | self.name = f.split('/')[-1] |
|
650 | self.name = f.split('/')[-1] | |
651 | elif hasattr(f, 'read'): |
|
651 | elif hasattr(f, 'read'): | |
652 | self.f = f |
|
652 | self.f = f | |
653 | self.name = f.name.split('/')[-1] |
|
653 | self.name = f.name.split('/')[-1] | |
654 | else: |
|
654 | else: | |
655 | self.f = f |
|
655 | self.f = f | |
656 | self.name = None |
|
656 | self.name = None | |
657 |
|
657 | |||
658 | if self.f: |
|
658 | if self.f: | |
659 | if 'racp' in self.name: |
|
659 | if 'racp' in self.name: | |
660 | self.parse_racp() |
|
660 | self.parse_racp() | |
661 | elif 'dat' in self.name: |
|
661 | elif 'dat' in self.name: | |
662 | self.parse_dat() |
|
662 | self.parse_dat() | |
663 |
|
663 | |||
664 | def get_line_parameters(self, data, line): |
|
664 | def get_line_parameters(self, data, line): | |
665 |
|
665 | |||
666 | line_params = {} |
|
666 | line_params = {} | |
667 | for label in data: |
|
667 | for label in data: | |
668 | if 'L%d' % line in label or '(Line %d)' % line in label or 'Line%d' % line in label: |
|
668 | if 'L%d' % line in label or '(Line %d)' % line in label or 'Line%d' % line in label: | |
669 | line_params[label] = data[label] |
|
669 | line_params[label] = data[label] | |
670 | return line_params |
|
670 | return line_params | |
671 |
|
671 | |||
672 | def parse_racp(self): |
|
672 | def parse_racp(self): | |
673 |
|
673 | |||
674 | data = {} |
|
674 | data = {} | |
675 | raw_data = [s.strip() for s in self.f.readlines()] |
|
675 | raw_data = [s.strip() for s in self.f.readlines()] | |
676 | for line in raw_data: |
|
676 | for line in raw_data: | |
677 | if line and '=' in line: |
|
677 | if line and '=' in line: | |
678 | label, value = line.strip().split('=') |
|
678 | label, value = line.strip().split('=') | |
679 | data[label] = value |
|
679 | data[label] = value | |
680 | self.data['experiment_type'] = data['EXPERIMENT TYPE'] |
|
680 | self.data['experiment_type'] = data['EXPERIMENT TYPE'] | |
681 | self.data['header_version'] = data['HEADER VERSION'] |
|
681 | self.data['header_version'] = data['HEADER VERSION'] | |
682 | self.data['name'] = data['EXPERIMENT NAME'] |
|
682 | self.data['name'] = data['EXPERIMENT NAME'] | |
683 | self.data['ipp'] = float(data['IPP']) |
|
683 | self.data['ipp'] = float(data['IPP']) | |
684 | self.data['ntx'] = int(data['NTX']) |
|
684 | self.data['ntx'] = int(data['NTX']) | |
685 | if 'CLOCK DIVIDER' in data: |
|
685 | if 'CLOCK DIVIDER' in data: | |
686 | self.data['clock_divider'] = int(data['CLOCK DIVIDER']) |
|
686 | self.data['clock_divider'] = int(data['CLOCK DIVIDER']) | |
687 | else: |
|
687 | else: | |
688 | self.data['clock_divider'] = 1 |
|
688 | self.data['clock_divider'] = 1 | |
689 | self.data['clock'] = float(data['RELOJ'])*self.data['clock_divider'] |
|
689 | self.data['clock'] = float(data['RELOJ'])*self.data['clock_divider'] | |
690 | self.data['time_before'] = int(data['TR_BEFORE']) |
|
690 | self.data['time_before'] = int(data['TR_BEFORE']) | |
691 | self.data['time_after'] = int(data['TR_AFTER']) |
|
691 | self.data['time_after'] = int(data['TR_AFTER']) | |
692 | if 'SYNCHRO DELAY' in data: |
|
692 | if 'SYNCHRO DELAY' in data: | |
693 | self.data['sync'] = int(data['SYNCHRO DELAY']) |
|
693 | self.data['sync'] = int(data['SYNCHRO DELAY']) | |
694 | else: |
|
694 | else: | |
695 | self.data['sync'] = 0 |
|
695 | self.data['sync'] = 0 | |
696 | self.data['lines'] = [] |
|
696 | self.data['lines'] = [] | |
697 |
|
697 | |||
698 | #Add TR line |
|
698 | #Add TR line | |
699 | if 'Pulse selection_TR' in data: |
|
699 | if 'Pulse selection_TR' in data: | |
700 | if 'A' in data['Pulse selection_TR']: |
|
700 | if 'A' in data['Pulse selection_TR']: | |
701 | rng = data['Pulse selection_TR'].replace('A', '') |
|
701 | rng = data['Pulse selection_TR'].replace('A', '') | |
702 | elif 'B' in data['Pulse selection_TR']: |
|
702 | elif 'B' in data['Pulse selection_TR']: | |
703 | rng = data['Pulse selection_TR'].replace('B', '') |
|
703 | rng = data['Pulse selection_TR'].replace('B', '') | |
704 | else: |
|
704 | else: | |
705 | rng = data['Pulse selection_TR'] |
|
705 | rng = data['Pulse selection_TR'] | |
706 | line = {'type':'tr', 'range': rng, 'TX_ref':'TXA'} |
|
706 | line = {'type':'tr', 'range': rng, 'TX_ref':'TXA'} | |
707 | else: |
|
707 | else: | |
708 | line = {'type': 'tr', 'range': 0, 'TX_ref': '0'} |
|
708 | line = {'type': 'tr', 'range': 0, 'TX_ref': '0'} | |
709 |
|
709 | |||
710 | self.data['lines'].append(line) |
|
710 | self.data['lines'].append(line) | |
711 |
|
711 | |||
712 | #Add TX's lines |
|
712 | #Add TX's lines | |
713 | if 'TXA' in data: |
|
713 | if 'TXA' in data: | |
714 | line = {'type':'tx', 'pulse_width':data['TXA'], 'delays':'0'} |
|
714 | line = {'type':'tx', 'pulse_width':data['TXA'], 'delays':'0'} | |
715 | if 'Pulse selection_TXA' in data: |
|
715 | if 'Pulse selection_TXA' in data: | |
716 | line['range'] = data['Pulse selection_TXA'] |
|
716 | line['range'] = data['Pulse selection_TXA'] | |
717 | else: |
|
717 | else: | |
718 | line['range'] = '0' |
|
718 | line['range'] = '0' | |
719 | self.data['lines'].append(line) |
|
719 | self.data['lines'].append(line) | |
720 |
|
720 | |||
721 | if 'TXB' in data: |
|
721 | if 'TXB' in data: | |
722 | line = {'type':'tx', 'pulse_width':data['TXB'], 'delays':'0'} |
|
722 | line = {'type':'tx', 'pulse_width':data['TXB'], 'delays':'0'} | |
723 | if 'Pulse selection_TXB' in data: |
|
723 | if 'Pulse selection_TXB' in data: | |
724 | line['range'] = data['Pulse selection_TXB'] |
|
724 | line['range'] = data['Pulse selection_TXB'] | |
725 | else: |
|
725 | else: | |
726 | line['range'] = '0' |
|
726 | line['range'] = '0' | |
727 |
|
727 | |||
728 | if 'Number of Taus' in data: |
|
728 | if 'Number of Taus' in data: | |
729 | delays = [data['TAU({0})'.format(i)] for i in range(int(data['Number of Taus']))] |
|
729 | delays = [data['TAU({0})'.format(i)] for i in range(int(data['Number of Taus']))] | |
730 | line['delays'] = ','.join(delays) |
|
730 | line['delays'] = ','.join(delays) | |
731 |
|
731 | |||
732 | self.data['lines'].append(line) |
|
732 | self.data['lines'].append(line) | |
733 |
|
733 | |||
734 | #Add Other lines (4-6) |
|
734 | #Add Other lines (4-6) | |
735 | for n in range(4, 7): |
|
735 | for n in range(4, 7): | |
736 | params = self.get_line_parameters(data, n) |
|
736 | params = self.get_line_parameters(data, n) | |
737 | labels = params.keys() |
|
737 | labels = params.keys() | |
738 |
|
738 | |||
739 | if 'L%d_FLIP' % n in labels: |
|
739 | if 'L%d_FLIP' % n in labels: | |
740 | line = {'type':'flip', 'number_of_flips':data['L%d_FLIP' % n]} |
|
740 | line = {'type':'flip', 'number_of_flips':data['L%d_FLIP' % n]} | |
741 | elif 'Code Type' in data and n==4: |
|
741 | elif 'Code Type' in data and n==4: | |
742 | line = {'type':'codes', 'code':data['Code Type'], 'TX_ref':data['L%d_REFERENCE' % n]} |
|
742 | line = {'type':'codes', 'code':data['Code Type'], 'TX_ref':data['L%d_REFERENCE' % n]} | |
743 | elif 'Code Type (Line %d)' % n in labels: |
|
743 | elif 'Code Type (Line %d)' % n in labels: | |
744 | line = {'type':'codes', 'code':data['Code Type (Line %d)' % n], 'TX_ref':data['L%d_REFERENCE' % n]} |
|
744 | line = {'type':'codes', 'code':data['Code Type (Line %d)' % n], 'TX_ref':data['L%d_REFERENCE' % n]} | |
745 | elif 'Sampling Windows (Line %d)' % n in data: |
|
745 | elif 'Sampling Windows (Line %d)' % n in data: | |
746 | line = {'type':'windows', 'TX_ref':data['L%d_REFERENCE' % n]} |
|
746 | line = {'type':'windows', 'TX_ref':data['L%d_REFERENCE' % n]} | |
747 | windows = [] |
|
747 | windows = [] | |
748 | for w in range(int(data['Sampling Windows (Line %d)' % n])): |
|
748 | for w in range(int(data['Sampling Windows (Line %d)' % n])): | |
749 | windows.append({'first_height':float(data['L%d_H0(%d)' % (n, w)]), |
|
749 | windows.append({'first_height':float(data['L%d_H0(%d)' % (n, w)]), | |
750 | 'number_of_samples':int(data['L%d_NSA(%d)' % (n, w)]), |
|
750 | 'number_of_samples':int(data['L%d_NSA(%d)' % (n, w)]), | |
751 | 'resolution':float(data['L%d_DH(%d)' % (n, w)])} |
|
751 | 'resolution':float(data['L%d_DH(%d)' % (n, w)])} | |
752 | ) |
|
752 | ) | |
753 | line['params'] = windows |
|
753 | line['params'] = windows | |
754 | elif 'Line%d' % n in labels and data['Line%d' % n]=='Synchro': |
|
754 | elif 'Line%d' % n in labels and data['Line%d' % n]=='Synchro': | |
755 | line = {'type':'sync', 'invert':0} |
|
755 | line = {'type':'sync', 'invert':0} | |
756 | elif 'L%d Number Of Portions' % n in labels: |
|
756 | elif 'L%d Number Of Portions' % n in labels: | |
757 | line = {'type':'prog_pulses'} |
|
757 | line = {'type':'prog_pulses'} | |
758 | if 'L%s Portions IPP Periodic' % n in data: |
|
758 | if 'L%s Portions IPP Periodic' % n in data: | |
759 | line['periodic'] = 1 if data['L%s Portions IPP Periodic' % n]=='YES' else 0 |
|
759 | line['periodic'] = 1 if data['L%s Portions IPP Periodic' % n]=='YES' else 0 | |
760 | portions = [] |
|
760 | portions = [] | |
761 | x = raw_data.index('L%d Number Of Portions=%s' % (n, data['L%d Number Of Portions' % n])) |
|
761 | x = raw_data.index('L%d Number Of Portions=%s' % (n, data['L%d Number Of Portions' % n])) | |
762 | for w in range(int(data['L%d Number Of Portions' % n])): |
|
762 | for w in range(int(data['L%d Number Of Portions' % n])): | |
763 | begin = raw_data[x+1+2*w].split('=')[-1] |
|
763 | begin = raw_data[x+1+2*w].split('=')[-1] | |
764 | end = raw_data[x+2+2*w].split('=')[-1] |
|
764 | end = raw_data[x+2+2*w].split('=')[-1] | |
765 | portions.append({'begin':int(begin), |
|
765 | portions.append({'begin':int(begin), | |
766 | 'end':int(end)} |
|
766 | 'end':int(end)} | |
767 | ) |
|
767 | ) | |
768 | line['params'] = portions |
|
768 | line['params'] = portions | |
769 | elif 'FLIP1' in data and n==5: |
|
769 | elif 'FLIP1' in data and n==5: | |
770 | line = {'type':'flip', 'number_of_flips':data['FLIP1']} |
|
770 | line = {'type':'flip', 'number_of_flips':data['FLIP1']} | |
771 | elif 'FLIP2' in data and n==6: |
|
771 | elif 'FLIP2' in data and n==6: | |
772 | line = {'type':'flip', 'number_of_flips':data['FLIP2']} |
|
772 | line = {'type':'flip', 'number_of_flips':data['FLIP2']} | |
773 | else: |
|
773 | else: | |
774 | line = {'type':'none'} |
|
774 | line = {'type':'none'} | |
775 |
|
775 | |||
776 | self.data['lines'].append(line) |
|
776 | self.data['lines'].append(line) | |
777 |
|
777 | |||
778 | #Add line 7 (windows) |
|
778 | #Add line 7 (windows) | |
779 | if 'Sampling Windows' in data: |
|
779 | if 'Sampling Windows' in data: | |
780 | line = {'type':'windows', 'TX_ref':data['L7_REFERENCE']} |
|
780 | line = {'type':'windows', 'TX_ref':data['L7_REFERENCE']} | |
781 | windows = [] |
|
781 | windows = [] | |
782 | x = raw_data.index('Sampling Windows=%s' % data['Sampling Windows']) |
|
782 | x = raw_data.index('Sampling Windows=%s' % data['Sampling Windows']) | |
783 | for w in range(int(data['Sampling Windows'])): |
|
783 | for w in range(int(data['Sampling Windows'])): | |
784 | h0 = raw_data[x+1+3*w].split('=')[-1] |
|
784 | h0 = raw_data[x+1+3*w].split('=')[-1] | |
785 | nsa = raw_data[x+2+3*w].split('=')[-1] |
|
785 | nsa = raw_data[x+2+3*w].split('=')[-1] | |
786 | dh = raw_data[x+3+3*w].split('=')[-1] |
|
786 | dh = raw_data[x+3+3*w].split('=')[-1] | |
787 | windows.append({'first_height':float(h0), |
|
787 | windows.append({'first_height':float(h0), | |
788 | 'number_of_samples':int(nsa), |
|
788 | 'number_of_samples':int(nsa), | |
789 | 'resolution':float(dh)} |
|
789 | 'resolution':float(dh)} | |
790 | ) |
|
790 | ) | |
791 | line['params'] = windows |
|
791 | line['params'] = windows | |
792 | self.data['lines'].append(line) |
|
792 | self.data['lines'].append(line) | |
793 | else: |
|
793 | else: | |
794 | self.data['lines'].append({'type':'none'}) |
|
794 | self.data['lines'].append({'type':'none'}) | |
795 |
|
795 | |||
796 | #Add line 8 (synchro inverted) |
|
796 | #Add line 8 (synchro inverted) | |
797 | self.data['lines'].append({'type':'sync', 'invert':1}) |
|
797 | self.data['lines'].append({'type':'sync', 'invert':1}) | |
798 |
|
798 | |||
799 | return |
|
799 | return | |
800 |
|
800 | |||
801 | def parse_dat(self): |
|
801 | def parse_dat(self): | |
802 | pass |
|
802 | pass | |
803 |
|
803 | |||
804 |
|
804 | |||
805 | def get_json(self, indent=None): |
|
805 | def get_json(self, indent=None): | |
806 | return json.dumps(self.data, indent=indent) |
|
806 | return json.dumps(self.data, indent=indent) | |
807 |
|
807 | |||
808 |
|
808 | |||
809 | def pulses_to_bar(X): |
|
809 | def pulses_to_bar(X): | |
810 |
|
810 | |||
811 |
|
811 | |||
812 | d = X[1:]-X[:-1] |
|
812 | d = X[1:]-X[:-1] | |
813 |
|
813 | |||
814 | up = np.where(d==1)[0] |
|
814 | up = np.where(d==1)[0] | |
815 | if X[0]==1: |
|
815 | if X[0]==1: | |
816 | up = np.concatenate((np.array([-1]), up)) |
|
816 | up = np.concatenate((np.array([-1]), up)) | |
817 | up += 1 |
|
817 | up += 1 | |
818 |
|
818 | |||
819 | dw = np.where(d==-1)[0] |
|
819 | dw = np.where(d==-1)[0] | |
820 | if X[-1]==1: |
|
820 | if X[-1]==1: | |
821 | dw = np.concatenate((dw, np.array([len(X)-1]))) |
|
821 | dw = np.concatenate((dw, np.array([len(X)-1]))) | |
822 | dw += 1 |
|
822 | dw += 1 | |
823 |
|
823 | |||
824 | return [(tup[0], tup[1]-tup[0]) for tup in zip(up, dw)] |
|
824 | return [(tup[0], tup[1]-tup[0]) for tup in zip(up, dw)] | |
825 |
|
825 | |||
826 |
|
826 | |||
827 | def pulses_from_code(ipp, ntx, codes, width, before=0): |
|
827 | def pulses_from_code(ipp, ntx, codes, width, before=0): | |
828 |
|
828 | |||
829 | if ntx>len(codes): |
|
829 | if ntx>len(codes): | |
830 | ipp_codes = [c for __ in xrange(ntx) for c in codes][:ntx] |
|
830 | ipp_codes = [c for __ in xrange(ntx) for c in codes][:ntx] | |
831 | else: |
|
831 | else: | |
832 | ipp_codes = codes[:ntx] |
|
832 | ipp_codes = codes[:ntx] | |
833 |
|
833 | |||
834 | f = width/len(codes[0]) |
|
834 | f = width/len(codes[0]) | |
835 |
|
835 | |||
836 | ipp_codes = [''.join([s*f for s in code]) for code in ipp_codes] |
|
836 | ipp_codes = [''.join([s*f for s in code]) for code in ipp_codes] | |
837 |
|
837 | |||
838 | if before>0: |
|
838 | if before>0: | |
839 | sbefore = '{0:0{1}d}'.format(0, before) |
|
839 | sbefore = '{0:0{1}d}'.format(0, before) | |
840 | else: |
|
840 | else: | |
841 | sbefore = '' |
|
841 | sbefore = '' | |
842 |
|
842 | |||
843 | temp = ['{0}{1}{2:0{3}d}'.format(sbefore, ipp_codes[i], 0, int(ipp)-len(ipp_codes[i])-before) for i in range(ntx)] |
|
843 | temp = ['{0}{1}{2:0{3}d}'.format(sbefore, ipp_codes[i], 0, int(ipp)-len(ipp_codes[i])-before) for i in range(ntx)] | |
844 |
|
844 | |||
845 | return (np.fromstring(''.join(temp), dtype=np.uint8)-48).astype(np.int8) |
|
845 | return (np.fromstring(''.join(temp), dtype=np.uint8)-48).astype(np.int8) | |
846 |
|
846 | |||
847 |
|
847 | |||
848 | def create_mask(ranges, ipp, ntx, sync): |
|
848 | def create_mask(ranges, ipp, ntx, sync): | |
849 |
|
849 | |||
850 | x = np.arange(ipp*ntx) |
|
850 | x = np.arange(ipp*ntx) | |
851 | iranges = set() |
|
851 | iranges = set() | |
852 |
|
852 | |||
853 | for index in ranges: |
|
853 | for index in ranges: | |
854 | if '-' in index: |
|
854 | if '-' in index: | |
855 | args = [int(a) for a in index.split('-')] |
|
855 | args = [int(a) for a in index.split('-')] | |
856 | iranges = iranges.union([i for i in range(args[0], args[1]+1)]) |
|
856 | iranges = iranges.union([i for i in range(args[0], args[1]+1)]) | |
857 | else: |
|
857 | else: | |
858 | iranges.add(int(index)) |
|
858 | iranges.add(int(index)) | |
859 |
|
859 | |||
860 | y = np.any([(x>=(idx-1)*ipp+sync) & (x<idx*ipp+sync) for idx in iranges], axis=0).astype(np.int8) |
|
860 | y = np.any([(x>=(idx-1)*ipp+sync) & (x<idx*ipp+sync) for idx in iranges], axis=0).astype(np.int8) | |
861 |
|
861 | |||
862 | return y |
|
862 | return y | |
863 |
|
863 | |||
864 |
|
864 | |||
865 | def pulses(X, period, width, delay=0, before=0, after=0, sync=0, shift=0): |
|
865 | def pulses(X, period, width, delay=0, before=0, after=0, sync=0, shift=0): | |
866 |
|
866 | |||
867 | delay_array = delay |
|
867 | delay_array = delay | |
868 |
|
868 | |||
869 | if isinstance(delay, (list, tuple)): |
|
869 | if isinstance(delay, (list, tuple)): | |
870 | delay_array = np.ones(len(X)) |
|
870 | delay_array = np.ones(len(X)) | |
871 | delays = [d for __ in xrange(len(X)/(period*len(delay))) for d in delay] |
|
871 | delays = [d for __ in xrange(len(X)/(period*len(delay))) for d in delay] | |
872 | for i, delay in enumerate(delays): |
|
872 | for i, delay in enumerate(delays): | |
873 | delay_array[np.arange(period*i, period*(i+1))] *= delay |
|
873 | delay_array[np.arange(period*i, period*(i+1))] *= delay | |
874 |
|
874 | |||
875 | if after>0: |
|
875 | if after>0: | |
876 | width += after+before |
|
876 | width += after+before | |
877 | before = 0 |
|
877 | before = 0 | |
878 |
|
878 | |||
879 | Y = ((X%period<width+delay_array+before+sync) & (X%period>=delay_array+before+sync)).astype(np.int8) |
|
879 | Y = ((X%period<width+delay_array+before+sync) & (X%period>=delay_array+before+sync)).astype(np.int8) | |
880 |
|
880 | |||
881 | if shift>0: |
|
881 | if shift>0: | |
882 | y = np.empty_like(Y) |
|
882 | y = np.empty_like(Y) | |
883 | y[:shift] = 0 |
|
883 | y[:shift] = 0 | |
884 | y[shift:] = Y[:-shift] |
|
884 | y[shift:] = Y[:-shift] | |
885 | return y |
|
885 | return y | |
886 | else: |
|
886 | else: | |
887 | return Y |
|
887 | return Y | |
888 |
|
888 | |||
889 |
|
889 | |||
890 | def plot_pulses(unit, maximun, lines): |
|
890 | def plot_pulses(unit, maximun, lines): | |
891 |
|
891 | |||
892 | from bokeh.resources import CDN |
|
892 | from bokeh.resources import CDN | |
893 | from bokeh.embed import components |
|
893 | from bokeh.embed import components | |
894 | from bokeh.mpl import to_bokeh |
|
894 | from bokeh.mpl import to_bokeh | |
895 | from bokeh.plotting import figure |
|
895 | from bokeh.plotting import figure | |
896 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, PreviewSaveTool |
|
896 | from bokeh.models.tools import WheelZoomTool, ResetTool, PanTool, PreviewSaveTool | |
897 |
|
897 | |||
898 |
|
898 | |||
899 | N = len(lines) |
|
899 | N = len(lines) | |
900 | fig = plt.figure(figsize=(10, 2+N*0.5)) |
|
900 | fig = plt.figure(figsize=(10, 2+N*0.5)) | |
901 | ax = fig.add_subplot(111) |
|
901 | ax = fig.add_subplot(111) | |
902 | labels = [] |
|
902 | labels = [] | |
903 | data = [] |
|
903 | data = [] | |
904 | for i, line in enumerate(lines): |
|
904 | for i, line in enumerate(lines): | |
905 | print line |
|
905 | print line | |
906 | labels.append(line.get_name()) |
|
906 | labels.append(line.get_name()) | |
907 | ax.broken_barh(pulses_to_bar(line.pulses_as_array()), (N-i-1, 0.5), |
|
907 | ax.broken_barh(pulses_to_bar(line.pulses_as_array()), (N-i-1, 0.5), | |
908 | edgecolor='none', facecolor='#2c3e50') |
|
908 | edgecolor='none', facecolor='#2c3e50') | |
909 | #data.append(line.pulses_as_array()) |
|
909 | #data.append(line.pulses_as_array()) | |
910 |
|
910 | |||
911 |
|
911 | |||
912 | #labels.append('{:3.2f} Km'.format(unit*100)) |
|
912 | #labels.append('{:3.2f} Km'.format(unit*100)) | |
913 | #ax.broken_barh(pulses_to_bar(pulses(np.arange(0, maximun), 200, 100)), (0, 0.5), |
|
913 | #ax.broken_barh(pulses_to_bar(pulses(np.arange(0, maximun), 200, 100)), (0, 0.5), | |
914 | # edgecolor='none', facecolor='#ae3910') |
|
914 | # edgecolor='none', facecolor='#ae3910') | |
915 |
|
915 | |||
916 |
|
916 | |||
917 | #ax.pcolor(data, cmap=cm.Blues, vmin=0, vmax=1) |
|
917 | #ax.pcolor(data, cmap=cm.Blues, vmin=0, vmax=1) | |
918 |
|
918 | |||
919 | labels.reverse() |
|
919 | labels.reverse() | |
920 | #plot = figure(x_range=[0, maximun], y_range=[0, N]) |
|
920 | #plot = figure(x_range=[0, maximun], y_range=[0, N]) | |
921 | #plot.image(image=[np.logical_not(data).astype(np.int8)], x=[0], y=[0], dh=[N], dw=[maximun], palette='Blues9') |
|
921 | #plot.image(image=[np.logical_not(data).astype(np.int8)], x=[0], y=[0], dh=[N], dw=[maximun], palette='Blues9') | |
922 | ax.set_yticklabels(labels) |
|
922 | ax.set_yticklabels(labels) | |
923 | plot = to_bokeh(fig, use_pandas=False) |
|
923 | plot = to_bokeh(fig, use_pandas=False) | |
924 | plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), PreviewSaveTool()] |
|
924 | plot.tools = [PanTool(dimensions=['width']), WheelZoomTool(dimensions=['width']), ResetTool(), PreviewSaveTool()] | |
925 |
|
925 | |||
926 | return components(plot, CDN) |
|
926 | return components(plot, CDN) |
@@ -1,171 +1,410 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 15, 2016 |
|
2 | Created on Feb 15, 2016 | |
3 |
|
3 | |||
4 | @author: Miguel Urco |
|
4 | @author: Miguel Urco | |
5 | ''' |
|
5 | ''' | |
6 | import struct |
|
6 | import struct | |
|
7 | import string | |||
7 |
|
8 | |||
8 | DDS_NBITS = 48 |
|
9 | DDS_NBITS = 48 | |
9 |
|
10 | |||
|
11 | FILE_STRUCTURE = """Phase Adjust Register 1 | |||
|
12 | ----------------------- | |||
|
13 | 00000000 | |||
|
14 | 00000000 | |||
|
15 | ----------------------- | |||
|
16 | Phase Adjust Register 2 | |||
|
17 | ----------------------- | |||
|
18 | 00000000 | |||
|
19 | 00000000 | |||
|
20 | ----------------------- | |||
|
21 | Frequency Tuning Word 1 | |||
|
22 | ----------------------- | |||
|
23 | 00000000 | |||
|
24 | 00000000 | |||
|
25 | 00000000 | |||
|
26 | 00000000 | |||
|
27 | 00000000 | |||
|
28 | 00000000 | |||
|
29 | ----------------------- | |||
|
30 | Frequency Tuning Word 2 | |||
|
31 | ----------------------- | |||
|
32 | 00000000 | |||
|
33 | 00000000 | |||
|
34 | 00000000 | |||
|
35 | 00000000 | |||
|
36 | 00000000 | |||
|
37 | 00000000 | |||
|
38 | ----------------------- | |||
|
39 | Delta Frequency Word | |||
|
40 | ----------------------- | |||
|
41 | 00000000 | |||
|
42 | 00000000 | |||
|
43 | 00000000 | |||
|
44 | 00000000 | |||
|
45 | 00000000 | |||
|
46 | 00000000 | |||
|
47 | ----------------------- | |||
|
48 | Update Clock | |||
|
49 | ----------------------- | |||
|
50 | 00000000 | |||
|
51 | 00000000 | |||
|
52 | 00000000 | |||
|
53 | 00000000 | |||
|
54 | ----------------------- | |||
|
55 | Ramp Rate Clock | |||
|
56 | ----------------------- | |||
|
57 | 00000000 | |||
|
58 | 00000000 | |||
|
59 | 00000000 | |||
|
60 | ----------------------- | |||
|
61 | Control Register | |||
|
62 | ----------------------- | |||
|
63 | 00000000 | |||
|
64 | 00000000 | |||
|
65 | 00000000 | |||
|
66 | 00000000 | |||
|
67 | ----------------------- | |||
|
68 | Output Shaped Keying I | |||
|
69 | Multiplier | |||
|
70 | ----------------------- | |||
|
71 | 00000000 | |||
|
72 | 00000000 | |||
|
73 | ----------------------- | |||
|
74 | Output Shaped Keying Q | |||
|
75 | Multiplier | |||
|
76 | ----------------------- | |||
|
77 | 00000000 | |||
|
78 | 00000000 | |||
|
79 | ----------------------- | |||
|
80 | Output Shaped Keying | |||
|
81 | Ramp Rate | |||
|
82 | ----------------------- | |||
|
83 | 00000000 | |||
|
84 | ----------------------- | |||
|
85 | QDAC | |||
|
86 | ----------------------- | |||
|
87 | 00000000 | |||
|
88 | 00000000 | |||
|
89 | ----------------------- | |||
|
90 | CLOCK INPUT | |||
|
91 | ----------------------- | |||
|
92 | 10.00000000""" | |||
|
93 | ||||
10 | def freq_to_binary(freq, mclock): |
|
94 | def freq_to_binary(freq, mclock): | |
11 |
|
95 | |||
12 | binary = (float(freq)/mclock)*(2**DDS_NBITS) |
|
96 | if not mclock: | |
|
97 | return None | |||
|
98 | ||||
|
99 | try: | |||
|
100 | binary = int((float(freq)/mclock)*(2**DDS_NBITS)) | |||
|
101 | except: | |||
|
102 | return 0 | |||
13 |
|
103 | |||
14 | return binary |
|
104 | return binary | |
15 |
|
105 | |||
16 | def binary_to_freq(binary, mclock): |
|
106 | def binary_to_freq(binary, mclock): | |
17 |
|
107 | |||
18 | freq = (float(binary)/(2**DDS_NBITS))*mclock |
|
108 | if not mclock: | |
|
109 | return None | |||
|
110 | ||||
|
111 | try: | |||
|
112 | freq = (float(binary)/(2**DDS_NBITS))*mclock | |||
|
113 | except: | |||
|
114 | return 0 | |||
19 |
|
115 | |||
20 | return freq |
|
116 | return freq | |
21 |
|
117 | |||
22 | def phase_to_binary(phase): |
|
118 | def phase_to_binary(phase): | |
23 |
|
119 | |||
24 | binary = float(phase)*8192/180.0 |
|
120 | try: | |
|
121 | binary = int(float(phase)*8192/180.0) | |||
|
122 | except: | |||
|
123 | return 0 | |||
25 |
|
124 | |||
26 | return binary |
|
125 | return binary | |
27 |
|
126 | |||
28 | def binary_to_phase(binary): |
|
127 | def binary_to_phase(binary): | |
29 |
|
128 | |||
30 | phase = float(binary)*180.0/8192 |
|
129 | try: | |
|
130 | phase = float(binary)*180.0/8192 | |||
|
131 | except: | |||
|
132 | return 0 | |||
31 |
|
133 | |||
32 | return phase |
|
134 | return phase | |
33 |
|
135 | |||
34 | def dds_str_to_dict(registers): |
|
136 | def __fill_dds_dict(parms): | |
|
137 | ||||
|
138 | my_dict = {'clock' : None, | |||
|
139 | 'multiplier' : 1, | |||
|
140 | 'frequencyA' : 0, | |||
|
141 | 'frequencyB' : 0, | |||
|
142 | 'frequencyA_Mhz' : 0, | |||
|
143 | 'frequencyB_Mhz' : 0, | |||
|
144 | 'phaseA_degress' : 0, | |||
|
145 | 'phaseB_degress' : 0, | |||
|
146 | 'modulation' : 0, | |||
|
147 | 'amplitudeI' : 0, | |||
|
148 | 'amplitudeQ' : 0, | |||
|
149 | 'amplitude_enabled' : 0, | |||
|
150 | 'delta_frequency' : 0, | |||
|
151 | 'update_clock' : 0, | |||
|
152 | 'ramp_rate_clock' : 0, | |||
|
153 | 'amplitude_ramp_rate' : 0, | |||
|
154 | 'qdac' : 0 | |||
|
155 | } | |||
|
156 | ||||
|
157 | my_dict.update(parms) | |||
|
158 | my_dict['phaseA'] = phase_to_binary(my_dict['phaseA_degrees']) | |||
|
159 | my_dict['phaseB'] = phase_to_binary(my_dict['phaseB_degrees']) | |||
|
160 | ||||
|
161 | pll_range = 0 | |||
|
162 | if my_dict['clock'] >= 200: | |||
|
163 | pll_range = 1 | |||
|
164 | ||||
|
165 | pll_bypass = 0 | |||
|
166 | if my_dict['multiplier'] < 4: | |||
|
167 | pll_bypass = 1 | |||
|
168 | ||||
|
169 | control_register = (1 << 28) + \ | |||
|
170 | (pll_range << 22) + (pll_bypass << 21) + \ | |||
|
171 | (my_dict['multiplier'] << 16) + \ | |||
|
172 | (my_dict['modulation'] << 9) + \ | |||
|
173 | (my_dict['amplitude_enabled'] << 5) | |||
|
174 | ||||
|
175 | my_dict['control_register'] = control_register | |||
|
176 | ||||
|
177 | return my_dict | |||
|
178 | ||||
|
179 | def dds_str_to_dict(registers, clock=None): | |||
35 |
|
180 | |||
36 | """ |
|
181 | """ | |
37 | Output: |
|
182 | Output: | |
38 | parms : Dictionary with keys |
|
183 | parms : Dictionary with keys | |
39 | multiplier : |
|
184 | multiplier : | |
40 | frequencyA : |
|
185 | frequencyA : | |
41 | frequencyB : |
|
186 | frequencyB : | |
42 | frequencyA_Mhz : |
|
187 | frequencyA_Mhz : | |
43 | frequencyB_Mhz : |
|
188 | frequencyB_Mhz : | |
44 | modulation : |
|
189 | modulation : | |
45 | phaseA_degrees : |
|
190 | phaseA_degrees : | |
46 | phaseB_degrees : |
|
191 | phaseB_degrees : | |
47 | amplitudeI : |
|
192 | amplitudeI : | |
48 | amplitudeQ : |
|
193 | amplitudeQ : | |
49 |
|
194 | |||
50 | """ |
|
195 | """ | |
51 |
|
196 | |||
52 | if not registers: |
|
197 | if not registers: | |
53 | return {} |
|
198 | return {} | |
54 |
|
199 | |||
55 | if len(registers) != 0x28: |
|
200 | if len(registers) != 0x28: | |
56 | return {} |
|
201 | return {} | |
57 |
|
202 | |||
58 | phaseA = struct.unpack('>H', registers[0x0:0x2])[0] |
|
203 | phaseA = struct.unpack('>H', registers[0x0:0x2])[0] | |
59 | phaseB = struct.unpack('>H', registers[0x2:0x4])[0] |
|
204 | phaseB = struct.unpack('>H', registers[0x2:0x4])[0] | |
60 |
|
205 | |||
61 | frequencyA = struct.unpack('>Q', '\x00\x00' + registers[0x04:0x0A])[0] |
|
206 | frequencyA = struct.unpack('>Q', '\x00\x00' + registers[0x04:0x0A])[0] | |
62 | frequencyB = struct.unpack('>Q', '\x00\x00' + registers[0x0A:0x10])[0] |
|
207 | frequencyB = struct.unpack('>Q', '\x00\x00' + registers[0x0A:0x10])[0] | |
63 |
|
208 | |||
64 | delta_frequency = struct.unpack('>Q', '\x00\x00' + registers[0x10:0x16])[0] |
|
209 | delta_frequency = struct.unpack('>Q', '\x00\x00' + registers[0x10:0x16])[0] | |
65 |
|
210 | |||
66 | update_clock = struct.unpack('>I', registers[0x16:0x1A])[0] |
|
211 | update_clock = struct.unpack('>I', registers[0x16:0x1A])[0] | |
67 |
|
212 | |||
68 | ramp_rate_clock = struct.unpack('>I', '\x00' + registers[0x1A:0x1D])[0] |
|
213 | ramp_rate_clock = struct.unpack('>I', '\x00' + registers[0x1A:0x1D])[0] | |
69 |
|
214 | |||
70 | control_register = struct.unpack('>I', registers[0x1D:0x21])[0] |
|
215 | control_register = struct.unpack('>I', registers[0x1D:0x21])[0] | |
71 |
|
216 | |||
72 | amplitudeI = struct.unpack('>H', registers[0x21:0x23])[0] |
|
217 | amplitudeI = struct.unpack('>H', registers[0x21:0x23])[0] | |
73 | amplitudeQ = struct.unpack('>H', registers[0x23:0x25])[0] |
|
218 | amplitudeQ = struct.unpack('>H', registers[0x23:0x25])[0] | |
74 |
|
219 | |||
75 | amp_ramp_rate = ord(registers[0x25]) |
|
220 | amp_ramp_rate = ord(registers[0x25]) | |
76 |
|
221 | |||
77 | qdac = struct.unpack('>H', registers[0x26:0x28])[0] |
|
222 | qdac = struct.unpack('>H', registers[0x26:0x28])[0] | |
78 |
|
223 | |||
79 | multiplier = (control_register & 0x001F0000) >> 16 |
|
224 | multiplier = (control_register & 0x001F0000) >> 16 | |
80 | modulation = (control_register & 0x00000E00) >> 9 |
|
225 | modulation = (control_register & 0x00000E00) >> 9 | |
81 | amplitude_enabled = (control_register & 0x00000020) >> 5 |
|
226 | amplitude_enabled = (control_register & 0x00000020) >> 5 | |
82 |
|
227 | |||
83 | parms = {'clock' : None, |
|
228 | frequencyA_Mhz = None | |
|
229 | frequencyB_Mhz = None | |||
|
230 | ||||
|
231 | if clock: | |||
|
232 | mclock = clock*multiplier | |||
|
233 | frequencyA_Mhz = binary_to_freq(frequencyA, mclock) | |||
|
234 | frequencyB_Mhz = binary_to_freq(frequencyB, mclock) | |||
|
235 | ||||
|
236 | parms = {'clock' : clock, | |||
84 | 'multiplier' : multiplier, |
|
237 | 'multiplier' : multiplier, | |
85 | 'frequencyA' : frequencyA, |
|
238 | 'frequencyA' : frequencyA, | |
86 | 'frequencyB' : frequencyB, |
|
239 | 'frequencyB' : frequencyB, | |
87 |
'frequencyA_Mhz' : |
|
240 | 'frequencyA_Mhz' : frequencyA_Mhz, | |
88 |
'frequencyB_Mhz' : |
|
241 | 'frequencyB_Mhz' : frequencyB_Mhz, | |
89 | 'phaseA' : phaseA, |
|
242 | 'phaseA' : phaseA, | |
90 | 'phaseB' : phaseB, |
|
243 | 'phaseB' : phaseB, | |
91 | 'phaseA_degrees' : binary_to_phase(phaseA), |
|
244 | 'phaseA_degrees' : binary_to_phase(phaseA), | |
92 | 'phaseB_degrees' : binary_to_phase(phaseB), |
|
245 | 'phaseB_degrees' : binary_to_phase(phaseB), | |
93 | 'modulation' : modulation, |
|
246 | 'modulation' : modulation, | |
94 | 'amplitudeI' : amplitudeI, |
|
247 | 'amplitudeI' : amplitudeI, | |
95 | 'amplitudeQ' : amplitudeQ, |
|
248 | 'amplitudeQ' : amplitudeQ, | |
96 | 'amplitude_enabled' : amplitude_enabled, |
|
249 | 'amplitude_enabled' : amplitude_enabled, | |
97 | 'delta_frequency' : delta_frequency, |
|
250 | 'delta_frequency' : delta_frequency, | |
98 | 'update_clock' : update_clock, |
|
251 | 'update_clock' : update_clock, | |
99 | 'ramp_rate_clock' : ramp_rate_clock, |
|
252 | 'ramp_rate_clock' : ramp_rate_clock, | |
100 | 'amp_ramp_rate' : amp_ramp_rate, |
|
253 | 'amp_ramp_rate' : amp_ramp_rate, | |
101 | 'qdac' : qdac |
|
254 | 'qdac' : qdac | |
102 | } |
|
255 | } | |
103 |
|
256 | |||
104 | return parms |
|
257 | return parms | |
105 |
|
258 | |||
106 | def dict_to_dds_str(parms): |
|
259 | def dict_to_dds_str(parms): | |
107 | """ |
|
260 | """ | |
108 | Input: |
|
261 | Input: | |
109 | parms : Dictionary with keys |
|
262 | parms : Dictionary with keys | |
110 | multiplier : 4 to 20 |
|
263 | multiplier : 4 to 20 | |
111 | frequencyA : 0 to (2**48-1) equivalent to: 0 - "Master clock" |
|
264 | frequencyA : 0 to (2**48-1) equivalent to: 0 - "Master clock" | |
112 | frequencyB : 0 to (2**48-1) equivalent to: 0 - "Master clock" |
|
265 | frequencyB : 0 to (2**48-1) equivalent to: 0 - "Master clock" | |
113 | modulation : 0 to 3 |
|
266 | modulation : 0 to 3 | |
114 | phaseA_degrees : 0 - 360 degrees |
|
267 | phaseA_degrees : 0 - 360 degrees | |
115 | phaseB_degrees : 0 - 360 degrees |
|
268 | phaseB_degrees : 0 - 360 degrees | |
116 | amplitudeI : 0 to (2**12-1) equivalent to: 0 - 100% |
|
269 | amplitudeI : 0 to (2**12-1) equivalent to: 0 - 100% | |
117 | amplitudeQ : 0 to (2**12-1) equivalent to: 0 - 100% |
|
270 | amplitudeQ : 0 to (2**12-1) equivalent to: 0 - 100% | |
118 | """ |
|
271 | """ | |
119 |
|
272 | |||
120 | my_dict = {'clock' : None, |
|
273 | my_dict = __fill_dds_dict(parms) | |
121 | 'multiplier' : 1, |
|
|||
122 | 'frequencyA' : 0, |
|
|||
123 | 'frequencyB' : 0, |
|
|||
124 | 'frequencyA_Mhz' : 0, |
|
|||
125 | 'frequencyB_Mhz' : 0, |
|
|||
126 | 'phaseA_degress' : 0, |
|
|||
127 | 'phaseB_degress' : 0, |
|
|||
128 | 'modulation' : 0, |
|
|||
129 | 'amplitudeI' : 0, |
|
|||
130 | 'amplitudeQ' : 0, |
|
|||
131 | 'amplitude_enabled' : 0, |
|
|||
132 | 'delta_frequency' : 0, |
|
|||
133 | 'update_clock' : 0, |
|
|||
134 | 'ramp_rate_clock' : 0, |
|
|||
135 | 'amplitude_ramp_rate' : 0, |
|
|||
136 | 'qdac' : 0 |
|
|||
137 | } |
|
|||
138 |
|
||||
139 | print "PArms", parms |
|
|||
140 |
|
||||
141 | my_dict.update(parms) |
|
|||
142 | my_dict['phaseA'] = phase_to_binary(my_dict['phaseA_degrees']) |
|
|||
143 | my_dict['phaseB'] = phase_to_binary(my_dict['phaseB_degrees']) |
|
|||
144 |
|
274 | |||
145 | registers = "" |
|
275 | registers = "" | |
146 |
|
276 | |||
147 | control_register = (my_dict['multiplier'] << 16) + (my_dict['modulation'] << 9) + (my_dict['amplitude_enabled'] << 5) |
|
|||
148 |
|
||||
149 | registers += struct.pack(">H", my_dict['phaseA']) |
|
277 | registers += struct.pack(">H", my_dict['phaseA']) | |
150 | registers += struct.pack(">H", my_dict['phaseB']) |
|
278 | registers += struct.pack(">H", my_dict['phaseB']) | |
151 |
|
279 | |||
152 | registers += struct.pack(">Q", my_dict['frequencyA'])[2:] |
|
280 | registers += struct.pack(">Q", my_dict['frequencyA'])[2:] | |
153 | registers += struct.pack(">Q", my_dict['frequencyB'])[2:] |
|
281 | registers += struct.pack(">Q", my_dict['frequencyB'])[2:] | |
154 |
|
282 | |||
155 | registers += struct.pack(">Q", my_dict['delta_frequency'])[2:] |
|
283 | registers += struct.pack(">Q", my_dict['delta_frequency'])[2:] | |
156 |
|
284 | |||
157 | registers += struct.pack(">I", my_dict['update_clock']) |
|
285 | registers += struct.pack(">I", my_dict['update_clock']) | |
158 |
|
286 | |||
159 | registers += struct.pack(">I", my_dict['ramp_rate_clock'])[1:] |
|
287 | registers += struct.pack(">I", my_dict['ramp_rate_clock'])[1:] | |
160 |
|
288 | |||
161 | registers += struct.pack(">I", control_register) |
|
289 | registers += struct.pack(">I", my_dict['control_register']) | |
162 |
|
290 | |||
163 | registers += struct.pack(">H", my_dict['amplitudeI']) |
|
291 | registers += struct.pack(">H", my_dict['amplitudeI']) | |
164 |
|
292 | |||
165 | registers += struct.pack(">H", my_dict['amplitudeQ']) |
|
293 | registers += struct.pack(">H", my_dict['amplitudeQ']) | |
166 |
|
294 | |||
167 | registers += chr(my_dict['amplitude_ramp_rate']) |
|
295 | registers += chr(my_dict['amplitude_ramp_rate']) | |
168 |
|
296 | |||
169 | registers += struct.pack(">H", my_dict['qdac']) |
|
297 | registers += struct.pack(">H", my_dict['qdac']) | |
170 |
|
298 | |||
171 | return registers No newline at end of file |
|
299 | return registers | |
|
300 | ||||
|
301 | def text_to_dict(lines): | |||
|
302 | ||||
|
303 | registers = "" | |||
|
304 | registers_v2 = [] | |||
|
305 | ||||
|
306 | for this_line in lines: | |||
|
307 | this_line = str.strip(this_line) | |||
|
308 | ||||
|
309 | if str.isalpha(this_line): | |||
|
310 | continue | |||
|
311 | ||||
|
312 | if not str.isdigit(this_line): | |||
|
313 | try: | |||
|
314 | value = float(this_line) | |||
|
315 | except: | |||
|
316 | continue | |||
|
317 | ||||
|
318 | registers_v2.append(value) | |||
|
319 | continue | |||
|
320 | ||||
|
321 | if len(this_line) != 8: | |||
|
322 | continue | |||
|
323 | ||||
|
324 | registers += chr(string.atoi(this_line,2)) | |||
|
325 | ||||
|
326 | mclock = None | |||
|
327 | if len(registers_v2) > 0: | |||
|
328 | mclock = registers_v2[0] | |||
|
329 | ||||
|
330 | my_dict = dds_str_to_dict(registers, mclock) | |||
|
331 | ||||
|
332 | return my_dict | |||
|
333 | ||||
|
334 | def dict_to_text(parms): | |||
|
335 | """ | |||
|
336 | It creates formatted DDS text using dictionary values. | |||
|
337 | """ | |||
|
338 | my_dict = __fill_dds_dict(parms) | |||
|
339 | ||||
|
340 | lines = FILE_STRUCTURE.split('\n') | |||
|
341 | ||||
|
342 | cad = '{0:016b}'.format(my_dict['phaseA']) | |||
|
343 | lines[2] = cad[0:8] | |||
|
344 | lines[3] = cad[8:16] | |||
|
345 | ||||
|
346 | cad = '{0:016b}'.format(my_dict['phaseB']) | |||
|
347 | lines[7] = cad[0:8] | |||
|
348 | lines[8] = cad[8:16] | |||
|
349 | ||||
|
350 | cad = '{0:048b}'.format(my_dict['frequencyA']) | |||
|
351 | lines[12] = cad[0:8] | |||
|
352 | lines[13] = cad[8:16] | |||
|
353 | lines[14] = cad[16:24] | |||
|
354 | lines[15] = cad[24:32] | |||
|
355 | lines[16] = cad[32:40] | |||
|
356 | lines[17] = cad[40:48] | |||
|
357 | ||||
|
358 | cad = '{0:048b}'.format(my_dict['frequencyB']) | |||
|
359 | lines[21] = cad[0:8] | |||
|
360 | lines[22] = cad[8:16] | |||
|
361 | lines[23] = cad[16:24] | |||
|
362 | lines[24] = cad[24:32] | |||
|
363 | lines[25] = cad[32:40] | |||
|
364 | lines[26] = cad[40:48] | |||
|
365 | ||||
|
366 | cad = '{0:048b}'.format(my_dict['delta_frequency']) | |||
|
367 | lines[30] = cad[0:8] | |||
|
368 | lines[31] = cad[8:16] | |||
|
369 | lines[32] = cad[16:24] | |||
|
370 | lines[33] = cad[24:32] | |||
|
371 | lines[34] = cad[32:40] | |||
|
372 | lines[35] = cad[40:48] | |||
|
373 | ||||
|
374 | cad = '{0:032b}'.format(my_dict['update_clock']) | |||
|
375 | lines[39] = cad[0:8] | |||
|
376 | lines[40] = cad[8:16] | |||
|
377 | lines[41] = cad[16:24] | |||
|
378 | lines[42] = cad[24:32] | |||
|
379 | ||||
|
380 | cad = '{0:024b}'.format(my_dict['ramp_rate_clock']) | |||
|
381 | lines[46] = cad[0:8] | |||
|
382 | lines[47] = cad[8:16] | |||
|
383 | lines[48] = cad[16:24] | |||
|
384 | ||||
|
385 | cad = '{0:032b}'.format(my_dict['control_register']) | |||
|
386 | lines[52] = cad[0:8] | |||
|
387 | lines[53] = cad[8:16] | |||
|
388 | lines[54] = cad[16:24] | |||
|
389 | lines[55] = cad[24:32] | |||
|
390 | ||||
|
391 | cad = '{0:016b}'.format(my_dict['amplitudeI']) | |||
|
392 | lines[60] = cad[0:8] | |||
|
393 | lines[61] = cad[8:16] | |||
|
394 | ||||
|
395 | cad = '{0:016b}'.format(my_dict['amplitudeQ']) | |||
|
396 | lines[66] = cad[0:8] | |||
|
397 | lines[67] = cad[8:16] | |||
|
398 | ||||
|
399 | cad = '{0:08b}'.format(my_dict['amplitude_ramp_rate']) | |||
|
400 | lines[72] = cad[0:8] | |||
|
401 | ||||
|
402 | cad = '{0:016b}'.format(my_dict['qdac']) | |||
|
403 | lines[76] = cad[0:8] | |||
|
404 | lines[77] = cad[8:16] | |||
|
405 | ||||
|
406 | lines[81] = '%10.8f' %my_dict['clock'] | |||
|
407 | ||||
|
408 | text = '\n'.join(lines) | |||
|
409 | ||||
|
410 | return text No newline at end of file |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now