imraa.c: Cleanup formatting of imraa.c
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -66,7 +66,8 @@ imraa_list_serialport()
|
|||||||
udev_enumerate_add_match_subsystem(enumerate, "tty");
|
udev_enumerate_add_match_subsystem(enumerate, "tty");
|
||||||
udev_enumerate_add_match_property(enumerate, "ID_VENDOR_ID", "8087");
|
udev_enumerate_add_match_property(enumerate, "ID_VENDOR_ID", "8087");
|
||||||
udev_enumerate_add_match_property(enumerate, "ID_MODEL_ID", "0ab6");
|
udev_enumerate_add_match_property(enumerate, "ID_MODEL_ID", "0ab6");
|
||||||
//udev_enumerate_add_match_property(enumerate, "ID_SERIAL", "Intel_ARDUINO_101_AE6642SQ55000RS");
|
// udev_enumerate_add_match_property(enumerate, "ID_SERIAL",
|
||||||
|
// "Intel_ARDUINO_101_AE6642SQ55000RS");
|
||||||
udev_enumerate_scan_devices(enumerate);
|
udev_enumerate_scan_devices(enumerate);
|
||||||
devices = udev_enumerate_get_list_entry(enumerate);
|
devices = udev_enumerate_get_list_entry(enumerate);
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ imraa_list_serialport()
|
|||||||
udev_enumerate_unref(enumerate);
|
udev_enumerate_unref(enumerate);
|
||||||
udev_unref(udev);
|
udev_unref(udev);
|
||||||
|
|
||||||
if(ret) {
|
if (ret) {
|
||||||
printf("Ardunio 101 Device Node Path: %s\n", ret);
|
printf("Ardunio 101 Device Node Path: %s\n", ret);
|
||||||
} else {
|
} else {
|
||||||
printf("Can't detect any Ardunio 101 Device on tty\n");
|
printf("Can't detect any Ardunio 101 Device on tty\n");
|
||||||
@@ -118,7 +119,7 @@ imraa_flash_101(const char* bin_path, const char* bin_file_name, const char* tty
|
|||||||
size_t bin_path_len = strlen(bin_path);
|
size_t bin_path_len = strlen(bin_path);
|
||||||
|
|
||||||
char* full_dfu_list = (char*) calloc((bin_path_len + strlen(dfu_list) + 1), sizeof(char));
|
char* full_dfu_list = (char*) calloc((bin_path_len + strlen(dfu_list) + 1), sizeof(char));
|
||||||
if(!full_dfu_list){
|
if (!full_dfu_list) {
|
||||||
printf("imraa_flash_101 can't allocate string buffer for dfu list\n");
|
printf("imraa_flash_101 can't allocate string buffer for dfu list\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -167,7 +168,7 @@ imraa_flash_101(const char* bin_path, const char* bin_file_name, const char* tty
|
|||||||
const char* dfu_option = " -v -a 7 -R";
|
const char* dfu_option = " -v -a 7 -R";
|
||||||
int buffersize = bin_path_len + strlen(dfu_upload) + strlen(bin_file_name) + strlen(dfu_option) + 1;
|
int buffersize = bin_path_len + strlen(dfu_upload) + strlen(bin_file_name) + strlen(dfu_option) + 1;
|
||||||
char* full_dfu_upload = calloc(buffersize, sizeof(char));
|
char* full_dfu_upload = calloc(buffersize, sizeof(char));
|
||||||
if(!full_dfu_upload){
|
if (!full_dfu_upload) {
|
||||||
printf("imraa_flash_101 can't allocate string buffer for dfu flash\n");
|
printf("imraa_flash_101 can't allocate string buffer for dfu flash\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@@ -272,11 +273,11 @@ imraa_handle_subplatform(struct json_object* jobj, bool force_update)
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stdout, "Starting to flash board\n");
|
fprintf(stdout, "Starting to flash board\n");
|
||||||
if(force_update) {
|
if (force_update) {
|
||||||
fprintf(stdout, "**Caution: force update mode**\n");
|
fprintf(stdout, "**Caution: force update mode**\n");
|
||||||
}
|
}
|
||||||
// dfu_loc = "/usr/bin";
|
// dfu_loc = "/usr/bin";
|
||||||
//TODO flash img checksum, and serialport validation?
|
// TODO flash img checksum, and serialport validation?
|
||||||
const char* detected_serialport = imraa_list_serialport();
|
const char* detected_serialport = imraa_list_serialport();
|
||||||
if (detected_serialport == NULL) {
|
if (detected_serialport == NULL) {
|
||||||
printf("No subplatform detected, skip flashing\n");
|
printf("No subplatform detected, skip flashing\n");
|
||||||
@@ -287,7 +288,7 @@ imraa_handle_subplatform(struct json_object* jobj, bool force_update)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
detected_serialport = "/dev/ttyACM0";
|
detected_serialport = "/dev/ttyACM0";
|
||||||
if ( dfu_loc != NULL && flash_loc != NULL && usbserial != NULL) {
|
if (dfu_loc != NULL && flash_loc != NULL && usbserial != NULL) {
|
||||||
if (imraa_flash_101(dfu_loc, flash_loc, detected_serialport) == 0) {
|
if (imraa_flash_101(dfu_loc, flash_loc, detected_serialport) == 0) {
|
||||||
imraa_write_lockfile(lockfile_loc, detected_serialport);
|
imraa_write_lockfile(lockfile_loc, detected_serialport);
|
||||||
} else {
|
} else {
|
||||||
@@ -312,12 +313,13 @@ imraa_handle_IO(struct json_object* jobj)
|
|||||||
if (json_object_object_get_ex(jobj, "IO", &ioarray) == true) {
|
if (json_object_object_get_ex(jobj, "IO", &ioarray) == true) {
|
||||||
ionum = json_object_array_length(ioarray);
|
ionum = json_object_array_length(ioarray);
|
||||||
printf("Length of IO array is %d\n", ionum);
|
printf("Length of IO array is %d\n", ionum);
|
||||||
mraa_io_obj = (mraa_io_objects_t*) malloc( ionum * sizeof(mraa_io_objects_t));
|
mraa_io_obj = (mraa_io_objects_t*) malloc(ionum * sizeof(mraa_io_objects_t));
|
||||||
if (!mraa_io_obj) {
|
if (!mraa_io_obj) {
|
||||||
printf("imraa_handle_IO malloc failed\n");
|
printf("imraa_handle_IO malloc failed\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
int index2 = -1;;//optional index for io configuration;
|
int index2 = -1;
|
||||||
|
; // optional index for io configuration;
|
||||||
if (json_object_is_type(ioarray, json_type_array)) {
|
if (json_object_is_type(ioarray, json_type_array)) {
|
||||||
for (i = 0; i < ionum; i++) {
|
for (i = 0; i < ionum; i++) {
|
||||||
struct json_object* ioobj = json_object_array_get_idx(ioarray, i);
|
struct json_object* ioobj = json_object_array_get_idx(ioarray, i);
|
||||||
@@ -337,10 +339,10 @@ imraa_handle_IO(struct json_object* jobj)
|
|||||||
if (json_object_object_get_ex(ioobj, "index2", &x) == true) {
|
if (json_object_object_get_ex(ioobj, "index2", &x) == true) {
|
||||||
index2 = json_object_get_int(x);
|
index2 = json_object_get_int(x);
|
||||||
}
|
}
|
||||||
//starting io configuration
|
// starting io configuration
|
||||||
if(strcmp(mraa_io_obj[i].type, "gpio") == 0){
|
if (strcmp(mraa_io_obj[i].type, "gpio") == 0) {
|
||||||
mraa_gpio_context gpio = NULL;
|
mraa_gpio_context gpio = NULL;
|
||||||
if(mraa_io_obj[i].raw){
|
if (mraa_io_obj[i].raw) {
|
||||||
printf("gpio raw init\n");
|
printf("gpio raw init\n");
|
||||||
gpio = mraa_gpio_init_raw(mraa_io_obj[i].index);
|
gpio = mraa_gpio_init_raw(mraa_io_obj[i].index);
|
||||||
} else {
|
} else {
|
||||||
@@ -353,7 +355,7 @@ imraa_handle_IO(struct json_object* jobj)
|
|||||||
}
|
}
|
||||||
} else if (strcmp(mraa_io_obj[i].type, "i2c") == 0) {
|
} else if (strcmp(mraa_io_obj[i].type, "i2c") == 0) {
|
||||||
mraa_i2c_context i2c = NULL;
|
mraa_i2c_context i2c = NULL;
|
||||||
if(mraa_io_obj[i].raw){
|
if (mraa_io_obj[i].raw) {
|
||||||
printf("i2c raw init\n");
|
printf("i2c raw init\n");
|
||||||
i2c = mraa_i2c_init_raw(mraa_io_obj[i].index);
|
i2c = mraa_i2c_init_raw(mraa_io_obj[i].index);
|
||||||
} else {
|
} else {
|
||||||
@@ -362,9 +364,9 @@ imraa_handle_IO(struct json_object* jobj)
|
|||||||
}
|
}
|
||||||
} else if (strcmp(mraa_io_obj[i].type, "pwm") == 0) {
|
} else if (strcmp(mraa_io_obj[i].type, "pwm") == 0) {
|
||||||
mraa_pwm_context pwm = NULL;
|
mraa_pwm_context pwm = NULL;
|
||||||
if(mraa_io_obj[i].raw){
|
if (mraa_io_obj[i].raw) {
|
||||||
printf("pwm raw init\n");
|
printf("pwm raw init\n");
|
||||||
pwm = mraa_pwm_init_raw(index2,mraa_io_obj[i].index);
|
pwm = mraa_pwm_init_raw(index2, mraa_io_obj[i].index);
|
||||||
} else {
|
} else {
|
||||||
printf("pwm init\n");
|
printf("pwm init\n");
|
||||||
pwm = mraa_pwm_init(mraa_io_obj[i].index);
|
pwm = mraa_pwm_init(mraa_io_obj[i].index);
|
||||||
@@ -375,7 +377,7 @@ imraa_handle_IO(struct json_object* jobj)
|
|||||||
}
|
}
|
||||||
} else if (strcmp(mraa_io_obj[i].type, "spi") == 0) {
|
} else if (strcmp(mraa_io_obj[i].type, "spi") == 0) {
|
||||||
mraa_spi_context spi = NULL;
|
mraa_spi_context spi = NULL;
|
||||||
if(mraa_io_obj[i].raw){
|
if (mraa_io_obj[i].raw) {
|
||||||
printf("spi raw init\n");
|
printf("spi raw init\n");
|
||||||
spi = mraa_spi_init_raw(mraa_io_obj[i].index, index2);
|
spi = mraa_spi_init_raw(mraa_io_obj[i].index, index2);
|
||||||
} else {
|
} else {
|
||||||
@@ -384,7 +386,7 @@ imraa_handle_IO(struct json_object* jobj)
|
|||||||
}
|
}
|
||||||
} else if (strcmp(mraa_io_obj[i].type, "uart") == 0) {
|
} else if (strcmp(mraa_io_obj[i].type, "uart") == 0) {
|
||||||
mraa_uart_context uart = NULL;
|
mraa_uart_context uart = NULL;
|
||||||
if(mraa_io_obj[i].raw){
|
if (mraa_io_obj[i].raw) {
|
||||||
printf("uart raw init\n");
|
printf("uart raw init\n");
|
||||||
uart = mraa_uart_init_raw(mraa_io_obj[i].label);
|
uart = mraa_uart_init_raw(mraa_io_obj[i].label);
|
||||||
} else {
|
} else {
|
||||||
@@ -494,7 +496,7 @@ main(int argc, char** argv)
|
|||||||
} else {
|
} else {
|
||||||
mraa_platform_t type = mraa_get_platform_type();
|
mraa_platform_t type = mraa_get_platform_type();
|
||||||
imraa_handle_subplatform(jobj, force_update);
|
imraa_handle_subplatform(jobj, force_update);
|
||||||
if( type == MRAA_NULL_PLATFORM || type == MRAA_UNKNOWN_PLATFORM) {
|
if (type == MRAA_NULL_PLATFORM || type == MRAA_UNKNOWN_PLATFORM) {
|
||||||
printf("imraa: Failed to do IO pinmuxing on null/unkown platform\n");
|
printf("imraa: Failed to do IO pinmuxing on null/unkown platform\n");
|
||||||
} else {
|
} else {
|
||||||
imraa_handle_IO(jobj);
|
imraa_handle_IO(jobj);
|
||||||
|
|||||||
Reference in New Issue
Block a user