Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ucp_common dependency

  • Loading branch information...
commit 79d7ec59b6c051a87cd5790c7618d3fb6df65af5 1 parent c7fde14
@aerosol aerosol authored
View
36 include/ira.hrl
@@ -1,36 +0,0 @@
--define(IRA, [
- {$!, 33},
- {$", 34},
- {$#, 35},
- {$$, 36},
- {$%, 37},
- {$&, 38},
- {$', 39},
- {$(, 40},
- {$), 41},
- {$*, 42},
- {$+, 43},
- {$,, 44},
- {$-, 45},
- {$., 46},
- {$/, 47},
-
- {$:, 58},
- {$;, 59},
- {$<, 60},
- {$=, 61},
- {$>, 62},
- {$?, 63},
- {$@, 64},
-
- {$[, 91},
- {$\\, 92},
- {$], 93},
- {$^, 94},
- {$_, 95},
-
- {${, 123},
- {$|, 124},
- {$}, 125},
- {$~, 126}
-]).
View
206 include/ucp_syntax.hrl
@@ -1,206 +0,0 @@
--record(ucp_header, {
- trn = "00",
- %% Transaction reference number, right justified with leading zero.
- len = "00000",
- %% Total number of IRA characters contained
- %% between stx and etx, right justified with leading zeros.
- o_r = "O",
- %% “O” indicates operation, “R” indicates result
- ot = "00"
- %% Operation Type:
- %% 01 Call input operation
- %% 02 Multiple address call input operation
- %% 03 Call input with supplementary services operation
- %% 30 SMS message transfer operation
- %% 31 SMT alert operation
- %% 5x 50-series, see chapter 5, 7
- %% 6x 60-series, see chapter 6, 7
- }).
-
--record(ucp_cmd_31,{
- adc = "", %% Address code for the SMT, maximum length is 16 digits.
- pid = "" %% SMT:
- %% 0100 Mobile Station
- %% 0122 Fax Group 3
- %% 0131 X.400
- %% 0138 Menu over PSTN
- %% 0139 PC appl. via PSTN
- %% 0339 PC appl. via X.25
- %% 0439 PC appl. via ISDN
- %% 0539 PC appl. via TCP/IP
- %% 0639.....PC appl. via abbreviated number
- }).
-
--record(ucp_cmd_5x, {
- adc = "", %% Address code recipient for the SM OadC 16 Num.
- %% String Address code originator
- %% If the OTOA field indicates alphanumeric OAdC.
- %% A 22 character string corresponds with a max. 11 character alphanumeric string.
- oadc = "", %% Address code originator, maximum length is 16 digits.
- ac = "", %% Authentication code originator (min 4 char., max 16 char)
- nrq = "", %% Notification Request 0 = NAdC not used 1 = NAdC used
- nadc = "", %% Notification Address
- nt = "", %% Notification Type1:
- %% Buffered message notification (BN),
- %% Delivery Notification (DN),
- %% Non-delivery notification (ND),
- %% 0 default value, 1 = DN, 2 = ND, 3 = DN+ND, 4 = BN, 5 = BN+DN, 6 = BN+ND, 7 = all.
- npid = "", %% Notification PID value:
- %% 0100 Mobile Station
- %% 0122 Fax Group 3
- %% 0131 X.400
- %% 0138 Menu over PSTN
- %% 0139 PC appl. over PSTN (E.164)
- %% 0339 PC appl. over X.25 (X.121)
- %% 0439 PC appl. over ISDN (E.164)
- %% 0539 PC appl. over TCP/IP
- lrq = "", %% Last Resort Address request: 0 = LRAd not used 1 = LRAd used
- lrad = "", %% Last Resort Address
- lpid = "", %% LRAd PID value:
- %% 0100 Mobile Station
- %% 0122 Fax Group 3
- %% 0131 X.400
- %% 0138 Menu over PSTN
- %% 0139 PC appl. over PSTN (E.164)
- %% 0339 PC appl. over X.25 (X.121)
- %% 0439 PC appl. over ISDN (E.164)
- %% 0539 PC appl. over TCP/IP
- dd = "", %% Deferred Delivery requested: 0 = DDT not used 1 = DDT used
- ddt = "", %% Deferred delivery time in DDMMYYHHmm
- vp = "", %% Validity period in DDMMYYHHmm
- rpid = "", %% Replace PID2, value 0000...0071, 0095,
- %% 0127(SIM Data Download), 0192...0255.
- scts = "", %% Service Centre Time Stamp in DDMMYYHHmmss.
- %% For a Short Message this is the time stamp of the Short Message itself.
- %% For a Notification this is the time stamp of the corresponding Short Message.
- dst = "", %% Delivery status:
- %% 0 = delivered
- %% 1 = buffered (see Rsn)
- %% 2 = not delivered (see Rsn)
- rsn = "", %% Reason code, value '000'...'255'.
- %% Code can be found in an SMSC configuration file witch can be
- %% changed by the operator. (See appendix A)
- dscts = "", %% Delivery time stamp in DDMMYYHHmmss.
- %% Indicates the actual time of delivery of the Short Message.
- mt="3", %% Message Type. Associated parameters depend on the value of MT.
- nb = "",
- msg = "",
- mms = "", %% More Messages to Send (to the same SME)
- pr = "", %% Priority Requested
- dcs = "", %% Deprecated. Data Coding scheme:
- %% 0 = default alphabet
- %% 1 = user defined data ('8 bit')
- mcls = "", %% Message Class:
- %% 0 = message class 0
- %% 1 = message class 1
- %% 2 = message class 2
- %% 3 = message class 3
- rpi = "", %% Reply Path:
- %% 1 = request
- %% 2 = response
- cpg = "", %% (reserved for Code Page)
- rply = "", %% (reserved for Reply type)
- otoa="1139", %% Originator Type Of Address:
- %% 1139 The OadC is set to NPI telephone and TON international.
- %% 5039 The OAdC contains an alphanumeric address (see OAdC and below).
- %% Leave OTOA empty for a numeric address in the OAdC.
- hplmn = "", %% Home PLMN Address
- xser = "", %% Extra Services
- %% With the XSer field one or more additional services can be specified.
- %% These services consist of IRA encoded data constructed in the
- %% following common format: TTLLDD...
- %% TT: represents two HEX characters defining the type of service.
- %% For a description of available services refer to section “Description Of XSer Extra Services”
- %% LL: represents two HEX characters defining the number of octets
- %% present in the data field DD.
- %% (Note that the number of HEX characters in the data DD is twice the number of octets)
- %% DD...: represents a stream of HEX characters defining the service specific data itself.
- %% If more than one additional service is to be specified in one message,
- %% this service information is concatenated without any separators, i.e.
- %% TT1LL1DD1...DD1TT2LL2DD2..DD2
- %% The above construction is designed such that in the
- %% future additional service types can be added to the XSer field.
- res4 = "", %% (reserved for future use)
- res5 = "" %% (reserved for future use)
- }).
-
--record(ucp_cmd_60, {
- oadc = "",
- %% Any valid X.121, E164, TCP/IP or abbreviated address, excluding prefixes
- oton = "", %% Originator Type of Numbering
- %% 1 = International number (starts with the country code)
- %% 2 = National number (default value if omitted)
- %% 6 = Abbreviated number (short number alias)
- onpi = "", %% Originator Numbering Plan Id:
- %% 1 = E.164 address (default value if omitted)
- %% 3 = X121 address
- %% 5 = Private (TCP/IP address/abbreviated number address)
- styp = "", %% Subtype of operation:
- %% 1 = open session
- %% 2 = reserved
- %% 3 = change password
- %% 4 = open provisioning session
- %% 5 = reserved
- %% 6 = change provisioning password
- pwd = "", %% Current password encoded into IRA characters,
- npwd = "", %% New password encoded into IRA characters
- vers = "", %% Version number 0100'
- ladc = "", %% Address to be filled in, removed from or checked in a
- %% VSMSC list, containing a valid X.121, E.164
- %% or TCP/IP address excluding prefixes
- lton = "", %% Type of Number list address:
- %% 1 = International number (starts with the country code)
- %% 2 = National number (default value if omitted)
- lnpi = "", %% Numbering Plan Id list address
- opid = "", %% Originator Protocol Identifier: 00 = Mobile station 39 = PC application
- res1 = ""
- }).
-
--record(ucp_cmd_61, {
- oadc = "", %% Any valid X.121, E164, TCP/IP or abbreviated address, excluding prefixes
- oton = "", %% Originator Type of Number:
- %% 1 = International number (starts with the country code)
- %% 2 = National number (default value if omitted)
- %% 6 = Abbreviated number (short number alias)
- onpi = "", %% Originator Numbering Plan Id:
- %% 1 = E.164 address (default value if omitted)
- %% 3 = X121 address
- %% 5 = Private (TCP/IP address/abbreviated number address)
- styp = "", %% Subtype of operation:
- %% 1 = open session
- %% 2 = reserved
- %% 3 = change password
- %% 4 = open provisioning session
- %% 5 = reserved
- %% 6 = change provisioning password
- pwd = "", %% Current password encoded into IRA characters,
- npwd = "", %% New password encoded into IRA characters
- vers = "", %% Version number 0100'
- ladc = "", %% Address to be filled in, removed from or checked in a
- %% VSMSC list, containing a valid X.121, E.164
- %% or TCP/IP address excluding prefixes
- lton = "", %% Type of Number list address:
- %% 1 = International number (starts with the country code)
- %% 2 = National number (default value if omitted)
- lnpi = "",
- res1 = "",
- res2 = ""
- }).
-
--record(short_ack,{
- ack = "A", %% Positive acknowledgement Char A
- sm = "" %% System message , String
- }).
-
--record(ack,{
- ack = "A", %% Positive acknowledgement Char A
- mvp = "",
- sm = "" %% System message , String
- }).
-
--record(nack, {
- nack = "N", %% Negative acknowledgement
- ec = "", %% Error Code, 2 Chars
- sm = "" %% System message , String
- }).
-
View
2  rebar.config
@@ -4,6 +4,8 @@
{lib_dirs, ["deps"]}.
{deps, [
+ {'ucp_common', ".*", {git, "git://github.com/jtendo/ucp_common.git",
+ "master"}},
{'lager', ".*", {git, "git://github.com/basho/lager.git", "master"}}
]}.
View
67 src/ucp_7bit.erl
@@ -1,67 +0,0 @@
--module(ucp_7bit).
-
--author("dawid.figiel@gmail.com").
--compile(export_all).
-
-%% 7-bit encoding
-%% ---------------------------------------------------------------------
-%% Function for converting string to 7-bit encoding according to:
-%% GSM 03.38 Version 5.3.0
-%% ---------------------------------------------------------------------
-%% Initial Function call: to_7bit(String).
-%% ---------------------------------------------------------------------
-%% Input: String containing only ASCII characters
-%% ---------------------------------------------------------------------
-%% Output: Binary encoded String
-%% ---------------------------------------------------------------------
-to_7bit([]) -> <<>>;
-to_7bit(String) -> to_7bit(list_to_binary(String),<<>>,1).
-
-to_7bit(<<Char1:8>>,<<>>,_Cntr) -> <<<<Char1>>/binary>>;
-to_7bit(<<_Char1:8>>,Out,8) -> Out;
-to_7bit(<< Char1:8>>,Out,7) ->
-%% << Out/binary,<<((Char1 bsr 6) bor 26)>>/binary >>;
- << Out/binary,<<((Char1 bsr 6) bor 64)>>/binary >>;
-to_7bit(<<Char1:8>>,Out,Cntr) ->
- << Out/binary,<<(Char1 bsr (Cntr - 1))>>/binary >>;
-to_7bit(<<_Char:8,In/binary>>,Out,8)->
- to_7bit(In,Out,1);
-to_7bit(<<Char1:8,Char2:8,In/binary>>,Out,Cntr)->
- SRChar1 = Char1 bsr (Cntr - 1),
- NewChar1 = <<Char2:Cntr,SRChar1:(8-Cntr)>>,
- to_7bit(<<<<Char2>>/binary,In/binary>>,<<Out/binary,NewChar1/binary>>,Cntr+1).
-
-%% 7-bit decoding
-%% ---------------------------------------------------------------------
-%% Function for converting 7-bit encoding to String according to:
-%% GSM 03.38 Version 5.3.0
-%% ---------------------------------------------------------------------
-%% Initial Function call: from_7bit(SevenBitEncodedBinary).
-%% ---------------------------------------------------------------------
-%% Input: Binary encoded String
-%% ---------------------------------------------------------------------
-%% Output: String containing only ASCII characters
-%% ---------------------------------------------------------------------
-from_7bit(List) when is_list(List) -> from_7bit(list_to_binary(List));
-from_7bit(<<>>) -> [];
-from_7bit(Bin) ->
- from_7bit(Bin,<<>>,<<>>,1).
-
-%%from_7bit(<<>>,<<13>>,Out,8) ->
-from_7bit(<<>>,<<32>>,Out,8) ->
- binary_to_list(Out);
-from_7bit(<<>>,<<CharN>>,Out,8) ->
- binary_to_list(<<Out/binary,CharN:8>>);
-from_7bit(<<>>,<<0>>,Out,_Cntr) ->
- binary_to_list(Out);
-from_7bit(<<>>,<<CharN>>,Out,Cntr) ->
- binary_to_list(<<Out/binary,0:(9-Cntr),CharN:(Cntr-1)>>);
-from_7bit(<<CharN:1,CharO:7,In/binary>>,<<CharI>>,Out,8) ->
- from_7bit(In,<<CharN>>,<<Out/binary,0:1,CharI:7,0:1,CharO:7>>,2);
-from_7bit(<<Byte:8,In/binary>>,<<>>,<<>>,1) ->
- CharN = Byte bsr 7,
- from_7bit(In,<<CharN>>,<<(Byte band 127)>>,2);
-from_7bit(<<Byte:8,In/binary>>,<<CharI>>,Out,Cntr) ->
- Char = (Byte bsl (Cntr - 1)) bor CharI,
- CharN = Byte bsr (8 - Cntr),
- from_7bit(In,<<CharN>>,<<Out/binary,0:1,Char:7>>,Cntr+1).
View
22 src/ucp_ira.erl
@@ -1,22 +0,0 @@
--module(ucp_ira).
--author('adam.rutkowski@jtendo.com').
--export([to/2]).
--include("ira.hrl").
-
-to(ira, Char) when is_integer(Char) ->
- case lists:keyfind(Char, 1, ?IRA) of
- {_, Ira} -> Ira;
- false -> Char
- end;
-to(ascii, Char) when is_integer(Char) ->
- case lists:keyfind(Char, 2, ?IRA) of
- {Ascii, _} -> Ascii;
- false -> Char
- end;
-to(Type, Str) when is_atom(Type), is_list(Str) ->
- lists:foldl(fun(Char, Acc) ->
- Acc ++ [to(Type, Char)]
- end, "", Str).
-
-
-
View
245 src/ucp_utils.erl
@@ -1,245 +0,0 @@
--module(ucp_utils).
--author('rafal.galczynski@jtendo.com').
--author('andrzej.trawinski@jtendo.com').
--author('adam.rutkowski@jtendo.com').
-
--include("ucp_syntax.hrl").
-
--export([decode_sender/2,
- compose_message/2,
- decode_message/1,
- wrap/1]).
-
--export([to_hexstr/1,
- hexstr_to_bin/1,
- hexstr_to_list/1]).
-
--define(STX, 16#02).
--define(ETX, 16#03).
--define(MIN_MESSAGE_TRN, 0).
--define(MAX_MESSAGE_TRN, 99).
--define(UCP_HEADER_LEN, 13).
--define(UCP_CHECKSUM_LEN, 2).
--define(UCP_SEPARATOR, $/).
-
-%%--------------------------------------------------------------------
-%% Convert string encoded in IRA into ASCII,
-%%--------------------------------------------------------------------
-from_ira(Str) ->
- ASCIMessage = lists:map(fun(X) -> ucp_ia5:gsm_to_ascii(X) end, Str),
- lists:flatten(ASCIMessage).
-
-%%--------------------------------------------------------------------
-%% Decode UCP OAdC field
-%%--------------------------------------------------------------------
-decode_sender(OTOA, OAdC) ->
- case OTOA of
- "5039" ->
- % Cut off sender length
- from_ira(
- ucp_7bit:from_7bit(
- hex:hexstr_to_list(
- string:substr(OAdC, 3))));
- _Other ->
- OAdC
- end.
-
-%%--------------------------------------------------------------------
-%% Compose whole UCP message
-%%--------------------------------------------------------------------
-compose_message(Header, Body) ->
- HF = lists:nthtail(1, tuple_to_list(Header)),
- BF = lists:nthtail(1, tuple_to_list(Body)),
- Len = length(string:join(lists:concat([HF, BF]), "/")) + 3, % 3: for delimiter and CRC
- LenS = string:right(integer_to_list(Len, 10), 5, $0),
- % Update header with proper len value
- NewHeader = Header#ucp_header{len = LenS},
- NHF = lists:nthtail(1, tuple_to_list(NewHeader)),
- % Build message
- Message = string:concat(string:join(lists:concat([NHF, BF]), "/"), "/"),
- CRC = calculate_crc(Message),
- string:concat(Message, CRC).
-
-%%--------------------------------------------------------------------
-%% Get 8 last significant bits of number
-%%--------------------------------------------------------------------
-get_8lsb(Integer) ->
- Integer band 255.
-
-%%--------------------------------------------------------------------
-%% Calculate CRC checksum for UCP Message
-%%--------------------------------------------------------------------
-calculate_crc(Data) when is_list(Data) ->
- string:right(integer_to_list(get_8lsb(lists:sum(Data)), 16), 2, $0).
-
-%%--------------------------------------------------------------------
-%% Decode binary into UCP message
-%%--------------------------------------------------------------------
-decode_message(Msg = <<?STX, BinHeader:?UCP_HEADER_LEN/binary, _/binary>>) ->
- Len = size(Msg) - 2,
- <<?STX, MsgS:Len/binary, ?ETX, Rest/binary>> = Msg,
- io:format("Received UCP message: ~s~n", [binary:bin_to_list(MsgS)]),
- % TODO: handle rest of the message
- case size(Rest) of
- 0 ->
- HeaderList = binary:bin_to_list(BinHeader),
- case list_to_tuple(re:split(HeaderList, "/", [{return, list}])) of
- {TRN, LEN, OR, OT} ->
- Header = #ucp_header{trn = TRN, len = LEN, o_r = OR, ot = OT},
- BodyLen = erlang:list_to_integer(LEN) - ?UCP_HEADER_LEN - ?UCP_CHECKSUM_LEN - 2,
- case Msg of
- <<?STX, _Header:?UCP_HEADER_LEN/binary, ?UCP_SEPARATOR,
- BinBody:BodyLen/binary, ?UCP_SEPARATOR,
- _CheckSum:?UCP_CHECKSUM_LEN/binary, ?ETX>> ->
- parse_body(Header, binary:bin_to_list(BinBody));
- _ ->
- {error, invalid_message}
- end;
- _ ->
- {error, invalid_header}
- end;
- _ -> {error, message_too_long}
- end;
-
-decode_message(_) ->
- {error, invalid_message}.
-
-%%--------------------------------------------------------------------
-%% Parse UCP operations
-%%--------------------------------------------------------------------
-parse_body(Header = #ucp_header{ot = OT, o_r = "O"}, Data) ->
- case {OT, field_split(Data)} of
- {"31", [ADC, PID]} ->
- Body = #ucp_cmd_31{adc = ADC, pid = PID},
- {ok, {Header, Body}};
- {"31", _} ->
- {error, {syntax_error, Header}};
- {"60", [OADC, OTON, ONPI, STYP, PWD, NPWD, VERS, LADC, LTON, LNPI, OPID, RES1]} ->
- Body = #ucp_cmd_60{ oadc = OADC,
- oton = OTON,
- onpi = ONPI,
- styp = STYP,
- pwd = ucp_ira:to(ascii, PWD),
- npwd = ucp_ira:to(ascii, NPWD),
- vers = VERS,
- ladc = LADC,
- lton = LTON,
- lnpi = LNPI,
- opid = OPID,
- res1 = RES1 },
- {ok, {Header, Body}};
- {"60", _} ->
- {error, {syntax_error, Header}};
- {"51", [ADC, OADC, AC, NRQ, NADC, NT, NPID,
- LRQ, LRAD, LPID, DD, DDT, VP, RPID, SCTS, DST, RSN, DSCTS,
- MT, NB, MSG, MMS, PR, DCS, MCLS, RPI, CPG, RPLY, OTOA, HPLMN,
- XSER, RES4, RES5]} ->
- Body = #ucp_cmd_5x{adc=ADC, oadc=OADC, ac=AC, nrq=NRQ, nadc=NADC,
- nt=NT, npid=NPID, lrq=LRQ, lrad=LRAD, lpid=LPID,
- dd=DD, ddt=DDT, vp=VP, rpid=RPID, scts=SCTS,
- dst=DST, rsn=RSN, dscts=DSCTS, mt=MT, nb=NB,
- msg=MSG, mms=MMS, pr=PR, dcs=DCS, mcls=MCLS,
- rpi=RPI, cpg=CPG, rply=RPLY, otoa=OTOA, hplmn=HPLMN,
- xser=XSER, res4=RES4, res5=RES5},
- {ok, {Header, Body}};
- {"51", _} ->
- {error, {syntax_error, Header}};
- {"52", [ADC, OADC, AC, NRQ, NADC, NT, NPID,
- LRQ, LRAD, LPID, DD, DDT, VP, RPID, SCTS, DST, RSN, DSCTS,
- MT, NB, MSG, MMS, PR, DCS, MCLS, RPI, CPG, RPLY, OTOA, HPLMN,
- XSER, RES4, RES5]} ->
- Body = #ucp_cmd_5x{adc=ADC, oadc=OADC, ac=AC, nrq=NRQ, nadc=NADC,
- nt=NT, npid=NPID, lrq=LRQ, lrad=LRAD, lpid=LPID,
- dd=DD, ddt=DDT, vp=VP, rpid=RPID, scts=SCTS,
- dst=DST, rsn=RSN, dscts=DSCTS, mt=MT, nb=NB,
- msg=MSG, mms=MMS, pr=PR, dcs=DCS, mcls=MCLS,
- rpi=RPI, cpg=CPG, rply=RPLY, otoa=OTOA, hplmn=HPLMN,
- xser=XSER, res4=RES4, res5=RES5},
- {ok, {Header, Body}};
- {"52", _} ->
- {error, {syntax_error, Header}};
- {"53", [ADC, OADC, AC, NRQ, NADC, NT, NPID,
- LRQ, LRAD, LPID, DD, DDT, VP, RPID, SCTS, DST, RSN, DSCTS,
- MT, NB, MSG, MMS, PR, DCS, MCLS, RPI, CPG, RPLY, OTOA, HPLMN,
- XSER, RES4, RES5]} ->
- Body = #ucp_cmd_5x{adc=ADC, oadc=OADC, ac=AC, nrq=NRQ, nadc=NADC,
- nt=NT, npid=NPID, lrq=LRQ, lrad=LRAD, lpid=LPID,
- dd=DD, ddt=DDT, vp=VP, rpid=RPID, scts=SCTS,
- dst=DST, rsn=RSN, dscts=DSCTS, mt=MT, nb=NB,
- msg=MSG, mms=MMS, pr=PR, dcs=DCS, mcls=MCLS,
- rpi=RPI, cpg=CPG, rply=RPLY, otoa=OTOA, hplmn=HPLMN,
- xser=XSER, res4=RES4, res5=RES5},
- {ok, {Header, Body}};
- {"53", _} ->
- {error, {syntax_error, Header}};
- _ ->
- {error, {unsupported_operation, Header}}
- end;
-
-
-%%--------------------------------------------------------------------
-%% Parse result messages
-%%--------------------------------------------------------------------
-parse_body(Header = #ucp_header{ot = OT, o_r = "R"}, Data) ->
- case {OT, field_split(Data)} of
- {_OT, ["A", SM]} -> % OT: 31, 60
- Body = #ack{sm = SM},
- {ok, {Header, Body}};
- {_OT, ["A", MVP, SM]} -> % OT: 51
- Body = #ack{sm = SM, mvp = MVP},
- {ok, {Header, Body}};
- {_OT, ["N", EC, SM]} -> % OT: 31, 51, 60
- Body = #nack{ec = EC, sm = SM},
- {ok, {Header, Body}};
- _ ->
- {error, unsupported_operation}
- end;
-
-parse_body(_Header, _Body) ->
- {error, unsupported_operation}.
-
-%%--------------------------------------------------------------------
-%% Utility functions
-%%--------------------------------------------------------------------
-
-wrap(Message) ->
- binary:list_to_bin([?STX, Message, ?ETX]).
-
-field_split(L) ->
- re:split(L, [?UCP_SEPARATOR], [{return,list}]).
-
-%%--------------------------------------------------------------------
-%% Hex mangling utils
-%%--------------------------------------------------------------------
-
-to_hexstr(Bin) when is_binary(Bin) ->
- to_hexstr(binary_to_list(Bin));
-
-to_hexstr(Int) when is_integer(Int) andalso Int > 255 ->
- to_hexstr(unicode, Int);
-
-to_hexstr(Int) when is_integer(Int) ->
- to_hexstr(ascii, Int);
-
-to_hexstr(L) when is_list(L) ->
- Type = case lists:any(fun(X) when X > 255 ->
- true;
- (_) ->
- false
- end, L) of
- true -> unicode;
- false -> ascii
- end,
- lists:flatten([to_hexstr(Type, X) || X <- L]).
-
-hexstr_to_bin(H) ->
- <<<<(erlang:list_to_integer([X], 16)):4>> || X <- H>>.
-
-hexstr_to_list(H) ->
- binary_to_list(hexstr_to_bin(H)).
-
-to_hexstr(ascii, Int) when is_integer(Int) ->
- string:right(integer_to_list(Int, 16), 2, $0);
-
-to_hexstr(unicode, Int) when is_integer(Int) ->
- string:right(integer_to_list(Int, 16), 4, $0).
Please sign in to comment.
Something went wrong with that request. Please try again.