-1

I have the data, which includes 32 bit scaled integers for latitude and longitude,32 bit floats for x y and z velocity and some 1-bit flags. I also am successfully sending at least one double over UDP but it appears to be trash on the other end and in Wireshark. I need bitwise access to toggle/change the data every second that I send out the data over UDP. The message format is simple and each data type will take up its size and has a certain start bit. It seems like I need to serialize but with the other end, not necessarily deserializing is that possible? My first thought was to make a structure with all the data then send the whole structure over UDP but with padding that seems wrong. The message needs to be 64 bytes long and each data type has a start bit and length of the format. This code compiles and works but with an unreadable latitude on the receiving side. Lat, long, and alt update every second. There are more data fields but I am trying to start small. A snippet of the format is attached with the data type, word location, start bit within that word, and length in bits is attached, lat, long, and alt are somewhere else within the message. Data Format Best idea right now is to use Cereal (http://uscilab.github.io/cereal/index.html) but not sure if that's a dead end.

struct TSPIstruct       //
{
    double Latitude;
    double Longitude;
    double Altitude;
};

void SendDataUDP(double latitude, double longitude, double altitude)
{
    TSPIstruct TSPI;
    TSPI = CompileTSPI(latitude, longitude, altitude);


    //printf("\n\r");
    printf("Sending GPS over UDP at %d", LastSystemTime);
    printf("\n\r");
    printf("\n\r");


    //send the message
    if (sendto(s, (char*)&(TSPI.Latitude), sizeof(double) , 0 , (struct sockaddr *) &si_other, slen) == SOCKET_ERROR)
    {
        printf("sendto() failed with error code : %d" , WSAGetLastError());
        exit(EXIT_FAILURE);
    }

    printf("UDP packet sent, latitude is %f", TSPI.Latitude);
    printf("\n\r");
    printf("\n\r");
    }

TSPIstruct CompileTSPI(double latitude, double longitude, double altitude)
{
    TSPIstruct TSPI;
    TSPI.Latitude = latitude;
    TSPI.Longitude = longitude;
    TSPI.Altitude = altitude;

    return TSPI;
}

2 Answers2

0

maybe a stupid question, but when sending binary data, you must consider not ONLY padding/alignment, but also bit ordering. You could skip the latter point if you are sure µp artitecture is the same on both sides. in TCP since old times they added:

uint32_t htonl(uint32_t host32bitvalue) ;

and so on..

if You try on the SAME local machine (i.e. 127.0.0.1) does it work?

ingconti
  • 10,876
  • 3
  • 61
  • 48
  • I will try this although I'm sure I could eventually see one of the values in Wireshark. When I get to the point of having 3 floats or doubles right beside each other in the message is my problem because of alignment/padding. I want to be able to see all my data in my UDP message in certain bit locations and be able to surely say, yes those 32 or 64 bits are a floating precision number of my latitude because I put them there. Is serialization going to solve this? – Unsavorysauce Nov 20 '17 at 07:20
  • Serialization is another concept. (usually in OOP..) Anyway if You use structs you will be aligned to 32 or 64 bit (depending on compiler). You can try using #pragma align, useful in these situations. If You try to send a complete struct, does it work? – ingconti Nov 20 '17 at 07:30
0

paste both client AND server code.. I will try under Unix and windows :)

ingconti
  • 10,876
  • 3
  • 61
  • 48