Author Topic: about the udp use!  (Read 22028 times)

Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: about the udp use!
« Reply #15 on: February 11, 2009, 12:45:08 PM »
Thanks a bunch!  I think i understand now whats going on there.  I'm going to try that right now!

Cheers

Marco

Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: about the udp use!
« Reply #16 on: February 11, 2009, 05:12:00 PM »
Hi Mark

Sorry, I'm stuck again.  Ok this is what I got so far, how ever the compiler sais fnUDPListner is not declared.

Code: [Select]
#include "config.h"


extern void fnFBWOE(TTASKTABLE *ptrTaskTable)
{
  #define OWN_TASK    fnFBWOE
  static USOCKET MyUDP_Socket;
 
  MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS);
  fnBindSocket(MyUDP_Socket, 1234);
 
  const unsigned char ucIP[] = {192,168, 0, 101};
 
  uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", 11);
  fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, 1234, (unsigned char*)&ptrUDP_Frame->tUDP_Header, 11, OWN_TASK);
}

I tried to declare it as the following, but the compiler sais its an ileagal storage class.

Code: [Select]
  static int  fnUDPListner(USOCKET c, unsigned char uc, unsigned char *ucIP, unsigned short us, unsigned char *data, unsigned short us2);

What should I declare fnUDPListner as?


Cheers

Marco
« Last Edit: February 11, 2009, 05:21:31 PM by Marco »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2983
    • View Profile
    • uTasker
Re: about the udp use!
« Reply #17 on: February 11, 2009, 06:58:40 PM »
Hi Marco

The listener is required for receiving UDP data on the defined UDP port.


// UDP data server - reception call back function
//
static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
   return 0;
}


You must supply the listener. If you don't actually want to receive any data on the port you can just add a dummy one like the one above. Put it before your code and you won't need to prototype it. Otherwise add:

static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength);

Regards

Mark


Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: about the udp use!
« Reply #18 on: February 14, 2009, 12:53:26 PM »
Hi Mark

Thanks I got that part to work, and I aslo figured out how to define MyUDP_Socket, I now have problems with ptrUDP_Frame.  Can you please tell me how to define ptrUDP_Frame.  I searched for it, but could not find it.

Code: [Select]
#include "config.h"


static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
  return 0;
}

extern void fnFBWOE(TTASKTABLE *ptrTaskTable)
{
  #define OWN_TASK    fnFBWOE
  #define UDP_BUFFER_SIZE        11                                   // Buffer size for UDP test message
  #define MY_UDP_PORT            1234
  static USOCKET MyUDP_Socket;
  UDP_HEADER     tUDP_Header;
 
  unsigned char  ucUDP_Message[UDP_BUFFER_SIZE];
  const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 101};
   
  MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
  fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
 
  uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", UDP_BUFFER_SIZE);
  fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
}

Cheers

Marco
« Last Edit: February 14, 2009, 01:38:43 PM by Marco »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2983
    • View Profile
    • uTasker
Re: about the udp use!
« Reply #19 on: February 14, 2009, 03:40:51 PM »
Hi Marco

static UDP_MESSAGE *ptrUDP_Frame;
ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));                  // get some memory for UDP frame


Regards

Mark

Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: about the udp use!
« Reply #20 on: February 15, 2009, 06:05:57 AM »
Hi Mark

I have actually tried "static UDP_MESSAGE *ptrUDP_Frame;" im getting an error "C2540: Expected: ,".  I'm not sure why that is.

Code: [Select]
#include "config.h"


static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
  return 0;
}

extern void fnFBWOE(TTASKTABLE *ptrTaskTable)
{
  #define OWN_TASK    fnFBWOE
  #define UDP_BUFFER_SIZE        11                                   // Buffer size for UDP test message
  #define MY_UDP_PORT            1234
  static USOCKET MyUDP_Socket;
  UDP_HEADER     tUDP_Header;
  static UDP_MESSAGE *ptrUDP_Frame;
  ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));                  // get some memory for UDP frame
 
  unsigned char  ucUDP_Message[UDP_BUFFER_SIZE];
  const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 101};
   
  MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
  fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
 
  uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", UDP_BUFFER_SIZE);
  fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
}

Cheers

Marco
« Last Edit: February 15, 2009, 06:37:55 AM by Marco »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2983
    • View Profile
    • uTasker
