[Ttssh2-commit] [3820] YMODEM: ファイル受信処理のリファクタリング

svnno****@sourc***** svnno****@sourc*****
2010年 3月 24日 (水) 14:32:01 JST


Revision: 3820
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=3820
Author:   yutakapon
Date:     2010-03-24 14:32:01 +0900 (Wed, 24 Mar 2010)

Log Message:
-----------
YMODEM: ファイル受信処理のリファクタリング
*複数ファイルの受信は未サポート

Modified Paths:
--------------
    trunk/teraterm/teraterm/filesys.cpp
    trunk/teraterm/ttpfile/ymodem.c


-------------- next part --------------
Modified: trunk/teraterm/teraterm/filesys.cpp
===================================================================
--- trunk/teraterm/teraterm/filesys.cpp	2010-03-24 04:28:46 UTC (rev 3819)
+++ trunk/teraterm/teraterm/filesys.cpp	2010-03-24 05:32:01 UTC (rev 3820)
@@ -1313,8 +1313,11 @@
 		else
 		(*SetFileVar)(FileVar);
 	}
-	else /* IdZReceive or IdZAuto */
+	else {/* IdZReceive or IdZAuto */
 		FileVar->OpId = OpYRcv;
+		// ƒtƒ@ƒCƒ‹“]‘—Žž‚̃IƒvƒVƒ‡ƒ“‚Í"Yopt1K"‚ÉŒˆ‚ß‘Å‚¿B
+		Opt = Yopt1K;
+	}
 
 	TalkStatus = IdTalkQuiet;
 

Modified: trunk/teraterm/ttpfile/ymodem.c
===================================================================
--- trunk/teraterm/ttpfile/ymodem.c	2010-03-24 04:28:46 UTC (rev 3819)
+++ trunk/teraterm/ttpfile/ymodem.c	2010-03-24 05:32:01 UTC (rev 3820)
@@ -280,7 +280,7 @@
 		break;
 
 	case IdYReceive:
-#if 0
+#if 0   // for debug
 		strcpy(inistr, "sb teraterm2.ini\r\n");
 //		strcpy(inistr, "sb foo.txt\r\n");
 		YWrite(fv,yv,cv, inistr , strlen(inistr));
@@ -313,6 +313,15 @@
 	}
 }
 
