unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ToolWin, ComCtrls, ImgList, StdCtrls, ExtCtrls, Buttons, Unit_dll, Menus, DateUtils,Winsock,SHELLAPI; type TForm1 = class(TForm) ToolBar1: TToolBar; tbStartService: TToolButton; tbStopService: TToolButton; ImageList1: TImageList; ImageList2: TImageList; tbSendData: TToolButton; tbClear: TToolButton; tbQuit: TToolButton; Panel1: TPanel; lvUserTable: TListView; mmDataWnd: TMemo; Timer1: TTimer; ToolButton1: TToolButton; tbctr: TToolButton; CheckBox1: TCheckBox; MainMenu1: TMainMenu; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; N4: TMenuItem; Timer2: TTimer; N5: TMenuItem; N6: TMenuItem; Hex1: TMenuItem; N7: TMenuItem; N8: TMenuItem; N9: TMenuItem; N10: TMenuItem; N11: TMenuItem; N12: TMenuItem; SaveDialog1: TSaveDialog; N13: TMenuItem; N14: TMenuItem; OpenDialog1: TOpenDialog; Panel2: TPanel; sbSendData: TSpeedButton; Edit1: TEdit; Edit2: TEdit; StatusBar1: TStatusBar; N15: TMenuItem; procedure tbQuitClick(Sender: TObject); procedure tbStartServiceClick(Sender: TObject); procedure tbStopServiceClick(Sender: TObject); procedure tbSendDataClick(Sender: TObject); procedure tbClearClick(Sender: TObject); procedure lvUserTableClick(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure Timer1Timer(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure ToolButton1Click(Sender: TObject); procedure tbctrClick(Sender: TObject); procedure N2Click(Sender: TObject); procedure N4Click(Sender: TObject); procedure lvUserTableDblClick(Sender: TObject); procedure N6Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Hex1Click(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure N13Click(Sender: TObject); procedure N14Click(Sender: TObject); procedure mmDataWndChange(Sender: TObject); procedure sbSendDataClick(Sender: TObject); procedure Timer2Timer(Sender: TObject); procedure N15Click(Sender: TObject); //procedure Timer2Timer(Sender: TObject); // procedure HEX1Click(Sender: TObject); private { Private declarations } bIfServiceStarted:boolean; function BytetoIP(ui: ModemInfoStruct): String; public procedure AddText(p
Char); procedure PollUserTable; procedure ProcessData(dr:ModemDataStruct); procedure AddListItem(ui:ModemInfoStruct); function IntToIp(ip:Cardinal):String; function _DateTimeToUnix(const aValue:TDateTime):Int64; { Public declarations } end;var Form1: TForm1; svrport:integer; waittime:integer; SysAutoM:integer;implementationuses hsx_dialogs,Unit2,Unit3,Unit4,Unit5,Unit6;{$R *.DFM}function StrToHex(const s : string) : string;var iCount : integer; Value, CH, CL : Byte;begin SetLength(Result, 2 * Length(s)); for iCount:= 1 to Length(s) do begin Value:= Byte(S[iCount]); CH:= (Value shr 4) and $0F; CL:= Value and $0F; if CL < $0A then CL:= CL + $30 else CL:= CL + $37; if CH < $0A then CH:= CH + $30 else CH:= CH + $37; Result[iCount * 2 - 1]:= Char(CH); Result[iCount * 2]:= Char(CL); end;end;{procedure TForm1.ProcessMessage(var Msg:TMessage);var dr:ModemDataStruct; p
Char;begin GetMem(p,512); if (DSGetNextData(dr,100)>=0) then begin if dr.m_data_len=0 then PollUserTable else ProcessData(dr); end; FreeMem(p,512);end; }function HexToInt(Hex : string) : Cardinal;const cHex = '0123456789ABCDEF';var mult,i,loop : integer;beginresult := 0;mult := 1;for loop := length(Hex) downto 1 dobegini := pos(Hex[loop],cHex)-1;if (i < 0) then i := 0;inc(result,(i*mult));mult := mult * 16;end;end;procedure TForm1.FormCreate(Sender: TObject);begin svrport:=5000; sbSendData.Enabled:=false; n8.Enabled:=true; n9.Enabled:=false; n10.Enabled:=false; n11.Enabled:=false; n12.Enabled:=false;end;procedure TForm1.tbQuitClick(Sender: TObject);begin Close;end;procedure TForm1.tbStartServiceClick(Sender: TObject);var p
Char;iRet:integer;strResult:String;begin iRet:=DSStartService(svrport); if (iRet<>0) then begin strResult:='ÏÃÃÅÉ£ÈٿƼ¼Êý¾ÝÖÐÐÄ·þÎñÆô¶¯,ÕìÌý¶Ë¿ÚΪ'+inttostr(svrport); Form1.StatusBar1.Panels[1].Text:='Æô¶¯'; end else begin AddText('Êý¾ÝÖÐÐÄ·þÎñÆô¶¯Ê§°Ü£¡'); Form1.StatusBar1.Panels[1].Text:='Æô¶¯Ê§°Ü'; end; If SysAutoM = 1 Then begin form1.Timer1.Enabled:=true; end; AddText(PChar(strResult)); bIfServiceStarted:=true; tbStartService.Enabled:=false; tbStopService.Enabled:=true; tbSendData.Enabled:=true; sbSendData.Enabled:=true; tbctr.Enabled:=true; n8.Enabled:=false; n9.Enabled:=true; n10.Enabled:=true; n11.Enabled:=true; n12.Enabled:=true;end;procedure TForm1.tbStopServiceClick(Sender: TObject);var p
Char;strResult:String;begin GetMem(p,512); if (0=DSStopService) then begin DSGetLastError(p,512); AddText(p); end else begin Form1.StatusBar1.Panels[1].Text:='Í£Ö¹'; AddText('Í£Ö¹Êý¾ÝÖÐÐÄ·þÎñ³É¹¦£¡'); lvUserTable.Items.Clear ; end; bIfServiceStarted:=FALSE; FreeMem(p,512); tbStartService.Enabled:=true; tbStopService.Enabled:=false; tbSendData.Enabled:=false; sbSendData.Enabled:=false; tbctr.Enabled:=false; n8.Enabled:=true; n9.Enabled:=false; n10.Enabled:=false; n11.Enabled:=false; n12.Enabled:=false;end;procedure TForm1.AddText(p
Char);begin if mmDataWnd.Lines.Count>100 then mmDataWnd.Lines.Clear; mmDataWnd.Lines.Add(p);end;procedure TForm1.tbClearClick(Sender: TObject);begin mmDataWnd.Lines.Clear;end;procedure TForm1.PollUserTable;var ui:ModemInfoStruct; i:Integer; iDtuAmount:Integer; t_update:Cardinal; p
Char;begin lvUserTable.Items.Clear; GetMem(p,512); iDtuAmount:=DSGetModemCount; for i:=0 to iDtuAmount-1 do begin DSGetModemByPosition(i,ui); AddListItem(ui); end; FreeMem(p,512);end;{function HexStrToStr(const HexStr : string;const hexlen:integer) : string;const NumericBin : array[$30..$39] of Byte = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9);CharBin : array[$41..$46] of Byte = (10, 11, 12, 13, 14, 15);var BH, BL : Byte; iCount : integer; P : ^Byte;begin SetLength(Result, Length(HexStr) div 2); P:= Pointer(Result); for iCount:= 0 to Length(HexStr) div 2 - 1 do begin BH:= Byte(HexStr[iCount * 2 + 1]); if BH >= $41 then BH:= CharBin[BH] else BH:= NumericBin[BH]; BL:= Byte(HexStr[iCount * 2 + 2]); if BL >= $41 then BL:= CharBin[BL] else BL:= NumericBin[BL]; BH:= BH shl 4 + BL and $0F; P^:= BH; Inc(P); end;end; }procedure TForm1.ProcessData(dr:ModemDataStruct);var i:Integer; str:String; strId:String; strDate:String; time:TDateTime; rut:integer;begin strId:=format('%8.8x',[dr.m_modemId]); time:=UnixToDateTime(dr.m_recv_time+28800); strDate:=DateToStr(Date)+' '+TimeToStr(time); str:='ID:'+strId+'---'+'Time:'+strDate+'---'+'Len:'+IntToStr(dr.m_data_len); for i:=1 to Length(str) do if str
=#0 then str:=' '; mmdatawnd.Lines.Add(str); dr.m_data_buf[dr.m_data_len]:=#0; if Form1.CheckBox1.Checked =true then begin mmDataWnd.Lines.Add('Data:'+StrToHex(dr.m_data_buf)); end else begin mmDataWnd.Lines.Add('Data:'+dr.m_data_buf); end;end;procedure TForm1.AddListItem(ui:ModemInfoStruct);var list:TListItem;time:TDateTime;strDate:String;begin list:=lvUserTable.Items.Add; list.Caption:=format('%8.8x',[ui.m_modemId]); list.SubItems.Add(ui.m_phoneno); time:=UnixToDateTime(ui.m_conn_time+28800); strDate:=DateTimeToStr(time); list.SubItems.Add(strDate); time:=UnixToDateTime(ui.m_refresh_time+28800); strDate:=DateTimeToStr(time); list.SubItems.Add(strDate); //list.SubItems.Add(IntToIp(ui.m_dynip)); list.SubItems.Add(BytetoIP(ui));end;function TForm1.BytetoIP(ui:ModemInfoStruct):String;var ipstr:String;begin ipstr:=Inttostr(ord(ui.m_dynip[0]))+'.'+Inttostr(ord(ui.m_dynip[1]))+'.'+Inttostr(ord(ui.m_dynip[2]))+'.'+Inttostr(ord(ui.m_dynip[3]));{ ipstr:=Inttostr((ui.m_dynip[0]+256) Mod 256); ipstr:=ipstr+'.'+Inttostr((ui.m_dynip[1]+256) Mod 256); ipstr:=ipstr+'.'+Inttostr((ui.m_dynip[2]+256) Mod 256); ipstr:=ipstr+'.'+Inttostr((ui.m_dynip[3]+256) Mod 256); } BytetoIP:=ipstr;end;function TForm1.IntToIp(ip:Cardinal):String;var s:String;begin s:=''; s:=s+IntToStr(ip div (256*256*256)); s:=s+'.'; s:=s+IntToStr((ip div (256*256)) mod 256); s:=s+'.'; s:=s+IntToStr((ip div 256) mod 256); s:=s+'.'; s:=s+IntToStr(ip mod 256); IntToIp:=s;end;function TForm1._DateTimeToUnix(const AValue:TDateTime):Int64;begin Result := Round((AValue - 25569) * 3600*24);end;procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);begin if MessageDlg('È·¶¨ÒªÍ˳öÂð£¿',mtConfirmation,[mbYes,mbNo],0)=mrNo then CanClose:=false;end;procedure TForm1.Timer1Timer(Sender: TObject);var dr:ModemDataStruct;iRet:integer;begin if (bIfServiceStarted=true) then begin PollUserTable; iRet:=DSGetNextData(dr,0); if (iRet=1) then if (dr.m_data_len<>0) then begin// if dr.m_data_len=0 then// PollUserTable// else ProcessData(dr); end; end;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);var pChar;strResult:String;begin GetMem(p,512); if (0=DSStopService) then begin DSGetLastError(p,512); AddText(p); end else begin AddText('Í£Ö¹Êý¾ÝÖÐÐÄ·þÎñ³É¹¦!'); end; bIfServiceStarted:=FALSE; FreeMem(p,512); tbStartService.Enabled:=true; tbStopService.Enabled:=false; tbSendData.Enabled:=false; tbctr.Enabled:=false;end;procedure TForm1.ToolButton1Click(Sender: TObject);begin PollUserTable;end;procedure TForm1.tbSendDataClick(Sender: TObject);begin//Try// application.createform(Tform2,form2); form2.ShowModal;//finally// FreeAndNil(Form2);end;procedure TForm1.tbctrClick(Sender: TObject);begin if length(form1.Edit1.Text)>0 then begin Form1.Edit2.Text := '***COMMIT CONFIG***'; form1.sbSendData.Click; form3.ShowModal; end else MessageDlg('ÇëÏÈÔÚÁбíÉÏÑ¡ÔñÉ豸£¨Êó±ê×ó¼üµ¥»÷É豸IDºÅÂë¼´¿É£©',mtConfirmation,[mbYes],0);end;procedure TForm1.N2Click(Sender: TObject);begin aboutbox.ShowModal;end;procedure TForm1.N4Click(Sender: TObject);begin close;end;procedure TForm1.lvUserTableDblClick(Sender: TObject);begin tbSendData.Click;end;procedure TForm1.N6Click(Sender: TObject);begin form5:=tform5.Create(application); form5.ShowModal; form5.Free;end;procedure TForm1.Hex1Click(Sender: TObject);begin checkbox1.Checked:=hex1.Checked;end;procedure TForm1.CheckBox1Click(Sender: TObject);begin hex1.Checked:=checkbox1.Checked;end;procedure TForm1.N13Click(Sender: TObject);begin form1.OpenDialog1.FileName:='DataBakup.txt'; ShellExecute(Handle,'open', PAnsiChar(OpenDialog1.FileName), nil,nil,SW_SHOW);end;procedure TForm1.N14Click(Sender: TObject);begin DeleteFile('DataBakup.txt');end;procedure TForm1.mmDataWndChange(Sender: TObject);begin form1.SaveDialog1.FileName:='DataBakup.txt'; mmDataWnd.Lines.SaveToFile(SaveDialog1.FileName);end;procedure TForm1.sbSendDataClick(Sender: TObject);var modemId:Cardinal; fsendresult:integer;begin //½«edit1µÄ×Ö·û´®×ª»»³ÉidºÅ modemId:=StrToInt('$'+Edit1.Text); fsendresult:=DSSendData(modemId,Length(Edit2.Text),PChar(Edit2.Text)); If fsendresult = 1 then begin Form1.addtext (pchar('Ïò ' + edit1.Text + ' ·¢ËÍÊý¾Ý£º' + edit2.Text )); form1.AddText('¿ØÖÆÃüÁî·¢Ëͳɹ¦!'); form3.StatusBar1.Panels[0].Text:='Ïò'+form3.Edit1.Text+'·¢ËÍÃüÁî:'+form1.Edit2.Text+'³É¹¦£¡'; end Else form1.AddText ('·¢ËÍʧ°Ü!');end;procedure TForm1.lvUserTableClick(Sender: TObject);begin if lvUserTable.Selected <> nil then begin form1.Edit1.Text:=lvUserTable.Selected.Caption; form2.Edit1.Text:=lvUserTable.Selected.Caption; form3.Edit1.Text:=lvUserTable.Selected.Caption; end;end;procedure TForm1.Timer2Timer(Sender: TObject);begin Form1.StatusBar1.Panels[2].Text:= DateToStr(Date)+' '+TimeToStr(time);end;procedure TForm1.N15Click(Sender: TObject);begin form6.ShowModal;end;end.