Re: about the udp use!
« Reply #21 on: February 15, 2009, 11:54:09 AM »
Hi Marco

The following will work:


extern void fnFBWOE(void)
{
  #define OWN_TASK    fnFBWOE
  #define UDP_BUFFER_SIZE        11                                   // Buffer size for UDP test message
  #define MY_UDP_PORT            1234
  static USOCKET MyUDP_Socket;
  static UDP_MESSAGE *ptrUDP_Frame;
  const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 101};
  ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));                  // get some memory for UDP frame   
  MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
  fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
 
  uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", UDP_BUFFER_SIZE);
  fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
}


1) UDP_HEADER     tUDP_Header; and unsigned char  ucUDP_Message[UDP_BUFFER_SIZE]; are unused so I removed them
2) Your error was the uMalloc() position - it was before the static variable end - which is illegal syntax
3) What you still need to add is the handling of the ARP_RESOLUTION_SUCCESS event.

The first time your routine sends the IP address is probably not in the ARP table. This causes ARP to send a request to resolve this on the local network. Your task will be informed when this has been completed and then it needs to repeat the message. When further UDP frames are sent the IP address will have been resolved and so will be immediately sent (until the IP entry times out in the ARP table and the process will then be repeated)


In your task you thus need

    unsigned char       ucInputMessage[HEADER_LENGTH];                  // reserve space for receiving messages
....

    while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) {   // check input queue
        switch ( ucInputMessage[MSG_SOURCE_TASK] ) {                     // switch depending on message source
        case  TASK_ARP:
            fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the contents
            switch (ucInputMessage[ 0 ]) {                               // ARP sends us either ARP resolution success or failed
            case ARP_RESOLUTION_SUCCESS:                                 // IP address has been resolved (repeat UDP frame).
                fnSendUDP(MyUDP_Socket, ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
                break;

            case ARP_RESOLUTION_FAILED:                                  // IP address could not be resolved...
                break;
            }
            break;
        }
    }



Regards

Mark

Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: about the udp use!
« Reply #22 on: February 15, 2009, 06:27:45 PM »
Hi Mark

I'm now getting loads of compile errors, it still has a problem with static UDP_MESSAGE *ptrUDP_Frame;.  The error is "2450: Expected: ,"

By the way am I suposed to change extern void fnFBWOE(TTASKTABLE *ptrTaskTable)  to extern void fnFBWOE(void)  as that also gives me compile errors.

Code: [Select]
#include "config.h"


static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
  return 0;
}

extern void fnFBWOE(TTASKTABLE *ptrTaskTable) 
{
  #define OWN_TASK    fnFBWOE
  #define UDP_BUFFER_SIZE        11                                   // Buffer size for UDP test message
  #define MY_UDP_PORT            1234
  unsigned char       ucInputMessage[HEADER_LENGTH];                  // reserve space for receiving messages
  static USOCKET MyUDP_Socket;
  static UDP_MESSAGE *ptrUDP_Frame;
  const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 101};
  ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));                  // get some memory for UDP frame   
  MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
  fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
 
  uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", UDP_BUFFER_SIZE);
  fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
 
  while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) {   // check input queue
      switch ( ucInputMessage[MSG_SOURCE_TASK] ) {                     // switch depending on message source
      case  TASK_ARP:
          fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the contents
          switch (ucInputMessage[ 0 ]) {                               // ARP sends us either ARP resolution success or failed
          case ARP_RESOLUTION_SUCCESS:                                 // IP address has been resolved (repeat UDP frame).
              fnSendUDP(MyUDP_Socket, ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
              break;

          case ARP_RESOLUTION_FAILED:                                  // IP address could not be resolved...
              break;
          }
          break;
      }
  }


}

Cheers

Marco

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2983
    • View Profile
    • uTasker
Re: about the udp use!
« Reply #23 on: February 15, 2009, 07:00:00 PM »
Hi Marco

There are still missing defines and (I only just noticed) the OWN_TASK definition is incorrect.

I have written the task for you below. This will send the test message and then repeat it very 10s (see the timer).
I set OWN_TASK to MY_TASK - if you have a different name you can set it correctly.

Also make sure that the task is started after the Ethernet task has started. Trying to send frames before the Ethernet interface has been initialized will lead to errors.  To ensure correct start up it is usually easiest to start the task from application.c using

