Skip to content

Commit

Permalink
Allow the caller to set the size of the read
Browse files Browse the repository at this point in the history
  • Loading branch information
msantos committed Mar 7, 2012
1 parent 2d25488 commit b0af490
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/stk500.erl
Expand Up @@ -123,11 +123,19 @@ reset(FD) ->
version(FD) ->
reset(FD),

ok = serctl:write(FD, <<?Cmnd_STK_GET_PARAMETER, ?Parm_STK_SW_MAJOR, ?Sync_CRC_EOP>>),
{ok, <<?Resp_STK_INSYNC, Major, ?Resp_STK_OK>>} = read(FD, 3),
Size = [{size, 3}],

ok = serctl:write(FD, <<?Cmnd_STK_GET_PARAMETER, ?Parm_STK_SW_MINOR, ?Sync_CRC_EOP>>),
{ok, <<?Resp_STK_INSYNC, Minor, ?Resp_STK_OK>>} = read(FD, 3),
{ok, <<?Resp_STK_INSYNC, Major, ?Resp_STK_OK>>} = cmd(
FD,
<<?Cmnd_STK_GET_PARAMETER, ?Parm_STK_SW_MAJOR, ?Sync_CRC_EOP>>,
Size
),

{ok, <<?Resp_STK_INSYNC, Minor, ?Resp_STK_OK>>} = cmd(
FD,
<<?Cmnd_STK_GET_PARAMETER, ?Parm_STK_SW_MINOR, ?Sync_CRC_EOP>>,
Size
),

{Major, Minor}.

Expand Down Expand Up @@ -238,9 +246,11 @@ cmd(FD, Cmd, Opt) ->
{error, Error}
end.

cmd_1(FD, _Cmd, _Opt) ->
cmd_1(FD, _Cmd, Opt) ->

Size = proplists:get_value(size, Opt, 2),

case readx(FD, 2) of
case readx(FD, Size) of
{ok, Resp} ->
{ok, Resp};
{error, Error} ->
Expand Down

0 comments on commit b0af490

Please sign in to comment.