我对 LWFTP 库有疑问(来自https://github.com/gezedo)。我正在使用带有 RAW API 的 lwIP。板子从不发送任何 TCP 信号(应该发送 SYN 消息)。我的代码是下一个:
/**************************** sys_main.c *************************************/
#include "sys_common.h"
/* USER CODE BEGIN (1) */
/* Include FreeRTOS scheduler files */
#include "FreeRTOS.h"
#include "os_task.h"
#include "os_queue.h"
#include "het.h"
#include "esm.h"
#include "tcp_client.h"
#include "ping.h"
#include "sci.h"
#include "lwftp.h"
#include "includes.h"
extern void EMAC_LwIP_Main (uint8 * emacAddress);
uint8 emacAddress[6U] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU};
uint32 emacPhyAddress = 0U;
/********************************************************************************/
int min(int num1, int num2);
int min(int num1, int num2)
{
return (num1 > num2 ) ? num2 : num1;
}
static void ftp_retr_callback(void *arg, int result)
{
lwftp_session_t *s = (lwftp_session_t*)arg;
if ( result != LWFTP_RESULT_OK ) {
// ////LOG_ERROR("retr failed (%d)", result);
return lwftp_close(s);
}
// Test is done
lwftp_close(s);
}
static unsigned int data_sink(void *arg, const char* ptr, unsigned int len)
{
static const unsigned int mylen = 12345;
static char * const myconfig = (char*)0x20000000;
static unsigned int offset = 0;
if (ptr) {
len = min( len, mylen-offset );
memcpy( myconfig+offset, ptr, len );
offset += len;
}
return len;
}
static void ftp_stor_callback(void *arg, int result)
{
lwftp_session_t *s = (lwftp_session_t*)arg;
err_t error;
if ( result != LWFTP_RESULT_OK ) {
// ////LOG_ERROR("stor failed (%d)", result);
return lwftp_close(s);
}
// Continue with RETR request
s->data_sink = data_sink;
s->done_fn = ftp_retr_callback;
s->remote_path = "configfile";
error = lwftp_retrieve(s);
if ( error != LWFTP_RESULT_INPROGRESS ) {
// ////LOG_ERROR("lwftp_retrieve failed (%d)", error);
}
// FTP session will continue with RETR and sink callbacks
}
static unsigned int data_source(void *arg, const char** pptr, unsigned int maxlen)
{
static const unsigned int mylen = 12345;
static const char * const mydata = (char*)0x20000000;
static unsigned int offset = 0;
unsigned int len = 0;
// Check for data request or data sent notice
if (pptr) {
len = mylen - offset;
if ( len > maxlen ) len = maxlen;
*pptr = mydata + offset;
} else {
offset += maxlen;
if ( offset > mylen ) offset = mylen;
}
return len;
}
static void ftp_connect_callback(void *arg, int result)
{
lwftp_session_t *s = (lwftp_session_t*)arg;
err_t error;
if ( result != LWFTP_RESULT_LOGGED ) {
////LOG_ERROR("login failed (%d)", result);
return lwftp_close(s);
}
// Continue with STOR request
s->data_source = data_source;
s->done_fn = ftp_stor_callback;
s->remote_path = "logfile";
error = lwftp_store(s);
if ( error != LWFTP_RESULT_INPROGRESS ) {
////LOG_ERROR("lwftp_store failed (%d)", error);
}
// FTP session will continue with STOR and source callbacks
}
static void ftp_test(void)
{
static lwftp_session_t s; // static content for the whole FTP session
err_t error;
// Initialize session data
memset(&s, 0, sizeof(s));
IP4_ADDR(&s.server_ip, 192,168,0,20);
s.server_port = 7070;
s.done_fn = ftp_connect_callback;
s.user = "username";
s.pass = "password";
// We have no extra user data, simply use the session structure
s.handle = &s;
// Start the connection state machine
error = lwftp_connect(&s);
if ( error != LWFTP_RESULT_INPROGRESS ) {
////LOG_ERROR("lwftp_connect failed (%d)", error);
}
// FTP session will continue with the connection callback
}
/********************************************************************************/
int main(void)
{
EMAC_LwIP_Main (emacAddress);
ftp_test();
while(1);
return 0;
}
函数 ftp_test() 调用 lwftp_connect(在 lwftp.c 中,来自 Gezedo 的 github),但从不发送任何 TCP 消息。我正在使用 TMS570LS3137 板。
非常感谢 !!