uTaskerStateChange(MY_TASK, UTASKER_ACTIVATE);



Code: [Select]
#include "config.h"

#define OWN_TASK               MY_TASK

#define UDP_BUFFER_SIZE        11                                        // buffer size for UDP test message
#define MY_UDP_PORT            1234

#define E_TIMER_NEXT_MESSAGE   1

typedef struct stUDP_MESSAGE
{
    unsigned short usLength;
    UDP_HEADER     tUDP_Header;                                          // reserve header space
    unsigned char  ucUDP_Message[UDP_BUFFER_SIZE];                       // reserve message space
} UDP_MESSAGE;

static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
    return 0;
}

extern void fnFBWOE(TTASKTABLE *ptrTaskTable) 
{
    static USOCKET MyUDP_Socket = -1;
    static UDP_MESSAGE *ptrUDP_Frame;
    const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 101};
    QUEUE_HANDLE        PortIDInternal = ptrTaskTable->TaskID;           // queue ID for task input
    unsigned char       ucInputMessage[HEADER_LENGTH];                   // reserve space for receiving messages

    if (MyUDP_Socket < 0) {                                              // only perform once
        ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));                  // get some memory for UDP frame   
        MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
        fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
        uMemcpy(&ptrUDP_Frame->ucUDP_Message, "Hello World", UDP_BUFFER_SIZE);
        fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
        uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(10*SEC), E_TIMER_NEXT_MESSAGE );
    }

    while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) {   // check input queue
        switch ( ucInputMessage[MSG_SOURCE_TASK] ) {                     // switch depending on message source
        case TIMER_EVENT:
            if (E_TIMER_NEXT_MESSAGE == ucInputMessage[MSG_TIMER_EVENT]) {
                fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
                uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(10*SEC), E_TIMER_NEXT_MESSAGE );
            }
            break;

        case  TASK_ARP:
            fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the contents
            switch (ucInputMessage[ 0 ]) {                               // ARP sends us either ARP resolution success or failed
                case ARP_RESOLUTION_SUCCESS:                             // IP address has been resolved (repeat UDP frame).
                    fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
                    break;

                case ARP_RESOLUTION_FAILED:                              // IP address could not be resolved...
                    break;
            }
            break;
        }
    }
}

A task must always have the parameter (TTASKTABLE *ptrTaskTable)


Regards

Mark



Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: about the udp use!
« Reply #24 on: February 16, 2009, 07:58:49 AM »
Hi Mark

Thanks for that I realy apprechiate the help! Am i suposed to remove the following from TaskConfig.h?

Code: [Select]
  { "fnFBWOE", fnFBWOE, NO_QUE, (DELAY_LIMIT)(5 * SEC), (DELAY_LIMIT)(2 * SEC), UTASKER_STOP},  // fnFBWOE Task run after 5s and run periodically every 2 seconds.

Do I have to change anything else in TaskConfig.h?

I put "uTaskerStateChange(fnFBWOE, UTASKER_ACTIVATE);" just after "uTaskerStateChange(TASK_DEBUG, UTASKER_ACTIVATE);" in application.c.  I'm getting an error "expected signed char, given void".  Is there anything else I'm suposed to do in application.c?

Cheers

Marco

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2983
    • View Profile
    • uTasker
Re: about the udp use!
« Reply #25 on: February 16, 2009, 12:05:02 PM »
Hi Marco

uTaskerStateChange(fnFBWOE, UTASKER_ACTIVATE);

This is not correct, you need to use

uTaskerStateChange(MY_TASK, UTASKER_ACTIVATE);

where MY_TASK is the task reference that you have given in TaskConfig.h, eg.

#define TASK_MODBUS             'f'

Make sure that you have also added this to the task list ctNodes[].

I see that you have configured the task to be delayed and then started periodically. You can change this to

  { "fnFBWOE",      fnFBWOE,         SMALL_QUEUE, (DELAY_LIMIT)(NO_DELAY_RESERVE_MONO), 0, UTASKER_STOP},

in order to use the monostable task timer in the last code, the task must have a queue as well.

Regards

Mark


Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: about the udp use!
« Reply #26 on: February 16, 2009, 03:51:46 PM »
Thank you so much!  It works, I realy apprechiate all the help!

Thanks again

Marco

Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: about the udp use!
« Reply #27 on: February 24, 2009, 02:21:53 PM »
Hi Mark, I continued to play around with UDP, I have now grouped all the ADC values along with some other variables into a char array and I'm sending out an updated packet every 50ms.

Code: [Select]
static char StrMsg[36]= "String Build - Error"; // If string is not built this messege will be sent.

#define OWN_TASK               TASK_SUDP

#define UDP_BUFFER_SIZE        37                                        // buffer size for UDP test message
#define MY_UDP_PORT            1234

#define E_TIMER_NEXT_MESSAGE   1

typedef struct stUDP_MESSAGE
{
    unsigned short usLength;
    UDP_HEADER     tUDP_Header;                                          // reserve header space
    unsigned char  ucUDP_Message[UDP_BUFFER_SIZE];                       // reserve message space
} UDP_MESSAGE;

static int fnUDPListner(USOCKET SocketNr, unsigned char ucEvent, unsigned char *ucIP, unsigned short usPortNr, unsigned char *data, unsigned short usLength)
{
    return 0;
}


// <<<<<<<<<<<<<<<<<<< Send UDP Function >>>>>>>>>>>>>>>>
extern void fnSUDP(TTASKTABLE *ptrTaskTable) 
{
    static USOCKET MyUDP_Socket = -1;
    static UDP_MESSAGE *ptrUDP_Frame;
    const unsigned char ucIP[IPV4_LENGTH]= {192, 168, 0, 101};
    QUEUE_HANDLE        PortIDInternal = ptrTaskTable->TaskID;           // queue ID for task input
    unsigned char       ucInputMessage[HEADER_LENGTH];                   // reserve space for receiving messages
   
    if (MyUDP_Socket < 0) {                                              // only perform once
        ptrUDP_Frame    = uMalloc(sizeof(UDP_MESSAGE));                  // get some memory for UDP frame   
        MyUDP_Socket = fnGetUDP_socket(TOS_MINIMISE_DELAY, fnUDPListner, (UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS));
        fnBindSocket(MyUDP_Socket, MY_UDP_PORT);
        uMemcpy(&ptrUDP_Frame->ucUDP_Message,StrMsg, UDP_BUFFER_SIZE);
        fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
        uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(0.05*SEC), E_TIMER_NEXT_MESSAGE );
    }

    while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) {   // check input queue
        switch ( ucInputMessage[MSG_SOURCE_TASK] ) {                     // switch depending on message source
        case TIMER_EVENT:
            if (E_TIMER_NEXT_MESSAGE == ucInputMessage[MSG_TIMER_EVENT]) {
                uMemcpy(&ptrUDP_Frame->ucUDP_Message,StrMsg, UDP_BUFFER_SIZE);
                fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
                uTaskerMonoTimer( OWN_TASK, (DELAY_LIMIT)(0.05*SEC), E_TIMER_NEXT_MESSAGE );
            }
            break;

        case  TASK_ARP:
            fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the contents
            switch (ucInputMessage[ 0 ]) {                               // ARP sends us either ARP resolution success or failed
                case ARP_RESOLUTION_SUCCESS:                             // IP address has been resolved (repeat UDP frame).
                    uMemcpy(&ptrUDP_Frame->ucUDP_Message,StrMsg, UDP_BUFFER_SIZE);
                    fnSendUDP(MyUDP_Socket, (unsigned char *)ucIP, MY_UDP_PORT, (unsigned char*)&ptrUDP_Frame->tUDP_Header, UDP_BUFFER_SIZE, OWN_TASK);
                    break;

                case ARP_RESOLUTION_FAILED:                              // IP address could not be resolved...
                    break;
            }
            break;
        }
    }
}

I wrote a simple program, to convert an unsigned intiger into 2 chars, I'm sure there is a simpler way to do it in C.

Code: [Select]
// <<<<<<<<<<<<<  Convert 2byte int to 2 chars >>>>>>>>>>>>>>>>>>
unsigned char IntToString(unsigned int InpInt, int ChrNum)
{
  char OutChar[3];
  char RetChar;
  OutChar[1]=(char)(InpInt / 256);
  OutChar[2] =(char)(InpInt%256);
  RetChar = OutChar[ChrNum];
  return((char)RetChar);
}

I then wrote a program which is on a timer from TaskConfig.h, which then combines all the chars into StrMsg.

