Esempio n. 1
0
char SSerial::serialGetchar()
{
	if (!connected) {
		printf( "Getchar()  not connected\n");		//return -1;
		return 0;
	}
	
	//printf( "Getchar() "); fflush(stdout);
	char      buff[3];
	const long int LOOPS = 600000;
	int c;
	long int count=0;
	if (available()) {
//	do {	
			c = ::read( fd, (void*)&buff, 1 );
			if (c==0) printf("0");
			else if (c==-1) printf("?");
			else printf("%c", buff[0]);		
			return buff[0];
		}
		else {
			printf("no data\n");
			return 0;
		}
		
//			count++;
//	} while ((c==0) || ((c==-1) && (count<LOOPS)));

	//printf( "c=%d; count=%d; ", c, count); 	fflush(stdout);
	if (count>=LOOPS) {
		buff[0] = -1;
		printf("timeout!\n");
		return 0;
	}
//	else
//		printf(" %x_%c ", buff[0], buff[0]);
		

}
Esempio n. 2
0
void QNativeWifiEngine::disconnectFromId(const QString &id)
{
    QMutexLocker locker(&mutex);

    if (!available()) {
        locker.unlock();
        emit connectionError(id, InterfaceLookupError);
        return;
    }

    QString interface = getInterfaceFromId(id);

    if (interface.isEmpty()) {
        locker.unlock();
        emit connectionError(id, InterfaceLookupError);
        return;
    }

    QStringList split = interface.mid(1, interface.length() - 2).split('-');

    GUID guid;
    guid.Data1 = split.at(0).toUInt(0, 16);
    guid.Data2 = split.at(1).toUShort(0, 16);
    guid.Data3 = split.at(2).toUShort(0, 16);
    guid.Data4[0] = split.at(3).left(2).toUShort(0, 16);
    guid.Data4[1] = split.at(3).right(2).toUShort(0, 16);
    for (int i = 0; i < 6; ++i)
        guid.Data4[i + 2] = split.at(4).mid(i*2, 2).toUShort(0, 16);

    DWORD result = local_WlanDisconnect(handle, &guid, 0);
    if (result != ERROR_SUCCESS) {
#ifdef BEARER_MANAGEMENT_DEBUG
        qDebug("%s: WlanDisconnect failed with error %ld\n", __FUNCTION__, result);
#endif
        locker.unlock();
        emit connectionError(id, DisconnectionError);
        return;
    }
}
Esempio n. 3
0
uint8_t REDFLY::socketClosed(uint8_t socket)
{
    if(available()) //check for new data, if socket closed?
    {
        uint8_t sock=INVALID_SOCKET;
        uint16_t len=0;
        socketRead(&sock, &len, 0, 0, 0, 0);
    }

    if(socket != INVALID_SOCKET)
    {
        for(uint8_t i=0; i<MAX_SOCKETS; i++)
        {
            if(socket_state[i].handle == socket) //socket found
            {
                return 0;
            }
        }
    }

    return 1;
}
Esempio n. 4
0
bool recvfromAck(uint8_t* buf, uint8_t* len, uint8_t* from, uint8_t* to, uint8_t* id, uint8_t* flags)
{
	uint8_t _from;
	uint8_t _to;
	uint8_t _id;
	uint8_t _flags;
	// Get the message before its clobbered by the ACK (shared rx and tx buffer in some drivers
	if (available() && recvfrom(buf, len, &_from, &_to, &_id, &_flags))
	{
		// Never ACK an ACK
		if (!(_flags & RH_FLAGS_ACK))
		{
			// Its a normal message for this node, not an ACK
			if (_to != RH_BROADCAST_ADDRESS)
			{
				// Its not a broadcast, so ACK it
				// Acknowledge message with ACK set in flags and ID set to received ID
				acknowledge(_id, _from);
			}
			// If we have not seen this message before, then we are interested in it
			if (_id != _seenIds[_from])
			{
				if (from)
					*from = _from;
				if (to)
					*to = _to;
				if (id)
					*id = _id;
				if (flags)
					*flags = _flags;
				_seenIds[_from] = _id;
				return true;
			}
			// Else just re-ack it and wait for a new one
		}
	}
	// No message for us available
	return false;
}
Esempio n. 5
0
void pr_ivec_block(FILE *fp,int indent,const char *title,int vec[],int n, bool bShowNumbers)
{
    int i,j;
    
    if (available(fp,vec,indent,title))
    {
        indent=pr_title_n(fp,indent,title,n);
        i = 0;
        while (i < n)
        {
            j = i+1;
            while (j < n && vec[j] == vec[j-1]+1)
            {
                j++;
            }
            /* Print consecutive groups of 3 or more as blocks */
            if (j - i < 3)
            {
                while(i < j)
                {
                    (void) pr_indent(fp,indent);
                    (void) fprintf(fp,"%s[%d]=%d\n",
                                   title,bShowNumbers?i:-1,vec[i]);
                    i++;
                }
            }
            else
            {
                (void) pr_indent(fp,indent);
                (void) fprintf(fp,"%s[%d,...,%d] = {%d,...,%d}\n",
                               title,
                               bShowNumbers?i:-1,
                               bShowNumbers?j-1:-1,
                               vec[i],vec[j-1]); 
                i = j;
            }
        }
    }
}
Esempio n. 6
0
void RF24Mesh::handlePacket()
{
	int count=0;
	// Is there anything ready for us?
  while ( available() )
  {
	  IF_SERIAL_DEBUG(printf_P(PSTR("There are available received message %d \n\r"),count++));

    // If so, take a look at it 
    RF24NetworkHeader header;
    peek(header);

    // Dispatch the message to the correct handler.
    switch (header.type)
    {
	case 'J':
		handle_JoinMessage(header);
		break;
    case 'W':
      handle_WelcomeMessage(header);
      break;
    case 'D':
      handle_DataMessage(header);
      break;
	case 'F':
	  handle_ForwardData(header);
	  break;
	case 'U':
	  handle_UpdateWeightMessage(header);
	  break;
    default:
	  printf_P(PSTR("*** WARNING *** Unknown message type %s\n\r"),header.toString());
      read(header,0,0);
      break;
    };
  }

}
Esempio n. 7
0
static void pr_cmap(FILE *fp, int indent, const char *title,
                    gmx_cmap_t *cmap_grid, gmx_bool bShowNumbers)
{
    int i,j,nelem;
    real dx,idx;
	
    dx    = 360.0 / cmap_grid->grid_spacing;
    nelem = cmap_grid->grid_spacing*cmap_grid->grid_spacing;
	
    if(available(fp,cmap_grid,indent,title))
    {
        fprintf(fp,"%s\n",title);
		
        for(i=0;i<cmap_grid->ngrid;i++)
        {
            idx = -180.0;
            fprintf(fp,"%8s %8s %8s %8s\n","V","dVdx","dVdy","d2dV");
			
            fprintf(fp,"grid[%3d]={\n",bShowNumbers?i:-1);
			
            for(j=0;j<nelem;j++)
            {
                if( (j%cmap_grid->grid_spacing)==0)
                {
                    fprintf(fp,"%8.1f\n",idx);
                    idx+=dx;
                }
				
                fprintf(fp,"%8.3f ",cmap_grid->cmapdata[i].cmap[j*4]);
                fprintf(fp,"%8.3f ",cmap_grid->cmapdata[i].cmap[j*4+1]);
                fprintf(fp,"%8.3f ",cmap_grid->cmapdata[i].cmap[j*4+2]);
                fprintf(fp,"%8.3f\n",cmap_grid->cmapdata[i].cmap[j*4+3]);
            }
            fprintf(fp,"\n");
        }
    }
	
}
Esempio n. 8
0
//
// skip()
//
size_t InputStream::skip(size_t n)
    throw(IOException)
{
    /* [email protected] 14/7/2004
    ignore((int) n);
    return (size_t) gcount();
    */

    unsigned char skip_buffer[SKIP_BUFFER_SIZE];

    if (n == 0)
    {
        return n;
    }

    size_t buff_available       = available();
    size_t to_skip              = min(n, buff_available);
    size_t to_read              = to_skip;
    size_t to_read_in_this_loop = 0;


    while (to_read > 0)
    {
        to_read_in_this_loop = min((unsigned int)to_read, SKIP_BUFFER_SIZE);

        size_t n_read = 0;
        while (n_read < to_read_in_this_loop)
        {
            size_t read_res = read(skip_buffer, SKIP_BUFFER_SIZE, 0,
                                   to_read_in_this_loop - n_read);
            n_read += read_res;
        }

        to_read -= to_read_in_this_loop;
    }

    return to_skip;
}
Esempio n. 9
0
int WiFiUDP::read(unsigned char* buf, size_t size)
{
	// sizeof(size_t) is architecture dependent
	// but we need a 16 bit data type here
	uint16_t size_tmp = available();
	
	if (size_tmp == 0) {
		return -1;
	}
	
	if (size < size_tmp) {
		size_tmp = size;
	}

	for (uint32_t i = 0; i < size_tmp; ++i) {
		buf[i] = _buffer[_tail++];
		_rcvSize--;

		if (_tail == _head) {
			// the full buffered data has been read, reset head and tail for next transfer
			_tail = _head = 0;

			// clear the buffer full flag
			_flag &= ~SOCKET_BUFFER_FLAG_FULL;

			// setup buffer and buffer size to transfer the remainder of the current packet
			// or next received packet
			if (hif_small_xfer) {
				recvfrom(_socket, _buffer, SOCKET_BUFFER_MTU, 0);
			} else {
				recvfrom(_socket, _buffer + SOCKET_BUFFER_UDP_HEADER_SIZE, SOCKET_BUFFER_MTU, 0);
			}
			m2m_wifi_handle_events(NULL);
		}
	}

	return size_tmp;
}
  void Client_connection::send(Request_ptr req, Response_handler on_res, const size_t bufsize, timeout_duration timeout)
  {
    Expects(available());
    req_ = std::move(req);
    on_response_ = std::move(on_res);
    Expects(on_response_ != nullptr);
    timeout_dur_ = timeout;

    if(timeout_dur_ > timeout_duration::zero())
      timer_.restart(timeout_dur_);

    // if the stream is not established, send the request when connected
    if(not stream_->is_connected())
    {
      stream_->on_connect([this, bufsize](auto&)
      {
        this->send_request(bufsize);
      });
    }
    else {
      send_request(bufsize);
    }
  }
