NVRAMEditor.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:40k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * NVRAMEditor.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * META NVRAM editor source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "form_main.h"
- #include "NVRAMEditor.h"
- #include "man_fdm.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- //#define MAX_RID_NUM_IN_LID 3000
- TfrmNVRAMEditor *frmNVRAMEditor;
- // added by Andy Ueng
- int iNVRAM_TreeItemIndex=0;
- // new tree ds.
- int iTotalTreeItemCount=0;
- extern int Determine_LID_Category(char *LID_Name_para);
- //============================================================================
- static void __stdcall NVRAM_node_read_rec_cnf_cb( const FT_NVRAM_READ_CNF *cnf, const short token, void *usrData)
- { frmNVRAMEditor->NVRAM_node_read_rec_cnf_cb(cnf, token, usrData );
- }
- //----------------------------------------------------------------------------
- static void __stdcall NVRAM_node_write_rec_cnf_cb(const FT_NVRAM_WRITE_CNF *cnf, const short token, void *usrData)
- {
- frmNVRAMEditor->NVRAM_node_write_rec_cnf_cb(cnf, token, usrData );
- }
- //----------------------------------------------------------------------------
- static void CNF_NVRAMLock( void )
- { frmNVRAMEditor->CNF_NVRAMLock();
- }
- //============================================================================
- //---------------------------------------------------------------------------
- __fastcall TfrmNVRAMEditor::TfrmNVRAMEditor(TComponent* Owner)
- : TForm(Owner)
- {
- // tbReadFromNVRAM->Enabled = true;
- // tbSaveToNVRAM->Enabled = true;
- // tbNVRAMClear->Enabled = true;
- // tbLockNVRAM->Enabled = true;
- m_NVRAM_ReadReq = NULL;
- m_NVRAM_WriteReq = NULL;
- m_NVRAM_node_read_rec.buf = NULL;
- m_pc_all_LID_name_buf = NULL;
- m_pNVRAM_TreeItem = NULL;
- m_psl_NVRAM_list = NULL;
- m_psl_LID_list = NULL;
- m_ptn_LIDNode = NULL;
- m_ptn_RIDNode = NULL;
- }
- //---------------------------------------------------------------------------
- __fastcall TfrmNVRAMEditor::~TfrmNVRAMEditor(void)
- {
- FreeDynMem();
- }
- //---------------------------------------------------------------------------
- void TfrmNVRAMEditor::FreeDynMem(void)
- {
- if( m_NVRAM_ReadReq != NULL )
- {
- delete m_NVRAM_ReadReq;
- m_NVRAM_ReadReq = NULL;
- }
- if( m_NVRAM_WriteReq != NULL)
- {
- delete m_NVRAM_WriteReq;
- m_NVRAM_WriteReq = NULL;
- }
- if( m_NVRAM_node_read_rec.buf != NULL )
- {
- delete m_NVRAM_node_read_rec.buf;
- m_NVRAM_node_read_rec.buf = NULL;
- }
- if( m_pc_all_LID_name_buf != NULL )
- {
- delete [] m_pc_all_LID_name_buf;
- m_pc_all_LID_name_buf = NULL;
- }
- if( m_pNVRAM_TreeItem != NULL )
- {
- delete m_pNVRAM_TreeItem;
- m_pNVRAM_TreeItem = NULL;
- }
- if( m_psl_NVRAM_list != NULL )
- {
- delete m_psl_NVRAM_list;
- m_psl_NVRAM_list = NULL;
- }
- if( m_psl_LID_list != NULL )
- {
- delete [] m_psl_LID_list;
- m_psl_LID_list = NULL;
- }
- if( m_ptn_LIDNode != NULL )
- {
- delete [] m_ptn_LIDNode;
- m_ptn_LIDNode = NULL;
- }
- if( m_ptn_RIDNode != NULL )
- {
- delete [] m_ptn_RIDNode;
- m_ptn_RIDNode = NULL;
- }
- }
- //===========================================================================
- void TfrmNVRAMEditor::CurrentPageReset( void )
- {
- tbReadFromNVRAM->Enabled = true;
- tbSaveToNVRAM->Enabled = true;
- tbNVRAMTreeProperty->Enabled = true;
- tbNVRAMClear->Enabled = true;
- tbLockNVRAM->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void TfrmNVRAMEditor::CurrentPageLock( void )
- {
- tbReadFromNVRAM->Enabled = false;
- tbSaveToNVRAM->Enabled = false;
- tbNVRAMTreeProperty->Enabled = false;
- tbNVRAMClear->Enabled = false;
- tbLockNVRAM->Enabled = false;
- }
- //===========================================================================
- //---------------------------------------------------------------------------
- bool get_StringList_from_buf( TStringList *psl, char *pc_buf,
- int buf_len, char c_sep )
- {
- int iStart=0;
- AnsiString as_sub;
- char *pc_sub = (char *) malloc( buf_len );
- if ( pc_sub == NULL )
- {
- ShowMessage(" memory alloc error ");
- return false;
- }
- FillMemory( pc_sub, buf_len, ' ' );
- for ( int i=0; i< buf_len; i++)
- {
- if ( *(pc_buf+i) == c_sep)
- {
- FillMemory( pc_sub, buf_len, ' ' );
- memcpy( pc_sub, pc_buf+iStart, i-iStart);
- psl->Add( AnsiString( pc_sub ));
- iStart = i+1;
- }
- } // for
- if ( pc_sub != NULL )
- {
- free( pc_sub );
- }
- return true;
- } // get_StringList_from_buf
- //---------------------------------------------------------------------------
- bool TfrmNVRAMEditor::find_node_index( TreeStructType *tst, void *pNode, int &index)
- {
- //for ( int i=0; i< MAX_ELEMENT_IN_NVRAM; i++)
- // for ( int i=0; i< TOTAL_RID_COUNT ; i++)
- for ( int i=0; i<m_iTotalRecNum; i++)
- {
- if ( tst[ i ].pNode == pNode )
- {
- index = i;
- return true;
- }
- }
- return false;
- }
- //---------------------------------------------------------------------------
- void TfrmNVRAMEditor::fill_StringGrid( TStringGrid *sg,
- int iStartCol, int iStartRow,
- int iDisplayColCount, int iDataLen,
- AnsiString as )
- {
- int iTotalRow = iDataLen/iDisplayColCount;
- int I, J;
- for (I=iStartCol; I<=(iDisplayColCount+iStartCol-1); I++)
- {
- for (J=iStartRow; J<=(iTotalRow+iStartRow-1); J++)
- {
- sg->Cells[I][J] = as;
- }
- }
- if ( iDataLen % iDisplayColCount > 0)
- {
- for (I=iStartCol; I<=( (iDataLen%iDisplayColCount)+iStartCol-1); I++)
- {
- J = iTotalRow+iStartRow;
- sg->Cells[I][J] = as;
- }
- }
- }
- //------------------------------------------------------------------------------
- void TfrmNVRAMEditor::show_Raw_Data_on_StringGrid( TStringGrid *sg,
- char *buf,
- int buf_len)
- {
- AnsiString as;
- int I,J;
- for (I = 0; I < sg->ColCount; I++)
- {
- for (J = 0; J < sg->RowCount; J++)
- {
- sg->Cells[I][J] = "";
- }
- }
- for ( int index=0; index < buf_len; index++ )
- {
- I = (index % ( RAW_DATA_COL_COUNTS )) + sg->FixedCols;
- J = (index / ( RAW_DATA_COL_COUNTS )) + sg->FixedRows;
- sg->Cells[I][J] = IntToHex( (unsigned char)(*(buf+index)), 2 ); // to Hex String
- }
- }
- //---------------------------------------------------------------------------
- void TfrmNVRAMEditor::InitializeNVRAMEditor( void )
- {
- iNVRAM_TreeItemIndex=0;
- iTotalTreeItemCount=0;
- FreeDynMem();
- tb_Init_NVRAMClick(NULL);
- NVRAM_RawDataTree->InitDataBase( NVRAMMan->Get_NvramDbVariant() );
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmNVRAMEditor::tb_Init_NVRAMClick(TObject *Sender)
- {
- META_RESULT MetaResult;
- tv_NVRAM->Items->Clear();
- // TTreeNode *ptn_Node;
- int i_LID_name_buf_len=0;
- if( NULL == m_psl_NVRAM_list )
- {
- m_psl_NVRAM_list = new TStringList();
- }
- // int i_n_of_LID=0;
- // {
- MetaResult = META_NVRAM_GetAllLIDNameLength( &i_LID_name_buf_len );
- if ( MetaResult != META_SUCCESS )
- {
- META_result_handler( MetaResult );
- }
- if ( i_LID_name_buf_len <= 0 )
- {
- Application->MessageBox( "Execution Failure : LID name length error", "FAILURE", MB_OK );
- return;
- }
- if( m_pc_all_LID_name_buf == NULL)
- {
- m_pc_all_LID_name_buf = new char[i_LID_name_buf_len];
- }
- MetaResult = META_NVRAM_GetAllLIDName(
- m_pc_all_LID_name_buf,
- i_LID_name_buf_len,
- &m_iTotalLidNum );
- if ( MetaResult != META_SUCCESS )
- {
- META_result_handler( MetaResult );
- }
- if( NULL == m_psl_LID_list )
- { m_psl_LID_list = new TStringList*[m_iTotalLidNum];
- }
- if( NULL == m_ptn_LIDNode )
- { m_ptn_LIDNode = new TTreeNode*[m_iTotalLidNum];
- }
-
- // TStringList* psl_NVRAM_list;
-
- if (! get_StringList_from_buf( m_psl_NVRAM_list, m_pc_all_LID_name_buf,
- i_LID_name_buf_len, ' '))
- {
- Application->MessageBox( "Execution Failure : parse NVRAM LID name error", "FAILURE", MB_OK );
- return;
- }
- TTreeNode *ptn_SysNode, *ptn_L1CalNode, *ptn_OtherNode;
- int rec_num=0, rec_index;
-
- char rec_buf[20];
- if(! Get_Max_RecNum( m_psl_NVRAM_list, m_iTotalLidNum, m_iMaxRecNum ) )
- {
- Application->MessageBox( "Execution Failure : Get maximum record number fail", "FAILURE", MB_OK );
- return;
- }
- if(! Get_Total_RecNum( m_psl_NVRAM_list, m_iTotalLidNum, m_iTotalRecNum ) )
- {
- Application->MessageBox( "Execution Failure : Get total record number fail", "FAILURE", MB_OK );
- return;
- }
- if( NULL == m_ptn_RIDNode )
- {
- m_ptn_RIDNode = new TTreeNode**[m_iTotalLidNum];
- for( int j = 0; j <m_iTotalLidNum; j++ )
- {
- m_ptn_RIDNode[j] = new TTreeNode*[m_iMaxRecNum];
- }
- }
- if( NULL == m_pNVRAM_TreeItem )
- { m_pNVRAM_TreeItem = new TreeStructType[m_iTotalRecNum];
- }
- // add LID to tree list
- ptn_SysNode = tv_NVRAM->Items->Add( NULL , "System related LID" );
- ptn_L1CalNode = tv_NVRAM->Items->Add( NULL , "L1 LID" );
- ptn_OtherNode = tv_NVRAM->Items->Add( NULL , "Other LID" );
- for ( int j=0; j<m_iTotalLidNum; j++)
- {
- int LID_category;
- LID_category = Determine_LID_Category(m_psl_NVRAM_list->Strings[j].c_str());
- switch(LID_category)
- {
- case SYSTEM_RELATED_LID_CATEGORY:
- {
- m_ptn_LIDNode[j] = tv_NVRAM->Items->AddChild( ptn_SysNode , m_psl_NVRAM_list->Strings[j] );
- MetaResult = META_NVRAM_GetRecNum(m_psl_NVRAM_list->Strings[j].c_str(), &rec_num);
- if( MetaResult != META_SUCCESS )
- {
- META_result_handler(MetaResult);
- }
- for(rec_index = 0; rec_index < rec_num; rec_index++)
- {
- sprintf(rec_buf, "%d", rec_index+1);
- m_ptn_RIDNode[j][rec_index] = tv_NVRAM->Items->AddChild( m_ptn_LIDNode[j] , rec_buf );
- }
- }
- break;
- case L1_CALIBRATION_LID_CATEGORY:
- {
- m_ptn_LIDNode[j] = tv_NVRAM->Items->AddChild( ptn_L1CalNode , m_psl_NVRAM_list->Strings[j] );
- MetaResult = META_NVRAM_GetRecNum(m_psl_NVRAM_list->Strings[j].c_str(), &rec_num);
- if( MetaResult != META_SUCCESS )
- {
- META_result_handler(MetaResult);
- }
- for(rec_index = 0; rec_index < rec_num; rec_index++)
- {
- sprintf(rec_buf, "%d", rec_index+1);
- m_ptn_RIDNode[j][rec_index] = tv_NVRAM->Items->AddChild( m_ptn_LIDNode[j] , rec_buf );
- }
- }
- break;
- case OTHER_LID_CATEGORY:
- {
- m_ptn_LIDNode[j] = tv_NVRAM->Items->AddChild( ptn_OtherNode , m_psl_NVRAM_list->Strings[j] );
- MetaResult = META_NVRAM_GetRecNum(m_psl_NVRAM_list->Strings[j].c_str(), &rec_num);
- if( MetaResult != META_SUCCESS )
- {
- META_result_handler(MetaResult);
- }
- for(rec_index = 0; rec_index < rec_num; rec_index++)
- {
- sprintf(rec_buf, "%d", rec_index+1);
- m_ptn_RIDNode[j][rec_index] = tv_NVRAM->Items->AddChild( m_ptn_LIDNode[j] , rec_buf );
- }
- }
- break;
- }
- for(rec_index = 0; rec_index < rec_num; rec_index++)
- {
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].pNode = m_ptn_RIDNode[j][rec_index];
- strcpy( m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].LIDNAME, m_psl_NVRAM_list->Strings[j].c_str());
- iNVRAM_TreeItemIndex++;
- iTotalTreeItemCount++;
- }
- } // for j
- // } // for i
- }
- //---------------------------------------------------------------------------
- void TfrmNVRAMEditor::read_Raw_Data_from_StringGrid( TStringGrid *sg,
- int iStartCol, int iStartRow,
- int iDisplayColCount, int iDataLen,
- char *buf )
- {
- int I,J;
- for ( int index=0; index < iDataLen; index++ )
- {
- I = (index % ( RAW_DATA_COL_COUNTS )) + sg->FixedCols;
- J = (index / ( RAW_DATA_COL_COUNTS )) + sg->FixedRows;
- (*(buf+index)) = StrToInt ( AnsiString("0x")+ sg->Cells[I][J] );
- }
- }
- //-----------------------------------------------------------------------------
- // modified by Andy Ueng
- // bool TfrmNVRAMEditor::get_index_from_group_element_name( char * group_name,
- // char * element_name,
- // int &index )
- // modified by Andy Ueng
- // bool TfrmNVRAMEditor::get_index_from_LID( char *LID_para, int &index )
- bool TfrmNVRAMEditor::get_index_from_LID( char *LID_para, int *index )
- // end of modified
- {
- for ( int I=0; I < iTotalTreeItemCount; I++)
- {
- // modified by Andy Ueng
- // if ( ( strcmp( FDM_TreeItem[I].GroupName, group_name ) == 0 ) &&
- // ( strcmp( FDM_TreeItem[I].ElementName, element_name ) == 0 ) )
- if ( ( strcmp( m_pNVRAM_TreeItem[I].LIDNAME, LID_para ) == 0 ) )
- // end of modified
- {
- *index = I;
- return true;
- }
- }
- return false;
- }
- //---------------------------------------------------------------------------
- // end of added
- //---------------------------------------------------------------------------
- void __fastcall TfrmNVRAMEditor::tbReadFromNVRAMClick(TObject *Sender)
- {
- META_RESULT MetaResult;
- if( ! NVRAMMan->Get_IsInit() )
- {
- frmMainSel->mnuFDMDatabaseClick(Sender);
- }
- if( ! NVRAMMan->Get_IsInit() )
- {
- Application->MessageBox( "Execution Failure : NVRAM database file initialize fail", "FAILURE", MB_OK );
- return;
- }
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- if ( NULL == tv_NVRAM->Selected )
- {
- Application->MessageBox( " You need to select a record from left tree view window ", "Notice", MB_OK );
- return;
- }
- m_ptn_selected = tv_NVRAM->Selected ;
- if ( NULL == m_ptn_selected )
- return;
- if (! find_node_index( m_pNVRAM_TreeItem, tv_NVRAM->Selected, iNVRAM_TreeItemIndex ))
- {
- Application->MessageBox( "Execution Failure : NVRAM editor can't find this node", "FAILURE", MB_OK );
- return;
- }
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = false;
- }
- if ( m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle.intVal == 0 )
- {
- // do nothing
- }
- else
- {
- long lModified;
- NVRAM_RawDataTree->TreeGetModify( m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle, &lModified );
- if ( lModified )
- {
- NVRAM_RawDataTree->TreeSetSel( m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle );
- int msg_result = Application->MessageBox( " Do you want to save this struct ? ",
- " NVRAM editor ",
- MB_YESNOCANCEL) ;
- switch ( msg_result )
- {
- case IDYES :
- {
- tbSaveToNVRAMClick( NULL );
- NVRAM_RawDataTree->TreeDeleteItem( m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle ); // added by Andy Ueng
- m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle.intVal = 0;
- // IDyes-> download & read back from fdm
- //return;
- }
- break;
- case IDNO :
- {
- NVRAM_RawDataTree->TreeDeleteItem( m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle );
- m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle.intVal = 0;
- }
- break;
- case IDCANCEL :
- {
- tbReadFromNVRAM->Enabled = true;
- return;
- }
- } // switch
- } // if
- else
- {
- NVRAM_RawDataTree->TreeDeleteItem( m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle );
- m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle.intVal = 0;
- }
- }
- int i_struct_name_buf_len=0;
- MetaResult = META_NVRAM_GetRecStructNameLength(m_ptn_selected->Parent->Text.c_str(),
- &i_struct_name_buf_len );
- if ( MetaResult != META_SUCCESS )
- {
- META_result_handler( MetaResult );
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = true;
- }
- return;
- }
- // char *pc_struct_buf;
- // pc_struct_buf = ( char *) malloc( i_struct_name_buf_len );
- if ( i_struct_name_buf_len > 0 ) // ==0 RawData
- {
- MetaResult = META_NVRAM_GetRecStructName(m_ptn_selected->Parent->Text.c_str(),
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].StructName,
- i_struct_name_buf_len );
- if ( MetaResult != META_SUCCESS )
- {
- META_result_handler( MetaResult );
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = true;
- }
- return;
- }
- MetaResult = META_NVRAM_GetRecLen( m_ptn_selected->Parent->Text.c_str(),
- &(m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen) );
- if ( MetaResult != META_SUCCESS )
- {
- META_result_handler( MetaResult );
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = true;
- }
- return;
- }
- if( NULL == m_NVRAM_node_read_rec.buf )
- { m_NVRAM_node_read_rec.buf = new char[m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen];
- }
- m_NVRAM_node_read_rec.len = m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen;
- }
- else
- {
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen = 0;
- strcpy ( m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].StructName,
- m_ptn_selected->Text.c_str()
- );
- if( NULL == m_NVRAM_node_read_rec.buf )
- { m_NVRAM_node_read_rec.buf = new char[ RAW_DATA_BUF_LEN ];
- }
- m_NVRAM_node_read_rec.len = RAW_DATA_BUF_LEN ;
- }
- if( NULL == m_NVRAM_ReadReq )
- { m_NVRAM_ReadReq = new FT_NVRAM_READ_REQ;
- }
- m_NVRAM_ReadReq->LID = m_ptn_selected->Parent->Text.c_str();
- m_NVRAM_ReadReq->RID = m_ptn_selected->Text.ToInt();
- MetaResult = META_NVRAM_Read_r( m_META_HANDLE_Obj.Get_MainHandle(),
- m_NVRAM_ReadReq,
- &m_NVRAM_node_read_rec,
- ::NVRAM_node_read_rec_cnf_cb,
- &m_sNVRAM_node_read_rec_token,
- NULL );
- if ( MetaResult != META_SUCCESS )
- {
- META_result_handler(MetaResult);
- if ( Sender != NULL )
- { dynamic_cast <TControl *>(Sender)->Enabled = true;
- }
- return;
- }
- else
- {
- m_ptn_rec = m_ptn_selected;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmNVRAMEditor::tbSaveToNVRAMClick(TObject *Sender)
- {
- if( ! NVRAMMan->Get_IsInit() )
- {
- frmMainSel->mnuFDMDatabaseClick(Sender);
- }
- if( ! NVRAMMan->Get_IsInit() )
- {
- Application->MessageBox( "Execution Failure : NVRAM database file initialize fail", "FAILURE", MB_OK );
- return;
- }
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- if ( NVRAM_RawDataTree->Visible )
- { // Active X tree
- if ( tv_NVRAM->Selected == NULL )
- {
- Application->MessageBox( " You must select a element to download to NVRAM ", "Notice", MB_OK );
- return;
- }
- m_ptn_selected = tv_NVRAM->Selected;
- if ( m_ptn_selected->Parent == NULL )
- {
- Application->MessageBox( " You need to select a element to download to NVRAM ", "Notice", MB_OK );
- return;
- }
- if (! get_index_from_LID( m_ptn_selected->Parent->Text.c_str(),
- &iNVRAM_TreeItemIndex
- ))
- {
- Application->MessageBox( " NVRAM editor error: can't find index", "FAILURE", MB_OK );
- return;
- }
- iNVRAM_TreeItemIndex = iNVRAM_TreeItemIndex + m_ptn_selected->Text.ToInt()-1;
- // if( m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle.intVal ==0)
- // {
- // Application->MessageBox( " Please read this struct from NVRAM before downloading", "Notice", MB_OK );
- // return;
- // }
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = false;
- }
- if( NULL == m_NVRAM_WriteReq )
- {
- m_NVRAM_WriteReq = new FT_NVRAM_WRITE_REQ;
- }
- m_NVRAM_WriteReq->LID = m_ptn_selected->Parent->Text.c_str();
- m_NVRAM_WriteReq->RID = m_ptn_selected->Text.ToInt(); // temp set to 1
- m_NVRAM_WriteReq->buf = m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].Buf;
- m_NVRAM_WriteReq->len = m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].iDataLen;
- META_RESULT MetaResult = META_NVRAM_Write_r( m_META_HANDLE_Obj.Get_MainHandle(),
- m_NVRAM_WriteReq,
- ::NVRAM_node_write_rec_cnf_cb,
- &m_sNVRAM_node_write_rec_token,
- NULL );
-
- if ( MetaResult != META_SUCCESS )
- {
- META_result_handler(MetaResult);
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = true;
- }
- return;
- }
- }
- else
- {
- read_Raw_Data_from_StringGrid( sg_NVRAM_editor,
- RAW_DATA_START_COL,
- RAW_DATA_START_ROW,
- RAW_DATA_COL_COUNTS,
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen,
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].Buf );
- META_RESULT mr1 = META_NVRAM_Write_r( m_META_HANDLE_Obj.Get_MainHandle(),
- m_NVRAM_WriteReq,
- ::NVRAM_node_write_rec_cnf_cb,
- &m_sNVRAM_node_write_rec_token,
- NULL );
- if ( mr1 != META_SUCCESS )
- {
- META_result_handler( mr1);
- if ( Sender != NULL )
- {
- dynamic_cast <TControl *>(Sender)->Enabled = true;
- }
- return;
- }
- }
- }
- //-----------------------------------------------------------------------------
- void __stdcall TfrmNVRAMEditor::NVRAM_node_read_rec_cnf_cb( const FT_NVRAM_READ_CNF *cnf, const short token, void *usrData)
- {
- tbReadFromNVRAM->Enabled = true;
- if ( cnf->status != FDM_READ_SUCCESS )
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) " NVRAM read record fail ";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- Application->MessageBox( "NVRAM read record fail", "FAILURE", MB_OK );
- }
- else
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) " NVRAM read record successfully ";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- if (m_NVRAM_node_read_rec.len ==0)
- {
- sb_NVRAM_editor->Panels->Items[1]->Text = " buf length: 0 ";
- return;
- }
- else
- {
- sb_NVRAM_editor->Panels->Items[1]->Text = " buf length: " +
- IntToStr( m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen);
- }
- if (m_NVRAM_node_read_rec.status == FDM_DATA_VALID)
- {
- sb_NVRAM_editor->Panels->Items[2]->Text = " data valid ";
- }
- else
- {
- sb_NVRAM_editor->Panels->Items[2]->Text = " data invalid ";
- return;
- }
- if ( m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen > 0)
- {
- NVRAM_RawDataTree->Visible = true;
- tbNVRAMTreeProperty->Enabled = true;
- sg_NVRAM_editor->Visible = false;
- memcpy( m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].Buf,
- m_NVRAM_node_read_rec.buf,
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen
- );
- if( NULL != m_NVRAM_node_read_rec.buf )
- {
- delete [] m_NVRAM_node_read_rec.buf;
- m_NVRAM_node_read_rec.buf = NULL;
- }
- //long bStruct = true;
- NVRAM_RawDataTree->EncodeNvramData( m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen,
- TVariant((long)m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].Buf),
- TVariant((char *)m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].LIDNAME) ,
- &m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].vTreeItemHandle
- );
- }
- else
- {
- memcpy( m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].Buf,
- m_NVRAM_node_read_rec.buf,
- m_NVRAM_node_read_rec.len
- );
- if( NULL != m_NVRAM_node_read_rec.buf)
- {
- delete [] m_NVRAM_node_read_rec.buf;
- m_NVRAM_node_read_rec.buf = NULL;
- }
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen = m_NVRAM_node_read_rec.len;
- NVRAM_RawDataTree->Visible = false;
- tbNVRAMTreeProperty->Enabled = false;
- sg_NVRAM_editor->Visible = true;
- show_Raw_Data_on_StringGrid( sg_NVRAM_editor,
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].Buf,
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen
- );
- }
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].bRead = true;
- }
- }
- //------------------------------------------------------------------------------
- void __stdcall TfrmNVRAMEditor::NVRAM_node_write_rec_cnf_cb( const FT_NVRAM_WRITE_CNF *cnf, const short token, void *usrData)
- {
- tbSaveToNVRAM->Enabled = true;
- if ( cnf->status == FDM_WRITE_SUCCESS )
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) " NVRAM write record successfully ";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- if ( NVRAM_RawDataTree->Visible )
- {
- NVRAM_RawDataTree->TreeSetModify( m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle,
- false);
- }
- }
- else
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) " NVRAM write record fail ";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- Application->MessageBox( "NVRAM write record fail", "FAILURE", MB_OK );
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmNVRAMEditor::tbNVRAMTreePropertyClick(TObject *Sender)
- {
- LPUNKNOWN pUnk = NULL;
- pUnk = NVRAM_RawDataTree->ControlInterface;
- IOleObject* pIOle = NULL;
- if ( SUCCEEDED( pUnk->QueryInterface( IID_IOleObject, (void**)&pIOle)))
- {
- IOleClientSite* pCS = NULL;
- pIOle->GetClientSite(&pCS);
- RECT rct;
- pIOle->DoVerb(OLEIVERB_PROPERTIES,NULL,pCS,0, this->Handle ,&rct);
- pIOle->Release();
- pCS->Release();
- }
- }
- //---------------------------------------------------------------------------
- bool TfrmNVRAMEditor::get_index_from_handle( TreeStructType *tst,
- int i,
- int &index )
- {
- for( int I=0; I<iTotalTreeItemCount; I++)
- {
- if (tst[ I ].vTreeItemHandle.intVal == i )
- {
- index = I;
- return true;
- }
- }
- return false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmNVRAMEditor::tbNVRAMClearClick(TObject *Sender)
- {
- if( ! NVRAMMan->Get_IsInit() )
- {
- frmMainSel->mnuFDMDatabaseClick(Sender);
- }
- if( ! NVRAMMan->Get_IsInit() )
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) " NVRAM database file initialization fail";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- Application->MessageBox( "Execution Failure : NVRAM database file initialization fail", "FAILURE", MB_OK );
- return;
- }
- if ( NVRAM_RawDataTree->Visible )
- {
- if (iTotalTreeItemCount == 0)
- return;
- TVariant vTreeItemHandle;
- NVRAM_RawDataTree->TreeGetSel( &vTreeItemHandle );
- if ( vTreeItemHandle.intVal == 0 )
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) " Please select a tree item to clear ";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- Application->MessageBox( "Please select a tree item to clear", "WARNING", MB_OK );
- return;
- }
- int iItemIndex = -1;
- if ( ! get_index_from_handle( m_pNVRAM_TreeItem, vTreeItemHandle.intVal , iItemIndex ))
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) " NVRAM editor error: can't get item index ";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- Application->MessageBox( "Execution Failure : NVRAM editor error: can't get item index", "FAILURE", MB_OK );
- }
- else
- {
- long lModified;
- NVRAM_RawDataTree->TreeGetModify( m_pNVRAM_TreeItem[ iItemIndex].vTreeItemHandle , &lModified );
- if ( lModified )
- {
- int msg_result = Application->MessageBox( " Do you want to save this struct ? ",
- " NVRAM editor ",
- MB_YESNOCANCEL) ;
- switch ( msg_result )
- {
- case IDYES :
- tbSaveToNVRAMClick( NULL );
- tbNVRAMClearClick(Sender);
- return;
- case IDNO :
- NVRAM_RawDataTree->TreeDeleteItem( m_pNVRAM_TreeItem[ iItemIndex ].vTreeItemHandle );
- m_pNVRAM_TreeItem[ iItemIndex ].vTreeItemHandle.intVal = 0 ;
- break;
- case IDCANCEL :
- return;
- } // switch
- }
- else
- {
- NVRAM_RawDataTree->TreeDeleteItem( m_pNVRAM_TreeItem[ iItemIndex ].vTreeItemHandle );
- m_pNVRAM_TreeItem[ iItemIndex ].vTreeItemHandle.intVal = 0 ;
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) " Clear NVRAM record successfully";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- }
- }
- }
- else
- {
- fill_StringGrid( sg_NVRAM_editor,
- RAW_DATA_START_COL,
- RAW_DATA_START_ROW,
- RAW_DATA_COL_COUNTS,
- m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].iDataLen,
- AnsiString("00") );
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmNVRAMEditor::OnClick(TObject *Sender)
- {
- if (find_node_index( m_pNVRAM_TreeItem, tv_NVRAM->Selected, iNVRAM_TreeItemIndex ))
- {
- if(m_pNVRAM_TreeItem[ iNVRAM_TreeItemIndex ].vTreeItemHandle.intVal != 0)
- {
- NVRAM_RawDataTree->TreeSetSel( m_pNVRAM_TreeItem[iNVRAM_TreeItemIndex].vTreeItemHandle );
- }
- }
- }
- //---------------------------------------------------------------------------
- bool TfrmNVRAMEditor::Get_Total_RecNum( TStringList* psl_list, int lid_num, int &total_rec_num )
- {
- META_RESULT MetaResult;
- int rec_num;
- total_rec_num = 0;
- for( int i=0; i<lid_num; i++ )
- {
- MetaResult = META_NVRAM_GetRecNum(psl_list->Strings[i].c_str(), &rec_num);
- if( MetaResult != META_SUCCESS )
- {
- return false;
- }
- total_rec_num += rec_num;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool TfrmNVRAMEditor::Get_Max_RecNum( TStringList* psl_list, int lid_num, int &max_rec_num )
- {
- META_RESULT MetaResult;
- int rec_num;
- max_rec_num = 0;
- for( int i=0; i<lid_num; i++ )
- {
- MetaResult = META_NVRAM_GetRecNum(psl_list->Strings[i].c_str(), &rec_num);
- if( MetaResult != META_SUCCESS )
- {
- return false;
- }
- if( max_rec_num < rec_num )
- max_rec_num = rec_num;
- }
- return true;
- }
- void __fastcall TfrmNVRAMEditor::tbLockNVRAMClick(TObject *Sender)
- {
- m_NVRAM_LOCK_Obj.ConfirmCallback = ::CNF_NVRAMLock;
- m_NVRAM_LOCK_Obj.REQ_Start();
- CurrentPageLock();
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) " Locks NVRAM progressing ";
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- }
- //---------------------------------------------------------------------------
- void TfrmNVRAMEditor::CNF_NVRAMLock( void )
- {
- int state = m_NVRAM_LOCK_Obj.Get_ConfirmState();
- switch( state )
- {
- case STATE_NVRAM_LOCK_OK:
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString) " Locks NVRAM successfully ";
- }
- break;
- case STATE_NVRAM_LOCK_FAIL:
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString)" Locks NVRAM fail";
- Application->MessageBox( "Execution Failure : Locks NVRAM ", "FAILURE", MB_OK );
- //Force_WiFi_Stop();
- }
- break;
- case STATE_NVRAM_LOCK_TIMEOUT:
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString)" Locks NVRAM timeout";
- Application->MessageBox( "Execution Timeout : Locks NVRAM ", "TIMEOUT", MB_OK );
- // Force_WiFi_Stop();
- }
- break;
- case STATE_NVRAM_LOCK_STOP:
- {
- sb_NVRAM_editor->Panels->Items[0]->Text = (AnsiString)" Locks NVRAM stop";
- }
- break;
- }
- CurrentPageReset();
- sb_NVRAM_editor->Panels->Items[1]->Text = (AnsiString) "";
- sb_NVRAM_editor->Panels->Items[2]->Text = (AnsiString) "";
- }