/************************************************************************
検査シーケンサ
 *************************************************************************/

/* 多重インクルードの回避 */
#ifndef TESTSEQUENCER_H_INCLUDED
#define TESTSEQUENCER_H_INCLUDED

#include <nn.h>
#include "Config.h"
#include "TestListManager.h"
#include "TesterLog/ProductionLogViewer.h"
#include "CompositeApplicationList.h"

namespace uji{
namespace seq{

namespace drawer{
    void DrawOK();
    void DrawNG();
}

/************************************************************************
 ************************************************************************/
class TestSequencer{
  public:
      TestSequencer():m_IsNgLogEnable(false)
    {
        m_TestListManager = new TestListManager;
        m_Config = new Config;

        //検査結果制御用インスタンス作成（ずっとインスタンスを消去しません）
        if( m_TestResultManager==0 )
        {
            m_TestResultManager= new TestResultManager;
        }
    }

    ~TestSequencer()
    {
        delete m_Config;
        delete m_TestListManager;
    }
    
    void  SetCurrentTest(int id) //テストIDを設定
    {
        m_CurrentTest = id; 
    }

    void Initialize();
    void OpenMenu();
    void Execute();
    void EnableNgLog(){ m_IsNgLogEnable=true; }
    void DesableNgLog(){ m_IsNgLogEnable=false;}

    void OpenLogMenu();       // product.log
    void OpenInspectLogMenu();// inspect.log

    static uji::seq::TestResultManager  *m_TestResultManager;   //テスト結果マネージャ

    // カメラ撮影画像保存Heapメモリ用
    u8 *CAM_BUF;

  private:
    bool Execute1Sequence();
    bool SpecialHandlingFlagOnReboot();
    void ShowTesterStatus();
    void ShowInformation();
    void ShowErrorMessage();
    u32  ShowCompositeApplicationList(CompositeApplicationList* list, const s32 listNum);
    int  CalcActiveSequenceLength();
    void Draw(void);
    void AddNgLog(void);
    bool OutputTestResult(bool judge, uji::sys::TextWindow *textWindow);//IRからの検査結果出力
    
    // ShowCompositeApplicationList関数用
    void SCAL_GetProductionLogInformation(CompositeApplicationList* list, const s32 listNum);
    void SCAL_DrawDisplay0(uji::sys::GraphicsDrawing *gfx, CompositeApplicationList* list, const s32 listNum);
    void SCAL_DrawDisplay1(uji::sys::GraphicsDrawing *gfx);
    void SCAL_SetCursor1stPos(CompositeApplicationList* list, const s32 listNum);
    void SCAL_GetRemainingBatteryLv();
    void SCAL_InputKey(uji::sys::Pad& pad, const s32 listNum);

    int                 m_SequenceLength;           //シーケンスの長さ情報
    int                 m_AgingCount;               //エージング回数
    int                 m_Progress;                 //シーケンスの進行状況
    int                 m_CurrentTest;              //現在のテストを保持
    nn::os::Tick::Tick  m_StartTick;                //検査開始時のＴＩＣＫ

    uji::seq::TestListManager           *m_TestListManager;     //テストリストマネージャ
    uji::seq::Config                    *m_Config;              //コンフィグ
    uji::sys::TextWindow                *m_Window;              //表示用ウインドウ
    uji::sys::TextWindow                *m_CamWindow;              //表示用ウインドウ

    bool m_IsNgLogEnable;
    char m_SpecialNgMessage[0x80];

    //InspectLog
    void Export_InspectLog();

    //ProductLog
    void Open_LogFSMenu();
    void Export_ProductLog();
    void ExtractCpuBoard(void);

    //PortChecker
    void RunPortChecker(void);

    //通信メニュー
    void OpenCommMenu(void);
};

} // namespace seq
} // namespace uji
/* 多重インクルードの回避 */
#endif
