Ejemplo n.º 1
0
int YMODEMCLASS::CheckDataBlock0(void)
{
	int   rVal=FT_SUCCESS ;
	char *path ;
	path = new char[256] ;
 	if (Status)
 		{
		lpStatus->writeName = TRUE ;
 		lstrcpy(lpStatus->filename, lpBuffer) ;
 		lpStatus->blocksize +=128 ;
 		lpStatus->blockno++ ;
 		lpStatus->UpdateStatusWindow() ;
    if (lpStatus->transferStop) return FT_LOCALCANCEL ;
		lpStatus->writeName = FALSE ;
 		}
	if (lpBuffer[0]=='\0')
	  {
		CommPutChar (oiConn, ACK) ;
		if(Status)
			DestroyWindow(lpStatus->hStatus) ;
		return(FT_FILEEND);
		}
		
	sprintf (path, "%s\\%s", directory, lpBuffer) ;
	if (!lpBuffer[lstrlen (lpBuffer)+1])
		{
		length = 0L;
     moddate = 0L ;
		}
	else
		{
		sscanf(&lpBuffer[lstrlen(lpBuffer)+1], "%ld %lo", &length, &moddate) ;
		}
	OFSTRUCT of ;
	if (hFile!=HFILE_ERROR)
		{
		CloseHandle (hFile) ;
     hFile = HFILE_ERROR ;
		}
	if (hFile==HFILE_ERROR)
		{
		char *filename = CutFileName (path) ;
		hFile = CreateFile (filename, &of, OF_CREATE) ;
		}
	if (hFile!=HFILE_ERROR)
	  {
		rvDataCount = 0 ;
		setmem(lpBuffer, maxblocksize, ' ') ;
 		CommPutChar (oiConn, ACK) ;
 		bLastSeq = bSeq ;
 		bSeq++ ;
 		dataBlock0 = FALSE ;
		fltr_state = WAIT_SOH ;
		}
	else
		rVal =FT_LOCALCANCEL ;

	return rVal ;	
}
Ejemplo n.º 2
0
void YMODEMCLASS::EndSendBinaryFile (void)
{
	char c = EOT ;

  CommPutChar (oiConn, c) ;
	if (Status)
		DestroyWindow (lpStatus->hStatus) ;
	if (hFile!=HFILE_ERROR)
		CloseHandle (hFile) ;
	hFile = HFILE_ERROR ;

	return ;
}
Ejemplo n.º 3
0
int YMODEMCLASS::EndTransferBinaryFile(void)
{
	struct tm *t ;
	struct ftime ft ;

  CommPutChar (oiConn, ACK) ;
	if (hFile!=HFILE_ERROR)
    {
		if (moddate)
			{
			putenv ("TZ=GMT0GMT") ;
			tzset() ;
			t = localtime(&moddate) ;
			ft.ft_tsec = t->tm_sec /2 ;
			ft.ft_min  = t->tm_min ;
			ft.ft_hour = t->tm_hour ;
			ft.ft_day  = t->tm_mday ;
			ft.ft_month= t->tm_mon +1 ;
			ft.ft_year = t->tm_year-80 ;
   		setftime(hFile, &ft) ;
			}
				
		CloseHandle (hFile) ;
		rvDataCount = 0 ;
		waittimes = 0 ;
		bSeq = bLastSeq =0 ;
		dataBlock0 = TRUE ;
		lErrorCount =0 ;
		if (Status)
			{
			lpStatus->error = 0 ;
			lpStatus->blocksize = 0 ;
			lpStatus->blockno = 0 ;
			lstrcpy(lpStatus->filename, "") ;
			lpStatus->UpdateStatusWindow() ;
			if (lpStatus->transferStop) return FT_LOCALCANCEL ;
    	}
		fltr_state = SEND_INIT ;
		}
	else
  	{
		if(Status)
			DestroyWindow(lpStatus->hStatus) ;
    }
	return FT_SUCCESS;
}
Ejemplo n.º 4
0
int YMODEMCLASS::CheckDataBlock (void)
{
	BYTE hiCRC ,loCRC ;
	int  bCRC ;
	BYTE checksum ;
	BOOL checkOK=TRUE ;
  int  rVal = FT_SUCCESS ; 

	if (fCRC)
		{
		hiCRC = CommGetChar (oiConn) ;
    loCRC = CommGetChar (oiConn) ;
		bCRC = CalcCRC16 (lpBuffer, maxblocksize) ;
		if (hiCRC!=HIBYTE(bCRC)||loCRC!=LOBYTE(bCRC))
			checkOK = FALSE ;				
		}
	else
		{
    checksum = CommGetChar (oiConn) ;
		if(checksum!=CheckSum (lpBuffer))
   		checkOK = FALSE ;
		}

	if (checkOK)
		{
		if (dataBlock0)
			rVal = CheckDataBlock0() ;
    else
			{
			fltr_state = WAIT_SOH ;
			WriteToFile () ;
			}
		}
	else
	 {
	 rvDataCount = 0 ;
	 setmem(lpBuffer, maxblocksize, ' ') ;
   CommPutChar (oiConn, NAK) ;
		fltr_state = WAIT_SOH ;
	 }
  return (rVal) ;
}
Ejemplo n.º 5
0
void task1(void * pdata )
{

    INT8U  ch;
    INT8U  err;
    static INT8U print_out_buf[60] = {0};
    static INT8U scan_buf[90]= {0};
    static UART_AT_STATE_TypeDef g_uart_at_state = UART_AT_STATE_AT;
    //U10开机信号
    static bool flag_start_u10_sig = true;
    flag_start_u10_sig = true;

    GPIO_WriteHigh(GPIOD,GPIO_PIN_2);//高
    OSTimeDlyHMSM(0,0,4,0 );
    GPIO_WriteLow(GPIOD,GPIO_PIN_2);


    //cszdata=cszdata;
    //UART_Print("AT\r\n");

    //UART_Print("AT12345abcdefghijklmnopqrest\r\n");

    //g_uart_at_state = UART_AT_STATE_AT;
    g_uart_at_state = UART_AT_STATE_INIT2_REP;
    //注意!在最高优先级任务循环前打开定时器中断,以满足在OSStart()前不产生中断的要求。
    //在系统调用OSInit()时会自动创建一个优先级最低的系统任务,创建过程中会调用OS_EXIT_CRITICAL()打开EA。
    //若在InitTimer0()里打开T0中断,则违反了在OSStart()前不产生中断的要求。
    //切记将ET0=1;放在最高优先级任务里,OSStart()将调用OSStartHighRdy()第一个运行最高优先级任务,这样ET0=1总能被第一个执行。
    //ET0=1;

    for (;;)
    {
#if 0
        if(flag_start_u10_sig)//只执行一次 //U10开机信号
        {
            GPIO_WriteHigh(GPIOD,GPIO_PIN_2);//高
            flag_start_u10_sig = false;
            OSTimeDlyHMSM(0,0,4,0 );
            //  GPIO_WriteLow(GPIOD,GPIO_PIN_2);
            //  Delay(0x3ffff);
            GPIO_WriteLow(GPIOD,GPIO_PIN_2);
        }
#endif
#if ONE_FRAME_EN
        //INT8U scan_buf[20]={0};

        //printf("task1 \r\n");
        //UART_Print("AT\r\n");
        //OSTimeDlyHMSM(0,0,0,20);
        // CommPutChar('9', OS_TICKS_PER_SEC);
        //      CommPutChar('\r', OS_TICKS_PER_SEC);
        //      CommPutChar('\n', OS_TICKS_PER_SEC);
        UART_Scan(scan_buf);
#if DEBUG_EN
        if(scan_buf[0] != '\0')
        {
            sprintf(print_out_buf,"YOU SEND: %s\r\n",scan_buf);
            UART_Print(print_out_buf);
            memset(scan_buf,0,60);
        }
#endif

#if 0
        if(strstr((char const *)scan_buf, "abcdef"))
        {
            UART_Print("YOU SEND: abcdef\r\n");

        }
#endif
#if 1

        switch(g_uart_at_state)
        {
        case UART_AT_STATE_INIT2_REP:
            if(strstr((char const *)scan_buf, "+INIT: 2"))
            {
                UART_Print("AT\r\n");
                g_uart_at_state = UART_AT_STATE_AT;
            }
            break;
        case UART_AT_STATE_AT:
            if(strstr((char const *)scan_buf, "OK"))
            {
                UART_Print("ATI\r\n");
                g_uart_at_state = UART_AT_STATE_ATI;
            }

            break;
        case UART_AT_STATE_ATI:
            if(strstr((char const *)scan_buf, "OK"))
            {
                UART_Print("AT+CREG?\r\n");
                g_uart_at_state = UART_AT_STATE_OK;
            }

            break;
        case UART_AT_STATE_OK:
            if(strstr((char const *)scan_buf, "+CREG:"))
            {
                UART_Print("AT+qflst=\"*\"\r\n");
                //g_uart_at_state = UART_AT_STATE_AT;
                g_uart_at_state = UART_AT_STATE_INIT2_REP;
            }
            //g_uart_at_state = UART_AT_STATE_AT;

            break;
        default:
            break;

        }
#endif

        //OSTimeDlyHMSM(0,0,0,20);
#else
        ch  = CommGetChar(0, &err);
        if(ch!=NUL)
        {
            CommPutChar(ch, 0);

        }
        OSTimeDly(2);
#endif
    }

#if 0
    while(1)
    {
#if 0
        printf("task1 ");

        if(g_flag__rx_frame_complete)//串口收到消息,字符串
        {
            g_flag__rx_frame_complete=false;
            //pBuf=UART2_GetData(&len);
            Uart_GetStr( (char *)g_uart_rx_content);
            if(strstr((char const *)g_uart_rx_content,"halt") )
            {
                printf("you send the message is :halt \r\n");
                asm("halt\n");
            }
        }

#endif

        OSTimeDlyHMSM(0,0,0,TIME_DELAY );

    }
#endif
}