📄 app.c
字号:
POP3c_MboxStat(socket, &message_qty, &mailbox_size, &errMsg);
if (errMsg == POP3c_ERR_NONE) {
APP_TRACE_DEBUG(("POP3c_MboxStat: %d msg, %d bytes\n", message_qty, mailbox_size));
} else {
APP_TRACE_DEBUG(("Error - POP3c_MboxStat: %d\n", errMsg));
}
for (i = 1; i <= message_qty; i++)
{
POP3c_MsgStat(socket, i, &message_size, &errMsg);
if (errMsg == POP3c_ERR_NONE) {
APP_TRACE_DEBUG((" Message %d: %d bytes\n", i, message_size));
}
else {
APP_TRACE_DEBUG((" Error - POP3c_MsgStat: %d\n", errMsg));
}
}
for (i = 1; i <= message_qty; i++) {
APP_TRACE_DEBUG(("\n\n"));
POP3c_MsgStat(socket, i, &message_size, &errMsg);
if (errMsg == POP3c_ERR_NONE) {
APP_TRACE_DEBUG((" Message %d: %d bytes\n", i, message_size));
}
else {
APP_TRACE_DEBUG((" Error - POP3c_MsgStat: %d\n", errMsg));
}
POP3c_MsgRetrieve(socket, i, message_buffer, BUFFER_SIZE, DEF_NO, &errMsg);
if (errMsg != POP3c_ERR_NONE) {
APP_TRACE_DEBUG((" POP3c_MsgRetrieve error code: %d\n", errMsg));
}
POP3c_MsgRead(message_buffer, BUFFER_SIZE, &mail_struct, &errMsg);
if (errMsg != POP3c_ERR_NONE) {
APP_TRACE_DEBUG((" POP3c_MsgRead error code: %d\n", errMsg));
}
APP_TRACE_DEBUG(("\nContent of message %d\n\n", i));
APP_TRACE_DEBUG(("From : %s\n", mail_struct.From));
APP_TRACE_DEBUG(("Sender : %s\n", mail_struct.Sender));
APP_TRACE_DEBUG(("Date : %s\n", mail_struct.Date));
APP_TRACE_DEBUG(("Reply to : %s\n", mail_struct.Reply_to));
APP_TRACE_DEBUG(("Subject : %s\n\n", mail_struct.Subject));
APP_TRACE_DEBUG(("%s\n\n", mail_struct.Body));
APP_TRACE_DEBUG(("Original message (buffer):\n"));
j = 0;
while (message_buffer[j] != '\0') {
APP_TRACE_DEBUG(("%c", message_buffer[j]));
j++;
}
}
POP3c_Disconnect(socket, &errMsg);
APP_TRACE_DEBUG(("Disconnected\n"));
}
#endif /* APP_POP3c_EN */
#if APP_SMTPc_EN
void App_TestSMTPc (void)
{
NET_IP_ADDR ip_server;
NET_IP_ADDR client_addr;
NET_ERR errMsg;
NET_SOCK_ID sock;
SMTPc_MSG msg;
SMTPc_MBOX from;
SMTPc_MBOX to;
SMTPc_MBOX cc;
SMTPc_MBOX bcc;
CPU_CHAR message[] = "Test avec ligne beaucoup trop longue abcdefghijkl "
"Test avec ligne beaucoup trop longue abcdefghijkl "
"Test avec ligne beaucoup trop longue abcdefghijkl "
"Test avec ligne beaucoup trop longue abcdefghijkl "
"Plus de 1000";
ip_server = NetASCII_Str_to_IP("192.168.0.2", &errMsg);
if (errMsg != NET_ASCII_ERR_NONE) {
APP_TRACE_DEBUG(( "Error - NetASCII_Str_to_IP: %d\n", errMsg));
return;
}
client_addr = NetASCII_Str_to_IP("192.168.0.11", &errMsg);
if (errMsg != NET_ASCII_ERR_NONE) {
APP_TRACE_DEBUG(( "Error - NetASCII_Str_to_IP: %d\n", errMsg));
return;
}
APP_TRACE_DEBUG(("Connecting...\n"));
sock = SMTPc_Connect(ip_server, 0, client_addr, DEF_NO, &errMsg);
if (errMsg == SMTPc_ERR_NONE) {
APP_TRACE_DEBUG(("Connected to server (socket: %d)\n", sock));
} else {
APP_TRACE_DEBUG(("Error - SMTPc_Connect: %d\n", errMsg));
return;
}
SMTPcADT_SetSMTPcMbox(&from, "J.-D. Hatier", "jdhatier@micrium.com", &errMsg);
SMTPcADT_SetSMTPcMbox(&to, "J.-D. Hatier", "jdhatier@micrium.com", &errMsg);
SMTPcADT_SetSMTPcMbox(&cc, "J.-D. Hatier", "jdhatier@micrium.com", &errMsg);
SMTPcADT_SetSMTPcMbox(&bcc, "J.-D. Hatier", "smtp-test@micrium.com", &errMsg);
SMTPcADT_InitSMTPcMsg(&msg, &from, &from, &errMsg);
msg.ToArray[0] = &to;
msg.CCArray[1] = &bcc;
msg.BCCArray[2] = &cc;
msg.ContentBodyMsg = message;
msg.ContentBodyMsgLen = Str_Len(message);
Str_Copy(msg.Subject, "Test");
SMTPc_SendMsg(sock, &msg, &errMsg);
SMTPc_Disconnect(sock, &errMsg);
APP_TRACE_DEBUG(("Disconnected\n"));
}
#endif /* APP_SMTPc_EN */
#if APP_SNTPc_EN
/*
*********************************************************************************************************
* TEST SNTP CLIENT
*********************************************************************************************************
*/
static void App_TestSNTPc (void)
{
CLK_DATE_TIME date_time;
CLK_TS_NTP ntp_time;
SNTP_PKT sntp_pkt;
CPU_INT32U sntp_test;
CPU_INT08U buf[40];
Clk_Init();
Clk_DateTime_Make(&date_time, 2006, 1, 1, 0, 0, 0, App_Clk_UTC_Offset);
Clk_SetDateTime(&date_time);
Clk_DateTime_ToStr(&date_time, 1, buf);
APP_TRACE_DEBUG(("CLOCK: %s.\n", buf));
sntp_test = SNTP_ReqRemoteTime(App_IP_NTP_Srvr, &sntp_pkt);
if (sntp_test == DEF_OK) {
ntp_time = SNTP_GetRemoteTime_s(&sntp_pkt);
Clk_SetTS_NTP(&ntp_time);
}
Clk_GetDateTime(&date_time);
Clk_DateTime_ToStr(&date_time, 1, buf);
APP_TRACE_DEBUG(("CLOCK: %s.\n", buf));
OSTimeDlyHMSM(0, 0, 5, 0);
Clk_GetDateTime(&date_time);
Clk_DateTime_ToStr(&date_time, 1, buf);
APP_TRACE_DEBUG(("CLOCK: %s.\n", buf));
OSTimeDlyHMSM(0, 0, 5, 0);
Clk_GetDateTime(&date_time);
Clk_DateTime_ToStr(&date_time, 1, buf);
APP_TRACE_DEBUG(("CLOCK: %s.\n", buf));
}
CPU_INT32U SNTP_GetLocalTime_s (void)
{
CLK_TS_NTP ts_ntp;
Clk_GetTS_NTP(&ts_ntp);
return ((CPU_INT32U)ts_ntp);
}
#endif /* APP_SNTPc_EN */
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*
* Description : This function creates the application tasks.
*
* Arguments : None.
*********************************************************************************************************
*/
static void App_TaskCreate (void)
{
#if (OS_TASK_NAME_SIZE >= 16)
CPU_INT08U err;
#endif /* (OS_TASK_NAME_SIZE >= 16) */
OSTaskCreateExt( App_Task_1,
(void *)0,
(OS_STK *)&App_1_TaskStk[APP_1_OS_CFG_TASK_STK_SIZE - 1],
APP_1_OS_CFG_TASK_PRIO,
APP_1_OS_CFG_TASK_PRIO,
(OS_STK *)&App_1_TaskStk[0],
APP_1_OS_CFG_TASK_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
#if (OS_TASK_NAME_SIZE >= 16)
OSTaskNameSet(APP_1_OS_CFG_TASK_PRIO, "Yellow LED task", &err);
#endif /* (OS_TASK_NAME_SIZE >= 16) */
}
/*
*********************************************************************************************************
* TASK #1
*
* Description : This is an example of a task.
*
* Arguments : p_arg argument passed to 'AppTask1()' by 'OSTaskCreate()'.
*
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*
* 2) Interrupts are enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*
* 3) This Task uses the LEDs and the switch of the CSB937 board,
* it blinks user LED 2 on the CSB937.
*********************************************************************************************************
*/
static void App_Task_1 (void *p_arg)
{
(void)&p_arg; /* Prevent compiler warning. */
OSCPUUsageMax = 0;
while (DEF_YES) { /* Task body, always written as an infinite loop. */
LED_Toggle(1);
OSTimeDlyHMSM(0, 0, 0, 250);
if (OSCPUUsageMax < OSCPUUsage) {
OSCPUUsageMax = OSCPUUsage;
}
}
}
#if APP_DHCPc_EN
/*
*********************************************************************************************************
* DHCPc_Print()
*
* Description : Print the DHCP header...
*********************************************************************************************************
*/
static void DHCPc_Print (DHCP_HDR *d)
{
CPU_INT08U *client_ip;
CPU_INT08U *your_ip;
CPU_INT08U *server_ip;
CPU_INT08U *router_ip;
CPU_INT32U xid;
client_ip = (CPU_INT08U *)&(d->ciaddr);
your_ip = (CPU_INT08U *)&(d->yiaddr);
server_ip = (CPU_INT08U *)&(d->siaddr);
router_ip = (CPU_INT08U *)&(d->giaddr);
Mem_Copy(&xid, &d->xid, 4);
APP_TRACE_DEBUG((" DHCP:\n"));
APP_TRACE_DEBUG((" op = %s, htype = %d, hlen = %d, hops = %d\n",
DHCPc_GetOperStr(d->op),
d->htype,
d->hlen,
d->hops));
APP_TRACE_DEBUG((" seconds = %d, flags = 0x%x, xid= 0x%lx\n",
NET_UTIL_NET_TO_HOST_16(d->secs),
NET_UTIL_NET_TO_HOST_16(d->flags),
NET_UTIL_NET_TO_HOST_32(xid)));
APP_TRACE_DEBUG((" caddr = %02x:%02x:%02x:%02x:%02x:%02x\n",
d->chaddr[0],
d->chaddr[1],
d->chaddr[2],
d->chaddr[3],
d->chaddr[4],
d->chaddr[5]));
APP_TRACE_DEBUG((" client_ip = %d.%d.%d.%d\n",
client_ip[0],
client_ip[1],
client_ip[2],
client_ip[3]));
APP_TRACE_DEBUG((" your_ip = %d.%d.%d.%d\n",
your_ip[0],
your_ip[1],
your_ip[2],
your_ip[3]));
APP_TRACE_DEBUG((" server_ip = %d.%d.%d.%d\n",
server_ip[0],
server_ip[1],
server_ip[2],
server_ip[3]));
APP_TRACE_DEBUG((" router_ip = %d.%d.%d.%d\n",
router_ip[0],
router_ip[1],
router_ip[2],
router_ip[3]));
if (d->file[0] != '\0') {
APP_TRACE_DEBUG((" bootfile: %s\n", d->file));
}
if (d->sname[0] != '\0') {
APP_TRACE_DEBUG((" server_hostname: %s\n", d->sname));
}
DHCPc_PrintOptions((CPU_INT08U *)(d + 1));
}
/*
*********************************************************************************************************
* DHCPc_PrintOptions()
*
* Description : Verbosely display the DHCP options pointed to by the incoming options pointer.
*
* Note(s) : 1) Vendor specific information:
* The data within this option is vendor specific. The RFC2132 says that the encapsulated
* data with this option SHOULD follow the same format as the outer-layer options, but is
* not mandatory.
*********************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -