⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nvrameditor.cpp

📁 MTK_NVRAM_Editor的源码,可能对你们有用哦
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "form_main.h"
#include "NVRAMEditor.h"
#include "man_fdm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
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 );
}
//---------------------------------------------------------------------------
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, '\0' );

       for ( int i=0; i< buf_len; i++)
       {
          if ( *(pc_buf+i) == c_sep)
          {
             FillMemory( pc_sub, buf_len, '\0' );
             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 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++)
     {
       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 __fastcall TfrmNVRAMEditor::tb_Init_NVRAMClick(TObject *Sender)
{
   tv_NVRAM->Items->Clear();

   TTreeNode *ptn_Node;


   TStringList* psl_LID_list[ MAX_LID_NUM_IN_NVRAM ];
   TTreeNode *ptn_LIDNode[ MAX_LID_NUM_IN_NVRAM ];
   TTreeNode *ptn_RIDNode[ MAX_LID_NUM_IN_NVRAM ][ MAX_RID_NUM_IN_LID ];


   int i_LID_name_buf_len=0;
   char *pc_all_LID_name_buf=NULL;
   TStringList* psl_NVRAM_list;
   psl_NVRAM_list = new TStringList();
   int i_n_of_LID=0;

   {

     mr1 = META_NVRAM_GetAllLIDNameLength(&i_LID_name_buf_len  );

       if ( mr1 != META_SUCCESS )
       {
            META_result_handler( mr1);
       }



      if ( i_LID_name_buf_len <= 0 )
       {
          ShowMessage(" META LAB: LID name length error ");
          return;
       }


       if(  pc_all_LID_name_buf == NULL)
       {
          pc_all_LID_name_buf = new char[i_LID_name_buf_len];
       }   




       mr1 = META_NVRAM_GetAllLIDName(
                                         pc_all_LID_name_buf,
                                         i_LID_name_buf_len,
                                         &i_n_of_LID );

       if ( mr1 != META_SUCCESS )
       {
            META_result_handler( mr1);
       }



   //  TStringList* psl_NVRAM_list;
    // psl_NVRAM_list = new TStringList();

     if (! get_StringList_from_buf( psl_NVRAM_list, pc_all_LID_name_buf,
                            i_LID_name_buf_len, '\0'))
   {
      ShowMessage(" META LAB : parse NVRAM LID name error ");
      return;
   }

       TTreeNode *ptn_SysNode, *ptn_L1CalNode, *ptn_OtherNode;
       int rec_num=0, rec_index;
       char rec_buf[20];
       ptn_SysNode = tv_NVRAM->Items->Add( NULL , "System related LID" );
       ptn_L1CalNode = tv_NVRAM->Items->Add( NULL , "L1 calibration LID" );
       ptn_OtherNode = tv_NVRAM->Items->Add( NULL , "Other LID" );


  for ( int j=0; j< i_n_of_LID; j++)
       {

         int LID_category;
         LID_category = Determine_LID_Category(psl_NVRAM_list->Strings[j].c_str());
         switch(LID_category)
           {
            case SYSTEM_RELATED_LID_CATEGORY:
              ptn_LIDNode[j] = tv_NVRAM->Items->AddChild( ptn_SysNode , psl_NVRAM_list->Strings[j] );
              mr1 = META_NVRAM_GetRecNum(psl_NVRAM_list->Strings[j].c_str(), &rec_num);
              if( mr1 != META_SUCCESS )
                {
                  META_result_handler( mr1);
                }
              for(rec_index = 0; rec_index < rec_num; rec_index++)
                {
                 sprintf(rec_buf, "%d", rec_index+1);
                 ptn_RIDNode[j][rec_index] = tv_NVRAM->Items->AddChild( ptn_LIDNode[j] , rec_buf );
                }

            break;

            case L1_CALIBRATION_LID_CATEGORY:
              ptn_LIDNode[j] = tv_NVRAM->Items->AddChild( ptn_L1CalNode , psl_NVRAM_list->Strings[j] );
              mr1 = META_NVRAM_GetRecNum(psl_NVRAM_list->Strings[j].c_str(), &rec_num);
              if( mr1 != META_SUCCESS )
                {
                  META_result_handler( mr1);
                }
              for(rec_index = 0; rec_index < rec_num; rec_index++)
                {
                 sprintf(rec_buf, "%d", rec_index+1);
                 ptn_RIDNode[j][rec_index] = tv_NVRAM->Items->AddChild( ptn_LIDNode[j] , rec_buf );
                }
            break;

            case OTHER_LID_CATEGORY:
              ptn_LIDNode[j] = tv_NVRAM->Items->AddChild( ptn_OtherNode , psl_NVRAM_list->Strings[j] );
              mr1 = META_NVRAM_GetRecNum(psl_NVRAM_list->Strings[j].c_str(), &rec_num);
              if( mr1 != META_SUCCESS )
                {
                  META_result_handler( mr1);
                }
              for(rec_index = 0; rec_index < rec_num; rec_index++)
                {
                 sprintf(rec_buf, "%d", rec_index+1);
                 ptn_RIDNode[j][rec_index] = tv_NVRAM->Items->AddChild( ptn_LIDNode[j] , rec_buf );
                }
            break;
           }



           for(rec_index = 0; rec_index < rec_num; rec_index++)
                {
                 NVRAM_TreeItem[ iNVRAM_TreeItemIndex ].pNode = ptn_RIDNode[j][rec_index];
                 strcpy( NVRAM_TreeItem[ iNVRAM_TreeItemIndex ].LIDNAME, psl_NVRAM_list->Strings[j].c_str());
                 iNVRAM_TreeItemIndex++;
                 iTotalTreeItemCount++;
                }

          




       } // for  j

   } // for  i

   if(pc_all_LID_name_buf)
   {
      delete [] pc_all_LID_name_buf;
      pc_all_LID_name_buf = NULL;
   }
   if(psl_NVRAM_list)
   {
      delete psl_NVRAM_list;
      psl_NVRAM_list = NULL;
   }

}

//---------------------------------------------------------------------------
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( NVRAM_TreeItem[I].LIDNAME, LID_para ) == 0 ) )
        // end of modified
         {
             *index = I;
             return true;
         }

      }
      return false;
  }
//---------------------------------------------------------------------------
// end of added

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -