Ejemplo n.º 1
0
/*---------------------------------------------------------------------------------------------------------*/
void LIN_FunctionTestUsingLinCtlReg(void)
{
    uint32_t u32Item;

    /* Set UART Configuration, LIN Max Speed is 20K */
    UART_SetLine_Config(UART1, 9600, UART_WORD_LEN_8, UART_PARITY_NONE, UART_STOP_BIT_1);

    /* === CASE 1====
        The sample code will send a LIN header with a 12-bit break field,
        0x55 sync field and ID field is 0x30. Measurement the UART1 Tx pin to check it.
    */

    /* === CASE 2====
        The sample code will send a LIN header with ID is 0x35 and response field.
        The response field with 8 data bytes and checksum without including ID.
        Measurement the UART1 Tx pin to check it.
    */

    /* === CASE 3====
        The sample code will send a LIN header with ID is 0x12 and response field.
        The response field with 8 data bytes and checksum with including ID.
        Measurement the UART1 Tx pin to check it.
    */

    do {
        LIN_TestItem();
        u32Item = getchar();
        printf("%c\n", u32Item);
        switch(u32Item) {
        case '1':
            LIN_SendHeaderUsingLinCtlReg(0x30, UART_LIN_CTL_LIN_HEAD_SEL_BREAK_SYNC_ID);
            break;
        case '2':
            LIN_MasterTestUsingLinCtlReg(0x35, MODE_CLASSIC);
            break;
        case '3':
            LIN_MasterTestUsingLinCtlReg(0x12, MODE_ENHANCED);
            break;
        default:
            break;
        }
    } while(u32Item != 27);

    /* Clear header select setting */
    UART1->LIN_CTL &= ~UART_LIN_CTL_LIN_HEAD_SEL_Msk;

    UART_Close(UART1);

    printf("\nLINSample Code End.\n");
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    int fd = FALSE;
    int ret;
    char rcv_buf[512];
	char send_buf[512];
    int i;
    if(argc != 2){
	    printf("Usage: %s /dev/ttySn \n",argv[0]);
	    return FALSE;
    }
    fd = UART_Open(fd,argv[1]);
    if(FALSE == fd){
	    printf("open error\n");
	    exit(1);
    }
    ret  = UART_Init(fd,9600,0,8,1,'N');
    if (FALSE == fd){
	    printf("Set Port Error\n");
	    exit(1);
    }
    strcpy(send_buf,"ff0161\n");
    ret  = UART_Send(fd,send_buf,strlen(send_buf));
    if(FALSE == ret){
	    printf("write error!\n");
	    exit(1);
    }
    printf("command: %s\n",send_buf);
    memset(rcv_buf,0,sizeof(rcv_buf));
    for(i=0;;i++)
    {
	    ret = UART_Recv(fd, rcv_buf,512);
    	if( ret > 0){
	    	rcv_buf[ret]='\0';
	    	printf("%s",rcv_buf);
	    } else {
	    	printf("cannot receive data1\n");
            //break;
	    }
	  	if('\n' == rcv_buf[ret-1]) break;
    }
    UART_Close(fd);
    return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
	ros::init(argc, argv, "nav");
	ros::NodeHandle n;
	//ros::Publisher chatter_pub = n.advertise<mini::naviLoc>("navmsg", 1);
	tf::TransformBroadcaster br;
	tf::Transform transform_v2c,transform_w2v;
	tf::Quaternion q(-sqrt(2)/2,0,0,sqrt(2)/2); //need calibration
	transform_v2c.setOrigin(tf::Vector3(-0.025,0.125,0.23)); //need calibration
	transform_v2c.setRotation(q);	
	transform_v2c = transform_v2c.inverse();

	int fd = -1;
	fd = UART_Open(fd,"/dev/ttyS4");
	UART_Init(fd,115200,0,8,1,'N');	

	int data_len = 10;
	char rcv_buf[100];
	//FILE* fp = fopen("/home/haha/catkin_ws/odom.txt","w");

	int ret;

	while (ros::ok())
	{
		mini::naviLoc msg;	
		struct timeval tv;	

		while(1)
		{
			//ROS_INFO(" ");
			ret = UART_Recv(fd, rcv_buf,1);
			//ROS_INFO("[%d]",ret);
			//usleep(10000);
			if(ret==1)
			{
				//ROS_INFO("[%02X]",rcv_buf[0]);
			}
			if(ret==1 && rcv_buf[0]==char(0xA2))
			{
				break;
			}
		}
		int counter = 1;
		while(counter<data_len)
		{
			//ROS_INFO(" ");
			ret = UART_Recv(fd, &rcv_buf[counter],1);
			//ROS_INFO("[%d]",ret);
			/*for(int i=0;i<ret;i++)
			{
				printf("%02X ",rcv_buf[i]);
			}
			printf("\n");*/
			if(ret==-1)
			{
				continue;
			}
			counter++;
		}
 		gettimeofday(&tv,0);
		if(rcv_buf[data_len-1]!=char(0x2A))
		{
			continue;
		}
		unsigned int timeStamp = tv.tv_sec%100000*1000+tv.tv_usec/1000;
		SerialData2Msg(timeStamp, rcv_buf, data_len, msg);
		
		ros::Time ros_time = ros::Time::now();
		transform_w2v.setOrigin(tf::Vector3(msg.x,msg.y,0.0)); 
		q.setRPY(0.0,0.0,msg.theta);
		transform_w2v.setRotation(q);
		transform_w2v = transform_w2v.inverse();
		
		br.sendTransform(tf::StampedTransform(transform_w2v, ros_time, "/base_frame","/odom_frame"));
		br.sendTransform(tf::StampedTransform(transform_v2c, ros_time, "/camera_rgb_optical_frame","/base_frame"));
    	//chatter_pub.publish(msg);
		ROS_INFO("[%d],[%f],[%f],[%f]",msg.timestamp,msg.x,msg.y,msg.theta);
		//fprintf(fp,"%d %f %f %f\n",msg.timestamp,msg.x,msg.y,msg.theta);
		
		//fflush(fp);
    	ros::spinOnce();
	}
	UART_Close(fd);
	//fclose(fp);
	return 0;
}
Ejemplo n.º 4
0
int main(int argc, char** argv)
{
	int rc = 0;
	unsigned char buf[100];
	unsigned char readbuf[100];

	/**********UART************/
	int		fd = FALSE;
    int 	ret;
    unsigned char	rcv_buf[512];
	unsigned char 	send_buf[64];
	Data_t	rcv_data;
    int i;
	int j;

    cJSON *root,*img,*thm;
    char *out;
	/* Our "gallery" item: */
	root=cJSON_CreateObject();
	cJSON_AddItemToObject(root, "Image", img=cJSON_CreateObject());
	cJSON_AddNumberToObject(img,"Width",800);
	cJSON_AddNumberToObject(img,"Height",600);
	cJSON_AddStringToObject(img,"Title","View from 15th Floor");
	cJSON_AddItemToObject(img, "Thumbnail", thm=cJSON_CreateObject());
	cJSON_AddStringToObject(thm, "Url", "http:/*www.example.com/image/481989943");
	cJSON_AddNumberToObject(thm,"Height",125);
	cJSON_AddStringToObject(thm,"Width","100");
	out=cJSON_Print(root);	cJSON_Delete(root);	printf("%s\n",out);	free(out);	/* Print to text, Delete the cJSON, print it, release the string. */

	fd = UART_Open(fd,"/dev/ttyS1");
    if(FALSE == fd){
	   printf("open error\n");
	   exit(1);
    }
    ret  = UART_Init(fd,115200,0,8,1,'N');
    if (FALSE == fd){
	   printf("Set Port Error\n");
	   exit(1);
    }
    ret  = UART_Send(fd,"*IDN?\n",6);
    if(FALSE == ret){
	   printf("write error!\n");
	   exit(1);
    }
    printf("command: %s\n","*IDN?");
    memset(rcv_buf,0,sizeof(rcv_buf));

	if (argc < 2)
		usage();

	char* topic = argv[1];

//	if (strchr(topic, '#') || strchr(topic, '+'))
//		opts.showtopics = 1;
//	if (opts.showtopics)
//		printf("topic is %s\n", topic);

	getopts(argc, argv);

	Network n;
	Client c;
	MQTTMessage message={0,0,0,0,"hello",5};//dup,qos,retained,packetid,payload,payloadlen


	NewNetwork(&n);
	ConnectNetwork(&n, opts.host, opts.port);
	MQTTClient(&c, &n, 1000, buf, 100, readbuf, 100);

	MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
	data.willFlag = 0;
	data.MQTTVersion = 3;
	data.clientID.cstring = opts.clientid;
	data.username.cstring = opts.username;
	data.password.cstring = opts.password;

	data.keepAliveInterval = 10;
	data.cleansession = 1;
	printf("Connecting to %s %d\n", opts.host, opts.port);

	rc = MQTTConnect(&c, &data);
	printf("Connected %d\n", rc);

//test
while(1)
{
		message.payload = "efewewreweefer";
        message.payloadlen = strlen(message.payload);
			MQTTPublish(&c,topic,&message);
}
	while (!toStop)
	{
		MQTTYield(&c, 1000);
	}
	printf("Stopping\n");
	UART_Close(fd);
	MQTTDisconnect(&c);
	n.disconnect(&n);

	return 0;
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
	/******MQTT*******/
	MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
	int rc = 0;
	char buf[200];
	int buflen = sizeof(buf);
	int mysock = 0;
	MQTTString topicString = MQTTString_initializer;
	char* payload = "mypayload";
	int payloadlen = strlen(payload);
	int len = 0;
	char *host = "192.168.8.241";
	int port = 1883;

	/******UART*******/
	int fd = FALSE;
	int ret;
	char rcv_buf[512];
 	int i;
	if(argc < 2){
		printf("Usage: %s /dev/ttySn \n",argv[0]);
		return FALSE;
	}

	if (argc > 2)
		host = argv[2];

	if (argc > 3)
		port = atoi(argv[3]);
	
	fd = UART_Open(fd,argv[1]);
	if(FALSE == fd){
		printf("open error\n");
		exit(1);
	}
	ret  = UART_Init(fd,9600,0,8,1,'N');
	if (FALSE == fd){
		printf("Set Port Error\n");
		exit(1);
	}

	ret  = UART_Send(fd,"*IDN?\n",6);
	if(FALSE == ret){
		printf("write error!\n");
		exit(1);
	}
	printf("command: %s\n","*IDN?");
	memset(rcv_buf,0,sizeof(rcv_buf));

	/**************MQTT tansport*************/

	mysock = transport_open(host,port);
	if(mysock < 0)
		return mysock;

	printf("Sending to hostname %s port %d\n", host, port);

	data.clientID.cstring = "me";
	data.keepAliveInterval = 20;
	data.cleansession = 1;
	data.username.cstring = "testuser";
	data.password.cstring = "testpassword";
	data.MQTTVersion = 4;


	for(i=0;;i++)
	{
	   	ret = UART_Recv(fd, rcv_buf,512);	
		if(ret > 0)
		{
			rcv_buf[ret]='\0';
			printf("%s",rcv_buf);

			len = MQTTSerialize_connect((unsigned char *)buf, buflen, &data);
			topicString.cstring = "mytopic";
		
			len += MQTTSerialize_publish((unsigned char *)(buf + len), buflen - len, 0, 0, 0, 0, topicString, (unsigned char *)rcv_buf, ret+1);
			len += MQTTSerialize_disconnect((unsigned char *)(buf + len), buflen - len);
			rc = transport_sendPacketBuffer(mysock, buf, len);
			if (rc == len)
				printf("Successfully published\n");
			else
				printf("Publish failed\n");
		}
		else
		{
			printf("cannot receive data1\n");
			break;
		}
	}

exit:
	UART_Close(fd);
	transport_close(mysock);

	return 0;
}