blob: 9fde90e8afe7e8c0e798a89e1899e1af46c0953b [file] [log] [blame]
/*
Copyright (C) 2018 Open Networking Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include "utils.h"
std::string serial_number_to_str(bcmolt_serial_number* serial_number) {
#define SERIAL_NUMBER_SIZE 12
char buff[SERIAL_NUMBER_SIZE+1];
sprintf(buff, "%c%c%c%c%1X%1X%1X%1X%1X%1X%1X%1X",
serial_number->vendor_id.arr[0],
serial_number->vendor_id.arr[1],
serial_number->vendor_id.arr[2],
serial_number->vendor_id.arr[3],
serial_number->vendor_specific.arr[0]>>4 & 0x0f,
serial_number->vendor_specific.arr[0] & 0x0f,
serial_number->vendor_specific.arr[1]>>4 & 0x0f,
serial_number->vendor_specific.arr[1] & 0x0f,
serial_number->vendor_specific.arr[2]>>4 & 0x0f,
serial_number->vendor_specific.arr[2] & 0x0f,
serial_number->vendor_specific.arr[3]>>4 & 0x0f,
serial_number->vendor_specific.arr[3] & 0x0f);
return buff;
}
std::string vendor_specific_to_str(char const * const vendor_specific) {
char buff[SERIAL_NUMBER_SIZE+1];
sprintf(buff, "%1X%1X%1X%1X%1X%1X%1X%1X",
vendor_specific[0]>>4 & 0x0f,
vendor_specific[0] & 0x0f,
vendor_specific[1]>>4 & 0x0f,
vendor_specific[1] & 0x0f,
vendor_specific[2]>>4 & 0x0f,
vendor_specific[2] & 0x0f,
vendor_specific[3]>>4 & 0x0f,
vendor_specific[3] & 0x0f);
return buff;
}