Пример #1
0
void upgrade_try(void*p)
{
	uchar send[10]={0},recv[10]={0};
	int i=0;

	initialize();
	power_screen(true);
	show_logo(true); 

	if(!prepare_mobile(false)) { post_trace("prepare mobile false");
        return;
    }
	if(!prepare_transport()) {	 post_trace("prepare transport false");
        return;
    }
	while(true){
		for(i = 0; i<10; i++){     
        	send[i] = rand();    
   		 }  
  		if(!communication_test(send,10,recv)){
			if(!gprs_connect(SERVER_ADDR, SERVER_PORT)){
				prepare_transport();
				continue;
			}		
		}
		if(memcmp(send, recv, 10)==0 ){
			post_trace("send=recv");	
		}else{
			post_trace("send!=recv");	
		}
    }
}
Пример #2
0
void component_key_boardcast()
{
	const uint8 DATA_SIZE = sizeof(HMC5883L_data) + sizeof(RTC_Clock) + sizeof(MMA8451_data);
	char szTrace[piece_size], szData[piece_size];
	
	sprintf(szTrace, "key = broadcast");
	post_trace(szTrace);
	
	mobile_state();
	if(!prepare_transport()) {
		post_trace("gprs power on error");
		
		return;
	}
	read_file("temp", szData, DATA_SIZE);
	post_trace("read sensor data in file named \"temp\" in tf card");
	communication_test((uchar*)szData, DATA_SIZE, (uchar*)szTrace);
	gprs_disconnect();
	power_device(ED_GPRS, EP_OFF);
	if(memcmp(szData, szTrace, DATA_SIZE) == 0) {
		HMC5883L_data *data_5883 = (HMC5883L_data*)szTrace;
		RTC_Clock *clock = (RTC_Clock*)(szTrace + sizeof(HMC5883L_data));
		Sensor *data_8451 = (Sensor*)(szTrace + sizeof(HMC5883L_data) + sizeof(RTC_Clock));
		
		sprintf(szTrace, "传输成功, 5883, x %d, y %d, z %d, 时间, 20%02d年%02d月%02d日%02d时%02d分%02d秒, 8451, x %d, y %d, z %d",
			data_5883->x, data_5883->y, data_5883->z, clock->year, clock->month, clock->day, clock->hour, clock->minute, clock->second, data_8451->x, data_8451->y, data_8451->z);
	} else {
		strcpy(szTrace, "传输失败");
	}
	report_content(szTrace);
	post_trace("broadcast completed");	
	mobile_state();
}
Пример #3
0
switch_status_t sip_dig_function(_In_opt_z_ const char *cmd, _In_opt_ switch_core_session_t *session, _In_ switch_stream_handle_t *stream)

