⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userdatatypeunit.pas

📁 访问西门子手机,可发送AT指令,并进行解码和加码.
💻 PAS
字号:
unit UserDataTypeUnit;

interface
uses
  SyncObjs,Forms,SysUtils,IniFiles;
const
 WaitToSend   = 1 ;
 SendFail     = 2 ;
 SendSuccess  = 3 ;

 DeviceMaxCount = 16  ;
 MsgBufLength   = 200 ;
type
  TMarkType = (                       //用于标志手机类型
              ChinaMobile  ,         //  中国移动
              ChinaUnicon  ,         //  中国联通
              CDMA         ,         //  CDMA
              Other                  //  其他类型
              ) ;
  TPrefixSet = Set of 130..139 ;  // 手机前缀集合类型
  TMobilePrefixSet = Array[ChinaMobile..other ] of TPrefixSet ;


  PMsgRecord = ^TMsgRecord ;
  TMsgRecord = Record                   //    短信记录类型
             MsgID     : Integer ;           //    短信ID
             TargetMobileNum : String ;  //    目标手机号
             SourceMobileNum : String ;  //    短信发送的源手机
             UserId    : Integer      ;
             SendTime,ReceiveTime : Tdatetime  ;
             Prio      : Integer    ;
             Content   : AnsiString ;
             StudentID : String     ;
             Status    : Byte       ;
             SchoolID  : String     ;
             Next      : PMsgRecord ;
       End ;
  TMsgLine = Record
            nCount : Integer ; // 缓冲个数
            MsgAr  : Array [0..MsgBufLength-1] of TMsgRecord ;    //   发送和接收缓冲
          end;

  // TAllThreadStatus 用于记录线程是否处于运行状态,"正"表示正在运行,"False"表示停止运行
  TThreadStutus = ( BeHalt,BeRunning,BeStopping);
  TThreadInfo = record
        ThreadStatus :  TThreadStutus ; 
  end;

  TDeviceInfo = Record
       DeviceID     : Integer     ;  // 设备ID,程序中内部使用,值为DeviceList中的下标
       DeviceName   : String      ;  // 设备名称
       Address      : Integer     ;  // 地址
       TerminalType : Integer     ;  // 终端类型
       SIM_TYPE     : TMarkType   ;  // 服务商类型
       SMS_CENTER   : String      ;  // 短信中心
       ThreadInfo   : TThreadInfo ;

       nSucceedToSend,nFailToSend,nRecv,nFetch: Integer ; // 流量信息
  end;

  TDeviceGroup = Record
       DeviceList : Array [0..DeviceMaxCount-1] of TDeviceInfo ;
       ValidDeviceQuantity : Integer ;
  end;

  TGlobalInfo = Class
       constructor Create ;
     public
       strCurrentDir    : String ; // 目标文件的目录
       MobilePrefixSet  : TMobilePrefixSet ;
       DeviceGroup : TDeviceGroup ;
       nFetch,nSucceedToSend,nFailToSend,nRecv : Integer  ;

       function  AllThreadIsStop : Boolean ;
       procedure CreateAThread(DeviceID : Integer ) ;
       procedure DestoryAThread(DeviceID : Integer ) ;
       procedure AddFlux(_Fetch,_SucceedToSend,_FailToSend,_Recv : Integer);

       procedure AppendLog( _Log : Ansistring);
       function GetLog : AnsiString ;

       procedure ClearFlux ; 
     protected
       ThreadCount : Integer     ;  // 线程计数
       strLog : AnsiString ;
  end;


  function  MarkTypeToStr( nMarkType : TMarkType ) : String ;
  function  IntToMarkType(  nMark : Integer ) : TMarkType ;
  function  GetRemoteConString : Ansistring ;
  function  GetLocalConString : Ansistring ;
  procedure AppendToLog( _Log : Ansistring);
  function  GetLog : Ansistring;
var
  csGlobal : TCriticalSection  ;
  GlobalInfo : TGlobalInfo ;

implementation
{ TGlobalInfo }
function GetRemoteConString: Ansistring;
var
  IniFile : TIniFile ;
  strFileName : String;
begin
  csGlobal.Acquire ;
  strFileName := GlobalInfo.strCurrentDir +'\Server.ini';
  csGlobal.Release ;

  IniFile := TIniFile.Create(strFileName);
  Result  := IniFile.ReadString('Db','adocon','');
  IniFile.Free;
end;

function GetLocalConString : Ansistring ;
var
  strCon,strCurrentDir : Ansistring  ;
begin
  csGlobal.Acquire ;
  strCurrentDir := GlobalInfo.strCurrentDir ;
  csGlobal.Release ;

  strCon := 'Provider=Microsoft.Jet.OLEDB.4.0;'+
            'Data Source=' + strCurrentDir +'\Device\Local.mdb;Persist Security Info=False';
  Result := strCon ;
