/** * @brief Processes data transfers after a TFTP write request * @param _args: used as pointer on TFTP connection args * @param upcb: pointer on udp_pcb structure * @param pkt_buf: pointer on a pbuf stucture * @param ip_addr: pointer on the receive IP_address structure * @param port: receive port address * @retval none */ static void IAP_wrq_recv_callback(void *_args, struct udp_pcb *upcb, struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port) { tftp_connection_args *args = (tftp_connection_args *)_args; uint32_t data_buffer[128]; u16 count=0; static uint32_t process = 0; static uint16_t process_x = UPDATE_WORD_START_X; char buff[10]; static uint16_t process_buff = 0; #ifdef USE_LCD char message[40]; #endif if (pkt_buf->len != pkt_buf->tot_len) { udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE; lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> ÒÔÌ«ÍøÉý¼¶³ö´íÁË¡£´íÎó´úÂ룺2",UPDATE_FONT); UDP_AddUpdateError(); // #ifdef USE_LCD // LCD_SetTextColor(Red); // LCD_DisplayStringLine(Line9, (uint8_t*)"Invalid data length"); // #endif return; } /* Does this packet have any valid data to write? */ if ((pkt_buf->len > TFTP_DATA_PKT_HDR_LEN) && (IAP_tftp_extract_block(pkt_buf->payload) == (args->block + 1))) { /* copy packet payload to data_buffer */ pbuf_copy_partial(pkt_buf, data_buffer, pkt_buf->len - TFTP_DATA_PKT_HDR_LEN, TFTP_DATA_PKT_HDR_LEN); total_count += pkt_buf->len - TFTP_DATA_PKT_HDR_LEN; count = (pkt_buf->len - TFTP_DATA_PKT_HDR_LEN)/4; if (((pkt_buf->len - TFTP_DATA_PKT_HDR_LEN)%4)!=0) count++; /* Write received data in Flash */ switch ( FLASH_If_Write(&Flash_Write_Address, data_buffer ,count) ) { case 0: process++; if ((process % 30) == 0) { process_buff += 5; lcd_font24(process_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"-",UPDATE_FONT); process_x += 12; usprintf(buff,"%3d%%",process_buff); lcd_font24(process_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,buff,UPDATE_FONT); } break; case 1: udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE; lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> ÒÔÌ«ÍøÉý¼¶³ö´íÁË¡£´íÎó´úÂ룺3",UPDATE_FONT); UDP_AddUpdateError(); case 2: udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE; lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"> ÒÔÌ«ÍøÉý¼¶³ö´íÁË¡£´íÎó´úÂ룺4",UPDATE_FONT); UDP_AddUpdateError(); } /* update our block number to match the block number just received */ args->block++; /* update total bytes */ (args->tot_bytes) += (pkt_buf->len - TFTP_DATA_PKT_HDR_LEN); /* This is a valid pkt but it has no data. This would occur if the file being written is an exact multiple of 512 bytes. In this case, the args->block value must still be updated, but we can skip everything else. */ } else if (IAP_tftp_extract_block(pkt_buf->payload) == (args->block + 1)) { /* update our block number to match the block number just received */ args->block++; } /* Send the appropriate ACK pkt*/ IAP_tftp_send_ack_packet(upcb, addr, port, args->block); /* If the last write returned less than the maximum TFTP data pkt length, * then we've received the whole file and so we can quit (this is how TFTP * signals the EndTransferof a transfer!) */ if (pkt_buf->len < TFTP_DATA_PKT_LEN_MAX) { IAP_tftp_cleanup_wr(upcb, args); pbuf_free(pkt_buf); lcd_font24(process_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"100%",UPDATE_FONT); udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE; uPdateFinish = YES; // #ifdef USE_LCD // LCD_SetTextColor(White); // LCD_DisplayStringLine(Line5, (uint8_t*)"Tot bytes Received:"); // sprintf(message, "%d bytes ",total_count); // LCD_DisplayStringLine(Line6, (uint8_t*)message); // LCD_DisplayStringLine(Line8, (uint8_t*)"State: Prog Finished "); // #endif } else { // udp_lcd_y += UPDATE_WORD_SIZE + UPDATE_ROW_DISTANCE; // lcd_font24(udp_lcd_x,udp_lcd_y,COLOR_POINT,COLOR_BACK,"Reset the board",UPDATE_FONT); // #ifdef USE_LCD // LCD_SetTextColor(Red); // LCD_DisplayStringLine(Line9, (uint8_t*)" Reset the board "); // #endif pbuf_free(pkt_buf); return; } }
/** * @brief Processes data transfers after a TFTP write request * @param _args: used as pointer on TFTP connection args * @param upcb: pointer on udp_pcb structure * @param pkt_buf: pointer on a pbuf stucture * @param ip_addr: pointer on the receive IP_address structure * @param port: receive port address * @retval None */ static void IAP_wrq_recv_callback(void *_args, struct udp_pcb *upcb, struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port) { tftp_connection_args *args = (tftp_connection_args *)_args; uint32_t data_buffer[128]; uint16_t count=0; #ifdef USE_LCD char message[40]; #endif if (pkt_buf->len != pkt_buf->tot_len) { #ifdef USE_LCD LCD_ErrLog("Invalid data length\n"); #endif return; } /* Does this packet have any valid data to write? */ if ((pkt_buf->len > TFTP_DATA_PKT_HDR_LEN) && (IAP_tftp_extract_block(pkt_buf->payload) == (args->block + 1))) { /* copy packet payload to data_buffer */ pbuf_copy_partial(pkt_buf, data_buffer, pkt_buf->len - TFTP_DATA_PKT_HDR_LEN, TFTP_DATA_PKT_HDR_LEN); total_count += pkt_buf->len - TFTP_DATA_PKT_HDR_LEN; count = (pkt_buf->len - TFTP_DATA_PKT_HDR_LEN)/4; if (((pkt_buf->len - TFTP_DATA_PKT_HDR_LEN)%4)!=0) count++; /* Write received data in Flash */ FLASH_If_Write(&Flash_Write_Address, data_buffer ,count); /* update our block number to match the block number just received */ args->block++; /* update total bytes */ (args->tot_bytes) += (pkt_buf->len - TFTP_DATA_PKT_HDR_LEN); /* This is a valid pkt but it has no data. This would occur if the file being written is an exact multiple of 512 bytes. In this case, the args->block value must still be updated, but we can skip everything else. */ } else if (IAP_tftp_extract_block(pkt_buf->payload) == (args->block + 1)) { /* update our block number to match the block number just received */ args->block++; } /* Send the appropriate ACK pkt*/ IAP_tftp_send_ack_packet(upcb, addr, port, args->block); /* If the last write returned less than the maximum TFTP data pkt length, * then we've received the whole file and so we can quit (this is how TFTP * signals the EndTransferof a transfer!) */ if (pkt_buf->len < TFTP_DATA_PKT_LEN_MAX) { IAP_tftp_cleanup_wr(upcb, args); pbuf_free(pkt_buf); #ifdef USE_LCD sprintf(message, "%d bytes ",(int)total_count); LCD_UsrLog("Tot bytes Received:, %s\n", message); LCD_UsrLog(" State: Prog Finished \n"); LCD_UsrLog("Reset the board \n"); #endif } else { pbuf_free(pkt_buf); return; } }
/** * @brief Processes data transfers after a TFTP write request * @param _args: used as pointer on TFTP connection args * @param upcb: pointer on udp_pcb structure * @param pkt_buf: pointer on a pbuf stucture * @param ip_addr: pointer on the receive IP_address structure * @param port: receive port address * @retval none */ static void IAP_wrq_recv_callback(void *_args, struct udp_pcb *upcb, struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port) { tftp_connection_args *args = (tftp_connection_args *)_args; uint32_t data_buffer[128]; char message[20]; u16 count=0; if (pkt_buf->len != pkt_buf->tot_len) { return; } /* Does this packet have any valid data to write? */ if ((pkt_buf->len > TFTP_DATA_PKT_HDR_LEN) && (IAP_tftp_extract_block(pkt_buf->payload) == (args->block + 1))) { /* copy packet payload to data_buffer */ pbuf_copy_partial(pkt_buf, data_buffer, pkt_buf->len - TFTP_DATA_PKT_HDR_LEN, TFTP_DATA_PKT_HDR_LEN); total_count += pkt_buf->len - TFTP_DATA_PKT_HDR_LEN; count = (pkt_buf->len - TFTP_DATA_PKT_HDR_LEN)/4; if (((pkt_buf->len - TFTP_DATA_PKT_HDR_LEN)%4)!=0) count++; /* Write received data in Flash */ FLASH_If_Write(&Flash_Write_Address, data_buffer ,count); /* update our block number to match the block number just received */ args->block++; /* update total bytes */ (args->tot_bytes) += (pkt_buf->len - TFTP_DATA_PKT_HDR_LEN); /* This is a valid pkt but it has no data. This would occur if the file being written is an exact multiple of 512 bytes. In this case, the args->block value must still be updated, but we can skip everything else. */ } else if (IAP_tftp_extract_block(pkt_buf->payload) == (args->block + 1)) { /* update our block number to match the block number just received */ args->block++; } /* Send the appropriate ACK pkt*/ IAP_tftp_send_ack_packet(upcb, addr, port, args->block); /* If the last write returned less than the maximum TFTP data pkt length, * then we've received the whole file and so we can quit (this is how TFTP * signals the EndTransferof a transfer!) */ if (pkt_buf->len < TFTP_DATA_PKT_LEN_MAX) { IAP_tftp_cleanup_wr(upcb, args); pbuf_free(pkt_buf); #ifdef USE_LCD LCD_SetTextColor(White); LCD_DisplayStringLine(Line5, (char*)"Tot bytes Received:"); sprintf(message, "%u bytes ",total_count); LCD_DisplayStringLine(Line6, (uint8_t*)message); LCD_SetTextColor(Red); LCD_DisplayStringLine(Line9, (char*)"State: Prog Finished "); #endif BKP_WriteBackupRegister(BKP_DR11,0); /* generate a watchdog reset */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE); //SerialPutString("\r\nENABLE WTD! \n"); WWDG_Enable(0x40); while(1); } else { pbuf_free(pkt_buf); return; } }