/*快捷键*/ void CAdjustTestWaterTemperatureWindow::keyReleaseEvent(QKeyEvent *event) { if (!event->isAutoRepeat()) { if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { } else if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_A) { setProperty("testFlag",1); if(property("id").toInt() == 0) { setProperty("id", property("number").toInt() - 1); } else setProperty("id", property("id").toInt() - 1); _currentStep[property("id").toInt()]->setFocus(); sendFrame(0x3,0x1,_currentStep[property("id").toInt()]->value()); _centerGrid->removeWidget(_currentItem); _centerGrid->addWidget(_currentItem, 3, property("id").toInt() + 1); } else if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_D) { setProperty("testFlag",1); if(property("id").toInt() == property("number").toInt() - 1) { setProperty("id", 0); } else setProperty("id", property("id").toInt() + 1); _currentStep[property("id").toInt()]->setFocus(); sendFrame(0x3,0x1,_currentStep[property("id").toInt()]->value()); _centerGrid->removeWidget(_currentItem); _centerGrid->addWidget(_currentItem, 3, property("id").toInt() + 1); } else if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_W) { increaseButtonClicked(); } else if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_S) { decreaseButtonClicked(); } else if (event->modifiers() == Qt::ControlModifier && event->key() == Qt::Key_S) { saveAllAdjustButtonClicked(); } else if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_R) { readButtonClicked(); } else if (event->modifiers() == Qt::NoModifier && event->key() == Qt::Key_Z) { zeroButtonClicked(); } } }
void RTTeensyLink::processReceivedMessage() { RTTEENSYLINK_MESSAGE* message; // a pointer to the message part of the frame int identityLength; int suffixLength; message = & (m_RXFrameBuffer.message); // get the message pointer switch (message->messageType) { case RTTEENSYLINK_MESSAGE_POLL: case RTTEENSYLINK_MESSAGE_ECHO: RTTeensyLinkConvertIntToUC2(RTTEENSYLINK_MY_ADDRESS, message->messageAddress); sendFrame(&(m_RXFrameBuffer), m_RXFrameBuffer.messageLength); // just send the frame back as received break; case RTTEENSYLINK_MESSAGE_IDENTITY: identityLength = strlen(RTTeensyLinkConfig.identity); suffixLength = strlen(m_identitySuffix); memcpy(message->data, RTTeensyLinkConfig.identity, identityLength + 1); // copy in identity if ((identityLength + suffixLength) < RTTEENSYLINK_DATA_MAX_LEN - 1) { memcpy(message->data + identityLength, m_identitySuffix, suffixLength + 1); // copy in suffix } else { suffixLength = 0; } RTTeensyLinkConvertIntToUC2(RTTEENSYLINK_MY_ADDRESS, message->messageAddress); message->data[RTTEENSYLINK_DATA_MAX_LEN - 1] = 0; // make sure zero terminated if it was truncated sendFrame(&(m_RXFrameBuffer), RTTEENSYLINK_MESSAGE_HEADER_LEN + identityLength + suffixLength + 1); break; default: if (message->messageType < RTTEENSYLINK_MESSAGE_CUSTOM) { // illegal code message->data[0] = RTTEENSYLINK_RESPONSE_ILLEGAL_COMMAND; message->data[1] = message->messageType; // this is the offending code message->messageType = RTTEENSYLINK_MESSAGE_ERROR; RTTeensyLinkConvertIntToUC2(RTTEENSYLINK_MY_ADDRESS, message->messageAddress); sendFrame(&(m_RXFrameBuffer), RTTEENSYLINK_MESSAGE_HEADER_LEN + 2); break; } processCustomMessage(message->messageType, message->messageParam, message->data, m_RXFrameBuffer.messageLength - RTTEENSYLINK_MESSAGE_HEADER_LEN); // see if anyone wants to process it break; } }
TCPServerProcessor::TCPServerProcessor() : m_port(1337), m_waiting(false) { m_server = new Server(this); connect(this, SIGNAL( sendFrame(quint32,QVariantList)), m_server, SLOT( sendFrame(quint32,QVariantList)) ); //m_inputPinCvMatData = createCvMatDataInputPin( "image", this, IInputPin::CONNECTION_OPTIONAL ); //m_inputPinDouble = createInputPin<double>( "double_test", this, IInputPin::CONNECTION_OPTIONAL ); //m_inputPinCvScalar = createInputPin<cv::Scalar>( "cv::Scalar", this, IInputPin::CONNECTION_OPTIONAL ); plv::createDynamicInputPin( "generic pin", this, plv::IInputPin::CONNECTION_OPTIONAL ); }
/** * This function is used to send a chained frame. * * @param data * the data to be send */ int sendChainedFrame(struct file *filp,const unsigned char data[],int len) { int count_status=0 ; int length = len; int offset = 0; int ret=0; unsigned char *lastDataPackage=NULL; unsigned char *dataPackage=NULL; NFC_DBG_MSG(KERN_INFO "sendChainedFrame - Enter\n"); dataPackage = gDataPackage; do { NFC_DBG_MSG(KERN_INFO "sendChainedFrame \n"); // send a chained frame and receive the acknowledge memcpy(&dataPackage[0],&data[offset], ifs); count_status = sendFrame(filp,dataPackage, PH_SCAL_T1_CHAINING,ifs); if(count_status==0) { NFC_ERR_MSG(KERN_INFO "ERROR1: Failed to send Frame\n"); return -1; } receiveAcknowledge(filp); udelay(1000); length = length - ifs; offset = offset + ifs; ret += count_status; }while (length > ifs); #if 1 // send the last frame lastDataPackage = gDataPackage; memcpy(&lastDataPackage[0],&data[offset], length); count_status = sendFrame(filp,lastDataPackage, PH_SCAL_T1_SINGLE_FRAME,length); if(count_status == 0) { NFC_ERR_MSG(KERN_INFO "ERROR2:Failed to send Frame\n"); return -1; } #endif NFC_DBG_MSG(KERN_INFO "sendChainedFrame - Exit\n"); ret += count_status; return ret; }
void CanHandler::CANIO(CAN_FRAME& frame) { static CAN_FRAME CANioFrame; CANioFrame.id = CAN_OUTPUTS; CANioFrame.length = 8; CANioFrame.extended = 0; //standard frame CANioFrame.rtr = 0; for(int i=0; i==8; i++) { if(frame.data.bytes[i]==0x88)setOutput(i,true); if(frame.data.bytes[i]==0xFF)setOutput(i,false); } for(int i=0; i==8; i++) { if(getOutput(i))CANioFrame.data.bytes[i]=0x88; else CANioFrame.data.bytes[i]=0xFF; } sendFrame(CANioFrame); CANioFrame.id = CAN_ANALOG_INPUTS; int i=0; uint16_t anaVal; for(int j=0; j>6; j+=2) { anaVal=getAnalog(i++); CANioFrame.data.bytes[j]=highByte (anaVal); CANioFrame.data.bytes[j+1]=lowByte(anaVal); } sendFrame(CANioFrame); CANioFrame.id = CAN_DIGITAL_INPUTS; CANioFrame.length = 4; for(int i=0; i==4; i++) { if (getDigital(i))CANioFrame.data.bytes[i]=0x88; else CANioFrame.data.bytes[i]=0xff; } sendFrame(CANioFrame); }
void QAmqpChannelPrivate::close(const QAmqpMethodFrame &frame) { Q_Q(QAmqpChannel); qAmqpDebug(">> CLOSE"); QByteArray data = frame.arguments(); QDataStream stream(&data, QIODevice::ReadOnly); qint16 code = 0, classId, methodId; stream >> code; QString text = QAmqpFrame::readAmqpField(stream, QAmqpMetaType::ShortString).toString(); stream >> classId; stream >> methodId; QAMQP::Error checkError = static_cast<QAMQP::Error>(code); if (checkError != QAMQP::NoError) { error = checkError; errorString = qPrintable(text); Q_EMIT q->error(error); } qAmqpDebug(">> code: %d", code); qAmqpDebug(">> text: %s", qPrintable(text)); qAmqpDebug(">> class-id: %d", classId); qAmqpDebug(">> method-id: %d", methodId); Q_EMIT q->closed(); // complete handshake QAmqpMethodFrame closeOkFrame(QAmqpFrame::Channel, miCloseOk); closeOkFrame.setChannel(channelNumber); sendFrame(closeOkFrame); // notify everyone that the channel was closed on us. notifyClosed(); }
void TclClass::sendColor(byte red, byte green, byte blue) { byte flag; flag = makeFlag(red,green,blue); sendFrame(flag,red,green,blue); }
void AdminConnection::processGetCommandTypes(InputFrame::Ptr frame){ DEBUG("doing get command types frame"); OutputFrame::Ptr of = createFrame(frame); CommandManager::getCommandManager()->doGetCommandTypes(frame, of); sendFrame(of); }
void AdminConnection::processCommand(InputFrame::Ptr frame){ DEBUG("doing command frame"); OutputFrame::Ptr of = createFrame(frame); CommandManager::getCommandManager()->executeCommand(frame, of); sendFrame(of); }
void AdminConnection::processDescribeCommand(InputFrame::Ptr frame) { Logger::getLogger()->debug("doing describe command frame"); if(frame->getDataLength() < 4){ throw FrameException(fec_FrameError); } int numdesc = frame->unpackInt(); if(frame->getDataLength() < 4 + 4 * numdesc){ throw FrameException(fec_FrameError); } sendSequence(frame,numdesc); if(numdesc == 0){ DEBUG("asked for no commands to describe"); throw FrameException( fec_NonExistant, "You didn't ask for any command descriptions, try again"); } for(int i = 0; i < numdesc; i++){ OutputFrame::Ptr of = createFrame(frame); int cmdtype = frame->unpackInt(); CommandManager::getCommandManager()->describeCommand(cmdtype, of); sendFrame(of); } }
/** * @brief * * @return */ int HttpStream::run() { Select select( 60 ); select.addWriter( mConnection->socket() ); if ( !waitForProviders() ) return( 1 ); while ( !mStop && select.wait() >= 0 ) { if ( mStop ) break; Select::CommsList writeable = select.getWriteable(); if ( writeable.size() <= 0 ) { Error( "Writer timed out" ); mStop = true; break; } mQueueMutex.lock(); if ( !mFrameQueue.empty() ) { for ( FrameQueue::iterator iter = mFrameQueue.begin(); iter != mFrameQueue.end(); iter++ ) { sendFrame( writeable, *iter ); //delete *iter; } mFrameQueue.clear(); } mQueueMutex.unlock(); usleep( INTERFRAME_TIMEOUT ); } return( 0 ); }
void WsConnection::send(const string& message, bool binary) { char opcode = binary ? 0x2 : 0x1; //for utf-8, we assume message is already utf-8 sendFrame(true, opcode, message); }
void RFM69::send(uint8_t toAddress, const void* buffer, uint8_t bufferSize, bool requestACK) { writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks uint32_t now = millis(); while (!canSend() && millis() - now < RF69_CSMA_LIMIT_MS) receiveDone(); sendFrame(toAddress, buffer, bufferSize, requestACK, false); }
void comDemo() { //init USB if(initUSBCommunicationSync()!=0) { return; } //init UDP if(initCommunication()!=0) { return; } usleep(1000000); char type; uint32_t data0; uint32_t data1; uint32_t data2; uint32_t data3; uint32_t rss0; uint32_t rss1; uint32_t rss2; uint32_t rss3; while(1) { //read USB if(readUSBFrameSync(&type,&data0,&data1,&data2,&data3,&rss0,&rss1,&rss2,&rss3)==0) { //send UDP sendFrame(type,data0,data1,data2,STOP_MISSION); } } closeUSBCommunicationSync(); }
void debugger(){ Serial.write(START_TX); switch(serialCommand){ case PORTS_STATUS:{ Serial.write(PORTS_STATUS); //frame id byte frame[]={PINA, PINB, PINC, PINE, PINF, PING, PINH, 0}; sendFrame(frame); endTx(); break; } case PORT_CONFIG:{ Serial.write(PORT_CONFIG); Serial.println("test"); Serial.println(DDRA, BIN); Serial.println(DDRB, BIN); Serial.println(DDRC, BIN); Serial.println(DDRE, BIN); Serial.println(DDRF, BIN); Serial.println(DDRG, BIN); Serial.println(DDRH, BIN); endTx(); break; } default:{ Serial.println("Don't understand"); } } }
//------------------------------------------------------------------------------ bool BaseWebSocketSessionManager::sendBinary(AbstractWebSocketConnection* connection, unsigned char* data, std::size_t size) { WebSocketFrame frame(data,size,Poco::Net::WebSocket::FRAME_BINARY); return sendFrame(connection,frame); }
NcpSpi::NcpSpi(Instance *aInstance) : NcpBase(aInstance) , mTxState(kTxStateIdle) , mHandlingRxFrame(false) , mResetFlag(true) , mPrepareTxFrameTask(*aInstance, &NcpSpi::PrepareTxFrame, this) , mSendFrameLength(0) { SpiFrame sendFrame(mSendFrame); SpiFrame emptyFullAccept(mEmptySendFrameFullAccept); SpiFrame emptyZeroAccept(mEmptySendFrameZeroAccept); sendFrame.SetHeaderFlagByte(/* aResetFlag */ true); sendFrame.SetHeaderAcceptLen(0); sendFrame.SetHeaderDataLen(0); emptyFullAccept.SetHeaderFlagByte(/* aResetFlag */ true); emptyFullAccept.SetHeaderAcceptLen(kSpiBufferSize - kSpiHeaderSize); emptyFullAccept.SetHeaderDataLen(0); emptyZeroAccept.SetHeaderFlagByte(/* aResetFlag */ true); emptyZeroAccept.SetHeaderAcceptLen(0); emptyZeroAccept.SetHeaderDataLen(0); mTxFrameBuffer.SetFrameAddedCallback(HandleFrameAddedToTxBuffer, this); otPlatSpiSlaveEnable(&NcpSpi::SpiTransactionComplete, &NcpSpi::SpiTransactionProcess, this); // We signal an interrupt on this first transaction to // make sure that the host processor knows that our // reset flag was set. otPlatSpiSlavePrepareTransaction(mEmptySendFrameZeroAccept, kSpiHeaderSize, mEmptyReceiveFrame, kSpiHeaderSize, /* aRequestTras */ true); }
void RTArduLink::processReceivedMessage(RTARDULINK_PORT *portInfo) { RTARDULINK_MESSAGE *message; // a pointer to the message part of the frame unsigned int address; message = &(portInfo->RXFrameBuffer.message); // get the message pointer address = RTArduLinkConvertUC2ToUInt(message->messageAddress); switch (portInfo->index) { case RTARDULINK_HOST_PORT: processHostMessage(); // came from this upstream link return; case RTARDULINK_DAISY_PORT: // came from dasiy chain port if (address != RTARDULINK_HOST_PORT) // true if it came from a daisy chained subsystem, not a directly connected subsystem RTArduLinkConvertIntToUC2(address + RTARDULINKHAL_MAX_PORTS, message->messageAddress); else RTArduLinkConvertIntToUC2(RTARDULINK_DAISY_PORT, message->messageAddress); break; default: RTArduLinkConvertIntToUC2(address + portInfo->index, message->messageAddress); break; } // if get here, need to forward to host port sendFrame(m_hostPort, &(portInfo->RXFrameBuffer), portInfo->RXFrameBuffer.messageLength); }
virtual void initializeTransportAdapters() { // Preparing custom device adapter mpTransportAdapter = new MockTransportAdapter(*this, *this); EXPECT_CALL(*mpTransportAdapter, run()).Times(1); EXPECT_CALL(*mpTransportAdapter, scanForNewDevices()) .Times(1) .WillOnce(Invoke(mpTransportAdapter, &MockTransportAdapter::doScanForNewDevices)) ; EXPECT_CALL(*mpTransportAdapter, connectDevice(Data::DeviceHandle)) .Times(1) .WillOnce(Invoke(mpTransportAdapter, &MockTransportAdapter::doConnectDevice)) ; EXPECT_CALL(*mpTransportAdapter, sendFrame(Data::ConnectionHandle, _, 512, Data::UserData)) .Times(1) .WillOnce(Invoke(mpTransportAdapter, &MockTransportAdapter::doSendFrame)) ; EXPECT_CALL(*mpTransportAdapter, disconnectDevice(Data::DeviceHandle)) .Times(1) .WillOnce(Invoke(mpTransportAdapter, &MockTransportAdapter::doDisconnectDevice)) ; addTransportAdapter(mpTransportAdapter); LOG4CPLUS_INFO_EXT(mLogger, "Transport adapters initialized"); }
ssize_t WsConnection::handleMessage(const ConnectionPtr_t& conn, uint8_t opcode, const string& data) { switch(opcode) { case 0x1: //utf-8 data m_callback(shared_from_this(), Ws_MessageEvent, (void*)&data); break; case 0x2: //binary data m_callback(shared_from_this(), Ws_MessageEvent, (void*)&data); break; case 0x8: //clsoe m_callback(shared_from_this(), Ws_CloseEvent, 0); conn->shutDown(500); break; case 0x9: //ping sendFrame(true, 0xA, data); break; case 0xA: //pong m_callback(shared_from_this(), Ws_PongEvent, (void*)&data); break; default: //error LOG_ERROR("invalid opcode %d", opcode); return -1; } return 0; }
// TODO: Keep-Alive timer for connectivity monitoring. // Monitor latency/frequency for signal quality. void ARControlConnection::onPing(const ARControlFrame &frame) { sendFrame(frame.type, (quint8)ARNET_C2D_PONG_ID, frame.seq, frame.payload.data(), frame.payload.size()); }
void VideoDecoderThread::decodePacket(AVPacket* pPacket) { bool bGotPicture = m_pFrameDecoder->decodePacket(pPacket, m_pFrame, m_bSeekDone); if (bGotPicture) { m_bSeekDone = false; sendFrame(m_pFrame); } }
/** * send text data to client * @param num uint8_t client id * @param payload uint8_t * * @param length size_t * @param headerToPayload bool (see sendFrame for more details) */ void WebSocketsClient::sendTXT(uint8_t * payload, size_t length, bool headerToPayload) { if(length == 0) { length = strlen((const char *) payload); } if(clientIsConnected(&_client)) { sendFrame(&_client, WSop_text, payload, length, true, true, headerToPayload); } }
int main(int argc, char *argv[]) { int sock, n; unsigned int length; struct sockaddr_in server, from; struct hostent *hp; char buffer[256]; if (argc != 3) { printf("Usage: server port\n"); exit(1); } sock= socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) error("socket"); server.sin_family = AF_INET; hp = gethostbyname(argv[1]); if (hp==0) error("Unknown host"); bcopy((char *)hp->h_addr, (char *)&server.sin_addr, hp->h_length); server.sin_port = htons(atoi(argv[2])); length=sizeof(struct sockaddr_in); cout<<"connecting sock!\n"; string file = readAllFile("1.txt"); cout<<"file: "<<file<<endl; char* filep= (char*)malloc((file.size()+1)*sizeof(char)); memcpy(filep, file.c_str(), file.size()+1); cout<<"try to send "<<filep<<endl; sendFrame(filep, file.size()+1, address(0), address(0), sock, &server); /*Packet p; p.setData("salam", 6); p.send(sock, atoi(argv[2])); p.recive(sock, &from); p.getData(buffer); cout<<buffer<<endl; printf("Please enter the message: "); bzero(buffer,256); fgets(buffer,255,stdin); n=send(sock,buffer, strlen(buffer),0); if (n < 0) error("Sendto"); n = recvfrom(sock,buffer,256,0,(struct sockaddr *)&from, &length); if (n < 0) error("recvfrom"); write(1,"Got an ack: ",12); write(1,buffer,n);*/ close(sock); return 0; }
void SerialComFrame::startNetwork() { sof = 0xfe; cmd_0 = 0x0a; cmd_1 = 0x18; length = 00; sendFrame(); }
void CAdjustTestWaterTemperatureWindow::decreaseButtonClicked() { if(property("testFlag").toBool()) { int newv = _currentStep[property("id").toInt()]->value() - _currentAmount->value(); _currentStep[property("id").toInt()]->setValue(newv); sendFrame(0x3,0x1,newv); } }
/** * send binary data to client * @param num uint8_t client id * @param payload uint8_t * * @param length size_t */ void WebSocketsServer::sendBIN(uint8_t num, uint8_t * payload, size_t length) { if(num >= WEBSOCKETS_SERVER_CLIENT_MAX) { return; } WSclient_t * client = &_clients[num]; if(clientIsConnected(client)) { sendFrame(client, WSop_binary, payload, length); } }
void WebSocket::shutdown(Poco::UInt16 statusCode, const std::string& statusMessage) { Poco::Buffer<char> buffer(statusMessage.size() + 2); Poco::MemoryOutputStream ostr(buffer.begin(), buffer.size()); Poco::BinaryWriter writer(ostr, Poco::BinaryWriter::NETWORK_BYTE_ORDER); writer << statusCode; writer.writeRaw(statusMessage); sendFrame(buffer.begin(), static_cast<int>(ostr.charsWritten()), FRAME_FLAG_FIN | FRAME_OP_CLOSE); }
// should be called immediately after reception in case sender wants ACK void RFM69::sendACK(const void* buffer, uint8_t bufferSize) { uint8_t sender = SENDERID; int16_t _RSSI = RSSI; // save payload received RSSI value writeReg(REG_PACKETCONFIG2, (readReg(REG_PACKETCONFIG2) & 0xFB) | RF_PACKET2_RXRESTART); // avoid RX deadlocks uint32_t now = millis(); while (!canSend() && millis() - now < RF69_CSMA_LIMIT_MS) receiveDone(); sendFrame(sender, buffer, bufferSize, false, true); RSSI = _RSSI; // restore payload RSSI }
void Interface::resetDevice(void) { UCTK::Frame frame; frame.setId(PKT_ID_RESET); frame.setPayloadSize(0); if (!sendFrame(frame)) throw std::runtime_error(DTR("failed to reset device")); }