16,472
社区成员
发帖
与我相关
我的任务
分享
// TODO: 在此添加控件通知处理程序代码
if(m_hTreeDeviceRoot != NULL)
m_TreeControl.DeleteItem(m_hTreeDeviceRoot);
//2014.03.05这个数据是否需要重置
m_iDeviceCount = 1;
//保存ID的下标
SaveRecvIDCount = 0;
m_hTreeDeviceRoot = m_TreeControl.InsertItem(_T("All Device List"),0,0);
//根节点添加为1 以后的慢慢添加
m_TreeControl.SetItemData(m_hTreeDeviceRoot,1);
//默认把所有的都清除掉(初始化)
//****************************************************
//这个动作在
m_Monitor1Flag=FALSE;
m_Monitor2Flag=FALSE;
m_SendRecvFlag=FALSE;
m_ReadM1PCidFlag=FALSE;
m_ReadM2PCidFlag=FALSE;
ReadArrIpFlag=FALSE;
//先全部关掉所有的复选框
SetAllCheckBox();
//再删除之前有的下拉框资源
DeleteComboxString();
PCrecvID = -1;
AddNumber = 1;
AddNewComboxItem();
AddPicture();
CWnd::Invalidate(TRUE);
m_ProGress.SetPos(0);
ProGressPos = 0;
memset(&gIP,0,sizeof(gIP));
memset(&IpType,0,sizeof(IpType));
memset(&subNet,0,sizeof(subNet));
memset(&gateway,0,sizeof(gateway));
unsigned char buff2[128];
memset(buff2,0,sizeof(buff2));
unsigned char cmd;
cmd = 0xff;
unsigned char interfaceType;
interfaceType = 0x01;
unsigned char SendBuf[64];
memset(&SendBuf,0,sizeof(SendBuf));
int SendLen = 0;
//广播也走新协议
SendLen = CreateBroadDataPackage(&SendBuf,interfaceType,cmd);
//8 - 20
//预留位置的部分是一个
CreateBroadcastSocket();
//int m=0;
sendto(m_udpSockfd, (char *)SendBuf,SendLen ,0, (struct sockaddr *)&m_BroServerAddr,sizeof(struct sockaddr));
//发送
int k = 20;
//--------------------------------------------------------------
//特别标记。初始化为0.
//m_iDeviceCount=1;
//--------------------------------------------------------------
while (k--)
{
Sleep(10);
ProGressPos += 5;
if (ProGressPos>100)
ProGressPos=100;
m_ProGress.SetPos(ProGressPos);
//返回
int add_len=sizeof(struct sockaddr);
//接受到的是一个buf
memset(buff2,0,sizeof(buff2));
//_cprintf("ready for recv\n");
int RecvCount=recvfrom(m_udpSockfd, (char *)buff2, sizeof(buff2),0, (struct sockaddr *)&m_BroClientAddr,&add_len);//接受到buf、
_cprintf("%d \n",RecvCount);
//_cprintf("the Client recv ip is:%s \n",inet_ntoa(m_BroClientAddr.sin_addr));
//先比较 头 尾 和 Length
if ((buff2[0] == 0xa5)&&(buff2[1] == 0x6c)&&(buff2[RecvCount-1] == 0xae)&&(buff2[2] == RecvCount))
{
int NameLength = 0;//
//
for (int j = 18 ; j < RecvCount - 8 ; j++)//末尾三位是checsum 和尾
{
//if ((RecvBuf[j] = 0x21)&&(RecvBuf[j+2] = 0x21))
if ((buff2[j] == 0x2d)&&(buff2[j+1] == 0x0c)&&(buff2[j+2] == 0x2d)&&(buff2[16] == 0xff))
{
//j 找对了
NameLength = (RecvCount - 4) - (j + 7);//11位包括 8个ID 2个- -和1个.
//_cprintf("check is ok \n");
CString strLength;
strLength.Format(_T("%d"),NameLength);
//AfxMessageBox(strLength);
if (gIP[m_iDeviceCount-1][0]==0)
{
strncpy(gIP[m_iDeviceCount-1],inet_ntoa(m_BroClientAddr.sin_addr),15);
gIP[m_iDeviceCount-1][15]=0;
}
CString str;
#ifdef _UNICODE
str.Format(L"%S",gIP[m_iDeviceCount-1]);
#else
str.Format("%s",gIP[m_iDeviceCount-1]);
#endif
//int NameLength=RecvCount-31;
CString strName;
for(int k=0;k<NameLength;k++)
{
strName += buff2[j + 8 + k];
}
//这些ip 怎么保存起来12.23
HTREEITEM child=m_TreeControl.InsertItem(strName, 0, 0, m_hTreeDeviceRoot);
m_TreeControl.SetItemData(child,m_iDeviceCount+1);
//这里的++是为了主动添加ip的ID
m_iDeviceCount++;
m_TreeControl.Expand( m_hTreeDeviceRoot, TVE_EXPAND );
//break;
j = RecvCount - 8;//快速结束本次循环
}
}
}
}
_cprintf("the m_iDeviceCount is %d \n",m_iDeviceCount);
CloseSocket();