form_WiFiEEPROM.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:26k
源码类别:

MTK

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include <stdio.h>
  4. #pragma hdrstop
  5. // form
  6. #ifndef _FORM_WIFIEEPROM_H_
  7. #include "form_WiFiEEPROM.h"
  8. #endif
  9. #ifndef _FORM_MAIN_H_
  10. #include "form_main.h"
  11. #endif
  12. // misc
  13. #ifndef  _MISC_WIFI_H_
  14. #include "misc_wifi.h"
  15. #endif
  16. //---------------------------------------------------------------------------
  17. #pragma package(smart_init)
  18. #pragma resource "*.dfm"
  19. TfrmWiFiEEPROM *frmWiFiEEPROM;
  20. #define    PNLIDX_WGI       0x01
  21. #define    PNLIDX_TXDC      0x02
  22. #define    PNLIDX_2400MTXP  0x04
  23. //---------------------------------------------------------------------------
  24. void ConfirmCallback_ReadEE( void )
  25. {   frmWiFiEEPROM->ConfirmCallback_ReadEE();
  26. }
  27. //---------------------------------------------------------------------------
  28. void ConfirmCallback_WriteEE( void )
  29. {   frmWiFiEEPROM->ConfirmCallback_WriteEE();
  30. }
  31. //---------------------------------------------------------------------------
  32. __fastcall TfrmWiFiEEPROM::TfrmWiFiEEPROM(TComponent* Owner)
  33.         : TForm(Owner)
  34. {
  35.     edtCCKCHDAC[ 0] = edtCCKCHDAC00;
  36.     edtCCKCHDAC[ 1] = edtCCKCHDAC01;
  37.     edtCCKCHDAC[ 2] = edtCCKCHDAC02;
  38.     edtCCKCHDAC[ 3] = edtCCKCHDAC03;
  39.     edtCCKCHDAC[ 4] = edtCCKCHDAC04;
  40.     edtCCKCHDAC[ 5] = edtCCKCHDAC05;
  41.     edtCCKCHDAC[ 6] = edtCCKCHDAC06;
  42.     edtCCKCHDAC[ 7] = edtCCKCHDAC07;
  43.     edtCCKCHDAC[ 8] = edtCCKCHDAC08;
  44.     edtCCKCHDAC[ 9] = edtCCKCHDAC09;
  45.     edtCCKCHDAC[10] = edtCCKCHDAC0A;
  46.     edtCCKCHDAC[11] = edtCCKCHDAC0B;
  47.     edtCCKCHDAC[12] = edtCCKCHDAC0C;
  48.     edtCCKCHDAC[13] = edtCCKCHDAC0D;
  49.     edtOFDMCHDAC[ 0] = edtOFDMCHDAC00;
  50.     edtOFDMCHDAC[ 1] = edtOFDMCHDAC01;
  51.     edtOFDMCHDAC[ 2] = edtOFDMCHDAC02;
  52.     edtOFDMCHDAC[ 3] = edtOFDMCHDAC03;
  53.     edtOFDMCHDAC[ 4] = edtOFDMCHDAC04;
  54.     edtOFDMCHDAC[ 5] = edtOFDMCHDAC05;
  55.     edtOFDMCHDAC[ 6] = edtOFDMCHDAC06;
  56.     edtOFDMCHDAC[ 7] = edtOFDMCHDAC07;
  57.     edtOFDMCHDAC[ 8] = edtOFDMCHDAC08;
  58.     edtOFDMCHDAC[ 9] = edtOFDMCHDAC09;
  59.     edtOFDMCHDAC[10] = edtOFDMCHDAC0A;
  60.     edtOFDMCHDAC[11] = edtOFDMCHDAC0B;
  61.     edtOFDMCHDAC[12] = edtOFDMCHDAC0C;
  62.     edtOFDMCHDAC[13] = edtOFDMCHDAC0D;
  63.     Init();
  64. }
  65. //---------------------------------------------------------------------------
  66. void TfrmWiFiEEPROM::Init( void )
  67. {
  68.      m_bInit          = true;
  69.      m_sEEGeneral.usReserved0 = 0x0000;
  70.      m_sEEGeneral.usReserved1 = 0x0000;
  71.      m_sEEGeneral.ucReserved2 = 0x00;
  72.      m_usReserved3 = 0x0000;
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TfrmWiFiEEPROM::FormShow(TObject *Sender)
  76. {
  77.     if( m_bInit )
  78.     {
  79.         m_bInit = false;
  80.         m_sWiFiCap = frmMainSel->Get_FinalWiFiCap();
  81.     }    
  82. }
  83. //---------------------------------------------------------------------------
  84. //------------------------------------------------------------------------------
  85. void  TfrmWiFiEEPROM::ReDrawFields( int idx )
  86. {
  87.     int i;
  88.     char str[256];
  89.     if( idx & PNLIDX_WGI )
  90.     {
  91.         if( 0 == btnWGI->Tag ) // Dec
  92.         {
  93.             btnWGI->Caption = "Dec";
  94.             lblBBChipID0x->Visible = false;
  95.             lblRFChipID0x->Visible = false;
  96.             lblSN0x->Visible = false;
  97.             lblMACAddr0x->Visible = false;
  98.             lblChecksum0x->Visible = false;
  99.             edtBBChipID->Text = IntToStr( m_sEEGeneral.usBBChipID );
  100.             edtRFChipID->Text = IntToStr( m_sEEGeneral.usRFChipID );
  101.             edtSN->Text       = IntToStr( m_sEEGeneral.uiSN );
  102.             for( i=0; i<sizeof(m_sEEGeneral.sMACAddr.mac_addr)/sizeof(m_sEEGeneral.sMACAddr.mac_addr[0]); i++ )
  103.             {
  104.                 edtMACAddr[i]->Text  = IntToStr( m_sEEGeneral.sMACAddr.mac_addr[i] );
  105.             }
  106.             edtChecksum->Text = IntToStr( m_sEEGeneral.ucChecksum );
  107.         }
  108.         else
  109.         {
  110.             btnWGI->Caption = "Hex";
  111.             lblBBChipID0x->Visible = true;
  112.             lblRFChipID0x->Visible = true;
  113.             lblSN0x->Visible = true;
  114.             lblMACAddr0x->Visible = true;
  115.             lblChecksum0x->Visible = true;
  116.             sprintf( str, "%X", m_sEEGeneral.usBBChipID );
  117.             edtBBChipID->Text = str;
  118.             sprintf( str, "%X", m_sEEGeneral.usRFChipID );
  119.             edtRFChipID->Text = str;
  120.             sprintf( str, "%X", m_sEEGeneral.uiSN );
  121.             edtSN->Text = str;
  122.             for( i=0; i<sizeof(m_sEEGeneral.sMACAddr.mac_addr)/sizeof(m_sEEGeneral.sMACAddr.mac_addr[0]); i++ )
  123.             {
  124.                 sprintf( str, "%X", m_sEEGeneral.sMACAddr.mac_addr[i] );
  125.                 edtMACAddr[i]->Text = str;
  126.             }
  127.             sprintf( str, "%X", m_sEEGeneral.ucChecksum );
  128.             edtChecksum->Text = str;
  129.         }
  130.     }
  131.     if( idx & PNLIDX_TXDC )
  132.     {
  133.         if( 0 == btnTXDC->Tag ) // Dec
  134.         {
  135.             btnTXDC->Caption = "Dec";
  136.             lblTXIDC0x->Visible = false;
  137.             lblTXQDC0x->Visible = false;
  138.             edtTXIDC->Text = IntToStr( m_sEEGeneral.sTxDcOffset.i_ch_offset );
  139.             edtTXQDC->Text = IntToStr( m_sEEGeneral.sTxDcOffset.q_ch_offset );
  140.         }
  141.         else // Hex
  142.         {
  143.             btnTXDC->Caption = "Hex";
  144.             lblTXIDC0x->Visible = true;
  145.             lblTXQDC0x->Visible = true;
  146.             sprintf( str, "%X", m_sEEGeneral.sTxDcOffset.i_ch_offset );
  147.             edtTXIDC->Text = str;
  148.             sprintf( str, "%X", m_sEEGeneral.sTxDcOffset.q_ch_offset );
  149.             edtTXQDC->Text = str;
  150.         }
  151.     }
  152.     if( idx & PNLIDX_2400MTXP )
  153.     {
  154.         if( 0 == btn2400MTXP->Tag ) // Dec
  155.         {
  156.             btn2400MTXP->Caption = "Dec";
  157.             for(i=0; i<NUM_TX_POWER_2400M_CH; i++)
  158.             {
  159.                 edtCCKCHDAC[i]->Text = IntToStr( m_sTxPwr2400M.CCKTxPWR[i] );
  160.                 edtOFDMCHDAC[i]->Text = IntToStr( m_sTxPwr2400M.OFDMTxPWR[i] );
  161.             }
  162.         }
  163.         else
  164.         {
  165.             btn2400MTXP->Caption = "Hex";
  166.             for(i=0; i<NUM_TX_POWER_2400M_CH; i++)
  167.             {
  168.                 sprintf( str, "%X", m_sTxPwr2400M.CCKTxPWR[i] );
  169.                 edtCCKCHDAC[i]->Text = str;
  170.                 sprintf( str, "%X", m_sTxPwr2400M.OFDMTxPWR[i] );
  171.                 edtOFDMCHDAC[i]->Text = str;
  172.             }
  173.         }
  174.     }
  175. }
  176. //---------------------------------------------------------------------------
  177. bool  TfrmWiFiEEPROM::CheckFields( void )
  178. {
  179.     AnsiString text;
  180.     unsigned char ucdata;
  181.     unsigned short usdata;
  182.     unsigned int uidata;
  183.     int i;
  184.     if( 0 == btnWGI->Tag ) // Dec
  185.     {
  186.         // General information
  187.         text = edtBBChipID->Text;  if( !IsValidDecWiFiBBChipID( text, usdata ) )         {  edtBBChipIDCheck(edtBBChipID);   return false;   }
  188.         m_sEEGeneral.usBBChipID = usdata;
  189.         text = edtRFChipID->Text;  if( !IsValidDecWiFiRFChipID( text, usdata ) )         {  edtRFChipIDCheck(edtRFChipID);   return false;   }
  190.         m_sEEGeneral.usRFChipID = usdata;
  191.         text = edtSN->Text;  if( !IsValidDecWiFiSN( text, uidata ) )                     {  edtSNCheck(edtSN);   return false;   }
  192.         m_sEEGeneral.uiSN = uidata;
  193.         for( i=0; i<sizeof(m_sEEGeneral.sMACAddr.mac_addr)/sizeof(m_sEEGeneral.sMACAddr.mac_addr[0]); i++ )
  194.         {
  195.             text = edtMACAddr[i]->Text;  if( !IsValidDecWiFiMACAddress( text, ucdata ) )                     {  edtMACAddrCheck(edtMACAddr[i]);   return false;   }
  196.             m_sEEGeneral.sMACAddr.mac_addr[i] = ucdata;
  197.         }
  198.     }
  199.     else  // Hex
  200.     {
  201.         // General information
  202.         text = edtBBChipID->Text;  if( !IsValidHexWiFiBBChipID( text, usdata ) )         {  edtBBChipIDCheck(edtBBChipID);   return false;   }
  203.         m_sEEGeneral.usBBChipID = usdata;
  204.         text = edtRFChipID->Text;  if( !IsValidHexWiFiRFChipID( text, usdata ) )         {  edtRFChipIDCheck(edtRFChipID);   return false;   }
  205.         m_sEEGeneral.usRFChipID = usdata;
  206.         text = edtSN->Text;  if( !IsValidHexWiFiSN( text, uidata ) )                     {  edtSNCheck(edtSN);   return false;   }
  207.         m_sEEGeneral.uiSN = uidata;
  208.         for( i=0; i<sizeof(m_sEEGeneral.sMACAddr.mac_addr)/sizeof(m_sEEGeneral.sMACAddr.mac_addr[0]); i++ )
  209.         {
  210.             text = edtMACAddr[i]->Text;  if( !IsValidHexWiFiMACAddress( text, ucdata ) )                     {  edtMACAddrCheck(edtMACAddr[i]);   return false;   }
  211.             m_sEEGeneral.sMACAddr.mac_addr[i] = ucdata;
  212.         }
  213.     }
  214.     return true;
  215. }
  216. //---------------------------------------------------------------------------
  217. void  TfrmWiFiEEPROM::CurrentPageReset( void )
  218. {
  219.     // WiFi general information
  220.     btnWGI->Enabled = true;
  221.     edtBBChipID->Enabled = true;
  222.     edtRFChipID->Enabled = true;
  223.     edtSN->Enabled = true;
  224.     for(int i=0; i<sizeof(m_sEEGeneral.sMACAddr.mac_addr)/sizeof(m_sEEGeneral.sMACAddr.mac_addr[0]); i++ )
  225.     {
  226.         edtMACAddr[i]->Enabled = true;
  227.     }
  228.     // TX DC offset
  229.     btnTXDC->Enabled = true;
  230.     // 2.4G TX power table
  231.     btn2400MTXP->Enabled = true;
  232.     btnUploadFromEEPROM->Enabled = true;
  233.     btnDownloadToEEPROM->Enabled = true;
  234.     btnLoadFromFile->Enabled = true;
  235.     btnSaveToFile->Enabled = true;
  236. }
  237. //---------------------------------------------------------------------------
  238. void  TfrmWiFiEEPROM::CurrentPageLock( void )
  239. {
  240.     // WiFi general information
  241.     btnWGI->Enabled = false;
  242.     edtBBChipID->Enabled = false;
  243.     edtRFChipID->Enabled = false;
  244.     edtSN->Enabled = false;
  245.     for(int i=0; i<sizeof(m_sEEGeneral.sMACAddr.mac_addr)/sizeof(m_sEEGeneral.sMACAddr.mac_addr[0]); i++ )
  246.     {
  247.         edtMACAddr[i]->Enabled = false;
  248.     }    
  249.     // TX DC offset
  250.     btnTXDC->Enabled = false;
  251.     // 2.4G TX power table
  252.     btn2400MTXP->Enabled = false;
  253.     btnUploadFromEEPROM->Enabled = false;
  254.     btnDownloadToEEPROM->Enabled = false;
  255.     btnLoadFromFile->Enabled = false;
  256.     btnSaveToFile->Enabled = false;
  257. }
  258. //--------------------------------------------------------------------------
  259. void  TfrmWiFiEEPROM::ShowHintLabel( TControl *sender, char* hint )
  260. {
  261.    TPoint pt0 = this->ClientOrigin;
  262.    TPoint pt1 = sender->ClientOrigin;
  263.    lblHint->Left = (pt1.x-pt0.x);
  264.    lblHint->Top  = (pt1.y-pt0.y)+sender->Height+3;
  265.    lblHint->Caption = hint;
  266.    lblHint->Visible = true;
  267.    HintTimer->Enabled = true;
  268. }
  269. //---------------------------------------------------------------------------
  270. void __fastcall TfrmWiFiEEPROM::btnWGIClick(TObject *Sender)
  271. {
  272.     if( 0 == btnWGI->Tag )  // Dec-->Hex
  273.     {   btnWGI->Tag = 1;
  274.     }
  275.     else  //Hex-->Dec
  276.     {   btnWGI->Tag = 0;
  277.     }
  278.     ReDrawFields( PNLIDX_WGI );
  279. }
  280. //---------------------------------------------------------------------------
  281. void __fastcall TfrmWiFiEEPROM::btnTXDCClick(TObject *Sender)
  282. {
  283.     if( 0 == btnTXDC->Tag )  // Dec-->Hex
  284.     {   btnTXDC->Tag = 1;
  285.     }
  286.     else  //Hex-->Dec
  287.     {   btnTXDC->Tag = 0;
  288.     }
  289.     ReDrawFields( PNLIDX_TXDC );
  290. }
  291. //---------------------------------------------------------------------------
  292. void __fastcall TfrmWiFiEEPROM::btn2400MTXPClick(TObject *Sender)
  293. {
  294.     if( 0 == btn2400MTXP->Tag )  // Dec-->Hex
  295.     {   btn2400MTXP->Tag = 1;
  296.     }
  297.     else  //Hex-->Dec
  298.     {   btn2400MTXP->Tag = 0;
  299.     }
  300.     ReDrawFields( PNLIDX_2400MTXP );
  301. }
  302. //---------------------------------------------------------------------------
  303. void __fastcall TfrmWiFiEEPROM::edtBBChipIDCheck(TObject *Sender)
  304. {
  305.     AnsiString  text;
  306.     unsigned short  usdata;
  307.     TEdit *edit = (TEdit*)Sender;
  308.     char  hint[] = " value shall be 0~65535 ";
  309.     text = edit->Text;
  310.     if( 0 == btnWGI->Tag ) // Dec
  311.     {
  312.         if( !IsValidDecWiFiBBChipID( text, usdata ) )
  313.         {
  314.             ShowHintLabel( edit, hint );
  315.             edit->SetFocus();
  316.             return;
  317.         }
  318.     }
  319.     else
  320.     {
  321.         if( !IsValidHexWiFiBBChipID( text, usdata ) )
  322.         {
  323.             ShowHintLabel( edit, hint );
  324.             edit->SetFocus();
  325.             return;
  326.         }
  327.     }
  328.     m_sEEGeneral.usBBChipID = usdata;
  329. }
  330. //---------------------------------------------------------------------------
  331. void __fastcall TfrmWiFiEEPROM::edtRFChipIDCheck(TObject *Sender)
  332. {
  333.     AnsiString  text;
  334.     unsigned short  usdata;
  335.     TEdit *edit = (TEdit*)Sender;
  336.     char  hint[] = " value shall be 0~65535 ";
  337.     text = edit->Text;
  338.     if( 0 == btnWGI->Tag ) // Dec
  339.     {
  340.         if( !IsValidDecWiFiRFChipID( text, usdata ) )
  341.         {
  342.             ShowHintLabel( edit, hint );
  343.             edit->SetFocus();
  344.             return;
  345.         }
  346.     }
  347.     else
  348.     {
  349.         if( !IsValidHexWiFiRFChipID( text, usdata ) )
  350.         {
  351.             ShowHintLabel( edit, hint );
  352.             edit->SetFocus();
  353.             return;
  354.         }
  355.     }
  356.     m_sEEGeneral.usRFChipID = usdata;
  357. }
  358. //---------------------------------------------------------------------------
  359. void __fastcall TfrmWiFiEEPROM::edtSNCheck(TObject *Sender)
  360. {
  361.     AnsiString  text;
  362.     unsigned int  uidata;
  363.     TEdit *edit = (TEdit*)Sender;
  364.     char  hint[] = " value shall be 0~0xFFFFFFFF ";
  365.     text = edit->Text;
  366.     if( 0 == btnWGI->Tag ) // Dec
  367.     {
  368.         if( !IsValidDecWiFiSN( text, uidata ) )
  369.         {
  370.             ShowHintLabel( edit, hint );
  371.             edit->SetFocus();
  372.             return;
  373.         }
  374.     }
  375.     else
  376.     {
  377.         if( !IsValidHexWiFiSN( text, uidata ) )
  378.         {
  379.             ShowHintLabel( edit, hint );
  380.             edit->SetFocus();
  381.             return;
  382.         }
  383.     }
  384.     m_sEEGeneral.uiSN = uidata;
  385. }
  386. //---------------------------------------------------------------------------
  387. void __fastcall TfrmWiFiEEPROM::edtMACAddrCheck(TObject *Sender)
  388. {
  389.     AnsiString  text;
  390.     unsigned char  mac_addr_char;
  391.     TEdit *edit = (TEdit*)Sender;
  392.     char  hint[] = " value shall be 0x00~0xFF ";
  393.     text = edit->Text;
  394.     
  395.     if( 0 == btnWGI->Tag ) // Dec
  396.     {
  397.         if( !IsValidDecWiFiMACAddress( text, mac_addr_char ) )
  398.         {
  399.             ShowHintLabel( edit, hint );
  400.             edit->SetFocus();
  401.             return;
  402.         }
  403.     }
  404.     else
  405.     {
  406.         if( !IsValidHexWiFiMACAddress( text, mac_addr_char ) )
  407.         {
  408.             ShowHintLabel( edit, hint );
  409.             edit->SetFocus();
  410.             return;
  411.         }
  412.     }
  413.     m_sEEGeneral.sMACAddr.mac_addr[edit->Tag] = mac_addr_char;
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TfrmWiFiEEPROM::btnUploadFromEEPROMClick(TObject *Sender)
  417. {
  418.     m_sEE.count          = WIFI_EE_LEN_BB_CHIP_ID   +
  419.                          WIFI_EE_LEN_RF_CHIP_ID   +
  420.                          WIFI_EE_LEN_SN           +
  421.                          WIFI_EE_LEN_MAC_ADDR     +
  422.                          WIFI_EE_LEN_RESERVED0    +
  423.                          WIFI_EE_LEN_TX_IQ        +
  424.                          WIFI_EE_LEN_RESERVED1    +
  425.                          WIFI_EE_LEN_RESERVED2    +
  426.                          WIFI_EE_LEN_CHECKSUM     +
  427.                          WIFI_EE_LEN_TXP_2_4_G;
  428.                          
  429.     for (unsigned int i=0; i<m_sEE.count; i++ )
  430.     {
  431.         m_sEE.eeprom[i].index = 2*i;
  432.     }
  433.     m_WIFI_EE_Obj.ConfirmCallback = ::ConfirmCallback_ReadEE;
  434.     m_WIFI_EE_Obj.REQ_Read_From_EE_Start( m_sEE );
  435.     sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString)"  Read EEPROM progressing";
  436. }
  437. //---------------------------------------------------------------------------
  438. void TfrmWiFiEEPROM::ConfirmCallback_ReadEE( void )
  439. {
  440.     E_METAAPP_RESULT_T state = m_WIFI_EE_Obj.Get_ConfirmState();
  441.     switch (state)
  442.     {
  443.         case METAAPP_SUCCESS:
  444.         {
  445.             m_sEE = m_WIFI_EE_Obj.Get_EE();
  446.             ReDrawFields( PNLIDX_WGI | PNLIDX_TXDC | PNLIDX_2400MTXP );
  447.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString)"  Read EEPROM successfully";
  448.         }
  449.         break;
  450.         case METAAPP_FAIL:
  451.         {
  452.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString)"  Read EEPROM fail";
  453.             Application->MessageBox( "Execution Fail : Read EEPROM", "FAIL", MB_OK );
  454.         }
  455.         break;
  456.         case METAAPP_TIMEOUT:
  457.         {
  458.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString)"  Read EEPROM timeout";
  459.             Application->MessageBox( "Execution Timeout : Read EEPROM", "TIMEOUT", MB_OK );
  460.         }
  461.         break;
  462.         case METAAPP_STOP:
  463.         {
  464.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString)"  Read EEPROM stop";
  465.         }    
  466.         break;
  467.     }
  468.     CurrentPageReset();
  469. }
  470. //---------------------------------------------------------------------------
  471. void __fastcall TfrmWiFiEEPROM::btnDownloadToEEPROMClick(TObject *Sender)
  472. {
  473.    // m_sEE.eeprom_index = WIFI_EE_ADDR_BB_CHIP_ID;
  474.     m_sEE.count          = WIFI_EE_LEN_BB_CHIP_ID   +
  475.                          WIFI_EE_LEN_RF_CHIP_ID   +
  476.                          WIFI_EE_LEN_SN           +
  477.                          WIFI_EE_LEN_MAC_ADDR     +
  478.                          WIFI_EE_LEN_RESERVED0    +
  479.                          WIFI_EE_LEN_TX_IQ        +
  480.                          WIFI_EE_LEN_RESERVED1    +
  481.                          WIFI_EE_LEN_RESERVED2    +
  482.                          WIFI_EE_LEN_CHECKSUM     +
  483.                          WIFI_EE_LEN_TXP_2_4_G;
  484.     for (unsigned int i=0; i<m_sEE.count; i++)
  485.     {
  486.         m_sEE.eeprom[i].index = 2*i;
  487.     }
  488.     m_sEEGeneral.ucChecksum = m_WIFI_EE_Obj.Calculate_Checksum( m_sEEGeneral );
  489.     Compose_EEPROM_Data();
  490.     m_WIFI_EE_Obj.ConfirmCallback = ::ConfirmCallback_WriteEE;
  491.     m_WIFI_EE_Obj.REQ_Write_To_EE_Start( m_sEE );
  492.     sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString)"  Write EEPROM progressing";
  493. }
  494. //---------------------------------------------------------------------------
  495. void TfrmWiFiEEPROM::ConfirmCallback_WriteEE( void )
  496. {
  497.     E_METAAPP_RESULT_T state = m_WIFI_EE_Obj.Get_ConfirmState();
  498.     switch( state )
  499.     {
  500.         case METAAPP_SUCCESS:
  501.         {
  502.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString)"  Write EEPROM successfully";
  503.         }
  504.         break;
  505.         case METAAPP_FAIL:
  506.         {
  507.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString)"  Write EEPROM fail";
  508.             Application->MessageBox( "Execution Timeout : Write EEPROM", "FAIL", MB_OK );
  509.         }
  510.         break;
  511.         case METAAPP_TIMEOUT:
  512.         {
  513.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString)"  Write EEPROM timeout";
  514.             Application->MessageBox( "Execution Timeout : Write EEPROM", "TIMEOUT", MB_OK );
  515.         }
  516.         break;
  517.         case METAAPP_STOP:
  518.         {
  519.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString)"  Write EEPROM stop";
  520.         }    
  521.         break;
  522.     }
  523.     CurrentPageReset();
  524. }
  525. //---------------------------------------------------------------------------
  526. void __fastcall TfrmWiFiEEPROM::btnLoadFromFileClick(TObject *Sender)
  527. {
  528.     char str[512];
  529.     bool ok;
  530.     float  fdata;
  531.     ok = OpenDialog->Execute();
  532.     if( !ok )
  533.     {
  534.         sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString) "  Load WiFi EEPROM setting from file fail";
  535.         return;
  536.     }
  537.     strcpy( str, OpenDialog->FileName.c_str() );
  538.     // General information
  539.     //if( cbWGIHeader->Checked )
  540.     {
  541.         ok = m_WIFI_EE_Obj.REQ_Read_General_Info_From_File( str );
  542.         if( !ok )
  543.         {
  544.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString) "  Load WiFi EEPROM setting from file fail";
  545.             Application->MessageBox( "Execution Failure : Load WiFi EEPROM setting from file", "FAILURE", MB_OK );
  546.             return;
  547.         }
  548.         m_sEEGeneral = m_WIFI_EE_Obj.Get_EEGeneral();
  549.     }
  550.     ReDrawFields( PNLIDX_WGI | PNLIDX_TXDC | PNLIDX_2400MTXP );
  551.     sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString) "  Load WiFi TX setting from file successfully";
  552. }
  553. //---------------------------------------------------------------------------
  554. void __fastcall TfrmWiFiEEPROM::btnSaveToFileClick(TObject *Sender)
  555. {
  556.    char str[512];
  557.     bool ok;
  558.     ok = SaveDialog->Execute();
  559.     if( !ok )
  560.     {
  561.         sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString) "  Save WiFi EEPROM setting to file fail";
  562.         return;
  563.     }
  564.     if( ! CheckFields() )
  565.     {
  566.         sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString) "  Save WiFi EEPROM setting to file fail";
  567.         return;
  568.     }
  569.     strcpy( str, SaveDialog->FileName.c_str() );
  570.     /// General information
  571.    // if( cbWGIHeader->Checked )
  572.     {
  573.         m_WIFI_EE_Obj.Set_EEGeneral( m_sEEGeneral );
  574.         ok = m_WIFI_EE_Obj.REQ_Write_General_Info_To_File( str );
  575.         if( !ok )
  576.         {
  577.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString) "  Save WiFi EEPROM setting to file fail";
  578.             Application->MessageBox( "Execution Failure : Save WiFi EEPROM setting to file", "FAILURE", MB_OK );
  579.             return;
  580.         }
  581.     }
  582.     // TX DC offset
  583.    // if( cbTXDCHeader->Checked )
  584.     {
  585.         m_WIFI_EE_Obj.Set_TxDcOffset( m_sEEGeneral.sTxDcOffset );
  586.         ok = m_WIFI_EE_Obj.REQ_Write_TX_DC_Offset_To_File( str );
  587.         if( !ok )
  588.         {
  589.             sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString) "  Save WiFi EEPROM setting to file fail";
  590.             Application->MessageBox( "Execution Failure : Save WiFi EEPROM setting to file", "FAILURE", MB_OK );
  591.             return;
  592.         }
  593.     }
  594.     // 2.4G TX power table
  595.    // if( cb2400MTXPHeader->Checked )
  596.     {
  597.         if( m_sWiFiCap.support_802_11g || m_sWiFiCap.support_802_11b )
  598.         {
  599.             m_WIFI_EE_Obj.Set_TxChannelDac2400M( m_sTxPwr2400M );
  600.             ok = m_WIFI_EE_Obj.REQ_Write_TxPower2400M_To_File( str );
  601.             if( !ok )
  602.             {
  603.                 sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString) "  Save WiFi EEPROM setting to file fail";
  604.                 Application->MessageBox( "Execution Failure : Save WiFi EEPROM setting to file", "FAILURE", MB_OK );
  605.                 return;
  606.             }
  607.         }
  608.     }
  609.     sbWiFiEEPROM->Panels->Items[0]->Text = (AnsiString) "  Save WiFi EEPROM setting to file successfully";
  610. }
  611. //---------------------------------------------------------------------------
  612. void __fastcall TfrmWiFiEEPROM::HintTimerTimer(TObject *Sender)
  613. {
  614.     HintTimer->Enabled = false;
  615.     lblHint->Visible = false;
  616. }
  617. //---------------------------------------------------------------------------
  618. void TfrmWiFiEEPROM::Compose_EEPROM_Data( void )
  619. {
  620.     // BB chip ID
  621.     m_sEE.eeprom[WIFI_EE_ADDR_BB_CHIP_ID].eeprom_data16   = m_sEEGeneral.usBBChipID;
  622.     // RF chip ID
  623.     m_sEE.eeprom[WIFI_EE_ADDR_RF_CHIP_ID].eeprom_data16   = m_sEEGeneral.usRFChipID;
  624.     // SN
  625.     m_sEE.eeprom[WIFI_EE_ADDR_SN].eeprom_data16           = m_sEEGeneral.uiSN       & 0x0000FFFF;
  626.     m_sEE.eeprom[WIFI_EE_ADDR_SN+1].eeprom_data16         = m_sEEGeneral.uiSN       & 0xFFFF0000 >> 16;
  627.     // MAC address
  628.     for( int i=0; i< sizeof(m_sEEGeneral.sMACAddr.mac_addr)/sizeof(m_sEEGeneral.sMACAddr.mac_addr[0]); i=i+2 )
  629.     {
  630.         m_sEE.eeprom[WIFI_EE_ADDR_MAC_ADDR+i/2].eeprom_data16     = m_sEEGeneral.sMACAddr.mac_addr[i] | (m_sEEGeneral.sMACAddr.mac_addr[i+1]<<8);
  631.     }
  632.     // reserved 0
  633.     m_sEE.eeprom[WIFI_EE_ADDR_RESERVED0].eeprom_data16   = m_sEEGeneral.usReserved0;
  634.     // TX DC offset
  635.     m_sEE.eeprom[WIFI_EE_ADDR_TX_IQ].eeprom_data16       = m_sEEGeneral.sTxDcOffset.q_ch_offset;
  636.     m_sEE.eeprom[WIFI_EE_ADDR_TX_IQ].eeprom_data16       = (m_sEE.eeprom[WIFI_EE_ADDR_TX_IQ].eeprom_data16 << 8) |
  637.                                                             m_sEEGeneral.sTxDcOffset.i_ch_offset;
  638.     // reserved 1
  639.     m_sEE.eeprom[WIFI_EE_ADDR_RESERVED1].eeprom_data16   = m_sEEGeneral.usReserved1;
  640.     // checksum
  641.     m_sEE.eeprom[WIFI_EE_ADDR_CHECKSUM].eeprom_data16    = m_sEEGeneral.ucChecksum;
  642.     m_sEE.eeprom[WIFI_EE_ADDR_CHECKSUM].eeprom_data16    = (m_sEE.eeprom[WIFI_EE_ADDR_CHECKSUM].eeprom_data16 << 8) |
  643.                                                            m_sEEGeneral.ucReserved2;
  644.     // reserved 3
  645.     m_sEE.eeprom[WIFI_EE_ADDR_RESERVED3].eeprom_data16   = m_usReserved3;
  646. }
  647. //---------------------------------------------------------------------------
  648. void TfrmWiFiEEPROM::DeCompose_EEPROM_Data( void )
  649. {
  650.     int i, j;
  651.     // WiFi general information
  652.     // BB chip ID
  653.     m_sEEGeneral.usBBChipID = m_sEE.eeprom[WIFI_EE_ADDR_BB_CHIP_ID].eeprom_data16;
  654.     // RF chip ID
  655.     m_sEEGeneral.usRFChipID = m_sEE.eeprom[WIFI_EE_ADDR_RF_CHIP_ID].eeprom_data16;
  656.     // SN
  657.     m_sEEGeneral.uiSN       = (m_sEE.eeprom[WIFI_EE_ADDR_SN+1].eeprom_data16<<16)  |
  658.                                m_sEE.eeprom[WIFI_EE_ADDR_SN].eeprom_data16;
  659.     // MAC address
  660.     for( i=0; i< sizeof(m_sEEGeneral.sMACAddr.mac_addr)/sizeof(m_sEEGeneral.sMACAddr.mac_addr[0]); i++ )
  661.     {
  662.         if( 0 == i % 2 )
  663.         {
  664.             m_sEEGeneral.sMACAddr.mac_addr[i] = m_sEE.eeprom[WIFI_EE_ADDR_MAC_ADDR+i/2].eeprom_data16 & 0x00FF;
  665.         }
  666.         else
  667.         {   m_sEEGeneral.sMACAddr.mac_addr[i] = (m_sEE.eeprom[WIFI_EE_ADDR_MAC_ADDR+i/2].eeprom_data16 & 0xFF00) >> 8;
  668.         }
  669.     }
  670.     // reserve 0
  671.     m_sEEGeneral.usReserved0 = m_sEE.eeprom[WIFI_EE_ADDR_RESERVED0].eeprom_data16;
  672.     // TX IQ offset
  673.     m_sEEGeneral.sTxDcOffset.q_ch_offset = (m_sEE.eeprom[WIFI_EE_ADDR_TX_IQ].eeprom_data16&0xFF00)>>8;
  674.     m_sEEGeneral.sTxDcOffset.i_ch_offset = m_sEE.eeprom[WIFI_EE_ADDR_TX_IQ].eeprom_data16&0x00FF;
  675.     // reserved 1
  676.     m_sEEGeneral.usReserved1 = m_sEE.eeprom[WIFI_EE_ADDR_RESERVED1].eeprom_data16;
  677.     // reserved 2
  678.     m_sEEGeneral.ucReserved2    = m_sEE.eeprom[WIFI_EE_ADDR_CHECKSUM].eeprom_data16 & 0xFF00;
  679.     // checksum
  680.     m_sEEGeneral.ucChecksum = (m_sEE.eeprom[WIFI_EE_ADDR_CHECKSUM].eeprom_data16>>8) & 0x00FF;
  681.     // reserved 3
  682.     m_usReserved3 = m_sEE.eeprom[WIFI_EE_ADDR_RESERVED3].eeprom_data16;
  683.     // 2.4G TX power table
  684.     for( i=0; i<NUM_TX_POWER_2400M_CH; i++ )
  685.     {
  686.         m_sTxPwr2400M.CCKTxPWR[i] = m_sEE.eeprom[i].eeprom_data16;
  687.     }
  688. }