int sol_platform_impl_get_machine_id(char id[SOL_STATIC_ARRAY_SIZE(33)]) { #ifdef CPUID_ID_LEN char cpuid[CPUID_ID_LEN]; /* Assume, for now, the the cpuid we get is a valid UUID */ cpuid_get(cpuid); serial_to_string(cpuid, CPUID_ID_LEN, id); return 0; #else return -ENOSYS; #endif }
int sol_platform_impl_get_serial_number(char **number) { #ifdef CPUID_ID_LEN char cpuid[CPUID_ID_LEN]; if (!number) return -EINVAL; *number = malloc(CPUID_ID_LEN * 2 + 1); SOL_NULL_CHECK(*number, -ENOMEM); cpuid_get(cpuid); serial_to_string(cpuid, CPUID_ID_LEN, *number); return 0; #else return -ENOSYS; #endif }
/*! \fn void process_uart_data() * \brief Read data from uart input buffer, decode the command and execute them. * */ void process_uart_data() { static char buffer[128]; static uint32_t buffer_index = 0; uint32_t count, i; // load everything from the buffer count = sw_uart_read_existing((uint8_t*) buffer, buffer_index, sizeof(buffer) / sizeof(uint8_t)); buffer_index += count; if (count != 0) { for (i = 0; i < buffer_index; i++) { uint32_t offset; if (buffer[i] == '#') { // make it string buffer[i] = '\0'; // "add xxxxxxxxxxxxxxxx" packet if ((strlen(buffer) == strlen("add xxxxxxxxxxxxxxxx")) && (memcmp(buffer, "add ", strlen("add ")) == 0)) { BOOL status; uint8_t serial[8]; // add serial code to the database command occured // check if the serial code is correct iButton serial code (family code and crc must be correcet) status = convert_ascii_serial_code_to_byte_array(serial, (uint8_t*) buffer + strlen("add ")); // add to the database if (status == TRUE) { database_add_serial(serial); sw_uart_send_str("done\r\n"); } else { sw_uart_send_str("error\r\n"); } } // "remove xxxxxxxxxxxxxxxx" else if ((strlen(buffer) >= strlen("remove xxxxxxxxxxxxxxxx")) && (memcmp(buffer, "remove ", strlen("remove ")) == 0)) { BOOL status; uint8_t serial[8]; // remove serial code from database command occured // check if the serial code is correct iButton serial code (family code and crc must be correcet) status = convert_ascii_serial_code_to_byte_array(serial, (uint8_t*) buffer + strlen("remove ")); // add to the database if (status == TRUE) { database_remove_serial(serial); sw_uart_send_str("done\r\n"); } else { sw_uart_send_str("error\r\n"); } } else if ((strlen(buffer) >= strlen("contain xxxxxxxxxxxxxxxx")) && (memcmp(buffer, "contain ", strlen("contain ")) == 0)) { BOOL status; uint8_t serial[8]; // remove serial code from database command occured // check if the serial code is correct iButton serial code (family code and crc must be correcet) status = convert_ascii_serial_code_to_byte_array(serial, (uint8_t*) buffer + strlen("contain ")); // add to the database if (status == TRUE) { if (database_contain(serial) == TRUE) { sw_uart_send_str("yes\r\n"); } else sw_uart_send_str("no\r\n"); } else { sw_uart_send_str("error\r\n"); } } // "erease" else if (strcmp(buffer, "erease") == 0) { // erease whole database command occured datab_erease(); sw_uart_send_str("done\r\n"); } // "getall" else if (strcmp(buffer, "getall") == 0) { uint32_t i; uint8_t serial[8]; char text[32]; for (i = 0; i < EEPROM_ENTRY_MAX_COUNT; i++) { // load entry datab_get_entry_at(serial, i); // check if it is valid serial number if ((serial[0] == 0x01) && (simple_crc(serial, 8) == 0)) { // send it via uartsimpleCrc serial_to_string(text, serial); sw_uart_send_str(text); sw_uart_send_str("\r\n"); } } } // "help" else if (strcmp(buffer, "help") == 0) { char help[] = "Not implemented yet\r\n"; sw_uart_send_str(help); } // shift buffer left offset = i; for (i = offset + 1; i < buffer_index; i++) { buffer[i - offset - 1] = buffer[i]; } buffer_index -= offset + 1; break; } } } }