当前位置: 首页>>代码示例>>C++>>正文


C++ EthernetUDP::write方法代码示例

本文整理汇总了C++中EthernetUDP::write方法的典型用法代码示例。如果您正苦于以下问题:C++ EthernetUDP::write方法的具体用法?C++ EthernetUDP::write怎么用?C++ EthernetUDP::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EthernetUDP的用法示例。


在下文中一共展示了EthernetUDP::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: send

void WakeOnLan::send(byte* mac, byte port, EthernetUDP udp) {

    byte preamble[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
	
    byte i;

    udp.beginPacket(_ip, port);
	
    udp.write(preamble, sizeof preamble);
    
    for (i = 0; i < 16; i++)
	
      udp.write(mac, sizeof mac);
      
    udp.endPacket();

#else // ARDUINO not defined or ARDUINO < 100

void WakeOnLan::send(byte* mac, byte port) {

	byte magic_packet[102] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
	
	for (byte i = 6; i < 102; i++)
	{
		magic_packet[i] = mac[i%6];		
	}
	
	Udp.sendPacket(magic_packet, 102, _ip, port);	

#endif // #if defined(ARDUINO) && ARDUINO >= 100

}
开发者ID:snargledorf,项目名称:WakeOnLan-Arduino,代码行数:32,代码来源:WakeOnLan.cpp

示例2: loop

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  char Size[4];
  if(packetSize)
  {
    if(packetSize == 4)
    {
      IPAddress remote = Udp.remoteIP();
    
      // read the packet into packetBufffer
      Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
      char Command[4];
      for(int nCom = 0; nCom < 4; nCom++)
        {
        Command[nCom] = packetBuffer[nCom];
        }
            
      if (Command[0] == 't')
      {
        digitalWrite(13, HIGH);
      }
      else if (Command[0] == 'r')
      {
        digitalWrite(12, HIGH);
      }
      else if (Command[0] == 'e')
      {
        digitalWrite(10, HIGH);
      }   
      else if (Command[0] == 'w')
      {
        analogWrite(11, 65);
      }      
      else
      {
        digitalWrite(13, LOW);
        digitalWrite(12, LOW);
        analogWrite(11, 0);
      }

      // send a reply, to the IP address and port that sent us the packet we received
      itoa(packetSize, Size, 10);
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      Udp.write(ReplyBuffer);
      Udp.write(packetBuffer);
      Udp.write(Size);
      Udp.endPacket();
    delay(1000);
    }
    else
    {
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      Udp.write("NOPE");
      Udp.endPacket();
    }
  }
}
开发者ID:osu-underwater,项目名称:materov2013,代码行数:58,代码来源:acknowledger.cpp

示例3: UDP_Send_Data

// --------------------------------------------------- Ethernet Send Data -----------------------------------------------------------
void UDP_Send_Data()

{
	Udp.beginPacket(ip_rpi, rpi_port);
	Udp.write(nav.ch, sizeof(nav.data));
	Udp.write(cam.ch, sizeof(cam.pose));
	Udp.write(imu.ch, sizeof(imu.imu_data));
	Udp.endPacket();
}
开发者ID:mcprakash,项目名称:ROV_UMN,代码行数:10,代码来源:base_fcns.cpp

示例4: writePacket

void SNMPClass::writePacket(IPAddress address, uint16_t port, char *extra_data)
{
  Udp.beginPacket(address, port);
  Udp.write(_packet+_packetPos+1, _packetSize);
  
  if(extra_data != NULL){
    Udp.write((byte*)extra_data, _extra_data_size);
  }
  
  Udp.endPacket();
}
开发者ID:rexpark,项目名称:Arduino-SNMP,代码行数:11,代码来源:ArduinoSNMP.cpp

示例5: sendNTPpacket

void sendNTPpacket(const byte *address)
/**
 * send an NTP request to the time server at the given address
 */
{
    // set all bytes in the buffer to 0
    memset(pb, 0, NTP_PACKET_SIZE);

    // Initialize values needed to form NTP request
    // (see URL above for details on the packets)
    pb[0] = 0b11100011;   // LI, Version, Mode
    pb[1] = 0;     // Stratum, or type of clock
    pb[2] = 6;     // Polling Interval
    pb[3] = 0xEC;  // Peer Clock Precision
    // 8 bytes of zero for Root Delay & Root Dispersion
    pb[12]  = 49;
    pb[13]  = 0x4E;
    pb[14]  = 49;
    pb[15]  = 52;

    // all NTP fields have been given values, now
    // you can send a packet requesting a timestamp:
    Udp.beginPacket(address, 123); //NTP requests are to port 123
    Udp.write(pb,NTP_PACKET_SIZE);
    Udp.endPacket();
}
开发者ID:mechatrocity,项目名称:greenOmatic,代码行数:26,代码来源:Ethernets.cpp

示例6: uartToUdp

void uartToUdp()
{
  bool sendIt = false;

  if (Serial.available() > 0)
  {
    uartBuffer[uartCounter] = Serial.read();
    if (uartBuffer[uartCounter] == HDLC_SS_BYTE)
    {
      if (hdlcStart)sendIt = true;
      else
      {
        hdlcStart = true;
        Timer1.start();
      }
    }
    else if (hdlcStart)
    {
      ++uartCounter;
    }
  }

  if (sendIt)
  {
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(uartBuffer, uartCounter);
    Udp.endPacket();
    resetUartBuffer();
  }
}
开发者ID:cytrus77,项目名称:Arduinosy,代码行数:30,代码来源:RET_Emu_NKI.cpp

示例7: roveEthernet_SendUdpPacket

roveEthernet_Error roveEthernet_SendUdpPacket(roveIP destIP, uint16_t destPort, const uint8_t* msg, size_t msgSize)
{
  udpReceiver.beginPacket(destIP, destPort);
  udpReceiver.write(msg, msgSize);
  udpReceiver.endPacket();
  return ROVE_ETHERNET_ERROR_SUCCESS;
}
开发者ID:MST-MRDT,项目名称:RoveBoard-Energia,代码行数:7,代码来源:RoveEthernet.cpp

示例8: logger

void SyslogClass::logger(uint8_t facility, uint8_t severity, const char tag[], const char message[]) {
        String Pri;

        Pri="<";
        Pri+=(8 * facility + severity);
        Pri+=">";
  
        char UDPBufferPri[Pri.length()+1];
        Pri.toCharArray(UDPBufferPri,Pri.length()+1);

        SyslogUdp.beginPacket(ip_syslogserver, SYSLOG_DEFAULT_PORT);

        SyslogUdp.write(UDPBufferPri);
        SyslogUdp.write(tag);
        SyslogUdp.write(" ");
        SyslogUdp.write(message);
        SyslogUdp.endPacket();
}
开发者ID:apdlv72,项目名称:SwitchControl,代码行数:18,代码来源:Syslog.cpp

示例9: sendUdp

int sendUdp( char * data, int size )
{
  if ( ! active ) return 0 ;
  
  Udp.beginPacket(*timeServerAddress, serverPort);
  byte count = Udp.write((const unsigned char *)data,size);
  Udp.endPacket();
  return (int) count ;
}
开发者ID:phord,项目名称:master_clock,代码行数:9,代码来源:Udp.cpp

示例10: sendUDPNotification

void Notification::sendUDPNotification(EthernetUDP &udpSocket, aJsonObject *pushurl_channel, char *payload1, extData payload2)
{
  Serial.print(F("Sending a UDP response: "));
  Serial.println(payload1);

  udpSocket.beginPacket(udpSocket.remoteIP(), udpSocket.remotePort());

  // The actual payload
  udpSocket.write(payload1);

  // Extra payload is generated by running a callback function
  if (payload2 != NULL)
  {
    (*payload2)(&udpSocket);
  }

  udpSocket.write("}"); // The end of the JSON data, i.e. '}'
  udpSocket.endPacket();
}
开发者ID:ToniA,项目名称:arduino-wp-heatpump-controller,代码行数:19,代码来源:Notification.cpp

示例11: sendNtpPacket

void sendNtpPacket(IPAddress& address)
{
	// set all bytes in the buffer to 0
	memset(packetBuffer, 0, NTP_PACKET_SIZE); 

	// Initialize values needed to form NTP request
	packetBuffer[0] = 0b11100011;   // LI, Version, Mode
	packetBuffer[1] = 0;     // Stratum, or type of clock
	packetBuffer[2] = 6;     // Polling Interval
	packetBuffer[3] = 0xEC;  // Peer Clock Precision

	// 8 bytes of zero for Root Delay & Root Dispersion
	packetBuffer[12]  = 49; 
	packetBuffer[13]  = 0x4E;
	packetBuffer[14]  = 49;
	packetBuffer[15]  = 52;

	// all NTP fields have been given values, now
	// you can send a packet requesting a timestamp:         
	Udp.beginPacket(address, 123); //NTP requests are to port 123
	Udp.write(packetBuffer,NTP_PACKET_SIZE);
	Udp.endPacket(); 
  
}
开发者ID:chuckhinson,项目名称:lizard,代码行数:24,代码来源:ntptime.cpp

示例12: commandInterfaceTick

void commandInterfaceTick() {
  int packetSize = cmdsock.parsePacket();
  if(cmdsock.available()) {
    
    // read the packet into packetBufffer
    cmdsock.read(udpPacketBuffer, PACKET_SIZE);

    if(memcmp("INGV\0", udpPacketBuffer, 5) != 0) {
      return;
    }

    bool reboot = false;
    unsigned long unixTimeM = getUNIXTime();
    unsigned long uptime = getUNIXTime() - getBootTime();
    byte macaddress[6] = { 0 };
    getMACAddress(macaddress);
    uint32_t probeSpeed = getProbeSpeedStatistic();
    uint32_t freeramkb = freeMemory();
    float latency = 0;
    if(udpPacketBuffer[5] == PKTTYPE_GETINFO) {
      latency = tcpLatency();
    }

    float longitude = 0;
    float latitude = 0;

    switch(udpPacketBuffer[5]) {
      case PKTTYPE_DISCOVERY:
        // Reply to discovery
        udpPacketBuffer[5] = PKTTYPE_DISCOVERY_REPLY;

        memcpy(udpPacketBuffer + 6, macaddress, 6);
        
        memcpy(udpPacketBuffer + 12, getVersionAsString().c_str(), 4);
        memcpy(udpPacketBuffer + 16, "uno", 3);
        break;
      case PKYTYPE_PING:
        // Reply to ping
        udpPacketBuffer[5] = PKYTYPE_PONG;
        break;
      case PKTTYPE_SENDGPS:
        // Get coords
        udpPacketBuffer[5] = PKTTYPE_OK;

        memcpy(&latitude, udpPacketBuffer + 12, 4);
        memcpy(&longitude, udpPacketBuffer + 16, 4);
        reverse4bytes((byte*)&latitude);
        reverse4bytes((byte*)&longitude);
        
        break;
      case PKTTYPE_REBOOT:
        // Reboot
        // Reply with OK
        udpPacketBuffer[5] = PKTTYPE_OK;
        reboot = true;
        break;
      case PKTTYPE_GETINFO:
        udpPacketBuffer[5] = PKTTYPE_GETINFO_REPLY;

        memcpy(udpPacketBuffer + 6, macaddress, 6);
        memcpy(udpPacketBuffer + 28, &uptime, 4);
        memcpy(udpPacketBuffer + 32, &unixTimeM, 4);
        memcpy(udpPacketBuffer + 36, VERSION, 4);
        memcpy(udpPacketBuffer + 40, &freeramkb, 4);
        memcpy(udpPacketBuffer + 44, &latency, 4);
        memcpy(udpPacketBuffer + 53, "uno", 3);
        memcpy(udpPacketBuffer + 57, "MMA7361", 7);
        memcpy(udpPacketBuffer + 65, &probeSpeed, 4);

        break;
#ifdef RESET_ENABLED
      case PKTTYPE_RESET:
        initEEPROM();
        reboot = true;
        break;
#endif
      default:
        // Unknown packet or invalid command
        return;
    }

    if(longitude != 0 && latitude != 0) {
      setLongitude(longitude);
      setLatitude(latitude);
    }

    cmdsock.beginPacket(cmdsock.remoteIP(), cmdsock.remotePort());
    cmdsock.write(udpPacketBuffer, PACKET_SIZE);
    cmdsock.endPacket();
    cmdsock.flush();

    if(reboot) {
      soft_restart();
    }
  }
}
开发者ID:sapienzaapps,项目名称:seismoclouddevice-arduino,代码行数:96,代码来源:CommandInterface.cpp

示例13: gatewayTransportSend

bool gatewayTransportSend(MyMessage &message)
{
	bool ret = true;
	char *_ethernetMsg = protocolFormat(message);

    setIndication(INDICATION_GW_TX);

	_w5100_spi_en(true);
	#if defined(MY_CONTROLLER_IP_ADDRESS)
		#if defined(MY_USE_UDP)
			_ethernetServer.beginPacket(_ethernetControllerIP, MY_PORT);
			_ethernetServer.write(_ethernetMsg, strlen(_ethernetMsg));
			// returns 1 if the packet was sent successfully
			ret = _ethernetServer.endPacket();
		#else
			EthernetClient client;
			#if defined(MY_CONTROLLER_URL_ADDRESS)
	                	if (client.connected() || client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
	        	#else
	                	if (client.connected() || client.connect(_ethernetControllerIP, MY_PORT)) {
	        	#endif
	                	client.write(_ethernetMsg, strlen(_ethernetMsg));
	                }
	                else {
	                	// connecting to the server failed!
	                	ret = false;
	                }
		#endif
	#else
		// Send message to connected clients
		#if defined(MY_GATEWAY_ESP8266)
			for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++)
			{
				if (clients[i] && clients[i].connected())
				{
					clients[i].write((uint8_t*)_ethernetMsg, strlen(_ethernetMsg));
				}
			}
		#else
			_ethernetServer.write(_ethernetMsg);
		#endif
	#endif
	_w5100_spi_en(false);
	return ret;

}


#if defined(MY_GATEWAY_ESP8266)
	bool _readFromClient(uint8_t i) {
		while (clients[i].connected() && clients[i].available()) {
			char inChar = clients[i].read();
			if (inputString[i].idx < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
				// if newline then command is complete
				if (inChar == '\n' || inChar == '\r') {
					// Add string terminator and prepare for the next message
					inputString[i].string[inputString[i].idx] = 0;
					debug(PSTR("Client %d: %s\n"), i, inputString[i].string);
					inputString[i].idx = 0;
					if (protocolParse(_ethernetMsg, inputString[i].string)) {
						return true;
					}

				} else {
					// add it to the inputString:
					inputString[i].string[inputString[i].idx++] = inChar;
				}
			} else {
				// Incoming message too long. Throw away
				debug(PSTR("Client %d: Message too long\n"), i);
				inputString[i].idx = 0;
				// Finished with this client's message. Next loop() we'll see if there's more to read.
				break;
			}
		}
		return false;
	}
#else
	bool _readFromClient() {
		while (client.connected() && client.available()) {
			char inChar = client.read();
			if (inputString.idx < MY_GATEWAY_MAX_RECEIVE_LENGTH - 1) {
				// if newline then command is complete
				if (inChar == '\n' || inChar == '\r') {
					// Add string terminator and prepare for the next message
					inputString.string[inputString.idx] = 0;
					debug(PSTR("Eth: %s\n"), inputString.string);
					inputString.idx = 0;
					if (protocolParse(_ethernetMsg, inputString.string)) {
						return true;
					}

				} else {
					// add it to the inputString:
					inputString.string[inputString.idx++] = inChar;
				}
			} else {
				// Incoming message too long. Throw away
				debug(PSTR("Eth: Message too long\n"));
				inputString.idx = 0;
//.........这里部分代码省略.........
开发者ID:Clio75,项目名称:MySensors,代码行数:101,代码来源:MyGatewayTransportEthernet.cpp

示例14: responsePdu

SNMP_API_STAT_CODES AgentuinoClass::responsePdu(SNMP_PDU *pdu)
{
	int32_u u;
	byte i;
	//
	// Length of entire SNMP packet
	_packetPos = 0;  // 23
	_packetSize = 25 + sizeof(pdu->requestId) + sizeof(pdu->error) + sizeof(pdu->errorIndex) + pdu->OID.size + pdu->VALUE.size;
	//
	memset(_packet, 0, SNMP_MAX_PACKET_LEN);
	//
	if ( _dstType == SNMP_PDU_SET ) {
		_packetSize += _setSize;
	} else {
		_packetSize += _getSize;
	}
	//
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_SEQUENCE;	// type
	_packet[_packetPos++] = (byte)_packetSize - 2;		// length
	//
	// SNMP version
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_INT;	// type
	_packet[_packetPos++] = 0x01;			// length
	_packet[_packetPos++] = 0x00;			// value
	//
	// SNMP community string
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_OCTETS;	// type
	if ( _dstType == SNMP_PDU_SET ) {
		_packet[_packetPos++] = (byte)_setSize;	// length
		for ( i = 0; i < _setSize; i++ ) {
			_packet[_packetPos++] = (byte)_setCommName[i];
		}
	} else {
		_packet[_packetPos++] = (byte)_getSize;	// length
		for ( i = 0; i < _getSize; i++ ) {
			_packet[_packetPos++] = (byte)_getCommName[i];
		}
	}
	//
	// SNMP PDU
	_packet[_packetPos++] = (byte)pdu->type;
	_packet[_packetPos++] = (byte)( sizeof(pdu->requestId) + sizeof((int32_t)pdu->error) + sizeof(pdu->errorIndex) + pdu->OID.size + pdu->VALUE.size + 14 );
	//
	// Request ID (size always 4 e.g. 4-byte int)
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_INT;	// type
	_packet[_packetPos++] = (byte)sizeof(pdu->requestId);
	u.int32 = pdu->requestId;
	_packet[_packetPos++] = u.data[3];
	_packet[_packetPos++] = u.data[2];
	_packet[_packetPos++] = u.data[1];
	_packet[_packetPos++] = u.data[0];
	//
	// Error (size always 4 e.g. 4-byte int)
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_INT;	// type
	_packet[_packetPos++] = (byte)sizeof((int32_t)pdu->error);
	u.int32 = pdu->error;
	_packet[_packetPos++] = u.data[3];
	_packet[_packetPos++] = u.data[2];
	_packet[_packetPos++] = u.data[1];
	_packet[_packetPos++] = u.data[0];
	//
	// Error Index (size always 4 e.g. 4-byte int)
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_INT;	// type
	_packet[_packetPos++] = (byte)sizeof(pdu->errorIndex);
	u.int32 = pdu->errorIndex;
	_packet[_packetPos++] = u.data[3];
	_packet[_packetPos++] = u.data[2];
	_packet[_packetPos++] = u.data[1];
	_packet[_packetPos++] = u.data[0];
	//
	// Varbind List
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_SEQUENCE;	// type
	_packet[_packetPos++] = (byte)( pdu->OID.size + pdu->VALUE.size + 6 ); //4
	//
	// Varbind
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_SEQUENCE;	// type
	_packet[_packetPos++] = (byte)( pdu->OID.size + pdu->VALUE.size + 4 ); //2
	//
	// ObjectIdentifier
	_packet[_packetPos++] = (byte)SNMP_SYNTAX_OID;	// type
	_packet[_packetPos++] = (byte)(pdu->OID.size);
	for ( i = 0; i < pdu->OID.size; i++ ) {
		_packet[_packetPos++] = pdu->OID.data[i];
	}
	//
	// Value
	_packet[_packetPos++] = (byte)pdu->VALUE.syntax;	// type
	_packet[_packetPos++] = (byte)(pdu->VALUE.size);
	for ( i = 0; i < pdu->VALUE.size; i++ ) {
		_packet[_packetPos++] = pdu->VALUE.data[i];
	}
	//
	Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
	Udp.write(_packet, _packetSize);
	Udp.endPacket();
//	Udp.write(_packet, _packetSize, _dstIp, _dstPort);
	//
	return SNMP_API_STAT_SUCCESS;
}
开发者ID:1sw,项目名称:Agentuino,代码行数:99,代码来源:Agentuino.cpp

示例15: send_message

/**
 * Copies an external byte array into _packet and then sends it out.
 * 
 * Original Auther: Rex Park
 * Added: November 8, 2015 (Designed to be used with a system that resends informs that haven't been acknowledged)
 */
void SNMPClass::send_message(IPAddress address, uint16_t port, byte *packet, uint16_t packet_size){
  Udp.beginPacket(address, port);
  Udp.write(packet, packet_size);
  Udp.endPacket();
}
开发者ID:rexpark,项目名称:Arduino-SNMP,代码行数:11,代码来源:ArduinoSNMP.cpp


注:本文中的EthernetUDP::write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。