1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 |
@@ -0,0 +1,113 | |||||
|
1 | ''' | |||
|
2 | Created on Nov 25, 2015 | |||
|
3 | ||||
|
4 | @author: Miguel Urco | |||
|
5 | ||||
|
6 | eth_device decorator is used to implement an api to ethernet devices. | |||
|
7 | When eth_device decorator is used it adds two parameters to any function (ip and port) | |||
|
8 | ||||
|
9 | #Definition of a function using eth_device decorator | |||
|
10 | ||||
|
11 | @eth_device(ID_CLASS) | |||
|
12 | def enable_acq(message) | |||
|
13 | cmd = "xxxxx" | |||
|
14 | payload = message | |||
|
15 | ||||
|
16 | return cmd, payload | |||
|
17 | ||||
|
18 | #How to call this function: | |||
|
19 | answer = enable_acq(ip, port, message) | |||
|
20 | ||||
|
21 | ''' | |||
|
22 | import sys | |||
|
23 | import struct | |||
|
24 | import json | |||
|
25 | ||||
|
26 | from devices.jro_device import eth_device, IdClass | |||
|
27 | ||||
|
28 | ID_CLASS = IdClass["jars"] | |||
|
29 | ||||
|
30 | CMD_RESET = 0X01 | |||
|
31 | CMD_CHANGEIP = 0X03 | |||
|
32 | #Add other commands | |||
|
33 | CMD_CONFIGURE = 0X10 | |||
|
34 | CMD_STATUS = 0X11 | |||
|
35 | CMD_SET_EXEPATH = 0X12 | |||
|
36 | CMD_ECHO = 0XFE | |||
|
37 | CMD_READ = 0X08 | |||
|
38 | CMD_STOP = 0X09 | |||
|
39 | ||||
|
40 | @eth_device(ID_CLASS) | |||
|
41 | def reset(): | |||
|
42 | ||||
|
43 | cmd = CMD_RESET | |||
|
44 | payload = '' | |||
|
45 | ||||
|
46 | return cmd, payload | |||
|
47 | ||||
|
48 | @eth_device(ID_CLASS) | |||
|
49 | def stop(): | |||
|
50 | ||||
|
51 | cmd = CMD_STOP | |||
|
52 | payload = '' | |||
|
53 | ||||
|
54 | return cmd, payload | |||
|
55 | ||||
|
56 | @eth_device(ID_CLASS) | |||
|
57 | def echo(message): | |||
|
58 | ||||
|
59 | cmd = CMD_ECHO | |||
|
60 | payload = message | |||
|
61 | ||||
|
62 | return cmd, payload | |||
|
63 | ||||
|
64 | @eth_device(ID_CLASS) | |||
|
65 | def configure(conf): | |||
|
66 | ||||
|
67 | cmd = CMD_CONFIGURE | |||
|
68 | payload = conf | |||
|
69 | ||||
|
70 | return cmd, payload | |||
|
71 | ||||
|
72 | @eth_device(ID_CLASS) | |||
|
73 | def status(): | |||
|
74 | ||||
|
75 | cmd = CMD_STATUS | |||
|
76 | payload = '' | |||
|
77 | ||||
|
78 | return cmd, payload | |||
|
79 | ||||
|
80 | @eth_device(ID_CLASS) | |||
|
81 | def read(): | |||
|
82 | ||||
|
83 | cmd = CMD_READ | |||
|
84 | payload = '' | |||
|
85 | ||||
|
86 | return cmd, payload | |||
|
87 | ||||
|
88 | @eth_device(ID_CLASS) | |||
|
89 | def set_exepath(path): | |||
|
90 | ||||
|
91 | cmd = CMD_SET_EXEPATH | |||
|
92 | payload = path | |||
|
93 | ||||
|
94 | return cmd, payload | |||
|
95 | ||||
|
96 | #--To take .json file from computer: | |||
|
97 | #with open('/home/fquino/Downloads/Experiment.json') as data_file: | |||
|
98 | # data = json.load(data_file) | |||
|
99 | ||||
|
100 | # data['configurations']['dds']='' | |||
|
101 | # data['configurations']['rc']['pulses']='' | |||
|
102 | # data['configurations']['rc']['delays']='' | |||
|
103 | ||||
|
104 | #data = json.dumps(data) | |||
|
105 | #----------------------------------- | |||
|
106 | ||||
|
107 | #print reset('10.10.10.100', 10000) | |||
|
108 | #print echo('10.10.10.95', 10000, 'Hola JARS :)') | |||
|
109 | ||||
|
110 | #json_data = json.dumps({'name':'archivo1','variable':9}) | |||
|
111 | #print configure('10.10.10.95', 10000, data) | |||
|
112 | #print configure('10.10.10.100', 10000, '') | |||
|
113 | #print status('10.10.10.100', 10000) |
@@ -11,4 +11,4 Alias /static/ /var/www/html/static/ | |||||
11 | Require all granted |
|
11 | Require all granted | |
12 | #Allow from all |
|
12 | #Allow from all | |
13 | </Files> |
|
13 | </Files> | |
14 | </Directory> No newline at end of file |
|
14 | </Directory> |
@@ -3,8 +3,4 from django.conf.urls import url | |||||
3 | urlpatterns = ( |
|
3 | urlpatterns = ( | |
4 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_abs_conf'), |
|
4 | url(r'^(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_abs_conf'), | |
5 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_abs_conf'), |
|
5 | url(r'^(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_abs_conf'), | |
6 | url(r'^(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_abs_conf'), |
|
6 | ) | |
7 | url(r'^(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_abs_conf'), |
|
|||
8 | url(r'^(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_abs_conf'), |
|
|||
9 | url(r'^(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_abs_conf'), |
|
|||
10 | ) No newline at end of file |
|
@@ -3,32 +3,32 from apps.main.models import Device | |||||
3 | from .models import CGSConfiguration |
|
3 | from .models import CGSConfiguration | |
4 |
|
4 | |||
5 | class CGSConfigurationForm(forms.ModelForm): |
|
5 | class CGSConfigurationForm(forms.ModelForm): | |
6 |
|
6 | |||
7 | def __init__(self, *args, **kwargs): |
|
7 | def __init__(self, *args, **kwargs): | |
8 | #request = kwargs.pop('request') |
|
8 | #request = kwargs.pop('request') | |
9 | super(CGSConfigurationForm, self).__init__(*args, **kwargs) |
|
9 | super(CGSConfigurationForm, self).__init__(*args, **kwargs) | |
10 |
|
10 | |||
11 | instance = getattr(self, 'instance', None) |
|
11 | instance = getattr(self, 'instance', None) | |
12 |
|
12 | |||
13 | if instance and instance.pk: |
|
13 | if instance and instance.pk: | |
14 |
|
14 | |||
15 | devices = Device.objects.filter(device_type__name='cgs') |
|
15 | devices = Device.objects.filter(device_type__name='cgs') | |
16 |
|
16 | |||
17 | if instance.experiment: |
|
17 | if instance.experiment: | |
18 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' |
|
18 | self.fields['experiment'].widget.attrs['disabled'] = 'disabled' | |
19 |
|
19 | |||
20 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] |
|
20 | self.fields['device'].widget.choices = [(device.id, device) for device in devices] | |
21 |
|
21 | |||
22 | def clean(self): |
|
22 | def clean(self): | |
23 | return |
|
23 | return | |
24 | # |
|
24 | # | |
25 |
|
25 | |||
26 | class Meta: |
|
26 | class Meta: | |
27 | model = CGSConfiguration |
|
27 | model = CGSConfiguration | |
28 | exclude = ('type', 'parameters', 'status') |
|
28 | exclude = ('type', 'parameters', 'status') | |
29 | #fields = ('experiment', 'device', 'freq0', 'freq1', 'freq2', 'freq3') |
|
29 | #fields = ('experiment', 'device', 'freq0', 'freq1', 'freq2', 'freq3') | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | class UploadFileForm(forms.Form): |
|
32 | class UploadFileForm(forms.Form): | |
33 | title = forms.CharField(label='Extension Type', widget=forms.TextInput(attrs={'readonly':'readonly'})) |
|
33 | title = forms.CharField(label='Extension Type', widget=forms.TextInput(attrs={'readonly':'readonly'})) | |
34 | file = forms.FileField() No newline at end of file |
|
34 | file = forms.FileField() |
@@ -245,6 +245,11 class JARSConfiguration(Configuration): | |||||
245 | return self.device.status |
|
245 | return self.device.status | |
246 |
|
246 | |||
247 |
|
247 | |||
|
248 | def start_device(self): | |||
|
249 | ||||
|
250 | self.write_device() | |||
|
251 | ||||
|
252 | ||||
248 | def echo(self): |
|
253 | def echo(self): | |
249 |
|
254 | |||
250 | answer = api.echo(self.device.ip_address,self.device.port_address,'(=') |
|
255 | answer = api.echo(self.device.ip_address,self.device.port_address,'(=') |
@@ -1,5 +1,4 | |||||
1 | import os |
|
1 | import os | |
2 | import ast |
|
|||
3 | import json |
|
2 | import json | |
4 |
|
3 | |||
5 | from django import forms |
|
4 | from django import forms | |
@@ -321,8 +320,7 class RCLineEditForm(forms.ModelForm): | |||||
321 | widget=forms.Select(attrs={'name':'%s|%s|%s' % (count, line.id, label)}), |
|
320 | widget=forms.Select(attrs={'name':'%s|%s|%s' % (count, line.id, label)}), | |
322 | help_text=help_text) |
|
321 | help_text=help_text) | |
323 |
|
322 | |||
324 | else: |
|
323 | else: | |
325 |
|
||||
326 | self.fields[label] = forms.CharField(initial=value, help_text=help_text) |
|
324 | self.fields[label] = forms.CharField(initial=value, help_text=help_text) | |
327 |
|
325 | |||
328 | if label in ('code', ): |
|
326 | if label in ('code', ): | |
@@ -337,9 +335,9 class RCLineEditForm(forms.ModelForm): | |||||
337 | elif params[label]['widget']=='dc': |
|
335 | elif params[label]['widget']=='dc': | |
338 | self.fields[label].widget = KmUnitDcWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
336 | self.fields[label].widget = KmUnitDcWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
339 | elif params[label]['widget']=='codes': |
|
337 | elif params[label]['widget']=='codes': | |
340 | self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) |
|
338 | self.fields[label].widget = CodesWidget(attrs={'line':line, 'km2unit':km2unit, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
341 | else: |
|
339 | else: | |
342 | self.fields[label].widget = DefaultWidget(attrs={'name':'%s|%s|%s' % (count, line.id, label)}) |
|
340 | self.fields[label].widget = DefaultWidget(attrs={'line':line, 'name':'%s|%s|%s' % (count, line.id, label)}) | |
343 |
|
341 | |||
344 |
|
342 | |||
345 | class Meta: |
|
343 | class Meta: |
@@ -293,7 +293,7 class IPData(object): | |||||
293 | def __sendTCPData(self, cadena): |
|
293 | def __sendTCPData(self, cadena): | |
294 |
|
294 | |||
295 | sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
|
295 | sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
296 |
sck.settimeout( |
|
296 | sck.settimeout(3) | |
297 |
|
297 | |||
298 | try: |
|
298 | try: | |
299 | sck.connect(self.address) |
|
299 | sck.connect(self.address) | |
@@ -314,7 +314,10 class IPData(object): | |||||
314 | if time.time() - ini > 0.5: |
|
314 | if time.time() - ini > 0.5: | |
315 | break |
|
315 | break | |
316 |
|
316 | |||
317 |
t |
|
317 | try: | |
|
318 | tmp = sck.recv(4096) | |||
|
319 | except: | |||
|
320 | break | |||
318 |
|
321 | |||
319 | if len(tmp) < 1: |
|
322 | if len(tmp) < 1: | |
320 | continue |
|
323 | continue |
@@ -35,8 +35,6 CMD_ECHO =0XFE | |||||
35 | RC_CMD_RESET =0X10 |
|
35 | RC_CMD_RESET =0X10 | |
36 | RC_CMD_WRITE =0x50 |
|
36 | RC_CMD_WRITE =0x50 | |
37 | RC_CMD_READ =0x8000 |
|
37 | RC_CMD_READ =0x8000 | |
38 | RC_CMD_ENABLE =0X24 |
|
|||
39 | RC_CMD_DISABLE =0X00 |
|
|||
40 |
|
38 | |||
41 | @eth_device(ID_CLASS) |
|
39 | @eth_device(ID_CLASS) | |
42 | def reset(): |
|
40 | def reset(): | |
@@ -71,32 +69,16 def echo(): | |||||
71 | return cmd, payload |
|
69 | return cmd, payload | |
72 |
|
70 | |||
73 | @eth_device(ID_CLASS) |
|
71 | @eth_device(ID_CLASS) | |
74 | def enable(): |
|
|||
75 |
|
||||
76 | cmd = RC_CMD_ENABLE |
|
|||
77 | payload = chr(0x01) |
|
|||
78 |
|
||||
79 | return cmd, payload |
|
|||
80 |
|
||||
81 | @eth_device(ID_CLASS) |
|
|||
82 | def disable(): |
|
|||
83 |
|
||||
84 | cmd = RC_CMD_DISABLE |
|
|||
85 | payload = chr(0x00) |
|
|||
86 |
|
||||
87 | return cmd, payload |
|
|||
88 |
|
||||
89 | @eth_device(ID_CLASS) |
|
|||
90 | def read_all_device(): |
|
72 | def read_all_device(): | |
91 |
|
73 | |||
92 | payload = "" |
|
74 | payload = "" | |
93 |
|
75 | |||
94 |
return |
|
76 | return CR_CMD_READ, payload | |
95 |
|
77 | |||
96 | @eth_device(ID_CLASS) |
|
78 | @eth_device(ID_CLASS) | |
97 | def write_all_device(payload): |
|
79 | def write_all_device(payload): | |
98 |
|
80 | |||
99 |
return |
|
81 | return CR_CMD_WRITE, payload | |
100 |
|
82 | |||
101 | def read_config(ip, port): |
|
83 | def read_config(ip, port): | |
102 | """ |
|
84 | """ | |
@@ -117,7 +99,7 def write_config(ip, port, parms): | |||||
117 |
|
99 | |||
118 | """ |
|
100 | """ | |
119 |
|
101 | |||
120 | payload = write_ram_memory(parms['pulses'], parms['delays']) |
|
102 | payload = data.dict_to_rc_str(parms) | |
121 |
|
103 | |||
122 | answer = write_all_device(ip, port, payload) |
|
104 | answer = write_all_device(ip, port, payload) | |
123 |
|
105 | |||
@@ -125,13 +107,13 def write_config(ip, port, parms): | |||||
125 |
|
107 | |||
126 | def __get_low_byte(valor): |
|
108 | def __get_low_byte(valor): | |
127 |
|
109 | |||
128 |
|
|
110 | return ord(valor & 0x00FF) | |
129 |
|
111 | |||
130 | def __get_high_byte(valor): |
|
112 | def __get_high_byte(valor): | |
131 |
|
113 | |||
132 |
|
|
114 | return ord((valor & 0xFF00) >> 8) | |
133 |
|
||||
134 |
|
115 | |||
|
116 | @eth_device(ID_CLASS) | |||
135 | def write_ram_memory(vector_valores, vector_tiempos): |
|
117 | def write_ram_memory(vector_valores, vector_tiempos): | |
136 |
|
118 | |||
137 | l1 = len(vector_valores) |
|
119 | l1 = len(vector_valores) | |
@@ -140,10 +122,10 def write_ram_memory(vector_valores, vector_tiempos): | |||||
140 | cad = "" |
|
122 | cad = "" | |
141 |
|
123 | |||
142 | for i in range(l1): |
|
124 | for i in range(l1): | |
143 |
|
|
125 | cad += ord(84) + __get_low_byte(vector_valores[i]) + ord(85) + __get_high_byte(vector_valores[i]) + \ | |
144 | ord(84) + __get_low_byte(vector_tiempos[i]) + ord(85) + __get_high_byte(vector_tiempos[i]) |
|
126 | ord(84) + __get_low_byte(vector_tiempos[i]) + ord(85) + __get_high_byte(vector_tiempos[i]) | |
145 |
|
127 | |||
146 | return cad |
|
128 | return RC_CMD_WRITE, cad | |
147 |
|
129 | |||
148 | if __name__ == '__main__': |
|
130 | if __name__ == '__main__': | |
149 | ip = "10.10.20.150" |
|
131 | ip = "10.10.20.150" |
@@ -17,7 +17,7 from django.conf.urls import include, url | |||||
17 | from django.contrib import admin |
|
17 | from django.contrib import admin | |
18 |
|
18 | |||
19 | urlpatterns = [ |
|
19 | urlpatterns = [ | |
20 |
url(r'^$', 'apps.main.views.index', name='index'), |
|
20 | url(r'^$', 'apps.main.views.index', name='index'), | |
21 | url(r'^admin/', include(admin.site.urls)), |
|
21 | url(r'^admin/', include(admin.site.urls)), | |
22 | url(r'^accounts/', include('apps.accounts.urls')), |
|
22 | url(r'^accounts/', include('apps.accounts.urls')), | |
23 | url(r'^', include('apps.main.urls')), |
|
23 | url(r'^', include('apps.main.urls')), |
General Comments 0
You need to be logged in to leave comments.
Login now