// XApi.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "XApi.h"
#include "XApiDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CXApiApp

BEGIN_MESSAGE_MAP(CXApiApp, CWinApp)
	//{{AFX_MSG_MAP(CXApiApp)
	//}}AFX_MSG
	ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXApiApp construction

CXApiApp::CXApiApp()
{
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CXApiApp object

CXApiApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CXApiApp initialization

CString AccToStrNoSpace (unsigned acc)
{
    int i;
    CString mStr = "";
    unsigned char dchar;

    for (i=0; i<8; ++i)
    {
        dchar=(unsigned char)(acc&0xf);
        acc >>= 4;
        if (dchar < 10)
        {
            mStr.Insert (0,dchar+'0');
        }
    }
    return mStr;
}

unsigned StrToAcc (CString AccS)
{
    unsigned acc = 0xffffffff;
    int s_len = AccS.GetLength ();
    int i;
    unsigned char dchar;

    if (s_len)
    {
        for (i=0; i<s_len; ++i)
        {
            dchar = AccS [i];
            if ((dchar >= '0') && (dchar <= '9'))
            {
                acc <<= 4;
                acc |= ((dchar - '0') & 0xf);
            }
            else
            {
                break;
            }
        }
    }
    return acc;
}

BOOL CXApiApp::InitInstance()
{

    // Initial call to library
    // Xymphony side port number can be set by "Ethernet/Basic/Companion signalling port"
    if (XAPI_Stack_initialize (Xapi_default_protocol_port))
    {
	AfxMessageBox("XAPI stack initialization failed");
	return FALSE;
    }

    CXApiDlg dlg;
    m_pMainWnd = &dlg;

    dlg.DoModal ();

    XAPI_Stack_release ();
      // final call to library before terminating program

    return FALSE;
}