Thread: Converting matrices to arrays/vectors in Cpp

  1. #1
    Registered User
    Join Date
    Feb 2022
    Posts
    5

    Converting matrices to arrays/vectors in Cpp

    Dear experts,


    Thanks for your help in advance.
    I have very limited knowledge of C/C++ but have a challenging task from a microcontroller's source code. The microcontroller is used to handle calculations and data transfer for a radar device.

    In the original source code, the radar transfers matrix type data over UART to a PC. But the frame rate of this transfer is limited and I am looking to increase it.


    Increasing the frame rate leads to 'clogging' of the UART and data transfer will usually fail. I am then looking into converting these matrices into vectors or arrays before trying to transfer them over the 'baudwidth' limited UART.

    The original codes of the function that handles the data transfer is as follows:

    Code:
    /** @brief Transmits detection data over UART
    
    *
    *    The following data is transmitted:
    *    1. Header (size = 32bytes), including "Magic word", (size = 8 bytes)
    *       and including the number of TLV items
    *    TLV Items:
    *    2. If detectedObjects flag is 1 or 2, DPIF_PointCloudCartesian structure containing
    *       X,Y,Z location and velocity for detected objects,
    *       size = sizeof(DPIF_PointCloudCartesian) * number of detected objects
    *    3. If detectedObjects flag is 1, DPIF_PointCloudSideInfo structure containing SNR
    *       and noise for detected objects,
    *       size = sizeof(DPIF_PointCloudCartesian) * number of detected objects
    *    4. If logMagRange flag is set,  rangeProfile,
    *       size = number of range bins * sizeof(uint16_t)
    *    5. If noiseProfile flag is set,  noiseProfile,
    *       size = number of range bins * sizeof(uint16_t)
    *    6. If rangeAzimuthHeatMap flag is set, the zero Doppler column of the
    *       range cubed matrix, size = number of Rx Azimuth virtual antennas *
    *       number of chirps per frame * sizeof(uint32_t)
    *    7. If rangeDopplerHeatMap flag is set, the log magnitude range-Doppler matrix,
    *       size = number of range bins * number of Doppler bins * sizeof(uint16_t)
    *    8. If statsInfo flag is set, the stats information
    *   @param[in] uartHandle   UART driver handle
    *   @param[in] result       Pointer to result from object detection DPC processing
    *   @param[in] timingInfo   Pointer to timing information provided from core that runs data path
    */
    
    staticvoid MmwDemo_transmitProcessedOutput
    
    (
    
       UART_Handle     uartHandle,
       DPC_ObjectDetection_ExecuteResult   *result,
       MmwDemo_output_message_stats        *timingInfo
    )
    {
    
       MmwDemo_output_message_header header;
       MmwDemo_GuiMonSel   *pGuiMonSel;
       MmwDemo_SubFrameCfg *subFrameCfg;
    uint32_t tlvIdx = 0;
    uint32_t index;
    uint32_t numPaddingBytes;
    uint32_t packetLen;
    uint8_t padding[MMWDEMO_OUTPUT_MSG_SEGMENT_LEN];
       MmwDemo_output_message_tl   tl[MMWDEMO_OUTPUT_MSG_MAX];
    int32_t errCode;
    uint16_t *detMatrix = (uint16_t *)result->detMatrix.data;
       DPIF_PointCloudCartesian *objOut;
       cmplx16ImRe_t *azimuthStaticHeatMap;
       DPIF_PointCloudSideInfo *objOutSideInfo;
       DPC_ObjectDetection_Stats *stats;
    
       /* Get subframe configuration */
       subFrameCfg = &gMmwMssMCB.subFrameCfg[result->subFrameIdx];
    
       /* Get Gui Monitor configuration */
       pGuiMonSel = &subFrameCfg->guiMonSel;
    
       /* Clear message header */
       memset((void *)&header, 0, sizeof(MmwDemo_output_message_header));
    
       /******************************************************************
          Send out data that is enabled, Since processing results are from DSP,
          address translation is needed for buffer pointers
       *******************************************************************/
       {
           detMatrix = (uint16_t *) SOC_translateAddress((uint32_t)detMatrix,
                                                        SOC_TranslateAddr_Dir_FROM_OTHER_CPU,
                                                        &errCode);
           DebugP_assert ((uint32_t)detMatrix!= SOC_TRANSLATEADDR_INVALID);
    
           objOut = (DPIF_PointCloudCartesian *) SOC_translateAddress((uint32_t)result->objOut,
                                                        SOC_TranslateAddr_Dir_FROM_OTHER_CPU,
                                                        &errCode);
           DebugP_assert ((uint32_t)objOut != SOC_TRANSLATEADDR_INVALID);
    
           objOutSideInfo = (DPIF_PointCloudSideInfo *) SOC_translateAddress((uint32_t)result->objOutSideInfo,
                                                        SOC_TranslateAddr_Dir_FROM_OTHER_CPU,
                                                        &errCode);
           DebugP_assert ((uint32_t)objOutSideInfo != SOC_TRANSLATEADDR_INVALID);
    
           stats = (DPC_ObjectDetection_Stats *) SOC_translateAddress((uint32_t)result->stats,
                                                        SOC_TranslateAddr_Dir_FROM_OTHER_CPU,
                                                        &errCode);
           DebugP_assert ((uint32_t)stats != SOC_TRANSLATEADDR_INVALID);
    
    
           result->radarCube.data = (void *) SOC_translateAddress((uint32_t) result->radarCube.data,
                                                        SOC_TranslateAddr_Dir_FROM_OTHER_CPU,
                                                        &errCode);
           DebugP_assert ((uint32_t) result->radarCube.data!= SOC_TRANSLATEADDR_INVALID);
       }
    
       /* Header: */
       header.platform =  0xA6843;
       header.magicWord[0] = 0x0102;
       header.magicWord[1] = 0x0304;
       header.magicWord[2] = 0x0506;
       header.magicWord[3] = 0x0708;
       header.numDetectedObj = result->numObjOut;
       header.version =    MMWAVE_SDK_VERSION_BUILD |
                           (MMWAVE_SDK_VERSION_BUGFIX << 8) |
                           (MMWAVE_SDK_VERSION_MINOR << 16) |
                           (MMWAVE_SDK_VERSION_MAJOR << 24);
    
       packetLen = sizeof(MmwDemo_output_message_header);
    if ((pGuiMonSel->detectedObjects == 1) || (pGuiMonSel->detectedObjects == 2) &&
            (result->numObjOut > 0))
       {
           tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_DETECTED_POINTS;
           tl[tlvIdx].length = sizeof(DPIF_PointCloudCartesian) * result->numObjOut;
           packetLen += sizeof(MmwDemo_output_message_tl) + tl[tlvIdx].length;
           tlvIdx++;
       }
       /* Side info */
    if ((pGuiMonSel->detectedObjects == 1) && (result->numObjOut > 0))
       {
           tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_DETECTED_POINTS_SIDE_INFO;
           tl[tlvIdx].length = sizeof(DPIF_PointCloudSideInfo) * result->numObjOut;
           packetLen += sizeof(MmwDemo_output_message_tl) + tl[tlvIdx].length;
           tlvIdx++;
       }
    if (pGuiMonSel->logMagRange)
       {
           tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_RANGE_PROFILE;
           tl[tlvIdx].length = sizeof(uint16_t) * subFrameCfg->numRangeBins;
           packetLen += sizeof(MmwDemo_output_message_tl) + tl[tlvIdx].length;
           tlvIdx++;
       }
    if (pGuiMonSel->noiseProfile)
       {
           tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_NOISE_PROFILE;
           tl[tlvIdx].length = sizeof(uint16_t) * subFrameCfg->numRangeBins;
           packetLen += sizeof(MmwDemo_output_message_tl) + tl[tlvIdx].length;
           tlvIdx++;
       }
    if (pGuiMonSel->rangeAzimuthHeatMap)
       {
           tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_AZIMUT_STATIC_HEAT_MAP;
           tl[tlvIdx].length = result->azimuthStaticHeatMapSize * sizeof(cmplx16ImRe_t);
           packetLen += sizeof(MmwDemo_output_message_tl) +  tl[tlvIdx].length;
           tlvIdx++;
       }
    if (pGuiMonSel->rangeDopplerHeatMap)
       {
           tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_RANGE_DOPPLER_HEAT_MAP;
           tl[tlvIdx].length = subFrameCfg->numRangeBins * subFrameCfg->numDopplerBins * sizeof(uint16_t);
           packetLen += sizeof(MmwDemo_output_message_tl) + tl[tlvIdx].length;
           tlvIdx++;
       }
    
    if (pGuiMonSel->statsInfo)
       {
           tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_STATS;
           tl[tlvIdx].length = sizeof(MmwDemo_output_message_stats);
           packetLen += sizeof(MmwDemo_output_message_tl) + tl[tlvIdx].length;
           tlvIdx++;
    
           MmwDemo_getTemperatureReport();
           tl[tlvIdx].type = MMWDEMO_OUTPUT_MSG_TEMPERATURE_STATS;
           tl[tlvIdx].length = sizeof(MmwDemo_temperatureStats);
           packetLen += sizeof(MmwDemo_output_message_tl) + tl[tlvIdx].length;
           tlvIdx++;
       }
    
       header.numTLVs = tlvIdx;
       /* Round up packet length to multiple of MMWDEMO_OUTPUT_MSG_SEGMENT_LEN */
       header.totalPacketLen = MMWDEMO_OUTPUT_MSG_SEGMENT_LEN *
               ((packetLen + (MMWDEMO_OUTPUT_MSG_SEGMENT_LEN-1))/MMWDEMO_OUTPUT_MSG_SEGMENT_LEN);
       header.timeCpuCycles = Pmu_getCount(0);
       header.frameNumber = stats->frameStartIntCounter;
       header.subFrameNumber = result->subFrameIdx;
    
       UART_writePolling (uartHandle,
                          (uint8_t*)&header,
    sizeof(MmwDemo_output_message_header));
    
       tlvIdx = 0;
       /* Send detected Objects */
    if ((pGuiMonSel->detectedObjects == 1) || (pGuiMonSel->detectedObjects == 2) &&
           (result->numObjOut > 0))
       {
           UART_writePolling (uartHandle,
                              (uint8_t*)&tl[tlvIdx],
    sizeof(MmwDemo_output_message_tl));
    
           /*Send array of objects */
           UART_writePolling (uartHandle, (uint8_t*)objOut,
    sizeof(DPIF_PointCloudCartesian) * result->numObjOut);
           tlvIdx++;
       }
    
       /* Send detected Objects Side Info */
    if ((pGuiMonSel->detectedObjects == 1) && (result->numObjOut > 0))
       {
    
           UART_writePolling (uartHandle,
                              (uint8_t*)&tl[tlvIdx],
    sizeof(MmwDemo_output_message_tl));
    
           UART_writePolling (uartHandle, (uint8_t*)objOutSideInfo,
    sizeof(DPIF_PointCloudSideInfo) * result->numObjOut);
           tlvIdx++;
       }
    
       /* Send Range profile */
    if (pGuiMonSel->logMagRange)
       {
           UART_writePolling (uartHandle,
                              (uint8_t*)&tl[tlvIdx],
    sizeof(MmwDemo_output_message_tl));
    
    for(index = 0; index < subFrameCfg->numRangeBins; index++)
           {
               UART_writePolling (uartHandle,
                       (uint8_t*)&detMatrix[index*subFrameCfg->numDopplerBins],
    sizeof(uint16_t));
           }
           tlvIdx++;
       }
    
       /* Send noise profile */
    if (pGuiMonSel->noiseProfile)
       {
    uint32_t maxDopIdx = subFrameCfg->numDopplerBins/2 -1;
           UART_writePolling (uartHandle,
                              (uint8_t*)&tl[tlvIdx],
    sizeof(MmwDemo_output_message_tl));
    
    for(index = 0; index < subFrameCfg->numRangeBins; index++)
           {
               UART_writePolling (uartHandle,
                       (uint8_t*)&detMatrix[index*subFrameCfg->numDopplerBins + maxDopIdx],
    sizeof(uint16_t));
           }
           tlvIdx++;
       }
    
       /* Send data for static azimuth heatmap */
    if (pGuiMonSel->rangeAzimuthHeatMap)
       {
           azimuthStaticHeatMap = (cmplx16ImRe_t *) SOC_translateAddress((uint32_t)result->azimuthStaticHeatMap,
                                                        SOC_TranslateAddr_Dir_FROM_OTHER_CPU,
                                                        &errCode);
           DebugP_assert ((uint32_t)azimuthStaticHeatMap!= SOC_TRANSLATEADDR_INVALID);
    
           UART_writePolling (uartHandle,
                              (uint8_t*)&tl[tlvIdx],
    sizeof(MmwDemo_output_message_tl));
    
           UART_writePolling (uartHandle,
                   (uint8_t *)azimuthStaticHeatMap,
                   result->azimuthStaticHeatMapSize * sizeof(cmplx16ImRe_t));
    
           tlvIdx++;
       }
    
       /* Send data for range/Doppler heatmap */
    
    if (pGuiMonSel->rangeDopplerHeatMap == 1)
    
       {
           UART_writePolling (uartHandle,
                              (uint8_t*)&tl[tlvIdx],
    sizeof(MmwDemo_output_message_tl));
    
           UART_writePolling (uartHandle,
                   (uint8_t*)detMatrix,
    
                   tl[tlvIdx].length);
           tlvIdx++;
       }
    
       /* Send stats information */
    if (pGuiMonSel->statsInfo == 1)
       {
           UART_writePolling (uartHandle,
                              (uint8_t*)&tl[tlvIdx],
    sizeof(MmwDemo_output_message_tl));
    
           /* Address translation is done when buffer is received*/
           UART_writePolling (uartHandle,
                              (uint8_t*)timingInfo,
                              tl[tlvIdx].length);
           tlvIdx++;        
           UART_writePolling (uartHandle,
                              (uint8_t*)&tl[tlvIdx],
    sizeof(MmwDemo_output_message_tl));
           UART_writePolling (uartHandle,
                              (uint8_t*)&gMmwMssMCB.temperatureStats,
                              tl[tlvIdx].length);
           tlvIdx++;
       }
    
       /* Send padding bytes */
       numPaddingBytes = MMWDEMO_OUTPUT_MSG_SEGMENT_LEN - (packetLen & (MMWDEMO_OUTPUT_MSG_SEGMENT_LEN-1));
    if (numPaddingBytes<MMWDEMO_OUTPUT_MSG_SEGMENT_LEN)
       {
           UART_writePolling (uartHandle,
                               (uint8_t*)padding,
                               numPaddingBytes);
       }
    
    }

    I am looking into reducing the "rangeDopplerHeatMap" data which I suppose are in the "(uint8_t*)detMatrix" into vectors/arrays.

    I have tried solving this by the code below by changing the section of the "if (pGuiMonSel->rangeDopplerHeatMap == 1)" statement . But getting lots of compilation errors.


    Code:
    staticvoid MmwDemo_transmitProcessedOutput
    (
    
       UART_Handle     uartHandle,
       DPC_ObjectDetection_ExecuteResult   *result,
       MmwDemo_output_message_stats        *timingInfo
    )
    {
    .
    .
    .
    .
    uint8_t DopplerVector;
    uint32_t index2;
    
    
    
    
    /* Send data for range/Doppler heatmap */
    if (pGuiMonSel->rangeDopplerHeatMap == 1)
    
       {
    
           UART_writePolling (uartHandle, (uint8_t*)&tl[tlvIdx], sizeof(MmwDemo_output_message_tl));
    
    
    
    uint8_t[subFrameCfg->numDopplerBins] DopplerVector;
    
    for(index = 0; index < subFrameCfg->numRangeBins; index++)
           {
    for(index2 = 0; index2 < subFrameCfg->numDopplerBins; index2++){
    
                   DopplerVector[index2] = DopplerVector[index2]+detMatrix[index*subFrameCfg->numDopplerBins+index2]
    
               }
           }
    
    
           UART_writePolling (uartHandle, (uint8_t*) &DopplerVector, sizeof(uint16_t));
    
           tlvIdx++;
    
       }
    .
    .
    .
    .
    }
    The screenshot of the compilation errors are as in the image:

    Converting matrices to arrays/vectors in Cpp-capture-png



    Kindly help analyse and suggest fixes for my errors.

    regards,
    Tosin

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,161
    Code:
    uint8_t[subFrameCfg->numDopplerBins] DopplerVector;
    What do you think the above line does?
    Or what do you want it to do?

    Is this one of the lines that have an error?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,430
    Increasing the frame rate leads to 'clogging' of the UART and data transfer will usually fail. I am then looking into converting these matrices into vectors or arrays before trying to transfer them over the 'baudwidth' limited UART.
    Just changing matrices into vectors will not solve your problem.

    > In the original source code, the radar transfers matrix type data over UART to a PC.
    Whatever change you make here, you also need to make the same change in the PC code as well.
    Do you have that code?

    > uint8_t DopplerVector;
    For example, you seem to be trying to convert the data from a matrix of uint16_t into a vector of uint8_t.
    All very well, it would save 50% of the bandwidth.
    But are all the values in the range 0..255 to begin with? If not, you're going to lose all the important information.

    Plus you also need to make the SAME compatible change to the code on the PC as well.

    I take it that the really simple option of just increasing the baud rate of the UART is not an option.

    How much free memory do you have on the microcontroller?
    Enough to store all the data that all the calls to UART_writePolling would write in a single call to MmwDemo_transmitProcessedOutput
    If you are able to buffer all the data (or a good fraction of it), then data compression before sending would be an option as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Feb 2022
    Posts
    5
    That is correct. That is line 1618.
    It should have looked as follows:


    Code:
    1618     uint8_t[subFrameCfg->numDopplerBins] DopplerVector;
    Overall, I improved on my code as follows:
    Code:
    staticvoid MmwDemo_transmitProcessedOutput
    (
    
    
       UART_Handle     uartHandle,
    
       DPC_ObjectDetection_ExecuteResult   *result,
       MmwDemo_output_message_stats        *timingInfo
    
    )
    
    {
    .
    .
    
    .
    
    .
    uint8_t *DopplerVector;
    uint32_t index2;
    
    .
    
    .
    .
    /* Send data for range/Doppler heatmap */
    
    1613  if (pGuiMonSel->rangeDopplerHeatMap == 1)
    1614  {
    1615     UART_writePolling (uartHandle, (uint8_t*)&tl[tlvIdx], sizeof(MmwDemo_output_message_tl));
    1616
    
    1617
    
    1618     //uint8_t[subFrameCfg->numDopplerBins] DopplerVector;
    1619     DopplerVector = (uint8_t*)[subFrameCfg->numDopplerBins];
    
    1620     for(index = 0; index < subFrameCfg->numRangeBins; index++)
    
    1621     {
    
    1622        for(index2 = 0; index2 < subFrameCfg->numDopplerBins; index2++){
    
    1623            DopplerVector[index2] = DopplerVector[index2]+detMatrix[index*subFrameCfg->numDopplerBins+index2]
    
    1624        }
    
    1625     }
    
    1626
    
    1627     UART_writePolling (uartHandle, (uint8_t*) &DopplerVector, sizeof(uint16_t));
    
    1628     tlvIdx++;
    
    1629   }
    
    .
    .
    .
    .
    }


    But still got the following error
    Converting matrices to arrays/vectors in Cpp-capture2-png

  5. #5
    Registered User
    Join Date
    Feb 2022
    Posts
    5
    Quote Originally Posted by Tosin View Post
    Dear experts,

    I am looking into reducing the "rangeDopplerHeatMap" data which I suppose are in the "(uint8_t*)detMatrix" into vectors/arrays.

    I have tried solving this by the code below by changing the section of the "if (pGuiMonSel->rangeDopplerHeatMap == 1)" statement . But getting lots of compilation errors.


    Code:
    staticvoid MmwDemo_transmitProcessedOutput
    (
    
       UART_Handle     uartHandle,
       DPC_ObjectDetection_ExecuteResult   *result,
       MmwDemo_output_message_stats        *timingInfo
    )
    {
    .
    .
    .
    .
    uint8_t DopplerVector;
    uint32_t index2;
    
    
    
    
    /* Send data for range/Doppler heatmap */
    if (pGuiMonSel->rangeDopplerHeatMap == 1)
    
       {
    
           UART_writePolling (uartHandle, (uint8_t*)&tl[tlvIdx], sizeof(MmwDemo_output_message_tl));
    
    
    
    uint8_t[subFrameCfg->numDopplerBins] DopplerVector;
    
    for(index = 0; index < subFrameCfg->numRangeBins; index++)
           {
    for(index2 = 0; index2 < subFrameCfg->numDopplerBins; index2++){
    
                   DopplerVector[index2] = DopplerVector[index2]+detMatrix[index*subFrameCfg->numDopplerBins+index2]
    
               }
           }
    
    
           UART_writePolling (uartHandle, (uint8_t*) &DopplerVector, sizeof(uint16_t));
    
           tlvIdx++;
    
       }
    .
    .
    .
    .
    }
    A better presentation of my source code with line numbers is as follows:

    Code:
    .
    .
    .
    /* Send data for range/Doppler heatmap */
    1613  if (pGuiMonSel->rangeDopplerHeatMap == 1)
    1614  {
    1615     UART_writePolling (uartHandle, (uint8_t*)&tl[tlvIdx], sizeof(MmwDemo_output_message_tl));
    1616
    1617
    1618     uint8_t[subFrameCfg->numDopplerBins] DopplerVector;
    1619     for(index = 0; index < subFrameCfg->numRangeBins; index++)
    1620     {
    1621        for(index2 = 0; index2 < subFrameCfg->numDopplerBins; index2++){
    1622            DopplerVector[index2] = DopplerVector[index2]+detMatrix[index*subFrameCfg->numDopplerBins+index2]
    1623        }
    1624     }
    1625
    1626     UART_writePolling (uartHandle, (uint8_t*) &DopplerVector, sizeof(uint16_t));
    1627     tlvIdx++;
    1628   }
    .
    .
    .
    .
    }

  6. #6
    Registered User
    Join Date
    Feb 2022
    Posts
    5
    Quote Originally Posted by stahta01 View Post
    Code:
    uint8_t[subFrameCfg->numDopplerBins] DopplerVector;
    What do you think the above line does?
    Or what do you want it to do?

    Is this one of the lines that have an error?

    Tim S.
    Yes, this line gives an error.
    I commented it out, and the now have a successful compilation.
    Do you understand what this line is doing? Not fully. The code was provided to me, and I am not very conversant with C/Cpp.

  7. #7
    Registered User
    Join Date
    Feb 2022
    Posts
    5
    Quote Originally Posted by Salem View Post
    Just changing matrices into vectors will not solve your problem.

    > In the original source code, the radar transfers matrix type data over UART to a PC.
    Whatever change you make here, you also need to make the same change in the PC code as well.
    Do you have that code?
    I am aware I will have to change the PC code (here a raspberry pi) to take in vectors and rearrange first into matrices then perform other needed tasks.


    Quote Originally Posted by Salem View Post
    Just changing matrices into vectors will not solve your problem.

    > uint8_t DopplerVector;
    For example, you seem to be trying to convert the data from a matrix of uint16_t into a vector of uint8_t.
    All very well, it would save 50% of the bandwidth.
    But are all the values in the range 0..255 to begin with? If not, you're going to lose all the important information.

    Plus you also need to make the SAME compatible change to the code on the PC as well.
    I understand this conversion from uint16_t into uint8_t. Maybe it is not the best approach, and I will look further into that.


    Quote Originally Posted by Salem View Post
    Just changing matrices into vectors will not solve your problem.

    I take it that the really simple option of just increasing the baud rate of the UART is not an option.

    How much free memory do you have on the microcontroller?
    Enough to store all the data that all the calls to UART_writePolling would write in a single call to MmwDemo_transmitProcessedOutput
    If you are able to buffer all the data (or a good fraction of it), then data compression before sending would be an option as well.
    The baudrate on the microcontroller is limited, and increasing to the max did not solve the problem.
    I do not have sufficient memory to buffer all data. Could you please suggest how to go about data compression?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,430
    The first thing to do would be to save several (like 20+) complete frames of data on the PC side.

    Then do a hex dump of the files, like this
    Code:
    $ hd foo.c | head
    00000000  23 69 6e 63 6c 75 64 65  20 3c 73 74 64 69 6f 2e  |#include <stdio.|
    00000010  68 3e 0a 23 69 6e 63 6c  75 64 65 20 3c 73 74 64  |h>.#include <std|
    00000020  6c 69 62 2e 68 3e 0a 23  69 6e 63 6c 75 64 65 20  |lib.h>.#include |
    00000030  3c 73 74 72 69 6e 67 2e  68 3e 0a 23 69 6e 63 6c  |<string.h>.#incl|
    00000040  75 64 65 20 3c 63 74 79  70 65 2e 68 3e 0a 23 70  |ude <ctype.h>.#p|
    00000050  72 61 67 6d 61 20 77 61  72 6e 69 6e 67 28 64 69  |ragma warning(di|
    00000060  73 61 62 6c 65 20 3a 20  34 39 39 36 29 0a 0a 73  |sable : 4996)..s|
    00000070  74 72 75 63 74 20 4d 65  6d 62 65 72 20 7b 0a 20  |truct Member {. |
    00000080  20 63 68 61 72 20 6d 65  6d 62 65 72 49 64 5b 36  | char memberId[6|
    00000090  5d 2c 20 6e 61 6d 65 5b  34 30 5d 2c 20 67 65 6e  |], name[40], gen|
    You should be able to see this at the start of each file.
    Code:
       header.platform =  0xA6843;
       header.magicWord[0] = 0x0102;
       header.magicWord[1] = 0x0304;
       header.magicWord[2] = 0x0506;
       header.magicWord[3] = 0x0708;
    Next, you see how well it might compress. In the case of text files, the result is usually pretty good.
    Code:
    $ wc -c foo.c
    4568 foo.c
    $ bzip2 -z -c foo.c | wc -c
    1267
    If your transmitted messages also compress well, then compressing the data may be an option.
    zlib Home Site is an example of a well regarded compression / decompression library.

    > The microcontroller is used to handle calculations and data transfer for a radar device.
    Another thing to look at is comparing the differences between adjacent frames of data.
    In the same way that adjacent frames of a movie are very similar, adjacent frames of radar are going to be similar.
    Perhaps you can only send the difference each time, rather than the whole thing.

    But this may require too much memory to allow you to compare adjacent messages.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. converting function to include vectors
    By a.mlw.walker in forum C Programming
    Replies: 17
    Last Post: 08-10-2011, 08:33 AM
  2. beginner; need help with Vectors & Matrices
    By sam... in forum C Programming
    Replies: 11
    Last Post: 11-23-2010, 11:54 PM
  3. Converting byte arrays to vectors
    By kasun in forum C++ Programming
    Replies: 3
    Last Post: 03-02-2004, 10:31 AM
  4. 2-D Arrays (Matrices)
    By Mak in forum C Programming
    Replies: 2
    Last Post: 11-27-2003, 03:01 PM
  5. Points, vectors, matrices
    By subnet_rx in forum Game Programming
    Replies: 17
    Last Post: 01-11-2002, 02:29 PM

Tags for this Thread