bool Uart::Open(QString adresse){ // Default Settings für Conflict serial.settings.BaudRate = BAUD57600; serial.settings.DataBits = DATA_8; serial.settings.Parity = PAR_NONE; serial.settings.StopBits = STOP_1; serial.settings.FlowControl = FLOW_OFF; serial.settings.Timeout_Millisec = 0; // Portliste abrufen serial.portlist = QextSerialEnumerator::getPorts(); // Port öffnem serial.port = new QextSerialPort(serial.portlist.at(adresse.toInt()).portName,serial.settings); // Prüfen ob geöffnet if(serial.port->open(QextSerialPort::ReadWrite)){ timer = new QTimer(); timer->start(timerInterval); QObject::connect(timer, SIGNAL(timeout()),this,SLOT(sendData())); QObject::connect(serial.port, SIGNAL(readyRead()),this,SLOT(RcvData())); serial.portNr = adresse.toInt(); serial.open = true; return true; }else{ return false; } }
bool Uart::Close(){ if(serial.open == true){ QObject::disconnect(timer, SIGNAL(timeout()),this,SLOT(sendData())); QObject::disconnect(serial.port, SIGNAL(readyRead()),this,SLOT(RcvData())); serial.port->close(); serial.portNr = 0; serial.open = false; return true; }else{ return false; } }
/********************************************************** Method closes previously opened socket return: ERROR ret. val: --------------- -1 - comm. line is not in the data(GPRS) state OK ret val: ----------- 0 - socket was not closed 1 - socket was successfully closed an example of usage: GSM gsm; gsm.CloseSocket(); **********************************************************/ char GSM::CloseSocket(void) { char ret_val = -1; byte i; byte* rx_data; if (CLS_FREE == GetCommLineStatus()) { ret_val = 1; // socket was already closed return (ret_val); } // we are in the DATA state so try to close the socket // --------------------------------------------------- for (i = 0; i < 3; i++) { // make dalay 500msec. before escape seq. "+++" RcvData(1500, 100, &rx_data); // trick - function is used for generation a delay // send escape sequence +++ and wait for "NO CARRIER" SendData("+++"); if (RX_FINISHED_STR_RECV == WaitResp(5000, 1000, "OK")) { SetCommLineStatus(CLS_ATCMD); ret_val = SendATCmdWaitResp("AT+CIPCLOSE", 5000, 1000, "CLOSE OK", 2); if (ret_val == AT_RESP_OK) { // socket was successfully closed ret_val = 1; } else ret_val = 0; // socket was not successfully closed SetCommLineStatus(CLS_FREE); break; } else { // try common AT command just to be sure that the socket // has not been already closed ret_val = SendATCmdWaitResp("AT", 1000, 1000, "OK", 2); if (ret_val == AT_RESP_OK) { // socket was successfully closed ret_val = 1; SetCommLineStatus(CLS_FREE); break; } else { ret_val = 0; } } } return (ret_val); }
//static PT_THREAD(protothread_I2C(struct pt *pt)){ // PT_BEGIN(pt); // while(1){ // // PT_YIELD_TIME_msec(500); // } // PT_END(pt); //} static PT_THREAD(protothread_uart(struct pt *pt)) { // this thread interacts with the PC keyboard to take user input and set up PID parameters PT_BEGIN(pt); // send the prompt via DMA to serial sprintf(PT_send_buffer, "%s", "cmd>"); // by spawning a print thread PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output));//send date and time while (1) { temp = 0; temp = RcvData(addr); sprintf(PT_send_buffer, "%s%d%s", "Temperature value: " ,temp, "\n\r"); // by spawning a print thread PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output));//send date and time // //spawn a thread to handle terminal input // // the input thread waits for input // // -- BUT does NOT block other threads // // string is returned in "PT_term_buffer" // PT_SPAWN(pt, &pt_input, PT_GetSerialBuffer(&pt_input));//wait for input // sscanf(PT_term_buffer, "%s %f", cmd, &value); // // // echo // sprintf(PT_send_buffer,"%04x%s", rcv, "\n");//send original message // PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) ); // sprintf(PT_send_buffer,"\n");//next line // PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) ); // sprintf(PT_send_buffer,"\r");//carriage return // PT_SPAWN(pt, &pt_DMA_output, PT_DMA_PutSerialBuffer(&pt_DMA_output) ); PT_YIELD_TIME_msec(500); } // while(1) PT_END(pt); } // uart input thread
S32 CNetObj::Run() { DEBUG_INFO("CNetObj::Run()...\n"); //Test; //m_pStream->Open("E:\\Src\\Video\\TestVideo.avi", AV_STREAM_MODE); //m_bAvStreamSnd = true; S32 rSize = 0; S32 FreeLen = 0; timeval tv = { 0, 200 * 1000 }; fd_set rFds; fd_set wFds; fd_set * pWFds = NULL; m_bRuning = true; while (m_bRuning) { if (m_bResetSock) { if (MW_SUCC != m_Sock.Reconnect()) { sleep(3); continue; } m_bResetSock = false; } FD_ZERO(&rFds); FD_ZERO(&wFds); FD_SET(m_Sock.Handle(), &rFds); FD_SET(m_Sock.Handle(), &wFds); if (m_bAvStreamSnd) { pWFds = &wFds; } else { pWFds = NULL; } if (::select(m_Sock.Handle() + 1, &rFds, pWFds, NULL, &tv) <= 0) { continue; } if (FD_ISSET(m_Sock.Handle(), &rFds)) { FreeLen = m_RcvBuf.GetFreeLen(); if (FreeLen < 64) { DEBUG_INFO("The packet is to bigger...\n"); m_RcvBuf.Clear(); FreeLen = m_RcvBuf.GetFreeLen(); } rSize = RcvData(m_RcvBuf.GetWrPos(), FreeLen, 3); if (rSize > 0) { m_RcvBuf.AddDataLen(rSize); ParseData(); } } if (pWFds && FD_ISSET(m_Sock.Handle(), &wFds)) { SndAvStream(5); } } m_bSafeDelete = true; //ObjStop(); DEBUG_INFO("Session exit sHandle:%d\n", m_Sock.Handle()); return MW_SUCC; }