summaryrefslogtreecommitdiff
path: root/H64E-2
diff options
context:
space:
mode:
Diffstat (limited to 'H64E-2')
-rw-r--r--H64E-2/h64e-model.c87
-rw-r--r--H64E-2/h64e-model.h13
-rw-r--r--H64E-2/h64e.c16
-rw-r--r--H64E-2/h64e.h8
-rw-r--r--H64E-2/main.c13
5 files changed, 125 insertions, 12 deletions
diff --git a/H64E-2/h64e-model.c b/H64E-2/h64e-model.c
index bfdfca2..b794f52 100644
--- a/H64E-2/h64e-model.c
+++ b/H64E-2/h64e-model.c
@@ -7,3 +7,90 @@
//
#include "h64e-model.h"
+
+int h64e_si_init(H64E_stream_in *in, ssize_t size)
+{
+ in->size = size;
+ in->cur_size = 0;
+ in->buf = malloc(size);
+ return 0;
+}
+
+//return amount of copied bytes
+int h64e_si_data_in(H64E_stream_in *in, uint8_t *data, size_t size)
+{
+ ssize_t start = in->cur_size;
+ ssize_t end = start+size;
+ ssize_t len = 0;
+ if (end > in->size)
+ {
+ end = in->size;
+ }
+
+ len = end-start;
+
+ memcpy(in->buf, data, len);
+
+ return (int)len;
+}
+
+int h64e_si_data_out(H64E_stream_in *in, uint8_t *data, size_t size)
+{
+ ssize_t len=0;
+
+ if (size<in->cur_size)
+ {
+ len = size;
+ } else {
+ len = in->cur_size;
+ }
+
+ memcpy(data,in->buf,len);
+ memmove(in->buf,in->buf[len],len);
+ in->cur_size -= len;
+
+ return len;
+}
+
+int h64e_so_init(H64E_stream_out *out, ssize_t size)
+{
+ out->size = size;
+ out->cur_size = 0;
+ out->buf = malloc(size);
+ return 0;
+}
+
+int h64e_so_data_in(H64E_stream_in *out, uint8_t *data, size_t size)
+{
+ ssize_t start = out->cur_size;
+ ssize_t end = start+size;
+ ssize_t len = 0;
+ if (end > out->size)
+ {
+ end = out->size;
+ }
+
+ len = end-start;
+
+ memcpy(out->buf, data, len);
+
+ return (int)len;
+}
+
+int h64e_so_data_out(H64E_stream_in *out, uint8_t *data, size_t size)
+{
+ ssize_t len=0;
+
+ if (size<out->cur_size)
+ {
+ len = size;
+ } else {
+ len = out->cur_size;
+ }
+
+ memcpy(data,out->buf,len);
+ memmove(out->buf,out->buf[len],len);
+ out->cur_size -= len;
+
+ return len;
+}
diff --git a/H64E-2/h64e-model.h b/H64E-2/h64e-model.h
index 41c4a4a..516f8dc 100644
--- a/H64E-2/h64e-model.h
+++ b/H64E-2/h64e-model.h
@@ -10,6 +10,7 @@
#define h64e_model_h
#include <stdio.h>
+#include <string.h>
typedef int (*trnf_clb)(char*);
@@ -20,9 +21,9 @@ typedef struct H64E_stream_in {
} 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, const uint8_t *data, size_t size);
+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);
typedef struct H64E_stream_out {
int cur_size;
@@ -31,8 +32,8 @@ typedef struct H64E_stream_out {
} 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, const uint8_t *data, size_t size);
+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);
#endif /* h64e_model_h */
diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c
index ddcfc5c..0072030 100644
--- a/H64E-2/h64e.c
+++ b/H64E-2/h64e.c
@@ -10,20 +10,32 @@
int h64e_init(H64E_t *s)
{
+ printf("init structure\n");
+ s->fmt.column_size = 16;
+ s->fmt.offset_addr = 0;
+ s->fmt.flag_offset = 0;
+ s->fmt.flag_no_group = 0;
+ s->fmt.group = H64E_G_BYTE;
+ s->fmt.flag_output = 0;
+ s->fmt.output_type = H64E_O_NONE;
+
+ s->sin = NULL;
+ s->sout = NULL;
return 0;
}
int h64e_check_param( H64E_t *fmt )
{
+ printf("Check parametrs set\n");
return 0;
}
-int h64e_set_input(H64E_t *s)
+int h64e_set_input(H64E_t *s, H64E_stream_in *sin)
{
return 0;
}
-int h64e_set_output(H64E_t *s)
+int h64e_set_output(H64E_t *s, H64E_stream_out *sout)
{
return 0;
}
diff --git a/H64E-2/h64e.h b/H64E-2/h64e.h
index f96edbd..397a36b 100644
--- a/H64E-2/h64e.h
+++ b/H64E-2/h64e.h
@@ -51,16 +51,16 @@ typedef struct H64E_format
typedef struct H64E_t
{
H64E_format fmt;
- H64E_stream_in sin;
- H64E_stream_out sout;
+ H64E_stream_in *sin;
+ H64E_stream_out *sout;
int fd_in;
int fd_out;
} H64E_t;
int h64e_init(H64E_t *s);
int h64e_check_param( H64E_t *s );
-int h64e_set_input(H64E_t *s);
-int h64e_set_output(H64E_t *s);
+int h64e_set_input(H64E_t *s, H64E_stream_in *sin);
+int h64e_set_output(H64E_t *s, H64E_stream_out *sout);
int h64e_convert(H64E_t *s);
int h64e_destroy(H64E_t *s);
diff --git a/H64E-2/main.c b/H64E-2/main.c
index 8830f1d..e1d3d7b 100644
--- a/H64E-2/main.c
+++ b/H64E-2/main.c
@@ -161,12 +161,20 @@ int main(int argc, const char * argv[]) {
int param_offset = -1;
char *fname = NULL;
int fd;
+ int in_bytes = 0;
+ uint8_t buf[128];
printf("H64E-2 Project started 1\n");
//initialise structure
H64E_t h64e;
+ H64E_stream_in sin;
+ H64E_stream_out sout;
h64e_init(&h64e);
+ h64e_si_init(&sin, 128);
+ h64e_so_init(&sout, 128);
+ h64e_set_input(&h64e, &sin);
+ h64e_set_output(&h64e, &sout);
//set all params from arguments
@@ -238,9 +246,14 @@ int main(int argc, const char * argv[]) {
//register formats
//do conversation, reading input and outputing
+ while ((in_bytes = file_read(fd,(char *)&buf,128)) != -1)
+ {
+ printf("Reading %d bytes\n",in_bytes);
+ }
//deinit all structures
h64e_destroy(&h64e);
+ file_close(fd);
printf("Ending Execution\n");
return 0;