@@ -1,122 +1,135 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Dec 2, 2014 |
|
2 | Created on Dec 2, 2014 | |
3 |
|
3 | |||
4 | @author: Miguel Urco |
|
4 | @author: Miguel Urco | |
5 |
|
5 | |||
6 | eth_device decorator is used to implement an api to ethernet devices. |
|
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) |
|
7 | When eth_device decorator is used it adds two parameters to any function (ip and port) | |
8 |
|
8 | |||
9 | #Definition |
|
9 | #Definition | |
10 |
|
10 | |||
11 | @eth_device |
|
11 | @eth_device | |
12 | def enable_rf() |
|
12 | def enable_rf() | |
13 | cmd = "xxxxx" |
|
13 | cmd = "xxxxx" | |
14 | payload = "xxxxxx" |
|
14 | payload = "xxxxxx" | |
15 |
|
15 | |||
16 | return cmd, payload |
|
16 | return cmd, payload | |
17 |
|
17 | |||
18 | #How to call this function: |
|
18 | #How to call this function: | |
19 | answer = enable_rf(ip, port) |
|
19 | answer = enable_rf(ip, port) | |
20 |
|
20 | |||
21 | ''' |
|
21 | ''' | |
22 | import data |
|
22 | import data | |
23 |
|
23 | |||
24 | from devices.jro_device import eth_device, IdClass |
|
24 | from devices.jro_device import eth_device, IdClass | |
25 |
|
25 | |||
26 | ID_CLASS = IdClass["rc"] |
|
26 | ID_CLASS = IdClass["rc"] | |
27 |
|
27 | |||
28 | CMD_RESET =0X01 |
|
28 | CMD_RESET =0X01 | |
29 | CMD_ENABLE =0X02 |
|
29 | CMD_ENABLE =0X02 | |
30 | CMD_CHANGEIP =0X03 |
|
30 | CMD_CHANGEIP =0X03 | |
31 | CMD_STATUS =0X04 |
|
31 | CMD_STATUS =0X04 | |
|
32 | CMD_DISABLE =0X02 | |||
32 | CMD_ECHO =0XFE |
|
33 | CMD_ECHO =0XFE | |
33 |
|
34 | |||
34 |
|
|
35 | RC_CMD_RESET =0X10 | |
35 | DDS_CMD_ENABLE_RF =0x11 |
|
36 | RC_CMD_WRITE =0x50 | |
36 | # DDS_CMD_MULTIPLIER =0X12 |
|
37 | RC_CMD_READ =0x8000 | |
37 | # DDS_CMD_MODE =0x13 |
|
|||
38 | # DDS_CMD_FREQUENCY_A =0X14 |
|
|||
39 | # DDS_CMD_FREQUENCY_B =0x15 |
|
|||
40 | # DDS_CMD_PHASE_A =0X16 |
|
|||
41 | # DDS_CMD_PHASE_B =0x17 |
|
|||
42 | # DDS_CMD_AMPLITUDE_1 =0X19 #Se han invertido la posicion de los canales |
|
|||
43 | # DDS_CMD_AMPLITUDE_2 =0x18 #en el PCB |
|
|||
44 |
|
||||
45 | DDS_CMD_WRITE =0x50 |
|
|||
46 | DDS_CMD_READ =0x8000 |
|
|||
47 |
|
38 | |||
48 | @eth_device(ID_CLASS) |
|
39 | @eth_device(ID_CLASS) | |
49 | def reset(): |
|
40 | def reset(): | |
50 |
|
41 | |||
51 | cmd = CMD_RESET |
|
42 | cmd = CMD_RESET | |
52 | payload = "" |
|
43 | payload = "" | |
53 |
|
44 | |||
54 | return cmd, payload |
|
45 | return cmd, payload | |
55 |
|
46 | |||
56 | @eth_device(ID_CLASS) |
|
47 | @eth_device(ID_CLASS) | |
57 | def change_ip(ip, mask="255.255.255.0", gateway="0.0.0.0"): |
|
48 | def change_ip(ip, mask="255.255.255.0", gateway="0.0.0.0"): | |
58 |
|
49 | |||
59 | cmd = CMD_CHANGEIP |
|
50 | cmd = CMD_CHANGEIP | |
60 | payload = ip + '/' + mask + '/' + gateway |
|
51 | payload = ip + '/' + mask + '/' + gateway | |
61 |
|
52 | |||
62 | return cmd, payload |
|
53 | return cmd, payload | |
63 |
|
54 | |||
64 | @eth_device(ID_CLASS) |
|
55 | @eth_device(ID_CLASS) | |
65 | def status(): |
|
56 | def status(): | |
66 |
|
57 | |||
67 | cmd = CMD_STATUS |
|
58 | cmd = CMD_STATUS | |
68 | payload = "" |
|
59 | payload = "" | |
69 |
|
60 | |||
70 | return cmd, payload |
|
61 | return cmd, payload | |
71 |
|
62 | |||
72 | @eth_device(ID_CLASS) |
|
63 | @eth_device(ID_CLASS) | |
73 | def echo(): |
|
64 | def echo(): | |
74 |
|
65 | |||
75 | cmd = CMD_ECHO |
|
66 | cmd = CMD_ECHO | |
76 | payload = "" |
|
67 | payload = "" | |
77 |
|
68 | |||
78 | return cmd, payload |
|
69 | return cmd, payload | |
79 |
|
70 | |||
80 | @eth_device(ID_CLASS) |
|
71 | @eth_device(ID_CLASS) | |
81 | def read_all_device(): |
|
72 | def read_all_device(): | |
82 |
|
73 | |||
83 | payload = "" |
|
74 | payload = "" | |
84 |
|
75 | |||
85 |
return |
|
76 | return CR_CMD_READ, payload | |
86 |
|
77 | |||
87 | @eth_device(ID_CLASS) |
|
78 | @eth_device(ID_CLASS) | |
88 | def write_all_device(payload): |
|
79 | def write_all_device(payload): | |
89 |
|
80 | |||
90 |
return |
|
81 | return CR_CMD_WRITE, payload | |
91 |
|
82 | |||
92 | def read_config(ip, port): |
|
83 | def read_config(ip, port): | |
93 | """ |
|
84 | """ | |
94 | Output: |
|
85 | Output: | |
95 | parms : Dictionary with keys |
|
86 | parms : Dictionary with keys | |
96 |
|
87 | |||
97 | """ |
|
88 | """ | |
98 | payload = read_all_device(ip, port) |
|
89 | payload = read_all_device(ip, port) | |
99 |
|
90 | |||
100 | return data.rc_str_to_dict(payload) |
|
91 | return data.rc_str_to_dict(payload) | |
101 |
|
92 | |||
102 | def write_config(ip, port, parms): |
|
93 | def write_config(ip, port, parms): | |
103 | """ |
|
94 | """ | |
104 | Input: |
|
95 | Input: | |
105 | ip : |
|
96 | ip : | |
106 | port : |
|
97 | port : | |
107 | parms : Dictionary with keys |
|
98 | parms : Dictionary with keys | |
108 |
|
99 | |||
109 | """ |
|
100 | """ | |
110 |
|
101 | |||
111 | payload = data.dict_to_rc_str(parms) |
|
102 | payload = data.dict_to_rc_str(parms) | |
112 |
|
103 | |||
113 | answer = write_all_device(ip, port, payload) |
|
104 | answer = write_all_device(ip, port, payload) | |
114 |
|
105 | |||
115 | return answer |
|
106 | return answer | |
116 |
|
107 | |||
|
108 | def __get_low_byte(valor): | |||
|
109 | ||||
|
110 | return ord(valor & 0x00FF) | |||
|
111 | ||||
|
112 | def __get_high_byte(valor): | |||
|
113 | ||||
|
114 | return ord((valor & 0xFF00) >> 8) | |||
|
115 | ||||
|
116 | @eth_device(ID_CLASS) | |||
|
117 | def write_ram_memory(vector_valores, vector_tiempos): | |||
|
118 | ||||
|
119 | l1 = len(vector_valores) | |||
|
120 | l2 = len(vector_tiempos) | |||
|
121 | ||||
|
122 | cad = "" | |||
|
123 | ||||
|
124 | for i in range(l1): | |||
|
125 | cad += ord(84) + __get_low_byte(vector_valores[i]) + ord(85) + __get_high_byte(vector_valores[i]) + \ | |||
|
126 | ord(84) + __get_low_byte(vector_tiempos[i]) + ord(85) + __get_high_byte(vector_tiempos[i]) | |||
|
127 | ||||
|
128 | return RC_CMD_WRITE, cad | |||
|
129 | ||||
117 | if __name__ == '__main__': |
|
130 | if __name__ == '__main__': | |
118 | ip = "10.10.20.150" |
|
131 | ip = "10.10.20.150" | |
119 | port = 2000 |
|
132 | port = 2000 | |
120 |
|
133 | |||
121 | print status(ip, port) |
|
134 | print status(ip, port) | |
122 | print read_config(ip, port) No newline at end of file |
|
135 | print read_config(ip, port) |
General Comments 0
You need to be logged in to leave comments.
Login now