当前位置: 代码迷 >> VC >> array指针数组的赋值有关问题
  详细解决方案

array指针数组的赋值有关问题

热度:8662   发布时间:2013-02-25 00:00:00.0
array指针数组的赋值问题
/*VS2005 C++ FORM dotnet platform 

问题是我对ss_info_glaobal1[1]->ss_data[1]->CounterValue 赋值时,怎么把
ss_info_glaobal1[1]->ss_data[2]->CounterValue 
ss_info_glaobal1[1]->ss_data[3]->CounterValue 
ss_info_glaobal1[1]->ss_data[4]->CounterValue 
ss_info_glaobal1[1]->ss_data[5]->CounterValue 
ss_info_glaobal1[1]->ss_data[6]->CounterValue 
等的值也给修改了?

对ptr = ss_info_glaobal1[1];
ptr->time_out = SS_TIME_OUT_MAX;
ptr->mac_h = mach;
ptr->mac_l = macl;
ptr->bcid = m_str.Bcid;
的赋值也是把 ss_info_glaobal1[2]
ss_info_glaobal1[3]
ss_info_glaobal1[4]
ss_info_glaobal1[5]
的值给修改了。

一般在服务器重启后出现这种问题。
*/

#define CNT_ID_SS_NUM 0x4

#define STRUCT_SSENTRY_DATA_SIZE 48  
typedef struct
{
  UINT8 MacAddr[6];
  UINT16 Bcid;
  UINT32 IPADDR;
  UINT16 DIUC;
  UINT16 UIUC;

  UINT16 DL_ZONE;
  UINT16 UL_ZONE;
  UINT32 SsPower;
  UINT16 Rssi1;
  UINT16 Rssi2;
  UINT16 Cnr1;
  UINT16 Cnr2;

  UINT32 Rx_Bytes;
  UINT32 Tx_Bytes;
  UINT32 Error_Pdus;
  UINT32 timer;
}STRUCT_SsEntry_Data;


public ref class UdpState
{
  public: UdpClient^ udpClient ;  
  public: IPEndPoint^ ipEndPoint ;  
  public: unsigned long id;
};

public ref class DISPLAY_DATA1
{
public:
unsigned long CounterID;
unsigned long CounterValue;
};
public ref class SS_INFO_GLOBAL
{
public:
unsigned long bsid_h;
unsigned long bsid_l;
unsigned long mac_h;
unsigned long mac_l;
unsigned long bcid;
unsigned long time_out;
array <DISPLAY_DATA1^>^ ss_data;
};

static int bcid1_index;
static array<SS_INFO_GLOBAL^>^ ss_info_glaobal1;//[8]
static unsigned long isMessageReceived ;
System::IAsyncResult^ socket1_result;
private: System::Net::Sockets::UdpClient^ socket1;
private: System::Net::IPEndPoint^ ipEndPoint;

void Initialize(void)
{  
ss_info_glaobal1 = gcnew array<SS_INFO_GLOBAL^>(128);
for(i = 0; i<128; i++)
{
ss_info_glaobal1[i] = gcnew SS_INFO_GLOBAL();
ss_info_glaobal1[i]->ss_data = gcnew array<DISPLAY_DATA1^>(CNT_ID_SS_NUM);
for(j = 0; j < CNT_ID_SS_NUM; j++)
{
ss_info_glaobal1[i]->ss_data[j] = gcnew DISPLAY_DATA1();
}
}
}

