| 83 | } |
| 84 | |
| 85 | int get_byte_data_from_parameter(char* input, unsigned char* dest, size_t len) |
| 86 | { |
| 87 | const char* delim = " ,{}\n\r"; |
| 88 | |
| 89 | // Make a copy of the input string to avoid modifying the original |
| 90 | char* input_copy = strdup(input); |
| 91 | if (input_copy == NULL) { |
| 92 | // Memory allocation failed |
| 93 | return -1; |
| 94 | } |
| 95 | |
| 96 | // For each token in the string, parse and store in buf[]. |
| 97 | char* token = strtok(input, delim); |
| 98 | int i = 0; |
| 99 | while (token) { |
| 100 | char* endptr; |
| 101 | long int val = strtol(token, &endptr, 0); |
| 102 | |
| 103 | if (i >= len) |
| 104 | return -1; |
| 105 | |
| 106 | dest[i++] = val; |
| 107 | token = strtok(NULL, delim); |
| 108 | } |
| 109 | |
| 110 | return i; |
| 111 | } |
| 112 | |
| 113 | int get_float_data_from_parameter(char* input, float* dest, size_t len) |
| 114 | { |