Esempio n. 11
0
void CachedImage::download()
{
    if (_url.isEmpty() || isDownloading())
        return;

    if (_available)
    {
        emit available();
        return;
    }

    if (_headReply)
        _headReply->abort();

    _reply = _man->web()->get(QNetworkRequest(_url));

    Q_TEST(connect(_reply, SIGNAL(finished()),                         this, SLOT(_saveData())));
    Q_TEST(connect(_reply, SIGNAL(downloadProgress(qint64,qint64)),    this, SLOT(_changeBytes(qint64,qint64))));
    Q_TEST(connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(_printError(QNetworkReply::NetworkError))));
    Q_TEST(connect(_reply, SIGNAL(sslErrors(QList<QSslError>)),        this, SLOT(_printErrors(QList<QSslError>))));

    emit downloadingChanged();
}
Esempio n. 12
0
// -------------------------------------------------------------
int FlexCAN::read(CAN_message_t &msg)
{
  unsigned long int startMillis;

  startMillis = msg.timeout? millis() : 0;

  while( !available() ) {
    if ( !msg.timeout || (msg.timeout<=(millis()-startMillis)) ) {
      // early EXIT nothing here
      return 0;
    }
    yield();
  }

  // get identifier and dlc
  msg.len = FLEXCAN_get_length(FLEXCAN0_MBn_CS(rxb));
  msg.req = (FLEXCAN0_MBn_CS(rxb) & FLEXCAN_MB_CS_RTR)? 1:0;
  msg.ext = (FLEXCAN0_MBn_CS(rxb) & FLEXCAN_MB_CS_IDE)? 1:0;
  msg.id  = (FLEXCAN0_MBn_ID(rxb) & FLEXCAN_MB_ID_EXT_MASK);
  
  if(!msg.ext) {
    msg.id >>= FLEXCAN_MB_ID_STD_BIT_NO;
  }
Esempio n. 13
0
//0 for non-blocking (returns immediately), -1 for infinite blocking
/*virtual*/ int USBSerialStream::read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout/*=osWaitForever*/)
{
  DBG("Trying to read at most %d chars", maxLength);
  int ret = waitAvailable(timeout);
  if(ret)
  {
    WARN("Error %d while waiting for incoming data", ret);
    return ret;
  }
  int a = available(); //Prevent macro issues
  int readLen = MIN( a, maxLength );
  *pLength = readLen;

  setupReadableISR(false);
  while(readLen--)
  {
    m_inBuf.dequeue(buf);
    buf++;
  }
  setupReadableISR(true);
  DBG("Read %d chars successfully", *pLength);
  return OK;
}
Esempio n. 14
0
    /**
     *  Push Method: push the input value into the queue.\n
     *  If fixedsize has been set to \p true, this method may
     *  return false. This means EWOULDBLOCK
     *  and the call should be retried.
     *
     *  \param data Data to be pushed in the buffer
     *  \return \p false if \p fixedsize is set to \p true OR if \p data is NULL
     *  OR if there is not a buffer to write to.
     *
     *  \return \p true if the push succedes.
     */
    inline bool push(void * const data) {
        /* NULL values cannot be pushed in the queue */
        if (!data || !buf_w) return false;

        // If fixedsize has been set to \p true, this method may
        // return false. This means EWOULDBLOCK
        if (!available()) {

            if (fixedsize) return false;

            // try to get a new buffer
            INTERNAL_BUFFER_T * t = pool.next_w(size);
            assert(t); //if (!t) return false; // EWOULDBLOCK
            buf_w = t;
            in_use_buffers++;
#if defined(UBUFFER_STATS)
            atomic_long_inc(&numBuffers);
#endif
        }
        //DBG(assert(buf_w->push(data)); return true;);
        buf_w->push(data);
        return true;
    }
Esempio n. 15
0
void pr_mtop(FILE *fp,int indent,const char *title,gmx_mtop_t *mtop,
             gmx_bool bShowNumbers)
{
    int mt,mb;

    if (available(fp,mtop,indent,title)) {
        indent=pr_title(fp,indent,title);
        (void) pr_indent(fp,indent);
        (void) fprintf(fp,"name=\"%s\"\n",*(mtop->name));
        pr_int(fp,indent,"#atoms",mtop->natoms);
        for(mb=0; mb<mtop->nmolblock; mb++) {
            pr_molblock(fp,indent,"molblock",&mtop->molblock[mb],mb,
                        mtop->moltype,bShowNumbers);
        }
        pr_ffparams(fp,indent,"ffparams",&(mtop->ffparams),bShowNumbers);
        pr_atomtypes(fp,indent,"atomtypes",&(mtop->atomtypes),bShowNumbers);
        for(mt=0; mt<mtop->nmoltype; mt++) {
            pr_moltype(fp,indent,"moltype",&mtop->moltype[mt],mt,
                       &mtop->ffparams,bShowNumbers);
        }
        pr_groups(fp,indent,"groups",&mtop->groups,bShowNumbers);
    }
}
Esempio n. 16
0
uint8_t EthernetClient::connected()
{
	int rc;
	uint8_t val;
	
	if (available() > 0)
		return 1;
	
	if (sws == NULL) return 0;
	if (sws->_sock == SWS_INVALID_SOCKET)
		return 0;
	
	rc = SWS_recv(sws->_sock, &val, 1, 0);
	if (rc == 0)
		return 0;
	
	if (rc > 0) {
		_RegBuf = val;
		_RegLen = 1;
	}
	
	return 1;
}
Esempio n. 17
0
	/**
	 * Read one byte from the ring buffer with a timeout (~ in ms)
	 *
	 */
	static inline uint8_t read_char(unsigned char &byte, uint16_t timeout = 0) {
		uint16_t i = 0;
		uint8_t j = 0;

		// Hack for timeout
		if (timeout > 0)
			timeout *= 26;

		while (!available()) {
			if (timeout > 0) {
				if (i > timeout)
					return READ_TIMEOUT;
				if (j == 0)
					i++;
				j++;
			}
		}

		byte = rx_buffer_.buffer[rx_buffer_.tail];
		rx_buffer_.tail = (rx_buffer_.tail + 1) % RX_BUFFER_SIZE;

		return READ_SUCCESS;
	}
