/*********************************************************************
*                     SEGGER Microcontroller GmbH                    *
*        Solutions for real time microcontroller applications        *
**********************************************************************
*                                                                    *
*        (c) 1996 - 2022  SEGGER Microcontroller GmbH                *
*                                                                    *
*        Internet: www.segger.com    Support:  support@segger.com    *
*                                                                    *
**********************************************************************
----------------------------------------------------------------------
File        : ID_SCREEN_BUC_NET_SETT_UPDATE_Slots.c
Purpose     : AppWizard managed file, function content could be changed
---------------------------END-OF-HEADER------------------------------
*/

#include "Application.h"
#include "../Generated/Resource.h"
#include "../Generated/ID_SCREEN_BUC_NET_SETT_UPDATE.h"
#include "../Generated/ID_SCREEN_BUC_NET_SETTINGS.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "../utilities/fsl_debug_console.h"

/*** Begin of user code area ***/
/*** End of user code area ***/

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       cbID_SCREEN_BUC_NET_SETT_UPDATE
*/
void cbID_SCREEN_BUC_NET_SETT_UPDATE(WM_MESSAGE * pMsg) {
  GUI_USE_PARA(pMsg);
}

/*********************************************************************
*
*       ID_SCREEN_BUC_NET_SETT_UPDATE__ID_BUTTON_BACK_BUC_NETT_SETT_UPDATE__WM_NOTIFICATION_CLICKED
*/
void ID_SCREEN_BUC_NET_SETT_UPDATE__ID_BUTTON_BACK_BUC_NETT_SETT_UPDATE__WM_NOTIFICATION_CLICKED(APPW_ACTION_ITEM * pAction, WM_HWIN hScreen, WM_MESSAGE * pMsg, int * pResult) {
			if(BUC_Net_Sett_Save_Flag==1 && BUC_Net_Validate_Flag==1)
			{
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_IP_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_IP_ADDR_VAL, gui_update_Buc_net_IP_Addr);

				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_SNET_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_SNET_ADDR_VAL, gui_update_Buc_net_SubNet_Addr);

				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_GATEWAY_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_GATEWAY_ADDR_VAL, gui_update_Buc_net_gateway_Addr);

			}
			else if(Parameter_UDP_Pkt_from_BUC_Received==1)
			{
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_IP_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_IP_ADDR_VAL, gui_BUC_IP_Addr1);

				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_SNET_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_SNET_ADDR_VAL, gui_BUC_Subnet_Addr1);

				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_GATEWAY_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_GATEWAY_ADDR_VAL, gui_BUC_Gateway_Addr1);
			}

			//gui_Screen_Param_Default
			else if(g_Rx_Param_from_BUC_Pkt_Cnt<1)
			{
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_IP_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_IP_ADDR_VAL, gui_Screen_Param_Default);

				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_SNET_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_SNET_ADDR_VAL, gui_Screen_Param_Default);

				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_GATEWAY_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_GATEWAY_ADDR_VAL, gui_Screen_Param_Default);
			}

			else if (g_Rx_Param_from_BUC_Pkt_Cnt>1 && Parameter_UDP_Pkt_from_BUC_Received==0)
			{
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_IP_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_IP_ADDR_VAL, Backup_gui_BUC_IP_Addr1);

				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_SNET_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_SNET_ADDR_VAL, Backup_gui_BUC_Subnet_Addr1);

				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_GATEWAY_ADDR_VAL, "");
				APPW_SetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_GATEWAY_ADDR_VAL, Backup_gui_BUC_Gateway_Addr1);
			}
  GUI_USE_PARA(pAction);
  GUI_USE_PARA(hScreen);
  GUI_USE_PARA(pMsg);
  GUI_USE_PARA(pResult);
}

