Module: FXT009 (Q2687RDG)
-“Developer Studio”,“2.1.0.201108080830-R7547”
-“Open AT Embedded Software Suite package”,“2.33.0.201009161739”
-“Open AT OS Package”,“6.32.0.03”
-“Firmware Package”,“7.43.0.201009151513”
-“WIP Open AT Plug-in Package”,“5.30.0.2040”
I started with the sample “UDP_Client” code and verified that the server was receiving the message sent from the Wavecom.
I then modified that code to receive a response using the same socket. I presumed I could just set the “WIP_COPT_PORT” option and expect a “WIP_CEV_READ” event to occur when the response was sent from the server.
The problem is that I don’t receive a WIP_CEV_READ event at all, at least not on the port I’m expecting it on.
The remote server is set to respond on the port set on the originating Client (i.e. the Client’s local port). When creating the socket on the Wavecom I set the local port number to 11000 using the “WIP_COPT_PORT” option however apparently the server sees the message as coming from port 1025, not 11000 as expected. On that basis it responds to the Wavecom using port 1025, hence the reason I never receive a WIP_CEV_READ event.
I haven’t changed any other WIP options so defaults are used for all but the local port, destination IP address and destination port number. There appears to be some kind of port translation happening ?
I must have some fundamental error here in both my understanding and code so would appreciate some help in resolving it.
Code for the modified “entry_point.c” module of the sample is included below:
//***************************************************************************
// entry_point.c (modified) - Copyright Wavecom S.A. (c) 2006
//***************************************************************************
/****************************************************************************
* File : entry_point.c
*
*/
//These constants have been set for the System
#define PEER_PORT 12500 // Remote server port
#define PEER_STRADDR "testserver.dfs.fred.com" // Remote server name
#define LOCAL_PORT 1000 // Local listening port
#define MESSAGE "\x00\x09\x01\x00\x00\x20\x00\x02\x0D\xFF\x8B\x77"
#define RCV_BUFFER_SIZE 512
#define INTERVAL 30
#define WAIT_TIME 5 // Wait time before transmit (secs)
#include "adl_global.h"
#include "wip.h"
//**************************************************************************
// Globals
/***************************************************************************
static wip_channel_t socket = NULL;
/***************************************************************************
// Function prototypes
/***************************************************************************
static void evh( wip_event_t *ev, void *ctx);
static void evh_timer( u8 tmr_id); // For Tx interval
//**************************************************************************
// Function : appli_entry_point
//--------------------------------------------------------------------------------------------
// Object : Called once the WIP IP stack is fully initialized.
//**************************************************************************
void appli_entry_point()
{
// Create the socket and set for read mode.
socket = wip_UDPCreateOpts( evh, NULL,
WIP_COPT_PORT, LOCAL_PORT,
WIP_COPT_END );
}
//**************************************************************************
// Function : evh_timer
//--------------------------------------------------------------------------------------------
// Purpose : Sends a packet, upon reception of this timer
// event subscribed by [evh].
//--------------------------------------------------------------------------------------------
// Variable Name |IN |OUT|GLB| Utilisation
//--------------------+---+---+---+-------------------------------------------------------
// tmr_id | | | | unused
//--------------------+---+---+---+--------------------------------------------------------
//**************************************************************************
static void evh_timer( u8 tmr_id)
{
int nwrite;
TRACE(( 1, "[evh_timer] Write MESSAGE\n" ));
nwrite = wip_writeOpts( socket, MESSAGE, sizeof(MESSAGE),
WIP_COPT_PEER_ADDR, PEER_STRADDR,
WIP_COPT_PEER_PORT, PEER_PORT,
WIP_COPT_END );
}
/**************************************************************************
// Function : evh
//-------------------------------------------------------------------------------------------
// Purpose : Handles events happening on the UDP socket.
// When a packet is received, its sender address
// and port are gathered, together with its content
//-------------------------------------------------------------------------------------------
// Variable Name |IN |OUT|GLB| Utilisation
//--------------------+---+---+---+------------------------------------------------------
// ev | X | | | WIP event
//--------------------+---+---+---+------------------------------------------------------
// ctx | | | | unused
//--------------------+---+---+---+------------------------------------------------------
//*************************************************************************
static void evh( wip_event_t *ev, void *ctx )
{
switch( ev->kind )
{
case WIP_CEV_OPEN:
{
static int tmr_handler;
wip_debug ( "[evh] UDP socket ready and waiting (WIP_CEV_OPEN event).\n\n" );
// Start a 2-second timer and send the message in its event handler.
wip_debug( "[evh_udp_tx] (WIP_CEV_OPEN event), starting the timer\n\n");
tmr_handler = adl_tmrSubscribe( TRUE, 10*WAIT_TIME,
ADL_TMR_TYPE_100MS, evh_timer);
break;
}
case WIP_CEV_READ:
{
// a [WIP_CEV_READ] event is received every time an UDP datagram is
// received by the UDP socket.
wip_debug ( "[evh] A datagram arrived (WIP_CEV_READ event).\n\n" );
}
case WIP_CEV_DONE:
{
wip_debug ( "[evh] WIP_CEV_DONE event on UDP socket event handler.\n\n" );
break;
}
case WIP_CEV_WRITE:
{
wip_debug ( "[evh] WIP_CEV_WRITE event on UDP socket event handler.\n\n ");
break;
}
case WIP_CEV_ERROR:
{
wip_debug( "[evh] Error %i on socket. Closing.\n\n",
ev->content.error.errnum );
wip_close( ev->channel );
break;
}
default:
{
wip_debug( "[evh] Some other event received\n\n");
break;
}
}
}