?? uitaxiserviceodmpclientlogistic.pas
字號:
//==============================================================================
// $修訂版本號: 1.0 $
// $日期 : 2007年4月20日 星期五 14:44:42 $
// $版本號 : 1.0.0 Goshgen 1 $
//
// 電召客戶端邏輯層定義。
//
//
// $BeginLog$
// $Endlog $
// $Copyright 版權(quán)所有 (c)2007 TRANSIT 保留所有權(quán)利$
//==============================================================================
{:
電召客戶端邏輯層定義。
}
unit uITaxiServiceODMPClientLogistic;
interface
uses Classes, DB, SysUtils, uBaseODMProtocalClient, uBaseODMDefs,
uBaseODMProtocalUtils, uBaseODMProtocalCommander,
uITaxiServiceODMPLogisticDefs;
Type
{: 接收回復指令的觸發(fā)事件。}
TOnProtocalReplyResult = procedure(_status_id: Integer) of Object;
{: 接收主動發(fā)送的指令的觸發(fā)事件。}
TOnProtocalReceiveResult = procedure(_p_protocal_dataset: PBaseODMProtocalDataset) of Object;
// 觸發(fā)連接狀態(tài)
TOnLogResult = procedure(_sender: TObject; _is_connect: Boolean) of Object;
// 觸發(fā)連接錯誤
TOnTCPClientErrorEvent = procedure(_sender: TObject) of Object;
{: 電召客戶端邏輯層類。}
TITaxiServiceBaseODMProtocalClientLogistic = class
private
// 客戶端
baseNetClient : TBaseODMProtocalClient;
{: 指令狀態(tài)觸發(fā)事件。}
FOnProtocalReplyResult : TOnProtocalReplyResult;
FOnProtocalReceiveResult : TOnProtocalReceiveResult;
FOnLogResult : TOnLogResult;
FOnTCPClientError : TOnTCPClientErrorEvent;
procedure doOnProtocalResult(_sender: TObject; _protocal_dataset: PBaseODMProtocalDataset;
_command_status: TBaseODMCommanderStatus);
procedure doOnTCPClientDisConnect(_sender: TObject);
procedure doOnTCPClientConnect(_sender: TObject);
procedure doOnTCPClientError(_sender: TObject; _ip: string);
// 構(gòu)造析構(gòu)
public
constructor Create;
destructor Destroy; override;
public
procedure ConnectCallServer(_address: string; _port: Integer);
procedure DisConnectCallServer;
procedure SendODMP(_p_protocal_dataset: PBaseODMProtocalDataset);
procedure AuthODMP(_command_name, _user_name, _user_password: string;
_is_ok, _is_active, _is_kick: Boolean);
procedure CallODMP(_command_name: string; _caller_id: Integer;
_caller_lon, _caller_lat: Double;
_caller_info: string);
procedure SendNoop;
procedure SendHelp;
procedure SendQuit;
published
property OnProtocalReplyResult : TOnProtocalReplyResult
read FOnProtocalReplyResult
write FOnProtocalReplyResult;
property OnProtocalReceiveResult : TOnProtocalReceiveResult
read FOnProtocalReceiveResult
write FOnProtocalReceiveResult;
property OnLogResult : TOnLogResult
read FOnLogResult
write FOnLogResult;
property OnTCPClientError : TOnTCPClientErrorEvent
read FOnTCPClientError
write FOnTCPClientError;
end;
implementation
{ TITaxiServiceBaseODMProtocalClientLogistic }
//------------------------------------------------------------------------------
// 構(gòu)造與析構(gòu)
//------------------------------------------------------------------------------
{: 構(gòu)造函數(shù)。
}
constructor TITaxiServiceBaseODMProtocalClientLogistic.Create;
begin
// 定義常用指令
DefineListCommandDefine := TStringList.Create;
DefineListODMPDataDefine := TStringList.Create;
baseNetClient := TBaseODMProtocalClient.Create;
baseNetClient.OnProtocalResult := doOnProtocalResult;
baseNetClient.OnTCPClientConnect := doOnTCPClientConnect;
baseNetClient.OnTCPClientDisConnect := doOnTCPClientDisConnect;
baseNetClient.OnTCPClientError := doOnTCPClientError;
TITaxiServiceODMPLogisticUtils.defineCommandBCMSeatLogon;
TITaxiServiceODMPLogisticUtils.defineCommandBCMTaskInfoBase;
TITaxiServiceODMPLogisticUtils.DefineCommandBCMTaskCancel;
TITaxiServiceODMPLogisticUtils.DefineCommandBCMTaskReply;
TITaxiServiceODMPLogisticUtils.DefineCommandBCMTaskEnd;
TITaxiServiceODMPLogisticUtils.defineCommandBCMTaskInfoAdditional;
TITaxiServiceODMPLogisticUtils.DefineCommandBCMTaskNew;
TITaxiServiceODMPLogisticUtils.defineCommandBCMTaskStatus;
TITaxiServiceODMPLogisticUtils.DefineCommandBCMTaskTaxiInfo;
TITaxiServiceODMPLogisticUtils.DefineCommandBCMTaskProcessDisconnect;
end;
{: 析構(gòu)函數(shù)。
}
destructor TITaxiServiceBaseODMProtocalClientLogistic.Destroy;
begin
TBaseODMProtocalUtils.ClearDefineCommandList(DefineListCommandDefine);
DefineListCommandDefine.Free;
TBaseODMProtocalUtils.ClearDefineDataList(DefineListODMPDataDefine);
DefineListODMPDataDefine.Free;
baseNetClient.Free;
inherited;
end;
//------------------------------------------------------------------------------
// 公有方法 -- 連接和觸發(fā)事件
//------------------------------------------------------------------------------
{: 客戶端連接服務端。
@param _address IP地址
@param _port 端口
}
procedure TITaxiServiceBaseODMProtocalClientLogistic.ConnectCallServer(_address: string;
_port: Integer);
begin
baseNetClient.Connect(_address, _port);
end;
{: 客戶端斷開服務端。
@param _address IP地址
@param _port 端口
}
procedure TITaxiServiceBaseODMProtocalClientLogistic.DisConnectCallServer;
begin
baseNetClient.Disconnect;
end;
{: 指令接收觸發(fā)事件。
@param _p_protocal_dataset 指令集
@param _command_status 指令狀態(tài)
}
procedure TITaxiServiceBaseODMProtocalClientLogistic.doOnProtocalResult(
_sender: TObject; _protocal_dataset: PBaseODMProtocalDataset;
_command_status: TBaseODMCommanderStatus);
begin
// 觸發(fā)日志
TBaseODMProtocalUtils.OnProtocalResult(
_protocal_dataset^.Command^.CommandDefine^.CommandName,
'', _command_status);
// 處理邏輯指令
case _command_status of
// 接收指令
TBaseODMCommanderStatusReceive:
// 如果是回復的指令
if _protocal_dataset^.Command^.CommandDefine^.CommandName = 'REPLY' then
begin
if Assigned(FOnProtocalReplyResult) then
FOnProtocalReplyResult(StrToIntDef(_protocal_dataset^.Command^.CommandStatus, 0));
end
// 收到服務端發(fā)送的指令
else begin
if Assigned(FOnProtocalReceiveResult) then
FOnProtocalReceiveResult(_protocal_dataset);
end
end;
end;
{: 斷開觸發(fā)事件。
@param _p_protocal_dataset 指令集
@param _command_status 指令狀態(tài)
}
procedure TITaxiServiceBaseODMProtocalClientLogistic.doOnTCPClientDisConnect(
_sender: TObject);
begin
if Assigned(FOnLogResult) then
FOnLogResult(Self, False);
end;
{: 連接觸發(fā)事件。
@param _p_protocal_dataset 指令集
@param _command_status 指令狀態(tài)
}
procedure TITaxiServiceBaseODMProtocalClientLogistic.doOnTCPClientConnect(
_sender: TObject);
begin
if Assigned(FOnLogResult) then
FOnLogResult(Self, True);
end;
procedure TITaxiServiceBaseODMProtocalClientLogistic.doOnTCPClientError(_sender: TObject; _ip: string);
begin
if Assigned(FOnLogResult) then
FOnLogResult(Self, False);
end;
//------------------------------------------------------------------------------
// 公有方法 -- 指令發(fā)送
//------------------------------------------------------------------------------
{: 發(fā)送認證。
@param _p_protocal_dataset 指令數(shù)據(jù)集
}
procedure TITaxiServiceBaseODMProtocalClientLogistic.SendODMP(_p_protocal_dataset: PBaseODMProtocalDataset);
begin
// 發(fā)送指令對象
baseNetClient.commander.SendCommand(_p_protocal_dataset);
// 釋放指令對象
TBaseODMProtocalUtils.ClearProtocalDataset(_p_protocal_dataset);
end;
{: 發(fā)送認證。
@param _user_name 用戶名
@param _user_password 密碼
@param _is_kick 是否踢用戶
}
procedure TITaxiServiceBaseODMProtocalClientLogistic.AuthODMP(_command_name, _user_name,
_user_password: string; _is_ok, _is_active, _is_kick: Boolean);
var
p_protocal_dataset : PBaseODMProtocalDataset;
begin
// 建立對象
p_protocal_dataset := TBaseODMProtocalUtils.BuildProtocalDataset(
_command_name, False, 0);
// 增加指令對象內(nèi)容
TBaseODMProtocalUtils.BuildCommandAddParams(p_protocal_dataset^.Command,
'UserName', _user_name);
TBaseODMProtocalUtils.BuildCommandAddParams(p_protocal_dataset^.Command,
'Password', _user_password);
TBaseODMProtocalUtils.BuildCommandAddParams(p_protocal_dataset^.Command,
'IsOK', _is_ok);
TBaseODMProtocalUtils.BuildCommandAddParams(p_protocal_dataset^.Command,
'IsActive', _is_active);
TBaseODMProtocalUtils.BuildCommandAddParams(p_protocal_dataset^.Command,
'IsKick', _is_kick);
// 發(fā)送指令對象
baseNetClient.commander.SendCommand(p_protocal_dataset);
// 釋放指令對象
TBaseODMProtocalUtils.ClearProtocalDataset(p_protocal_dataset);
end;
{: 發(fā)送招車指令。
@param _caller_id 業(yè)務編號
@param _caller_lon 經(jīng)度
@param _caller_lat 緯度
@param _caller_info 招車人信息
}
procedure TITaxiServiceBaseODMProtocalClientLogistic.CallODMP(_command_name: string;
_caller_id: Integer; _caller_lon, _caller_lat: Double; _caller_info: string);
begin
// // 建立對象
// p_protocal_dataset := TBaseODMProtocalUtils.BuildProtocalDataset(
// _command_name, False, 0);
//
// // 增加指令對象內(nèi)容
// TBaseODMProtocalUtils.BuildCommandAddParams(p_protocal_dataset^.Command,
// 'Caller_id, '');
// TBaseODMProtocalUtils.BuildCommandAddParams(p_protocal_dataset^.Command,
// _caller_lon, '');
// TBaseODMProtocalUtils.BuildCommandAddParams(p_protocal_dataset^.Command,
// _caller_lat, '');
// TBaseODMProtocalUtils.BuildCommandAddParams(p_protocal_dataset^.Command,
// _caller_info, _caller_info);
//
// // 發(fā)送指令對象
// baseNetClient.commander.SendCommand(p_protocal_dataset);
// // 釋放指令對象
// TBaseODMProtocalUtils.ClearProtocalDataset(p_protocal_dataset);
end;
////------------------------------------------------------------------------------
//// 公有方法 -- 定義常用指令
////------------------------------------------------------------------------------
//
//{: 定義認證指令。}
//procedure TITaxiServiceBaseODMProtocalClientLogistic.defineCommandAuth;
//var
// p_command_define: PBaseODMProtocalCommandDefine;
//begin
// // 定義指令定義
// p_command_define := TBaseODMProtocalUtils.DefineCommandDefine(
// 'AUTH', TBaseODMProtocalCommandDefineWithDataNo, True);
//
// // 定義指令定義的參數(shù)
// TBaseODMProtocalUtils.DefineCommandDefineAddParam(p_command_define,
// 'user_name', '用戶名', 'UserName', ftString);
// TBaseODMProtocalUtils.DefineCommandDefineAddParam(p_command_define,
// 'user_password', '密碼', 'UserPassword', ftString);
// TBaseODMProtocalUtils.DefineCommandDefineAddParam(p_command_define,
// 'is_ok', '是否成功', 'IsOK', ftBoolean);
// TBaseODMProtocalUtils.DefineCommandDefineAddParam(p_command_define,
// 'is_active', '是否激活', 'IsActive', ftBoolean);
// TBaseODMProtocalUtils.DefineCommandDefineAddParam(p_command_define,
// 'is_kickoff', '是否踢用戶', 'IsKickoff', ftBoolean);
//end;
//
//{: 定義召車指令。}
//procedure TITaxiServiceBaseODMProtocalClientLogistic.defineCommandCall;
//var
// p_command_define: PBaseODMProtocalCommandDefine;
//begin
// // 定義指令定義
// p_command_define := TBaseODMProtocalUtils.DefineCommandDefine(
// 'CALL', TBaseODMProtocalCommandDefineWithDataNo, True);
//
// // 定義指令定義的參數(shù)
// TBaseODMProtocalUtils.DefineCommandDefineAddParam(p_command_define,
// 'caller_id', '業(yè)務編號', 'CallerID', ftInteger);
// TBaseODMProtocalUtils.DefineCommandDefineAddParam(p_command_define,
// 'caller_lon', '經(jīng)度', 'CallerLon', ftFloat);
// TBaseODMProtocalUtils.DefineCommandDefineAddParam(p_command_define,
// 'caller_lat', '緯度', 'CallerLat', ftFloat);
// TBaseODMProtocalUtils.DefineCommandDefineAddParam(p_command_define,
// 'caller_info', '召車人信息', 'CallerInfo', ftString);
//end;
//
//{: 定義幫助指令。}
//procedure TITaxiServiceBaseODMProtocalClientLogistic.defineCommandHelp;
//begin
// TBaseODMProtocalUtils.DefineCommandDefine(
// 'HELP', TBaseODMProtocalCommandDefineWithDataNo, True);
//end;
//
//{: 定義空指令。}
//procedure TITaxiServiceBaseODMProtocalClientLogistic.defineCommandNoop;
//begin
// TBaseODMProtocalUtils.DefineCommandDefine(
// 'NOOP', TBaseODMProtocalCommandDefineWithDataNo, True);
//end;
//
//{: 定義退出指令。}
//procedure TITaxiServiceBaseODMProtocalClientLogistic.defineCommandQuit;
//begin
// TBaseODMProtocalUtils.DefineCommandDefine(
// 'QUIT', TBaseODMProtocalCommandDefineWithDataNo, True);
//end;
procedure TITaxiServiceBaseODMProtocalClientLogistic.SendHelp;
begin
baseNetClient.commander.SendCommandHelp;
end;
procedure TITaxiServiceBaseODMProtocalClientLogistic.SendNoop;
begin
baseNetClient.commander.SendCommandNoop;
end;
procedure TITaxiServiceBaseODMProtocalClientLogistic.SendQuit;
begin
baseNetClient.commander.SendCommandQuit;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -