Exemplo n.º 1
0
void hwDebugPrint(const char *fmt, ... )
{
	char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
#ifdef MY_GATEWAY_FEATURE
	// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
	snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
	MY_SERIALDEVICE.print(fmtBuffer);
#else
	// prepend timestamp (AVR nodes)
	MY_SERIALDEVICE.print(hwMillis());
	MY_SERIALDEVICE.print(" ");
#endif
	va_list args;
	va_start (args, fmt );
#ifdef MY_GATEWAY_FEATURE
	// Truncate message if this is gateway node
	vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args);
	fmtBuffer[sizeof(fmtBuffer) - 2] = '\n';
	fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#else
	vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args);
#endif
	va_end (args);
	MY_SERIALDEVICE.print(fmtBuffer);
	MY_SERIALDEVICE.flush();

	//MY_SERIALDEVICE.write(freeRam());
}
Exemplo n.º 2
0
void MySensor::debugPrint(const char *fmt, ... ) {
	char fmtBuffer[300];
	if (isGateway) {
		// prepend debug message to be handled correctly by gw (C_INTERNAL, I_LOG_MESSAGE)
		snprintf_P(fmtBuffer, 299, PSTR("0;0;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
#ifdef __Raspberry_Pi
		printf(fmtBuffer);
#else
		Serial.print(fmtBuffer);
#endif
	}
	va_list args;
	va_start (args, fmt );
	va_end (args);
	if (isGateway) {
		// Truncate message if this is gateway node
		vsnprintf_P(fmtBuffer, 60, fmt, args);
		fmtBuffer[59] = '\n';
		fmtBuffer[60] = '\0';
	} else {
		vsnprintf_P(fmtBuffer, 299, fmt, args);
	}
	va_end (args);
#ifdef __Raspberry_Pi
	printf(fmtBuffer);
	fflush(stdout);
#else
	Serial.print(fmtBuffer);
	Serial.flush();
#endif
	//Serial.write(freeRam());
}
Exemplo n.º 3
0
    /**
     * Output a variable argument list log string with the specified priority level.
     * Only defined for Arduino as depicted below.
     *
     * @param level  - DEBUG, INFO, WARNING, ERROR, FATAL
     * @param tag    - Module name
     * @param format - variadic log string
     */
    void OCLogv(LogLevel level, PROGMEM const char * tag, PROGMEM const char * format, ...)
    {
        char buffer[LINE_BUFFER_SIZE];
        va_list ap;
        va_start(ap, format);

        GET_PROGMEM_BUFFER(buffer, &(LEVEL[level]));
        Serial.print(buffer);

        char c;
        Serial.print(F(": "));

        while ((c = pgm_read_byte(tag))) {
            Serial.write(c);
            tag++;
        }
        Serial.print(F(": "));

#ifdef __AVR__
        vsnprintf_P(buffer, sizeof(buffer), format, ap);
#else
        vsnprintf(buffer, sizeof(buffer), format, ap);
#endif
        for(char *p = &buffer[0]; *p; p++) // emulate cooked mode for newlines
        {
            if(*p == '\n')
            {
                Serial.write('\r');
            }
            Serial.write(*p);
        }
        Serial.println();
        va_end(ap);
    }
// this gets rid of snprintf_P
void mysnprintf_P(char* buf, int len, const char* fmt, ...)
{
	va_list args;
	va_start (args, fmt );
	vsnprintf_P(buf, len, fmt, args);
	va_end (args);
}
Exemplo n.º 5
0
void hwDebugPrint(const char *fmt, ...)
{
#ifndef MY_DEBUGDEVICE
#define MY_DEBUGDEVICE MY_SERIALDEVICE
#endif
#ifndef MY_DISABLED_SERIAL
	char fmtBuffer[MY_SERIAL_OUTPUT_SIZE];
#ifdef MY_GATEWAY_SERIAL
	// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
	snprintf_P(fmtBuffer, sizeof(fmtBuffer), PSTR("0;255;%" PRIu8 ";0;%" PRIu8 ";%" PRIu32 " "),
	           C_INTERNAL, I_LOG_MESSAGE, hwMillis());
	MY_DEBUGDEVICE.print(fmtBuffer);
#else
	// prepend timestamp
	MY_DEBUGDEVICE.print(hwMillis());
	MY_DEBUGDEVICE.print(F(" "));
#endif
	va_list args;
	va_start(args, fmt);
	vsnprintf_P(fmtBuffer, sizeof(fmtBuffer), fmt, args);
#ifdef MY_GATEWAY_SERIAL
	// Truncate message if this is gateway node
	fmtBuffer[sizeof(fmtBuffer) - 2] = '\n';
	fmtBuffer[sizeof(fmtBuffer) - 1] = '\0';
#endif
	va_end(args);
	MY_DEBUGDEVICE.print(fmtBuffer);
#else
	(void)fmt;
#endif
}
Exemplo n.º 6
0
// create a printf like interface to the Arduino Serial function. Format string stored in PROGMEM
void PiLink::print_P(const char *fmt, ... ){
	char tmp[128]; // resulting string limited to 128 chars
	va_list args;
	va_start (args, fmt );
	vsnprintf_P(tmp, 128, fmt, args);
	va_end (args);
	Serial.print(tmp);
}
Exemplo n.º 7
0
void _TM_DEBUG (char *fmt, ... )
{
  char tmp[128]; // resulting string limited to 128 chars
  va_list args;
  va_start (args, fmt );
  vsnprintf_P(tmp, 128, fmt, args);
  va_end (args);
  Serial.print(tmp);
}
Exemplo n.º 8
0
void PiLink::printFridgeAnnotation(const char * annotation, ...){
	char tempString[128]; // resulting string limited to 128 chars
	va_list args;	
	// Using print_P for the Annotation fails. Arguments are not passed correctly. Use Serial directly as a work around.
	va_start (args, annotation );
	vsnprintf_P(tempString, 128, annotation, args);
	va_end (args);
	printTemperaturesJSON(0, tempString);
}	 
Exemplo n.º 9
0
void lcd_Printf_P(PGM_P format, ...)
{
	va_list arg;

	va_start(arg, format);
	vsnprintf_P((char *)LCDWorkBuffer, portLCD_BUFFER, format, arg);
	lcd_Print((uint8_t *)LCDWorkBuffer);
	va_end(arg);
}
Exemplo n.º 10
0
// create a printf like interface to the Arduino Serial function. Format string stored in PROGMEM
void PiLink::print_P(const char *fmt, ... ){
	va_list args;
	va_start (args, fmt );
	vsnprintf_P(printfBuff, PRINTF_BUFFER_SIZE, fmt, args);
	va_end (args);
	if(SERIAL_READY(piStream)){ // if Serial connected (on Leonardo)
		piStream.print(printfBuff);
	}
}
Exemplo n.º 11
0
void avrSerialPrintf_P(PGM_P format, ...)
{
	va_list arg;

	va_start(arg, format);
	vsnprintf_P((char *)serialWorkBuffer, portSERIAL_BUFFER, format, arg);
	avrSerialPrint(serialWorkBuffer);
	va_end(arg);
}
Exemplo n.º 12
0
void ArduinoPrintf::printf_P( const prog_uint8_t* fmt, ... ) {
    char tmp[PRINTF_BUFFER];

    va_list args;
    va_start (args, fmt );
    vsnprintf_P(tmp, PRINTF_BUFFER, (const prog_char*)fmt, args);
    va_end (args);

    interface->print(tmp);
}
Exemplo n.º 13
0
void usart_xfprintf_P_arg(USART_ID usartId, PGM_P format, va_list arg)
{
	while(usartComBuf[usartId].workBufferInUse == USART_ENGAGED ) taskYIELD();
	usartComBuf[usartId].workBufferInUse = USART_ENGAGED;

	vsnprintf_P((char *)(usartComBuf[usartId].workBuffer), usartComBuf[usartId].workBufferSize, format, arg);
	usart_xfprint(usartId, (uint8_t *)(usartComBuf[usartId].workBuffer));

	usartComBuf[usartId].workBufferInUse = USART_VACANT;
}
Exemplo n.º 14
0
int sprintf_P(char* str, PGM_P formatP, ...) {
    int ret;
    va_list arglist;
    va_start(arglist, formatP);

    ret = vsnprintf_P(str, SIZE_IRRELEVANT, formatP, arglist);

    va_end(arglist);
    return ret;
}
Exemplo n.º 15
0
int snprintf_P(char* str, size_t strSize, PGM_P formatP, ...) {
    int ret;
    va_list arglist;
    va_start(arglist, formatP);

    ret = vsnprintf_P(str, strSize, formatP, arglist);

    va_end(arglist);
    return ret;
}
Exemplo n.º 16
0
void usart_fprintf_P_arg(USART_ID usartId, PGM_P format, va_list arg)
{
	while(usartComBuf[usartId].workBufferInUse == USART_ENGAGED ) _delay_us(25);
	usartComBuf[usartId].workBufferInUse = USART_ENGAGED;

	vsnprintf_P((char *)(usartComBuf[usartId].workBuffer), usartComBuf[usartId].workBufferSize, format, arg);
	usart_fprint(usartId,usartComBuf[usartId].workBuffer);

	usartComBuf[usartId].workBufferInUse = USART_VACANT;

}
Exemplo n.º 17
0
void MyGateway::serial(const char *fmt, ... ) {
   va_list args;
   va_start (args, fmt );
   vsnprintf_P(serialBuffer, MAX_SEND_LENGTH, fmt, args);
   va_end (args);
   Serial.print(serialBuffer);
   if (useWriteCallback) {
	   // We have a registered write callback (probably Ethernet)
	   dataCallback(serialBuffer);
   }
}
Exemplo n.º 18
0
void serial_printf(const __FlashStringHelper *fmt, ... )
{
	va_list args;
	va_start (args, fmt);
#ifdef __AVR__
	vsnprintf_P(buf, sizeof(buf), (const char *)fmt, args); // progmem for AVR
#else
	vsnprintf(buf, sizeof(buf), (const char *)fmt, args);
#endif
	va_end(args);
	Serial.println(buf);
}
Exemplo n.º 19
0
bool MsgQueue::addMessage(const char * msg, va_list args)
{
  if (message_count == MSGQUEUE_MAX_MESSAGES) { return false; }
  if (strlen_P(msg) >= MSGQUEUE_MAX_MESSAGE_LEN) { return false; }

  memset(messages[message_count], 0, MSGQUEUE_MAX_MESSAGE_LEN);
  vsnprintf_P(messages[message_count], MSGQUEUE_MAX_MESSAGE_LEN, msg, args);

  message_count++;
  queue_processing = true;
  return true;
}
Exemplo n.º 20
0
/* for documentation check os_test.h */
void test_debug_printf(const OS_PROGMEM char* format, ...)
{
   va_list vargs;
   char buff[OS_STACK_MINSIZE / 2]; /* half of stack size */

   va_start(vargs, format);
   /* use +_P version of vsnpintf since format is from program memory */
   vsnprintf_P(buff, sizeof(buff) - 1, format, vargs);
   buff[sizeof(buff) - 1] = '\0';
   va_end(vargs);

   uart_tx_rammem(buff);
}
Exemplo n.º 21
0
void EIoTCloudRestApi::printDebug(const char *fmt, ...) {
	char buff[300];

	va_list args;
	va_start(args, fmt);
	va_end(args);
		
	vsnprintf_P(buff, 299, fmt, args);
	
	va_end(args);
	Serial.print(buff);
	Serial.flush();
}
Exemplo n.º 22
0
size_t Print::printf_P(PGM_P format, ...) {
    va_list arg;
    va_start(arg, format);
    char temp[64];
    char* buffer = temp;
    size_t len = vsnprintf_P(temp, sizeof(temp), format, arg);
    va_end(arg);
    if (len > sizeof(temp) - 1) {
        buffer = new char[len + 1];
        if (!buffer) {
            return 0;
        }
        va_start(arg, format);
        vsnprintf_P(buffer, len + 1, format, arg);
        va_end(arg);
    }
    len = write((const uint8_t*) buffer, len);
    if (buffer != temp) {
        delete[] buffer;
    }
    return len;
}
Exemplo n.º 23
0
void PiLink::debugMessage(const char * message, ...){
	va_list args;
		
	//print 'D:' as prefix
	printResponse('D');
	
	// Using print_P for the Annotation fails. Arguments are not passed correctly. Use Serial directly as a work around.
	va_start (args, message );
	vsnprintf_P(printfBuff, PRINTF_BUFFER_SIZE, message, args);
	va_end (args);
	piStream.print(printfBuff);
	printNewLine();
}
Exemplo n.º 24
0
void PiLink::debugMessage(const char * message, ...){
	char tempString[128]; // resulting string limited to 128 chars
	va_list args;
	
	//print 'D:' as prefix
	print_P(PSTR("D:"));
	
	// Using print_P for the Annotation fails. Arguments are not passed correctly. Use Serial directly as a work around.
	va_start (args, message );
	vsnprintf_P(tempString, 128, message, args);
	va_end (args);
	Serial.print(tempString);

	print_P(PSTR("\n")); // print newline
}
Exemplo n.º 25
0
void hwDebugPrint(const char *fmt, ... ) {
	char fmtBuffer[300];
	#ifdef MY_GATEWAY_FEATURE
		// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
		snprintf_P(fmtBuffer, 299, PSTR("0;255;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
		MY_SERIALDEVICE.print(fmtBuffer);
	#endif
	va_list args;
	va_start (args, fmt );
	va_end (args);
	#ifdef MY_GATEWAY_FEATURE
		// Truncate message if this is gateway node
		vsnprintf_P(fmtBuffer, MY_GATEWAY_MAX_SEND_LENGTH, fmt, args);
		fmtBuffer[MY_GATEWAY_MAX_SEND_LENGTH-1] = '\n';
		fmtBuffer[MY_GATEWAY_MAX_SEND_LENGTH] = '\0';
	#else
		vsnprintf_P(fmtBuffer, 299, fmt, args);
	#endif
	va_end (args);
	MY_SERIALDEVICE.print(fmtBuffer);
	MY_SERIALDEVICE.flush();

	//MY_SERIALDEVICE.write(freeRam());
}
Exemplo n.º 26
0
void hwDebugPrint(const char *fmt, ... ) {
	char fmtBuffer[300];
	#ifdef MY_GATEWAY_FEATURE
		// prepend debug message to be handled correctly by controller (C_INTERNAL, I_LOG_MESSAGE)
		snprintf_P(fmtBuffer, 299, PSTR("0;0;%d;0;%d;"), C_INTERNAL, I_LOG_MESSAGE);
		Serial.print(fmtBuffer);
	#endif
	va_list args;
	va_start (args, fmt );
	va_end (args);
	#ifdef MY_GATEWAY_FEATURE
		// Truncate message if this is gateway node
		vsnprintf_P(fmtBuffer, 60, fmt, args);
		fmtBuffer[59] = '\n';
		fmtBuffer[60] = '\0';
	#else
		vsnprintf_P(fmtBuffer, 299, fmt, args);
	#endif
	va_end (args);
	Serial.print(fmtBuffer);
	Serial.flush();

	//Serial.write(freeRam());
}
Exemplo n.º 27
0
/* usart_printf_p() 

   Send a format string stored in flash memory to the USART.
*/
uint8_t usart_printf_p(const char *fmt, ...) {
    va_list args; 
    char printbuffer[USART_TXBUFFERSIZE]; 

    va_start (args, fmt); 
        /* For this to work, printbuffer must be larger than 
        * anything we ever want to print. 
        */ 
        vsnprintf_P (printbuffer, USART_TXBUFFERSIZE, fmt, args); 
    va_end (args); 

    /* Print the string */ 
    usart_puts(printbuffer); 
    return 0; 
}    
Exemplo n.º 28
0
void avrSerialxPrintf_P(xComPortHandlePtr pxPort, PGM_P format, ...)
{
    va_list arg;

    va_start(arg, format);

    while(pxPort->serialWorkBufferInUse == ENGAGED ) _delay_us(25);
    pxPort->serialWorkBufferInUse = ENGAGED;

    vsnprintf_P((char *)(pxPort->serialWorkBuffer), pxPort->serialWorkBufferSize, format, arg);
    avrSerialxPrint(pxPort, pxPort->serialWorkBuffer);

    pxPort->serialWorkBufferInUse = VACANT;

    va_end(arg);
}
Exemplo n.º 29
0
uint8_t
httplog_P(const char *message, ...)
{
  uint8_t result = httplog_buffer_empty();
  if (result)
  {
    va_list va;
    va_start(va, message);
    vsnprintf_P(httplog_tmp_buf, HTTPLOG_BUFFER_LEN, message, va);
    va_end(va);
    httplog_tmp_buf[HTTPLOG_BUFFER_LEN - 1] = 0;

    httplog_resolve_address();
  }
  return result;
}
Exemplo n.º 30
0
void
wprintw_P (WINDOW *win, const char *fmt, ...)
{
  char buf[COLS + 1];

  va_list va;
  va_start (va, fmt);

  TTYDEBUG ("wprintw: win=%p, %s to y=%d,x=%d ", win, fmt, win->y, win->x);
  vsnprintf_P (buf, COLS + 1, fmt, va);

  TTYDEBUG ("--> '%s'\n", buf);
  waddstr (win, buf);

  va_end (va);
}