Hi,
I have a wheather station and i want get data from station with rs232.
My station response when i put comand “OPEN” and my app send this command but no receive nothing…
I read data of rs232 with FcmDataHandler and put this data in the buffer and send to ftp server… but rs232 no receive nothing…
My code of appli.c:
/***************************************************************************/
/* Prototypes */
/***************************************************************************/
//void cfg_uart_ppp_client( void (*entry_point) (void));
//void cfg_uart_ppp_serv ( void (*entry_point) (void));
//void cfg_gsm_ppp_client ( void (*entry_point) (void));
//void cfg_gsm_ppp_serv ( void (*entry_point) (void));
void cfg_gprs ( void (*entry_point) (void));
void appli_entry_point ( void);
bool FcmDataHandler (u16 DataLen, u8 * Data);
/***************************************************************************/
/* Mandatory variables */
/*-------------------------------------------------------------------------*/
/* wm_apmCustomStackSize */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
#if __OAT_API_VERSION__ >= 400
const u16 wm_apmCustomStackSize = 4096;
#else
u32 wm_apmCustomStack[1024];
const u16 wm_apmCustomStackSize = sizeof(wm_apmCustomStack);
#endif
s8 FcmHdl;
bool FcmCtrlHandler (adl_fcmEvent_e Event){
switch (Event){
case ADL_FCM_EVENT_FLOW_OPENNED:{
adl_atSendResponse ( ADL_AT_UNS, "ADL_FCM_EVENT_FLOW_OPENNED\n\r");
//adl_fcmSwitchV24State(FcmHdl,ADL_FCM_V24_STATE_DATA);
}
}
return TRUE;
}
/***************************************************************************/
/* Function : adl_main */
/*-------------------------------------------------------------------------*/
/* Object : Customer application initialisation */
/* */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* InitType | x | | | Application start mode reason */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
void adl_main ( adl_InitType_e InitType )
{
int r;
adl_atCmdCreate( "AT+CBST=7,0,1", 1, NULL, NULL );
//adl_atCmdCreate("AT+IPR=9600", ADL_AT_PORT_TYPE(ADL_AT_UART1, FALSE), NULL, "*", NULL);
adl_tmrSubscribe ( TRUE, 300, ADL_TMR_TYPE_100MS, (adl_tmrHandler_t)appli_entry_point );
FcmHdl = adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART1,FcmCtrlHandler,FcmDataHandler);
TRACE (( 1, "Embedded Application : Main" ));
/* Initialize the stack */
r = wip_netInitOpts(
WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1, /* WIP traces on UART1 */
//WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART2,
//WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_TRACE,
WIP_NET_OPT_END);
/* Depending on the activated flag, take the proper config */
#if defined( OVER_UART_PPP_SERV)
/* Initialize PPP server over UART */
cfg_uart_ppp_serv( appli_entry_point);
#elif defined( OVER_UART_PPP_CLIENT)
/* Initialize PPP client over UART */
cfg_uart_ppp_client( appli_entry_point);
#elif defined( OVER_GSM_PPP_SERV)
/* Initialize PPP server over GSM */
cfg_gsm_ppp_serv( appli_entry_point);
#elif defined( OVER_GSM_PPP_CLIENT)
/* Initialize PPP client over GSM */
cfg_gsm_ppp_client( appli_entry_point);
#elif defined( OVER_GPRS)
/* Initialize GPRS connection */
cfg_gprs( appli_entry_point);
#else
/* Don't initialize any bearer; only
* localhost=127.0.0.1 will be reachable. */
appli_entry_point();
#endif
}
And my code of entry_point.c:
#define DST_SERVER "81.129.192.240" /* Address the FTP server */
#define DST_USER "tester" /* My FTP username */
#define DST_PASSWORD "1234" /* My FTP password */
#define DST_FILENAME "data.txt" /* Name of the file to put */
#define DST_ISPASSIVE FALSE /* Active or passive mode? */
#include "adl_global.h"
#include "wip.h"
/***************************************************************************/
/* Globals */
/***************************************************************************/
extern s8 FcmHdl;
/* Whatever data I want to send in [DST_FILENAME]. */
static u8 buffer [300];
/* How many bytes of [buffer] have already been sent. */
static int offset = 0;
static wip_channel_t
dst_ftp_cx = NULL, /* channel controlling the FTP connection. */
dst_data = NULL; /* channel used for file data transfer. */
/***************************************************************************/
/* Function prototypes */
/***************************************************************************/
static void evh_cx( wip_event_t *ev, void *ctx);
static void evh_data( wip_event_t *ev, void *ctx);
//Vou buscar todos os dados que vierem da rs232 e meto no buffer
//do ficheiro que vai para o servidor
bool FcmDataHandler (u16 DataLen, u8 * Data){
char a[2];
sprintf(a,"%s",(char *)Data);
a[1]=0;
strcat((char *)buffer,a);
return TRUE;
}
/***************************************************************************/
/* Function : appli_entry_point */
/*-------------------------------------------------------------------------*/
/* Object : Called once the WIP IP stack is fully initialized. */
/* This is the starting point of user applications. */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
void appli_entry_point() {
adl_fcmSwitchV24State(FcmHdl,ADL_FCM_V24_STATE_AT);
char comando[]="OPEN\n\r";
adl_fcmSendData(FcmHdl,(u8 *)comando,strlen(comando));
adl_fcmSwitchV24State(FcmHdl,ADL_FCM_V24_STATE_DATA);
wip_debug( "Opening FTP connection...\n");
dst_ftp_cx = wip_FTPCreateOpts (
DST_SERVER, evh_cx, NULL,
WIP_COPT_USER, DST_USER,
WIP_COPT_PASSWORD, DST_PASSWORD,
WIP_COPT_PASSIVE, DST_ISPASSIVE,
WIP_COPT_END);
offset=0;
if( ! dst_ftp_cx) { wip_debug( "Can't open dst FTP connection\n"); return; }
}
/***************************************************************************/
/* Function : evh_data */
/*-------------------------------------------------------------------------*/
/* Object : Handling events happenning on the FTP connection */
/* control channel. */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* ev | X | | | WIP event */
/*--------------------+---+---+---+----------------------------------------*/
/* ctx | | | | unused */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
static void evh_cx( wip_event_t *ev, void *ctx) {
switch( ev->kind) {
case WIP_CEV_OPEN:
/* FTP control initialized successfully -> open data dchannel */
dst_data = wip_putFile( dst_ftp_cx, DST_FILENAME, evh_data, NULL);
if( ! dst_data) { wip_debug( "Can't create data channel"); return; }
break;
case WIP_CEV_ERROR:
wip_debug( "Error %i on cx channel\n", ev->content.error.errnum);
/* fall through */
case WIP_CEV_PEER_CLOSE:
wip_debug( "Closing everything\n");
if( dst_data) { wip_close( dst_data); dst_data = NULL; }
wip_close( dst_ftp_cx); dst_ftp_cx = NULL;
break;
}
}
/***************************************************************************/
/* Function : evh_data */
/*-------------------------------------------------------------------------*/
/* Object : Handling events happenning on the data transfer channel */
/*-------------------------------------------------------------------------*/
/* Variable Name |IN |OUT|GLB| Utilisation */
/*--------------------+---+---+---+----------------------------------------*/
/* ev | X | | | WIP event */
/*--------------------+---+---+---+----------------------------------------*/
/* ctx | | | | unused */
/*--------------------+---+---+---+----------------------------------------*/
/***************************************************************************/
static void evh_data( wip_event_t *ev, void *ctx) {
switch( ev->kind) {
case WIP_CEV_OPEN:
/* Here, we could optionnally change the threshold which triggers
* [WIP_CEV_WRITE] events with the following setting:
wip_setOpts( ev->channel, WIP_COPT_SND_LOWAT, 3000, WIP_COPT_END);
* (This way, we wouldn't receive WRITE events until at least 3KB
* of TCP send buffer are available).
*/
break;
/* There is some space available in TCP send buffer, which allows me
* to write more data from [buffer]; let's write as much data as
* possible, up to the end of [buffer]. [nwrite] is the number of bytes
* I actually managed to put in the TCP buffer. */
case WIP_CEV_WRITE: {
int nwrite = wip_write( dst_data, buffer, sizeof( buffer) - offset);
if( nwrite < 0) { /*error*/ return; }
offset += nwrite; /* Update the number of bytes sent. */
if( offset == sizeof( buffer)) { /* All of [buffer] has been sent */
wip_close( dst_data); dst_data = NULL;
wip_close( dst_ftp_cx); dst_ftp_cx = NULL;
}
break;
}
case WIP_CEV_ERROR:
wip_debug( "Error %i on channel 0x%x\n", ev->content.error.errnum,
ev->channel);
wip_close( dst_data); dst_data = NULL;
if( dst_ftp_cx) { wip_close( dst_ftp_cx); dst_ftp_cx = NULL; }
break;
}
}
What is wrong on my code?
Please help…