Hi, The example code I sent you works in RAW mode.
That means you do not create any task or threads. Your functions are being called by the TCP stack. Please check again your code. In function vBasicWEBServer you need to call a function that creates the UDP server and assigns your own call back functions to the new PCB After that you call vTaskDelete( NULL ); and terminate the temporary task. The UDP server will not die after that as it is running as part of the LwIP code. You do not loop or call udp_recv yourself. If this is not understood let me know. BR, Noam. -----Original Message----- From: [email protected] on behalf of ajinkya Sent: Tue 4/16/2013 11:53 AM To: [email protected] Subject: Re: [lwip-users] STR912 lwIP + Freertos demo Hi Noam, I have tried the code, and have made some changes, but I have some issues. Here is the part of code. "BuildReply" function compares the received payload with the string, and sets "RetVal" flag, which we use "Discovery_recv" function to send different replies depending on the returned "RetVal" flag value. This is just for trials and testing i tried this code, and I am getting the expected reply. But I wanted to ask, *am I doing it correct??* I guess I am missing something. Because when I introduce the "vAC_ON_OFF_Function" it happens only once (I get a reply saying "AC Switched ON" and the signal is also sent) but then it is gone.........doesn't even reply ping. I have attached 2 screen shots of Wireshark for reference ( With_vAC_ON_OFF_Function_1.png <http://lwip.100.n7.nabble.com/file/n21320/With_vAC_ON_OFF_Function_1.png> , With_vAC_ON_OFF_Function_2.png <http://lwip.100.n7.nabble.com/file/n21320/With_vAC_ON_OFF_Function_2.png> ) And 2 more screen shots with plain request-reply ( plain-request-reply1.png <http://lwip.100.n7.nabble.com/file/n21320/plain-request-reply1.png> , plain-request-reply2.png <http://lwip.100.n7.nabble.com/file/n21320/plain-request-reply2.png> ) which was working fine (without the addon function - "vAC_ON_OFF_Function" ). Source addr-10.114.12.50 Dest Addr - 10.114.12.58 --(STR9 device address) void vBasicWEBServer( void *pvParameters ) { struct ip_addr xIpAddr, xNetMast, xGateway; extern err_t ethernetif_init( struct netif *netif ); err_t err; struct udp_pcb *my_pcb; struct pbuf *p; /* Parameters are not used - suppress compiler error. */ ( void ) pvParameters; /* Create and configure the EMAC interface. */ IP4_ADDR( &xIpAddr, emacIPADDR0, emacIPADDR1, emacIPADDR2, emacIPADDR3 ); IP4_ADDR( &xNetMast, emacNET_MASK0, emacNET_MASK1, emacNET_MASK2, emacNET_MASK3 ); IP4_ADDR( &xGateway, emacGATEWAY_ADDR0, emacGATEWAY_ADDR1, emacGATEWAY_ADDR2, emacGATEWAY_ADDR3 ); netif_add( &EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input ); /* make it the default interface */ netif_set_default( &EMAC_if ); /* bring it up */ netif_set_up(&EMAC_if); /*----------------------------Modify here---------------------------------------*/ /* Initialize UDP */ my_pcb = udp_new(); if(my_pcb != NULL) err = udp_bind(my_pcb, IP_ADDR_ANY, 1235); if(err == ERR_OK) { while (1) { udp_recv(my_pcb, Discovery_recv, my_pcb); } } /* Nothing else to do. No point hanging around. */ //vTaskDelete( NULL ); } /*----------------------------------------------------------------------------*/ /******************************************************************************/ /*----------------------------------------------------------------------------*/ static void Discovery_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port) { struct pbuf *pLocal_ON, *pLocal_OFF, *pLocal_Miss ; char *Payload_extract; char reply_msg1[]="AC Switched ON"; char reply_msg2[]="AC Switched OFF"; char reply_msg3[]="Ohh noo"; // p == NULL when client has terminated the udp connection. We will acknowledge the request and close conn. if(p == NULL) { return; } Payload_extract = (char*) p->payload; // take the pointer to the data or even better to copy it to a buffer pbuf_free(p); // Allocate a new pbuf for sending the response. pLocal_ON = pbuf_alloc(PBUF_TRANSPORT, sizeof(reply_msg1), PBUF_RAM); pLocal_OFF = pbuf_alloc(PBUF_TRANSPORT, sizeof(reply_msg2), PBUF_RAM); pLocal_Miss = pbuf_alloc(PBUF_TRANSPORT, sizeof(reply_msg3), PBUF_RAM); memcpy (pLocal_ON->payload, reply_msg1, sizeof(reply_msg1)); memcpy (pLocal_OFF->payload, reply_msg2, sizeof(reply_msg2)); memcpy (pLocal_Miss->payload, reply_msg3, sizeof(reply_msg3)); // create the response RetVal = BuildReply(Payload_extract); // Send the response. // pLocal->len = pLocal->tot_len = PayloadLength; if(RetVal == 1) { //PassArray = 1; //vAC_ON_OFF_Function(); //Send signal to switch ON AC- udp_sendto(upcb, pLocal_ON, addr, port); } else if(RetVal == 2) { //PassArray = 0; //vAC_ON_OFF_Function(); //Send signal to switch OFF AC udp_sendto(upcb, pLocal_OFF, addr, port); } else if(RetVal ==0) udp_sendto(upcb, pLocal_Miss, addr, port); pbuf_free(pLocal_ON); pbuf_free(pLocal_OFF); pbuf_free(pLocal_Miss); return; } /*----------------------------------------------------------------------------*/ static int BuildReply(char *Payload) { char AC_Sig_ON[] = "Switch ON AC"; char AC_Sig_OFF[] = "Switch OFF AC"; // add your own code here if(strcmp (Payload, AC_Sig_ON) == 0) //compare received payload with string RetVal = 1; else if(strcmp(Payload, AC_Sig_OFF) == 0) //compare received payload with string RetVal = 2; else RetVal = 0; return RetVal; } /*----------------------------------------------------------------------------*/ /*---------Add on code to send a signal on receiving perticular payload---------*/ /*------------------------------------------------------------------------*/ static int vAC_ON_OFF_Function() { PWMBusy = 1; ConfigurePWMfor_AC_ON(); if(PulseCount >= 31) { PulseCount =0; TIM_DeInit(TIM1); TIM_DeInit(TIM2); } PWMBusy = 0; return PWMBusy; } /*------------------------------------------------------------------------*/ void ConfigurePWMfor_AC_ON(void) { VIC_DeInit(); TIM_DeInit(TIM1); TIM_DeInit(TIM2); TIM2->OC1R = 0x0023; TIM2->OC2R = 0x0046; TIM2->CR2 = 0x0010; TIM2->CR1 = 0x8250; //carrier 38 khz TIM_ClearFlag(TIM1,TIM_FLAG_OC2); portENTER_CRITICAL(); { VIC_Config(TIM1_ITLine,VIC_IRQ, 0); VIC_ITCmd(TIM1_ITLine,ENABLE); //VIC_InitDefaultVectors(); TIM1->SR &= 0x0000; VIC0->ISR = 0x0000; } portEXIT_CRITICAL(); TIM1->OC1R = 0x00FF; TIM1->OC2R = 0x0FFF; TIM1->CR2 = 0x0810; TIM1->CR1 = 0x8250; // Signal of AC remote while(PulseCount < 31); } /*------------------------------------------------------------------------*/ void PWM_TIM1_IRQHandler(void) // Interrupt handler { /* Clear the interrupt. */ TIM1->SR = 0x0000; VIC0->ISR = 0x0000; if(PassArray != 1) TIM1->OC2R = OFFArrayOC2R[PulseCount]; else TIM1->OC2R = ONArrayOC2R[PulseCount]; TIM1->OC1R = ArrayOC1R[PulseCount]; if(PulseCount < 31) PulseCount++; else TIM1->CR1 &= 0x7FFF; //STOP timer counter so next interrupt will not occur VIC0->VAR = 0xFF; } -- View this message in context: http://lwip.100.n7.nabble.com/STR912-lwIP-Freertos-demo-tp21277p21320.html Sent from the lwip-users mailing list archive at Nabble.com. _______________________________________________ lwip-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/lwip-users ************************************************************************************ This footnote confirms that this email message has been scanned by PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses. ************************************************************************************ ************************************************************************************ This footnote confirms that this email message has been scanned by PineApp Mail-SeCure for the presence of malicious code, vandals & computer viruses. ************************************************************************************
_______________________________________________ lwip-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/lwip-users
