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


C++ EthernetUDP类代码示例

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


在下文中一共展示了EthernetUDP类的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: listen

void AgentuinoClass::listen(void) {
    // if bytes are available in receive buffer
    // and pointer to a function (delegate function)
    // isn't null, trigger the function
    Udp.parsePacket();
    if (Udp.available() && _callback != NULL) (*_callback)();
}
开发者ID:johnyHV,项目名称:Arduino-SNMP,代码行数:7,代码来源:Agentuino.cpp

示例3: 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

示例4: begin

SNMP_API_STAT_CODES SNMPClass::begin(const char *getCommName, const char *setCommName, const char *trapCommName, uint16_t port)
{
  //initialize request counter
    requestCounter = 1;
    _extra_data_size = 0;
    _udp_extra_data_packet = false;
    
  // set community name set/get sizes
  _setSize = strlen(setCommName);
  _getSize = strlen(getCommName);
  _trapSize = strlen(trapCommName);
  //
  // validate get/set community name sizes
  if ( _setSize > SNMP_MAX_NAME_LEN + 1 || _getSize > SNMP_MAX_NAME_LEN + 1 || _trapSize > SNMP_MAX_NAME_LEN + 1) {
    return SNMP_API_STAT_NAME_TOO_BIG;
  }
  //
  // set community names
  _getCommName = getCommName;
  _setCommName = setCommName;
  _trapCommName = trapCommName;
  
  // validate session port number
  if ( port == NULL || port == 0 ) port = SNMP_DEFAULT_PORT;
  //
  // init UDP socket
  Udp.stop();
  Udp.begin(port);

  return SNMP_API_STAT_SUCCESS;
}
开发者ID:rexpark,项目名称:Arduino-SNMP,代码行数:31,代码来源: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: getNtpTime

time_t getNtpTime()
{
  while (Udp.parsePacket() > 0) ; // discard any previously received packets
  Serial.println("Transmit NTP Request");
  sendNTPpacket(ntp_server);
  uint32_t beginWait = millis();
  while (millis() - beginWait < 2000) {
    int size = Udp.parsePacket();
    if (size >= NTP_PACKET_SIZE) {
      Serial.println("Receive NTP Response");
      Udp.read(packetBuffer, NTP_PACKET_SIZE);  // read packet into the buffer
      unsigned long secsSince1900;
      unsigned long fracSecs;
      // convert four bytes starting at location 40 to a long integer
      secsSince1900 =  (unsigned long)packetBuffer[40] << 24;
      secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
      secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
      secsSince1900 |= (unsigned long)packetBuffer[43];
      fracSecs =  (unsigned long)packetBuffer[44] << 24;
      fracSecs |= (unsigned long)packetBuffer[45] << 16;
      fracSecs |= (unsigned long)packetBuffer[46] << 8;
      fracSecs |= (unsigned long)packetBuffer[47];
      return ((time_t)(secsSince1900 - 2208988800UL)<<32) + fracSecs;
    }
  }
  Serial.println("No NTP Response :-(");
  return 0; // return 0 if unable to get the time
}
开发者ID:Orthogonal-Systems,项目名称:amc7812,代码行数:28,代码来源:amc7812_monitoringServer_inet.cpp

示例7: readUdp

int readUdp( char * buf, int size )
{
  if ( ! active ) return 0 ;
  int count = Udp.parsePacket() ;
  if ( count ) Udp.read( buf, size ) ;
  return count ;
}
开发者ID:phord,项目名称:master_clock,代码行数:7,代码来源:Udp.cpp

示例8: 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

示例9: 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

示例10: 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

示例11: handleData

// This function's purpose is to receive data and prepare it for parsing
void RobotOpenClass::handleData() {
	_packetBufferSize = Udp.parsePacket();
    
    // If there's data, read the packet in
    if (_packetBufferSize > 0) {
		_remotePort = Udp.remotePort();
		_remoteIp = Udp.remoteIP();
		Udp.read(_packetBufferAccessor, 256);
		parsePacket();	// Data is all set, time to parse through it
    }
}
开发者ID:Team766,项目名称:RobotOpen2006,代码行数:12,代码来源:RobotOpen.cpp

示例12: 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

示例13: restartNtpTime

/*
 * Restart our ntp handler.  This is only done as part of restarting the
 * network.  As such, all we want to do is make sure udp is still working.
 * We dont need to issue a time request unless one was already outstanding
 * (not likely)
 */
void restartNtpTime() {

	Udp.stop();

	Udp.begin(8888);

	// If we were already waiting for a response, let's re-issue the request
	if (ntpState == WAITING_FOR_RESPONSE) {
		sendTimeRequest();
	}

}
开发者ID:chuckhinson,项目名称:lizard,代码行数:18,代码来源:ntptime.cpp

示例14: udpToUart

void udpToUart()
{
  int packetSize = Udp.parsePacket();
  if(packetSize)
  {
    // read the packet into packetBufffer
    Udp.read(udpBuffer,MAX_HDLC_FRAME_SIZE);
    Serial.write(HDLC_SS_BYTE);
    Serial.write(udpBuffer, packetSize);
    Serial.write(0x12);
    Serial.write(0x34);
    Serial.write(HDLC_SS_BYTE);
  }
}
开发者ID:cytrus77,项目名称:Arduinosy,代码行数:14,代码来源:RET_Emu_NKI.cpp

示例15: gatewayTransportInit

bool gatewayTransportInit() {
	_w5100_spi_en(true);
	#if defined(MY_GATEWAY_ESP8266)
		#if defined(MY_ESP8266_SSID)
			// Turn off access point
			WiFi.mode (WIFI_STA);
			#if defined(MY_ESP8266_HOSTNAME)
				WiFi.hostname(MY_ESP8266_HOSTNAME);
			#endif
			(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD);
			#ifdef MY_IP_ADDRESS
				WiFi.config(_ethernetGatewayIP, _gatewayIp, _subnetIp);
			#endif
			while (WiFi.status() != WL_CONNECTED)
			{
				delay(500);
				MY_SERIALDEVICE.print(".");
				yield();
			}
			MY_SERIALDEVICE.print(F("IP: "));
			MY_SERIALDEVICE.println(WiFi.localIP());
		#endif

	#else
		#ifdef MY_IP_ADDRESS
			Ethernet.begin(_ethernetGatewayMAC, _ethernetGatewayIP);
		#else
			// Get IP address from DHCP
			if (!Ethernet.begin(_ethernetGatewayMAC)) {
				MY_SERIALDEVICE.print("DHCP FAILURE...");
				_w5100_spi_en(false);
				return false;
			}
		#endif 
		MY_SERIALDEVICE.print(F("IP: "));
		MY_SERIALDEVICE.println(Ethernet.localIP());
		// give the Ethernet interface a second to initialize
		delay(1000);
	#endif

	#ifdef MY_USE_UDP
		_ethernetServer.begin(_ethernetGatewayPort);
	#else
		// we have to use pointers due to the constructor of EthernetServer
		_ethernetServer.begin();
	#endif /* USE_UDP */
	_w5100_spi_en(false);
	return true;
}
开发者ID:Clio75,项目名称:MySensors,代码行数:49,代码来源:MyGatewayTransportEthernet.cpp


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