Exemplo n.º 1
0
void RTC_IRQHandler(void)
{
    if (RTC_GetITStatus(RTC_IT_SEC) != RESET)
    {
    /* Clear the RTC Second interrupt */
    RTC_ClearITPendingBit(RTC_IT_SEC);

    /* Enable time update */

    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    Time_Display();
    }

    if (RTC_GetITStatus(RTC_IT_ALR) != RESET)
    {
    /* Clear the RTC Second interrupt */
    RTC_ClearITPendingBit(RTC_IT_ALR);

    /* Enable time update */

    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();
    printf(" RTC WAKEUP\r\n");
    }
}
Exemplo n.º 2
0
/**
  * @brief  Returns the time entered by user, using demo board keys.
  * @param  None
  * @retval None
  */
void Time_Adjust(void)
{
  /* Display the current time */
  Time_Display();

  /* Change the current time */
  Time_Regulate();
}
Exemplo n.º 3
0
/**************************************************************/
//程 序 名: RCC_Config()
//开 发 者: MingH
//入口参数: 无
//功能说明: 显示当前时间: 时分秒
//**************************************************************/
void Time_Show(void)
{
	/* If 1s has been elapsed */
	if (TimeDisplay == 1)
	{
		/* Display current time */
		Time_Display(RTC_GetCounter());
		TimeDisplay = 0;
	}
}
Exemplo n.º 4
0
/**
  * @file   RTC_IRQHandler
  * @brief  RTC中断处理
  * @param  无
  * @retval 无
  */
void RTC_IRQHandler(void)
{
  static uint8_t Display;
  if (RTC_GetITStatus(RTC_IT_SEC) != RESET)
  {
    /* Clear the RTC Second interrupt */
    RTC_ClearITPendingBit(RTC_IT_SEC);
//	  Display = ~Display;
    LEDXToggle(LED1);		
    Time_Display();
  }
}
Exemplo n.º 5
0
/**
  * @brief  Shows the current time and date on LCD.
  * @param  None
  * @retval None
  */
static void Calendar_Show(void)
{
  /* If 1s has elapsed */
  if (uwTimeDisplay == 1)
  {
    /* Display current time */
    Time_Display();
    
    /* Display current date */
    Date_Display();
    
    uwTimeDisplay = 0;
  }
}
Exemplo n.º 6
0
/*
 * 函数名:Time_Show
 * 描述  :在超级终端中显示当前时间值
 * 输入  :无
 * 输出  :无
 * 调用  :外部调用
 */ 
void Time_Show(struct rtc_time *tm)
{	 
	  /* Infinite loop */
	  while (1)
	  {
	    /* 每过1s */
	    if (TimeDisplay == 1)
	    {
				/* Display current time */
	      Time_Display( RTC_GetCounter(),tm); 		  
	      TimeDisplay = 0;
	    }
	  }
}
Exemplo n.º 7
0
/**
  * @brief  Shows the current time (HH:MM:SS) on the Hyperterminal.
  * @param  None
  * @retval None
  */   
void Time_Show(void)
{
  printf("\n\r");

  /* Infinite loop */
  while (1)
  {
    /* If 1s has been elapsed */
    if (TimeDisplay == 1)
    {
      /* Display current time */
      Time_Display(RTC_GetCounter());
      TimeDisplay = 0;
    }
  }
}
Exemplo n.º 8
0
/**
  * @brief  Shows the current time and date on LCD.
  * @param  None
  * @retval None
  */
void Calendar_Show(void)
{
  while(1)
  {
    /* If 1s has elapsed */
    if (TimeDisplay == 1)
    {
      /* Display current time */
      Time_Display();

      /* Display current date */
      Date_Display();

      TimeDisplay = 0;
    }
  }
}
Exemplo n.º 9
0
Arquivo: rtc.c Projeto: vcheung/STM32
/*
 * 函数名:Time_Show
 * 描述  :在超级终端中显示当前时间值
 * 输入  :无
 * 输出  :无
 * 调用  :主函数调用,调用函数Time_Display(uint32_t TimeVar)
 */   