Code: [Select]
extern void fnBuildPacket(TTASKTABLE *ptrTaskTable) 
{
    char StrStart[2]= "[";  //Start of Data
    char StrStop[2]= "]";   //Stop of Data
    unsigned int intTPS;
    unsigned int intSPS;
    unsigned int intSpd;
    unsigned int intRpm;
    unsigned int intTmp;
    unsigned int intPsi;
    unsigned int intAlt;
    unsigned int intOLS;
    unsigned int intFLS;
    unsigned int intTrm;
    char chrRSK = 'R';
    char chrFNR = 'N';
    char chrCrC = 'F';
    char chrSpL = 'F';
    char chrSyC = 'T';
     
    static int cntrA;  // Counter needed for endcap placement on Packet
    static int cntrB;  // Counter needed for 2byte data segment placement on packet
   
    static unsigned int cntrC = 0;

    cntrC++;   //Test Data used to check update of transmission.
   
    intTPS = ATDDR0H;  // ADC channel 0
    intSPS = ATDDR1H;  // ADC channel 1
    intSpd = ATDDR2H;  // ADC channel 2
    intRpm = ATDDR3H;  // ADC channel 3
    intTmp = ATDDR4H;  // ADC channel 4
    intPsi = ATDDR5H;    // ADC channel 5
    intAlt = ATDDR6H;    // ADC channel 6
    intOLS = ATDDR7H;  // ADC channel 7
    intFLS = cntrC;
    intTrm = cntrC;
   
// <<<<<<<<<<<<<<<<< MSG string Construction >>>>>>>>>>>>>>   
   
    // Place the endcaps on the string
    for (cntrA = 0; cntrA <= 1; cntrA++)
    {
      StrMsg[cntrA] = StrStart[cntrA]; //Add the start Bracket
      StrMsg[cntrA + 26] = StrStop[cntrA]; //Add the Stop Bracket

    }
    // Add all the 2 Byte data segments
    for (cntrB = 0; cntrB <= 1; cntrB++)
    {
      StrMsg[cntrB + 1] = IntToString(intTPS, cntrB + 1);
      StrMsg[cntrB + 3] = IntToString(intSPS, cntrB + 1);
      StrMsg[cntrB + 5] = IntToString(intSpd, cntrB + 1);
      StrMsg[cntrB + 7] = IntToString(intRpm, cntrB + 1);
      StrMsg[cntrB + 9] = IntToString(intTmp, cntrB + 1);
      StrMsg[cntrB + 11] = IntToString(intPsi, cntrB + 1);
      StrMsg[cntrB + 13] = IntToString(intAlt, cntrB + 1);
      StrMsg[cntrB + 15] = IntToString(intOLS, cntrB + 1);
      StrMsg[cntrB + 17] = IntToString(intFLS, cntrB + 1);
      StrMsg[cntrB + 19] = IntToString(intTrm, cntrB + 1);
    }
    // Add aditional Controlls
    StrMsg[21] = chrRSK;
    StrMsg[22] = chrFNR;
    StrMsg[23] = chrCrC;
    StrMsg[24] = chrSpL;
    StrMsg[25] = chrSyC;
}

I just thought its a nice thing to play around with and mabe someone might find it usefull, I also uploaded my UDP test program for windows. Which makes use of winsock32
« Last Edit: February 24, 2009, 08:06:43 PM by Marco »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2983
    • View Profile
    • uTasker
Re: about the udp use!
« Reply #28 on: February 24, 2009, 05:19:01 PM »
Hi Marco

Many thanks for that contribution.

Also take a look at the function
extern CHAR          *fnBufferHex(unsigned long ulValue, unsigned char uLen, CHAR *pBuf);           // take a value and convert it to a string in a buffer

You may also be able to use that instead of the integer to string conversion. For conversion to decimal there is the function
extern CHAR *fnDebugDec(signed long slNumberToConvert, unsigned char ucStyle, CHAR *ptrBuf); // take a value and send it as decimal string over the debug interface or put in buffer


Regards

Mark

Offline Marco

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: about the udp use!
« Reply #29 on: February 24, 2009, 07:27:44 PM »
Thanks for that Mark, I'm sure that will take some load off of the CPU!

Cheers

Marco
« Last Edit: February 24, 2009, 08:08:38 PM by Marco »