comparison g23m-aci/aci/line_edit.c @ 0:75a11d740a02

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