void Time_Show(void)
{
	printf("\n\r");
	
	/* Infinite loop */
	while (1)
	{
		/* If 1s has paased
		 * 只有TimeDisplay 为1时才在上位机上显示时间,
		 * TimeDisplay是用户自己定义的标示符,在RTC中断
		 * 服务函数中被置1,即1秒被置1一次,也就是1秒才让串口向上位机发一次时间 */
		if (TimeDisplay == 1)
		{
			/* Display current time
			 * 将RTC计数器中的值传给函数 Time_Display */
			Time_Display(RTC_GetCounter());
			TimeDisplay = 0;
		}
	}
}
Exemplo n.º 10
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void) {
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */
  
  /* System Clocks Configuration */
  RCC_Configuration();
  
  /* System Tick Configuration at 1us */
  SysTick_Config(SystemCoreClock / 1000000);
  
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
  
  /* TIM2 Configuration */
  TIM2_Configuration();
  
  /* TIM3 Configuration */
  TIM3_Configuration();
  
  /* TIM6 Configuration (RTC load) */
  TIM6_Configuration();
  
#elif defined USE_EQDAS_SERVER
  
  /* TIM4 Configuration */
  TIM4_Configuration();
  
#endif
  
  /* CLCD Configuration */
  CLCD_Configuration();
  
  /* GLCD Configuration */
  GLCD_Configuration();
  
  /* UART1 Configuration */
  UART_Configuration();
  
  /* RTC configuration by setting the time by Serial USART1 */
  //RTC_SetTimeBySerial();

  /* WIZ820io SPI1 configuration */
  WIZ820io_SPI1_Configuration();
  
  /* W5200 Configuration */
  Set_network();
  
  /* Print WIZ820io configuration */
  printSysCfg();
  
  /* EXTI Configuration */
  EXTI_Configuration();
  
  /* FatFS configuration */
  f_mount(0, &fs);  // mSD
  //f_mount(1, &fs);  // NAND
  
  /* Display Total size of SD card in MB scale */
  SD_TotalSize();
  
  /* Scan all files in mSD card */
  scan_files(path);
  
  /* MAL configuration */
  //Set_System();
  
  /* UMS configuration */
  //Set_USBClock();
  //USB_Interrupts_Config();
  //USB_Init();
  
  /* loop upon completion of USB Enumeration */
  //while (bDeviceState != CONFIGURED);
  
  /* ATFC Algorithm GPIO */
  ATFC_GPIO_Configuration();
  
  /* ATFC Parameter Initialization */
  ATFCAlgorithmParameterSetup();
  
  // For TCP client's connection request delay
  presentTime = my_time;
  
  /* Clear CLCD before branch into main */
  CLCD_Clear();
  
  /* Alarm in 3 second */
  //RTC_SetAlarm(RTC_GetCounter() + 3);
  /* Wait until last write operation on RTC registers has finished */
  //RTC_WaitForLastTask();

  /* Create directory and sub directory in accordance with current date */
  //filePath = CreateDirectoryAccordingly(GetYearAndMergeToInt(), GetMonthAndMergeToInt(), 
                                        //GetDayAndMergeToInt(), RTC_GetCounter() / 3600);
  
  /* Create file in append mode in accordance with current minute */
  //CreateFileAppendModeAccordingly(filePath, (RTC_GetCounter() % 3600) / 60);
  
  // When everything is set, print message
  printf("\r\n\n - System is ready - ");
  
  while (1) {
    
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
    
    if(TimerCount > 1000) { // 0 ~ 999 (1000) = 1 sec
      TimerCount = 0;
      
      /*
      int x, y, z;
      x = mAxisBuf.tmp_data_x_lcd[index];
      y = mAxisBuf.tmp_data_y_lcd[index];
      z = mAxisBuf.tmp_data_z_lcd[index];
    
      char Serial_Buf[37];
      int hour, minute, second, tmsecond;
      hour = THH; minute = TMM; second = TSS; tmsecond = 0;
      sprintf(Serial_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d\r\n", 
                year, month, day, hour, minute, second, tmsecond, x, y, z);
      printf(Serial_Buf);
      */
      
      //my_time++;  // uncomment when tcp connection is needed
      
      /* Process Parameter Text Stream */
      if(PCFlag) {  // EQDAS Client System and ATFC Algorithm Setting
        PCFlag = false;
        
        ProcessParameterStream();
      }
    }
    
    /* Clock generated by TIM3 */
    if(ClientTimerCounter > 10) {  // 0 ~ 999 (1000) = 1 sec
      ClientTimerCounter = 0;
      
      int mAlgorithmContainer;
      
      year = GetYearAndMergeToInt();
      month = GetMonthAndMergeToInt();
      day = GetDayAndMergeToInt();
      hour = THH; minute = TMM; second = TSS; tmsecond = 0;
      
      int mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec;
      mYear = year; mMonth = month; mDay = day;
      mHour = hour; mMin = minute; mSec = second; mTMSec = tmsecond;
      
      x = mAxisBuf.tmp_data_x_lcd[arrIdx];
      y = mAxisBuf.tmp_data_y_lcd[arrIdx];
      z = mAxisBuf.tmp_data_z_lcd[arrIdx];

      if(flag_uart) { // prevent unpleasant impuse
        // Index synchronization
        arrIdx = index; 
        
        // Make a copy from raw collected data to temporary array
        CopyToTmpArray(arrIdx);
          
        // Copy to Temporary GAL array
        CopyToTmpGalArray(arrIdx);
        
        // Calculate GAL and copy to single temporary GAL value
        CalculateGalAndCopyToGal(arrIdx);
        
        // Determine KMA scale
        DetermineKMA(arrIdx);
  
        // Check sign bit and apply to int container
        CheckSignAndToInt(arrIdx); // this function also cuts surplus 1G 
        
        /* Switch menu & waveform display through graphic lcd */
        GLCD_AxisViewWithWaveform(mode, arrIdx, x, y, z);
        
        if(GoATFCFlag) {
          // Apply ATFC Algorithm to Axis x
          ATFCAlgorithm(mAxisBuf.tmp_data_x_lcd[arrIdx]);
        }
      }

      if(EventDetection) {
        GPIO_WriteBit(GPIOE, GPIO_Pin_15, Bit_SET);
        mAlgorithmContainer = x;
      } else {
        GPIO_WriteBit(GPIOE, GPIO_Pin_15, Bit_RESET);
        mAlgorithmContainer = 0; 
      }
      
      // Copy to data buffer to be written through FATFS
      //CopyToFatFsDataBuffer(arrIdx);
      
      /* EQDAQ01, 02 Client Routine ---------------------------------------------*/
      /* E1Flag or E2Flag set when client board successfully connect to server --*/
      /* Refer to wiz820.c line no. 300 for which flag to be set */
      if(E1Flag) {
        char E1_Buf[45];
        sprintf(E1_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d_%+05d\r\n", 
                mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec,
                x, y, z, mAlgorithmContainer);
        // Only when socket is established, allow send data
        if(getSn_SR(SOCK_TWO) == SOCK_ESTABLISHED) {
          /* send selected data */
          CountSendByte = send(SOCK_TWO, (uint8_t*)E1_Buf, strlen(E1_Buf), (bool)false);
        }
      }
      
      if(E2Flag) {
        char E2_Buf[45];
        sprintf(E2_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d\r\n", 
                mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec, x, y, z);
        // Only when socket is established, allow send data
        if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) {
          /* send selected data */
          send(SOCK_ZERO, (uint8_t*)E2_Buf, strlen(E2_Buf), (bool)false);
        }
      }
    }
    
    /* do RTC work on every second */
    if(RTCTIM6Count > 1000) {
      RTCTIM6Count = 0;
      
      if(InitialThirteenSeconds == 12) {
         InitialThirteenSeconds = 0;
         GoATFCFlag = true;
      } else {
        if(!GoATFCFlag) {
           InitialThirteenSeconds++;
        }
      }
      
      /* RTC 1Hz interrupt */
      if(RTCTimeDisplay) { // 1Hz calibrated by RTC
        RTCTimeDisplay = false; 
        
        /* Display current time */
        Time_Display(RTC_GetCounter());
      }
      
      /* RTC Alarm interrupt */
      if(RTCAlarmFlag) {
        RTCAlarmFlag = false;
        
        printf("\r\nRTC Alarm Actviated!");
      } 
    }
    
    /* Save log to file process ------------------------------------------------*/
    /* Save process needs to be run every single cycle due to delay might occur */
    if(GoAppendDataFlag) {  // every 500 sample (equals 5 sec), go save file.
      GoAppendDataFlag = false;
      
      int bytesWritten = 0;
      
      if(EachSecFlag) {
        // it means that DATA1_BUF is full and ready to flush out
        // be sure to empty out DATA1_BUF or will overflow and cause system to halt.
        
        /* Append first data for the duration of 1 second */
        bytesWritten = f_printf(&fsrc, DATA1_BUF);
        printf("\r\n%d of bytesWritten", bytesWritten);
        
        if(FileRecordCompleteFlag) {
          FileRecordCompleteFlag = false;
          printf("\r\nFile Record Complete!");
          /* Close the file */
          f_close(&fsrc);
        }
        
        // Reset DATA1_BUF
        memset(DATA1_BUF, 0, sizeof(DATA1_BUF)); 
      } else {
        /* Append another second of data */
        bytesWritten = f_printf(&fsrc, DATA2_BUF);
        printf("\r\n%d of bytesWritten", bytesWritten);
        
        if(FileRecordCompleteFlag) {
          FileRecordCompleteFlag = false;
          printf("\r\nFile Record Complete!");
          /* Close the file */
          f_close(&fsrc); 
        }
        
        // Reset DATA2_BUF
        memset(DATA2_BUF, 0, sizeof(DATA2_BUF));
      }
    }
    
#endif
    
    if(ParseUSART1) {
      ParseUSART1 = false;
      
      // run some test on SDIO
      //SDIO_TEST();

#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
      
      /* Print WIZ820io configuration */
      printSysCfg();

      printf("\r\n");
      printf("\r\nBKP_DR1 = %d", BKP_ReadBackupRegister(BKP_DR1));
      printf("\r\nBKP_DR2 = %d", BKP_ReadBackupRegister(BKP_DR2));
      printf("\r\nBKP_DR3 = %d", BKP_ReadBackupRegister(BKP_DR3));
      printf("\r\nBKP_DR4 = %d", BKP_ReadBackupRegister(BKP_DR4));
      printf("\r\nBKP_DR5 = %d", BKP_ReadBackupRegister(BKP_DR5));
      printf("\r\nBKP_DR6 = %d", BKP_ReadBackupRegister(BKP_DR6));
      printf("\r\nBKP_DR7 = %d", BKP_ReadBackupRegister(BKP_DR7));
      printf("\r\nBKP_DR8 = %d", BKP_ReadBackupRegister(BKP_DR8));
      printf("\r\nBKP_DR9 = %d", BKP_ReadBackupRegister(BKP_DR9));
      printf("\r\nBKP_DR10 = %d", BKP_ReadBackupRegister(BKP_DR10));
      printf("\r\nBKP_DR11 = %d", BKP_ReadBackupRegister(BKP_DR11));
      printf("\r\nBKP_DR12 = %d", BKP_ReadBackupRegister(BKP_DR12));
      printf("\r\nBKP_DR13 = %d", BKP_ReadBackupRegister(BKP_DR13));
      printf("\r\nBKP_DR14 = %d", BKP_ReadBackupRegister(BKP_DR14));
      printf("\r\nBKP_DR15 = %d", BKP_ReadBackupRegister(BKP_DR15));
      printf("\r\nBKP_DR16 = %d", BKP_ReadBackupRegister(BKP_DR16));
      
#elif (defined) USE_EQDAS_SERVER
      
      char buffer[37];
      sprintf(buffer, "%s_%s_%s_%s_%s\r\n",
                DAQBoardOne[arrIdx].Date,
                DAQBoardOne[arrIdx].Time,
                DAQBoardOne[arrIdx].AxisX,
                DAQBoardOne[arrIdx].AxisY,
                DAQBoardOne[arrIdx].AxisZ);
      printf("\r\nRX_BUF : %s, strlen(RX_BUF) : %d", (char*)RX_BUF, strlen((char*)RX_BUF));
      printf("\r\nstrlen(buffer) = %d\n%s", strlen(buffer), buffer);
      
      /*
      char *original = "-3843,+4095,+2069";
      char target[20];
      strncpy(target, original, strlen(original));
      
      char *one, *two, *three;
      char *AfterToken;
      AfterToken = strtok(target, ",");
      one = AfterToken;
      AfterToken = strtok(NULL, ",");
      two = AfterToken;
      AfterToken = strtok(NULL, ",");
      three = AfterToken;
      AfterToken = strtok(NULL, ",");
      if(AfterToken != NULL) printf("AfterToken is not empty");
      
      printf("\r\none : %s, two : %s, three : %s", one, two, three);*/
      
#endif
    
    }
    
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
    
    /*
    for(i=0; i<100; i++) {
      if(flag_uart) {
      // Make a copy from raw collected data to temporary array
      CopyToTmpArray(i);
        
      // Copy to Temporary GAL array
      CopyToTmpGalArray(i);
      
      // Calculate GAL and copy to single temporary GAL value
      CalculateGalAndCopyToGal(i);
      
      // Determine KMA scale
      DetermineKMA(i);

      // Check sign bit and apply to int container
      CheckSignAndToInt(i); // this function also cuts surplus 1G 
      }
    }
    */
    
// following routine is only necessary when the board works as server
#elif defined USE_EQDAS_SERVER
    
    /* EQ-DAQ-01 Parsing routine ------------------------------------------------- */
    /* Set E1Flag indicate that we have valid connection from EQ-DAQ-01(port 5050) */
    if(E1Flag) {
      E1Flag = false; // clear flag since this routine excutes ceaselessly over time
      
      ProcessTextStream(EQ_ONE, (char*)RX_BUF, E1Order);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag) {        
        // Send directly to PC
        SendToPC(E1Order);
      }
      
      if(E1Order < 99) E1Order++;
      else E1Order = 0;
    }
    
    /* EQ-DAQ-02 Parsing routine ------------------------------------------------- */
    /* Set E2Flag indicate that we have valid connection from EQ-DAQ-02(port 6060) */
    if(E2Flag) {
      E2Flag = false;
      
      ProcessTextStream(EQ_TWO, (char*)RX_BUF, E2Order);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag) {        
        // Send directly to PC
        SendToPC(E2Order);
      }
      
      if(E2Order < 99) E2Order++;
      else E2Order = 0;
    }

#endif

/* Setup TCP Client or Server -----------------------------------------------------*/
/* Please open config.h file to choose a proper board you wish to use */    
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)    

      /* Start TCP Client process */
      ProcessTcpClient(SOCK_ZERO);  // TCP Client
    
      /* Parameter setting Server side with port 5050 in default */
      ATFCTcpServer(SOCK_TWO, EQDAS_Conf_PORT);  // SOCK_TWO because of flag conformity
    
#elif defined USE_EQDAS_SERVER
    
      /* Process server socket with each port */
      ProcessTcpServer(SOCK_ZERO, 5050);  // designated as for EQM-DAQ-01 with port 5050
      ProcessTcpServer(SOCK_ONE, 6060);   // designated as for EQM-DAQ-02 with port 6060
      ProcessTcpServer(SOCK_TWO, 7070);   // designated as for PC-CLIENT  with port 7070
      ProcessTcpServer(SOCK_THREE, 8080); // designated as for PC_DUMP    with port 8080
      
      /*
      ProcessTcpServer(SOCK_FOUR, 9090);   // designated as for TOBEUSED with port 9090
      ProcessTcpServer(SOCK_FIVE, 10010);   // designated as for TOBEUSED with port 10010
      ProcessTcpServer(SOCK_SIX, 10020);    // designated as for TOBEUSED with port 10020
      ProcessTcpServer(SOCK_SEVEN, 10030);  // designated as for TOBEUSED with port 10030
      */
      
#endif
      
  }
}
Exemplo n.º 11
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void) {
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */
  
  /* System Clocks Configuration */
  RCC_Configuration();
  
  /* System Tick Configuration at 1us */
  SysTick_Config(SystemCoreClock / 1000000);
  
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
  
  /* TIM2 Configuration (Client & ATFC Server) */
  TIM2_Configuration();
  
#elif defined USE_EQDAS_SERVER
  
  /* TIM4 Configuration */
  TIM4_Configuration();
  
#endif
  
  /* TIM5 Configuration (GLCD & Ethernet) */
  TIM5_Configuration();
  
  /* TIM6 Configuration (RTC load) */
  //TIM6_Configuration();
  
  /* CLCD Configuration */
  CLCD_Configuration();
  
  /* GLCD Configuration */
  GLCD_Configuration();
  
  /* UART1 Configuration */
  UART_Configuration();
  
  /* RTC configuration by setting the time by Serial USART1 */
  RTC_SetTimeBySerial();
  
  /* Let user set the IP through terminal forcefully */
  //ForceIPSetBySerial();

  /* WIZ820io SPI1 configuration */
  WIZ820io_SPI1_Configuration();
  
  /* W5200 Configuration */
  Set_network();
  
  /* Print WIZ820io configuration */
  printSysCfg();
  
  /* EXTI Configuration */
  EXTI_Configuration();
  
  /* FatFS configuration */
  f_mount(0, &fs);  // mSD
  //f_mount(1, &fs);  // NAND
  
  /* Display Total size of SD card in MB scale */
  SD_TotalSize();
  
  /* Scan all files in mSD card */
  //scan_files(path);
  
  /* MAL configuration */
  //Set_System();
  
  /* UMS configuration */
  //Set_USBClock();
  //USB_Interrupts_Config();
  //USB_Init();
  
  /* loop upon completion of USB Enumeration */
  //while (bDeviceState != CONFIGURED);
  
  /* ATFC Algorithm GPIO */
  ATFC_GPIO_Configuration();
  
  /* ATFC Parameter Initialization */
  ATFCAlgorithmParameterSetup();
  
  /* GPS-UART3 Configuration - This have to be here otherwise it wouldn't work */
  GPS_Configuration();
  
  // For TCP client's connection request delay
  presentTime = my_time;

  /* Create directory and sub directory in accordance with current date */
  filePath = CreateDirectoryAccordingly(GetYearAndMergeToInt(), GetMonthAndMergeToInt(), 
                                        GetDayAndMergeToInt(), RTC_GetCounter() / 3600);
  
  /* Create file in append mode in accordance with current minute */
  CreateFileAppendModeAccordingly(filePath, (RTC_GetCounter() % 3600) / 60);
  
  /* Clear GLCD to better represent waveform */
  GLCD_Clear();
  
  //BKP_WriteBackupRegister(BKP_DR8, 0);
  
  // When everything is set, print message
  printf("\r\n\n - System is ready - ");
  
  while (1) {
    
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
    
    /* Index synchronization routine -----------------------------------------------*/
    if(SyncFlag) { // prevent unpleasant impuse from happening
      // Index synchronization dedicated to GLCD & Ethernet
      if(arrIdx != index) {
        // Index synchronization
        arrIdx = index;
      }
    }
    /* End of index synchronization routine -----------------------------------------*/
    
    if(TimerCount > 999) { // 0 ~ 999 (1000) = 1 sec
      TimerCount = 0;
      
      //my_time++;  // uncomment when tcp connection is needed
      
      /* Setup TCP Client or Server -------------------------------------------------*/
      /* Please open config.h file to choose a proper board you wish to use ---------*/    
      /* Start TCP Client process */
      ProcessTcpClient(SOCK_ZERO);  // TCP Client
      
      /* Parameter setting Server side with port 5050 in default */
      ATFCTcpServer(SOCK_TWO, EQDAS_Conf_PORT);  // SOCK_TWO because of flag conformity
      /*------------------------------------------------------------------------------*/
      
      /* Process Parameter Text Stream -----------------------------------------------*/
      if(PCFlag) {  // EQDAS Client System and ATFC Algorithm Setting
        PCFlag = false;
        
        ProcessParameterStream();
      }
      /* End of Parameter process ----------------------------------------------------*/
    }

    /* 10ms interval between points */
    if(TIM5Count >= 9) {
      TIM5Count = 0;
      
      // Make a copy from raw collected data to temporary array
      CopyToTmpArray(arrIdx);
      
      // Determine KMA scale
      KMAGrade = DetermineKMA(arrIdx);
      
      // Check sign bit and apply to int container
      CheckSignAndToInt(arrIdx); // this function also cuts surplus 1G
      
      /* Switch menu & waveform display through graphic lcd */
      GLCD_AxisViewWithWaveform(mode, arrIdx);
      
      //int mATFCBit;
      //mATFCBit_lcd = mAxisBuf.ATFCBit_lcd[arrIdx];
      
      int AxisDataToATFCAlgorithm, mATFCEventDetection;
      AxisDataToATFCAlgorithm = mAxisBuf.tmp_data_y_lcd[arrIdx];  // Axis Z
      ATFCAlgorithm(AxisDataToATFCAlgorithm);
      mATFCEventDetection = EventDetection;
      
      /* Display KMA Intensity on Graphic LCD */
      GLCD_DisplayKMAIntensity(KMAGrade, mATFCEventDetection);
      
      /* Prevent access to volatile variable warning */
      /* This have to be here in order to correct data to be used in ATFC */      
      /* ATFC Server side for each EQ DAS Client */
      if(EQATFCFlag) {
        int mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec;
        mYear = year; mMonth = month; mDay = day;
        mHour = hour; mMin = minute; mSec = second; mTMSec = arrIdx;
        
        int mX, mY, mZ, mATFCBit;
        mX = mAxisBuf.tmp_data_x_lcd[arrIdx] >> 2;
        mY = mAxisBuf.tmp_data_y_lcd[arrIdx] >> 2;
        mZ = mAxisBuf.tmp_data_z_lcd[arrIdx] >> 2;
        mATFCBit = mATFCEventDetection;
        
        char ATFC_Buf[40];
        sprintf(ATFC_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d_%d\r\n",
                mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec,
                mX, mY, mZ, mATFCBit);
        // Only when socket is established, allow send data
        if(getSn_SR(SOCK_TWO) == SOCK_ESTABLISHED) {  // SOCK_TWO : PC
          /* send selected data */
          send(SOCK_TWO, (uint8_t*)ATFC_Buf, strlen(ATFC_Buf), (bool)false);
        }
      }
      // Copy to data buffer to be written through FATFS
      //CopyToFatFsDataBuffer(arrIdx);
    }
    
    /* RTC 1Hz interrupt */
    if(RTCTimeDisplay) { // 1Hz calibrated by RTC
      RTCTimeDisplay = false;
      
      int TimeVar;
      TimeVar = RTC_GetCounter();
      /* Compute hour */
      THH = TimeVar / 3600;
      /* Compute minute */
      TMM = (TimeVar % 3600) / 60;
      /* Compute second */
      TSS = (TimeVar % 3600) % 60;
      
      /* Refresh date on every 1s */
      year = GetYearAndMergeToInt();
      month = GetMonthAndMergeToInt();
      day = GetDayAndMergeToInt();
      hour = THH; minute = TMM; second = TSS; tmsecond = 0;
      
      if(ThirtyMinuteMark == 1799) {
        ThirtyMinuteMark = 0;
        ThirtyMinuteFlag = true;
      } else {
        ThirtyMinuteMark++; 
      }
      
      /* Adjust realtime clock deviation */
      if(hour > 23) {
        int i, currentDay, mDay, mHour, mMin, mSec;
        mDay = hour / 24;
        
        for(i=0; i<mDay; i++) {
          IncreaseSingleDay();
          if(i == mDay - 1) {
            currentDay = (GetMonthAndMergeToInt() * 100) + GetDayAndMergeToInt();
            BKP_WriteBackupRegister(BKP_DR3, currentDay); // Save Month and Date
          }
        }
        mHour = THH % 24;
        mMin = TMM;
        mSec = TSS;
        
        /* Change the current time */
        RTC_SetCounter(mHour*3600 + mMin*60 + mSec);
      }
    }
    
#endif
    
    if(ParseGPS) {
      ParseGPS = false;
      
      char *srcstr = "$GPRMC";
      char *token = ",";  char *processedString;
      char StringYear[3], StringMonth[3], StringDay[3], StringHour[3], StringMinute[3], StringSecond[3];
      int GPSYear, GPSMonth, GPSDay, GPSHour, GPSMinute, GPSSecond;
      if(strncmp((char const*)GPS_Buffer, srcstr, 6) == 0) {
        //printf("GPS_Buffer = %s\r\n\r\n", (char*)GPS_Buffer);
        processedString = strtok((char*)GPS_Buffer, token);
        processedString = strtok(NULL, token);
        
        strncpy(StringHour, processedString, 2); StringHour[2] = 0;
        strncpy(StringMinute, processedString+2, 2); StringMinute[2] = 0;
        strncpy(StringSecond, processedString+4, 2); StringSecond[2] = 0;
        
        GPSHour = atoi(StringHour) + 9; // Current Hour = StringHour + 9
        GPSMinute = atoi(StringMinute);
        GPSSecond = atoi(StringSecond);
        
        int i; for(i=4; i!=0 ; i--) processedString = strtok(NULL, token);
        
        strncpy(StringYear, processedString+4, 2); StringYear[2] = 0;
        strncpy(StringMonth, processedString+2, 2); StringMonth[2] = 0;
        strncpy(StringDay, processedString, 2); StringDay[2] = 0;
        
        GPSYear = atoi(StringYear) + 2000;  // Currnet Year = StringYear + 2000
        GPSMonth = atoi(StringMonth);
        GPSDay = atoi(StringDay);
        
        /* The Year is chosen as criteria to the time */
        if( (GPSYear == GetYearAndMergeToInt()) && ThirtyMinuteFlag ) { // only when year matches between RTC and GPS
          ThirtyMinuteFlag = false;
          
          if(GPSMonth != GetMonthAndMergeToInt() || GPSDay != GetDayAndMergeToInt() ||
             GPSHour != THH || GPSMinute != TMM || GPSSecond != TSS) {
            /* Change the month and day */
            TranslateIntoMonth(GPSMonth);
            TranslateIntoDay(GPSDay);
            
            /* Save year data to unresettable backup register addr. no. 3 */
            int MMDD; MMDD = (GPSMonth * 100) + GPSDay;
            BKP_WriteBackupRegister(BKP_DR3, MMDD); // Save Month and Date  
            
            /* Change the current time */
            RTC_SetCounter(GPSHour*3600 + GPSMinute*60 + GPSSecond);
            
            printf("GPSHour = %d\r\n", GPSHour);
            printf("GPSMinute = %d\r\n", GPSMinute);
            printf("GPSSecond = %d\r\n\r\n", GPSSecond);
            
            printf("GPSYear = %d\r\n", GPSYear);
            printf("GPSMonth = %d\r\n", GPSMonth);
            printf("GPSDay = %d\r\n\r\n", GPSDay);
            
            printf("GPS-to-System synchronization complete!\r\n\r\n");
          }
        }
      }
    }
    
    if(ParseUSART1) {
      ParseUSART1 = false;
      
      // run some test on SDIO
      //SDIO_TEST();

#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
      
      /* Print WIZ820io configuration */
      printSysCfg();

      printf("\r\n");
      printf("BKP_DR1 = %d\r\n", BKP_ReadBackupRegister(BKP_DR1));
      printf("BKP_DR2 = %d\r\n", BKP_ReadBackupRegister(BKP_DR2));
      printf("BKP_DR3 = %d\r\n", BKP_ReadBackupRegister(BKP_DR3));
      printf("BKP_DR4 = %d\r\n", BKP_ReadBackupRegister(BKP_DR4));
      printf("BKP_DR5 = %d\r\n", BKP_ReadBackupRegister(BKP_DR5));
      printf("BKP_DR6 = %d\r\n", BKP_ReadBackupRegister(BKP_DR6));
      printf("BKP_DR7 = %d\r\n", BKP_ReadBackupRegister(BKP_DR7));
      printf("BKP_DR8 = %d\r\n", BKP_ReadBackupRegister(BKP_DR8));
      printf("BKP_DR9 = %d\r\n", BKP_ReadBackupRegister(BKP_DR9));
      printf("BKP_DR10 = %d\r\n", BKP_ReadBackupRegister(BKP_DR10));
      printf("BKP_DR11 = %d\r\n", BKP_ReadBackupRegister(BKP_DR11));
      printf("BKP_DR12 = %d\r\n", BKP_ReadBackupRegister(BKP_DR12));
      printf("BKP_DR13 = %d\r\n", BKP_ReadBackupRegister(BKP_DR13));
      printf("BKP_DR14 = %d\r\n", BKP_ReadBackupRegister(BKP_DR14));
      printf("BKP_DR15 = %d\r\n", BKP_ReadBackupRegister(BKP_DR15));
      printf("BKP_DR16 = %d\r\n\r\n", BKP_ReadBackupRegister(BKP_DR16));
      
      printf("RX_BUF = %s\r\n", RX_BUF);
      
      /*
      printf("\r\nstrlen(HEADER) : %d %s", strlen(HEADER), HEADER);
      
      printf("\r\nf_mkdir1 : ");
      char *dirPath = "0:/20130517";
      res = f_mkdir(dirPath);
      FPrintFatResult(res);
      
      printf("\r\nf_mkdir2 : ");
      dirPath = "0:/20130517/22H-23H";
      res = f_mkdir(dirPath);
      FPrintFatResult(res);
      
      char *filePath = "0:/20130517/2-23H/test.txt";
      // Create log file on the drive 0
      res = open_append(&fsrc, filePath);
      FPrintFatResult(res);
      
      if(res == FR_OK) {
        printf("test.txt successfully created\r\n");
        
        // Write buffer to file
        int bytesWritten;
        bytesWritten = f_printf(&fsrc, HEADER);
        printf("\r\n%d of bytesWritten", bytesWritten);
        
        // Close file
        f_close(&fsrc);
        
      } else if ( res == FR_EXIST ) {
        printf("\r\ntest.txt already exist");
      }
      */
      
      
#elif (defined) USE_EQDAS_SERVER
      
      char buffer[40];
      sprintf(buffer, "%s_%s_%s_%s_%s\r\n",
                DAQBoardOne[arrIdx].Date,
                DAQBoardOne[arrIdx].Time,
                DAQBoardOne[arrIdx].AxisX,
                DAQBoardOne[arrIdx].AxisY,
                DAQBoardOne[arrIdx].AxisZ);
      printf("\r\nRX_BUF : %s, strlen(RX_BUF) : %d", (char*)RX_BUF, strlen((char*)RX_BUF));
      printf("\r\nstrlen(buffer) = %d\n%s", strlen(buffer), buffer);
      
#endif
    
    }
    
// following routine is only necessary when the board works as server
#if defined USE_EQDAS_SERVER
    
    /* Server also needs to have get CLCD going while running */
    /* RTC 1Hz interrupt */
    if(RTCTimeDisplay) { // 1Hz calibrated by RTC
      RTCTimeDisplay = false;
      
      /* Adjust realtime clock deviation */
      if(hour > 23) {
        int i, currentDay, mDay, mHour, mMin, mSec;
        mDay = hour / 24;
        
        for(i=0; i<mDay; i++) {
          IncreaseSingleDay();
          if(i == mDay - 1) {
            currentDay = (GetMonthAndMergeToInt() * 100) + GetDayAndMergeToInt();
            BKP_WriteBackupRegister(BKP_DR3, currentDay); // Save Month and Date
          }
        }
        
        mHour = THH % 24;
        mMin = TMM;
        mSec = TSS;
        
        /* Change the current time */
        RTC_SetCounter(mHour*3600 + mMin*60 + mSec);
      }
      
      /* Display current time */
      Time_Display(RTC_GetCounter());
    }
    
    /* EQ-DAQ-01 Parsing routine ------------------------------------------------- */
    /* Set E1Flag indicate that we have valid connection from EQ-DAQ-01(port 5050) */
    if(E1Flag) {
      E1Flag = false; // clear flag since this routine excutes ceaselessly over time
      
      ProcessTextStream(EQ_ONE, (char*)RX_BUF, E1Order);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag && !E2Flag) { // only when PC is connected and EQ-DAQ-02 is not connected
        // Send directly to PC
        SingleBoardDataToSendToPC(EQ_ONE, E1Order-10);
      }
      
      if(E1Order < 99) E1Order++;
      else E1Order = 0;
    }
    
    /* EQ-DAQ-02 Parsing routine ------------------------------------------------- */
    /* Set E2Flag indicate that we have valid connection from EQ-DAQ-02(port 6060) */
    if(E2Flag) {
      E2Flag = false;
      
      ProcessTextStream(EQ_TWO, (char*)RX_BUF, E2Order);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag && !E1Flag) { // only when PC is connected and EQ-DAQ-01 is not connected
        // Send directly to PC
        //SendToPC(EQ_TWO, E2Order);
      }
      
      if(E2Order < 99) E2Order++;
      else E2Order = 0;
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag) {
        // Send directly to PC
        MultipleBoardDataToSendToPC(EQ_BOTH, E1Order-10, E2Order-10);
      }
    }
    
    /* Process server socket with each port */
    ProcessTcpServer(SOCK_ZERO, 5050);  // designated as for EQM-DAQ-01 with port 5050
    ProcessTcpServer(SOCK_ONE, 6060);   // designated as for EQM-DAQ-02 with port 6060
    ProcessTcpServer(SOCK_TWO, 7070);   // designated as for PC-CLIENT  with port 7070
    ProcessTcpServer(SOCK_THREE, 8080); // designated as for PC_DUMP    with port 8080
    
    /*
    ProcessTcpServer(SOCK_FOUR, 9090);   // designated as for TOBEUSED with port 9090
    ProcessTcpServer(SOCK_FIVE, 10010);   // designated as for TOBEUSED with port 10010
    ProcessTcpServer(SOCK_SIX, 10020);    // designated as for TOBEUSED with port 10020
    ProcessTcpServer(SOCK_SEVEN, 10030);  // designated as for TOBEUSED with port 10030
    */
      
#endif
      
  }
Exemplo n.º 12
0
/* 充放电结束后放置一小时 */
int delay_hour(void)
{

	FRESULT result;
	FATFS fs;
	FIL file;
	DIR DirInf;  
	uint32_t bw;


	char time_buf[TIME_MAX];
	char write_buf[WR_MAX];
	char tmp_buf[8];

	int sec = 0;
	int i = 0;
	int min_count = 0;
	double vol;


	result = f_mount(0, &fs);		
	if (result != FR_OK){
		printf("FileSystem Mounted Failed (%d)\r\n", result);
		goto ERROR;
	}

	result = f_opendir(&DirInf, "/");
	if (result != FR_OK){ 
		printf("Open Root Directory Error (%d)\r\n", result);
		goto ERROR;
	}
	
	result = f_open(&file, conf->file_name, FA_OPEN_ALWAYS | FA_READ | FA_WRITE);	
	if(result !=FR_OK){
		printf("open error, errornu:%d\n\r",result);
	 	goto ERROR;
	}

	if(f_lseek(&file,file.fsize) != FR_OK){
		printf("f_lseek error, errornu:%d\n\r",result);
		goto ERROR;
	}

	
	beeper_on();
	delay_ms(200);
	beeper_off();

	memset(time_buf,0,TIME_MAX);
	memset(write_buf,0,WR_MAX);

	printf("\n\r静置开始");
	Time_Display(RTC_GetCounter());
	printf("\n\r");

	bsp_LedOn(4);

	StartTimer(0,  1000);
//	Time_Display(RTC_GetCounter());
			
	do{
		if(jump)
			goto JMP;	
		
		if(CheckTimer(0) ) {	
			StartTimer(0,  1000);
			sec++;
			min_count ++;

			vol = ADC_SAMPLING();

			if(min_count >= 60){
				min_count = 0;

				record_time(time_buf);
				strcat(time_buf,",");						
	
	
				strcat(write_buf, time_buf);
				memset(time_buf,0,TIME_MAX);		
	
								
				sprintf(tmp_buf, "%.2f", vol);								      
				strcat(write_buf, tmp_buf);
				strcat(write_buf,",静置\n");
	
				if(i >= 9){
					result = f_write(&file,write_buf,sizeof(write_buf),&bw);			
					if(result != FR_OK){
						printf("file write faild, errornu:%d\n\r",result);
						goto ERROR;
					}
					
					memset(write_buf,0,WR_MAX);
					i = 0;
				}
	
				i++;
			}
		}	

	}while(sec < 3600);  /* 静置时间(单位:秒) */

JMP:
	jump = 0;
	if(i != 0){

		result = f_write(&file,write_buf,(15 + TIME_MAX)*i, &bw);			
		if(result != FR_OK){
			printf("file write faild, errornu:%d\n\r",result);
			goto ERROR;
			
		}
		i = 0;
	}
	memset(write_buf,0,WR_MAX);


	printf("静置结束");
	Time_Display(RTC_GetCounter());
	printf("\n\r");

	bsp_LedOff(4);

	f_close(&file);
	f_mount(0, NULL);
	return 0;
	

ERROR:
	bsp_LedOff(4);
	f_close(&file);
	f_mount(0, NULL);
	return 1;
}
Exemplo n.º 13
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void) {
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */
  
  /* System Clocks Configuration */
  RCC_Configuration();
  
  /* System Tick Configuration at 1us */
  SysTick_Config(SystemCoreClock / 1000000);
  
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
  
  /* TIM2 Configuration */
  TIM2_Configuration();
  
  /* TIM3 Configuration (10ms for Network Transmission)*/
  TIM3_Configuration();
  
  /* TIM5 Configuration (GLCD Time Share)*/
  TIM5_Configuration();
  
  /* TIM6 Configuration (RTC load) */
  TIM6_Configuration();
  
#elif defined USE_EQDAS_SERVER
  
  /* TIM4 Configuration */
  TIM4_Configuration();
  
#endif
  
  /* CLCD Configuration */
  CLCD_Configuration();
  
  /* GLCD Configuration */
  GLCD_Configuration();
  
  /* UART1 Configuration */
  UART_Configuration();
  
  /* GPS-UART3 Configuration */
  //GPS_Configuration();
  
  /* RTC configuration by setting the time by Serial USART1 */
  RTC_SetTimeBySerial();
  
  /* Forcefully let user set the IP through terminal */
  //ForceIPSetBySerial();

  /* WIZ820io SPI1 configuration */
  WIZ820io_SPI1_Configuration();
  
  /* W5200 Configuration */
  Set_network();
  
  /* Print WIZ820io configuration */
  printSysCfg();
  
  /* EXTI Configuration */
  EXTI_Configuration();
  
  /* FatFS configuration */
  f_mount(0, &fs);  // mSD
  //f_mount(1, &fs);  // NAND
  
  /* Display Total size of SD card in MB scale */
  SD_TotalSize();
  
  /* Scan all files in mSD card */
  scan_files(path);
  
  /* MAL configuration */
  //Set_System();
  
  /* UMS configuration */
  //Set_USBClock();
  //USB_Interrupts_Config();
  //USB_Init();
  
  /* loop upon completion of USB Enumeration */
  //while (bDeviceState != CONFIGURED);
  
  /* ATFC Algorithm GPIO */
  ATFC_GPIO_Configuration();
  
  /* ATFC Parameter Initialization */
  ATFCAlgorithmParameterSetup();
  
  // For TCP client's connection request delay
  presentTime = my_time;
  
  /* Clear CLCD before branch into main */
  CLCD_Clear();

  /* Create directory and sub directory in accordance with current date */
  filePath = CreateDirectoryAccordingly(GetYearAndMergeToInt(), GetMonthAndMergeToInt(), 
                                        GetDayAndMergeToInt(), RTC_GetCounter() / 3600);
  
  /* Create file in append mode in accordance with current minute */
  CreateFileAppendModeAccordingly(filePath, (RTC_GetCounter() % 3600) / 60);
  
  // When everything is set, print message
  printf("\r\n\n - System is ready - ");
  
  while (1) {
    
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
    
    if(TimerCount > 1000) { // 0 ~ 999 (1000) = 1 sec
      TimerCount = 0;
      
      /*
      int x, y, z;
      x = mAxisBuf.tmp_data_x_lcd[index];
      y = mAxisBuf.tmp_data_y_lcd[index];
      z = mAxisBuf.tmp_data_z_lcd[index];
    
      char Serial_Buf[37];
      int hour, minute, second, tmsecond;
      hour = THH; minute = TMM; second = TSS; tmsecond = 0;
      sprintf(Serial_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d\r\n", 
                year, month, day, hour, minute, second, tmsecond, x, y, z);
      printf(Serial_Buf);
      */
      
      //my_time++;  // uncomment when tcp connection is needed
      
      /* Process Parameter Text Stream */
      /*
      if(PCFlag) {  // EQDAS Client System and ATFC Algorithm Setting
        PCFlag = false;
        
        ProcessParameterStream();
      }
      */
    }
    
    /* GLCD Time Share */
    if(TIM5GLCDCount > 95) {  // Allocate proper time to share mcu resource with network
      TIM5GLCDCount = 0;
      
      /* Graphic LCD Copy and Process Routine -------------------------------------- */
      if(SyncFlag) { // prevent unpleasant impuse
        // Index synchronization dedicate to GLCD
        arrGLCDIdx = index;
        
        // Make a copy from raw collected data to temporary array
        CopyToTmpArray(arrGLCDIdx);
          
        // Copy to Temporary GAL array
        //CopyToTmpGalArray(arrIdx);
        
        // Calculate GAL and copy to single temporary GAL value
        //CalculateGalAndCopyToGal(arrIdx);
        
        // Determine KMA scale
        KMAGrade = DetermineKMA(arrGLCDIdx);
    
        // Check sign bit and apply to int container
        CheckSignAndToInt(arrGLCDIdx); // this function also cuts surplus 1G
      }
      
      int mATFCBit_lcd;
      mATFCBit_lcd = mAxisBuf.ATFCBit_lcd[arrGLCDIdx];
      
      /* Switch menu & waveform display through graphic lcd */
      GLCD_AxisViewWithWaveform(mode, arrGLCDIdx);
      
      /* Display KMA Intensity on Graphic LCD */
      GLCD_DisplayKMAIntensity(KMAGrade, mATFCBit_lcd);
    }
    
    /* Clock generated by TIM3 */
    if(ClientTimerCounter > 10) {  // 0 ~ 999 (1000) = 1 sec
      ClientTimerCounter = 0;
      
      year = GetYearAndMergeToInt();
      month = GetMonthAndMergeToInt();
      day = GetDayAndMergeToInt();
      hour = THH; minute = TMM; second = TSS; tmsecond = 0;
      
      int mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec;
      mYear = year; mMonth = month; mDay = day;
      mHour = hour; mMin = minute; mSec = second; mTMSec = tmsecond;

      if(SyncFlag) {
        // Index synchronization
        arrIdx = index;
      
        // Make a copy from raw collected data to temporary net array
        CopyToNetArray(arrIdx);
        
        // Check sign bit and apply to int container
        CheckSignAndToIntForNet(arrIdx); // this function also cuts surplus 1G
      }
      
      /* Prevent access to volatile variable warning */
      /* This have to be here in order to correct data to be used in ATFC */
      int mX, mY, mZ, mATFCBit;
      mX = mAxisNetBuf.axis_x_for_net[arrIdx];
      mY = mAxisNetBuf.axis_y_for_net[arrIdx];
      mZ = mAxisNetBuf.axis_z_for_net[arrIdx];
      mATFCBit = mAxisNetBuf.ATFCBit_net[arrIdx];
      
      /* EQDAQ01, 02 Client Routine ---------------------------------------------*/
      /* E1Flag or E2Flag set when client board successfully connect to server --*/
      /* Refer to wiz820.c line no. 406 for which flag to be set */
      if(E1Flag) {
        char E1_Buf[45];
        sprintf(E1_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d_%d\r\n", 
                mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec,
                mX, mY, mZ, mATFCBit);
        // Only when socket is established, allow send data
        if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) {
          /* send selected data */
          CountSendByte = send(SOCK_ZERO, (uint8_t*)E1_Buf, strlen(E1_Buf), (bool)false);
        }
      }
      
      if(E2Flag) {
        char E2_Buf[45];
        sprintf(E2_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d_%d\r\n", 
                mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec,
                mX, mY, mZ, mATFCBit);
        // Only when socket is established, allow send data
        if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) {
          /* send selected data */
          send(SOCK_ZERO, (uint8_t*)E2_Buf, strlen(E2_Buf), (bool)false);
        }
      }
    }
    
    /* do RTC work on every second */
    if(RTCTIM6Count > 1000) {
      RTCTIM6Count = 0;
      
      if(InitialThirteenSeconds == 12) {
         InitialThirteenSeconds = 0;
         GoATFCFlag = true;
      } else {
        if(!GoATFCFlag) {
           InitialThirteenSeconds++;
        }
      }
      
      /* RTC 1Hz interrupt */
      if(RTCTimeDisplay) { // 1Hz calibrated by RTC
        RTCTimeDisplay = false;
        
        /* Adjust realtime clock deviation */
        if(hour > 23) {
          int i, currentDay, mDay, mHour, mMin, mSec;
          mDay = hour / 24;
          
          for(i=0; i<mDay; i++) {
            IncreaseSingleDay();
            if(i == mDay - 1) {
              currentDay = (GetMonthAndMergeToInt() * 100) + GetDayAndMergeToInt();
              BKP_WriteBackupRegister(BKP_DR3, currentDay); // Save Month and Date
            }
          }
          
          mHour = THH % 24;
          mMin = TMM;
          mSec = TSS;
          
          /* Change the current time */
          RTC_SetCounter(mHour*3600 + mMin*60 + mSec);
        }
        
        /* Display current time */
        Time_Display(RTC_GetCounter());
        
        int OrderCount;
        for(OrderCount = 0; OrderCount < 100; OrderCount++) {
          // Copy to data buffer to be written through FATFS
          CopyToFatFsDataBuffer(OrderCount); 
        }
      }
      
      /* RTC Alarm interrupt */
      if(RTCAlarmFlag) {
        RTCAlarmFlag = false;
        
        printf("\r\nRTC Alarm Actviated!");
      } 
    }
    
#endif
    
    if(ParseGPS) {
      ParseGPS = false;
      
      printf("%s", GPS_Buffer);
    }
    
    if(ParseUSART1) {
      ParseUSART1 = false;
      
      // run some test on SDIO
      //SDIO_TEST();

#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
      
      /* Print WIZ820io configuration */
      printSysCfg();

      printf("\r\n");
      printf("\r\nBKP_DR1 = %d", BKP_ReadBackupRegister(BKP_DR1));
      printf("\r\nBKP_DR2 = %d", BKP_ReadBackupRegister(BKP_DR2));
      printf("\r\nBKP_DR3 = %d", BKP_ReadBackupRegister(BKP_DR3));
      printf("\r\nBKP_DR4 = %d", BKP_ReadBackupRegister(BKP_DR4));
      printf("\r\nBKP_DR5 = %d", BKP_ReadBackupRegister(BKP_DR5));
      printf("\r\nBKP_DR6 = %d", BKP_ReadBackupRegister(BKP_DR6));
      printf("\r\nBKP_DR7 = %d", BKP_ReadBackupRegister(BKP_DR7));
      printf("\r\nBKP_DR8 = %d", BKP_ReadBackupRegister(BKP_DR8));
      printf("\r\nBKP_DR9 = %d", BKP_ReadBackupRegister(BKP_DR9));
      printf("\r\nBKP_DR10 = %d", BKP_ReadBackupRegister(BKP_DR10));
      printf("\r\nBKP_DR11 = %d", BKP_ReadBackupRegister(BKP_DR11));
      printf("\r\nBKP_DR12 = %d", BKP_ReadBackupRegister(BKP_DR12));
      printf("\r\nBKP_DR13 = %d", BKP_ReadBackupRegister(BKP_DR13));
      printf("\r\nBKP_DR14 = %d", BKP_ReadBackupRegister(BKP_DR14));
      printf("\r\nBKP_DR15 = %d", BKP_ReadBackupRegister(BKP_DR15));
      printf("\r\nBKP_DR16 = %d", BKP_ReadBackupRegister(BKP_DR16));
      
      /*
      printf("\r\nstrlen(HEADER) : %d %s", strlen(HEADER), HEADER);
      
      printf("\r\nf_mkdir1 : ");
      char *dirPath = "0:/20130517";
      res = f_mkdir(dirPath);
      FPrintFatResult(res);
      
      printf("\r\nf_mkdir2 : ");
      dirPath = "0:/20130517/22H-23H";
      res = f_mkdir(dirPath);
      FPrintFatResult(res);
      
      char *filePath = "0:/20130517/2-23H/test.txt";
      // Create log file on the drive 0
      res = open_append(&fsrc, filePath);
      FPrintFatResult(res);
      
      if(res == FR_OK) {
        printf("test.txt successfully created\r\n");
        
        // Write buffer to file
        int bytesWritten;
        bytesWritten = f_printf(&fsrc, HEADER);
        printf("\r\n%d of bytesWritten", bytesWritten);
        
        // Close file
        f_close(&fsrc);
        
      } else if ( res == FR_EXIST ) {
        printf("\r\ntest.txt already exist");
      }
      */
      
      
#elif (defined) USE_EQDAS_SERVER
      
      char buffer[37];
      sprintf(buffer, "%s_%s_%s_%s_%s\r\n",
                DAQBoardOne[arrIdx].Date,
                DAQBoardOne[arrIdx].Time,
                DAQBoardOne[arrIdx].AxisX,
                DAQBoardOne[arrIdx].AxisY,
                DAQBoardOne[arrIdx].AxisZ);
      printf("\r\nRX_BUF : %s, strlen(RX_BUF) : %d", (char*)RX_BUF, strlen((char*)RX_BUF));
      printf("\r\nstrlen(buffer) = %d\n%s", strlen(buffer), buffer);
      
      /*
      char *original = "-3843,+4095,+2069";
      char target[20];
      strncpy(target, original, strlen(original));
      
      char *one, *two, *three;
      char *AfterToken;
      AfterToken = strtok(target, ",");
      one = AfterToken;
      AfterToken = strtok(NULL, ",");
      two = AfterToken;
      AfterToken = strtok(NULL, ",");
      three = AfterToken;
      AfterToken = strtok(NULL, ",");
      if(AfterToken != NULL) printf("AfterToken is not empty");
      
      printf("\r\none : %s, two : %s, three : %s", one, two, three);*/
      
#endif
    
    }
    
// following routine is only necessary when the board works as server
#if defined USE_EQDAS_SERVER
    
    /* Server also needs to have get CLCD going while running */
    /* RTC 1Hz interrupt */
    if(RTCTimeDisplay) { // 1Hz calibrated by RTC
      RTCTimeDisplay = false;
      
      /* Adjust realtime clock deviation */
      if(hour > 23) {
        int i, currentDay, mDay, mHour, mMin, mSec;
        mDay = hour / 24;
        
        for(i=0; i<mDay; i++) {
          IncreaseSingleDay();
          if(i == mDay - 1) {
            currentDay = (GetMonthAndMergeToInt() * 100) + GetDayAndMergeToInt();
            BKP_WriteBackupRegister(BKP_DR3, currentDay); // Save Month and Date
          }
        }
        
        mHour = THH % 24;
        mMin = TMM;
        mSec = TSS;
        
        /* Change the current time */
        RTC_SetCounter(mHour*3600 + mMin*60 + mSec);
      }
      
      /* Display current time */
      Time_Display(RTC_GetCounter());
    }
    
    /* EQ-DAQ-01 Parsing routine ------------------------------------------------- */
    /* Set E1Flag indicate that we have valid connection from EQ-DAQ-01(port 5050) */
    if(E1Flag) {
      E1Flag = false; // clear flag since this routine excutes ceaselessly over time
      
      ProcessTextStream(EQ_ONE, (char*)RX_BUF, E1Order);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag && !E2Flag) { // only when PC is connected and EQ-DAQ-02 is not connected
        // Send directly to PC
        //SendToPC(EQ_ONE, E1Order);
      }
      
      if(E1Order < 99) E1Order++;
      else E1Order = 0;
    } 
    
    /* EQ-DAQ-02 Parsing routine ------------------------------------------------- */
    /* Set E2Flag indicate that we have valid connection from EQ-DAQ-02(port 6060) */
    if(E2Flag) {
      E2Flag = false;
      
      ProcessTextStream(EQ_TWO, (char*)RX_BUF, E2Order);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag && !E1Flag) { // only when PC is connected and EQ-DAQ-01 is not connected
        // Send directly to PC
        //SendToPC(EQ_TWO, E2Order);
      }
      
      if(E2Order < 99) E2Order++;
      else E2Order = 0;
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag) {
        // Send directly to PC
        MultipleBoardDataToSendToPC(EQ_BOTH, E1Order, E2Order);
      }
    }

#endif

/* Setup TCP Client or Server -----------------------------------------------------*/
/* Please open config.h file to choose a proper board you wish to use -------------*/    
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
      
      /* Start TCP Client process */
      ProcessTcpClient(SOCK_ZERO);  // TCP Client
      
      /* Parameter setting Server side with port 5050 in default */
      ATFCTcpServer(SOCK_TWO, EQDAS_Conf_PORT);  // SOCK_TWO because of flag conformity
      
#elif defined USE_EQDAS_SERVER
      
      /* Process server socket with each port */
      ProcessTcpServer(SOCK_ZERO, 5050);  // designated as for EQM-DAQ-01 with port 5050
      ProcessTcpServer(SOCK_ONE, 6060);   // designated as for EQM-DAQ-02 with port 6060
      ProcessTcpServer(SOCK_TWO, 7070);   // designated as for PC-CLIENT  with port 7070
      ProcessTcpServer(SOCK_THREE, 8080); // designated as for PC_DUMP    with port 8080
      
      /*
      ProcessTcpServer(SOCK_FOUR, 9090);   // designated as for TOBEUSED with port 9090
      ProcessTcpServer(SOCK_FIVE, 10010);   // designated as for TOBEUSED with port 10010
      ProcessTcpServer(SOCK_SIX, 10020);    // designated as for TOBEUSED with port 10020
      ProcessTcpServer(SOCK_SEVEN, 10030);  // designated as for TOBEUSED with port 10030
      */
      
#endif
      
  }
}
Exemplo n.º 14
0
/*********************************************************************************************************
  * @brief  Calendar program.
  * @retval None
  ********************************************************************************************************/
void Calendar(void)
{
    CKCU_APBPerip1ClockConfig(CKCU_APBEN1_RTC, ENABLE);
    if(PWRCU_CheckReadyAccessed() != PWRCU_OK)
    {
        while(1);
    }

    /* Init LED3 and USART */
    LED_Configuration();
    USART_Configuration();

    /* Enable NVIC RTC interrupt */
    NVIC_EnableIRQ(RTC_IRQn);

    /* Check if the Power On Reset flag is set */
    if(PWRCU_GetFlagStatus() == PWRCU_FLAG_BAKPOR)
    {
        printf("\r\n\n Power On Reset occurred....");
    }

    if(PWRCU_ReadBackupRegister(PWRCU_BAKREG_0) != 0x5A5A)
    {
        u32 wInitTime = 0;
        /* Backup data register value is not correct or not yet programmed (when
           the first time the program is executed) */

        printf("\r\n\n RTC not yet configured....");

        /* RTC Configuration */
        RTC_Configuration();

        printf("\r\n RTC configured....");

        /* Adjust time by values entred by the user on the hyperterminal,
           Then store the init time to PWRCU_BAKREG_1. */
        wInitTime = Time_Regulate() ;
        PWRCU_WriteBackupRegister(PWRCU_BAKREG_1, wInitTime);

        /* Reset RTC Counter when Time is 23:59:59 */
        RTC_SetCompare(86400 - wInitTime) ;

        PWRCU_WriteBackupRegister(PWRCU_BAKREG_0, 0x5A5A);
        /* Enable RTC */
        RTC_Cmd(ENABLE) ;
    }
    else
    {
        printf("\r\n No need to configure RTC....");
    }

    /* Display current time in infinite loop */
    printf("\n\r");

    while (1)
    {
        /* If 1s has paased */
        if(gwTimeDisplay == 1)
        {
            /* Display current time.
               Current time is sum of the RTC counter value and the init time(stored in PWRCU_BAKREG_1 register).
               The init time (PWRCU_BAKREG_1 register) will be clear if the RTC Match flag(CMFLAG) is set.
               Refer to RTC_IRQHandler. */
            Time_Display(RTC_GetCounter() + PWRCU_ReadBackupRegister(PWRCU_BAKREG_1));
            gwTimeDisplay = 0;
        }
    }
}
Exemplo n.º 15
0
/*******************************************************************************
* Function Name  : Time_PreAdjust
* Description    : Returns the time entered by user, using demoboard keys.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
static void Time_PreAdjust(void)
{
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  /* Clear the LCD screen */
  LCD_Clear(White);

  LCD_SetDisplayWindow(160, 223, 128, 128);
 
  LCD_NORDisplay(WATCH_ICON);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  /* Disable LCD Window mode */
  LCD_WindowModeDisable();

  if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
    /* Allow access to BKP Domain */
    PWR_BackupAccessCmd(ENABLE);
   
    LCD_DisplayStringLine(Line7, "RTC Config PLZ Wait.");

    /* RTC Configuration */
    RTC_Configuration();
    LCD_DisplayStringLine(Line7, "       TIME         ");
    /* Clear Line8 */
    LCD_ClearLine(Line8);

    /* Display time separators ":" on Line4 */
    LCD_DisplayChar(Line8, 212, ':');
    LCD_DisplayChar(Line8, 166, ':');

    /* Display the current time */
    Time_Display(RTC_GetCounter());

    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();  
    /* Change the current time */
    RTC_SetCounter(Time_Regulate());

    BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);

    /* Clear Line7 */
    LCD_ClearLine(Line7);    
    /* Clear Line8 */
    LCD_ClearLine(Line8);    
    /* Adjust Date */
    Date_PreAdjust();    
  }
  else
  {  
    /* Clear Line8 */
    LCD_ClearLine(Line8);
    
    /* Display time separators ":" on Line4 */
    LCD_DisplayChar(Line8, 212, ':');
    LCD_DisplayChar(Line8, 166, ':');

    /* Display the current time */
    Time_Display(RTC_GetCounter());

    /* Wait until last write operation on RTC registers has finished */
    RTC_WaitForLastTask();  
    /* Change the current time */
    RTC_SetCounter(Time_Regulate());  
  }
}
Exemplo n.º 16
0
/*******************************************************************************
* Function Name  : Time_Show
* Description    : Shows the current time (HH/MM/SS) on LCD.
* Input          : None
* Output         : None
* Return         : None
******************************************************************************/
void Time_Show(void)
{
  uint32_t testvalue = 0, pressedkey = 0;
  
  /* Set the Back Color */
  LCD_SetBackColor(White);
  /* Set the Text Color */
  LCD_SetTextColor(Blue);
  /* Disable the JoyStick interrupts */
  IntExtOnOffConfig(DISABLE);

  while(ReadKey()!= NOKEY)
  {
  }

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  /* Clear the LCD screen */
  LCD_Clear(White);

  LCD_SetDisplayWindow(160, 223, 128, 128);
 
  LCD_NORDisplay(WATCH_ICON);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  /* Disable LCD Window mode */
  LCD_WindowModeDisable();

  if(BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
  {
    LCD_DisplayStringLine(Line7, "Time and Date Config");
    LCD_DisplayStringLine(Line8, "Select: Press SEL   ");
    LCD_DisplayStringLine(Line9, "Abort: Press Any Key");    
    
    while(testvalue == 0)
    {
      pressedkey = ReadKey();

      if(pressedkey == SEL)
      {
        /* Adjust Time */
        Time_PreAdjust();
        /* Clear the LCD */
        LCD_Clear(White);
        testvalue = 0x01;
      }
      else if (pressedkey != NOKEY)
      {
        /* Clear the LCD */
        LCD_ClearLine(Line8);
        /* Display the menu */
        DisplayMenu();
        /* Enable the JoyStick interrupts */
        IntExtOnOffConfig(ENABLE);
        return;
      }
    }
    /* Display time separators ":" on Line8 */
    LCD_DisplayChar(Line8, 212, ':');
    LCD_DisplayChar(Line8, 166, ':');
    /* Wait a press on any JoyStick pushbuttons */
    while(ReadKey() == NOKEY)
    {
      /* Display current time */
      Time_Display(RTC_GetCounter());
    }
  } 
  else
  {  
    while(ReadKey() != NOKEY)
    { 
    }
    /* Display time separators ":" on Line8 */
    LCD_DisplayChar(Line8, 212, ':');
    LCD_DisplayChar(Line8, 166, ':');
    /* Wait a press on any JoyStick pushbuttons */
    while(ReadKey() == NOKEY)
    {
      /* Display current time */
      Time_Display(RTC_GetCounter());
    }
  }
  /* Clear the LCD */
  LCD_ClearLine(Line8);
  /* Display the menu */
  DisplayMenu();
  /* Enable the JoyStick interrupts */
  IntExtOnOffConfig(ENABLE);
}
Exemplo n.º 17
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void) {
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */
  
  /* System Clocks Configuration */
  RCC_Configuration();
  
  /* System Tick Configuration at 1us */
  SysTick_Config(SystemCoreClock / 1000000);
  
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
  
  /* TIM2 Configuration */
  TIM2_Configuration();
  
  /* TIM3 Configuration */
  TIM3_Configuration();
  
  /* TIM6 Configuration (RTC load) */
  TIM6_Configuration();
  
#elif defined USE_EQDAS_SERVER
  
  /* TIM4 Configuration */
  TIM4_Configuration();
  
#endif
  
  /* UART1 Configuration */
  UART_Configuration();

  /* WIZ820io SPI1 configuration */
  WIZ820io_SPI1_Configuration();
  
  /* W5200 Configuration */
  Set_network();
  
  /* EXTI Configuration */
  EXTI_Configuration();
  
  /* CLCD Configuration */
  CLCD_Configuration();
  
  /* GLCD Configuration */
  GLCD_Configuration();
  
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
  
  /* RTC configuration by setting the time by Serial USART1 */
  RTC_SetTimeBySerial();
  
#endif
  
  /* FatFS configuration */
  f_mount(0, &fs);  // mSD
  //f_mount(1, &fs);  // NAND
  
  /* Display Total size of SD card in MB scale */
  SD_TotalSize();
  
  /* Scan all files in mSD card */
  scan_files(path);
  
  /* MAL configuration */
  //Set_System();
  
  /* UMS configuration */
  //Set_USBClock();
  //USB_Interrupts_Config();
  //USB_Init();
  
  /* loop upon completion of USB Enumeration */
  //while (bDeviceState != CONFIGURED);
  
  // For TCP client's connection request delay
  presentTime = my_time;
  
  /* Clear CLCD before branch into main */
  CLCD_Clear();
  
  /* Alarm in 3 second */
  //RTC_SetAlarm(RTC_GetCounter() + 3);
  /* Wait until last write operation on RTC registers has finished */
  //RTC_WaitForLastTask();
  
  // When everything is set, print message
  printf("\r\n\n - System is ready - ");
  
  while (1) {
    
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
    
    if(TimerCount >= 999) { // 0 ~ 999 (1000) = 1 sec
      TimerCount = 0;
      
      /*
      int x, y, z;
      x = mAxisBuf.tmp_data_x_lcd[index];
      y = mAxisBuf.tmp_data_y_lcd[index];
      z = mAxisBuf.tmp_data_z_lcd[index];
    
      char Serial_Buf[37];
      int hour, minute, second, tmsecond;
      hour = THH; minute = TMM; second = TSS; tmsecond = 0;
      sprintf(Serial_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d\r\n", 
                year, month, day, hour, minute, second, tmsecond, x, y, z);
      printf(Serial_Buf);
      */
      
      //my_time++;  // uncomment when tcp connection is needed

    }
    
    /* Clock generated by TIM3 */
    if(ClientTimerCounter >= 99) {  // 0 ~ 999 (1000) = 1 sec
      ClientTimerCounter = 0;
      
      arrIdx = index;
      
      year = GetYearAndMergeToInt();
      month = GetMonthAndMergeToInt();
      day = GetDayAndMergeToInt();
      hour = THH; minute = TMM; second = TSS; tmsecond = 0;
      
      /* EQDAQ01, 02 Client Routine ---------------------------------------------*/
      /* E1Flag or E2Flag set when client board successfully connect to server --*/
      /* Refer to wiz820.c line no. 300 for which flag to be set */
      if(E1Flag) {
        int x, y, z;
        x = mAxisBuf.tmp_data_x_lcd[arrIdx];
        y = mAxisBuf.tmp_data_y_lcd[arrIdx];
        z = mAxisBuf.tmp_data_z_lcd[arrIdx];
      
        char E1_Buf[20];        
        sprintf(E1_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d\r\n", 
                year, month, day, hour, minute, second, tmsecond, x, y, z);
        // Only when socket is established, allow send data
        if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) {
          /* send selected data */
          CountSendByte = send(SOCK_ZERO, (uint8_t*)E1_Buf, strlen(E1_Buf), (bool)false);
        }
      }
      
      if(E2Flag) {
        int x, y, z;
        x = mAxisBuf.tmp_data_x_lcd[arrIdx];
        y = mAxisBuf.tmp_data_y_lcd[arrIdx];
        z = mAxisBuf.tmp_data_z_lcd[arrIdx];
        
        char E2_Buf[20];
        sprintf(E2_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d\r\n", 
                year, month, day, hour, minute, second, tmsecond, x, y, z);
        // Only when socket is established, allow send data
        if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) {
          /* send selected data */
          send(SOCK_ZERO, (uint8_t*)E2_Buf, strlen(E2_Buf), (bool)false);
        }
      }
    }
    
    /* do RTC work on every 0.5 sec */
    if(RTCTIM6Count >= 499) {
      RTCTIM6Count = 0;
      
      /* RTC 1Hz interrupt */
      if(RTCTimeDisplay) { // 1Hz calibrated by RTC
        RTCTimeDisplay = false; 
        
        /* Display current time */
        Time_Display(RTC_GetCounter());
      }
      
      /* RTC Alarm interrupt */
      if(RTCAlarmFlag) {
        RTCAlarmFlag = false;
        
        printf("\r\nRTC Alarm Actviated!");
      } 
    }
    
