Help with UDP send

Status
Not open for further replies.

MrNobody

New Member
Hi,
Below is a function in C18 to send data using UDP. It is able to send "BYE" successfully.

Code:
void UDP_Send()
{
   #define LPORT_SEND 8001    //Local port to send from
   #define RPORT_SEND 8002    //Remote port to send to
   static ROM BYTE *StringData = "BYE"; 
   UDP_SOCKET    SocketTransmit;
   NODE_INFO    Remote;
   BYTE        *A;
   
   Remote.IPAddr.v[0]=192;
   Remote.IPAddr.v[1]=168;
   Remote.IPAddr.v[2]=2;
   Remote.IPAddr.v[3]=2;
   
   if(!MACIsLinked())
       return;
       
   SocketTransmit = UDPOpen(LPORT_SEND, &Remote, RPORT_SEND);
   
   if(SocketTransmit == INVALID_UDP_SOCKET)
       return;
       
   if(!UDPIsPutReady(SocketTransmit))
   {
       UDPClose(SocketTransmit);
       return;
   }
   
   AAA = UDPPutROMString(StringData);    // Send string

   UDPFlush();
   UDPClose(SocketTransmit);
}



How can i convert the code into a function which is able to receive variable passed to it, forexample UDP_Send("Hello") will send "Hello" instead of sending "BYE".
I tried to convert the code into:

Code:
 void UDP_Send(ROM BYTE *StringData)
 {
     #define LPORT_SEND 8001    //Local port to send from
     #define RPORT_SEND 8002    //Remote port to send to
     UDP_SOCKET    SocketTransmit;
     NODE_INFO    Remote;
     BYTE        *A;
     
     Remote.IPAddr.v[0]=192;
     Remote.IPAddr.v[1]=168;
     Remote.IPAddr.v[2]=2;
     Remote.IPAddr.v[3]=2;
     
     if(!MACIsLinked())
         return;
         
     SocketTransmit = UDPOpen(LPORT_SEND, &Remote, RPORT_SEND);
     
     if(SocketTransmit == INVALID_UDP_SOCKET)
         return;
         
     if(!UDPIsPutReady(SocketTransmit))
     {
         UDPClose(SocketTransmit);
         return;
     }
     
     AAA = UDPPutROMString(StringData);    // Send string
 
     UDPFlush();
     UDPClose(SocketTransmit);
 }



and call it using UDP_Send("Hello"); but it doesn't seem to work..

Please advice.
 
Have you tried UDP_Send((rom char*)"Hello");

I assume there is also a function UDPPutRAMString which could send actual variable strings. You would of course have to copy your ROM strings to RAM.

Mike.
 
Hi Mike,
Tried UDP_Send((rom char*)"Hello"); but in wireshark, it shows
"10 420.030195 192.168.2.4 192.168.2.2 UDP Source port: vcom-tunnel Destination port: teradataordbms[Malformed Packet]"

Yes, it does have function UDPPutRAMString.. Umm, how would I copy the ROM strings to RAM.

Is it UDP_Send((ram char*)"Hello");..?
 
I just do,
Code:
void CopyString(ram char* RamString,rom char * RomString){
    do{
        *RamString++=*RomString;
    }while(*RomString++!=0);
}
// and then do,
    CopyString(RamStringVar,(rom char*) "Hello World");

It is rather confusing having different pointer types that are not interchangeable.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…