Documentation: NexRtc.cpp Source File

| Documentation For Arduino users

- Main Page
- Related Pages
- Modules
- Classes
- Files
- Examples

- File List
- File Members

NexRtc.cpp
Go to the documentation of this file.
1
15 #include "NexRtc.h"
16
17 bool NexRtc::write_rtc_time(char *time)
18 {
19 char year[5],mon[3],day[3],hour[3],min[3],sec[3];
20 String cmd = String("rtc");
21 int i;
22
23 if(strlen(time) >= 19)
24 {
25 year[0]=time[0];year[1]=time[1];year[2]=time[2];year[3]=time[3];year[4]='\0';
26 mon[0]=time[5];mon[1]=time[6];mon[2]='\0';
27 day[0]=time[8];day[1]=time[9];day[2]='\0';
28 hour[0]=time[11];hour[1]=time[12];hour[2]='\0';
29 min[0]=time[14];min[1]=time[15];min[2]='\0';
30 sec[0]=time[17];sec[1]=time[18];sec[2]='\0';
31
32 cmd += "0=";
33 cmd += year;
34 sendCommand(cmd.c_str());
35 recvRetCommandFinished();
36
37 cmd = "";
38 cmd += "rtc1=";
39 cmd += mon;
40 sendCommand(cmd.c_str());
41 recvRetCommandFinished();
42
43 cmd = "";
44 cmd += "rtc2=";
45 cmd += day;
46 sendCommand(cmd.c_str());
47 recvRetCommandFinished();
48
49 cmd = "";
50 cmd += "rtc3=";
51 cmd += hour;
52 sendCommand(cmd.c_str());
53 recvRetCommandFinished();
54
55 cmd = "";
56 cmd += "rtc4=";
57 cmd += min;
58 sendCommand(cmd.c_str());
59 recvRetCommandFinished();
60
61 cmd = "";
62 cmd += "rtc5=";
63 cmd += sec;
64 sendCommand(cmd.c_str());
65 recvRetCommandFinished();
66
67 }
68 else
69 {
70 return false;
71 }
72 }
73
74 bool NexRtc::write_rtc_time(uint32_t *time)
75 {
76 char year[5],mon[3],day[3],hour[3],min[3],sec[3];
77 String cmd = String("rtc");
78 int i;
79
80 utoa(time[0],year,10);
81 utoa(time[1],mon, 10);
82 utoa(time[2],day, 10);
83 utoa(time[3],hour,10);
84 utoa(time[4],min, 10);
85 utoa(time[5],sec, 10);
86
87
88 cmd += "0=";
89 cmd += year;
90 sendCommand(cmd.c_str());
91 recvRetCommandFinished();
92
93 cmd = "";
94 cmd += "rtc1=";
95 cmd += mon;
96 sendCommand(cmd.c_str());
97 recvRetCommandFinished();
98
99 cmd = "";
100 cmd += "rtc2=";
101 cmd += day;
102 sendCommand(cmd.c_str());
103 recvRetCommandFinished();
104
105 cmd = "";
106 cmd += "rtc3=";
107 cmd += hour;
108 sendCommand(cmd.c_str());
109 recvRetCommandFinished();
110
111 cmd = "";
112 cmd += "rtc4=";
113 cmd += min;
114 sendCommand(cmd.c_str());
115 recvRetCommandFinished();
116
117 cmd = "";
118 cmd += "rtc5=";
119 cmd += sec;
120 sendCommand(cmd.c_str());
121 recvRetCommandFinished();
122
123 }
124
125 bool NexRtc::write_rtc_time(char *time_type,uint32_t number)
126 {
127 String cmd = String("rtc");
128 char buf[10] = {0};
129
130 utoa(number, buf, 10);
131 if(strstr(time_type,"year"))
132 {
133 cmd += "0=";
134 cmd += buf;
135 }
136 if(strstr(time_type,"mon"))
137 {
138 cmd += "1=";
139 cmd += buf;
140 }
141 if(strstr(time_type,"day"))
142 {
143 cmd += "2=";
144 cmd += buf;
145 }
146 if(strstr(time_type,"hour"))
147 {
148 cmd += "3=";
149 cmd += buf;
150 }
151 if(strstr(time_type,"min"))
152 {
153 cmd += "4=";
154 cmd += buf;
155 }
156 if(strstr(time_type,"sec"))
157 {
158 cmd += "5=";
159 cmd += buf;
160 }
161
162 sendCommand(cmd.c_str());
163 return recvRetCommandFinished();
164 }
165
166 uint32_t NexRtc::read_rtc_time(char *time,uint32_t len)
167 {
168 char time_buf[22] = {"0000/00/00 00:00:00 0"};
169 uint32_t year,mon,day,hour,min,sec,week;
170 String cmd;
171
172 cmd = "get rtc0";
173 sendCommand(cmd.c_str());
174 recvRetNumber(&year);
175
176 cmd = "";
177 cmd = "get rtc1";
178 sendCommand(cmd.c_str());
179 recvRetNumber(&mon);
180
181 cmd = "";
182 cmd = "get rtc2";
183 sendCommand(cmd.c_str());
184 recvRetNumber(&day);
185
186 cmd = "";
187 cmd = "get rtc3";
188 sendCommand(cmd.c_str());
189 recvRetNumber(&hour);
190
191 cmd = "";
192 cmd = "get rtc4";
193 sendCommand(cmd.c_str());
194 recvRetNumber(&min);
195
196 cmd = "";
197 cmd = "get rtc5";
198 sendCommand(cmd.c_str());
199 recvRetNumber(&sec);
200
201 cmd = "";
202 cmd = "get rtc6";
203 sendCommand(cmd.c_str());
204 recvRetNumber(&week);
205
206 time_buf[0] = year/1000 + '0';
207 time_buf[1] = (year/100)%10 + '0';
208 time_buf[2] = (year/10)%10 + '0';
209 time_buf[3] = year%10 + '0';
210 time_buf[5] = mon/10 + '0';
211 time_buf[6] = mon%10 + '0';
212 time_buf[8] = day/10 + '0';
213 time_buf[9] = day%10 + '0';
214 time_buf[11] = hour/10 + '0';
215 time_buf[12] = hour%10 + '0';
216 time_buf[14] = min/10 + '0';
217 time_buf[15] = min%10 + '0';
218 time_buf[17] = sec/10 + '0';
219 time_buf[18] = sec%10 + '0';
220 time_buf[20] = week + '0';
221 time_buf[21] = '\0';
222
223
224 if(len >= 22)
225 {
226 for(int i=0;i<22;i++)
227 {
228 time[i] = time_buf[i];
229 }
230 }
231 else{
232 for(int i=0;i<len;i++)
233 {
234 time[i] = time_buf[i];
235 }
236 }
237
238 }
239
240 uint32_t NexRtc::read_rtc_time(uint32_t *time,uint32_t len)
241 {
242 uint32_t time_buf[7] = {0};
243 String cmd;
244
245 cmd = "get rtc0";
246 sendCommand(cmd.c_str());
247 recvRetNumber(&time_buf[0]);
248
249 cmd = "";
250 cmd = "get rtc1";
251 sendCommand(cmd.c_str());
252 recvRetNumber(&time_buf[1]);
253
254 cmd = "";
255 cmd = "get rtc2";
256 sendCommand(cmd.c_str());
257 recvRetNumber(&time_buf[2]);
258
259 cmd = "";
260 cmd = "get rtc3";
261 sendCommand(cmd.c_str());
262 recvRetNumber(&time_buf[3]);
263
264 cmd = "";
265 cmd = "get rtc4";
266 sendCommand(cmd.c_str());
267 recvRetNumber(&time_buf[4]);
268
269 cmd = "";
270 cmd = "get rtc5";
271 sendCommand(cmd.c_str());
272 recvRetNumber(&time_buf[5]);
273
274 cmd = "";
275 cmd = "get rtc6";
276 sendCommand(cmd.c_str());
277 recvRetNumber(&time_buf[6]);
278
279
280 for(int i=0;i<len;i++)
281 {
282 time[i] = time_buf[i];
283 }
284
285 }
286
287
288 uint32_t NexRtc::read_rtc_time(char *time_type,uint32_t *number)
289 {
290 String cmd = String("get rtc");
291 char buf[10] = {0};
292
293 if(strstr(time_type,"year"))
294 {
295 cmd += '0';
296 }
297 else if(strstr(time_type,"mon"))
298 {
299 cmd += '1';
300 }
301 else if(strstr(time_type,"day"))
302 {
303 cmd += '2';
304 }
305 else if(strstr(time_type,"hour"))
306 {
307 cmd += '3';
308 }
309 else if(strstr(time_type,"min"))
310 {
311 cmd += '4';
312 }
313 else if(strstr(time_type,"sec"))
314 {
315 cmd += '5';
316 }
317 else if(strstr(time_type,"week"))
318 {
319 cmd += '6';
320 }
321 else{
322 return false;
323 }
324
325 sendCommand(cmd.c_str());
326 return recvRetNumber(number);
327 }
NexRtc.h
The definition of class NexRtc.
NexRtc::read_rtc_time
uint32_t read_rtc_time(char *time, uint32_t len)
read rtc time
Definition: NexRtc.cpp:166