From 784076d51c3d95443b53416e593c38c612c14bbe Mon Sep 17 00:00:00 2001 From: systemcoder Date: Sun, 15 Mar 2020 08:34:44 +0000 Subject: Output as hex works, first version that produces results. --- H64E-2/h64e-model.c | 81 ++++++++++++++++++++++++++++++++++----------------- H64E-2/h64e-model.h | 27 ++++++++++------- H64E-2/h64e.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ H64E-2/h64e.h | 37 +++++++++++++++++++----- H64E-2/main.c | 70 ++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 250 insertions(+), 48 deletions(-) (limited to 'H64E-2') diff --git a/H64E-2/h64e-model.c b/H64E-2/h64e-model.c index b794f52..3bd0d1f 100644 --- a/H64E-2/h64e-model.c +++ b/H64E-2/h64e-model.c @@ -8,7 +8,7 @@ #include "h64e-model.h" -int h64e_si_init(H64E_stream_in *in, ssize_t size) +int h64e_si_init(H64E_stream_in *in, int32_t size) { in->size = size; in->cur_size = 0; @@ -17,42 +17,53 @@ int h64e_si_init(H64E_stream_in *in, ssize_t size) } //return amount of copied bytes -int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, size_t size) +int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, int32_t size) { - ssize_t start = in->cur_size; - ssize_t end = start+size; - ssize_t len = 0; + int32_t start = in->cur_size; + int32_t end = start+size; + int32_t len = 0; + if (end > in->size) { end = in->size; } len = end-start; - - memcpy(in->buf, data, len); - + memcpy(&in->buf[start], data, len); + in->cur_size += len; return (int)len; } -int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, size_t size) +int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, int32_t size) { - ssize_t len=0; + int32_t len=0; + int32_t i=0; - if (sizecur_size) + if (size < in->cur_size) { len = size; } else { len = in->cur_size; } - memcpy(data,in->buf,len); - memmove(in->buf,in->buf[len],len); + //memcpy(data,&in->buf[0],len); + for (i=0;ibuf[i]; + } + + memmove(&in->buf[0],&in->buf[len],len); in->cur_size -= len; return len; } -int h64e_so_init(H64E_stream_out *out, ssize_t size) +int h64e_si_len(H64E_stream_in *in) +{ + return in->cur_size; +} + +int h64e_so_init(H64E_stream_out *out, int32_t size) { out->size = size; out->cur_size = 0; @@ -60,37 +71,55 @@ int h64e_so_init(H64E_stream_out *out, ssize_t size) return 0; } -int h64e_so_data_in(H64E_stream_in *out, uint8_t *data, size_t size) +int h64e_so_data_in(H64E_stream_out *out, uint8_t *data, int32_t size) { - ssize_t start = out->cur_size; - ssize_t end = start+size; - ssize_t len = 0; + int32_t start = out->cur_size; + int32_t end = start+size; + int32_t len = 0; + if (end > out->size) { end = out->size; } len = end-start; - - memcpy(out->buf, data, len); - + memcpy(&out->buf[start], data, len); + out->cur_size += len; return (int)len; } -int h64e_so_data_out(H64E_stream_in *out, uint8_t *data, size_t size) +int h64e_so_data_out(H64E_stream_out *out, uint8_t *data, int32_t size) { - ssize_t len=0; + int32_t len=0; + int32_t i=0; - if (sizecur_size) + if (size < out->cur_size) { len = size; } else { len = out->cur_size; } - memcpy(data,out->buf,len); - memmove(out->buf,out->buf[len],len); + //memcpy(data,&in->buf[0],len); + for (i=0;ibuf[i]; + } + + memmove(&out->buf[0],&out->buf[len],len); out->cur_size -= len; return len; } + +int h64e_so_ready(H64E_stream_out *out) +{ + int ret = 0; + + return ret; +} + +int h64e_so_len(H64E_stream_out *out) +{ + return out->cur_size; +} diff --git a/H64E-2/h64e-model.h b/H64E-2/h64e-model.h index 516f8dc..761d327 100644 --- a/H64E-2/h64e-model.h +++ b/H64E-2/h64e-model.h @@ -10,30 +10,37 @@ #define h64e_model_h #include +#include #include typedef int (*trnf_clb)(char*); typedef struct H64E_stream_in { - int cur_size; - int size; + int32_t cur_size; + int32_t size; uint8_t *buf; } H64E_stream_in; //used to get collected data -int h64e_si_init(H64E_stream_in *in, ssize_t size); -int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, size_t size); -int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, size_t size); +int h64e_si_init(H64E_stream_in *in, int32_t size); +int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, int32_t size); +int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, int32_t size); +int h64e_si_len(H64E_stream_in *in); typedef struct H64E_stream_out { - int cur_size; - int size; + int32_t cur_size; + int32_t size; uint8_t *buf; } H64E_stream_out; //using to collect output formated data -int h64e_so_init(H64E_stream_out *out, ssize_t size); -int h64e_so_data_in(H64E_stream_in *out, uint8_t *data, size_t size); -int h64e_so_data_out(H64E_stream_in *out, uint8_t *data, size_t size); +int h64e_so_init(H64E_stream_out *out, int32_t size); +int h64e_so_data_in(H64E_stream_out *out, uint8_t *data, int32_t size); +int h64e_so_data_out(H64E_stream_out *out, uint8_t *data, int32_t size); +/* + * Trigger that buffer is full, or trigger new line in buffer + */ +int h64e_so_ready(H64E_stream_out *out); +int h64e_so_len(H64E_stream_out *out); #endif /* h64e_model_h */ diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c index 0072030..1e0662c 100644 --- a/H64E-2/h64e.c +++ b/H64E-2/h64e.c @@ -49,3 +49,86 @@ int h64e_destroy(H64E_t *s) { return 0; } + +int h64e_fmt_init( H64E_format *fs) +{ + memset(fs,0,sizeof(H64E_format)); + + return 0; +} + +/* + * out_size - allways give enought data to buffer otherwise it will partially write data, or flush data out more often + */ +int h64e_fmt_byte(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size) +{ + //printf("h64e_fmt_byte in %d out %d\n",in_size,out_size); + int ret=0; + int cur_size=0; + int i,j=0; + const int SZ=16; + uint8_t buf[SZ]; + int buf_sz=0; + int trail_size=0; + + for (i=0; icur_pos += 1; + //add space if configured + if (fs->f_space) + { + if (buf_sz+1cur_pos == fs->column_size) + { + if (fs->f_new_line) { + //set triger to newline + fs->t_new_line = 1; + fs->cur_pos = 0; + //set new line to buffer + if (buf_sz+11) + { + int cnv_num=-1; + //printf("Input Out\n"); + cnv_bytes = h64e_si_data_out(&sin, &buf_cnv_in[0], 1); + //cnv_total += cnv_bytes; + + + //Convert output data to desired format + //printf("Start converting to byte8\n"); + cnv_num = h64e_fmt_byte(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 512); + //printf("Conversation amount\n"); + //Push all data ot output buffer + //printf("Write to output stream data %d bytes\n",cnv_bytes); + cnv_bytes = h64e_so_data_in(&sout, &buf_cnv_out[0], cnv_num); + cnv_total += cnv_num; + //printf("Written bytes to output steam %d bytes %d bytes total\n",cnv_bytes,cnv_total); + } + + //Get data out of buffer + if ((out_bytes = h64e_so_len(&sout)) > 0) + { + out_bytes = h64e_so_data_out(&sout, &buf_out[0],512); + buf_out[out_bytes] = 0x00; + printf("%s",buf_out); + } + /* + out_bytes = h64e_so_data_out(&sout, &buf_out[0],512); + printf("Output out\n"); + out_total += out_bytes; + buf_out[out_bytes] = 0x00; + printf("%s\n",buf_out); + printf("Read converted data %d bytes %d total bytes\n",out_bytes,out_total); + */ + //printf("Total: in %d cnv %d out %d\n",in_total,cnv_total,out_total); + + //printf("Reading %d bytes\n",in_bytes); } + //check and empty all buffers + //deinit all structures h64e_destroy(&h64e); file_close(fd); -- cgit v1.2.3