Ejemplo n.º 1
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
     */     
       
  /* RCC configuration */
  RCC_Configuration();
  
  /* TIM4 configuration */
  TIM4_Configuration();
  
  /* UART4 configuration */
  UART4_Configuration();
  
  /* WIZ820io SPI2 configuration */
  WIZ820io_SPI2_Configuration();  // one that is on left one
  
  /* WIZ820io SPI3 configuration */
  //WIZ820io_SPI3_Configuration();  // one that is on right one

  /* W5200 Configuration */
  Set_network();
  
  /* TLCD configuration */
  TLCD_Configuration();
  
  //TLCD_Write(0, 0, str1);
  //TLCD_Write(0, 1, str2);
  
  /* RTC Configuration */
  RTC_Configuration();
  
  /* EXIT4(Mode select button) configuration */
  EXTILine4_Configuration();
  
  /* EXIT5(F_SYNC : 100Hz) configuration */
  EXTILine5_Configuration();
  
  /* EXIT6(F_SCLK : 10KHz) configuration */
  EXTILine6_Configuration();
  
  /* myAccel3LV02 Configuration */
  Accel3LV02_Configuration();
  
  //myAccel3LV02 setup 1000.0111 Power on, enable all axis, self test off
  Accel_WriteReg(CTRL_REG1, 0xC7);
  // following routine setup myAccel3LV02 6g mode
  //Accel_WriteReg(CTRL_REG2, 0x80);
  
  /* GLCD configuration */
  GLCD_Configuration();
  
  // For TCP client's connection request delay
  presentTime = my_time;
  
  // When everything is set, print message
  printf("\r\n - System is ready - ");
    
  while(1) {
    if(TimerCount >= 1000) {  // thousand equals one second
      TimerCount = 0;
      
      // for Calculate connection delay
      my_time++;
      
      // retrieve axis data
      GetAccelValue(AXIS_X, &Xdata);
      GetAccelValue(AXIS_Y, &Ydata);
      GetAccelValue(AXIS_Z, &Zdata);
      
      char str[30];
      sprintf(str, "%d,%d,%d", 0xFFF&Xdata, 0xFFF&Ydata, 0xFFF&Zdata);
      TLCD_Clear();
      TLCD_Write(0, 0, str);
    }
    
    if(ParseUART4) {
      ParseUART4 = False; 
      
      // print Wiz810io configuration
      printSysCfg();
    }
    
    if(flag_uart == 1) {
      tmp_start = start;
    }
        
    switch(mode) {
    case SELECT_AXIS_X : break;
    case SELECT_AXIS_Y : break;
    case SELECT_AXIS_Z : break;
    }
    
    /* Ethernet Client Routine -----------------------------------------------*/
    /* SendFlag get set from when socket established and received any message */
    if(SendFlag) {
      SendFlag = False;
      
      char AxisData[30];
      for(order = 0; order < 100 ; order++) {
        float EW = 0;
        float NS = 0;
        float UD = 0;
        
        EW = data_x[order] * 1e-7;
        NS = data_y[order] * 1e-7;
        UD = data_z[order] * 1e-7;
        
        sprintf(AxisData, "%-0.7f,%-0.7f,%-0.7f\n", EW, NS, UD);
        
        // Only when socket is established, send data
        if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) {
          /* send the received data */
          send(SOCK_ZERO, (uint8*)AxisData, strlen(AxisData), (bool)False);
        }
      }
    }
    
    /* Process client socket with port 5050 */
    //ProcessTcpClient(SOCK_ZERO);
    
  }
}
Ejemplo n.º 2
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
     */
  
  /* RCC configuration */
  RCC_Configuration();
  
  /* TIM4 configuration */
  TIM4_Configuration();
  
  /* UART4 configuration */
  UART4_Configuration();
  
  /* Configure SysTick for each 1us */  
  SysTick_Config(SystemCoreClock / 1000000);
  
  /* TLCD configuration */
  TLCD_Configuration();

  /* RTC Configuration */
  RTC_Configuration();
  
  /* WIZ820io SPI2 configuration */
  WIZ820io_SPI2_Configuration();  // one that is on left one
  
  /* WIZ820io SPI3 configuration */
  //WIZ820io_SPI3_Configuration();  // one that is on right one

  /* W5200 Configuration */
  Set_network();
  
  /* EXIT4(Mode select button) configuration */
  EXTILine4_Configuration();
  
  /* EXIT5(F_SYNC : 100Hz) configuration */
  EXTILine5_Configuration();
  
  /* EXIT6(F_SCLK : 10KHz) configuration */
  EXTILine6_Configuration();
  
  /* myAccel3LV02 Configuration */
  Accel3LV02_Configuration();
  
  //myAccel3LV02 setup 1000.0111 Power on, enable all axis, self test off
  Accel_WriteReg(CTRL_REG1, 0xC7);
  // following routine setup myAccel3LV02 6g mode
  //Accel_WriteReg(CTRL_REG2, 0x80);
  
  /* GLCD configuration */
  GLCD_Configuration();
  
  /* Clear system loading string of TLCD */
  TLCD_Clear();
  
  // When everything is set, print message
  printf("\r\n - System is ready - ");
  
  while(1) {
    if(TimerCount >= 1000) {  // thousand equals one second
      TimerCount = 0;

      /*
      // retrieve axis data
      GetAccelValue(AXIS_X, &Xdata);
      GetAccelValue(AXIS_Y, &Ydata);
      GetAccelValue(AXIS_Z, &Zdata);
      
      char str[30];
      sprintf(str, "%d,%d,%d", 0xFFF&Xdata, 0xFFF&Ydata, 0xFFF&Zdata);
      TLCD_Clear();
      TLCD_Write(0, 0, str);
      */
    }
    
    if(ParseUART4) {
      ParseUART4 = false; 
      
      // print Wiz810io configuration
      printSysCfg();
    }
    
    if(flag_uart == 1) {
      tmp_start = index;
    }
    
    // On every impulse out of 100Hz do the work
    if(RbitFlag) {
      RbitFlag = false;
      
      // copy to buffer
      mAxisBuf.tmp_data_x_lcd[index] = mAxisData.data_x[index];
      mAxisBuf.tmp_data_y_lcd[index] = mAxisData.data_y[index];
      mAxisBuf.tmp_data_z_lcd[index] = mAxisData.data_z[index];
      
      // Copy to Temporary GAL array
      CopyToTmpGalArray(index);
      
      // Cut off to 1G
      CutOffTo1G(index);
      
      // Calculate GAL and copy to single temporary GAL value
      CalculateGalAndCopyToGal(index);
      
      // Determine KMA scale
      DetermineKMA(index);
      
      /* PC Client Parsing routine ------------------------------------------------- */
      /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */
      if(PCFlag) {
        //PCFlag = false;
        
        char PC_Buf[20];
        sprintf(PC_Buf, "%+d,%+d,%+d\n",
                mAxisBuf.tmp_data_x_lcd[index],
                mAxisBuf.tmp_data_y_lcd[index],
                mAxisBuf.tmp_data_z_lcd[index]);
        // code for stacking algorithm which will combine data from two boards into one
        // Only when socket is established, allow send data
        if(getSn_SR(SOCK_TWO) == SOCK_ESTABLISHED) {
          /* send selected data */
          send(SOCK_TWO, (uint8_t*)PC_Buf, strlen(PC_Buf), (bool)false);
        }
      }
      
      // increase index so that we can add to next array
      index++;
    }
        
    switch(mode) {
    case SELECT_AXIS_X : break;
    case SELECT_AXIS_Y : break;
    case SELECT_AXIS_Z : break;
    }
    
    // RTC Wakeup event
    if(WUFlag) {
      WUFlag = false;
      
      // Update current Date and Time
      RTC_TimeShow();
      
      // Display on TLCD
      TLCD_Write(0, 0, Date);
      TLCD_Write(0, 1, Time);
    }
    
    /* EQ-DAQ-01 Parsing routine ------------------------------------------------- */
    /* Set E1Flag indicate that we have valid connection from EQ-DAQ-01(port 5050) */
    if(E1Flag) {
      E1Flag = false;
      
      ProcessTextStream(EQ_ONE, (char*)RX_BUF);
    }
    
    /* 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);
    }
    
    /* 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 TOBEUSED   with port 8080
    
    /* Socket 4 to 7 reserved for future application
     * 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
     */
  }
}