1. bjoern
  2. arduino_osc

Commits

bjoern  committed 17128cd

Added sendPacket(char [],...) to send strings

  • Participants
  • Parent commits ac69880
  • Branches default

Comments (0)

Files changed (2)

File libraries/Ethernet/Udp.cpp

View file
 
 
 /* Send packet contained in buf of length len to peer at specified ip, and port */
+/* Use this function to transmit binary data that might contain 0x00 bytes*/
 /* This function returns sent data size for success else -1. */
 uint16_t UdpClass::sendPacket(uint8_t * buf, uint16_t len,  uint8_t * ip, uint16_t port){
 	return sendto(_sock,(const uint8_t *)buf,len,ip,port);
 }
 
+/* Send  zero-terminated string str as packet to peer at specified ip, and port */
+/* This function returns sent data size for success else -1. */
+uint16_t UdpClass::sendPacket(const char str[], uint8_t * ip, uint16_t port){	
+	// compute strlen
+	const char *s;
+	for(s = str; *s; ++s);
+	uint16_t len = (s-str);
+	// send packet
+	return sendto(_sock,(const uint8_t *)str,len,ip,port);
+}
 /* Is data available in rx buffer? Returns 0 if no, number of available bytes if yes. */
 int UdpClass::available() {
 	return getSn_RX_RSR(_sock);

File libraries/Ethernet/Udp.h

View file
 	
 public:
 	void begin(uint16_t);				// initialize, start listening on specified port
-	uint16_t sendPacket(uint8_t *, uint16_t, uint8_t *, uint16_t); //send a packet to specified peer
+	uint16_t sendPacket(uint8_t *, uint16_t, uint8_t *, uint16_t); //send a packet to specified peer 
+	uint16_t sendPacket(const char[], uint8_t *, uint16_t);  //send a string as a packet to specified peer
 	int available();								// has data been received?
 	uint16_t readPacket(uint8_t *, uint16_t);		// read a received packet 
 	uint16_t readPacket(uint8_t *, uint16_t, uint8_t *, uint16_t *);		// read a received packet, also return sender's ip and port