RTCM数据包编码

 

uint8_t rtcmbytes[1200] = {0};
uint32_t rtcm_size = 0;
static uint32_t SetRTCM3Data(uint64_t data, uint8_t bits, uint8_t *rtcmbytes, uint8_t end_flag)
{
    static uint32_t nbyte = 0;
    uint32_t temp_nbyte = 0;

    static uint64_t byte = 0;
    static uint8_t bitsbyte = 0;

    static uint32_t len = 0;

    bitsbyte += bits;
    byte = byte|((data)<<(64-bitsbyte));

    /* synchronize frame */
    if (nbyte==0)
    {
        if (data!=0xD3) return 0;
        rtcmbytes[nbyte++]=data;
        byte = byte<<8;
        bitsbyte -= 8;
        return 0;
    }
    uint8_t temp = bitsbyte/8;
    uint8_t temp_end = bitsbyte%8;
    if(end_flag && temp_end)
    {
        temp += 1;
        bitsbyte += temp_end;
    }
    for(int i = 0; i<temp; i++)
    {
        rtcmbytes[nbyte++] = (uint8_t)((((byte))&((uint64_t)0xFF00000000000000))>>56);
        byte = byte<<8;
        bitsbyte -= 8;
    }

    if (nbyte==3)
    {
        len=getbitu(rtcmbytes,14,10)+3; /* length without parity */
    }
    if (nbyte<3||nbyte<len) return 0;

    /* check parity */
    bitsbyte += 24;
    byte = byte|(((uint64_t)(rtk_crc24q(rtcmbytes,len)))<<(64-bitsbyte));

    temp = bitsbyte/8;
    for(int i = 0; i<temp; i++)
    {
        rtcmbytes[nbyte++] = (uint8_t)((((byte))&((uint64_t)0xFF00000000000000))>>56);
        byte = byte<<8;
    }
    temp_nbyte = len+3;

    nbyte = 0;
    byte = 0;
    bitsbyte = 0;
    len = 0;

    return temp_nbyte;
}

示例

 

 

        SetRTCM3Data(0xD3, 8, rtcmbytes, 0);
        SetRTCM3Data(0x00, 6, rtcmbytes, 0);
        SetRTCM3Data(0x2C, 10, rtcmbytes, 0);
        SetRTCM3Data(0x3E7, 12, rtcmbytes, 0);
        SetRTCM3Data(0x28, 8, rtcmbytes, 0);
        SetRTCM3Data(123456, 30, rtcmbytes, 0);
        SetRTCM3Data(2, 4, rtcmbytes, 0);
        SetRTCM3Data(0x12, 32, rtcmbytes, 0);
        SetRTCM3Data(0x12, 32, rtcmbytes, 0);
        SetRTCM3Data(0x12, 32, rtcmbytes, 0);
        SetRTCM3Data(0x12, 24, rtcmbytes, 0);
        SetRTCM3Data(0x12, 24, rtcmbytes, 0);
        SetRTCM3Data(0x12, 24, rtcmbytes, 0);
        SetRTCM3Data(0x12, 18, rtcmbytes, 0);
        SetRTCM3Data(0x12, 18, rtcmbytes, 0);
        SetRTCM3Data(0x12, 18, rtcmbytes, 0);
        SetRTCM3Data(0x00, 8, rtcmbytes, 0);
        SetRTCM3Data(36, 32, rtcmbytes, 0);
        rtcm_size = SetRTCM3Data(24, 32, rtcmbytes, 1);
        //printf("rtcm_size: %d\r\n", rtcm_size);
        MyPrintf((char*)rtcmbytes, rtcm_size);
        rtcm_size = 0;

 

结果

 

D3 00 2C 3E 72 80 00 78 90 08 00 00 00 48 00 00 00 48 00 00 00 48 00 00 48 00 00 48 00 00 48 00 12 00 04 80 01 20 00 00 00 02 40 00 00 01 80 16 A8 BC 

 

posted @ 2024-04-10 15:45  妖岭  阅读(170)  评论(0)    收藏  举报