コード例 #1
0
ファイル: client.c プロジェクト: asenisa12/telematics_task
void cli_send()
{
	char message[MAXLINE];
	puts("\n--->you are in DEFAULT mode type:\n"
			"--->'monitor'-for MONITORING mode\n"
			"--->'calculate'-for CALCULATING mode\n");

	while(work)
	{
		printf("\n>>");
		scanf("%s" , message);
		if(!check_commands(message))
		{
			printf("--->err: '%s' is not valid command\n\n",message);
			continue;
		}
		double m_res=atof(message);
		if(m_res>0||strcmp(message,"0")==0)
			send_num(sockfd, m_res);
		else
			send_str(sockfd, message);

		if(strcmp(message, "terminate")==0)
			kill(0,SIGINT);
		else if(strcmp(message, "monitor")==0)
		{
			puts("--->you are in monitoring mode\n");
			status=MONITORING;
		}
		else if(strcmp(message, "calculate")==0)
		{
			puts("--->you are in calculating mode\n");
			status=CALCULATING;
		}
		else usleep(5000);

	}
}
コード例 #2
0
ファイル: txtzyme.c プロジェクト: alanp/Txtzyme
void send_num(const uint16_t num) {
	if (num > 9) {
		send_num(num/10);
	}
	usb_serial_putchar('0' + num%10);
}		
コード例 #3
0
ファイル: txtzyme.c プロジェクト: alanp/Txtzyme
void parse(const char *buf) {
	uint16_t count = 0;
	char *loop;
	char ch;
	while ((ch = *buf++)) {
		switch (ch) {
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				x = ch - '0';
				while (*buf >= '0' && *buf <= '9') {
					x = x*10 + (*buf++ - '0');
				}
				break;
			case 'p':
				send_num(x);
				send_str(PSTR("\r\n"));
				break;
			case 'a':
			case 'b':
			case 'c':
			case 'd':
			case 'e':
			case 'f':
				port = ch - 'a';
				pin = x % 8;
				break;
			case 'i':
				*(uint8_t *)(0x21 + port * 3) &= ~(1 << pin);		// direction = input
				x = *(uint8_t *)(0x20 + port * 3) & (1 << pin) ? 1 : 0;	// x = pin
				break;
			case 'o':
				if (x % 2) {
					*(uint8_t *)(0x22 + port * 3) |= (1 << pin);	// pin = hi
				} else {
					*(uint8_t *)(0x22 + port * 3) &= ~(1 << pin);	// pin = low
				}
				*(uint8_t *)(0x21 + port * 3) |= (1 << pin);		// direction = output
				break;
			case 'm':
				_delay_ms(x);
				break;
			case 'u':
				_delay_loop_2(x*(F_CPU/4000000UL));
				break;
			case '{':
				count = x;
				loop = buf;
				while ((ch = *buf++) && ch != '}') {
				}
			case '}':
				if (count) {
					count--;
					buf = loop;
				}
				break;
			case 'k':
				x = count;
				break;
			case '_':
				while ((ch = *buf++) && ch != '_') {
					usb_serial_putchar(ch);
				}
				send_str(PSTR("\r\n"));
				break;
			case 's':
				x = analogRead(x);
				break;
			case 'v':
				#define QUOTEME_(x) #x
				#define QUOTEME(x) QUOTEME_(x)
				send_str(PSTR(QUOTEME(MCU)));
				send_str(PSTR("\r\n"));
				break;
			case 'h':
				send_str(PSTR("0-9<num>\tenter number\r\n<num>p\t\tprint number\r\n<num>a-f<pin>\tselect pin\r\n<pin>i<num>\tinput\r\n<pin><num>o\toutput\r\n<num>m\t\tmsec delay\r\n<num>u\t\tusec delay\r\n<num>{}\t\trepeat\r\nk<num>\t\tloop count\r\n_<words>_\tprint words\r\n<num>s<num>\tanalog sample\r\nv\t\tprint version\r\nh\t\tprint help\r\n"));
				break;
		}
	}
}