+// YMODEMƒT[ƒo‚©‚çƒtƒ@ƒCƒ‹‚ðŽóM‚·‚éÛAProtoParse()‚©‚çŒÄ‚яo‚³‚ê‚éŠÖ”B
+//
+// +-------+-------+--------+---------+-----+
+// |Header |Block# |1-Block#| Payload | CRC |
+// +-------+-------+--------+---------+-----+
+//    1       1        1      128/1024   2      byte
+//
+// return TRUE: ƒtƒ@ƒCƒ‹ŽóM’†
+//        FALSE: ŽóMŠ®—¹
 BOOL YReadPacket(PFileVar fv, PYVar yv, PComVar cv)
 {
 	BYTE b, d;
@@ -326,68 +335,72 @@
 	while ((c>0) && (! GetPkt))
 	{
 		switch (yv->PktReadMode) {
-	  case XpktSOH:
-		  if (b==SOH)
-		  {
-			  yv->PktIn[0] = b;
-			  yv->PktReadMode = XpktBLK;
-			  if (yv->YOpt==Xopt1K)
-				  YSetOpt(fv,yv,XoptCRC);
-			  yv->DataLen = 128;
+		  case XpktSOH:
+			  // SOH ‚© STX ‚©‚ŃuƒƒbƒN’·‚ªŒˆ‚Ü‚éB
+			  if (b==SOH)
+			  {
+				  yv->PktIn[0] = b;
+				  yv->PktReadMode = XpktBLK;
+				  yv->DataLen = SOH_DATALEN;
+				  FTSetTimeOut(fv,yv->TOutShort);
+			  }
+			  else if (b==STX)
+			  {
+				  yv->PktIn[0] = b;
+				  yv->PktReadMode = XpktBLK;
+				  yv->DataLen = STX_DATALEN;
+				  FTSetTimeOut(fv,yv->TOutShort);
+			  }
+			  else if (b==EOT)
+			  {
+				  if (fv->FileOpen) {
+					  fv->FileOpen = 0;
+					  _lclose(fv->FileHandle);
+					  fv->FileHandle = -1;
+				  }
+
+				  b = ACK;
+				  fv->Success = TRUE;
+				  YWrite(fv,yv,cv,&b, 1);
+				  return FALSE;
+			  }
+			  else {
+				  /* flush comm buffer */
+				  cv->InBuffCount = 0;
+				  cv->InPtr = 0;
+				  return TRUE;
+			  }
+			  break;
+		  case XpktBLK:
+			  yv->PktIn[1] = b;
+			  yv->PktReadMode = XpktBLK2;
 			  FTSetTimeOut(fv,yv->TOutShort);
-		  }
-		  else if (b==STX)
-		  {
-			  yv->PktIn[0] = b;
-			  yv->PktReadMode = XpktBLK;
-			  YSetOpt(fv,yv,Xopt1K);
-			  yv->DataLen = 1024;
-			  FTSetTimeOut(fv,yv->TOutShort);
-		  }
-		  else if (b==EOT)
-		  {
-			  b = ACK;
-			  fv->Success = TRUE;
-			  YWrite(fv,yv,cv,&b, 1);
-			  return FALSE;
-		  }
-		  else {
-			  /* flush comm buffer */
-			  cv->InBuffCount = 0;
-			  cv->InPtr = 0;
-			  return TRUE;
-		  }
-		  break;
-	  case XpktBLK:
-		  yv->PktIn[1] = b;
-		  yv->PktReadMode = XpktBLK2;
-		  FTSetTimeOut(fv,yv->TOutShort);
-		  break;
-	  case XpktBLK2:
-		  yv->PktIn[2] = b;
-		  if ((b ^ yv->PktIn[1]) == 0xff)
-		  {
-			  yv->PktBufPtr = 3;
-			  yv->PktBufCount = yv->DataLen + yv->CheckLen;
-			  yv->PktReadMode = XpktDATA;
-			  FTSetTimeOut(fv,yv->TOutShort);
-		  }
-		  else
-			  YSendNAK(fv,yv,cv);
-		  break;
-	  case XpktDATA:
-		  yv->PktIn[yv->PktBufPtr] = b;
-		  yv->PktBufPtr++;
-		  yv->PktBufCount--;
-		  GetPkt = yv->PktBufCount==0;
-		  if (GetPkt)
-		  {
-			  FTSetTimeOut(fv,yv->TOutLong);
-			  yv->PktReadMode = XpktSOH;
-		  }
-		  else
-			  FTSetTimeOut(fv,yv->TOutShort);
-		  break;
+			  break;
+		  case XpktBLK2:
+			  yv->PktIn[2] = b;
+			  if ((b ^ yv->PktIn[1]) == 0xff)
+			  {
+				  yv->PktBufPtr = 3;
+				  yv->PktBufCount = yv->DataLen + yv->CheckLen;
+				  yv->PktReadMode = XpktDATA;
+				  FTSetTimeOut(fv,yv->TOutShort);
+			  }
+			  else
+				  YSendNAK(fv,yv,cv);
+			  break;
+		  case XpktDATA:
+			  yv->PktIn[yv->PktBufPtr] = b;
+			  yv->PktBufPtr++;
+			  yv->PktBufCount--;
+			  GetPkt = yv->PktBufCount==0;
+			  if (GetPkt)
+			  {
+				  FTSetTimeOut(fv,yv->TOutLong);
+				  yv->PktReadMode = XpktSOH;
+			  }
+			  else
+				  FTSetTimeOut(fv,yv->TOutShort);
+			  break;
 		}
 
 		if (! GetPkt) c = YRead1Byte(fv,yv,cv,&b);
@@ -450,6 +463,9 @@
 		fv->FileHandle = _lcreat(fv->FullName,0);
 		fv->FileOpen = fv->FileHandle>0;
 
+		fv->DirLen = 0;
+		SetDlgItemText(fv->HWin, IDC_PROTOFNAME, &(fv->FullName[fv->DirLen]));
+
 		return TRUE;
 	}
 



Ttssh2-commit メーリングリストの案内