📄 main.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#include <winsock.h>
#include <time.h>
#pragma hdrstop
#include "Main.h"
#include "common.h"
#include "U_options.h"
#include "U_about.h"
#include "U_dreg.h"
#include "U_initcall.h"
#include "U_handover.h"
//---------------------------------------------------------------------------
#pragma link "AdvGrid"
#pragma link "BaseGrid"
#pragma link "AdvGrid"
#pragma link "BaseGrid"
#pragma resource "*.dfm"
TMainForm *MainForm;
AnsiString gSourceIp; //bs sim ip
AnsiString gDestinationIp; //gw ip
BS_ACTION_S bsAction;
BSSIM_CONFIG_S gConfig;
long msgTime;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
FILE * fConfig;
NMUDPBsMessage->LocalPort = HOST_BS_UDP_PORT;
NMUDPBsMessage->ReportLevel = Nmudp::Status_Basic;
NMUDPGwMessage->LocalPort = HOST_GW_UDP_PORT;
NMUDPGwMessage->ReportLevel = Nmudp::Status_Basic;
PanelBottom->Height = Panel->Height * 1/2;
PanelRight->Height = Panel->Height * 1/2;
AdvStringGridCase->Cells[0][0] = "Index";
AdvStringGridCase->Cells[1][0] = "Test Case";
AdvStringGridFlow->Cells[0][0] = "Time";
AdvStringGridFlow->ColWidths[0] = PanelBottom->Width * 140/822;
AdvStringGridFlow->Cells[1][0] = "Direction";
AdvStringGridFlow->ColWidths[1] = PanelBottom->Width * 50/822;
AdvStringGridFlow->Cells[2][0] = "MS ID";
AdvStringGridFlow->ColWidths[2] = PanelBottom->Width * 100/822;
AdvStringGridFlow->Cells[3][0] = "Function Type";
AdvStringGridFlow->ColWidths[3] = PanelBottom->Width * 220/822;
AdvStringGridFlow->Cells[4][0] = "Message Type";
AdvStringGridFlow->ColWidths[4] = PanelBottom->Width * 300/822;
if(NULL != (fConfig = fopen("bssim_config.dat","rb")))
{
memset(&gConfig,0,sizeof(BSSIM_CONFIG_S));
fread(&gConfig,sizeof(BSSIM_CONFIG_S),1,fConfig);
gSourceIp = gConfig.sourceIp;
gDestinationIp = gConfig.destinationIp;
fclose(fConfig);
}
}
//----------------------------------------------------------------------------
void __fastcall TMainForm::OptionsClick(TObject *Sender)
{
MainForm->Enabled = false;
OptionForm->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SpeedButtonOptionsClick(TObject *Sender)
{
MainForm->Enabled = false;
OptionForm->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::AboutClick(TObject *Sender)
{
MainForm->Enabled = false;
AboutForm->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ExitClick(TObject *Sender)
{
if (MessageDlg("Close BS Simulator?", mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
MainForm->Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SpeedButtonExitClick(TObject *Sender)
{
MainForm->Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::NMUDPBsMessageDataReceived(TComponent *Sender,
int NumberBytes, AnsiString FromIP, int Port)
{
int len;
char msId[16];
char funcType[128];
char msgType[128];
UDP_MSG_S st_udp_msg;
R64_MSG_S st_r64_msg;
NMUDPBsMessage->ReadBuffer(st_udp_msg.data,NumberBytes,len);
st_udp_msg.env.protocolSap = BS_UDP_SAP;
st_udp_msg.env.msgType = 0;
st_udp_msg.env.MessageLength = NumberBytes + UDP_HEADER_LEN;
st_udp_msg.dataLen = NumberBytes;
st_udp_msg.srcIp = inet_addr(gSourceIp.c_str());
st_udp_msg.srcUdpPort = Port;
st_udp_msg.destIp= inet_addr(gDestinationIp.c_str());
st_udp_msg.destUdpPort = GW_R6_UDP_PORT;
if(FAILURE == r64_decode_msg(&st_udp_msg, &st_r64_msg))
{
ShowMessage("decode error");
}
time(&msgTime);
AdvStringGridFlow->Cells[0][AdvStringGridFlow->RowCount-1] = ctime(&msgTime);
AdvStringGridFlow->Cells[1][AdvStringGridFlow->RowCount-1] = "BS-->GW";
sprintf(msId,"%02x-%02x-%02x-%02x-%02x-%02x",st_r64_msg.msgHead.msId.id[0],
st_r64_msg.msgHead.msId.id[1],
st_r64_msg.msgHead.msId.id[2],
st_r64_msg.msgHead.msId.id[3],
st_r64_msg.msgHead.msId.id[4],
st_r64_msg.msgHead.msId.id[5]);
AdvStringGridFlow->Cells[2][AdvStringGridFlow->RowCount-1] = msId;
getFuncMsgType(&st_r64_msg,funcType,msgType);
AdvStringGridFlow->Cells[3][AdvStringGridFlow->RowCount-1] = funcType;
AdvStringGridFlow->Cells[4][AdvStringGridFlow->RowCount-1] = msgType;
AdvStringGridFlow->AddRow();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SpeedButtonGoClick(TObject *Sender)
{
MainForm->Enabled = false;
FormInitCall->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::GoClick(TObject *Sender)
{
MainForm->Enabled = false;
FormInitCall->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::NMUDPGwMessageDataReceived(TComponent *Sender,
int NumberBytes, AnsiString FromIP, int Port)
{
int len;
char msId[16];
char funcType[128];
char msgType[128];
UDP_MSG_S st_udp_msg;
R64_MSG_S st_r64_msg;
NMUDPGwMessage->ReadBuffer(st_udp_msg.data,NumberBytes,len);
st_udp_msg.env.protocolSap = BS_UDP_SAP;
st_udp_msg.env.msgType = 0;
st_udp_msg.env.MessageLength = NumberBytes + UDP_HEADER_LEN;
st_udp_msg.dataLen = NumberBytes;
st_udp_msg.srcIp = inet_addr(gDestinationIp.c_str());
st_udp_msg.srcUdpPort = Port;
st_udp_msg.destIp= inet_addr(gSourceIp.c_str());
st_udp_msg.destUdpPort = BS_R6_UDP_PORT;
if(FAILURE == r64_decode_msg(&st_udp_msg, &st_r64_msg))
{
ShowMessage("decode error");
}
time(&msgTime);
AdvStringGridFlow->Cells[0][AdvStringGridFlow->RowCount-1] = ctime(&msgTime);
AdvStringGridFlow->Cells[1][AdvStringGridFlow->RowCount-1] = "GW-->BS";
sprintf(msId,"%02x-%02x-%02x-%02x-%02x-%02x",st_r64_msg.msgHead.msId.id[0],
st_r64_msg.msgHead.msId.id[1],
st_r64_msg.msgHead.msId.id[2],
st_r64_msg.msgHead.msId.id[3],
st_r64_msg.msgHead.msId.id[4],
st_r64_msg.msgHead.msId.id[5]);
AdvStringGridFlow->Cells[2][AdvStringGridFlow->RowCount-1] = msId;
getFuncMsgType(&st_r64_msg,funcType,msgType);
AdvStringGridFlow->Cells[3][AdvStringGridFlow->RowCount-1] = funcType;
AdvStringGridFlow->Cells[4][AdvStringGridFlow->RowCount-1] = msgType;
AdvStringGridFlow->AddRow();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ClearAll1Click(TObject *Sender)
{
int i;
for(i = 1;i<AdvStringGridFlow->RowCount;i++)
{
AdvStringGridFlow->Rows[i]->Clear();
}
AdvStringGridFlow->RowCount = 2;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SpeedButtonStopClick(TObject *Sender)
{
MainForm->Enabled = false;
FormDreg->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::StopClick(TObject *Sender)
{
MainForm->Enabled = false;
FormDreg->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
{
if (MessageDlg("Close BS Simulator?", mtConfirmation, TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
CanClose = true;
else
CanClose = false;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SpeedButtonHOClick(TObject *Sender)
{
MainForm->Enabled = false;
FormHO->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::HandOver1Click(TObject *Sender)
{
MainForm->Enabled = false;
FormHO->Visible = true;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -