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