/* * As getAsync() but it waits until message arrives. * Useful when command needs an answer but it is provided by async. transmission. */ uint8_t MWiFi::getAsyncWait(unsigned long ms) { setTimer(ms); uint8_t cd=0; while(WIFISerial.available()==0) {delay(10);if(getTimeout()) {return cd;}} return getAsync(); }
/* * Specialized stream for GPIO command. */ void MWiFi::sendGPMessage(int gp,int s) { GPIOMESS[6]=(uint8_t)gp; GPIOMESS[7]=(uint8_t)s; int i;for (i=0;i<9;i++) WIFISerial.write(GPIOMESS[i]); uint8_t ev=getAsync(); //eventually read async mess (simulate polling) #if WIFIDEBUG if(ev!=0) printAsync(ev); Serial.print(" > "); for (i=0;i<6;i++) {Serial.print(GPIOMESS[i],HEX);Serial.print(" ");} #endif }
/* * Create a stream of minimum standard length (7) with code command and no command data. */ void MWiFi::sendShortMess(uint8_t code) { PREAMBLE[2]=code; memset(&PREAMBLE[3],0,3); int i;for (i=0;i<6;i++) WIFISerial.write(PREAMBLE[i]); WIFISerial.write(0x45); uint8_t ev=getAsync(); //eventually read async mess (simulate polling) #if WIFIDEBUG if(ev!=0) printAsync(ev); Serial.print(" > "); for (i=0;i<6;i++) {Serial.print(PREAMBLE[i],HEX);Serial.print(" ");} Serial.print(0x45,HEX);Serial.println(); #endif }
/* * Create a stream with headers and trailer, containing a specialized message with its code, * length and command data. * Send command stream on WIFISerial. * And clean receive buffer reading possible async event. */ void MWiFi::sendLongMess(uint8_t code,uint8_t *buff,uint16_t len) { PREAMBLE[2]=code;PREAMBLE[3]=0; memcpy(&PREAMBLE[4],&len,2); int i; for (i=0;i<6;i++) WIFISerial.write(PREAMBLE[i]); for (i=0;i<len;i++) WIFISerial.write(buff[i]); WIFISerial.write(0x45); uint8_t ev=getAsync(); //eventually read async mess (simulate polling) #if WIFIDEBUG if(ev!=0) printAsync(ev); Serial.print(" > "); for (i=0;i<6;i++) {Serial.print(PREAMBLE[i],HEX);Serial.print(" ");} for (i=0;i<len;i++) {Serial.print(buff[i],HEX);Serial.print(" ");} Serial.print(0x45,HEX);Serial.println(); #endif }
ofHttpResponse ofxEmscriptenURLFileLoader::get(string url){ getAsync(url,url); return ofHttpResponse(); }