end;

constructor TGlobalInfo.Create;
var
  i : Integer;
begin
  strCurrentDir := ExtractFileDir(Application.ExeName) ;  // 当前目录

  MobilePrefixSet[ChinaMobile] := [135,136,137,138,139];  // 所有移动电话服务商的电话号码的前缀
  MobilePrefixSet[ChinaUnicon] := [130,131,132,133];
  MobilePrefixSet[CDMA]        := [133];
  MobilePrefixSet[Other]       := [130,131,132,133,134,135,136,137,138,139];

  for i:= 0 to  DeviceMaxCount-1 do                      // 设备信息置空
  begin
    DeviceGroup.DeviceList[i].DeviceID := i ;
    DeviceGroup.DeviceList[i].ThreadInfo.ThreadStatus := BeHalt ;
    DeviceGroup.ValidDeviceQuantity    := 0 ;
  end;

  ThreadCount    := 0 ;
  nFetch         := 0 ;
  nSucceedToSend := 0 ;
  nFailToSend    := 0 ;
  nRecv          := 0 ;
end;
function TGlobalInfo.AllThreadIsStop: Boolean;
begin
  if ( ThreadCount = 0 ) then
    Result := TRUE
  else
    Result := FALSE;
end;
function MarkTypeToStr( nMarkType : TMarkType ) : String ;
begin
  case nMarkType  of
     ChinaMobile : Result := 'ChinaMobile ';
     ChinaUnicon : Result := 'ChinaUnicon ';
     CDMA        : Result := 'CDMA        ';
     Other       : Result := 'Other       ';
  else
    Result := ' none ';
  end;
end;
function IntToMarkType(  nMark : Integer ) : TMarkType ;
begin
   case nMark of
     0 :  Result := ChinaMobile ;
     1 :  Result := ChinaUnicon ;
     2 :  Result := CDMA        ;
     3 :  Result := Other       ;
   else
     Result := Other ;
   end;
end;
procedure TGlobalInfo.CreateAThread(DeviceID: Integer);  // 当为发送线程序时,传送相应的设备ID;否则,传-1
begin
  Inc(ThreadCount,1);
  if ( DeviceID >= 0 ) and ( DeviceID < DeviceGroup.ValidDeviceQuantity  )  then
      DeviceGroup.DeviceList[DeviceID].ThreadInfo.ThreadStatus := BeRunning;
end;

procedure TGlobalInfo.DestoryAThread(DeviceID: Integer); // 当为发送线程序时,传送相应的设备ID;否则,传-1
begin
  Dec(ThreadCount,1);
  if ( DeviceID >= 0 ) and ( DeviceID < DeviceGroup.ValidDeviceQuantity  ) then
  begin
    DeviceGroup.DeviceList[DeviceID].ThreadInfo.ThreadStatus := BeHalt;
  end;
end;

procedure TGlobalInfo.AddFlux(_Fetch,_SucceedToSend,_FailToSend,_Recv : Integer);
begin
  Inc(nFetch,_Fetch);
  Inc(nSucceedToSend,_SucceedToSend);
  Inc(nFailToSend,_FailToSend);
  Inc(nRecv,_Recv);
end;

procedure TGlobalInfo.AppendLog(_Log: Ansistring);
begin
  strLog := strLog +#13#10 +_Log;
end;

function TGlobalInfo.GetLog: AnsiString;
begin
  Result := strLog ;
  strLog := '';
end;
procedure AppendToLog( _Log : Ansistring);
begin
  csGlobal.Acquire ;
  GlobalInfo.AppendLog(_Log);
  csGlobal.Release ;
end;
function  GetLog : Ansistring;
begin
  csGlobal.Acquire ;
  Result := GlobalInfo.GetLog ;
  csGlobal.Release ;
end;
procedure TGlobalInfo.ClearFlux;
var
  i: Integer;
begin
  GlobalInfo.nFetch         := 0 ;
  GlobalInfo.nSucceedToSend := 0 ;
  GlobalInfo.nFailToSend    := 0 ;
  GlobalInfo.nRecv          := 0 ;
  for i:= 0 to  DeviceMaxCount-1 do
    begin
      GlobalInfo.DeviceGroup.DeviceList[i].nSucceedToSend := 0 ;
      GlobalInfo.DeviceGroup.DeviceList[i].nFailToSend    := 0 ;
      GlobalInfo.DeviceGroup.DeviceList[i].nRecv          := 0 ;
      GlobalInfo.DeviceGroup.DeviceList[i].nFetch         := 0 ;
    end;
end;

Initialization
begin
  csGlobal     := TCriticalSection.Create ;       // 全局变量
  GlobalInfo   := TGlobalInfo.Create ;
end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -