ttyUSB0串口收发+六分sdk融合完全测试成功

效果:RTK线口输出GPGGA经过六分sdk把GPGGA数据传输到六分服务器,然后六分服务器通过一个回调函数下发RTCM数据,经过星网宇达惯导内部解析生成GPFPD数据从串口助手显示。

一、打开串口,设置标志位,设置波特率

    int   c=0, res;
    printf("uart Start...\n");
    fd = open(UART_DEVICE, O_RDWR|O_NOCTTY);
    if (fd < 0) {
        perror(UART_DEVICE);
        exit(1);
    }
    printf("uart Open...\n");
    set_speed(fd,115200);
	if (set_parity(fd,8,1,'N') == FALSE)  {
		printf("Set Parity Error\n");
		exit (0);
	}

二、经过循环,分别三个状态:初始化、start、work

while (SIXENTS_TRUE)
    {
        usleep(200 * 1000); // 200ms
        /****************************************
         * csdk_run_step: 0 sdk init
         *                1 sdk start
         *                2 work
         ****************************************/
        switch (csdk_run_step)
        {
            case 0:
            {
                retVal = sixents_sdkInit(&param);
                if (retVal != SIXENTS_RET_OK)
                {
                    printf("---MAIN case 0| sixents_sdkInit failed! retVal:%d.\r\n", retVal);
                    sixents_sdkFinal();
                }
                else
                {
                    retVal = sixents_sdkSetBuff(SIXENTS_BUFF_BIG);
                    printf("---MAIN case 0| sixents_sdkInit success---\r\n");
                    csdk_run_step = 1;
                }
            }
            break;
            case 1:
            {
                printf("---MAIN case 1| sixents_sdkStart start---\r\n");
                retVal = sixents_sdkStart();
                if (retVal != SIXENTS_RET_OK)
                {
                    printf("---MAIN case 1| sixents_sdkStart failed! retVal:%d ---\r\n", retVal);
                    usleep(1000 * 1000); // 0.3s
                }
                else
                {
                    printf("---MAIN case 1| sixents_sdkStart success---\r\n");
                    csdk_run_step = 2;
                }
            }
            break;
            case 2:
            {
                //if ((count < 11 && (count % 5) == 0)  || (count > 320 && (count % 5) == 0)) // 模拟60s不发送gga断开连接
                if ((count % 5) == 0) // 1s发送一次GGA
                {
                    res = read(fd, buf, 90);         
                    if(res==0)
                     continue;
                    buf[res]=0;
                    printf("send gga is: %s\n",buf);
                   
                    //sixents_char gga_temp[3];
                    printf("buf_len %d\n",strlen(buf));
                    retVal = sixents_sdkSendGGAStr(buf, strlen(buf));
                    if (retVal != SIXENTS_RET_OK)
                    {
                        printf("%s| Send GGA failed with error: %d.\n", __FUNCTION__, retVal);
                    }
                }

                retVal = sixents_sdkTick();
                if (retVal != SIXENTS_RET_OK)
                {
                    printf("%s| sdkTick failed with error: %d.\n", __FUNCTION__, retVal);
                }
                count++;
            }
            break;
            default:
                printf("[six-log]:switch nothing\r\n");
                break;
        }
        // check suspend flag and suspend task
        // if (Six_RTK_State_Flag == 0)
        //{
        //    csdk_run_step = 0; // state to 0
        //    // suspend csdk task and printf log
        //    sixents_sdkFinal();
        //    printf("[six-log]:*4-suspend sixents_task_CSDK !\r\n");
        //}
    } // while

    return retVal;
}

使用read函数从fd指向的串口里面读取gga数据存放到buf中,然后通过
retVal = sixents_sdkSendGGAStr(buf, strlen(buf));这条语句发送到六分平台,六分平台接收gga数据,把差分数据通过回调函数下发显示。

三、回调函数显示差分数据

void GetDiffData(const sixents_char* buff, sixents_uint32 len)
{
        sixents_uint32 i;
        int res = 0;
        printf("len is: %d\n",len);
    // if (buff == sixents_null || len == 0)
    // {
    //     return;
    // }
    // // ToDo: 以下应该修改为客户自己对差分数据处理的逻辑
    char *str;
    str = (char *)malloc(2*len*sizeof(char)+2);
    for (i = 0; i < len; i++)
    {
      char str_temp[2];
      //printf("%02x ", (sixents_uint8)buff[i]);
      sprintf(str_temp,"%02X",(sixents_uint8)buff[i]);
      strcpy(&str[i*2],str_temp);
      //write(fd,str,sizeof(str));
    }
    str[2*len*sizeof(char)] = '\r';
    str[2*len*sizeof(char)+1] = '\n';
      printf("%s",str);
      //close(fd);
    char *fd_str;
    fd_str = (char *)malloc(len+2);
      
    for(int i=0;i<len;i++)
    {
      fd_str[i] = buff[i];
    }
    fd_str[len] = '\r';
    fd_str[len+1] = '\n';
    fd = open(UART_DEVICE, O_RDWR|O_NOCTTY);
    write(fd,fd_str,len+2);
    for (i = 0; i < len; i++)
    {
         //printf("%02X ", ( sixents_uint8 )buff[i]);
         //if ((i + 1) % 80u == 0)
         //{
             //printf("\n");
         //}
    }
     printf("\n");
     //printf("\r\n");
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值