aboutsummaryrefslogtreecommitdiff
path: root/pipe_image.c
diff options
context:
space:
mode:
Diffstat (limited to 'pipe_image.c')
-rw-r--r--pipe_image.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/pipe_image.c b/pipe_image.c
index 7e24ea7..7856571 100644
--- a/pipe_image.c
+++ b/pipe_image.c
@@ -3,6 +3,7 @@
#include <endian.h>
#include <stdint.h>
#include <sys/types.h>
+#include "RS-232/rs232.h"
#define ANSI_FG_RED "\033[0;31m"
@@ -12,7 +13,7 @@
int main(int argc, char **argv) {
char *image_file_name = argc > 1 ? argv[1] : "kernel7.img";
-
+
FILE *image_file_handle = fopen(image_file_name, "r");
if (!image_file_handle)
@@ -31,15 +32,21 @@ int main(int argc, char **argv) {
if (fseek(image_file_handle, 0, SEEK_SET))
err(-1, "error navigating through file");
+ //init comport
+ int comport=16;
+
+ if(RS232_OpenComport(comport,115200,"8N1",0)==1)
+ err(1,"Error opening comport");
+
+
uint32_t image_size_le = htole32(image_size);
- if (fwrite(&image_size_le, 4, 1, stdout) != 1)
- err(-1, "couldn't write to stdout");
+ if (RS232_SendBuf(comport,(unsigned char*)&image_size_le,4) == 1)
+ err(1, "error writing number to serial");
ssize_t bytes_left = image_size;
-
- char buf[1024];
+ unsigned char buf[1024];
while (bytes_left)
{
size_t bytes_read;
@@ -47,9 +54,11 @@ int main(int argc, char **argv) {
< 1)
err(-1, "error reading the file");
- if (fwrite(buf, bytes_read, 1, stdout) != 1)
- err(-1, "error writing to stdout");
+ if (RS232_SendBuf(comport,buf,bytes_read) == 1)
+ err(1, "error writing to serial");
bytes_left -= bytes_read;
}
+ RS232_CloseComport(comport);
+
}