Esempio n. 18
0
void pr_ivecs(FILE *fp, int indent, const char *title, const ivec vec[], int n, gmx_bool bShowNumbers)
{
    int i, j;

    if (available(fp, vec, indent, title))
    {
        indent = pr_title_nxn(fp, indent, title, n, DIM);
        for (i = 0; i < n; i++)
        {
            pr_indent(fp, indent);
            fprintf(fp, "%s[%d]={", title, bShowNumbers ? i : -1);
            for (j = 0; j < DIM; j++)
            {
                if (j != 0)
                {
                    fprintf(fp, ", ");
                }
                fprintf(fp, "%d", vec[i][j]);
            }
            fprintf(fp, "}\n");
        }
    }
}
Esempio n. 19
0
void pr_rvecs_len(FILE *fp, int indent, const char *title, const rvec vec[], int n)
{
    int i, j;

    if (available(fp, vec, indent, title))
    {
        indent = pr_title_nxn(fp, indent, title, n, DIM);
        for (i = 0; i < n; i++)
        {
            pr_indent(fp, indent);
            fprintf(fp, "%s[%5d]={", title, i);
            for (j = 0; j < DIM; j++)
            {
                if (j != 0)
                {
                    fprintf(fp, ", ");
                }
                fprintf(fp, "%12.5e", vec[i][j]);
            }
            fprintf(fp, "} len=%12.5e\n", norm(vec[i]));
        }
    }
}
Esempio n. 20
0
void pr_mtop(FILE *fp, int indent, const char *title, const gmx_mtop_t *mtop,
             gmx_bool bShowNumbers)
{
    int mt, mb, j;

    if (available(fp, mtop, indent, title))
    {
        indent = pr_title(fp, indent, title);
        pr_indent(fp, indent);
        fprintf(fp, "name=\"%s\"\n", *(mtop->name));
        pr_int(fp, indent, "#atoms", mtop->natoms);
        pr_int(fp, indent, "#molblock", mtop->nmolblock);
        for (mb = 0; mb < mtop->nmolblock; mb++)
        {
            pr_molblock(fp, indent, "molblock", &mtop->molblock[mb], mb, mtop->moltype);
        }
        pr_str(fp, indent, "bIntermolecularInteractions",
               gmx::boolToString(mtop->bIntermolecularInteractions));
        if (mtop->bIntermolecularInteractions)
        {
            for (j = 0; (j < F_NRE); j++)
            {
                pr_ilist(fp, indent, interaction_function[j].longname,
                         mtop->ffparams.functype,
                         &mtop->intermolecular_ilist[j], bShowNumbers);
            }
        }
        pr_ffparams(fp, indent, "ffparams", &(mtop->ffparams), bShowNumbers);
        pr_atomtypes(fp, indent, "atomtypes", &(mtop->atomtypes), bShowNumbers);
        for (mt = 0; mt < mtop->nmoltype; mt++)
        {
            pr_moltype(fp, indent, "moltype", &mtop->moltype[mt], mt,
                       &mtop->ffparams, bShowNumbers);
        }
        pr_groups(fp, indent, &mtop->groups, bShowNumbers);
    }
}
/*!
* This method reads and empties the input buffer of `_dataStream`.
* It continues until it finds the specified prompt or until
* the specified amount of time has elapsed.
* It attempts to output the data it reads to `_diagStream`.
* @param prompt The prompt to read until.
* @param timeMS The time limit in milliseconds.
* @return `true` if it found the specified prompt within the time
* limit, otherwise `false`.
*/
bool Sodaq_WifiBee::skipTillPrompt(const char* prompt, const uint32_t timeMS)
{
  if (!_dataStream) {
    return false;
  }

  bool result = false;

  uint32_t startTS = millis();

  size_t index = 0;
  size_t promptLen = strlen(prompt);

  while (!timedOut32(startTS, timeMS)) {
    if (available()) {
      char c = read();
      diagPrint(c);

      if (c == prompt[index]) {
        index++;

        if (index == promptLen) {
          result = true;
          break;
        }
      }
      else {
        index = 0;
      }
    }
    else {
      _delay(10);
    }
  }

  return result;
}
Esempio n. 22
0
void pr_ilist(FILE *fp,int indent,const char *title,
              t_functype *functype,t_ilist *ilist, gmx_bool bShowNumbers)
{
    int i,j,k,type,ftype;
    t_iatom *iatoms;
    
    if (available(fp,ilist,indent,title) && ilist->nr > 0)
    {  
        indent=pr_title(fp,indent,title);
        (void) pr_indent(fp,indent);
        fprintf(fp,"nr: %d\n",ilist->nr);
        if (ilist->nr > 0) {
            (void) pr_indent(fp,indent);
            fprintf(fp,"iatoms:\n");
            iatoms=ilist->iatoms;
            for (i=j=0; i<ilist->nr;) {
#ifndef DEBUG
                (void) pr_indent(fp,indent+INDENT);
                type=*(iatoms++);
                ftype=functype[type];
                (void) fprintf(fp,"%d type=%d (%s)",
                               bShowNumbers?j:-1,bShowNumbers?type:-1,
                               interaction_function[ftype].name);
                j++;
                for (k=0; k<interaction_function[ftype].nratoms; k++)
                    (void) fprintf(fp," %u",*(iatoms++));
                (void) fprintf(fp,"\n");
                i+=1+interaction_function[ftype].nratoms;
#else
                fprintf(fp,"%5d%5d\n",i,iatoms[i]);
                i++;
#endif
            }
        }
    }
}
Esempio n. 23
0
void pr_idef(FILE *fp,int indent,const char *title,t_idef *idef, gmx_bool bShowNumbers)
{
  int i,j;
  
  if (available(fp,idef,indent,title)) {  
    indent=pr_title(fp,indent,title);
    (void) pr_indent(fp,indent);
    (void) fprintf(fp,"atnr=%d\n",idef->atnr);
    (void) pr_indent(fp,indent);
    (void) fprintf(fp,"ntypes=%d\n",idef->ntypes);
    for (i=0; i<idef->ntypes; i++) {
      (void) pr_indent(fp,indent+INDENT);
      (void) fprintf(fp,"functype[%d]=%s, ",
		     bShowNumbers?i:-1,
		     interaction_function[idef->functype[i]].name);
      pr_iparams(fp,idef->functype[i],&idef->iparams[i]);
    }
    (void) pr_real(fp,indent,"fudgeQQ",idef->fudgeQQ);

    for(j=0; (j<F_NRE); j++)
      pr_ilist(fp,indent,interaction_function[j].longname,
               idef->functype,&idef->il[j],bShowNumbers);
  }
}
Esempio n. 24
0
VavailabilityType OptSchedule::optScheduleToVavail()
{

	VavailabilityType::components_type components;

	ArrayOfVavailabilityContainedComponents::available_sequence asequence;

	vector<tavailable>::iterator itr;

	for (itr = m_vavailability.begin(); itr != m_vavailability.end(); itr++)
	{
		AvailableType::properties_type properties((*itr).get_dtstart(), (*itr).get_duration());

		ArrayOfVavailabilityContainedComponents::available_type available(properties);

		asequence.push_back(available);
	}

	components.available(asequence);

	VavailabilityType vavail(components);

	return vavail;
}
Esempio n. 25
0
void TwoWire::onService(void)
{
  if ( sercom->isSlaveWIRE() )
  {
    //Received data
    if(sercom->isDataReadyWIRE())
    {
      //Store data
      rxBuffer.store_char(sercom->readDataWIRE());

      //Stop or Restart detected
      if(sercom->isStopDetectedWIRE() || sercom->isRestartDetectedWIRE())
      {
        //Calling onReceiveCallback, if exists
        if(onReceiveCallback)
        {
          onReceiveCallback(available());
        }
      }
    }

    //Address Match
    if(sercom->isAddressMatch())
    {
      //Is a request ?
      if(sercom->isMasterReadOperationWIRE())
      {
        //Calling onRequestCallback, if exists
        if(onRequestCallback)
        {
          onRequestCallback();
        }
      }
    }
  }
}
Esempio n. 26
0
int HttpClient::skipResponseHeaders()
{
    isChunk = 0;
    header_line = "";
    
    // Just keep reading until we finish reading the headers or time out
    unsigned long timeoutStart = millis();
    // Whilst we haven't timed out & haven't reached the end of the headers
    while ((!endOfHeadersReached()) && 
           ( (millis() - timeoutStart) < iHttpResponseTimeout ))
    {
        if (available())
        {
            
            (void)readHeader();
            // We read something, reset the timeout counter
            timeoutStart = millis();
        }
        else
        {
            // We haven't got any data, so let's pause to allow some to
            // arrive
            delay(kHttpWaitForDataDelay);
        }
    }
    if (endOfHeadersReached())
    {
        // Success
        return HTTP_SUCCESS;
    }
    else
    {
        // We must've timed out
        return HTTP_ERROR_TIMED_OUT;
    }
}
Esempio n. 27
0
int MiLightRadio::begin()
{
  int retval = _pl1167.open();
  if (retval < 0) {
    return retval;
  }

  retval = _pl1167.setCRC(true);
  if (retval < 0) {
    return retval;
  }

  retval = _pl1167.setPreambleLength(3);
  if (retval < 0) {
    return retval;
  }

  retval = _pl1167.setTrailerLength(4);
  if (retval < 0) {
    return retval;
  }

  retval = _pl1167.setSyncword(0x147A, 0x258B);
  if (retval < 0) {
    return retval;
  }

  retval = _pl1167.setMaxPacketLength(8);
  if (retval < 0) {
    return retval;
  }

  available();

  return 0;
}
Esempio n. 28
0
int Me_Bluetooth::setName(String name)
{
	int isSuccess = 0;
	
	String recvBuf;
	char recvChar;
	
	String cmd("AT+NAME");
	cmd += name;
	cmd += '\r';
	cmd += '\n';
	int cmdLen = cmd.length();
	
	for(int i = 0; i < cmdLen; i++)
	{
		swSerial.write(cmd[i]);
	}
	
	delay(100);
	int len = 0;
	if(len = available())
	{
		for(int i = 0; i < len; i++)
		{
			recvChar = read();
			//Serial.print(recvChar);
			recvBuf += recvChar;
		}
		if(recvBuf.indexOf("OK") != -1)
		{
			isSuccess= 1;
		}
	}
	
	return isSuccess;
}
Esempio n. 29
0
void BlueTooth::receiveCommand()
{
  uint8_t buf[10];

  if(!m_lastConnectStatus || !available())
    return;

  size_t amt = read(buf, 10);

#ifdef DEBUG_BT
  printf("BT: got %u byte(s): ", amt);
#endif

  for(size_t i = 0; i < amt; i++)
  {
    uint8_t b = buf[i];
#ifdef DEBUG_BT
    printf("%x ", b);
#endif

    if(!m_inPacket) {
      if(buf[i] == '\e') {
#ifdef DEBUG_BT
        printf("Entering packet\n");
#endif
        m_inPacket = true;
        m_pktPtr = 0;
      }
      else
      {
#ifdef DEBUG_BT
        printf("[stray %02x]", b);
#endif
      }
      continue;
    }
Esempio n. 30
0
// Blocks until a valid message is received
void RHGenericDriver::waitAvailable()
{
    while (!available())
	YIELD;
}