array指针数组的赋值有关问题
array指针数组的赋值问题
/*VS2005 C++ FORM dotnet platform
问题是我对ssinfoglaobal1[1]->ssdata[1]->CounterValue 赋值时,怎么把
ssinfoglaobal1[1]->ssdata[2]->CounterValue
ssinfoglaobal1[1]->ssdata[3]->CounterValue
ssinfoglaobal1[1]->ssdata[4]->CounterValue
ssinfoglaobal1[1]->ssdata[5]->CounterValue
ssinfoglaobal1[1]->ssdata[6]->CounterValue
等的值也给修改了?
对ptr = ssinfoglaobal1[1];
ptr->timeout = SSTIMEOUTMAX;
ptr->mach = mach;
ptr->macl = macl;
ptr->bcid = mstr.Bcid;
的赋值也是把 ssinfoglaobal1[2]
ssinfoglaobal1[3]
ssinfoglaobal1[4]
ssinfoglaobal1[5]
的值给修改了。
一般在服务器重启后出现这种问题。
*/
#define CNTIDSSNUM 0x4
#define STRUCTSSENTRYDATASIZE 48
typedef struct
{
UINT8 MacAddr[6];
UINT16 Bcid;
UINT32 IPADDR;
UINT16 DIUC;
UINT16 UIUC;
UINT16 DLZONE;
UINT16 ULZONE;
UINT32 SsPower;
UINT16 Rssi1;
UINT16 Rssi2;
UINT16 Cnr1;
UINT16 Cnr2;
UINT32 RxBytes;
UINT32 TxBytes;
UINT32 ErrorPdus;
UINT32 timer;
}STRUCTSsEntryData;
public ref class UdpState
{
public: UdpClient^ udpClient ;
public: IPEndPoint^ ipEndPoint ;
public: unsigned long id;
};
public ref class DISPLAYDATA1
{
public:
unsigned long CounterID;
unsigned long CounterValue;
};
public ref class SSINFOGLOBAL
{
public:
unsigned long bsidh;
unsigned long bsidl;
unsigned long mach;
unsigned long macl;
unsigned long bcid;
unsigned long timeout;
array <DISPLAYDATA1^>^ ssdata;
};
static int bcid1index;
static array<SSINFOGLOBAL^>^ ssinfoglaobal1;//[8]
static unsigned long isMessageReceived ;
System::IAsyncResult^ socket1result;
private: System::Net::Sockets::UdpClient^ socket1;
private: System::Net::IPEndPoint^ ipEndPoint;
void Initialize(void)
{
ssinfoglaobal1 = gcnew array<SSINFOGLOBAL^>(128);
for(i = 0; i<128; i++)
{
ssinfoglaobal1[i] = gcnew SSINFOGLOBAL();
ssinfoglaobal1[i]->ssdata = gcnew array<DISPLAYDATA1^>(CNTIDSSNUM);
for(j = 0; j < CNTIDSSNUM; j++)
{
ssinfoglaobal1[i]->ssdata[j] = gcnew DISPLAYDATA1();
}
}
}
void receivemonitordataforbs(void)
{
UdpState^ udpState = gcnew UdpState();
udpState->ipEndPoint = ipEndPoint;
udpState->udpClient = socket1;
while(1)
{
if(isMessageReceived == 0)
{
isMessageReceived = 1;
try
{
socket1result = 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 msglen, msgnum, index;
unsigned long buflen;
unsigned long startbytes;
unsigned long mach,macl;
long long ltmp0;
array<unsigned char>^ receiveBytes ;
DBGSTAT Dbgstat;
STATVALUE Msgstat;
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;
}
Dbgstat.CommandType = (receiveBytes[0]<<24) + (receiveBytes[1]<<16) + (receiveBytes[2]<<8) + receiveBytes[3];
Dbgstat.DataLength = (receiveBytes[4]<<24) + (receiveBytes[5]<<16) + (receiveBytes[6]<<8) + receiveBytes[7];
startbytes = 8;
buflen = receiveBytes->Length;
if(buflen < (Dbgstat.DataLength+DBGSTATHEADERLENGTH))
{
Dbgstat.DataLength = (buflen - DBGSTATHEADERLENGTH)&0xfff8;
}
if(DBGSTATCMDQUERYREPLY == Dbgstat.CommandType)
{
isMessageReceived = 2;
}
if(Dbgstat.DataLength > 0)
{
msgnum = 0;
if(DBGSTATCMDCPSSGLOBALANSWER == Dbgstat.CommandType)
{
STRUCTSsEntryData mstr;
SSINFOGLOBAL^ ptr;
int bcidindex = 0xffff;
startbytes = DBGSTATHEADERLENGTH;
while(startbytes < Dbgstat.DataLength)
{
mstr.MacAddr[0] = receiveBytes[startbytes];
mstr.MacAddr[1] = receiveBytes[startbytes+1];
mstr.MacAddr[2] = receiveBytes[startbytes+2];
mstr.MacAddr[3] = receiveBytes[startbytes+3];
mstr.MacAddr[4] = receiveBytes[startbytes+4];
mstr.MacAddr[5] = receiveBytes[startbytes+5];
mstr.Bcid = (receiveBytes[startbytes+6]<<8) + receiveBytes[startbytes+7];
mstr.IPADDR = (receiveBytes[startbytes+8]<<24) + (receiveBytes[startbytes+9]<<16) + (receiveBytes[startbytes+10]<<8) + (receiveBytes[startbytes+11]);
mstr.DIUC = (receiveBytes[startbytes+12]<<8) + receiveBytes[startbytes+13];
mstr.UIUC = (receiveBytes[startbytes+14]<<8) + receiveBytes[startbytes+15];
mstr.DLZONE = (receiveBytes[startbytes+16]<<8) + receiveBytes[startbytes+17];
mstr.ULZONE = (receiveBytes[startbytes+18]<<8) + receiveBytes[startbytes+19];
mstr.SsPower = (receiveBytes[startbytes+20]<<24) + (receiveBytes[startbytes+21]<<16) + (receiveBytes[startbytes+22]<<8) + (receiveBytes[startbytes+23]);
mstr.Rssi1 = (receiveBytes[startbytes+24]<<8) + receiveBytes[startbytes+25];
mstr.Rssi2 = (receiveBytes[startbytes+26]<<8) + receiveBytes[startbytes+27];
mstr.Cnr1 = (receiveBytes[startbytes+28]<<8) + receiveBytes[startbytes+29];
mstr.Cnr2 = (receiveBytes[startbytes+30]<<8) + receiveBytes[startbytes+31];
mstr.RxBytes = (receiveBytes[startbytes+32]<<24) + (receiveBytes[startbytes+33]<<16) + (receiveBytes[startbytes+34]<<8) + (receiveBytes[startbytes+35]);
mstr.TxBytes = (receiveBytes[startbytes+36]<<24) + (receiveBytes[startbytes+37]<<16) + (receiveBytes[startbytes+38]<<8) + (receiveBytes[startbytes+39]);
mstr.ErrorPdus = (receiveBytes[startbytes+40]<<24) + (receiveBytes[startbytes+41]<<16) + (receiveBytes[startbytes+42]<<8) + (receiveBytes[startbytes+43]);
mstr.timer = (receiveBytes[startbytes+44]<<24) + (receiveBytes[startbytes+45]<<16) + (receiveBytes[startbytes+46]<<8) + (receiveBytes[startbytes+47]);
bcidindex = 0xffff;
mach = (receiveBytes[startbytes]<<24) + (receiveBytes[startbytes+1]<<16) + (receiveBytes[startbytes+2]<<8) + (receiveBytes[startbytes+3]);
macl = (receiveBytes[startbytes+4]<<24) + (receiveBytes[startbytes+5]<<16);
for(j = 0; j < (int)bcid1index; j++)
{
if((ssinfoglaobal1[j]->mach == mach)&&(ssinfoglaobal1[j]->macl == macl))
{
ptr = ssinfoglaobal1[j];
ptr->timeout = SSTIMEOUTMAX;
ptr->bcid = mstr.Bcid;
bcidindex = j;
break;
}
}
if(bcidindex == 0xffff)
{
if(bcid1index < 128)
{
ptr = ssinfoglaobal1[bcid1index];
ptr->timeout = SSTIMEOUTMAX;
ptr->mach = mach;
ptr->macl = macl;
ptr->bcid = mstr.Bcid;
bcidindex = bcid1index;
bcid1index++;
}else
{
isMessageReceived = 0;
return;
}
}
ssinfoglaobal1[bcidindex]->ssdata[0]->CounterValue = mstr.Bcid;
ssinfoglaobal1[bcidindex]->ssdata[1]->CounterValue = mach;
ssinfoglaobal1[bcidindex]->ssdata[2]->CounterValue = macl;
ssinfoglaobal1[bcidindex]->ssdata[3]->CounterValue = (mstr.DLZONE<<16)+mstr.ULZONE;
ssinfoglaobal1[bcidindex]->ssdata[4]->CounterValue = (mstr.DIUC<<16)+mstr.UIUC;
ssinfoglaobal1[bcidindex]->ssdata[5]->CounterValue = mstr.IPADDR;
ssinfoglaobal1[bcidindex]->ssdata[6]->CounterValue = mstr.SsPower;
ssinfoglaobal1[bcidindex]->ssdata[7]->CounterValue = (mstr.Rssi1<<16)+mstr.Rssi2;
ssinfoglaobal1[bcidindex]->ssdata[8]->CounterValue = (mstr.Cnr1<<16)+mstr.Cnr2;
ssinfoglaobal1[bcidindex]->ssdata[9]->CounterValue = mstr.RxBytes;
ssinfoglaobal1[bcidindex]->ssdata[10]->CounterValue = mstr.TxBytes;
ssinfoglaobal1[bcidindex]->ssdata[11]->CounterValue = mstr.ErrorPdus;
startbytes += STRUCTSSENTRYDATASIZE;
}
}
}
}