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/main.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 5 deletions(-) (limited to 'H64E-2/main.c') diff --git a/H64E-2/main.c b/H64E-2/main.c index e1d3d7b..bd1910e 100644 --- a/H64E-2/main.c +++ b/H64E-2/main.c @@ -161,8 +161,10 @@ int main(int argc, const char * argv[]) { int param_offset = -1; char *fname = NULL; int fd; - int in_bytes = 0; - uint8_t buf[128]; + int in_bytes = 0, out_bytes=0, cnv_bytes=0; + int in_total = 0, out_total=0, cnv_total=0; + uint8_t buf_in[128+1],buf_cnv_in[128+1],buf_cnv_out[256+1],buf_out[512+1]; + int i=0; printf("H64E-2 Project started 1\n"); @@ -172,10 +174,14 @@ int main(int argc, const char * argv[]) { H64E_stream_out sout; h64e_init(&h64e); h64e_si_init(&sin, 128); - h64e_so_init(&sout, 128); + h64e_so_init(&sout, 512); h64e_set_input(&h64e, &sin); h64e_set_output(&h64e, &sout); + H64E_format int8_fmt; + + h64e_fmt_init(&int8_fmt); + //set all params from arguments /*get cmd args and set options */ @@ -244,13 +250,67 @@ int main(int argc, const char * argv[]) { } //register formats + //configure format of u8 to terminate on new line and have space between types + int8_fmt.f_space = 1; + int8_fmt.f_new_line = 1; + int8_fmt.column_size = 16; //do conversation, reading input and outputing - while ((in_bytes = file_read(fd,(char *)&buf,128)) != -1) + while ((in_bytes = file_read(fd,(char *)&buf_in,1)) != -1) { - printf("Reading %d bytes\n",in_bytes); + if (in_bytes == 0) + { + //printf("Stream ended\n"); + break; + } + + //write to input stream, connect all streams in a pipe + in_total += in_bytes; + //printf("Read from file %d bytes %d bytes total\n",in_bytes,in_total); + h64e_si_data_in(&sin, &buf_in[0], in_bytes); + + //if buffer have enought data then convert it + if (h64e_si_len(&sin)>1) + { + 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