// tdebugDlg.cpp : implementation file
//
#include "stdafx.h"
#include "tdebug.h"
#include "tdebugDlg.h"
#include "usbprt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/global pointer to a file/
FILE *pf;
struct g_variables_functions{
int cnt;
unsigned long addr[2000];
unsigned long len[2000];
char name[2000][100];
unsigned value[2000];
} g_v,g_f;
union type_change{
unsigned char byte[8];
unsigned char us_char;
char s_char;
unsigned __int16 us_short;
__int16 s_short;
unsigned __int32 us_long;
__int32 s_long;
unsigned __int64 us_long_long;
__int64 s_long_long;
float s_float;
} g_type;
/
// CTdebugDlg dialog
CTdebugDlg::CTdebugDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTdebugDlg::IDD, pParent)
{
//{ {AFX_DATA_INIT(CTdebugDlg)
m_auto_detect = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTdebugDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{ {AFX_DATA_MAP(CTdebugDlg)
DDX_Control(pDX, IDC_BUTTON10, m_btn_step);
DDX_Control(pDX, IDC_BUTTON9, m_btn_docmd);
DDX_Control(pDX, IDC_EDIT4, m_edit_tcdbcmd);
DDX_Control(pDX, IDC_COMBO3, m_comb_device);
DDX_Control(pDX, IDC_COMBO2, m_comb_type);
DDX_Control(pDX, IDC_COMBO1, m_comb_bus);
DDX_Control(pDX, IDC_CHECK2, m_check2);
DDX_Control(pDX, IDC_USB, m_btn_usb);
DDX_Control(pDX, IDC_BUTTON8, m_btn_clrbk);
DDX_Control(pDX, IDC_BUTTON7, m_btn_clr);
DDX_Control(pDX, IDC_CHECK4, m_check_tcpc);
DDX_Control(pDX, IDC_CHECK3, m_bk_check);
DDX_Control(pDX, IDC_STATIC_CFG, m_bd_cfg);
DDX_Control(pDX, IDC_CHECK1, m_check1);
DDX_Control(pDX, IDC_BUTTON5, m_btn_stop);
DDX_Control(pDX, IDC_BUTTON6, m_btn_run);
DDX_Control(pDX, IDC_BUTTON3, m_btn_rst);
DDX_Control(pDX, IDC_STATIC_INF, m_info);
DDX_Control(pDX, IDC_BUTTON4, m_btn_mode);
DDX_Control(pDX, IDC_BUTTON1, m_btn_update);
DDX_Control(pDX, IDC_STATIC3, m_static_data);
DDX_Control(pDX, IDC_STATIC2, m_static_addr);
DDX_Control(pDX, IDC_STATIC1, m_board1);
DDX_Control(pDX, IDC_EDIT3, m_edit3);
DDX_Control(pDX, IDC_EDIT2, m_edit2);
DDX_Control(pDX, IDC_EDIT1, m_edit1);
DDX_Check(pDX, IDC_CHECK2, m_auto_detect);
DDX_Control(pDX,IDC_CUSTOM1,m_grid);
//}}AFX_DATA_MAP
//DDX_Control(pDX,IDC_CUSTOM1,m_grid);
}
BEGIN_MESSAGE_MAP(CTdebugDlg, CDialog)
//{ {AFX_MSG_MAP(CTdebugDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_EN_SETFOCUS(IDC_EDIT3, OnSetfocusEdit3)
ON_EN_KILLFOCUS(IDC_EDIT2, OnKillfocusEdit2)
ON_WM_CTLCOLOR()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_BN_CLICKED(IDC_USB, OnUsb)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
//}}AFX_MSG_MAP
ON_NOTIFY(NM_CLICK, IDC_CUSTOM1, OnGridClick)
ON_NOTIFY(GVN_ENDLABELEDIT, IDC_CUSTOM1, OnGridEndEdit)
END_MESSAGE_MAP()
/
// CTdebugDlg message handlers
BOOL CTdebugDlg::OnInitDialog()
{
if(__argc >=2)
{
m_usb_id = strtol(__argv[1],NULL,16);
}
else
{
m_usb_id = 0xffff;
}
CDialog::OnInitDialog();
nFullWidth=GetSystemMetrics(SM_CXSCREEN);
nFullHeight=GetSystemMetrics(SM_CYSCREEN);
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
CFont a;
a.CreateFont( 24, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T( "宋体" ) );
m_info.SetFont(&a);
m_info.GetDC()->SetTextColor(RGB(255,0,0));
m_info.SetWindowText("device ok");
set the grid /
m_ImageList.Create(MAKEINTRESOURCE(IDB_BITMAP1), 16, 2, RGB(255,255,255));
m_grid.SetImageList(&m_ImageList); //绑定grid控件和 图片列表
// m_grid.SetEditable(true);
m_grid.SetTextBkColor(RGB(0xFF, 0xFF, 0xE0)); //黄色背景
m_grid.SetTextColor(RGB(0x00, 0x00, 0xff));
//m_grid.SetFixedTextColor(RGB(0xff, 0x00, 0x00)); //表头的字体颜色
OnUsb();
unsigned char test_buf[8];
ReadMem(m_usb_handle,0x0000,test_buf,4,1);
ReadMem(m_usb_handle,0x0000,test_buf,4,4);
m_nTextLen = 0x100000;
m_edit1.SetLimitText(m_nTextLen);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTdebugDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTdebugDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTdebugDlg::OnButton1()
{
// TODO: Add your control notification handler code here
int i,j;
unsigned long addr_start,addr_end,addr_now;
unsigned char buf[1024*32];
unsigned char *pt;
CString str;
// unsigned char buf[32];
if(grid_mode == 0)
{
// addr_start = g_v.addr[0]; //get the start of the ".bss" section
// addr_end = g_v.addr[g_v.cnt-1] + g_v.len[g_v.cnt - 1]; // the end of the ".bss" section
if(m_usb_handle == NULL)
{
//MessageBox("no usb device!!");
debug_print("no usb device!");
}
else if(bss_end < bss_end)
{
//MessageBox("start addr is bigger than end addr!");
debug_print("start addr is bigger than end addr!");
}
else
{
ReadMem(m_usb_handle,bss_start,buf,bss_end-bss_start,device_type);
/*
addr_now = addr_start;
pt = buf;
i = 0;
do
{
if(addr_now == g_v.addr[i])
{
for(j=0;j<8;j++){
g_type.byte[j] = pt[j];
}
pt = pt + g_v.len[i];
addr_now = addr_now + g_v.len[i];
if(g_v.len[i] == 1)
str.Format("0x%02x",g_type.us_char);
else if(g_v.len[i] == 2)
str.Format("0x%04x",g_type.us_short);
else if(g_v.len[i] == 4)
str.Format("0x%08x",g_type.us_long);
else if(g_v.len[i] > 4)
{
//str.Format("click to get value");
str.Format("");
m_grid.SetItemImage(i+1,3,5);
}
//str.Format("0x%02x%02x%02x%02x",g_type.byte[3],g_type.byte[2],g_type.byte[1],g_type.byte[0]);
//set the m_grid///
m_grid.SetItemText(i+1,3,str);
//end of m_grid ///
i++;
}
else
{
pt++;
addr_now++;
}*/
for(i =0;i<g_v.cnt;i++)
{
for(j=0;j<8;j++){
addr_start = g_v.addr[i] - bss_start;
g_type.byte[j] = buf[j+addr_start];
}
if(g_v.len[i] == 1)
str.Format("0x%02x",g_type.us_char);
else if(g_v.len[i] == 2)
str.Format("0x%04x",g_type.us_short);
else if(g_v.len[i] == 4)
str.Format("0x%08x",g_type.us_long);
else if(g_v.len[i] > 4)
{
//str.Format("click to get value");
str.Format("");
m_grid.SetItemImage(i+1,3,5);
}
//str.Format("0x%02x%02x%02x%02x",g_type.byte[3],g_type.byte[2],g_type.byte[1],g_type.byte[0]);
//set the m_grid///
if(g_v.len[i] != 0)
m_grid.SetItemText(i+1,3,str);
else
{
m_grid.SetItemText(i+1,3,"len=0");
m_grid.SetItemImage(i+1,3,7);
}
//end of m_grid ///
//m_grid.AutoSize();
}
m_grid.Refresh();
}
}
else
{
//MessageBox("must set variables mode");
debug_print("must set variable mode");
}
}
// write the memory.
void CTdebugDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CWnd *pwnd=GetDlgItem(IDC_EDIT4);
if(GetFocus()==pwnd)
{
// MessageBox("test");
OnButton9();
}
else
{
CString str;
CString tcdb_str;
unsigned char buf[4];
long addr;
unsigned long value;
int i;
int byte_length;
CString str_device;
if(m_comb_type.GetCurSel() == 0)
{
byte_length=1;
}
else if(m_comb_type.GetCurSel() == 1)
{
byte_length=2;
}
else
{
byte_length=4;
}
//if(m_comb_device.GetCurSel()==0)
if(device_type == 4)
{
str_device="";
}
else
{
str_device="-u";
}
m_edit2.GetWindowText(str);
addr = strtol(str,NULL,16);
m_edit3.GetWindowText(str);
value = strtol(str,NULL,16);
if(strcmp(str,"") != 0)
{
//buf[0] = value;
switch(m_comb_bus.GetCurSel())
{
case 0:
for(i=0;i<byte_length;i++)
{
buf[i] = value&0xff;
value=value>>8;
}
WriteMem(m_usb_handle,addr,buf,byte_length,device_type);
break;
/* case 1:
str.Format("wa %04x %04x %s",addr,value,str_device);
tcdb_cmd(str);
break;*/
case 1:
str.Format("wf %04x %04x %s",addr,value,str_device);
tcdb_cmd(str);
break;
default:
break;
}
}
str.Format("## write %04x",addr);
debug_print(str);
}
}
void CTdebugDlg::debug_print(CString str)
{
#if 0
CString str_text;
int cnt,i;
char cstr[1000];
//char temp_buff[64*1024];
int nLength;
/*
m_edit1.GetWindowText(str_text);
nLength = m_edit1.GetWindowTextLength();
cnt = m_edit1.GetLineCount();
if(cnt >= 180)
{
m_edit1.GetLine(cnt-180,cstr,1000);
str_text = str_text.Right(str_text.GetLength() - strlen(cstr));
}
m_edit1.SetSel(nLength, 0);
m_edit1.ReplaceSel(str_text); */
m_edit1.GetWindowText(str_text);
str_text += str;
//str_text += "\r\n";
m_edit1.SetWindowText(str_text);
//nLength = m_edit1.GetWindowTextLength();
//m_edit1.SetSel(nLength, nLength);
//m_edit1.ReplaceSel(str_text);
for(i=0;i<100;i++)
cstr[i]=0;
// m_edit1.GetWindowText(str_text);
// str_text=str_text+"\r\n"+str;
// m_edit1.SetWindowText(str_text);
//
#include "stdafx.h"
#include "tdebug.h"
#include "tdebugDlg.h"
#include "usbprt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/global pointer to a file/
FILE *pf;
struct g_variables_functions{
int cnt;
unsigned long addr[2000];
unsigned long len[2000];
char name[2000][100];
unsigned value[2000];
} g_v,g_f;
union type_change{
unsigned char byte[8];
unsigned char us_char;
char s_char;
unsigned __int16 us_short;
__int16 s_short;
unsigned __int32 us_long;
__int32 s_long;
unsigned __int64 us_long_long;
__int64 s_long_long;
float s_float;
} g_type;
/
// CTdebugDlg dialog
CTdebugDlg::CTdebugDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTdebugDlg::IDD, pParent)
{
//{ {AFX_DATA_INIT(CTdebugDlg)
m_auto_detect = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTdebugDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{ {AFX_DATA_MAP(CTdebugDlg)
DDX_Control(pDX, IDC_BUTTON10, m_btn_step);
DDX_Control(pDX, IDC_BUTTON9, m_btn_docmd);
DDX_Control(pDX, IDC_EDIT4, m_edit_tcdbcmd);
DDX_Control(pDX, IDC_COMBO3, m_comb_device);
DDX_Control(pDX, IDC_COMBO2, m_comb_type);
DDX_Control(pDX, IDC_COMBO1, m_comb_bus);
DDX_Control(pDX, IDC_CHECK2, m_check2);
DDX_Control(pDX, IDC_USB, m_btn_usb);
DDX_Control(pDX, IDC_BUTTON8, m_btn_clrbk);
DDX_Control(pDX, IDC_BUTTON7, m_btn_clr);
DDX_Control(pDX, IDC_CHECK4, m_check_tcpc);
DDX_Control(pDX, IDC_CHECK3, m_bk_check);
DDX_Control(pDX, IDC_STATIC_CFG, m_bd_cfg);
DDX_Control(pDX, IDC_CHECK1, m_check1);
DDX_Control(pDX, IDC_BUTTON5, m_btn_stop);
DDX_Control(pDX, IDC_BUTTON6, m_btn_run);
DDX_Control(pDX, IDC_BUTTON3, m_btn_rst);
DDX_Control(pDX, IDC_STATIC_INF, m_info);
DDX_Control(pDX, IDC_BUTTON4, m_btn_mode);
DDX_Control(pDX, IDC_BUTTON1, m_btn_update);
DDX_Control(pDX, IDC_STATIC3, m_static_data);
DDX_Control(pDX, IDC_STATIC2, m_static_addr);
DDX_Control(pDX, IDC_STATIC1, m_board1);
DDX_Control(pDX, IDC_EDIT3, m_edit3);
DDX_Control(pDX, IDC_EDIT2, m_edit2);
DDX_Control(pDX, IDC_EDIT1, m_edit1);
DDX_Check(pDX, IDC_CHECK2, m_auto_detect);
DDX_Control(pDX,IDC_CUSTOM1,m_grid);
//}}AFX_DATA_MAP
//DDX_Control(pDX,IDC_CUSTOM1,m_grid);
}
BEGIN_MESSAGE_MAP(CTdebugDlg, CDialog)
//{ {AFX_MSG_MAP(CTdebugDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_EN_SETFOCUS(IDC_EDIT3, OnSetfocusEdit3)
ON_EN_KILLFOCUS(IDC_EDIT2, OnKillfocusEdit2)
ON_WM_CTLCOLOR()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_BN_CLICKED(IDC_USB, OnUsb)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
ON_BN_CLICKED(IDC_BUTTON10, OnButton10)
//}}AFX_MSG_MAP
ON_NOTIFY(NM_CLICK, IDC_CUSTOM1, OnGridClick)
ON_NOTIFY(GVN_ENDLABELEDIT, IDC_CUSTOM1, OnGridEndEdit)
END_MESSAGE_MAP()
/
// CTdebugDlg message handlers
BOOL CTdebugDlg::OnInitDialog()
{
if(__argc >=2)
{
m_usb_id = strtol(__argv[1],NULL,16);
}
else
{
m_usb_id = 0xffff;
}
CDialog::OnInitDialog();
nFullWidth=GetSystemMetrics(SM_CXSCREEN);
nFullHeight=GetSystemMetrics(SM_CYSCREEN);
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
CFont a;
a.CreateFont( 24, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T( "宋体" ) );
m_info.SetFont(&a);
m_info.GetDC()->SetTextColor(RGB(255,0,0));
m_info.SetWindowText("device ok");
set the grid /
m_ImageList.Create(MAKEINTRESOURCE(IDB_BITMAP1), 16, 2, RGB(255,255,255));
m_grid.SetImageList(&m_ImageList); //绑定grid控件和 图片列表
// m_grid.SetEditable(true);
m_grid.SetTextBkColor(RGB(0xFF, 0xFF, 0xE0)); //黄色背景
m_grid.SetTextColor(RGB(0x00, 0x00, 0xff));
//m_grid.SetFixedTextColor(RGB(0xff, 0x00, 0x00)); //表头的字体颜色
OnUsb();
unsigned char test_buf[8];
ReadMem(m_usb_handle,0x0000,test_buf,4,1);
ReadMem(m_usb_handle,0x0000,test_buf,4,4);
m_nTextLen = 0x100000;
m_edit1.SetLimitText(m_nTextLen);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTdebugDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTdebugDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTdebugDlg::OnButton1()
{
// TODO: Add your control notification handler code here
int i,j;
unsigned long addr_start,addr_end,addr_now;
unsigned char buf[1024*32];
unsigned char *pt;
CString str;
// unsigned char buf[32];
if(grid_mode == 0)
{
// addr_start = g_v.addr[0]; //get the start of the ".bss" section
// addr_end = g_v.addr[g_v.cnt-1] + g_v.len[g_v.cnt - 1]; // the end of the ".bss" section
if(m_usb_handle == NULL)
{
//MessageBox("no usb device!!");
debug_print("no usb device!");
}
else if(bss_end < bss_end)
{
//MessageBox("start addr is bigger than end addr!");
debug_print("start addr is bigger than end addr!");
}
else
{
ReadMem(m_usb_handle,bss_start,buf,bss_end-bss_start,device_type);
/*
addr_now = addr_start;
pt = buf;
i = 0;
do
{
if(addr_now == g_v.addr[i])
{
for(j=0;j<8;j++){
g_type.byte[j] = pt[j];
}
pt = pt + g_v.len[i];
addr_now = addr_now + g_v.len[i];
if(g_v.len[i] == 1)
str.Format("0x%02x",g_type.us_char);
else if(g_v.len[i] == 2)
str.Format("0x%04x",g_type.us_short);
else if(g_v.len[i] == 4)
str.Format("0x%08x",g_type.us_long);
else if(g_v.len[i] > 4)
{
//str.Format("click to get value");
str.Format("");
m_grid.SetItemImage(i+1,3,5);
}
//str.Format("0x%02x%02x%02x%02x",g_type.byte[3],g_type.byte[2],g_type.byte[1],g_type.byte[0]);
//set the m_grid///
m_grid.SetItemText(i+1,3,str);
//end of m_grid ///
i++;
}
else
{
pt++;
addr_now++;
}*/
for(i =0;i<g_v.cnt;i++)
{
for(j=0;j<8;j++){
addr_start = g_v.addr[i] - bss_start;
g_type.byte[j] = buf[j+addr_start];
}
if(g_v.len[i] == 1)
str.Format("0x%02x",g_type.us_char);
else if(g_v.len[i] == 2)
str.Format("0x%04x",g_type.us_short);
else if(g_v.len[i] == 4)
str.Format("0x%08x",g_type.us_long);
else if(g_v.len[i] > 4)
{
//str.Format("click to get value");
str.Format("");
m_grid.SetItemImage(i+1,3,5);
}
//str.Format("0x%02x%02x%02x%02x",g_type.byte[3],g_type.byte[2],g_type.byte[1],g_type.byte[0]);
//set the m_grid///
if(g_v.len[i] != 0)
m_grid.SetItemText(i+1,3,str);
else
{
m_grid.SetItemText(i+1,3,"len=0");
m_grid.SetItemImage(i+1,3,7);
}
//end of m_grid ///
//m_grid.AutoSize();
}
m_grid.Refresh();
}
}
else
{
//MessageBox("must set variables mode");
debug_print("must set variable mode");
}
}
// write the memory.
void CTdebugDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CWnd *pwnd=GetDlgItem(IDC_EDIT4);
if(GetFocus()==pwnd)
{
// MessageBox("test");
OnButton9();
}
else
{
CString str;
CString tcdb_str;
unsigned char buf[4];
long addr;
unsigned long value;
int i;
int byte_length;
CString str_device;
if(m_comb_type.GetCurSel() == 0)
{
byte_length=1;
}
else if(m_comb_type.GetCurSel() == 1)
{
byte_length=2;
}
else
{
byte_length=4;
}
//if(m_comb_device.GetCurSel()==0)
if(device_type == 4)
{
str_device="";
}
else
{
str_device="-u";
}
m_edit2.GetWindowText(str);
addr = strtol(str,NULL,16);
m_edit3.GetWindowText(str);
value = strtol(str,NULL,16);
if(strcmp(str,"") != 0)
{
//buf[0] = value;
switch(m_comb_bus.GetCurSel())
{
case 0:
for(i=0;i<byte_length;i++)
{
buf[i] = value&0xff;
value=value>>8;
}
WriteMem(m_usb_handle,addr,buf,byte_length,device_type);
break;
/* case 1:
str.Format("wa %04x %04x %s",addr,value,str_device);
tcdb_cmd(str);
break;*/
case 1:
str.Format("wf %04x %04x %s",addr,value,str_device);
tcdb_cmd(str);
break;
default:
break;
}
}
str.Format("## write %04x",addr);
debug_print(str);
}
}
void CTdebugDlg::debug_print(CString str)
{
#if 0
CString str_text;
int cnt,i;
char cstr[1000];
//char temp_buff[64*1024];
int nLength;
/*
m_edit1.GetWindowText(str_text);
nLength = m_edit1.GetWindowTextLength();
cnt = m_edit1.GetLineCount();
if(cnt >= 180)
{
m_edit1.GetLine(cnt-180,cstr,1000);
str_text = str_text.Right(str_text.GetLength() - strlen(cstr));
}
m_edit1.SetSel(nLength, 0);
m_edit1.ReplaceSel(str_text); */
m_edit1.GetWindowText(str_text);
str_text += str;
//str_text += "\r\n";
m_edit1.SetWindowText(str_text);
//nLength = m_edit1.GetWindowTextLength();
//m_edit1.SetSel(nLength, nLength);
//m_edit1.ReplaceSel(str_text);
for(i=0;i<100;i++)
cstr[i]=0;
// m_edit1.GetWindowText(str_text);
// str_text=str_text+"\r\n"+str;
// m_edit1.SetWindowText(str_text);