MBED implementation of JAudioStream
Diff: JAudioStream.cpp
- Revision:
- 1:b49a6e72f353
- Parent:
- 0:6f03883f9b43
- Child:
- 2:22ee01f24346
--- a/JAudioStream.cpp Wed Aug 12 13:19:20 2015 +0000 +++ b/JAudioStream.cpp Thu Aug 13 13:32:51 2015 +0000 @@ -1,34 +1,21 @@ #include "JAudioStream.h" -const char cont[] = {'c','o','n','t'}; -const char cond[] = {'c','o','n','d'}; -const char dcon[] = {'d','c','o','n'}; -const char rqst[] = {'r','q','s','t'}; -const char begn[] = {'b','e','g','n'}; -const char comt[] = {'c','o','m','t'}; - JAudioStream::JAudioStream() { connected = false; inTransmission = false; } -void JAudioStream::onUDPSocketEvent(UDPSocketEvent e) { - -} - void JAudioStream::begin(char* mac, char* ip, short port) { - EthernetErr ethErr = eth.setup(); - if (ethErr) { - // do something - } - Host me(IpAddr(), PORT); - udp.setOnEvent(this, &JAudioStream::onUDPSocketEvent); - udp.bind(me); + eth.init(); + eth.connect(); + udp.init(); + udp.set_blocking(true); } bool JAudioStream::connect(char* ip, short port, char* name) { remotePort = port; remoteIp = ip; + endPoint.set_address(ip, port); char size = MESSAGE_SIZE*2; char message[size]; buildMeassge(cont, REQUEST_RESPONSE_MODE, name, message); @@ -43,23 +30,10 @@ } bool JAudioStream::read(char *buffer, short amount, short timeOut) { - Timer t; - t.start(); - short to = t.read()+timeOut; bool result = false; - while (1) { - int packetSize = Udp.available(); - if (packetSize) { - Udp.readPacket(buffer, MAX_PACKT); - result = true; - break; - } - int c = t.read(); - if (to < c) { - break; - } + if (udp.receiveFrom(endPoint,buffer, MAX_PACKT) > 0) { + result = true; } - t.stop(); return result; } @@ -95,7 +69,7 @@ send(message, MESSAGE_SIZE); } -void JAudioStream::buildMeassge(const char* cmd, char param, char* message) { +void JAudioStream::buildMeassge(const char* cmd, int param, char* message) { char i; for(i=0; i<MESSAGE_COMP_SIZE; i++) { message[i] = cmd[i]; @@ -107,7 +81,7 @@ } } -void JAudioStream::buildMeassge(const char* cmd, char param, char* data, char* message) { +void JAudioStream::buildMeassge(const char* cmd, int param, char* data, char* message) { char i; for(i=0; i<MESSAGE_COMP_SIZE; i++) { message[i] = cmd[i]; @@ -123,7 +97,7 @@ } } -void JAudioStream::intTocharArr(char value, char* buff) { +void JAudioStream::intTocharArr(int value, char* buff) { buff[0] = (value >> 24) & 0xFF; buff[1] = (value >> 16) & 0xFF; buff[2] = (value >> 8) & 0xFF; @@ -131,7 +105,7 @@ } void JAudioStream::send(char* data, short len) { - udp.sendPacket(data, len, remoteIp, remotePort); + udp.sendTo(endPoint, data, len); } char* JAudioStream::getNowPlaying() {