%%%------------------------------------------------------------------- %%% @author cheese %%% @copyright (C) 2014, %%% @doc %%% %%% @end %%% Created : 21. Jan 2014 11:17 AM %%%------------------------------------------------------------------- -module(test). -author("cheese"). -include_lib("kernel/include/logger.hrl"). -behaviour(gen_server). %% API -export([start_link/0]). %% gen_server callbacks -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3, test_tic/0, test_titp/0, test_socket_handler/2, create_unique_from_data/1, mti_converted/1, test_cert/0]). -define(SERVER, ?MODULE). -record(state, {}). -include("../include/types_finance_protocol.hrl"). %%%=================================================================== %%% API %%%=================================================================== start_link() -> ?LOG_INFO("start_link: ~w~n", [?MODULE]), gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). %%%=================================================================== %%% gen_server callbacks %%%=================================================================== init([]) -> ?LOG_INFO("Start TEST~n", []), erlang:send_after(1000, self(), test), {ok, #state{}}. handle_call(_Request, _From, State) -> {reply, ok, State}. handle_cast(_Request, State) -> {noreply, State}. handle_info(test, State) -> test_cert(), {noreply, State}; handle_info(_Info, State) -> {noreply, State}. terminate(_Reason, _State) -> ok. code_change(_OldVsn, State, _Extra) -> {ok, State}. %%%=================================================================== %%% Internal functions %%%=================================================================== test_cert() -> {ok, Sql} = diint_start:get_mssql(<<"pax_test_odbc">>), ?LOG_INFO("Resp: ~s~n", [Sql]), ok. test_socket_handler(Message, SocketClientPid) -> ?LOG_INFO("TEST: Receive message from ~w: ~w~n", [SocketClientPid, Message]), ProcessName = getProcessname(), ?LOG_INFO("=================================================~n", []), ?LOG_INFO("TEST: Send to ~w~n", [ProcessName]), case rabbit_rpc:send_message_and_receive_response(ProcessName, Message, 15000) of {response, RespBytes} -> ?LOG_INFO("TEST: Received in test ~w~n", [RespBytes]), socket_utilites:send_message(RespBytes, SocketClientPid); {error, Reason} -> ?LOG_INFO("TEST: Wait rabbit error: ~w~n", [Reason]) end, ok. getProcessname() -> {_, {_, _, S}} = calendar:local_time(), RabbitConf = case (S rem 1) of 0 -> diint_utilites_common_sup:get_rabbit_config_1(<<"InfoCall.Front.Resp.Erlang.Test.1">>); _Other -> diint_utilites_common_sup:get_rabbit_config_2(<<"InfoCall.Front.Resp.Erlang.Test.2">>) end, ProcessName = rabbit_rpc:get_rabbit_rpc_process_name(RabbitConf), ProcessName. test_ms_sql() -> application:start(odbc), ConnStr = "DRIVER={SQL Server};SERVER=neptune.db.it.loc;Database=AtmBase;Uid=SSTServices;Pwd=Service1212", case odbc:connect(ConnStr, []) of {ok, Conn} -> Res = odbc:sql_query(Conn, "SELECT getdate() as NOW"), ?LOG_INFO("Res: ~w~n", [Res]); {Err} -> ?LOG_INFO("Err: ~w~n", [Err]) end, {ok, #state{}}. create_unique_from_data(Data) -> case protocol_tic:parse(Data) of {error, Reason} -> {error, Reason}; #parsed_iso_message{fields = {error, Reason}, mti = _MTI} -> {error, Reason}; #parsed_iso_message{fields = Fields, mti = MTI} -> ?LOG_INFO("Fields ~p", [Fields]), case protocol_iso_utilites:get_field(Fields, 11) of undefined -> {error, stan_not_present}; #iso_field{view_data = DataStan} -> case protocol_iso_utilites:get_field(Fields, 41) of undefined -> {error, term_not_present}; #iso_field{raw_data = TermData} -> MTI_Bin = mti_converted(MTI), <>/binary, DataStan/binary, <<":">>/binary, MTI_Bin/binary>> end end end. mti_converted(200) -> <<"200">>; mti_converted(210) -> <<"200">>; mti_converted(100) -> <<"100">>; mti_converted(110) -> <<"100">>; mti_converted(400) -> <<"410">>; mti_converted(410) -> <<"410">>; mti_converted(MTI) -> list_to_binary(integer_to_list(MTI)). test_tic() -> %%Bytes = <<"00A4M040000210B23864110EA0800000000000049400A04200000000000000000040212404967925415404904026011804002D0000000011000000000000122636778401540220000108CACS2161DN00 CHERKASSY 000804Gorkogo str., 11 ACQ2 CHERKASKAYA 00120140402DN00 DN00 000000018000000098001?0000000000000000000000000022CLP_QR_1ATM_U2AT5PN615001 030CC=0TC=5TL=3TLC=ukTZ=18000">>, Bytes = bytes_extension:hex_to_bytes("027241344D3039303030303230304632373836363131323841303930303030303030303030303034393030304130313936373939393730313030303030303030303133303130333130303030303030303030303530303036313531343137323234303030303339363238343230343137313631353036313536303131383034393031303030443030303030303030313130303030303030303030303336363739393937303130303030303030303031333D3235313231303130363437383038303430303030303030313438323230384341444E3939393950524956415442414E4B2020202020202020202020202020202020202020444E4550524F504554524F56534B202020202020202020202020202020203030303830344C656E696E67726164736B617961205374722E2035202020202020202020202020202020202020202020202020202020202020202020202020202020444E483020202020202020202020202020202020202020202020202020203030313230313630363135444E3030202020202020444E303020202020202020202020202020202020202020202020202020303030303030303439303030303030303834304343363135364430353241354232393930313F3030303030303030303030303030303030303030303030303030333144594E5F435552525F434F4E563B49443D313135333236303B234558434823303031202020202020202020202020202020202020202020202020202020202020202020202020202020202020202030363043433D30104D503D361054433D3510544C3D3310544C433D756B10545A3D343930303010414F443D30303030303030313030303010434F443D393830"), ?LOG_INFO("Bytes: ~s~n", [Bytes]), P = protocol_tic:parse(Bytes), ?LOG_INFO("TIC ~p", [P]), Unq = create_unique_from_data(Bytes), ?LOG_INFO("Unq: ~w", [Unq]), {ok, #state{}}. test_titp() -> Bytes = bytes_extension:hex_to_bytes("027241344D3039303030303230304632373836363131323841303930303030303030303030303034393030304130313936373939393730313030303030303030303133303130333130303030303030303030303530303036313531323534333134303030303339363238343136323135353332343036313536303131383034393031303030443030303030303030313130303030303030303030303336363739393937303130303030303030303031333D3235313231303130363437383038303430303030303030313438313630384341444E3939393950524956415442414E4B2020202020202020202020202020202020202020444E4550524F504554524F56534B202020202020202020202020202020203030303830344C656E696E67726164736B617961205374722E2035202020202020202020202020202020202020202020202020202020202020202020202020202020444E483020202020202020202020202020202020202020202020202020203030313230313630363135444E3030202020202020444E303020202020202020202020202020202020202020202020202020303030303030303439303030303030303834304343363135364430353241354232393930313F3030303030303030303030303030303030303030303030303030333144594E5F435552525F434F4E563B49443D313135323830343B234558434823303031202020202020202020202020202020202020202020202020202020202020202020202020202020202020202030363043433D30104D503D361054433D3510544C3D3210544C433D727510545A3D343930303010414F443D30303030303030313030303010434F443D393830"), %%logger:info("Bytes: ~w~n", [Bytes], ?LOG_FILE), %%logger:info("Hex: ~s~n", [bytes_extension:bin_to_hexstr(Bytes)], ?LOG_FILE), %%logger:info("Hex: ~w~n", [bytes_extension:bin_to_hexstr(Bytes)], ?LOG_FILE), P = protocol_titp:parse(Bytes), ?LOG_INFO("TITP ~p", [P]), ?LOG_INFO("TITP ~s", [protocol_titp:protocol_info_string(P)]), %%F49 = protocol_titp:get_titp_field_info(24), %%F49_New = F49#iso_field{ data = <<"0066">>}, %%FieldsNew = protocol_titp:set_field(P#parsed_iso_message.fields, F49_New), %%logger:info("TITP. FieldsNew: ~p~n", [FieldsNew], ?LOG_FILE), %%logger:simple_message("Bitmap: ~w", [protocol_titp:internal_pack_bitmap(P#parsed_iso_message.fields, 1, <<>>)]), %%Bt = protocol_titp:pack(P), %%logger:simple_message("Pack: ~w", [Bt]), %%Field_2 = protocol_titp:create_field_as_string(2, "4149000000001234"), %%NewFields = protocol_iso_utilites:set_field(P#parsed_iso_message.fields, Field_2), %%NewP = P#parsed_iso_message{ fields = NewFields}, %%logger:simple_message("TITP NewP. P: ~p", [NewP]), {ok, #state{}}.