/*********************************************************************
*
*       ID_SCREEN_BUC_NET_SETT_UPDATE__ID_BUTTON_BUC_IP_UPDATE_SAVE__WM_NOTIFICATION_CLICKED
*/
void ID_SCREEN_BUC_NET_SETT_UPDATE__ID_BUTTON_BUC_IP_UPDATE_SAVE__WM_NOTIFICATION_CLICKED(APPW_ACTION_ITEM * pAction, WM_HWIN hScreen, WM_MESSAGE * pMsg, int * pResult) {

			APPW_GetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_IP_ADDR_VAL, gui_update_Buc_net_IP_Addr, sizeof(gui_update_Buc_net_IP_Addr));
			APPW_GetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_SNET_ADDR_VAL, gui_update_Buc_net_SubNet_Addr, sizeof(gui_update_Buc_net_SubNet_Addr));
			APPW_GetText(ID_SCREEN_BUC_NET_SETT_UPDATE, ID_EDIT_BUC_GATEWAY_ADDR_VAL, gui_update_Buc_net_gateway_Addr, sizeof(gui_update_Buc_net_gateway_Addr));

			strcpy(gui_update_Buc_net_IP_Addr_validate,gui_update_Buc_net_IP_Addr);
			strcpy(gui_update_Buc_net_SubNet_Addr_validate,gui_update_Buc_net_SubNet_Addr);
			strcpy(gui_update_Buc_net_gateway_Addr_validate,gui_update_Buc_net_gateway_Addr);

			if((validate_BUC_ip(gui_update_Buc_net_IP_Addr_validate)==1) &&
						(validate_BUC_ip(gui_update_Buc_net_SubNet_Addr_validate)==1) &&
						(validate_BUC_ip(gui_update_Buc_net_gateway_Addr_validate)==1))
					{
						BUC_Net_Sett_Save_Flag =1;
						BUC_Net_Validate_Flag =1;
					}
					else
					{
						BUC_Net_Sett_Save_Flag =0;
						BUC_Net_Validate_Flag =2;
					}

//			PRINTF("\n\r BUC NET SETT UPDATE");
//			PRINTF("\n\r gui_update_Buc_net_IP_Addr=%s",gui_update_Buc_net_IP_Addr);
//			PRINTF("\n\r gui_update_Buc_net_SubNet_Addr=%s",gui_update_Buc_net_SubNet_Addr);
//			PRINTF("\n\r gui_update_Buc_net_gateway_Addr=%s",gui_update_Buc_net_gateway_Addr);
//			PRINTF("\n\r BUC_Net_Sett_Save_Flag=%d",BUC_Net_Sett_Save_Flag);
//			PRINTF("\n\r BUC_Net_Validate_Flag=%d",BUC_Net_Validate_Flag);
						if(BUC_Net_Sett_Save_Flag==1 && BUC_Net_Validate_Flag==1)
						{
							APPW_SetText(ID_SCREEN_BUC_NET_SETTINGS, ID_TEXT_BUC_IP_ADDR_DISP, "");
							APPW_SetText(ID_SCREEN_BUC_NET_SETTINGS, ID_TEXT_BUC_IP_ADDR_DISP, gui_update_Buc_net_IP_Addr);

							APPW_SetText(ID_SCREEN_BUC_NET_SETTINGS, ID_TEXT_BUC_SNET_ADDR_DISP, "");
							APPW_SetText(ID_SCREEN_BUC_NET_SETTINGS, ID_TEXT_BUC_SNET_ADDR_DISP, gui_update_Buc_net_SubNet_Addr);

							APPW_SetText(ID_SCREEN_BUC_NET_SETTINGS, ID_TEXT_BUC_GW_ADDR_DISP, "");
							APPW_SetText(ID_SCREEN_BUC_NET_SETTINGS, ID_TEXT_BUC_GW_ADDR_DISP, gui_update_Buc_net_gateway_Addr);
						}
  GUI_USE_PARA(pAction);
  GUI_USE_PARA(hScreen);
  GUI_USE_PARA(pMsg);
  GUI_USE_PARA(pResult);
}

/*************************** End of file ****************************/
