static int CDC_Device_getchar(FILE* Stream) { if (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)))) return _FDEV_EOF; return CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)); }
static int CDC_Device_getchar_Blocking(FILE* Stream) { while (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)))) { if (USB_DeviceState == DEVICE_STATE_Unattached) return _FDEV_EOF; CDC_Device_USBTask((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)); USB_USBTask(); } return CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)); }
static int AOA_Host_getchar_Blocking(FILE* Stream) { int16_t ReceivedByte; while ((ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream))) < 0) { if (USB_HostState == HOST_STATE_Unattached) return _FDEV_EOF; AOA_Host_USBTask((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream)); USB_USBTask(); } return ReceivedByte; }
static int PRNT_Device_getchar_Blocking(FILE* Stream) { int16_t ReceivedByte; while ((ReceivedByte = PRNT_Device_ReceiveByte((USB_ClassInfo_PRNT_Device_t*)fdev_get_udata(Stream))) < 0) { if (USB_DeviceState == DEVICE_STATE_Unattached) return _FDEV_EOF; PRNT_Device_USBTask((USB_ClassInfo_PRNT_Device_t*)fdev_get_udata(Stream)); USB_USBTask(); } return ReceivedByte; }
int Serial_getchar_Blocking(FILE *Stream) { USART_t* USART = fdev_get_udata(Stream); while (!(Serial_IsCharReceived(USART))); return Serial_ReceiveByte(USART); }
int Serial_putchar(char DataByte, FILE *Stream) { USART_t* USART = fdev_get_udata(Stream); Serial_SendByte(USART, DataByte); return 0; }
int Device_getchar(FILE* Stream) { int16_t ReceivedByte = Device_ReceiveByte((USB_EPInfo_Device_t*)fdev_get_udata(Stream)); if (ReceivedByte < 0) return _FDEV_EOF; return ReceivedByte; }
static int CDC_Device_getchar(FILE* Stream) { int16_t ReceivedByte = CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)); if (ReceivedByte < 0) return _FDEV_EOF; return ReceivedByte; }
int Serial_getchar(FILE *Stream) { USART_t* USART = fdev_get_udata(Stream); if (!(Serial_IsCharReceived(USART))) return _FDEV_EOF; return Serial_ReceiveByte(USART); }
static int AOA_Host_getchar(FILE* Stream) { int16_t ReceivedByte = AOA_Host_ReceiveByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream)); if (ReceivedByte < 0) return _FDEV_EOF; return ReceivedByte; }
static int CDC_Device_putchar(char c, FILE* Stream) { if(c == 0x0A) { CDC_Device_putchar(0x0D, Stream); } return CDC_Device_SendByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0; }
static int CDC_Device_getchar_Blocking(FILE* Stream) { int16_t ReceivedByte = 0; while ((ReceivedByte = CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))) < 0) { if (USB_DeviceState != DEVICE_STATE_Unattached) { CDC_Device_USBTask((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream)); USB_USBTask(); } else { ReceivedByte = (int16_t)_FDEV_EOF; } } return ReceivedByte; }
int BetterStream::_getchar(FILE *stream) { BetterStream *bs; bs = (BetterStream *)fdev_get_udata(stream); // We return -1 if there is nothing to read, which the library interprets // as an error, which our clients will need to deal with. return(bs->read()); }
int BetterStream::_putchar(char c, FILE *stream) { BetterStream *bs; bs = (BetterStream *)fdev_get_udata(stream); if ('\n' == c) bs->write('\r'); // ASCII translation on the cheap bs->write(c); return(0); }
int buffer_stream_getchar(FILE *f) { buffer_stream_t *pbs; int c; pbs = fdev_get_udata(f); if( pbs->incb != NULL) { pbs->incb(pbs->pbufin); } c = buffer_get_char(pbs->pbufin); return c; }
int buffer_stream_putchar(char c, FILE *f) { buffer_stream_t *pbs; pbs = fdev_get_udata(f); buffer_append_char(pbs->pbufout, c); if( pbs->outcb != NULL) { pbs->outcb(pbs->pbufout); } return EOF; }
int HTTPClient::clientWrite(char byte, FILE* stream) { if (stream == NULL) { return EOF; } http_stream_udata* udata = (http_stream_udata*) fdev_get_udata(stream); HTTPClient* client = udata->client; if (client->connected() == 0) { closeStream(stream); return EOF; } if (udata->encode == 0) { client->write(byte); if (client->debugCommunication) { Serial.print(byte); } } else { if (URI_ALLOWED(byte) || ((URI_RESERVED(byte) && (udata->encode & URI_ENCODE_RESERVED) == 0))) { client->write(byte); if (client->debugCommunication) { Serial.print(byte); } } else { char encoded[4] = { 0, 0, 0 }; sprintf(encoded, "%%%2x", byte); // Write only the first three bytes, not the trailing null for (char i = 0; i < 3; i++) { client->write(encoded[i]); if (client->debugCommunication) { Serial.print(encoded[i]); } } } } return 0; }
void HTTPClient::closeStream(FILE* stream) { if (stream != NULL) { http_stream_udata* udata = (http_stream_udata*) fdev_get_udata(stream); if (udata->client->connected()) { udata->client->stop(); } free(udata); fclose(stream); } }
int stdGet(FILE * stream) { STATWORD ps; int ch; struct tty *iptr; disable(ps); iptr = (struct tty *)fdev_get_udata(stream); wait(iptr->isem); /* wait for a character in buff */ ch = 0xff & iptr->ibuff[iptr->itail++]; --iptr->icnt; if (iptr->itail >= IBUFLEN) iptr->itail = 0; if (iptr->ieof && (iptr->ieofc == ch) ) ch = EOF; restore(ps); return(ch); }
/* prototype for a pseudo driver BUT ONLY FOR tty */ int stdPut(char ch, FILE * stream) { STATWORD ps; struct tty *iptr; iptr = (struct tty *)fdev_get_udata(stream); if ( ch==NEWLINE && iptr->ocrlf ) stdPut(RETURN, stream); disable(ps); wait(iptr->osem); /* wait for space in queue */ iptr->obuff[iptr->ohead++] = ch; ++iptr->ocnt; if (iptr->ohead >= OBUFLEN) iptr->ohead = 0; *USART[iptr->unit].UCSRB |= (1<<UDRIE0); /*ttyostart(iptr);*/ restore(ps); return(OK); }
void HTTPClient::setEncoding(FILE* stream, char encode, char encodeReserved) { http_stream_udata* udata = (http_stream_udata*) fdev_get_udata(stream); if (encode == 0) { udata->encode = 0; } else { if (encodeReserved) { udata->encode = URI_ENCODE | URI_ENCODE_RESERVED; } else { udata->encode = URI_ENCODE; } } }
// Custom implementation of printf borrowed from the teensy core files static int16_t printf_putchar(char c, FILE *fp) { ((class Print *)(fdev_get_udata(fp)))->write((uint8_t)c); return 0; }
int uart_dev_send(char c, FILE *fp) { return uart_send(fdev_get_udata(fp), c); }
int HTTPClient::clientRead(FILE* stream) { if (stream == NULL) { return EOF; } http_stream_udata* udata = (http_stream_udata*) fdev_get_udata(stream); HTTPClient* client = udata->client; if (!client->connected()) { return EOF; } //block until we got a byte while (client->available() == 0) { if (client->connected() == 0) { return EOF; } }; int result = client->read(); if (result == EOF) { return EOF; } if (client->debugCommunication) { Serial.print((byte) result); } //as long as we do not read encoded or it is no % everything is ok if (udata->encode == 0 || result != '%') { return result; } else { //block until we got the needed bytes while (client->available() >= 2) { if (client->connected() == 0) { return EOF; } }; char return_value = 0; for (char i = 0; i < 2; i++) { result = client->read(); if (result == EOF) { return EOF; } else if (result >= 'A' && result <= 'Z') { return_value += (1 - i) * 16 * (result - 'A'); } else if (result >= 'a' && result <= 'z') { return_value += (1 - i) * 16 * (result - 'a'); } else if (result >= '0' && result <= '9') { return_value += (1 - i) * 16 * (result - '0'); } } return return_value; } }
static int AOA_Host_putchar(char c, FILE* Stream) { return AOA_Host_SendByte((USB_ClassInfo_AOA_Host_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0; }
int uart_dev_recv(FILE *fp) { return uart_recv(fdev_get_udata(fp)); }
static int _serial_fd_getc(FILE *stream){ serial_dev_t dev = fdev_get_udata(stream); return serial_getc(dev) & 0xff; }
static void _serial_fd_putc(int c, FILE *stream){ serial_dev_t dev = fdev_get_udata(stream); serial_putc(dev, c); }
int Device_putchar(char c, FILE* Stream) { return Device_SendByte((USB_EPInfo_Device_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0; }
static int PRNT_Device_putchar(char c, FILE* Stream) { return PRNT_Device_SendByte((USB_ClassInfo_PRNT_Device_t*)fdev_get_udata(Stream), c) ? _FDEV_ERR : 0; }