2019-03-26 14:24:36 -04:00
|
|
|
//
|
|
|
|
// Created by nock on 26/03/19.
|
|
|
|
//
|
|
|
|
|
2019-05-01 12:25:19 -04:00
|
|
|
#include <errno.h>
|
2019-03-26 14:24:36 -04:00
|
|
|
#include <stdio.h>
|
2019-05-01 12:25:19 -04:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2019-03-26 14:24:36 -04:00
|
|
|
#include "image.h"
|
2019-05-01 12:25:19 -04:00
|
|
|
#include "nmgr.h"
|
|
|
|
|
|
|
|
void image_help(void){
|
|
|
|
printf("umcumgr image [list|upload|reset]\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *hex(char in) {
|
|
|
|
static char out[3] = {0};
|
|
|
|
static char lookup[] = {
|
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
|
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
|
|
|
|
};
|
|
|
|
out[0] = lookup[in >> 4];
|
|
|
|
out[1] = lookup[in & 0xf];
|
|
|
|
out[2] = 0;
|
|
|
|
return out;
|
|
|
|
}
|
2019-03-26 14:24:36 -04:00
|
|
|
|
2019-05-01 12:25:19 -04:00
|
|
|
void image_main(int fd, int argc, char **argv){
|
|
|
|
if (!strcmp(argv[1], "list")) {
|
|
|
|
int rc = write(fd, &(char []){SHELL_NLIP_PKT_START1, SHELL_NLIP_PKT_START2}, 2);
|
|
|
|
rc = write(fd, IMAGE_LIST_CMD, sizeof(IMAGE_LIST_CMD)-1);
|
|
|
|
if (rc < sizeof(IMAGE_LIST_CMD)-1) {
|
|
|
|
fprintf(stderr, "Failed to send command: %s", strerror(errno));
|
|
|
|
}
|
|
|
|
rc = write(fd, "\n", 1);
|
|
|
|
//return;
|
|
|
|
char tmp[256] = {0};
|
|
|
|
while (1) {
|
|
|
|
if (read(fd, &tmp, 255) < 0) {
|
|
|
|
if (errno == EAGAIN) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "Failed to read from port: %s\n", strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf("%s ", tmp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (!strcmp(argv[1], "upload")) {
|
|
|
|
printf("upload\n");
|
|
|
|
} else if (!strcmp(argv[1], "reset")) {
|
|
|
|
printf("reset\n");
|
|
|
|
} else {
|
|
|
|
image_help();
|
|
|
|
}
|
2019-03-26 14:24:36 -04:00
|
|
|
}
|