- 331 /*
-
332 * Read a script into memory.
-
333 */
-
334 static int readscript(const char *s)
-
335 {
-
336 FILE *fp;
-
337 struct line *tl, *prev = NULL;
-
338 char *t;
-
339 char buf[500]; /* max length of a line - this should be */
-
340 int lineno = 0;
-
341
-
342 if ((fp = fopen(s, "r")) == NULL) {
-
343 fprintf(stderr, _("runscript: couldn't open \"%s\"%s\n"), s, "\r");
-
344 exit(1);
-
345 }
-
346
-
347 /* Read all the lines into a linked list in memory. */
-
348 while ((t = fgets(buf, sizeof(buf), fp)) != NULL) {
-
349 lineno++;
-
350 if (strlen(t) == sizeof(buf) - 1) {
-
351 /* Wow, this is really braindead, once upon a time buf was 81 chars
-
352 * big and triggered nice errors for too long input lines, now
-
353 * we just enlarge the buffer and add a sanity check. This code
-
354 * needs to allocate memory dynamically... */
-
355 fprintf(stderr, "Input line %u too long, aborting (and fix me!)!\n",
-
356 lineno);
-
357 exit(1);
-
358 }
-
359 skipspace(&t);
-
360 if (*t == '\n' || *t == '#')
-
361 continue;
-
362 if (((tl = (struct line *)malloc(sizeof (struct line))) == NULL) ||
-
363 ((tl->line = strsave(t)) == NULL)) {
-
364 fprintf(stderr, _("script \"%s\": out of memory%s\n"), s, "\r");
-
365 exit(1);
-
366 }
-
367 if (prev)
-
368 prev->next = tl;
-
369 else
-
370 curenv->lines = tl;
-
371 tl->next = NULL;
-
372 tl->labelcount = 0;
-
373 tl->lineno = lineno;
-
374 prev = tl;
-
375 }
-
376 fclose(fp);
-
377 return 0;
-
378 }
在写runscript时,使用"\c"来分段发送命令,例如,
由于涉及项目内容,我替换了一些内容
- #!/bin/bash
-
#Firstly,config special configuration for board.
-
-
minicom_config="dslr"
-
minicom_0x30072_script="dslr_0x30072_runscript"
-
minicom_00bc0003_script="dslr_00bc0003_runscript"
-
minicom_command_step1="minicom $minicom_config -S $minicom_0x30072_script"
-
minicom_command_step2="minicom $minicom_config -S $minicom_00bc0003_script"
-
pkill_command="\"^${minicom_command_step1}$\""
-
pkill_command_2="\"^${minicom_command_step2}$\""
-
#echo $pkill_command
-
cat >$minicom_0x30072_script<< EOF
-
verbose on
-
send "command w 0x30072 FE"
-
send "command s"
-
send "\n"
-
sleep 5
-
print "\n+++exit minicom terminal!!!+++\n"
-
! pkill -f $pkill_command
-
EOF
-
-
cat >$minicom_00bc0003_script<< EOF
-
verbose on
-
send "command w 00bc0003 80 00 16 00 00 00 00 00 00 00 00 00 00 5A 5a 5a 00 5a 5a 5a 5a 5a 5a 5a 01 5a 5a 5a 5a 5a 5a 5a 00 01 02 03 04 05 06 07 08 09 0A 0B 5a 5a 64 64 0F 0F 1E 32 0F 64 96 05 B4 00 00 10 5a 5a 01 0A 00 5a 5a 5a 5a 5a 5a 5a 06 06 06 06 06 06 06 06 06 5a 5a 42 3C 24 12 09\c"
-
send "04 04 5A 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 00 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a\c"
-
send "5A 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a"
-
send "command s"
-
send "\n"
-
sleep 5
-
print "\n+++exit minicom terminal!!!+++\n"
-
! pkill -f $pkill_command_2
-
EOF
-
-
#echo $minicom_0x30072_script
-
$minicom_command_step1
-
sleep 5
-
$minicom_command_step2
-
#rm $minicom_script
-
#