void receive_monitor_data_for_bs(void)
{
UdpState^ udpState = gcnew UdpState();
udpState->ipEndPoint = ipEndPoint;
udpState->udpClient = socket1;
  while(1)
  {
if(isMessageReceived == 0)
{
isMessageReceived = 1;
try
{
socket1_result = socket1->BeginReceive(gcnew AsyncCallback(ReceiveCallback), udpState);
}catch( Exception^ e )
{
isMessageReceived = 0;
this->textBox31->Text += e->ToString(); Console::WriteLine( e->ToString() );
continue;
}
}else
{

System::Threading::Thread::Sleep(10);
Application::DoEvents();
}
  }
}
static void ReceiveCallback(System::IAsyncResult^ asyncResult)
{
int i, j, count;
int msg_len, msg_num, index;
unsigned long buf_len;
unsigned long start_bytes;
unsigned long mach,macl;

long long l_tmp0;
array<unsigned char>^ receiveBytes ;
DBG_STAT Dbg_stat;
STAT_VALUE Msg_stat;


UdpClient^ udpClient =((UdpState^)(asyncResult->AsyncState))->udpClient;
IPEndPoint^ ipEndPoint =((UdpState^)(asyncResult->AsyncState))->ipEndPoint;

try{
receiveBytes = udpClient->EndReceive(asyncResult, ipEndPoint);
}
catch( Exception^ e) 
{
isMessageReceived = 0;
Console::WriteLine( e->ToString() );
return;
}


Dbg_stat.CommandType = (receiveBytes[0]<<24) + (receiveBytes[1]<<16) + (receiveBytes[2]<<8) + receiveBytes[3];
Dbg_stat.DataLength = (receiveBytes[4]<<24) + (receiveBytes[5]<<16) + (receiveBytes[6]<<8) + receiveBytes[7];
start_bytes = 8;
buf_len = receiveBytes->Length;
if(buf_len < (Dbg_stat.DataLength+DBG_STAT_HEADER_LENGTH))
{
Dbg_stat.DataLength = (buf_len - DBG_STAT_HEADER_LENGTH)&0xfff8;
}
if(DBG_STAT_CMD_QUERY_REPLY == Dbg_stat.CommandType)
{
isMessageReceived = 2;
}
if(Dbg_stat.DataLength > 0)
{

msg_num = 0;

if(DBG_STAT_CMD_CP_SS_GLOBAL_ANSWER == Dbg_stat.CommandType)
{
STRUCT_SsEntry_Data m_str;
SS_INFO_GLOBAL^ ptr;

int bcid_index = 0xffff;

start_bytes = DBG_STAT_HEADER_LENGTH;
while(start_bytes < Dbg_stat.DataLength)
{
m_str.MacAddr[0] = receiveBytes[start_bytes];
m_str.MacAddr[1] = receiveBytes[start_bytes+1];
m_str.MacAddr[2] = receiveBytes[start_bytes+2];
m_str.MacAddr[3] = receiveBytes[start_bytes+3];
m_str.MacAddr[4] = receiveBytes[start_bytes+4];
m_str.MacAddr[5] = receiveBytes[start_bytes+5];
m_str.Bcid = (receiveBytes[start_bytes+6]<<8) + receiveBytes[start_bytes+7];
m_str.IPADDR = (receiveBytes[start_bytes+8]<<24) + (receiveBytes[start_bytes+9]<<16) + (receiveBytes[start_bytes+10]<<8) + (receiveBytes[start_bytes+11]);
m_str.DIUC = (receiveBytes[start_bytes+12]<<8) + receiveBytes[start_bytes+13];
m_str.UIUC = (receiveBytes[start_bytes+14]<<8) + receiveBytes[start_bytes+15];

m_str.DL_ZONE = (receiveBytes[start_bytes+16]<<8) + receiveBytes[start_bytes+17];
m_str.UL_ZONE = (receiveBytes[start_bytes+18]<<8) + receiveBytes[start_bytes+19];
m_str.SsPower = (receiveBytes[start_bytes+20]<<24) + (receiveBytes[start_bytes+21]<<16) + (receiveBytes[start_bytes+22]<<8) + (receiveBytes[start_bytes+23]);
m_str.Rssi1 = (receiveBytes[start_bytes+24]<<8) + receiveBytes[start_bytes+25];
m_str.Rssi2 = (receiveBytes[start_bytes+26]<<8) + receiveBytes[start_bytes+27];
m_str.Cnr1 = (receiveBytes[start_bytes+28]<<8) + receiveBytes[start_bytes+29];
m_str.Cnr2 = (receiveBytes[start_bytes+30]<<8) + receiveBytes[start_bytes+31];

m_str.Rx_Bytes = (receiveBytes[start_bytes+32]<<24) + (receiveBytes[start_bytes+33]<<16) + (receiveBytes[start_bytes+34]<<8) + (receiveBytes[start_bytes+35]);
m_str.Tx_Bytes = (receiveBytes[start_bytes+36]<<24) + (receiveBytes[start_bytes+37]<<16) + (receiveBytes[start_bytes+38]<<8) + (receiveBytes[start_bytes+39]);
m_str.Error_Pdus = (receiveBytes[start_bytes+40]<<24) + (receiveBytes[start_bytes+41]<<16) + (receiveBytes[start_bytes+42]<<8) + (receiveBytes[start_bytes+43]);
m_str.timer = (receiveBytes[start_bytes+44]<<24) + (receiveBytes[start_bytes+45]<<16) + (receiveBytes[start_bytes+46]<<8) + (receiveBytes[start_bytes+47]);

bcid_index = 0xffff;

mach = (receiveBytes[start_bytes]<<24) + (receiveBytes[start_bytes+1]<<16) + (receiveBytes[start_bytes+2]<<8) + (receiveBytes[start_bytes+3]);
macl = (receiveBytes[start_bytes+4]<<24) + (receiveBytes[start_bytes+5]<<16);

for(j = 0; j < (int)bcid1_index; j++)
{
if((ss_info_glaobal1[j]->mac_h == mach)&&(ss_info_glaobal1[j]->mac_l == macl))
{
ptr = ss_info_glaobal1[j];
ptr->time_out = SS_TIME_OUT_MAX;
ptr->bcid = m_str.Bcid;
bcid_index = j;
break;
}
}
if(bcid_index == 0xffff)
{
if(bcid1_index < 128)
{
ptr = ss_info_glaobal1[bcid1_index];
ptr->time_out = SS_TIME_OUT_MAX;
ptr->mac_h = mach;
ptr->mac_l = macl;
ptr->bcid = m_str.Bcid;
bcid_index = bcid1_index;
bcid1_index++;
}else
{
isMessageReceived = 0;
return;
}
}
ss_info_glaobal1[bcid_index]->ss_data[0]->CounterValue = m_str.Bcid;
ss_info_glaobal1[bcid_index]->ss_data[1]->CounterValue = mach;
ss_info_glaobal1[bcid_index]->ss_data[2]->CounterValue = macl;
ss_info_glaobal1[bcid_index]->ss_data[3]->CounterValue = (m_str.DL_ZONE<<16)+m_str.UL_ZONE;
ss_info_glaobal1[bcid_index]->ss_data[4]->CounterValue = (m_str.DIUC<<16)+m_str.UIUC;
ss_info_glaobal1[bcid_index]->ss_data[5]->CounterValue = m_str.IPADDR;
ss_info_glaobal1[bcid_index]->ss_data[6]->CounterValue = m_str.SsPower;
ss_info_glaobal1[bcid_index]->ss_data[7]->CounterValue = (m_str.Rssi1<<16)+m_str.Rssi2;
ss_info_glaobal1[bcid_index]->ss_data[8]->CounterValue = (m_str.Cnr1<<16)+m_str.Cnr2;
ss_info_glaobal1[bcid_index]->ss_data[9]->CounterValue = m_str.Rx_Bytes;
ss_info_glaobal1[bcid_index]->ss_data[10]->CounterValue = m_str.Tx_Bytes;
ss_info_glaobal1[bcid_index]->ss_data[11]->CounterValue = m_str.Error_Pdus;

start_bytes += STRUCT_SSENTRY_DATA_SIZE;
}
}
}
}


------解决方案--------------------------------------------------------
有难度,关注中~~~
------解决方案--------------------------------------------------------
请把出问题的语句标出

------解决方案--------------------------------------------------------
不能把关键的贴上来啊?
  相关解决方案