17 bool NexRtc::write_rtc_time(
char *time)
19 char year[5],mon[3],day[3],hour[3],min[3],sec[3];
20 String cmd = String(
"rtc");
23 if(strlen(time) >= 19)
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';
34 sendCommand(cmd.c_str());
35 recvRetCommandFinished();
40 sendCommand(cmd.c_str());
41 recvRetCommandFinished();
46 sendCommand(cmd.c_str());
47 recvRetCommandFinished();
52 sendCommand(cmd.c_str());
53 recvRetCommandFinished();
58 sendCommand(cmd.c_str());
59 recvRetCommandFinished();
64 sendCommand(cmd.c_str());
65 recvRetCommandFinished();
74 bool NexRtc::write_rtc_time(uint32_t *time)
76 char year[5],mon[3],day[3],hour[3],min[3],sec[3];
77 String cmd = String(
"rtc");
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);
90 sendCommand(cmd.c_str());
91 recvRetCommandFinished();
96 sendCommand(cmd.c_str());
97 recvRetCommandFinished();
102 sendCommand(cmd.c_str());
103 recvRetCommandFinished();
108 sendCommand(cmd.c_str());
109 recvRetCommandFinished();
114 sendCommand(cmd.c_str());
115 recvRetCommandFinished();
120 sendCommand(cmd.c_str());
121 recvRetCommandFinished();
125 bool NexRtc::write_rtc_time(
char *time_type,uint32_t number)
127 String cmd = String(
"rtc");
130 utoa(number, buf, 10);
131 if(strstr(time_type,
"year"))
136 if(strstr(time_type,
"mon"))
141 if(strstr(time_type,
"day"))
146 if(strstr(time_type,
"hour"))
151 if(strstr(time_type,
"min"))
156 if(strstr(time_type,
"sec"))
162 sendCommand(cmd.c_str());
163 return recvRetCommandFinished();
168 char time_buf[22] = {
"0000/00/00 00:00:00 0"};
169 uint32_t year,mon,day,hour,min,sec,week;
173 sendCommand(cmd.c_str());
174 recvRetNumber(&year);
178 sendCommand(cmd.c_str());
183 sendCommand(cmd.c_str());
188 sendCommand(cmd.c_str());
189 recvRetNumber(&hour);
193 sendCommand(cmd.c_str());
198 sendCommand(cmd.c_str());
203 sendCommand(cmd.c_str());
204 recvRetNumber(&week);
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';
226 for(
int i=0;i<22;i++)
228 time[i] = time_buf[i];
232 for(
int i=0;i<len;i++)
234 time[i] = time_buf[i];
242 uint32_t time_buf[7] = {0};
246 sendCommand(cmd.c_str());
247 recvRetNumber(&time_buf[0]);
251 sendCommand(cmd.c_str());
252 recvRetNumber(&time_buf[1]);
256 sendCommand(cmd.c_str());
257 recvRetNumber(&time_buf[2]);
261 sendCommand(cmd.c_str());
262 recvRetNumber(&time_buf[3]);
266 sendCommand(cmd.c_str());
267 recvRetNumber(&time_buf[4]);
271 sendCommand(cmd.c_str());
272 recvRetNumber(&time_buf[5]);
276 sendCommand(cmd.c_str());
277 recvRetNumber(&time_buf[6]);
280 for(
int i=0;i<len;i++)
282 time[i] = time_buf[i];
290 String cmd = String(
"get rtc");
293 if(strstr(time_type,
"year"))
297 else if(strstr(time_type,
"mon"))
301 else if(strstr(time_type,
"day"))
305 else if(strstr(time_type,
"hour"))
309 else if(strstr(time_type,
"min"))
313 else if(strstr(time_type,
"sec"))
317 else if(strstr(time_type,
"week"))
325 sendCommand(cmd.c_str());
326 return recvRetNumber(number);
The definition of class NexRtc.
uint32_t read_rtc_time(char *time, uint32_t len)
read rtc time