Skip to content

Commit

Permalink
Change maximum size of hexdump command (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Baldanos authored and bvernoux committed Nov 13, 2016
1 parent 9c9bd6d commit 613bde1
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 58 deletions.
52 changes: 32 additions & 20 deletions hydrabus/hydrabus_mode_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos);
static int show(t_hydra_console *con, t_tokenline_parsed *p);
static void scan(t_hydra_console *con, t_tokenline_parsed *p);
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data);
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint32_t nb_data);

#define I2C_DEV_NUM (1)

Expand Down Expand Up @@ -103,7 +103,8 @@ static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
{
mode_config_proto_t* proto = &con->mode->proto;
float arg_float;
int arg_int, t, i;
uint32_t arg_u32;
int t, i;
bsp_status_t bsp_status;

for (t = token_pos; p->tokens[t]; t++) {
Expand Down Expand Up @@ -155,11 +156,11 @@ static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
/* Integer parameter. */
if (p->tokens[t + 1] == T_ARG_TOKEN_SUFFIX_INT) {
t += 2;
memcpy(&arg_int, p->buf + p->tokens[t], sizeof(int));
memcpy(&arg_u32, p->buf + p->tokens[t], sizeof(uint32_t));
} else {
arg_int = 1;
arg_u32 = 1;
}
dump(con, proto->buffer_rx, arg_int);
dump(con, proto->buffer_rx, arg_u32);
break;
default:
return t - token_pos;
Expand Down Expand Up @@ -262,29 +263,40 @@ static uint32_t read(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data)
return status;
}

static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data)
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint32_t nb_data)
{
int i;
uint32_t status;
uint8_t tmp;
uint32_t bytes_read = 0;
uint8_t i, tmp, to_rx;
mode_config_proto_t* proto = &con->mode->proto;

status = BSP_ERROR;
for(i = 0; i < nb_data; i++) {
if(proto->ack_pending) {
/* Send I2C ACK */
bsp_i2c_read_ack(I2C_DEV_NUM, TRUE);
while(bytes_read < nb_data){
/* using 240 to stay aligned in hexdump */
if((nb_data-bytes_read) >= 240) {
to_rx = 240;
} else {
to_rx = (nb_data-bytes_read);
}

status = bsp_i2c_master_read_u8(proto->dev_num, &tmp);
rx_data[i] = tmp;
/* Read 1 data */
if(status != BSP_OK)
break;
status = BSP_ERROR;
for(i = 0; i < to_rx; i++) {
if(proto->ack_pending) {
/* Send I2C ACK */
bsp_i2c_read_ack(I2C_DEV_NUM, TRUE);
}

proto->ack_pending = 1;
status = bsp_i2c_master_read_u8(proto->dev_num, &tmp);
rx_data[i] = tmp;
/* Read 1 data */
if(status != BSP_OK)
break;

proto->ack_pending = 1;
}
print_hex(con, rx_data, to_rx);

bytes_read += to_rx;
}
print_hex(con, rx_data, nb_data);
return status;
}

Expand Down
33 changes: 23 additions & 10 deletions hydrabus/hydrabus_mode_onewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos);
static int show(t_hydra_console *con, t_tokenline_parsed *p);
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data);
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint32_t nb_data);

static const char* str_prompt_onewire[] = {
"onewire1" PROMPT,
Expand Down Expand Up @@ -266,7 +266,8 @@ static int init(t_hydra_console *con, t_tokenline_parsed *p)
static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
{
mode_config_proto_t* proto = &con->mode->proto;
int arg_int, t;
uint32_t arg_u32;
int t;

for (t = token_pos; p->tokens[t]; t++) {
switch (p->tokens[t]) {
Expand All @@ -291,11 +292,11 @@ static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
/* Integer parameter. */
if (p->tokens[t + 1] == T_ARG_TOKEN_SUFFIX_INT) {
t += 2;
memcpy(&arg_int, p->buf + p->tokens[t], sizeof(int));
memcpy(&arg_u32, p->buf + p->tokens[t], sizeof(uint32_t));
} else {
arg_int = 1;
arg_u32 = 1;
}
dump(con, proto->buffer_rx, arg_int);
dump(con, proto->buffer_rx, arg_u32);
break;
case T_MSB_FIRST:
proto->dev_bit_lsb_msb = DEV_SPI_FIRSTBIT_MSB;
Expand Down Expand Up @@ -357,14 +358,26 @@ static uint32_t read(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data)
return BSP_OK;
}

static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data)
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint32_t nb_data)
{
int i;
uint32_t bytes_read = 0;
uint8_t i, to_rx;

while(bytes_read < nb_data){
/* using 240 to stay aligned in hexdump */
if((nb_data-bytes_read) >= 240) {
to_rx = 240;
} else {
to_rx = (nb_data-bytes_read);
}

for(i = 0; i < nb_data; i++) {
rx_data[i] = onewire_read_u8(con);
for(i = 0; i < to_rx; i++) {
rx_data[i] = onewire_read_u8(con);
}
print_hex(con, rx_data, to_rx);

bytes_read += to_rx;
}
print_hex(con, rx_data, nb_data);
return BSP_OK;
}

Expand Down
30 changes: 22 additions & 8 deletions hydrabus/hydrabus_mode_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos);
static int show(t_hydra_console *con, t_tokenline_parsed *p);
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data);
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint32_t nb_data);