#endif
    
    if(ParseUSART1) {
      ParseUSART1 = false;
      
      // print system configuration
      //printSysCfg();
      
      // run some test on SDIO
      //SDIO_TEST();

#if (defined USE_EQDAS01) || (defined USE_EQDAS02)

      
      
#elif (defined) USE_EQDAS_SERVER
      
      char buffer[37];
      sprintf(buffer, "%s_%s_%s_%s_%s\r\n",
                DAQBoardOne[arrIdx].Date,
                DAQBoardOne[arrIdx].Time,
                DAQBoardOne[arrIdx].AxisX,
                DAQBoardOne[arrIdx].AxisY,
                DAQBoardOne[arrIdx].AxisZ);
      printf("\r\nRX_BUF : %s, strlen(RX_BUF) : %d", (char*)RX_BUF, strlen((char*)RX_BUF));
      printf("\r\nstrlen(buffer) = %d\n%s", strlen(buffer), buffer);
      
      /*
      char *original = "-3843,+4095,+2069";
      char target[20];
      strncpy(target, original, strlen(original));
      
      char *one, *two, *three;
      char *AfterToken;
      AfterToken = strtok(target, ",");
      one = AfterToken;
      AfterToken = strtok(NULL, ",");
      two = AfterToken;
      AfterToken = strtok(NULL, ",");
      three = AfterToken;
      AfterToken = strtok(NULL, ",");
      if(AfterToken != NULL) printf("AfterToken is not empty");
      
      printf("\r\none : %s, two : %s, three : %s", one, two, three);*/
      
#endif
    
    }
    
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)
    
    for(i=0; i<100; i++) {
      // Make a copy from raw collected data to temporary array
      CopyToTmpArray(i);
        
      // Copy to Temporary GAL array
      CopyToTmpGalArray(i);
      
      // Calculate GAL and copy to single temporary GAL value
      CalculateGalAndCopyToGal(i);
      
      // Determine KMA scale
      DetermineKMA(i);
      
      // Check sign bit and apply to int container
      CheckSignAndToInt(i); // this function also cuts surplus 1G
      
      // Copy to data buffer to be written through FATFS
      //CopyToFatFsDataBuffer(arrIdx);
    }
    
    /* Save log to file process */
    if(GoAppendDataFlag) {  // every 500 sample (equals 5 sec), go save file.
      GoAppendDataFlag = false;
      
      int bytesWritten = 0;
      
      /* Open or create a log file and ready to append */
      //char *filePath = "/20130517/22H-23H/test.txt";
      //res = open_append(&fsrc, filePath);
      //FPrintFatResult(res);
      
      if(FiveSecFlag) {
        // it means that DATA1_BUF is full and ready to flush out
        // be sure to empty out DATA1_BUF or will overflow and cause system to halt.
        
        /* Append 5 second of data */
        bytesWritten = f_printf(&fsrc, DATA1_BUF);
    
        /* Close the file */
        f_close(&fsrc);
        
        printf("\r\n%d of bytesWritten", bytesWritten);
        
        // Reset DATA1_BUF
        memset(DATA1_BUF, 0, sizeof(DATA1_BUF));
        
      } else {
        // here means that DATA2_BUF is full and ready to flush out
        // be sure to empty out DATA2_BUF or will overflow and cause system to halt.
        
        /* Append 5 second of data */
        bytesWritten = f_printf(&fsrc, DATA2_BUF);

        /* Close the file */
        f_close(&fsrc);
        
        printf("\r\n%d of bytesWritten", bytesWritten);
        
        // Reset DATA2_BUF
        memset(DATA2_BUF, 0, sizeof(DATA2_BUF));
      }
    }
    
// following routine is only necessary when the board works as server
#elif defined USE_EQDAS_SERVER
    
    /* EQ-DAQ-01 Parsing routine ------------------------------------------------- */
    /* Set E1Flag indicate that we have valid connection from EQ-DAQ-01(port 5050) */
    if(E1Flag) {
      E1Flag = false; // clear flag since this routine excutes ceaselessly over time
      
      ProcessTextStream(EQ_ONE, (char*)RX_BUF, E1Order);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag) {        
        // Send directly to PC
        SendToPC(E1Order);
      }
      
      if(E1Order < 99) E1Order++;
      else E1Order = 0;
    }
    
    /* EQ-DAQ-02 Parsing routine ------------------------------------------------- */
    /* Set E2Flag indicate that we have valid connection from EQ-DAQ-02(port 6060) */
    if(E2Flag) {
      E2Flag = false;
      
      ProcessTextStream(EQ_TWO, (char*)RX_BUF, E2Order);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag) {        
        // Send directly to PC
        SendToPC(E2Order);
      }
      
      if(E2Order < 99) E2Order++;
      else E2Order = 0;
    }

#endif

/* Setup TCP Client or Server -----------------------------------------------------*/
/* Please open config.h file to choose a proper board you wish to use */    
#if (defined USE_EQDAS01) || (defined USE_EQDAS02)    

      /* Start TCP Client process */
      ProcessTcpClient(SOCK_ZERO);
    
#elif defined USE_EQDAS_SERVER
    
      /* Process server socket with each port */
      ProcessTcpServer(SOCK_ZERO, 5050);  // designated as for EQM-DAQ-01 with port 5050
      ProcessTcpServer(SOCK_ONE, 6060);   // designated as for EQM-DAQ-02 with port 6060
      ProcessTcpServer(SOCK_TWO, 7070);   // designated as for PC-CLIENT  with port 7070
      ProcessTcpServer(SOCK_THREE, 8080); // designated as for PC_DUMP    with port 8080
      
      /*
      ProcessTcpServer(SOCK_FOUR, 9090);   // designated as for TOBEUSED with port 9090
      ProcessTcpServer(SOCK_FIVE, 10010);   // designated as for TOBEUSED with port 10010
      ProcessTcpServer(SOCK_SIX, 10020);    // designated as for TOBEUSED with port 10020
      ProcessTcpServer(SOCK_SEVEN, 10030);  // designated as for TOBEUSED with port 10030
      */
      
#endif
      
  }
}
Exemplo n.º 18
0
int battery(void)
{


	int i;
	printf("\n\r");
	Time_Display(RTC_GetCounter());
	if(show_inf())
		return 1;

//	printf("\r放电开始");
//	Time_Display(RTC_GetCounter());
//	printf("\n\r");
//
//	if(dis_charge())
//		return 1;
//
//	printf("放电结束");
//	Time_Display(RTC_GetCounter());
//	printf("\n\r放电时间为:%d分钟\n\r",record[0]);
//
//	if(delay_hour())
//		return 1;



	printf("\r不加修复器:充电 开始");
	Time_Display(RTC_GetCounter());
	printf("\n\r");

	if(charge())
		return 1;
	
       	printf("不加修复器:充电 结束");
	Time_Display(RTC_GetCounter());
	printf("\n\r");

	if(delay_hour())
		return 1;
	
	printf("\n\r不加修复器:放电 开始");
	Time_Display(RTC_GetCounter());
	printf("\n\r");
	

	if(dis_charge())
		return 1;

	printf("不加修复器:放电 结束");
	Time_Display(RTC_GetCounter());
	printf("\n\r放电时间为:%d分钟\n\r",record[0]);

	if(delay_hour())
		return 1;

	printf("\n\r带修复器充放%d次\n\r",conf->times);
	br_con_on();
	for(i = 0; i < conf->times; i++){
		

		printf("\n\r带修复器第%d次:充电 开始",i + 1);
		Time_Display(RTC_GetCounter());
		printf("\n\r");

		if(charge())
			return 1;

		printf("带修复器第%d次:充电 结束",i + 1);
		Time_Display(RTC_GetCounter());
		printf("\n\r");
		
							 
		if(delay_hour())
			return 1;

		printf("\n\r带修复器第%d次:放电 开始",i + 1);
		Time_Display(RTC_GetCounter());
		printf("\n\r");

		if(dis_charge())
			return 1;


		printf("带修复器第%d次:放电 结束",i + 1);
		Time_Display(RTC_GetCounter());
		printf("\n\r放电时间为:%d分钟\n\r",record[i+1]);

		if(i+1 < conf->times){
				

			if(delay_hour())
				return 1;
		}
		
	}

	br_con_off();

	if(show_dis_time())
		return 1;

	time_out = 0;
	rec = 0;

	memset(record, 0, sizeof(record));	
	
	return 0;


	
}