5 #include "IoTDeviceAddress.h"
6 #include "application.h"
10 // IoTUDP class for iotruntime
11 // Implemented based on IoTUDP.java that is used to wrap communication socket for UDP
13 // @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
19 // IoTUDP class properties
23 uint8_t* strHostAddress;
32 IoTUDP(IoTDeviceAddress* iotDevAdd) {
34 strHostAddress = iotDevAdd->getAddress();
35 iSrcPort = iotDevAdd->getSourcePortNumber();
36 iDstPort = iotDevAdd->getDestinationPortNumber();
39 //socket = new UDPSocket(iSrcPort);
40 socket.begin(iSrcPort);
49 uint8_t* getHostAddress() {
50 return strHostAddress;
59 int getDestinationPort() {
64 void setTimeOut(int interval) {
71 void sendData(const char* buffer, int bufferLen) {
72 //void sendData(const void* buffer, int bufferLen) {
73 unsigned short destinationPort = (unsigned short) iDstPort;
74 IPAddress ipFromBytes = strHostAddress;
75 socket.sendPacket(buffer, bufferLen, ipFromBytes, destinationPort);
76 //socket->sendTo(buffer, bufferLen, strHostAddress, destinationPort);
80 // Receive data packet
81 int receiveData(char* buffer, int iMaxDataLength) {
82 //int receiveData(void* buffer, int iMaxDataLength) {
83 //unsigned short destinationPort = (unsigned short) iDstPort;
84 return socket.receivePacket(buffer, iMaxDataLength);
85 //return socket->recvFrom(buffer, iMaxDataLength, strHostAddress, destinationPort);