{
	int exitcode = 0;
	int o_sctp = 1, o_tls_sctp = 1, o_verbatim = 1;
	int family = 0, multiple = 0;
	char const *dnsserver = NULL;
	char const *string;
	url_t *uri = NULL;

	char const *host;
	char const *port;
	char *transport = NULL, tport[32];
	int argc;
	char *argv_[25] = { 0 };
	char *mycmd = NULL;
	char **argv;
	struct dig dig[1] = {{ NULL }};
	su_home_t *home = NULL;
	int xml = 0;

	home = su_home_new(sizeof(*home));

	argv = argv_;
	argv++;

	if (!cmd) {
		{usage(1);}
	}

	mycmd = strdup(cmd);

	argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv_) / sizeof(argv_[0])) - 1);
	argv = argv_;


	if (!argv[1]) {
		{usage(1);}
	}
	
	if (!strcasecmp(argv[1], "xml")) {
		switch_event_add_header_string(stream->param_event, SWITCH_STACK_BOTTOM, "xml", "true");
		argv++;
		xml++;
	}

	argv[0] = "sofia_dig";


	//if (su_init() != 0)
	//return -1;

	while (argv[1] && argv[1][0] == '-') {
		if (strcmp(argv[1], "-v") == 0)
			o_verbatim++;
		else if (strcmp(argv[1], "-6") == 0)
			dig->ip6 = ++family;
		else if (strcmp(argv[1], "-4") == 0)
			dig->ip4 = ++family;
		else if (strncmp(argv[1], "-p", 2) == 0) {
			char const *proto;

			if (argv[1][2] == '=')
				proto = argv[1] + 3;
			else if (argv[1][2])
				proto = argv[1] + 2;
			else
				proto = argv++[2];

			if (proto == NULL)
				{usage(2);}

			if (prepare_transport(dig, proto) < 0) {
				goto fail;
			}
		}
		else if (strcmp(argv[1], "--udp") == 0)
			prepare_transport(dig, "udp");
		else if (strcmp(argv[1], "--tcp") == 0)
			prepare_transport(dig, "tcp");
		else if (strcmp(argv[1], "--tls") == 0)
			prepare_transport(dig, "tls");
		else if (strcmp(argv[1], "--sctp") == 0)
			prepare_transport(dig, "sctp");
		else if (strcmp(argv[1], "--tls-sctp") == 0)
			prepare_transport(dig, "tls-sctp");
		else if (strcmp(argv[1], "--tls-udp") == 0)
			prepare_transport(dig, "tls-udp");
		else if (strcmp(argv[1], "--no-sctp") == 0)
			o_sctp = 0, o_tls_sctp = 0;
		else if (strcmp(argv[1], "--help") == 0)
			{usage(0);}
		else if (strcmp(argv[1], "-h") == 0)
			{usage(0);}
		else if (strcmp(argv[1], "-?") == 0)
			{usage(0);}
		else if (strcmp(argv++[1], "-") == 0)
			break;
		else
			{usage(2);}
		argv++;
	}


	if (xml) {
		stream->write_function(stream, "%s", "<routes>\n");
	} else {
		stream->write_function(stream, "%10s\t%10s\t%10s\t%10s\t%10s\n", "Preference", "Weight", "Transport", "Port", "Address");
		stream->write_function(stream, "================================================================================\n");
	}

	if (!family)
		dig->ip4 = 1, dig->ip6 = 2;

	if (argv[1] && argv[1][0] == '@')
		dnsserver = argv++[1] + 1;



	if (!argv[1])
		{usage(2);}


	multiple = argv[1] && argv[2];

	if (!count_transports(dig, NULL, NULL)) {
		prepare_transport(dig, "udp");
		prepare_transport(dig, "tcp");
		if (o_sctp)
			prepare_transport(dig, "sctp");
		prepare_transport(dig, "tls");
		if (o_tls_sctp)
			prepare_transport(dig, "tls-sctp");
	}

	dig->sres = sres_resolver_new(getenv("SRESOLV_CONF"));
	if (!dig->sres)
		{usage(1);}
	
	for (; (string = argv[1]); argv++) {
		if (multiple)
			stream->write_function(stream, "%s", string);

		uri = url_hdup(home, (void *)string);

		if (uri && uri->url_type == url_unknown)
			url_sanitize(uri);

		if (uri && uri->url_type == url_any)
			continue;

		if (!uri || (uri->url_type != url_sip && uri->url_type != url_sips)) {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s: invalid uri\n", string);
			exitcode = 1;
			continue;
		}

		port = url_port(uri);
		if (port && !port[0]) port = NULL;
		if (url_param(uri->url_params, "transport=", tport, sizeof tport) > 0)
			transport = tport;

		host = uri->url_host;

		if (host_is_ip_address(host)) {
			if (transport) {
				print_result(host, port, transport, 1.0, 1, stream);
			}
			else if (uri->url_type == url_sips) {
				print_result(host, port, "tls", 1.0, 1, stream);
			}
			else {
				print_result(host, port, "udp", 1.0, 1, stream);
				print_result(host, port, "tcp", 1.0, 2, stream);
			}
			continue;
		}

		if (!host_is_domain(host)) {
			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s: invalid host\n", string);
			exitcode = 1;
			continue;
		}

		dig->sips = uri->url_type == url_sips;
		dig->preference = 1;

		if (!port && !transport && dig_naptr(dig, host, 1.0, stream))
			continue /* resolved naptr */;
		else if (!port && dig_all_srvs(dig, transport, host, 1.0, stream))
			continue /* resolved srv */;
		else if (dig_addr(dig, transport, host, port, 1.0, stream))
			continue /* resolved a/aaaa */;

		stream->write_function(stream, "-ERR: %s: not found\n", string);
		exitcode = 1;
	}

	if (xml) {
		stream->write_function(stream, "%s", "</routes>\n");
	}


 fail:
	su_home_unref(home);
	sres_resolver_unref(dig->sres);
	switch_safe_free(mycmd);

	return SWITCH_STATUS_SUCCESS;
}