예제 #1
0
void run_test(const char * test_msg, uint8_t num_channels, uint8_t depth,
    bool circular) {
  print(test_msg);
  
  cb_arg = 0;
  
  group.num_channels = num_channels;
  group.circular = circular;
  group.end_cb = adc_callback;
  
  if (depth > 1) cb_expect = 2;
  else cb_expect = 1;
  if (circular) cb_expect *= 3;
  
  adcStartConversion(&ADCD1, &group, buffer, depth);
  
  while (ADCD1.state == ADC_ACTIVE) ;
  
  
  int index = 0;
  for (int j = 0; j < depth; j++) {
    for (int i = 0; i < group.num_channels; i++) {
      index = i + (j * group.num_channels);
      sniprintf(out_string, 128, chn_fmt_string, group.channels[i]);
      print(out_string);
      
      sniprintf(out_string, 128, raw_fmt_string, buffer[index]); 
      print(out_string);
      
      if (group.channels[i] == 30) { /* internal temp sensor */
        buffer[index] = adcMSP430XAdjustTemp(&group, buffer[index]);
      }
      else {
        buffer[index] = adcMSP430XAdjustResult(&group, buffer[index]);
      }
      
      sniprintf(out_string, 128, cooked_fmt_string, buffer[index]); 
      print(out_string);
    }
  }
  
  if (cb_arg == cb_expect) {
    print(success_string);
  }
  else {
    print(fail_string);
  }
}
예제 #2
0
void
owl_hexdump_f(const char *title, const char *pos, int len)
{
	char line[80], *p;
	int i, j;
        owl_printf("%s - hexdump(len=%d):\n\r", title, len); 
	for(i = 0; i < len; i += 16) {
		p = line;
		for(j = 0; j < 16; j++) {
			if(i + j < len)
				sniprintf(p, line + sizeof(line) - p, "%02x ",
                                          (unsigned char)pos[i + j]);
			else
				strcpy(p, "   ");
			p += 3;
		}
		strcpy(p, ": ");
		for(j = 0; j < 16; j++) {
			if(i + j < len) {
				if(isprint((unsigned char) pos[i + j]))
					*p++ = pos[i + j];
				else
					*p++ = '.';
			}
		}
		*p = '\0';
		owl_printf("   %s\n\r", line);
	}
} 
예제 #3
0
/**
  Performs an HTTP GET operation to the path at the address / port specified.

  The data returned from the web server (up to maxresponse bytes) is written into the given buffer.

  @param hostname The name of the host to connect to.
  @param path The path on the server to connect to.
  @param port The port to connect on - standard http port is 80
  @param response The buffer read the response back into.
  @param maxresponse An integer specifying the size of the response buffer.
  @param headers (optional) An array of strings to be sent as headers - last element in the array must be 0.
  @return the number of bytes received, or < 0 on error.

  \b Example
  \code
  #define BUF_LENGTH 100
  char myBuffer[BUF_LENGTH];
  int justGot = webclientGet("www.makingthings.com", "/test/path", 80, myBuffer, BUF_LENGTH, 0);
  \endcode
  Now we should have the results of the HTTP GET from \b www.makingthings.com/test/path in \b myBuffer.
*/
int webclientGet(const char* hostname, const char* path, int port, char* response, int maxresponse, const char* headers[])
{
    int s = tcpOpen(networkGetHostByName(hostname), port);
    if (s > -1) {
        // construct the GET request
        int len = sniprintf(webclientBuf, WEBCLIENT_BUFFER_SIZE, "GET %s HTTP/1.1\r\n%s%s%s",
                            path,
                            (hostname != NULL) ? "Host: " : "",
                            (hostname != NULL) ? hostname : "",
                            (hostname != NULL) ? "\r\n" : ""  );
        tcpWrite(s, webclientBuf, len);

        if (headers != NULL) {
            for ( ; *headers != 0; headers++) {
                tcpWrite(s, *headers, strlen(*headers));
                tcpWrite(s, "\r\n", 2);
            }
        }

        if (tcpWrite(s, "\r\n", 2 ) < 0) { // all done with headers...just check our last write here...
            tcpClose(s);
            return -1;
        }

        // read the data into the given buffer until there's none left, or the passed in buffer is full
        len = webclientReadResponse(s, response, maxresponse);
        tcpClose(s);
        return len;
    }
    return -1;
}
예제 #4
0
int picolCommandMath(struct picolInterp *i, int argc, char **argv, void *pd) {
	char buf[64];
	int a, b, c;
	if (argc != 3)
		return picolArityErr(i, argv[0]);
	a = atoi(argv[1]);
	b = atoi(argv[2]);
	if (argv[0][0] == '+')
		c = a + b;
	else if (argv[0][0] == '-')
		c = a - b;
	else if (argv[0][0] == '*')
		c = a * b;
	else if (argv[0][0] == '/')
		c = a / b;
	else if (argv[0][0] == '>' && argv[0][1] == '\0')
		c = a > b;
	else if (argv[0][0] == '>' && argv[0][1] == '=')
		c = a >= b;
	else if (argv[0][0] == '<' && argv[0][1] == '\0')
		c = a < b;
	else if (argv[0][0] == '<' && argv[0][1] == '=')
		c = a <= b;
	else if (argv[0][0] == '=' && argv[0][1] == '=')
		c = a == b;
	else if (argv[0][0] == '!' && argv[0][1] == '=')
		c = a != b;
	else
		c = 0; /* I hate warnings */
	sniprintf(buf, 64, "%d", c);
	picolSetResult(i, buf);
	return PICOL_OK;
}
예제 #5
0
/**
  Performs an HTTP POST operation to the path at the address / port specified.
  A buffer with the data to be POSTed is passed in, and up to maxresponse bytes of the response
  from the server are written back into the same buffer.
  @param hostname The name of the host to connect to.
  @param path The path on the server to post to.
  @param port The port to connect on - standard http port is 80
  @param data The buffer to write from, and then read the response back into
  @param data_length The number of bytes to write from \b data
  @param maxresponse How many bytes of the response to read back into \b data
  @param headers (optional) An array of strings to be sent as headers - last element in the array must be 0.
  @return The number of bytes written, or -1 on failure.

  \b Example
  \code
  // we'll post a test message to www.makingthings.com/post/path
  int bufLength = 100;
  char myBuffer[bufLength];
  int datalength = siprintf(myBuffer, "A test message to post"); // load the buffer with some data to send
  webclientPost("www.makingthings.com", "/post/path", 80, myBuffer, datalength, bufLength, 0);
  \endcode
*/
int webclientPost(const char* hostname, const char* path, int port, char* data, int data_length, int maxresponse, const char* headers[])
{
    int s = tcpOpen(networkGetHostByName(hostname), port);
    if (s > -1) {
        int len = sniprintf(webclientBuf, WEBCLIENT_BUFFER_SIZE,
                            "POST %s HTTP/1.1\r\nContent-Length: %d\r\n%s%s%s",
                            path, data_length,
                            (hostname != NULL) ? "Host: " : "",
                            (hostname != NULL) ? hostname : "",
                            (hostname != NULL) ? "\r\n" : "");
        tcpWrite(s, webclientBuf, len);

        if (headers != NULL) {
            for ( ; *headers != 0; headers++) {
                tcpWrite(s, *headers, strlen(*headers));
                tcpWrite(s, "\r\n", 2);
            }
        }
        tcpWrite(s, "\r\n", 2); // all done with headers

        // send the body...just check our last write here...
        if (tcpWrite(s, data, data_length) <= 0) {
            tcpClose(s);
            return -1;
        }

        // read back the response
        len = webclientReadResponse(s, data, maxresponse);
        tcpClose(s);
        return len;
    }
    return -1;
}
예제 #6
0
파일: util.c 프로젝트: AndreyMostovov/asf
const char* mac2str(uint8_t* mac)
{
        static char buf[18];
        sniprintf(buf, sizeof(buf), "%02x-%02x-%02x-%02x-%02x-%02x",
                 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
        return buf;
}
예제 #7
0
파일: util.c 프로젝트: AndreyMostovov/asf
int join_argv(char *dst, size_t dst_len, int argc, char* argv[]) {
        char *p = dst;
        int i;
        int len = 0;

        /* Not really kosher, an ssid may legally contain 0-bytes but
         * the console interface does not deal with that.
         */
        for (i = 0; i < argc; i++) {
                len += strlen(argv[i]);
                if (len > dst_len) {
			printk("ssid too long (max %d)\n", (int) dst_len);
                        return 0;
                }
                p += sniprintf(p,
                               dst_len - (p - dst),
                               "%s ",
                               argv[i]);
        }
        if (p == dst) {
                return 0;
        }
        p--;
        *p = '\0'; /* Delete last space */

        return p - dst;
}
예제 #8
0
CString & CString::Set(const char *_str, unsigned int maxSize)
{
	if (_str) {
		if (_str != str) {
			length = min(strlen(_str), maxSize);

			if (SetBufferSize(length + 1))
				sniprintf(str, length + 1, "%s", _str);
			else
				length = 0;
		}
	}
	else {
		length = 0;
		if (SetBufferSize(length + 1))
			str[0] = '\0';
	}

	return *this;
}
예제 #9
0
void DecodeKey( word keyCode, word keyFlags )
{
    static bool resetState = false;

    bool flagKeyRelease = ( keyFlags & fKeyRelease ) != 0;

    bool reset1 = ( keyFlags & ( fKeyCtrlLeft | fKeyCtrlRight ) ) == ( fKeyCtrlLeft | fKeyCtrlRight );

    static bool reset2 = false;
    if( keyCode == KEY_POWER && !flagKeyRelease ) reset2 = true;
    if( keyCode == KEY_POWER && flagKeyRelease ) reset2 = false;

    static bool reset3 = false;
    if( keyCode == KEY_PRNTSCR && !flagKeyRelease ) reset3 = true;
    if( keyCode == KEY_PRNTSCR && flagKeyRelease ) reset3 = false;

    if( ( reset1 || reset2 || reset3 ) != resetState )
    {
        resetState = reset1 || reset2 || reset3;
        CPU_Reset( resetState );
        DelayMs( 100 );
    }

    //------------------------------------------------------

    if( !flagKeyRelease )
    {
        if( ( keyFlags & fKeyCtrl ) != 0 )
        {
            switch( keyCode )
            {
                case KEY_1 :
                    specConfig.specVideoMode = 0;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_2 :
                    specConfig.specVideoMode = 1;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_3 :
                    specConfig.specVideoMode = 2;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_4 :
                    specConfig.specVideoMode = 3;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_5 :
                    specConfig.specVideoMode = 4;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_F12 :
                    CPU_NMI();
                    break;
            }
        }
        else if ( fKeyAlt & keyFlags )
        {
            int kc;

            switch ( keyCode )
            {
                case KEY_0:
                    kc = 0;
                    break;
                case KEY_1:
                    kc = 1;
                    break;
                case KEY_2:
                    kc = 2;
                    break;
                case KEY_3:
                    kc = 3;
                    break;
                case KEY_4:
                    kc = 4;
                    break;
                case KEY_5:
                    kc = 5;
                    break;
                case KEY_6:
                    kc = 6;
                    break;
                case KEY_7:
                    kc = 7;
                    break;
                case KEY_8:
                    kc = 8;
                    break;
                case KEY_9:
                    kc = 9;
                    break;
                default:
                    kc = -1;
                    break;
            }
            if ( kc >= 0 )
            {
                char snaName[ 0x10 ];
                sniprintf( snaName, sizeof(snaName), "!slot_%.1d.sna", kc );
                SaveSnapshot( snaName );
            }
        }

        else
        {
            switch( keyCode )
            {
                case KEY_ESC :
                    Debugger_Enter();
                    break;

                case KEY_PAUSE :
                    Shell_Pause();
                    break;

                case KEY_F1 :
                    specConfig.specTurbo = 0;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;
                case KEY_F2 :
                    specConfig.specTurbo = 1;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;
                case KEY_F3 :
                    specConfig.specTurbo = 2;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;
                case KEY_F4 :
                    specConfig.specTurbo = 3;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;

                case KEY_F5 :
                    SystemBus_Write( 0xc00000, 0x00004 );
                    break;
                case KEY_F6 :
                    {
                        CPU_Stop();

                        byte specPort7ffd = SystemBus_Read( 0xc00017 );

                        byte page = ( specPort7ffd & ( 1 << 3 ) ) != 0 ? 7 : 5;
                        dword addr = 0x800000 | ( page << 13 );

                        SystemBus_Write( 0xc00020, 0 );  // use bank 0

                        for( int i = 0x1800; i < 0x1b00; i += 2 )
                        {
                            SystemBus_Write( addr + ( i >> 1 ), 0x3838 );
                        }

                        CPU_Start();
                    }
                    break;

                case KEY_F9 :
                    Shell_SettingsMenu();
                    break;

                case KEY_F10 :
                    Shell_DisksMenu();
                    break;

                case KEY_F11 :
                    if( ( keyFlags & fKeyShift ) != 0 ) Shell_SaveSnapshot();
                    else SaveSnapshot( UpdateSnaName() );
                    break;

                case KEY_F12 :
                    Shell_Browser();
                    break;

                case KEY_EQUALS :
                case KEY_KP_PLUS :
                    if( !Tape_Started() ) Tape_Restart();
                    break;

                case KEY_MINUS :
                case KEY_KP_MINUS :
                    if( !Tape_Started() ) Tape_Start();
                    else Tape_Stop();
                    break;

                case KEY_INSERT :
                    specConfig.specMouseSwap = !specConfig.specMouseSwap;
                    break;
            }
        }
    }
}
예제 #10
0
void
vsyslog(int priority, const char *format, va_list ap)
{
	rtems_bsd_syslog_context *ctx = rtems_bsd_syslog_get_context();
	int pri = LOG_PRI(priority);
	char fmt[128];
	char buf[128];
	const char *src;
	char *dst;
	size_t rem;
	char *m;
	int n;
	size_t len;

	if ((LOG_MASK(pri) & ctx->mask) == 0) {
		return;
	}

	/* Expand the %m in the format string and add a newline character */

	src = format;
	dst = &fmt[0];
	rem = sizeof(fmt) - 2;

	while ((m = strstr(src, "%m")) != NULL) {
		size_t c = m - src;

		if (c > rem) {
			rtems_bsd_syslog_format_buffer_overflow();
			return;
		}

		memcpy(dst, src, c);
		dst += c;
		src += c + 2;
		rem -= c;

		n = sniprintf(dst, rem, "%s", strerror(errno));
		if (n > rem || n < 0) {
			rtems_bsd_syslog_format_buffer_overflow();
			return;
		}

		dst += (size_t) n;
		rem -= (size_t) n;
	}

	len = strlen(src);
	if (len > rem) {
		rtems_bsd_syslog_format_buffer_overflow();
		return;
	}

	memcpy(dst, src, len);
	dst += len;
	dst[0] = '\n';
	dst[1] = '\0';

	/* Print into buffer */

	dst = &buf[0];
	rem = sizeof(buf) - 1;

	n = sniprintf(dst, rem, "%s: ", rtems_bsd_syslog_priorities[pri]);
	if (n <= rem) {
		dst += (size_t) n;
		rem -= (size_t) n;
	}

	n = sniprintf(dst, rem, "%s: ", rtems_bsd_program_get_name());
	if (n <= rem) {
		dst += (size_t) n;
		rem -= (size_t) n;
	}

	vsniprintf(dst, rem, &fmt[0], ap);

	/* Write in one rush */

	fputs(&buf[0], stderr);
}
예제 #11
0
파일: trace.c 프로젝트: BigEd/speccy2010
char *bdi_sys_stat_decode( word data )
{
    static char str[8];
    sniprintf( str, sizeof(str),"0x%.4x", data );
    return str;
}
예제 #12
0
파일: trace.c 프로젝트: BigEd/speccy2010
char *bdi_port_desc( word data )
{
    static char str[8];
    sniprintf( str, sizeof(str),"0x%.4x", data );
    return str;
}
예제 #13
0
파일: trace.c 프로젝트: BigEd/speccy2010
char *ticks_str2( word data )
{
    static char str[8];
    sniprintf( str, sizeof(str),"0x%.4x", data );
    return str;
}
예제 #14
0
파일: trace.c 프로젝트: BigEd/speccy2010
char *wd_command_decode( word data )
{
    static char str[8];
    sniprintf( str, sizeof(str),"0x%.4x", data );
    return str;
}
예제 #15
0
파일: trace.c 프로젝트: BigEd/speccy2010
char *wd_stat_decode( word data, word data2 )
{
    static char str[16];
    sniprintf( str, sizeof(str),"0x%.4x, 0x%.4x", data, data2 );
    return str;
}
예제 #16
0
파일: rtc.c 프로젝트: e-asphyx/tomatobox
int time_to_str(char *buf, size_t sz, const struct tm *tim) {
	return sniprintf(buf, sz, "%02d:%02d:%02d %02d-%02d-%d",
					tim->tm_hour, tim->tm_min, tim->tm_sec,
					tim->tm_mday, tim->tm_mon + 1, YEAR_BASE + tim->tm_year);
}
예제 #17
0
void Tape_SelectFile(const char *name)
{
	sniprintf(tapePath, sizeof(tapePath), "%s", name);
}
예제 #18
0
THD_FUNCTION(Thread1, arg) {

  (void)arg;

  /*
   * Activate the serial driver 0 using the driver default configuration.
   */
  sdStart(&SD1, NULL);

  /* Activate the ADC driver 1 using its config */
  adcStart(&ADCD1, &config);

  while (chnGetTimeout(&SD1, TIME_INFINITE)) {
    print(start_msg);
    chThdSleepMilliseconds(2000);

    /* Test 1 - 1ch1d, no circular */
    run_test(test_1_msg, 1, 1, false);
    
    /* Test 2 - 1ch8d, no circular */
    run_test(test_2_msg, 1, 8, false);
    
    /* Test 3 - 4chd1, no circular */
    run_test(test_3_msg, 4, 1, false);
    
    /* Test 4 - 4ch8d, no circular */
    run_test(test_4_msg, 4, 8, false);
    
    /* Test 5 - 1ch1d, circular */
    run_test(test_5_msg, 1, 1, true);
    
    /* Test 6 - 1ch8d, circular */
    run_test(test_6_msg, 1, 8, true);
    
    /* Test 7 - 4ch1d, circular */
    run_test(test_7_msg, 4, 1, true);
    
    /* Test 8 - 4ch8d, circular */
    run_test(test_8_msg, 4, 8, true);
    
    /* Test 9 - 1ch1d, synchronous */
    print(test_9_msg);
    cb_arg = 0;
    
    group.num_channels = 1;
    group.circular = false;
    group.end_cb = adc_callback;
    
    cb_expect = 1;
    
    adcConvert(&ADCD1, &group, buffer, 1);
    
    while (ADCD1.state == ADC_ACTIVE) ;
    
    sniprintf(out_string, 128, chn_fmt_string, group.channels[0]);
    print(out_string);
    
    sniprintf(out_string, 128, raw_fmt_string, buffer[0]); 
    print(out_string);
    
    buffer[0] = adcMSP430XAdjustTemp(&group, buffer[0]);
    
    sniprintf(out_string, 128, cooked_fmt_string, buffer[0]); 
    print(out_string);
    
    if (cb_arg == cb_expect) {
      print(success_string);
    }
    else {
      print(fail_string);
    }
  }
}