boolean VC0706::runCommand(uint8_t cmd, uint8_t *args, uint8_t argn, uint8_t resplen, boolean flushflag) { // flush out anything in the buffer? if (flushflag) { readResponse(100, 10); } // Serial.print("SerialNum: "); // Serial.println(serialNum); // Serial.print("command: "); // Serial.println(cmd); // Serial.print("argn: "); // Serial.println(argn); // Serial.print("args: "); // for (int ii = 0; ii < argn; ii++) // { // Serial.print(args[ii]); // Serial.print(","); // } // Serial.println("\n"); sendCommand(cmd, args, argn); if (readResponse(resplen, 200)!= resplen) { Serial.println("Response not the right length or too late"); return false; } if (! verifyResponse(cmd)) { return false; } return true; }
void DigiFi::endATMode() { //back to trasparent mode Serial1.print("AT+E\r"); debug(readResponse(0)); Serial1.print("AT+ENTM\r"); debug(readResponse(0)); debug("exit at mode"); }
boolean Camera::runCommand(uint8_t cmd, uint8_t *args, uint8_t argn, uint8_t resplen, boolean flushflag) { if (flushflag) { readResponse(100, 10); } sendCommand(cmd, args, argn); if (readResponse(resplen, 200) != resplen) return false; if (!verifyResponse(cmd)) return false; return true; }
bool DigiFi::get(char *aHost, char *aPath){ if(connect(aHost) == 1){ //delay(500); Serial1.print("GET "); Serial1.print(aPath); Serial1.print(" HTTP/1.1\r\nHost: "); Serial1.print(aHost); Serial1.print("\r\nCache-Control: no-cache\r\nConnection: close\r\n\r\n"); Serial1.flush(); //don't block while awating reply debug("wait for response..."); bool success = true; int i=0; int st = millis(); while(!Serial1.available()){ if(millis() - st > requestTimeout * 1000) { success = false; break; } if(((millis() - st) % 1000) == 1) debugWrite('.'); i++; } debug("get header"); if(success == false) return 0; aHeader = readResponse(0); debug(aHeader); String contentLength = aHeader.substring(aHeader.lastIndexOf("Content-Length: ")); contentLength = contentLength.substring(16,contentLength.indexOf("\n")); debug(contentLength); debug("get body"); aBody = readResponse(contentLength.toInt()); return 1; } else return 0; //To do: /* User agent! Better handle timeouts/other errors Actually look at returned header for status Efficiency! */ }
boolean camera_VC0706::runCommand(uint8_t cmd, uint8_t *args, uint8_t argn, uint8_t resplen, boolean flushflag) { // flush out anything in the buffer? if (flushflag) { readResponse(100, 10); } sendCommand(cmd, args, argn); if (readResponse(resplen, 200) != resplen) return false; if (! verifyResponse(cmd)) return false; return true; }
int runCommand(uint8_t cmd, uint8_t *args, uint8_t argn, uint8_t resplen, int flushflag) { // flush out anything in the buffer? if (flushflag) { readResponse(100, 10); } sendCommand(cmd, args, argn); if (readResponse(resplen, 200) != resplen) return 0; if (!verifyResponse(cmd)) return 0; return 1; }
/* This function does initiate a search for a keyword in all EPG Event of the Channel channel_id in sectionsd. The parameter search_typ does specify the search mode 0: none -> all EPG events of the channel are returned 1: keyword search in EPG Title 2: keyword search in EPG short description (INFO1) 3: keyword search in EPG description (INFO2) In case of a match, the EPG event is added to the Eventlist eList. */ bool CSectionsdClient::getEventsServiceKeySearchAdd(CChannelEventList& eList,const t_channel_id channel_id,char search_typ,std::string& search_text) { int nBufSize=0; nBufSize += sizeof(t_channel_id); nBufSize += sizeof(char); nBufSize += search_text.size()+1; char* pSData = new char[nBufSize]; char* pSData_ptr = pSData; *(t_channel_id*)pSData_ptr = channel_id; pSData_ptr += sizeof(t_channel_id); *pSData_ptr = search_typ; pSData_ptr += sizeof(char); strcpy(pSData_ptr,search_text.c_str()); if (send(sectionsd::allEventsChannelIDSearch, pSData, nBufSize)) { int nBufSize2 = readResponse(); if( nBufSize2 > 0) { char* pData = new char[nBufSize2]; receive_data(pData, nBufSize2); char* dp = pData; // int a = eList.size(); while(dp < pData + nBufSize2) { CChannelEvent aEvent; aEvent.eventID = *((event_id_t *) dp); dp+=sizeof(aEvent.eventID); aEvent.startTime = *((time_t *) dp); dp+=sizeof(aEvent.startTime); aEvent.duration = *((unsigned *) dp); dp+=sizeof(aEvent.duration); aEvent.description= dp; dp+=aEvent.description.length()+1; aEvent.text= dp; dp+=aEvent.text.length()+1; eList.push_back(aEvent); } // int b = eList.size() -a; delete[] pData; } } delete[] pSData; close_connection(); return true; }
void DigiFi::setPageDisplayMode(char *mode)//WEBSWITCH (iw|ew) { Serial1.print("AT+WEBSWITCH="); Serial1.print(mode); Serial1.print("\r"); readResponse(0); }
bool MtpDevice::sendObject(MtpObjectInfo* info, int srcFD) { Mutex::Autolock autoLock(mMutex); int remaining = info->mCompressedSize; mRequest.reset(); mRequest.setParameter(1, info->mHandle); if (sendRequest(MTP_OPERATION_SEND_OBJECT)) { // send data header writeDataHeader(MTP_OPERATION_SEND_OBJECT, remaining); char buffer[65536]; while (remaining > 0) { int count = read(srcFD, buffer, sizeof(buffer)); if (count > 0) { int written = mData.write(mRequestOut, buffer, count); // FIXME check error remaining -= count; } else { break; } } } MtpResponseCode ret = readResponse(); return (remaining == 0 && ret == MTP_RESPONSE_OK); }
std::string CSectionsdClient::getStatusinformation(void) { std::string ret = ""; if (send(sectionsd::dumpStatusinformation)) { int nBufSize = readResponse(); if( nBufSize > 0) { char* pData = new char[nBufSize]; if (!receive_data(pData, nBufSize)) { /* receive_data might have timed out etc. */ delete[] pData; close_connection(); return ret; // still empty. } ret = pData; delete[] pData; } else printf("no response from sectionsd\n"); } close_connection(); return ret; }
void DigiFi::setPageLanguage(char *lang)//PLANG CN|EN { Serial1.print("AT+PLANG="); Serial1.print(lang); Serial1.print("\r"); readResponse(0); }
bool CSectionsdClient::getNVODTimesServiceKey(const t_channel_id channel_id, CSectionsdClient::NVODTimesList& nvod_list) { if (send(sectionsd::timesNVODservice, (char*)&channel_id, sizeof(channel_id))) { nvod_list.clear(); int nBufSize = readResponse(); char* pData = new char[nBufSize]; receive_data(pData, nBufSize); char* dp = pData; CSectionsdClient::responseGetNVODTimes response; while( dp< pData+ nBufSize ) { response.service_id = *(t_service_id *) dp; dp += sizeof(t_service_id); response.original_network_id = *(t_original_network_id *) dp; dp += sizeof(t_original_network_id); response.transport_stream_id = *(t_transport_stream_id *) dp; dp += sizeof(t_transport_stream_id); response.zeit = *(CSectionsdClient::sectionsdTime*) dp; dp += sizeof(CSectionsdClient::sectionsdTime); nvod_list.insert( nvod_list.end(), response); } close_connection(); return true; } else { close_connection(); return false; } }
// Try to make the modem go to sleep. // It is recommended to call this after the modem has been // woken up through the wakeup pin. bool Hiber::goToSleep(GoToSleepResult *result, int *reason, int *seconds_left) { sendCommandName("go_to_sleep"); sendCommandFinish(); String arguments[2]; int arguments_returned = 0; short code = readResponse(arguments, 2, &arguments_returned); switch (code) { case RESPONSE_STARTING_TO_SLEEP: { int _reason = arguments[0].toInt(); if (_reason == 0) { *result = GTSR_OK_ONLY_WKUP0; } else { *result = GTSR_OK; } if (reason != nullptr) *reason = arguments[0].toInt(); if (reason != nullptr) *seconds_left = arguments[1].toInt(); return true; } case RESPONSE_CANNOT_SLEEP_WKUP0_HIGH: { *result = GTSR_WAKEUP0_HIGH; return false; } default: { *result = GTSR_ERROR; return false; } } }
CNetDataImpl* CNetRequestImpl::sendString(const String& strBody) { CNetDataImpl* pNetData = new CNetDataImpl; do { if ( isError() ) break; CAtlStringW strHeaders = L"Content-Type: application/x-www-form-urlencoded\r\n"; if ( !HttpAddRequestHeaders( hRequest, strHeaders, -1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE ) ) { pszErrFunction = L"HttpAddRequestHeaders"; break; } if ( !HttpSendRequest( hRequest, NULL, 0, const_cast<char*>(strBody.c_str()), strBody.length() ) ) { pszErrFunction = L"HttpSendRequest"; break; } //Sleep(5000); readResponse(pNetData); }while(0); return pNetData; }
void CSectionsdClient::freeMemory() { send(sectionsd::freeMemory); readResponse(); close_connection(); }
void DigiFi::setWifiCfgPassword(char *aswd) { Serial1.print("AT+ASWD="); Serial1.print(aswd); Serial1.print("\r"); readResponse(0); }
void DigiFi::setModId(char *modid)//WRMID { Serial1.print("AT+WRMID="); Serial1.print(modid); Serial1.print("\r"); readResponse(0); }
void DigiFi::setSleepMode(char *mode) { Serial1.print("AT+MSLP="); Serial1.print(mode); Serial1.print("\r"); readResponse(0); }
void DigiFi::setUpgradeFile(char *filename) { Serial1.print("AT+UPFILE="); Serial1.print(filename); Serial1.print("\r"); readResponse(0); }
void DigiFi::setUpgradeUrl(char *url)//url,filename (filename is optional, if provided upgrade is auto started) { Serial1.print("AT+UPURL="); Serial1.print(url); Serial1.print("\r"); readResponse(0); }
void CSectionsdClient::writeSI2XML(const char * epgxmlname) { send(sectionsd::writeSI2XML, (char*) epgxmlname, strlen(epgxmlname)); readResponse(); close_connection(); }
CNetResponseImpl* CNetRequestImpl::downloadFile(common::CRhoFile& oFile) { CNetResponseImpl* pNetResp = new CNetResponseImpl; do { if ( isError() ) break; if ( !HttpSendRequest( hRequest, NULL, 0, NULL, 0 ) ) { pszErrFunction = L"HttpSendRequest"; break; } readResponse(pNetResp); if ( isError() ) break; readInetFile(hRequest,pNetResp, &oFile); }while(0); return pNetResp; }
// The mother- generic request method. // int RestClient::request(const char* method, const char* path, const char* body, String* response){ HTTP_DEBUG_PRINT("HTTP: connect\n"); if(client.connect(host, port)){ HTTP_DEBUG_PRINT("HTTP: connected\n"); HTTP_DEBUG_PRINT("REQUEST: \n"); // Make a HTTP request line: write(method); write(" "); write(path); write(" HTTP/1.1\r\n"); for(int i=0; i<num_headers; i++){ write(headers[i]); write("\r\n"); } write("Host: "); write(host); write("\r\n"); write("Connection: close\r\n"); if(body != NULL){ char contentLength[30]; sprintf(contentLength, "Content-Length: %d\r\n", strlen(body)); write(contentLength); if(!contentTypeSet){ write("Content-Type: application/x-www-form-urlencoded\r\n"); } } write("\r\n"); if(body != NULL){ write(body); write("\r\n"); write("\r\n"); } //make sure you write all those bytes. delay(100); HTTP_DEBUG_PRINT("HTTP: call readResponse\n"); int statusCode = readResponse(response); HTTP_DEBUG_PRINT("HTTP: return readResponse\n"); //cleanup HTTP_DEBUG_PRINT("HTTP: stop client\n"); num_headers = 0; client.stop(); delay(50); HTTP_DEBUG_PRINT("HTTP: client stopped\n"); return statusCode; }else{ HTTP_DEBUG_PRINT("HTTP Connection failed\n"); return 0; } }
bool CSectionsdClient::getEPGid(const event_id_t eventid, const time_t starttime, CEPGData * epgdata) { sectionsd::commandGetEPGid msg; msg.eventid = eventid; msg.starttime = starttime; if (send(sectionsd::epgEPGid, (char *)&msg, sizeof(msg))) { int nBufSize = readResponse(); if (nBufSize > 0) { char* pData = new char[nBufSize]; if (!receive_data(pData, nBufSize)) { /* receive_data might have timed out etc. */ delete[] pData; close_connection(); return false; } close_connection(); char* dp = pData; epgdata->eventID = *((event_id_t *)dp); dp+= sizeof(epgdata->eventID); epgdata->title = dp; dp+=strlen(dp)+1; epgdata->info1 = dp; dp+=strlen(dp)+1; epgdata->info2 = dp; dp+=strlen(dp)+1; // 21.07.2005 - rainerk // Convert line-terminated extended events to vector of strings dp = parseExtendedEvents(dp, epgdata); // *dp is the length, dp+1 is the chararray[] epgdata->contentClassification = std::string(dp+1, *dp); dp+=*dp+1; epgdata->userClassification = std::string(dp+1, *dp); dp+=*dp+1; epgdata->fsk = *dp++; epgdata->epg_times.startzeit = ((CSectionsdClient::sectionsdTime *) dp)->startzeit; epgdata->epg_times.dauer = ((CSectionsdClient::sectionsdTime *) dp)->dauer; dp+= sizeof(CSectionsdClient::sectionsdTime); delete[] pData; return true; } else printf("no response from sectionsd\n"); } close_connection(); return false; }
// Requests a GPS fix on the modem. Will enqueue the request // and handle it in the background. You can put the wakeup pin // low and the modem will automatically go back to sleep when // either a fix or a timeout occurred. bool Hiber::doGPSFix() { sendCommandName("do_gps_fix"); sendCommandFinish(); return readResponse() == RESPONSE_OK; }
void CSectionsdClient::setPrivatePid(const unsigned short pid) { send(sectionsd::setPrivatePid, (char*)&pid, sizeof(pid)); readResponse(); close_connection(); }
void CSectionsdClient::setEventsAreOldInMinutes(const unsigned short minutes) { send(sectionsd::setEventsAreOldInMinutes, (char*)&minutes, sizeof(minutes)); readResponse(); close_connection(); }
void CSectionsdClient::setSectionsdScanMode(const int scanMode) { send(sectionsd::setSectionsdScanMode, (char*)&scanMode, sizeof(scanMode)); readResponse(); close_connection(); }
int ESP8266_XYZ::httpGet(const char* server, String path, int port, String *response){ String msg = ""; String server_str = server; if(connectServer(server, port)){ #ifdef DEBUG Serial.println("Connected to server"); #endif } else { #ifdef DEBUG Serial.println("Connection Failure"); #endif } server_str += ":"; server_str += String(port); //GET HTTP/1.1\r\nHost: \r\n\r\n //Solicitud HTTP al servidor //Header msg += "GET "; msg += path; msg += " HTTP/1.1\r\nHost: "; msg += server_str; msg += "\r\n\r\n"; //Se envía el mensaje al servidor client.print(msg); //Se obtiene el código de estado de la solicitud return readResponse(response); }
void CSectionsdClient::readSIfromXML(const char * epgxmlname) { send(sectionsd::readSIfromXML, (char*) epgxmlname, strlen(epgxmlname) + 1); // include '\0' readResponse(); close_connection(); }