From a44a42b67d2a6d428ed451025c2052fce2a1fc6e Mon Sep 17 00:00:00 2001 From: forth32 Date: Thu, 2 Apr 2015 08:27:05 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?HDLC-=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- balong_flash.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/balong_flash.c b/balong_flash.c index e9d8b00..149c4cc 100644 --- a/balong_flash.c +++ b/balong_flash.c @@ -31,7 +31,10 @@ unsigned char devname[50]="/dev/ttyUSB0"; unsigned char replybuf[4096]; unsigned char datamodecmd[]="AT^DATAMODE"; unsigned char resetcmd[]="AT^RESET"; + unsigned char OKrsp[]={0x0d, 0x0a, 0x4f, 0x4b, 0x0d, 0x0a}; +unsigned char NAKrsp[]={0x03, 0x00, 0x02, 0xba, 0x0a, 0x7e}; + unsigned int dpattern=0xa55aaa55; unsigned int mflag=0,eflag=0,rflag=0; unsigned char filename [100]; @@ -196,13 +199,24 @@ send_cmd(cmddone,1,replybuf); // Входим в HDLC-режим printf("\n Входим в режим HDLC..."); port_timeout(100); +i=0; + +rehdlc: +if (i == 10) { + printf("превышено число попыток входа в режим\n"); + return; +} + write(siofd,datamodecmd,strlen(datamodecmd)); res=read(siofd,replybuf,6); if (res != 6) { - printf("\n Неправильный ответ на DATAMODE\n"); + printf("\n Неправильная длина ответ на DATAMODE\n"); dump(replybuf,res,0); return; } +i++; +if (memcmp(replybuf,NAKrsp,6) == 0) goto rehdlc; + if (memcmp(replybuf,OKrsp,6) != 0) { printf("\n Неправильный ответ на DATAMODE\n"); dump(replybuf,res,0);