diff options
Diffstat (limited to 'H64E-2/h64e.c')
-rw-r--r-- | H64E-2/h64e.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c index 15b883e..39884ca 100644 --- a/H64E-2/h64e.c +++ b/H64E-2/h64e.c @@ -569,6 +569,7 @@ int h64e_fmt_align( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t if (fs->f_output_types) { + /* if (fs->output_fmt == H64E_O_INT8) { int ii = in_data[i]; @@ -577,6 +578,9 @@ int h64e_fmt_align( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t unsigned int uu = in_data[i]; buf3_sz = snprintf((char *)&buf3[0], BUF_SZ, "%4u ", uu); } + */ + buf3_sz = h64e_fmt_type(fs, &in_data[i], in_size-i, buf3, BUF_SZ); + //printf("buf3_sz %d\n",buf3_sz); } } else { @@ -837,3 +841,113 @@ int h64e_fmt_hex(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *ou return buf_sz; } + +int h64e_fmt_type(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size) +{ + int buf_sz = -1; + int data_sz = -1; + int type = fs->output_fmt; + + //printf("!!!type %d\n",type); + switch (type) + { + case H64E_O_UINT8: + case H64E_O_INT8: + //data_sz = 1; + data_sz = 3; + break; + case H64E_O_UINT16: + case H64E_O_INT16: + //data_sz = 2; + data_sz = 5; + break; + case H64E_O_UINT32: + case H64E_O_INT32: + //data_sz = 4; + data_sz = 10; + break; + case H64E_O_UINT64: + case H64E_O_INT64: + //data_sz = 8; + data_sz = 19; + break; + } + + switch(type) + { + case H64E_O_INT8: + case H64E_O_INT16: + case H64E_O_INT32: + case H64E_O_INT64: + data_sz += 1; + break; + } + + if (out_size < data_sz) + { + printf("Output buffer too small h64e_fmt_type\n"); + return -1; + } + + switch (type) + { + case H64E_O_UINT8: + { + //printf("H64E_O_UINT8\n"); + uint8_t *u8 = (uint8_t *)in_data; + buf_sz = snprintf((char *)out_data, out_size, "%3u ", *u8); + break; + } + case H64E_O_INT8: + { + //printf("H64E_O_INT8\n"); + int8_t *i8 = (int8_t *)in_data; + buf_sz = snprintf((char *)out_data, out_size, "%4i ", *i8); + break; + } + case H64E_O_UINT16: + { + //printf("H64E_O_UINT16\n"); + uint16_t *u16 = (uint16_t *)in_data; + buf_sz = snprintf((char *)out_data, out_size, "%5hu ", *u16); + break; + } + case H64E_O_INT16: + { + //printf("H64E_O_INT16\n"); + int16_t *i16 = (int16_t *)in_data; + buf_sz = snprintf((char *)out_data, out_size, "%6hd ", *i16); + break; + } + case H64E_O_UINT32: + { + //printf("H64E_O_UINT32\n"); + uint32_t *u32 = (uint32_t *)in_data; + buf_sz = snprintf((char *)out_data, out_size, "%10u ", *u32); + break; + } + case H64E_O_INT32: + { + //printf("H64E_O_INT32\n"); + int32_t *i32 = (int32_t *)in_data; + buf_sz = snprintf((char *)out_data, out_size, "%11d ", *i32); + break; + } + case H64E_O_UINT64: + { + //printf("H64E_O_UINT64\n"); + uint64_t *u64 = (uint64_t *)in_data; + buf_sz = snprintf((char *)out_data, out_size, "%20llu ", *u64); + break; + } + case H64E_O_INT64: + { + //printf("H64E_O_INT64\n"); + int64_t *i64 = (int64_t *)in_data; + buf_sz = snprintf((char *)out_data, out_size, "%20lld ", *i64); + break; + } + } + + return buf_sz; +} |