static const char* str_pins_spi1= {
"CS: PA15\r\nSCK: PB3\r\nMISO: PB4\r\nMOSI: PB5\r\n"
Expand Down Expand Up @@ -130,6 +130,7 @@ static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
{
mode_config_proto_t* proto = &con->mode->proto;
float arg_float;
uint32_t arg_u32;
int arg_int, t, i;
bsp_status_t bsp_status;

Expand Down Expand Up @@ -249,11 +250,11 @@ static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
/* Integer parameter. */
if (p->tokens[t + 1] == T_ARG_TOKEN_SUFFIX_INT) {
t += 2;
memcpy(&arg_int, p->buf + p->tokens[t], sizeof(int));
memcpy(&arg_u32, p->buf + p->tokens[t], sizeof(uint32_t));
} else {
arg_int = 1;
arg_u32 = 1;
}
dump(con, proto->buffer_rx, arg_int);
dump(con, proto->buffer_rx, arg_u32);
break;
default:
return t - token_pos;
Expand Down Expand Up @@ -325,14 +326,27 @@ static uint32_t read(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data)
return status;
}

static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data)
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint32_t nb_data)
{
uint32_t status;
uint32_t bytes_read = 0;
uint8_t to_rx;
mode_config_proto_t* proto = &con->mode->proto;

status = bsp_spi_read_u8(proto->dev_num, rx_data, nb_data);
if (status == BSP_OK) {
print_hex(con, rx_data, nb_data);
while(bytes_read < nb_data){
/* using 240 to stay aligned in hexdump */
if((nb_data-bytes_read) >= 240) {
to_rx = 240;
} else {
to_rx = (nb_data-bytes_read);
}

status = bsp_spi_read_u8(proto->dev_num, rx_data, to_rx);
if (status == BSP_OK) {
print_hex(con, rx_data, to_rx);
}

bytes_read += to_rx;
}
return status;
}
Expand Down
33 changes: 23 additions & 10 deletions hydrabus/hydrabus_mode_threewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos);
static int show(t_hydra_console *con, t_tokenline_parsed *p);
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data);
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint32_t nb_data);

static threewire_config config;
static TIM_HandleTypeDef htim;
Expand Down Expand Up @@ -265,7 +265,8 @@ static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
{
mode_config_proto_t* proto = &con->mode->proto;
float arg_float;
int arg_int, t;
uint32_t arg_u32;
int t;

for (t = token_pos; p->tokens[t]; t++) {
switch (p->tokens[t]) {
Expand Down Expand Up @@ -306,11 +307,11 @@ static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
/* Integer parameter. */
if (p->tokens[t + 1] == T_ARG_TOKEN_SUFFIX_INT) {
t += 2;
memcpy(&arg_int, p->buf + p->tokens[t], sizeof(int));
memcpy(&arg_u32, p->buf + p->tokens[t], sizeof(uint32_t));
} else {
arg_int = 1;
arg_u32 = 1;
}
dump(con, proto->buffer_rx, arg_int);
dump(con, proto->buffer_rx, arg_u32);
break;
default:
return t - token_pos;
Expand Down Expand Up @@ -363,14 +364,26 @@ static uint32_t read(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data)
return BSP_OK;
}

static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data)
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint32_t nb_data)
{
int i;
uint32_t bytes_read = 0;
uint8_t i, to_rx;

while(bytes_read < nb_data){
/* using 240 to stay aligned in hexdump */
if((nb_data-bytes_read) >= 240) {
to_rx = 240;
} else {
to_rx = (nb_data-bytes_read);
}

for(i = 0; i < nb_data; i++) {
rx_data[i] = threewire_read_u8(con);
for(i = 0; i < to_rx; i++) {
rx_data[i] = threewire_read_u8(con);
}
print_hex(con, rx_data, to_rx);

bytes_read += to_rx;
}
print_hex(con, rx_data, nb_data);
return BSP_OK;
}

Expand Down
33 changes: 23 additions & 10 deletions hydrabus/hydrabus_mode_twowire.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos);
static int show(t_hydra_console *con, t_tokenline_parsed *p);
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data);
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint32_t nb_data);

static twowire_config config;
static TIM_HandleTypeDef htim;
Expand Down Expand Up @@ -280,7 +280,8 @@ static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
{
mode_config_proto_t* proto = &con->mode->proto;
float arg_float;
int arg_int, t;
uint32_t arg_u32;
int t;

for (t = token_pos; p->tokens[t]; t++) {
switch (p->tokens[t]) {
Expand Down Expand Up @@ -321,11 +322,11 @@ static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos)
/* Integer parameter. */
if (p->tokens[t + 1] == T_ARG_TOKEN_SUFFIX_INT) {
t += 2;
memcpy(&arg_int, p->buf + p->tokens[t], sizeof(int));
memcpy(&arg_u32, p->buf + p->tokens[t], sizeof(uint32_t));
} else {
arg_int = 1;
arg_u32 = 1;
}
dump(con, proto->buffer_rx, arg_int);
dump(con, proto->buffer_rx, arg_u32);
break;
default:
return t - token_pos;
Expand Down Expand Up @@ -378,14 +379,26 @@ static uint32_t read(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data)
return BSP_OK;
}

static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint8_t nb_data)
static uint32_t dump(t_hydra_console *con, uint8_t *rx_data, uint32_t nb_data)
{
int i;
uint32_t bytes_read = 0;
uint8_t i, to_rx;

for(i = 0; i < nb_data; i++) {
rx_data[i] = twowire_read_u8(con);
while(bytes_read < nb_data){
/* using 240 to stay aligned in hexdump */
if((nb_data-bytes_read) >= 240) {
to_rx = 240;
} else {
to_rx = (nb_data-bytes_read);
}

for(i = 0; i < to_rx; i++) {
rx_data[i] = twowire_read_u8(con);
}
print_hex(con, rx_data, to_rx);

bytes_read += to_rx;
}
print_hex(con, rx_data, nb_data);
return BSP_OK;
}

Expand Down

0 comments on commit 613bde1

Please sign in to comment.