Chinaunix首页 | 论坛 | 博客
  • 博客访问: 98658
  • 博文数量: 21
  • 博客积分: 1192
  • 博客等级: 少尉
  • 技术积分: 227
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-22 11:00
文章分类

全部博文(21)

文章存档

2014年(1)

2012年(16)

2011年(4)

分类: LINUX

2012-03-07 18:18:36

minicom 2.4版本中,在读取脚本时,每行的最大长度为500字节

  1. 331 /*
  2.   332 * Read a script into memory.
  3.   333 */
  4.   334 static int readscript(const char *s)
  5.   335 {
  6.   336 FILE *fp;
  7.   337 struct line *tl, *prev = NULL;
  8.   338 char *t;
  9.   339 char buf[500]; /* max length of a line - this should be */
  10.   340 int lineno = 0;
  11.   341
  12.   342 if ((fp = fopen(s, "r")) == NULL) {
  13.   343 fprintf(stderr, _("runscript: couldn't open \"%s\"%s\n"), s, "\r");
  14.   344 exit(1);
  15.   345 }
  16.   346
  17.   347 /* Read all the lines into a linked list in memory. */
  18.   348 while ((t = fgets(buf, sizeof(buf), fp)) != NULL) {
  19.   349 lineno++;
  20.   350 if (strlen(t) == sizeof(buf) - 1) {
  21.   351 /* Wow, this is really braindead, once upon a time buf was 81 chars
  22.   352 * big and triggered nice errors for too long input lines, now
  23.   353 * we just enlarge the buffer and add a sanity check. This code
  24.   354 * needs to allocate memory dynamically... */
  25.   355 fprintf(stderr, "Input line %u too long, aborting (and fix me!)!\n",
  26.   356      lineno);
  27.   357 exit(1);
  28.   358 }
  29.   359 skipspace(&t);
  30.   360 if (*t == '\n' || *t == '#')
  31.   361 continue;
  32.   362 if (((tl = (struct line *)malloc(sizeof (struct line))) == NULL) ||
  33.   363 ((tl->line = strsave(t)) == NULL)) {
  34.   364 fprintf(stderr, _("script \"%s\": out of memory%s\n"), s, "\r");
  35.   365 exit(1);
  36.   366 }
  37.   367 if (prev)
  38.   368 prev->next = tl;
  39.   369 else
  40.   370 curenv->lines = tl;
  41.   371 tl->next = NULL;
  42.   372 tl->labelcount = 0;
  43.   373 tl->lineno = lineno;
  44.   374 prev = tl;
  45.   375 }
  46.   376 fclose(fp);
  47.   377 return 0;
  48.   378 }

在写runscript时,使用"\c"来分段发送命令,例如,

由于涉及项目内容,我替换了一些内容


  1. #!/bin/bash
  2. #Firstly,config special configuration for board.

  3. minicom_config="dslr"
  4. minicom_0x30072_script="dslr_0x30072_runscript"
  5. minicom_00bc0003_script="dslr_00bc0003_runscript"
  6. minicom_command_step1="minicom $minicom_config -S $minicom_0x30072_script"
  7. minicom_command_step2="minicom $minicom_config -S $minicom_00bc0003_script"
  8. pkill_command="\"^${minicom_command_step1}$\""
  9. pkill_command_2="\"^${minicom_command_step2}$\""
  10. #echo $pkill_command
  11. cat >$minicom_0x30072_script<< EOF
  12. verbose on
  13. send "command w 0x30072 FE"
  14. send "command s"
  15. send "\n"
  16. sleep 5
  17. print "\n+++exit minicom terminal!!!+++\n"
  18. ! pkill -f $pkill_command
  19. EOF

  20. cat >$minicom_00bc0003_script<< EOF
  21. verbose on
  22. 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"
  23. 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"
  24. 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"
  25. send "command s"
  26. send "\n"
  27. sleep 5
  28. print "\n+++exit minicom terminal!!!+++\n"
  29. ! pkill -f $pkill_command_2
  30. EOF

  31. #echo $minicom_0x30072_script
  32. $minicom_command_step1
  33. sleep 5
  34. $minicom_command_step2
  35. #rm $minicom_script
  36. #

阅读(2437) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~