unsigned int CNetBase::NetWorkThread(DWORD Onwer) { if( m_bConnectDestroy ) { return 0; } ConnectInfo* pConnect = (ConnectInfo*)Onwer; char* pnetdata = new char[RECEIVEBUFLEN]; int iLen; while( pConnect->m_bConnect ) { Sleep( 1 ); iLen = recv( pConnect->m_Socket, pnetdata, RECEIVEBUFLEN, 0 ); if( iLen > 0 ) { pConnect->SaveData( pnetdata, iLen ); } if( pConnect->IsHavdData() ) //取道缓冲数据 { //触发事件 //PostMessage( pConnect->m_hWnd, pConnect->m_dwEventID, (DWORD)pConnect,0 ); NetProcess((DWORD)pConnect, 0 ); } if( pConnect->m_SendLen > 0 ) //发送数据 { EnterCriticalSection( &pConnect->m_SendCritSect ); iLen = send( pConnect->m_Socket, pConnect->m_pSendMemPool, pConnect->m_SendLen, 0 ); if( iLen > 0 ) { pConnect->m_SendLen = 0; } else { int er = WSAGetLastError(); char temp[32]; JK_SPRITF(temp, "%d\n", er); //OutputDebugString( temp ); } LeaveCriticalSection( &pConnect->m_SendCritSect ); } } delete[] pnetdata; pConnect->m_bIsClosed = true; return 0; }
void main(void) { /* Clock configuration -----------------------------------------*/ CLK_Config(); /* GPIO configuration ------------------------------------------*/ GPIO_Config_Init(); UART1_Config(); UART3_Config(); PWM_Config(); TIM2_Config(); TIM3_Config(); TIM4_Config(); I2C_RTC_Init(); /* Enable general interrupts */ enableInterrupts(); //【秒, 分, 时, 日, 星期, 月, 年】 uint8_t time[] = {00, 12, 10, 1, 1, 6, 15}; //Set_RT8563(time, 2, 7); ResetNetMode(); #if 0 uint8_t Alarm[5][3] = {1, 16, 31, 1, 16, 33, 1, 16, 35}; uint8_t Time[7] = {0}; uint8_t AlarmState = 0; uint8_t AlarmDelay = 1; unsigned int NET_AUTO_SEND = 0; #endif while (1) { #if 0 Delay(1000); Send_BAT_Voltage(Get_BAT_Value()); UART3_SendString("\n", 1); AQI2PM25(Get_DS_Value()); #endif if(DeviceStatus.Time_30ms == 1) { TouchKey_Read(); DeviceStatus.Time_30ms = 0; } if(DeviceStatus.Time_100ms == 1) { if(UART1_GetFlagStatus(UART1_FLAG_IDLE) == SET) { if(DataSize != 0) { DataResolve(RxRecvBuffer, DataSize); NetProcess(); DataSize = 0; } } DeviceStatus.Time_100ms = 0; } if(DeviceStatus.Time_1_s == 1) { Get_RT8563(time, 2, 7); #if 0 ArrayCopy((uint8_t *)&NetMode.SendData, time, 7); UART3_SendString((uint8_t *)&NetMode.SendData, 7); if(NetMode.Status & NET_CONNECT) { NET_LED_FLASH; NET_AUTO_SEND++; if(NET_AUTO_SEND == 10)//自动发送数据 { NetSendDataLength(); NET_AUTO_SEND = 0; } } else NET_AUTO_SEND = 0; #endif DeviceStatus.Time_1_s = 0; } if(DeviceStatus.Time_30_s == 1) { NetModeErrorFix(); DeviceStatus.Time_30_s = 0; } #if 0 GetTime(Time); if(ArrayCMP(Alarm, Time, 3) == 0 && AlarmState == 0) { GPIO_WriteHigh(GPIOF, GPIO_PIN_5); FAN_SPEED_HIGH; //高速 Alarm[2] += AlarmDelay; AlarmState = 1; } else if(ArrayCMP(Alarm, Time, 3) == 0 && AlarmState == 1) { GPIO_WriteLow(GPIOF, GPIO_PIN_5); FAN_SPEED_OFF; AlarmState = 0; Alarm[2] -= AlarmDelay; } #endif } }