comparison g23m/condat/ms/src/aci/line_edit.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul : line
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This modul ...
18 +-----------------------------------------------------------------------------
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <ctype.h>
25
26 #include "typedefs.h"
27 #include "vsi.h"
28 #include "pei.h"
29 #include "aci_mem.h"
30 #include "P_ACI.val"
31
32 #include "line_edit.h"
33 #include "line_edit_intern.h"
34 #include "line_split_intern.h"
35
36
37 GLOBAL char g_ledit_echoBuf[MAX_CMD_LEN+1];
38
39 static T_LEDIT_SRC_MAINTAIN *rootSrc = NULL;
40
41 /* state machine functions */
42 static T_LEDIT_RSLT ledit_idle (T_LEDIT_INTERN *leditInt);
43 static T_LEDIT_RSLT ledit_prefix_a (T_LEDIT_INTERN *leditInt);
44 static T_LEDIT_RSLT ledit_prefix_t (T_LEDIT_INTERN *leditInt);
45 static T_LEDIT_RSLT ledit_repeat (T_LEDIT_INTERN *leditInt);
46 static T_LEDIT_RSLT ledit_collect (T_LEDIT_INTERN *leditInt);
47 static T_LEDIT_RSLT ledit_run_cmd (T_LEDIT_INTERN *leditInt);
48 /* help functions */
49 static T_LEDIT_SRC_MAINTAIN *ledit_getNewSrcMaintain (T_LEDIT_SRC_MAINTAIN *lesm);
50 static T_LEDIT_SRC_MAINTAIN *ledit_getSrcM (UBYTE src_id, const UBYTE *chars, USHORT len);
51 static T_LEDIT_SRC_MAINTAIN *ledit_getSrc (UBYTE src_id);
52
53 static T_LEDIT_RSLT ledit_remove_src (T_LEDIT_SRC_MAINTAIN *lesm);
54 static T_LEDIT_RSLT ledit_check_param (const UBYTE *chars, USHORT len);
55 static T_LEDIT_RSLT ledit_clear_lineBuf(T_LEDIT_INTERN *leditInt);
56 static T_LEDIT_RSLT ledit_clear_all (T_LEDIT_INTERN *leditInt);
57 static T_LEDIT_RSLT ledit_backup (T_LEDIT_INTERN *leditInt);
58 static T_LEDIT_RSLT ledit_echo (T_LEDIT_INTERN *leditInt);
59 static void ledit_echo_clear (void);
60
61 /*
62 +--------------------------------------------------------------------+
63 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
64 | STATE : code ROUTINE : ledit_set_config |
65 +--------------------------------------------------------------------+
66
67 PURPOSE : - configure CR, LF, BS chars --> similiar to S3, S4, S5
68 - configure echo --> similiar to ATE echo cmds in command mode
69 - configure echo --> similiar to ATF echo cmds in data mode
70 */
71 T_LEDIT_RSLT ledit_set_config (UBYTE src_id, T_LEDIT line)
72 {
73 T_LEDIT_SRC_MAINTAIN *lineSrcM = NULL;
74 UBYTE *chars = NULL;
75 USHORT len = 0;
76
77 /*
78 * get the maintenance for this AT source or create a new one or die
79 */
80 if ((lineSrcM = ledit_getSrcM (src_id, chars, len)) EQ NULL)
81 {
82 return (LEDIT_FAIL);
83 }
84 /*
85 * some checks of T_LEDIT line
86 */
87 if (line.atE NEQ 0xFF)
88 {
89 if ((line.atE EQ TRUE) OR (line.atE EQ FALSE))
90 {
91 lineSrcM->leditInt->lineHabit.atE = line.atE;
92 }
93 else
94 {
95 return (LEDIT_FAIL);
96 }
97 }
98
99 if (line.S3 NEQ 0xFF)
100 {
101 if (line.S3 < 128)
102 {
103 lineSrcM->leditInt->lineHabit.S3 = line.S3;
104 }
105 else
106 {
107 return (LEDIT_FAIL);
108 }
109 }
110
111 if (line.S4 NEQ 0xFF)
112 {
113 if (line.S4 < 128)
114 {
115 lineSrcM->leditInt->lineHabit.S4 = line.S4;
116 }
117 else
118 {
119 return (LEDIT_FAIL);
120 }
121 }
122
123 if (line.S5 NEQ 0xFF)
124 {
125 if (line.S5 < 128)
126 {
127 lineSrcM->leditInt->lineHabit.S5 = line.S5;
128 }
129 else
130 {
131 return (LEDIT_FAIL);
132 }
133 }
134
135 if (line.smsEnd NEQ 0xFF)
136 {
137 if (line.smsEnd < 128)
138 {
139 lineSrcM->leditInt->lineHabit.smsEnd = line.smsEnd;
140 }
141 else
142 {
143 return (LEDIT_FAIL);
144 }
145 }
146
147 return (LEDIT_CMPL);
148 }
149
150
151 /*
152 +--------------------------------------------------------------------+
153 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
154 | STATE : code ROUTINE : ledit_ctrl |
155 +--------------------------------------------------------------------+
156
157 PURPOSE : - inform and control line edit
158 - in err will be error code and error message of line edit
159 */
160
161 T_LEDIT_RSLT ledit_ctrl (UBYTE src_id, T_LEDIT_CTRL ctrl, T_LEDIT_ERR **err)
162 {
163 T_LEDIT_SRC_MAINTAIN *lineSrcM = NULL;
164
165 TRACE_FUNCTION ("ledit_ctrl()");
166
167 /*
168 * get the maintenance for this AT source or create a new one or die
169 */
170 if ((lineSrcM = ledit_getSrcM (src_id, NULL, 0)) EQ NULL)
171 {
172 return (LEDIT_FAIL);
173 }
174
175 switch (ctrl)
176 {
177 case LEDIT_CTRL_PROMPT:
178 {
179 ledit_echo_clear();
180 strcpy (g_ledit_echoBuf,"> ");
181 TRACE_EVENT("ledit_ctrl(): prompt for SMS editing");
182 return (LEDIT_CMPL);
183 }
184 case LEDIT_CTRL_CRLF_PROMPT:
185 {
186 ledit_echo_clear();
187 /* (IRA 13, 10, 62, 32) see 07.05 */
188 g_ledit_echoBuf[0] = 0x0D; /* lineSrcM->leditInt->lineHabit.S3; */ /* CR */
189 g_ledit_echoBuf[1] = 0x0A; /* lineSrcM->leditInt->lineHabit.S4; */ /* LF */
190 g_ledit_echoBuf[2] = 0x3E; /* '>' */
191 g_ledit_echoBuf[3] = 0x20; /* ' ' */
192 g_ledit_echoBuf[4] = '\0';
193 TRACE_EVENT("ledit_ctrl(): default settings for line behaviour");
194 return (LEDIT_CMPL);
195 }
196 case LEDIT_CTRL_CMPL:
197 {
198 TRACE_EVENT("ledit_ctrl(): reset ledit internals");
199 ledit_clear_all(lineSrcM->leditInt);
200 return (LEDIT_CMPL);
201 }
202 case LEDIT_CTRL_REMOVE_SRC:
203 {
204 ledit_remove_src(lineSrcM);
205 return (LEDIT_CMPL);
206 }
207 case LEDIT_CTRL_ERROR:
208 {
209 if (err)
210 {
211 *err = &lineSrcM->leditInt->err;
212 }
213 return (LEDIT_CMPL);
214 }
215 case LEDIT_CTRL_MORE_CMDS: /* query whether there are more than one cmd */
216 {
217 if (lineSrcM->leditInt->cmdGetIter < lineSrcM->leditInt->cmdIndex) /* check if cmdline already fully parsed */
218 {
219 TRACE_EVENT("ledit_ctrl(): are there more commands ? Yes !");
220 return (LEDIT_CMPL);
221 }
222 else
223 {
224 TRACE_EVENT("ledit_ctrl(): are there more commands ? No !");
225 return (LEDIT_FAIL);
226 }
227 }
228 default:
229 {
230 if (*err)
231 {
232 (*err)->code = LEDIT_ERR_Unknown;
233 (*err)->msg = ledit_err[LEDIT_ERR_Unknown].msg;
234 }
235 return (LEDIT_FAIL);
236 }
237 }
238 }
239
240 /*
241 +--------------------------------------------------------------------+
242 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
243 | STATE : code ROUTINE : ledit_get_first |
244 +--------------------------------------------------------------------+
245
246 PURPOSE : -
247 */
248
249 T_LEDIT_RSLT ledit_get_first (UBYTE src_id, T_LEDIT_ATCMD **cmd)
250 {
251 T_LEDIT_SRC_MAINTAIN *lesm = ledit_getSrc(src_id);
252
253 TRACE_FUNCTION ("ledit_get_first()");
254
255 *cmd = NULL; /* init with no command available */
256
257 if (lesm EQ NULL)
258 {
259 return (LEDIT_FAIL);
260 }
261
262 if (lesm->leditInt->cmdm EQ NULL)
263 {
264 return (LEDIT_FAIL);
265 }
266
267 *cmd = lesm->leditInt->cmdm->cmd;
268 return (LEDIT_CMPL);
269 }
270
271
272 /*
273 +--------------------------------------------------------------------+
274 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
275 | STATE : code ROUTINE : ledit_get_next |
276 +--------------------------------------------------------------------+
277
278 PURPOSE : -
279 */
280
281 T_LEDIT_RSLT ledit_get_next (UBYTE src_id, T_LEDIT_ATCMD **cmd)
282 {
283 T_LEDIT_ATCMD_M **curCmd = NULL;
284
285 T_LEDIT_SRC_MAINTAIN *lesm = ledit_getSrc(src_id);
286
287 TRACE_FUNCTION ("ledit_get_next()");
288
289 *cmd = NULL; /* init with no command available */
290
291 if (lesm EQ NULL)
292 {
293 return (LEDIT_FAIL);
294 }
295
296 ++(lesm->leditInt->cmdGetIter); /* 1 .. n */
297
298 ledit_free_cmd(lesm->leditInt); /* clear all (=previous) commands */
299 lesm->leditInt->cmdm = NULL;
300 if (ledit_split(lesm->leditInt) EQ LEDIT_CMPL)
301 {
302 curCmd = &(lesm->leditInt->cmdm);
303 if (*curCmd)
304 {
305 *cmd = (*curCmd)->cmd;
306 return (LEDIT_CMPL);
307 }
308 }
309
310 return (LEDIT_FAIL); /* no further command available */
311 }
312
313
314 /*
315 +--------------------------------------------------------------------+
316 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
317 | STATE : code ROUTINE : ledit_get_current |
318 +--------------------------------------------------------------------+
319
320 PURPOSE : - for text mode relevant functions, which have to be called twice
321 1. with the destination adress
322 2. with the text
323 */
324
325 T_LEDIT_RSLT ledit_get_current (UBYTE src_id, T_LEDIT_ATCMD **cmd)
326 {
327 T_LEDIT_SRC_MAINTAIN *lesm = ledit_getSrc(src_id);
328
329 TRACE_FUNCTION ("ledit_get_current()");
330
331 *cmd = NULL; /* init with no command available */
332
333 if (lesm EQ NULL)
334 {
335 return (LEDIT_FAIL);
336 }
337
338 if (lesm->leditInt->cmdm EQ NULL)
339 {
340 return (LEDIT_FAIL);
341 }
342
343 *cmd = lesm->leditInt->cmdm->cmd;
344 return (LEDIT_CMPL);
345 }
346
347
348 /*
349 +--------------------------------------------------------------------+
350 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
351 | STATE : code ROUTINE : ledit_text |
352 +--------------------------------------------------------------------+
353
354 PURPOSE : -
355 - switch from cmd mode to text mode
356 */
357
358 T_LEDIT_RSLT ledit_text (UBYTE src_id, const UBYTE *chars, USHORT len)
359 {
360 T_LEDIT_SRC_MAINTAIN *lineSrcM = NULL;
361 char c = '\0';
362
363 static unsigned int beginline; /* first character position in current line */
364
365 TRACE_FUNCTION ("ledit_text()");
366
367 /*
368 * get the maintenance for this AT source
369 */
370 if ((lineSrcM = ledit_getSrcM (src_id, chars, len)) EQ NULL)
371 {
372 return (LEDIT_FAIL);
373 }
374
375 ledit_echo_clear ();
376 /*
377 * we use the cmdBuffer to store the text, so clean it up at first calling of this function
378 * in case of text sent in several chunks (this function is called again), concatenate them
379 * by leaving the copy iterator and the cmdBuffer untouched
380 * txtChunk is a binary flag
381 */
382 if (lineSrcM->leditInt->txtChunk EQ FALSE)
383 {
384 ledit_clear_lineBuf (lineSrcM->leditInt);
385 lineSrcM->leditInt->txtChunk = TRUE;
386 beginline=0;
387 }
388
389 while (lineSrcM->leditInt->srcBufIter < len)
390 {
391 c = lineSrcM->leditInt->srcBuffer[lineSrcM->leditInt->srcBufIter];
392
393 if (lineSrcM->leditInt->copyIter EQ MAX_CMD_LEN) /* FIXME: Should be depending to csca arround 160 */
394 {
395 if (c EQ 0x1b)
396 ;
397 else if (c EQ lineSrcM->leditInt->lineHabit.S5)
398 ;
399 else if (c EQ lineSrcM->leditInt->lineHabit.smsEnd)
400 ;
401 else
402 return (LEDIT_IGNORE);
403 }
404 if (c EQ 0x1b) /* ESC */
405 {
406 if (lineSrcM->leditInt->smsBuffer)
407 {
408 ACI_MFREE (lineSrcM->leditInt->smsBuffer); /* at first delete possible last text */
409 }
410 lineSrcM->leditInt->smsBuffer = NULL;
411 lineSrcM->leditInt->txtChunk = FALSE;
412 return (LEDIT_ESC); /* don't generate any error message */
413 }
414 else if (c EQ lineSrcM->leditInt->lineHabit.smsEnd) /* CTRL-Z, for all non V25.ter conform rockers */
415 {
416 lineSrcM->leditInt->origBuffer[lineSrcM->leditInt->origBufIter++] = '\0'; /* terminate text */
417 lineSrcM->leditInt->lineBuffer[lineSrcM->leditInt->copyIter++] = '\0'; /* terminate text */
418
419 if (lineSrcM->leditInt->smsBuffer)
420 {
421 ACI_MFREE (lineSrcM->leditInt->smsBuffer); /* at first delete possible last text */
422 }
423 ACI_MALLOC(lineSrcM->leditInt->smsBuffer, ((lineSrcM->leditInt->copyIter+1) * sizeof(char)));
424 if (lineSrcM->leditInt->smsBuffer EQ NULL)
425 {
426 return (LEDIT_FAIL);
427 }
428 strcpy (lineSrcM->leditInt->smsBuffer, lineSrcM->leditInt->lineBuffer);
429 lineSrcM->leditInt->txtChunk = FALSE;
430 return (LEDIT_CMPL);
431 }
432 else if (c EQ lineSrcM->leditInt->lineHabit.S3)
433 {
434 lineSrcM->leditInt->origBuffer[lineSrcM->leditInt->origBufIter++] = 0x0a; /* add newline into SMS */
435 lineSrcM->leditInt->lineBuffer[lineSrcM->leditInt->copyIter++] = 0x0a; /* add newline into SMS */
436 /*
437 * split text, so emit promp "> " again
438 */
439 g_ledit_echoBuf[lineSrcM->leditInt->srcBufIter] = 0x0d; /* lineSrcM->leditInt->lineHabit.S3; */
440 g_ledit_echoBuf[lineSrcM->leditInt->srcBufIter+1] = 0x0a; /* lineSrcM->leditInt->lineHabit.S4; */
441 g_ledit_echoBuf[lineSrcM->leditInt->srcBufIter+2] = 0x3e; /* '>' */
442 g_ledit_echoBuf[lineSrcM->leditInt->srcBufIter+3] = 0x20; /* ' ' */
443 beginline = lineSrcM->leditInt->copyIter; /* reset line */
444 }
445 else if (c EQ lineSrcM->leditInt->lineHabit.S4)
446 {
447 ; /* ignore Linefeeds */
448 }
449 else if (c EQ lineSrcM->leditInt->lineHabit.S5) /* backspace */
450 {
451 /*
452 * delete last character in cmd buffer by setting iterator one step back
453 */
454 if (lineSrcM->leditInt->copyIter > beginline)
455 {
456 --(lineSrcM->leditInt->origBufIter);
457 --(lineSrcM->leditInt->copyIter);
458 g_ledit_echoBuf[lineSrcM->leditInt->srcBufIter] = c;
459 return (LEDIT_COLLECT);
460 }
461 else
462 return (LEDIT_IGNORE);
463 }
464 else
465 {
466 lineSrcM->leditInt->origBuffer[lineSrcM->leditInt->origBufIter++] = c; /* copy character to cmd buffer */
467 lineSrcM->leditInt->lineBuffer[lineSrcM->leditInt->copyIter++] = c; /* copy character to cmd buffer */
468 g_ledit_echoBuf[lineSrcM->leditInt->srcBufIter] = c;
469 }
470 ++(lineSrcM->leditInt->srcBufIter);
471 }
472 return (LEDIT_COLLECT);
473 }
474
475 /*
476 +--------------------------------------------------------------------+
477 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
478 | STATE : code ROUTINE : ledit_get_text |
479 +--------------------------------------------------------------------+
480
481 PURPOSE : -
482 */
483
484 T_LEDIT_RSLT ledit_get_text (UBYTE src_id, char **txt)
485 {
486 T_LEDIT_SRC_MAINTAIN *lineSrcM = NULL;
487 /*
488 * get the maintenance for this AT source
489 */
490 if ((lineSrcM = ledit_getSrcM (src_id, NULL, 0)) EQ NULL)
491 {
492 return (LEDIT_FAIL);
493 }
494
495 if (*txt)
496 {
497 ACI_MFREE (*txt); /* free the cmd parameter part */
498 }
499
500 ACI_MALLOC (*txt, (strlen(lineSrcM->leditInt->smsBuffer)+1) * sizeof(char));
501 if (*txt EQ NULL)
502 {
503 return (LEDIT_FAIL);
504 }
505 /*
506 * the complementary ACI_MFREE takes place in ledit_ctrl (src_params->src_id,LEDIT_CTRL_CMPL, NULL);
507 * which has to called for success or fail of a AT cmd line. grep in ati_cmd.c and ati_ret.c
508 */
509 if (lineSrcM->leditInt->smsBuffer)
510 {
511 strcpy (*txt, lineSrcM->leditInt->smsBuffer); /* the parameter of the AT cmd is now the SMS text */
512 }
513 else
514 {
515 **txt = '\0'; /* in case of 0 byte text */
516 }
517 return (LEDIT_CMPL);
518 }
519
520 /*
521 +--------------------------------------------------------------------+
522 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
523 | STATE : code ROUTINE : ledit_backup |
524 +--------------------------------------------------------------------+
525
526 PURPOSE : - for possible next A/ back up the current cmd line
527 NOW: we shift the lineBuffer to execBuffer for execution!!!
528 */
529
530 static T_LEDIT_RSLT ledit_backup (T_LEDIT_INTERN *leditInt)
531 {
532 if (leditInt->execBuffer)
533 {
534 ACI_MFREE (leditInt->execBuffer);
535 }
536
537 leditInt->execBuffer = leditInt->lineBuffer;
538 leditInt->lineBuffer = NULL;
539 return (LEDIT_CMPL);
540 }
541
542 /*
543 +--------------------------------------------------------------------+
544 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
545 | STATE : code ROUTINE : ledit_echo_clear |
546 +--------------------------------------------------------------------+
547
548 PURPOSE : -
549 */
550 static void ledit_echo_clear (void)
551 {
552 memset(g_ledit_echoBuf, '\0', sizeof(g_ledit_echoBuf));
553 }
554
555
556 /*
557 +--------------------------------------------------------------------+
558 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
559 | STATE : code ROUTINE : ledit_echo |
560 +--------------------------------------------------------------------+
561
562 PURPOSE : - for echoing put the current chars into the g_ledit_echoBuffer
563 but attention:
564 all chars before the first [aA] are ignored
565 the same between [aA] and [tT]
566 Example : "murx blah fiT + cFun = 1" will be echoed as
567 - ------------
568 "aT + cFun = 1"
569 */
570 static T_LEDIT_RSLT ledit_echo (T_LEDIT_INTERN *leditInt)
571 {
572 int i = 0;
573 while (g_ledit_echoBuf[i]) /* skip possible [aAtT] */
574 {
575 ++i;
576 }
577
578 while (leditInt->srcBufIterE < leditInt->len)
579 {
580 g_ledit_echoBuf[i] = leditInt->srcBuffer[leditInt->srcBufIterE];
581 if (leditInt->srcBuffer[leditInt->srcBufIterE] EQ leditInt->lineHabit.S3)
582 {
583 ++i;
584 break;
585 }
586 ++(leditInt->srcBufIterE);
587 ++i;
588 }
589
590 g_ledit_echoBuf[i] = '\0';
591
592 leditInt->srcBufIterE = 0;
593
594 return (LEDIT_CMPL);
595 }
596
597
598
599 /*
600 +--------------------------------------------------------------------+
601 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
602 | STATE : code ROUTINE : ledit_remove_src |
603 +--------------------------------------------------------------------+
604
605 PURPOSE :
606 */
607 static T_LEDIT_RSLT ledit_remove_src (T_LEDIT_SRC_MAINTAIN *lesm)
608 {
609 T_LEDIT_SRC_MAINTAIN *ledSrcM = rootSrc;
610 T_LEDIT_SRC_MAINTAIN *tmp = rootSrc;
611
612 if (rootSrc EQ lesm)
613 {
614 tmp = rootSrc->next;
615 ledit_clear_all (rootSrc->leditInt);
616 ACI_MFREE (rootSrc->leditInt);
617 rootSrc->leditInt = NULL;
618 rootSrc = tmp;
619 return (LEDIT_CMPL);
620 }
621 else
622 {
623 while(ledSrcM)
624 {
625 if (ledSrcM EQ lesm)
626 {
627 tmp->next = ledSrcM->next;
628 ledit_clear_all (ledSrcM->leditInt);
629 ACI_MFREE (ledSrcM->leditInt);
630 ACI_MFREE (ledSrcM);
631 ledSrcM = NULL;
632 return (LEDIT_CMPL);
633 }
634 tmp = ledSrcM;
635 ledSrcM = ledSrcM->next;
636 }
637 return (LEDIT_FAIL);
638 }
639 }
640
641 /*
642 +--------------------------------------------------------------------+
643 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
644 | STATE : code ROUTINE : ledit_getNewSrcMaintain |
645 +--------------------------------------------------------------------+
646
647 PURPOSE :
648 */
649 static T_LEDIT_SRC_MAINTAIN *ledit_getNewSrcMaintain (T_LEDIT_SRC_MAINTAIN *lesm)
650 {
651 static
652 T_LEDIT ledit_initial = {13, 10, 8, 1, 0x1a};
653 /* S3 S4 S5 E, smsEnd */
654
655 ACI_MALLOC(lesm, (sizeof (T_LEDIT_SRC_MAINTAIN)));
656 if (lesm EQ NULL)
657 {
658 return NULL;
659 }
660 lesm->next = NULL;
661
662 ACI_MALLOC(lesm->leditInt,(sizeof (T_LEDIT_INTERN)));
663 if (lesm->leditInt EQ NULL)
664 {
665 ACI_MFREE (lesm);
666 lesm = NULL;
667 return NULL;
668 }
669 memset(lesm->leditInt, '\0', sizeof (T_LEDIT_INTERN));
670
671 lesm->leditInt->copyIter = 0;
672
673 lesm->leditInt->srcBuffer = NULL;
674 lesm->leditInt->srcBufIter = 0;
675
676 lesm->leditInt->smsBuffer = NULL;
677
678 lesm->leditInt->lineBuffer = NULL;
679 lesm->leditInt->lineBufIter = 0;
680
681 lesm->leditInt->origBuffer = NULL;
682 lesm->leditInt->origBufIter = 0;
683
684 lesm->leditInt->execBuffer = NULL;
685 lesm->leditInt->execBufIter = 0;
686
687 lesm->leditInt->state = ledit_idle;
688 lesm->leditInt->lineHabit = ledit_initial;
689 lesm->leditInt->err.code = LEDIT_ERR_NONE;
690 lesm->leditInt->err.msg = NULL;
691 lesm->leditInt->isStr = FALSE;
692 lesm->leditInt->cmdGetIter = 0;
693 lesm->leditInt->cmdm = NULL;
694 ledit_clear_all(lesm->leditInt);
695
696 return lesm;
697 }
698
699 /*
700 +--------------------------------------------------------------------+
701 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
702 | STATE : code ROUTINE : ledit_getSrcM |
703 +--------------------------------------------------------------------+
704
705 PURPOSE :
706 */
707
708 static T_LEDIT_SRC_MAINTAIN *ledit_getSrcM (UBYTE src_id, const UBYTE *chars, USHORT len)
709 {
710 static BOOL firstCall = 1;
711 T_LEDIT_SRC_MAINTAIN *ledSrcM = NULL;
712 T_LEDIT_SRC_MAINTAIN *tmp = NULL;
713
714 /*
715 * get the very first AT source maintenance
716 */
717 if (firstCall)
718 {
719 firstCall = 0;
720 if ((rootSrc = ledit_getNewSrcMaintain (rootSrc)) EQ NULL)
721 {
722 return NULL;
723 }
724 rootSrc->leditInt->src_id = src_id;
725 rootSrc->leditInt->srcBufIterE = 0;
726 rootSrc->leditInt->srcBufIter = 0;
727 rootSrc->leditInt->srcBuffer = chars;
728 rootSrc->leditInt->len = len;
729 return rootSrc;
730 }
731 /*
732 * do we have a maintenance for this src_id ?
733 */
734 ledSrcM = rootSrc;
735 tmp = rootSrc;
736 while(ledSrcM AND ledSrcM->leditInt->src_id NEQ src_id)
737 {
738 tmp = ledSrcM;
739 ledSrcM = ledSrcM->next;
740 }
741 if (ledSrcM EQ NULL)
742 {
743 /*
744 * No, this AT source called line edit for the very first time
745 */
746 if ((ledSrcM = ledit_getNewSrcMaintain (ledSrcM)) EQ NULL)
747 {
748 return NULL;
749 }
750 tmp->next = ledSrcM;
751 }
752
753 ledSrcM->leditInt->src_id = src_id;
754 ledSrcM->leditInt->srcBufIterE = 0;
755 ledSrcM->leditInt->srcBufIter = 0;
756 ledSrcM->leditInt->srcBuffer = chars;
757 ledSrcM->leditInt->len = len;
758 ledSrcM->leditInt->err.msg = NULL;
759 ledSrcM->leditInt->err.code = LEDIT_ERR_NONE;
760
761 return ledSrcM;
762 }
763
764 /*
765 +--------------------------------------------------------------------+
766 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
767 | STATE : code ROUTINE : ledit_getSrc |
768 +--------------------------------------------------------------------+
769
770 PURPOSE : get an existing source maintenance
771 */
772
773 static T_LEDIT_SRC_MAINTAIN *ledit_getSrc (UBYTE src_id)
774 {
775 T_LEDIT_SRC_MAINTAIN *ledSrcM = NULL;
776
777 ledSrcM = rootSrc;
778
779 while(ledSrcM AND ledSrcM->leditInt->src_id NEQ src_id)
780 {
781 ledSrcM = ledSrcM->next;
782 }
783 if (ledSrcM EQ NULL)
784 {
785 return NULL;
786 }
787 return ledSrcM;
788 }
789
790
791 /*
792 +--------------------------------------------------------------------+
793 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
794 | STATE : code ROUTINE : ledit_check_param |
795 +--------------------------------------------------------------------+
796
797 PURPOSE : -
798 */
799
800 static T_LEDIT_RSLT ledit_check_param (const UBYTE *chars, USHORT len)
801 {
802 if (len EQ 0
803 OR chars EQ NULL)
804 {
805 return (LEDIT_FAIL);
806 }
807 if (len > MAX_CMD_LEN)
808 {
809 return (LEDIT_FAIL);
810 }
811 return (LEDIT_CMPL);
812 }
813
814
815 /*
816 +--------------------------------------------------------------------+
817 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
818 | STATE : code ROUTINE : ledit_cmd |
819 +--------------------------------------------------------------------+
820
821 PURPOSE : - receive char, chars or complete AT-string sent by UART, bluetooth, SAT, ...
822 - run the state machine to build up valid AT commands
823 */
824
825 T_LEDIT_RSLT ledit_cmd (UBYTE src_id, const UBYTE *chars, USHORT len)
826 {
827 T_LEDIT_RSLT rv = LEDIT_COLLECT;
828 T_LEDIT_SRC_MAINTAIN *lineSrcM = NULL;
829
830 TRACE_FUNCTION ("ledit_cmd()");
831
832 /*
833 * get the maintenance for this AT source or create a new one or die
834 */
835 if ((lineSrcM = ledit_getSrcM (src_id, chars, len)) EQ NULL)
836 {
837 return (LEDIT_FAIL);
838 }
839 /*
840 * at first check, whether the last cmd line is already processed by ATI
841 * ATI will call then ledit_ctrl(src_id,LEDIT_CTRL_CMPL,NULL)
842 * which reset the state machine
843 */
844 if (lineSrcM->leditInt->state EQ ledit_run_cmd)
845 {
846 /*
847 * ATI did not confirmed the last cmd line
848 */
849 lineSrcM->leditInt->err.code = LEDIT_ERR_LastCmdPending;
850 lineSrcM->leditInt->err.msg = ledit_err[LEDIT_ERR_LastCmdPending].msg;
851 return (LEDIT_FAIL);
852 }
853
854 /*
855 * the caller of ledit_cmd is responsible to echoing the passed chars back
856 * so clear at first the old chars from the last call of ledit_cmd
857 */
858 ledit_echo_clear();
859
860 if (ledit_check_param(chars, len) EQ LEDIT_FAIL)
861 {
862 lineSrcM->leditInt->err.code = LEDIT_ERR_NoValidCommand;
863 lineSrcM->leditInt->err.msg = ledit_err[LEDIT_ERR_NoValidCommand].msg;
864 return (LEDIT_FAIL);
865 }
866 /*
867 * the chars of the raw source cmd line can be parsed now
868 * call state machine and check the return value
869 */
870 while ((lineSrcM->leditInt->srcBufIter < len) AND ((rv EQ LEDIT_COLLECT) OR (rv EQ LEDIT_IGNORE)))
871 {
872 rv = (*lineSrcM->leditInt->state)(lineSrcM->leditInt);
873 if (rv EQ LEDIT_FAIL)
874 {
875 ledit_clear_all(lineSrcM->leditInt);
876 if (lineSrcM->leditInt->lineHabit.atE)
877 {
878 ledit_echo(lineSrcM->leditInt);
879 }
880 return rv;
881 }
882 }
883 /*
884 * the chars [aAtT] have already been put into g_ledit_echoBuf by these states
885 */
886 if ((lineSrcM->leditInt->state NEQ ledit_prefix_a)
887 AND(lineSrcM->leditInt->state NEQ ledit_prefix_t))
888 {
889 /*
890 * but then, put all chars after [tT] into g_ledit_echoBuf
891 */
892 if (lineSrcM->leditInt->lineHabit.atE)
893 {
894 ledit_echo(lineSrcM->leditInt);
895 }
896 }
897 /*
898 * if ready to execute, state machine will call ledit_run_cmd()
899 * or in case of A/ ledit_repeat() first and then ledit_run_cmd()
900 */
901 if (lineSrcM->leditInt->state EQ ledit_repeat)
902 {
903 rv = (*lineSrcM->leditInt->state)(lineSrcM->leditInt);
904 if (rv EQ LEDIT_FAIL)
905 {
906 ledit_clear_all(lineSrcM->leditInt);
907 TRACE_EVENT ("ledit_cmd(): ledit_repeat FAILED");
908 return rv;
909 }
910 }
911
912 if (lineSrcM->leditInt->state EQ ledit_run_cmd)
913 {
914 rv = (*lineSrcM->leditInt->state)(lineSrcM->leditInt);
915 if (rv EQ LEDIT_FAIL)
916 {
917 ledit_clear_all(lineSrcM->leditInt);
918 if (lineSrcM->leditInt->lineHabit.atE)
919 {
920 ledit_echo(lineSrcM->leditInt);
921 }
922 ledit_echo_clear();
923 TRACE_EVENT ("ledit_cmd(): ledit_run_cmd FAILED");
924 return rv;
925 }
926 }
927 TRACE_EVENT_P1 ("ledit_cmd(): returns with %d", rv);
928 return rv;
929 }
930
931 /*
932 +--------------------------------------------------------------------+
933 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
934 | STATE : code ROUTINE : ledit_idle |
935 +--------------------------------------------------------------------+
936
937 PURPOSE : - state 1 of command line parser
938 - start parsing of AT command line with received [aA]
939 - is final state with received '\0'
940 */
941 static T_LEDIT_RSLT ledit_idle (T_LEDIT_INTERN *leditInt)
942 {
943 char c = leditInt->srcBuffer[leditInt->srcBufIter++];
944 #ifdef _SIMULATION_
945 TRACE_FUNCTION ("ledit_idle()");
946 #endif
947 if(c EQ leditInt->lineHabit.S3)
948 {
949 return (LEDIT_OK); /* simple <CR> will emit an OK */
950 }
951
952 switch (c)
953 {
954 case 'a':
955 case 'A':
956 {
957 if (leditInt->lineHabit.atE)
958 {
959 g_ledit_echoBuf[0] = c;
960 }
961 leditInt->state = ledit_prefix_a;
962 return (LEDIT_COLLECT);
963 }
964 default:
965 {
966 TRACE_EVENT_P1("ledit_idle(): ignored character is %d", c);
967 return (LEDIT_IGNORE);
968 }
969 }
970 }
971 /*
972 +--------------------------------------------------------------------+
973 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
974 | STATE : code ROUTINE : ledit_prefix_a |
975 +--------------------------------------------------------------------+
976
977 PURPOSE : - state 2 of command line parser
978
979 */
980
981 static void ledit_prefix_help (T_LEDIT_INTERN *leditInt, char c)
982 {
983 if (leditInt->lineHabit.atE)
984 {
985 if ((g_ledit_echoBuf[0] EQ 'a') OR (g_ledit_echoBuf[0] EQ 'A'))
986 {
987 g_ledit_echoBuf[1] = c;
988 }
989 else
990 {
991 g_ledit_echoBuf[0] = c;
992 }
993 }
994 }
995
996 static T_LEDIT_RSLT ledit_prefix_a (T_LEDIT_INTERN *leditInt)
997 {
998 char c = leditInt->srcBuffer[leditInt->srcBufIter++];
999 #ifdef _SIMULATION_
1000 TRACE_FUNCTION ("ledit_prefix_a()");
1001 #endif
1002 if(c EQ leditInt->lineHabit.S3)
1003 {
1004 return (LEDIT_FAIL); /* A<CR> (or what has been set for S3) makes no sense */
1005 }
1006
1007 switch (c)
1008 {
1009 case SLASH: /* '/' will not be echoed */
1010 {
1011 leditInt->state = ledit_repeat;
1012 return (LEDIT_EXCT);
1013 }
1014 case 't':
1015 case 'T':
1016 {
1017 ledit_prefix_help (leditInt, c);
1018 leditInt->srcBufIterE = leditInt->srcBufIter;
1019 leditInt->state = ledit_prefix_t;
1020 return (LEDIT_COLLECT);
1021 }
1022 default:
1023 {
1024 if(c EQ leditInt->lineHabit.S5) /* backspace */
1025 {
1026 ledit_prefix_help (leditInt, c);
1027 leditInt->state = ledit_idle;
1028 return (LEDIT_COLLECT); /* A<S5> go back */
1029 }
1030 return (LEDIT_IGNORE);
1031 }
1032 }
1033 }
1034 /*
1035 +--------------------------------------------------------------------+
1036 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
1037 | STATE : code ROUTINE : ledit_prefix_t |
1038 +--------------------------------------------------------------------+
1039
1040 PURPOSE : - state 3 of command line parser
1041
1042 */
1043 static T_LEDIT_RSLT ledit_prefix_t (T_LEDIT_INTERN *leditInt)
1044 {
1045 char c = leditInt->srcBuffer[leditInt->srcBufIter++];
1046 #ifdef _SIMULATION_
1047 TRACE_FUNCTION ("ledit_prefix_t()");
1048 #endif
1049 if(c EQ leditInt->lineHabit.S3)
1050 {
1051
1052 if (leditInt->lineHabit.atE)
1053 {
1054 g_ledit_echoBuf[2] = c;
1055 }
1056 return (LEDIT_OK); /* AT<CR> will emit an OK */
1057 }
1058 if(c EQ leditInt->lineHabit.S5) /* backspace */
1059 {
1060 ledit_prefix_help (leditInt, c);
1061 leditInt->state = ledit_prefix_a;
1062 return (LEDIT_COLLECT); /* AT<S5> go back */
1063 }
1064 leditInt->srcBufIter--; /* collect needs the first character after "AT", as well */
1065 leditInt->state = ledit_collect;
1066 return (LEDIT_COLLECT);
1067 }
1068 /*
1069 +--------------------------------------------------------------------+
1070 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
1071 | STATE : code ROUTINE : ledit_collect |
1072 +--------------------------------------------------------------------+
1073
1074 PURPOSE : - state 4 of command line parser
1075
1076 */
1077 static T_LEDIT_RSLT ledit_repeat (T_LEDIT_INTERN *leditInt)
1078 {
1079 TRACE_FUNCTION ("ledit_repeat()");
1080
1081 ++(leditInt->srcBufIter); /* to reach the end of cmd line */
1082
1083 if (leditInt->execBuffer AND leditInt->execBuffer[0]) /* is there anything to repeat? */
1084 {
1085 if (leditInt->lineBuffer) /* discard current "A/" */
1086 {
1087 ACI_MFREE(leditInt->lineBuffer);
1088 leditInt->lineBuffer = NULL;
1089 }
1090
1091 if (leditInt->origBuffer) /* discard current "A/" */
1092 {
1093 ACI_MFREE(leditInt->origBuffer);
1094 leditInt->origBuffer = NULL;
1095 }
1096
1097 ledit_echo_clear ();
1098 leditInt->state = ledit_run_cmd;
1099 return (LEDIT_EXCT);
1100 }
1101 return (LEDIT_FAIL);
1102 }
1103 /*
1104 +--------------------------------------------------------------------+
1105 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
1106 | STATE : code ROUTINE : ledit_collect |
1107 +--------------------------------------------------------------------+
1108
1109 PURPOSE : - state 4 of command line parser
1110
1111 */
1112 static T_LEDIT_RSLT ledit_collect (T_LEDIT_INTERN *leditInt)
1113 {
1114 int i = 0;
1115 char c = leditInt->srcBuffer[leditInt->srcBufIter++];
1116 USHORT len = 0;
1117 #ifdef _SIMULATION_
1118 TRACE_FUNCTION ("ledit_collect()");
1119 #endif
1120 if (leditInt->lineBuffer EQ NULL)
1121 {
1122 ledit_clear_lineBuf(leditInt);
1123 }
1124
1125 while (i < leditInt->len)
1126 {
1127 if (leditInt->copyIter+2 EQ MAX_CMD_LEN) /* some precheck, +2 for "AT" */
1128 {
1129 if (c EQ leditInt->lineHabit.S3)
1130 ;
1131 else if (c EQ leditInt->lineHabit.S5)
1132 ;
1133 else
1134 {
1135 ledit_prefix_help(leditInt, '\a');
1136 return (LEDIT_IGNORE); /* loop on all other commands if we would exceed the string */
1137 }
1138 }
1139
1140 if(c EQ leditInt->lineHabit.S3)
1141 {
1142 leditInt->origBuffer[leditInt->origBufIter] = '\0'; /* terminate cmd string */
1143 leditInt->lineBuffer[leditInt->copyIter] = '\0'; /* terminate cmd string */
1144 if (leditInt->isStr NEQ FALSE)
1145 {
1146 /*
1147 * a string parameter did not end with "
1148 * e.g: at+cpbw=1,"+491721212",145,"D2 Kundenbetreuung <--- missing closing "
1149 */
1150 leditInt->err.code = LEDIT_ERR_NoValidCommand;
1151 leditInt->err.msg = ledit_err[LEDIT_ERR_NoValidCommand].msg;
1152 return (LEDIT_FAIL);
1153 }
1154 /*
1155 * for possibly repeating backup the current cmd line
1156 */
1157 ledit_backup(leditInt);
1158 leditInt->state = ledit_run_cmd;
1159 leditInt->origBufIter = 0;
1160 leditInt->copyIter = 0;
1161 return (LEDIT_EXCT);
1162 }
1163 else if(c EQ leditInt->lineHabit.S4)
1164 {
1165 ; /* ignore LF */
1166 }
1167 else if(c EQ leditInt->lineHabit.S5)
1168 {
1169 len = leditInt->origBufIter;
1170 if ( leditInt->origBuffer[--(len)] EQ '"' ) /* Checks if the character to be deleted is '"' */
1171 {
1172 leditInt->isStr = !(leditInt->isStr); /* Toggles the variable "isStr" when '"" got deleted */
1173 }
1174 if (leditInt->copyIter > 0)
1175 {
1176 --(leditInt->copyIter); /* delete last character in cmd buffer by setting iterator i one step back */
1177 }
1178 if (leditInt->origBufIter > 0)
1179 {
1180 --(leditInt->origBufIter); /* delete last character in cmd buffer by setting iterator i one step back */
1181 }
1182 if (leditInt->copyIter EQ 0) /* reached first character after "AT" */
1183 {
1184 leditInt->state = ledit_prefix_t; /* Fall back into state 't' */
1185 ledit_prefix_help (leditInt, c);
1186 leditInt->origBuffer[leditInt->origBufIter] = '\0'; /* Terminate Command !!! ACI-FIX-12036 AV2 */
1187 leditInt->lineBuffer[leditInt->copyIter] = '\0'; /* Terminate Command !!! ACI-FIX-12036 AV2 */
1188 return (LEDIT_COLLECT); /* AT<S5> go back */
1189 }
1190 }
1191 else
1192 {
1193 switch (c)
1194 {
1195 case WS:
1196 {
1197 if (leditInt->isStr) /* don't modify anything within string e.g.: "BlAh 1234" */
1198 {
1199 leditInt->origBuffer[leditInt->origBufIter++] = c;
1200 leditInt->lineBuffer[leditInt->copyIter++] = c;
1201 break;
1202 }
1203 break; /* just to eat up white space */
1204 }
1205 default:
1206 {
1207 if ((c > 0x20) AND (!(c & 0x80))) /* only printable chars with 7 bits */
1208 {
1209 if (c EQ '"')
1210 {
1211 leditInt->isStr = !(leditInt->isStr);
1212 }
1213 leditInt->origBuffer[leditInt->origBufIter++] = c; /* copy character to cmd buffer */
1214 if (!(leditInt->isStr) AND c >= 'a' AND c <= 'z')
1215 {
1216 c -= 0x20; /* to upper */
1217 }
1218 leditInt->lineBuffer[leditInt->copyIter++] = c; /* copy character to cmd buffer */
1219 }
1220 }
1221 }
1222 }
1223 c = leditInt->srcBuffer[leditInt->srcBufIter++];
1224 ++i;
1225 if (leditInt->srcBufIter > leditInt->len)
1226 {
1227 break;
1228 }
1229 }
1230 leditInt->origBuffer[leditInt->origBufIter] = '\0';
1231 leditInt->lineBuffer[leditInt->copyIter] = '\0'; /* Terminate Command !!! ACI-FIX-12036 AV2 */
1232
1233 return (LEDIT_COLLECT);
1234 }
1235
1236 /*
1237 +--------------------------------------------------------------------+
1238 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
1239 | STATE : code ROUTINE : ledit_run_cmd |
1240 +--------------------------------------------------------------------+
1241
1242 PURPOSE : - state 5 of command line parser
1243
1244 */
1245 static T_LEDIT_RSLT ledit_run_cmd (T_LEDIT_INTERN *leditInt)
1246 {
1247 TRACE_FUNCTION("ledit_run_cmd()");
1248 leditInt->cmdIndex = 1;
1249 leditInt->cmdGetIter = 1;
1250 ledit_free_cmd(leditInt); /* clear all (=previous) commands */
1251 leditInt->cmdm = NULL;
1252 return (ledit_split (leditInt));
1253 }
1254
1255 /*
1256 +--------------------------------------------------------------------+
1257 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
1258 | STATE : code ROUTINE : ledit_clear_cmdBuf |
1259 +--------------------------------------------------------------------+
1260
1261 PURPOSE : -
1262 */
1263 static T_LEDIT_RSLT ledit_clear_lineBuf (T_LEDIT_INTERN *leditInt)
1264 {
1265 if (leditInt->lineBuffer EQ NULL)
1266 {
1267 ACI_MALLOC(leditInt->lineBuffer,((MAX_CMD_LEN+1) * sizeof (char)));
1268 }
1269 if (leditInt->lineBuffer EQ NULL)
1270 return (LEDIT_FAIL);
1271
1272 memset(leditInt->lineBuffer, '\0',(MAX_CMD_LEN+1) * sizeof (char));
1273 if (leditInt->origBuffer EQ NULL)
1274 {
1275 ACI_MALLOC(leditInt->origBuffer,((MAX_CMD_LEN+1) * sizeof (char)));
1276 }
1277 if (leditInt->origBuffer EQ NULL)
1278 return (LEDIT_FAIL);
1279
1280 memset(leditInt->origBuffer, '\0',(MAX_CMD_LEN+1) * sizeof (char));
1281 return (LEDIT_CMPL);
1282 }
1283
1284 /*
1285 +--------------------------------------------------------------------+
1286 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
1287 | STATE : code ROUTINE : ledit_clear_all |
1288 +--------------------------------------------------------------------+
1289
1290 PURPOSE : -
1291 */
1292 static T_LEDIT_RSLT ledit_clear_all (T_LEDIT_INTERN *leditInt)
1293 {
1294 ledit_free_cmd(leditInt); /* maintained by ledit_split */
1295 leditInt->cmdm = NULL;
1296
1297 if (leditInt->smsBuffer)
1298 {
1299 ACI_MFREE (leditInt->smsBuffer);
1300 leditInt->smsBuffer = NULL;
1301 }
1302
1303 if (leditInt->lineBuffer)
1304 {
1305 ACI_MFREE (leditInt->lineBuffer);
1306 leditInt->lineBuffer = NULL;
1307 }
1308 if (leditInt->origBuffer)
1309 {
1310 ACI_MFREE (leditInt->origBuffer);
1311 leditInt->origBuffer = NULL;
1312 }
1313
1314 leditInt->txtChunk = 0;
1315 leditInt->copyIter = 0;
1316 leditInt->origBufIter = 0;
1317 leditInt->lineBufIter = 0;
1318 leditInt->execBufIter = 0;
1319 leditInt->srcBufIter = 0;
1320 leditInt->cmdGetIter = 0;
1321 leditInt->cmdIndex = 0;
1322 leditInt->isStr = FALSE;
1323 leditInt->state = ledit_idle; /* reset to default state */
1324 return (LEDIT_CMPL);
1325 }
1326
1327
1328 /*
1329 +--------------------------------------------------------------------+
1330 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
1331 | STATE : code ROUTINE : ledit_trace_line |
1332 +--------------------------------------------------------------------+
1333
1334 PURPOSE : prepare a text buffer for tracing of an AT cmd line.
1335 a cmd line is ready for tracing after receiving of the termination
1336 character<S3> and removing of all non necessary characters,
1337 e.g.: white spaces and the the characters in the mAlberTO phenomenon
1338 " m a lb er t o<S3>" is interpreted as ATO !
1339 the characters can come in as single chars, chunk of chars or as complete line.
1340 the actual trace takes place with trace_cmd_line()
1341
1342 */
1343
1344 T_LEDIT_RSLT ledit_trace_line (UBYTE src_id, char *txt)
1345 {
1346 T_LEDIT_SRC_MAINTAIN *lineSrcM = NULL;
1347 /*
1348 * get the maintenance for this AT source
1349 */
1350 if ((lineSrcM = ledit_getSrcM (src_id, NULL, 0)) EQ NULL)
1351 {
1352 return (LEDIT_FAIL);
1353 }
1354
1355 if (lineSrcM->leditInt->execBuffer)
1356 {
1357 strncpy (txt, lineSrcM->leditInt->execBuffer, 77); /* limit to 77 chars, 2 are used for "AT" */
1358 txt[77] = '\0';
1359 return (LEDIT_CMPL);
1360 }
1361 else
1362 {
1363 return (LEDIT_FAIL);
1364 }
1365 }
1366