Added vector sprint for bit

master
Xavier Arteaga 4 years ago committed by Xavier Arteaga
parent 818f3ea7c7
commit ff5fbbf0a0

@ -121,6 +121,7 @@ SRSLTE_API void srslte_vec_fprint_i(FILE* stream, const int* x, const uint32_t l
SRSLTE_API void srslte_vec_fprint_s(FILE* stream, const int16_t* x, const uint32_t len);
SRSLTE_API void srslte_vec_fprint_hex(FILE* stream, uint8_t* x, const uint32_t len);
SRSLTE_API void srslte_vec_sprint_hex(char* str, const uint32_t max_str_len, uint8_t* x, const uint32_t len);
SRSLTE_API void srslte_vec_sprint_bin(char* str, const uint32_t max_str_len, const uint8_t* x, const uint32_t len);
/* Saves/loads a vector to a file */
SRSLTE_API void srslte_vec_save_file(char* filename, const void* buffer, const uint32_t len);

@ -374,6 +374,36 @@ void srslte_vec_sprint_hex(char* str, const uint32_t max_str_len, uint8_t* x, co
str[max_str_len - 1] = 0;
}
void srslte_vec_sprint_bin(char* str, const uint32_t max_str_len, const uint8_t* x, const uint32_t len)
{
// Trim maximum size
uint32_t N = SRSLTE_MIN(max_str_len - 1, len);
// If the number of bits does not fit in the string, leave space for "..." if possible
if (N < len) {
if (N >= 3) {
N -= 3;
} else {
N = 0;
}
}
// Write 1s and 0s
for (uint32_t i = 0; i < N; i++) {
str[i] = x[i] == 0 ? '0' : '1';
}
// Write "..." if all 1s and 0s did not fit
if (N < len) {
for (uint32_t i = N; i < max_str_len - 1; i++) {
str[i] = '.';
}
str[max_str_len - 1] = 0;
} else {
str[N] = 0;
}
}
void srslte_vec_save_file(char* filename, const void* buffer, const uint32_t len)
{
FILE* f;

Loading…
Cancel
Save