Display pldmtool platform command output in JSON
./pldmtool platform GetPDR -d 17
{
"nextRecordHandle": 18,
"responseCount": 19,
"recordHandle": 17,
"PDRHeaderVersion": 1,
"PDRType": "Terminus Locator PDR",
"recordChangeNumber": 0,
"dataLength": 9,
"PLDMTerminusHandle": 1,
"validity": "valid",
"TID": 1,
"containerID": 0,
"terminusLocatorType": "MCTP_EID",
"terminusLocatorValueSize": 1,
"EID": 8
}
./pldmtool platform GetPDR -d 1
{
"nextRecordHandle": 2,
"responseCount": 20,
"recordHandle": 1,
"PDRHeaderVersion": 1,
"PDRType": "FRU Record Set PDR",
"recordChangeNumber": 0,
"dataLength": 10,
"PLDMTerminusHandle": 0,
"FRURecordSetIdentifier": 1,
"entityType": "System (logical)",
"entityInstanceNumber": 1,
"containerID": 0
}
./pldmtool platform GetPDR -d 15
{
"nextRecordHandle": 16,
"responseCount": 26,
"recordHandle": 15,
"PDRHeaderVersion": 1,
"PDRType": "Entity Association PDR",
"recordChangeNumber": 0,
"dataLength": 16,
"containerID": 2,
"associationType": "Physical",
"containerEntityType": "System chassis (main enclosure)",
"containerEntityInstanceNumber": 1,
"containerEntityContainerID": 1,
"containedEntityCount": 1,
"containedEntityType[1]": "System Board",
"containedEntityInstanceNumber[1]": 1,
"containedEntityContainerID[1]": 2
./pldmtool platform GetPDR -d 18
{
"nextRecordHandle": 19,
"responseCount": 29,
"recordHandle": 18,
"PDRHeaderVersion": 1,
"PDRType": "State Effecter PDR",
"recordChangeNumber": 0,
"dataLength": 19,
"PLDMTerminusHandle": 1,
"effecterID": 1,
"entityType": "Virtual Machine Manager",
"entityInstanceNumber": 0,
"containerID": 0,
"effecterSemanticID": 0,
"effecterInit": "noInit",
"effecterDescriptionPDR": false,
"compositeEffecterCount": 1,
"stateSetID": "Boot Progress(196)",
"possibleStatesSize": 1,
"possibleStates": " 1 1 2"
}
./pldmtool platform GetPDR -d 21
{
"nextRecordHandle": 0,
"responseCount": 84,
"recordHandle": 21,
"PDRHeaderVersion": 1,
"PDRType": "Numeric Effecter PDR",
"recordChangeNumber": 0,
"dataLength": 74,
"PLDMTerminusHandle": 0,
"effecterID": 4,
"entityType": 193,
"entityInstanceNumber": 0,
"containerID": 0,
"effecterSemanticID": 0,
"effecterInit": 0,
"effecterAuxiliaryNames": false,
"baseUnit": 72,
"unitModifier": 0,
"rateUnit": 0,
"baseOEMUnitHandle": 0,
"auxUnit": 0,
"auxUnitModifier": 0,
"auxrateUnit": 0,
"auxOEMUnitHandle": 0,
"isLinear": true,
"effecterDataSize": 4,
"resolution": 1,
"offset": 0,
"accuracy": 0,
"plusTolerance": 0,
"minusTolerance": 0,
"stateTransitionInterval": 0,
"TransitionInterval": 0,
"maxSettable": 0,
"minSettable": 0,
"rangeFieldFormat": 3,
"rangeFieldSupport": 0,
"nominalValue": 0,
"normalMax": 0,
"normalMin": 0,
"ratedMax": 0,
"ratedMin": 0
}
./pldmtool platform SetStateEffecterStates -i 1 -c 1 -d 1 1
{
"Response": "SUCCESS"
}
./pldmtool platform SetNumericEffecterValue -i 4 -s 4 -d 2100000000
{
"Response": "SUCCESS"
}
Change-Id: I4572adb9a033435ddf05a5eb4b2ea3dbd0f3070f
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/pldmtool/pldm_platform_cmd.cpp b/pldmtool/pldm_platform_cmd.cpp
index d54ec20..9bd0ccb 100644
--- a/pldmtool/pldm_platform_cmd.cpp
+++ b/pldmtool/pldm_platform_cmd.cpp
@@ -18,6 +18,8 @@
} // namespace
+using ordered_json = nlohmann::ordered_json;
+
class GetPDR : public CommandInterface
{
public:
@@ -178,7 +180,7 @@
auto typeString = std::to_string(type);
try
{
- return pdrType.at(type) + "(" + typeString + ")";
+ return pdrType.at(type);
}
catch (const std::out_of_range& e)
{
@@ -186,53 +188,48 @@
}
}
- void printCommonPDRHeader(const pldm_pdr_hdr* hdr)
+ void printCommonPDRHeader(const pldm_pdr_hdr* hdr, ordered_json& output)
{
- std::cout << "recordHandle: " << hdr->record_handle << std::endl;
- std::cout << "PDRHeaderVersion: " << unsigned(hdr->version)
- << std::endl;
- std::cout << "PDRType: " << getPDRType(hdr->type) << std::endl;
- std::cout << "recordChangeNumber: " << hdr->record_change_num
- << std::endl;
- std::cout << "dataLength: " << hdr->length << std::endl << std::endl;
+ output["recordHandle"] = hdr->record_handle;
+ output["PDRHeaderVersion"] = unsigned(hdr->version);
+ output["PDRType"] = getPDRType(hdr->type);
+ output["recordChangeNumber"] = hdr->record_change_num;
+ output["dataLength"] = hdr->length;
}
- void printPossibleStates(uint8_t possibleStatesSize,
- const bitfield8_t* states)
+ std::string printPossibleStates(uint8_t possibleStatesSize,
+ const bitfield8_t* states)
{
uint8_t possibleStatesPos{};
- auto printStates = [&possibleStatesPos](const bitfield8_t& val) {
+ std::string data;
+ auto printStates = [&possibleStatesPos, &data](const bitfield8_t& val) {
+ std::stringstream pstates;
for (int i = 0; i < CHAR_BIT; i++)
{
if (val.byte & (1 << i))
{
- std::cout << " " << (possibleStatesPos * CHAR_BIT + i);
+ pstates << " " << (possibleStatesPos * CHAR_BIT + i);
+ data.append(pstates.str());
}
}
possibleStatesPos++;
};
std::for_each(states, states + possibleStatesSize, printStates);
+ return data;
}
- void printStateSensorPDR(const uint8_t* data)
+ void printStateSensorPDR(const uint8_t* data, ordered_json& output)
{
auto pdr = reinterpret_cast<const pldm_state_sensor_pdr*>(data);
-
- std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle
- << std::endl;
- std::cout << "sensorID: " << pdr->sensor_id << std::endl;
- std::cout << "entityType: " << getEntityName(pdr->entity_type)
- << std::endl;
- std::cout << "entityInstanceNumber: " << pdr->entity_instance
- << std::endl;
- std::cout << "containerID: " << pdr->container_id << std::endl;
- std::cout << "sensorInit: " << sensorInit[pdr->sensor_init]
- << std::endl;
- std::cout << "sensorAuxiliaryNamesPDR: "
- << (pdr->sensor_auxiliary_names_pdr ? "true" : "false")
- << std::endl;
- std::cout << "compositeSensorCount: "
- << unsigned(pdr->composite_sensor_count) << std::endl;
+ output["PLDMTerminusHandle"] = pdr->terminus_handle;
+ output["sensorID"] = pdr->sensor_id;
+ output["entityType"] = getEntityName(pdr->entity_type);
+ output["entityInstanceNumber"] = pdr->entity_instance;
+ output["containerID"] = pdr->container_id;
+ output["sensorInit"] = sensorInit[pdr->sensor_init];
+ output["sensorAuxiliaryNamesPDR"] =
+ (pdr->sensor_auxiliary_names_pdr ? true : false);
+ output["compositeSensorCount"] = unsigned(pdr->composite_sensor_count);
auto statesPtr = pdr->possible_states;
auto compositeSensorCount = pdr->composite_sensor_count;
@@ -241,13 +238,10 @@
{
auto state = reinterpret_cast<const state_sensor_possible_states*>(
statesPtr);
- std::cout << "stateSetID: " << getStateSetName(state->state_set_id)
- << std::endl;
- std::cout << "possibleStatesSize: "
- << unsigned(state->possible_states_size) << std::endl;
- std::cout << "possibleStates:";
- printPossibleStates(state->possible_states_size, state->states);
- std::cout << std::endl;
+ output["stateSetID"] = getStateSetName(state->state_set_id);
+ output["possibleStatesSize"] = getStateSetName(state->state_set_id);
+ output["possibleStates"] =
+ printPossibleStates(state->possible_states_size, state->states);
if (compositeSensorCount)
{
@@ -257,7 +251,7 @@
}
}
- void printPDRFruRecordSet(uint8_t* data)
+ void printPDRFruRecordSet(uint8_t* data, ordered_json& output)
{
if (data == NULL)
{
@@ -268,17 +262,14 @@
pldm_pdr_fru_record_set* pdr =
reinterpret_cast<pldm_pdr_fru_record_set*>(data);
- std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle
- << std::endl;
- std::cout << "FRURecordSetIdentifier: " << pdr->fru_rsi << std::endl;
- std::cout << "entityType: " << getEntityName(pdr->entity_type)
- << std::endl;
- std::cout << "entityInstanceNumber: " << pdr->entity_instance_num
- << std::endl;
- std::cout << "containerID: " << pdr->container_id << std::endl;
+ output["PLDMTerminusHandle"] = unsigned(pdr->terminus_handle);
+ output["FRURecordSetIdentifier"] = unsigned(pdr->fru_rsi);
+ output["entityType"] = getEntityName(pdr->entity_type);
+ output["entityInstanceNumber"] = unsigned(pdr->entity_instance_num);
+ output["containerID"] = unsigned(pdr->container_id);
}
- void printPDREntityAssociation(uint8_t* data)
+ void printPDREntityAssociation(uint8_t* data, ordered_json& output)
{
const std::map<uint8_t, const char*> assocationType = {
{PLDM_ENTITY_ASSOCIAION_PHYSICAL, "Physical"},
@@ -294,240 +285,170 @@
pldm_pdr_entity_association* pdr =
reinterpret_cast<pldm_pdr_entity_association*>(data);
- std::cout << "containerID: " << pdr->container_id << std::endl;
- std::cout << "associationType: "
- << assocationType.at(pdr->association_type) << std::endl
- << std::endl;
-
- std::cout << "containerEntityType: "
- << getEntityName(pdr->container.entity_type) << std::endl;
- std::cout << "containerEntityInstanceNumber: "
- << pdr->container.entity_instance_num << std::endl;
- std::cout << "containerEntityContainerID: "
- << pdr->container.entity_container_id << std::endl;
-
- std::cout << "containedEntityCount: "
- << static_cast<unsigned>(pdr->num_children) << std::endl
- << std::endl;
+ output["containerID"] = int(pdr->container_id);
+ output["associationType"] = assocationType.at(pdr->association_type);
+ output["containerEntityType"] =
+ getEntityName(pdr->container.entity_type);
+ output["containerEntityInstanceNumber"] =
+ int(pdr->container.entity_instance_num);
+ output["containerEntityContainerID"] =
+ int(pdr->container.entity_container_id);
+ output["containedEntityCount"] =
+ static_cast<unsigned>(pdr->num_children);
auto child = reinterpret_cast<pldm_entity*>(&pdr->children[0]);
for (int i = 0; i < pdr->num_children; ++i)
{
- std::cout << "containedEntityType[" << i + 1
- << "]: " << getEntityName(child->entity_type)
- << std::endl;
- std::cout << "containedEntityInstanceNumber[" << i + 1
- << "]: " << child->entity_instance_num << std::endl;
- std::cout << "containedEntityContainerID[" << i + 1
- << "]: " << child->entity_container_id << std::endl
- << std::endl;
+ output.emplace("containedEntityType[" + std::to_string(i + 1) + "]",
+ getEntityName(child->entity_type));
+ output.emplace("containedEntityInstanceNumber[" +
+ std::to_string(i + 1) + "]",
+ unsigned(child->entity_instance_num));
+ output.emplace("containedEntityContainerID[" +
+ std::to_string(i + 1) + "]",
+ unsigned(child->entity_container_id));
+
++child;
}
}
- void printNumericEffecterPDR(uint8_t* data)
+ void printNumericEffecterPDR(uint8_t* data, ordered_json& output)
{
struct pldm_numeric_effecter_value_pdr* pdr =
(struct pldm_numeric_effecter_value_pdr*)data;
- std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle
- << std::endl;
- std::cout << "effecterID: " << pdr->effecter_id << std::endl;
- std::cout << "entityType: " << pdr->entity_type << std::endl;
- std::cout << "entityInstanceNumber: " << pdr->entity_instance
- << std::endl;
- std::cout << "containerID: " << pdr->container_id << std::endl;
- std::cout << "effecterSemanticID: " << pdr->effecter_semantic_id
- << std::endl;
- std::cout << "effecterInit: " << unsigned(pdr->effecter_init)
- << std::endl;
- std::cout << "effecterAuxiliaryNames: "
- << (unsigned(pdr->effecter_auxiliary_names) ? "true"
- : "false")
- << std::endl;
- std::cout << "baseUnit: " << unsigned(pdr->base_unit) << std::endl;
- std::cout << "unitModifier: " << unsigned(pdr->unit_modifier)
- << std::endl;
- std::cout << "rateUnit: " << unsigned(pdr->rate_unit) << std::endl;
- std::cout << "baseOEMUnitHandle: "
- << unsigned(pdr->base_oem_unit_handle) << std::endl;
- std::cout << "auxUnit: " << unsigned(pdr->aux_unit) << std::endl;
- std::cout << "auxUnitModifier: " << unsigned(pdr->aux_unit_modifier)
- << std::endl;
- std::cout << "auxrateUnit: " << unsigned(pdr->aux_rate_unit)
- << std::endl;
- std::cout << "auxOEMUnitHandle: " << unsigned(pdr->aux_oem_unit_handle)
- << std::endl;
- std::cout << "isLinear: "
- << (unsigned(pdr->is_linear) ? "true" : "false") << std::endl;
- std::cout << "effecterDataSize: " << unsigned(pdr->effecter_data_size)
- << std::endl;
- std::cout << "resolution: " << pdr->resolution << std::endl;
- std::cout << "offset: " << pdr->offset << std::endl;
- std::cout << "accuracy: " << pdr->accuracy << std::endl;
- std::cout << "plusTolerance: " << unsigned(pdr->plus_tolerance)
- << std::endl;
- std::cout << "minusTolerance: " << unsigned(pdr->minus_tolerance)
- << std::endl;
- std::cout << "stateTransitionInterval: "
- << pdr->state_transition_interval << std::endl;
- std::cout << "TransitionInterval: " << pdr->transition_interval
- << std::endl;
+
+ output["PLDMTerminusHandle"] = int(pdr->terminus_handle);
+ output["effecterID"] = int(pdr->effecter_id);
+ output["entityType"] = int(pdr->entity_type);
+ output["entityInstanceNumber"] = int(pdr->entity_instance);
+ output["containerID"] = int(pdr->container_id);
+ output["effecterSemanticID"] = int(pdr->effecter_semantic_id);
+ output["effecterInit"] = unsigned(pdr->effecter_init);
+ output["effecterAuxiliaryNames"] =
+ (unsigned(pdr->effecter_auxiliary_names) ? true : false);
+ output["baseUnit"] = unsigned(pdr->base_unit);
+ output["unitModifier"] = unsigned(pdr->unit_modifier);
+ output["rateUnit"] = unsigned(pdr->rate_unit);
+ output["baseOEMUnitHandle"] = unsigned(pdr->base_oem_unit_handle);
+ output["auxUnit"] = unsigned(pdr->aux_unit);
+ output["auxUnitModifier"] = unsigned(pdr->aux_unit_modifier);
+ output["auxrateUnit"] = unsigned(pdr->aux_rate_unit);
+ output["auxOEMUnitHandle"] = unsigned(pdr->aux_oem_unit_handle);
+ output["isLinear"] = (unsigned(pdr->is_linear) ? true : false);
+ output["effecterDataSize"] = unsigned(pdr->effecter_data_size);
+ output["resolution"] = unsigned(pdr->resolution);
+ output["offset"] = unsigned(pdr->offset);
+ output["accuracy"] = unsigned(pdr->accuracy);
+ output["plusTolerance"] = unsigned(pdr->plus_tolerance);
+ output["minusTolerance"] = unsigned(pdr->minus_tolerance);
+ output["stateTransitionInterval"] =
+ unsigned(pdr->state_transition_interval);
+ output["TransitionInterval"] = unsigned(pdr->transition_interval);
+
switch (pdr->effecter_data_size)
{
case PLDM_EFFECTER_DATA_SIZE_UINT8:
- std::cout << "maxSettable: "
- << unsigned(pdr->max_set_table.value_u8) << std::endl;
- std::cout << "minSettable: "
- << unsigned(pdr->min_set_table.value_u8) << std::endl;
+ output["maxSettable"] = unsigned(pdr->max_set_table.value_u8);
+ output["minSettable"] = unsigned(pdr->min_set_table.value_u8);
break;
case PLDM_EFFECTER_DATA_SIZE_SINT8:
- std::cout << "maxSettable: "
- << unsigned(pdr->max_set_table.value_s8) << std::endl;
- std::cout << "minSettable: "
- << unsigned(pdr->min_set_table.value_s8) << std::endl;
+ output["maxSettable"] = unsigned(pdr->max_set_table.value_s8);
+ output["minSettable"] = unsigned(pdr->min_set_table.value_s8);
break;
case PLDM_EFFECTER_DATA_SIZE_UINT16:
- std::cout << "maxSettable: " << pdr->max_set_table.value_u16
- << std::endl;
- std::cout << "minSettable: " << pdr->min_set_table.value_u16
- << std::endl;
+ output["maxSettable"] = unsigned(pdr->max_set_table.value_u16);
+ output["minSettable"] = unsigned(pdr->min_set_table.value_u16);
break;
case PLDM_EFFECTER_DATA_SIZE_SINT16:
- std::cout << "maxSettable: " << pdr->max_set_table.value_s16
- << std::endl;
- std::cout << "minSettable: " << pdr->min_set_table.value_s16
- << std::endl;
+ output["maxSettable"] = unsigned(pdr->max_set_table.value_s16);
+ output["minSettable"] = unsigned(pdr->min_set_table.value_s16);
break;
case PLDM_EFFECTER_DATA_SIZE_UINT32:
- std::cout << "maxSettable: " << pdr->max_set_table.value_u32
- << std::endl;
- std::cout << "minSettable: " << pdr->min_set_table.value_u32
- << std::endl;
+ output["maxSettable"] = unsigned(pdr->max_set_table.value_u32);
+ output["minSettable"] = unsigned(pdr->min_set_table.value_u32);
break;
case PLDM_EFFECTER_DATA_SIZE_SINT32:
- std::cout << "maxSettable: " << pdr->max_set_table.value_s32
- << std::endl;
- std::cout << "minSettable: " << pdr->min_set_table.value_s32
- << std::endl;
+ output["maxSettable"] = unsigned(pdr->max_set_table.value_s32);
+ output["minSettable"] = unsigned(pdr->min_set_table.value_s32);
break;
default:
break;
}
- std::cout << "rangeFieldFormat: " << unsigned(pdr->range_field_format)
- << std::endl;
- std::cout << "rangeFieldSupport: "
- << unsigned(pdr->range_field_support.byte) << std::endl;
+
+ output["rangeFieldFormat"] = unsigned(pdr->range_field_format);
+ output["rangeFieldSupport"] = unsigned(pdr->range_field_support.byte);
+
switch (pdr->range_field_format)
{
case PLDM_RANGE_FIELD_FORMAT_UINT8:
- std::cout << "nominalValue: "
- << unsigned(pdr->nominal_value.value_u8) << std::endl;
- std::cout << "normalMax: " << unsigned(pdr->normal_max.value_u8)
- << std::endl;
- std::cout << "normalMin: " << unsigned(pdr->normal_min.value_u8)
- << std::endl;
- std::cout << "ratedMax: " << unsigned(pdr->rated_max.value_u8)
- << std::endl;
- std::cout << "ratedMin: " << unsigned(pdr->rated_min.value_u8)
- << std::endl;
+ output["nominalValue"] = unsigned(pdr->nominal_value.value_u8);
+ output["normalMax"] = unsigned(pdr->normal_max.value_u8);
+ output["normalMin"] = unsigned(pdr->normal_min.value_u8);
+ output["ratedMax"] = unsigned(pdr->rated_max.value_u8);
+ output["ratedMin"] = unsigned(pdr->rated_min.value_u8);
break;
case PLDM_RANGE_FIELD_FORMAT_SINT8:
- std::cout << "nominalValue: "
- << unsigned(pdr->nominal_value.value_s8) << std::endl;
- std::cout << "normalMax: " << unsigned(pdr->normal_max.value_s8)
- << std::endl;
- std::cout << "normalMin: " << unsigned(pdr->normal_min.value_s8)
- << std::endl;
- std::cout << "ratedMax: " << unsigned(pdr->rated_max.value_s8)
- << std::endl;
- std::cout << "ratedMin: " << unsigned(pdr->rated_min.value_s8)
- << std::endl;
+ output["nominalValue"] = unsigned(pdr->nominal_value.value_s8);
+ output["normalMax"] = unsigned(pdr->normal_max.value_s8);
+ output["normalMin"] = unsigned(pdr->normal_min.value_s8);
+ output["ratedMax"] = unsigned(pdr->rated_max.value_s8);
+ output["ratedMin"] = unsigned(pdr->rated_min.value_s8);
break;
case PLDM_RANGE_FIELD_FORMAT_UINT16:
- std::cout << "nominalValue: " << pdr->nominal_value.value_u16
- << std::endl;
- std::cout << "normalMax: " << pdr->normal_max.value_u16
- << std::endl;
- std::cout << "normalMin: " << pdr->normal_min.value_u16
- << std::endl;
- std::cout << "ratedMax: " << pdr->rated_max.value_u16
- << std::endl;
- std::cout << "ratedMin: " << pdr->rated_min.value_u16
- << std::endl;
+ output["nominalValue"] = unsigned(pdr->nominal_value.value_u16);
+ output["normalMax"] = unsigned(pdr->normal_max.value_u16);
+ output["normalMin"] = unsigned(pdr->normal_min.value_u16);
+ output["ratedMax"] = unsigned(pdr->rated_max.value_u16);
+ output["ratedMin"] = unsigned(pdr->rated_min.value_u16);
break;
case PLDM_RANGE_FIELD_FORMAT_SINT16:
- std::cout << "nominalValue: " << pdr->nominal_value.value_s16
- << std::endl;
- std::cout << "normalMax: " << pdr->normal_max.value_s16
- << std::endl;
- std::cout << "normalMin: " << pdr->normal_min.value_s16
- << std::endl;
- std::cout << "ratedMax: " << pdr->rated_max.value_s16
- << std::endl;
- std::cout << "ratedMin: " << pdr->rated_min.value_s16
- << std::endl;
+ output["nominalValue"] = unsigned(pdr->nominal_value.value_s16);
+ output["normalMax"] = unsigned(pdr->normal_max.value_s16);
+ output["normalMin"] = unsigned(pdr->normal_min.value_s16);
+ output["ratedMax"] = unsigned(pdr->rated_max.value_s16);
+ output["ratedMin"] = unsigned(pdr->rated_min.value_s16);
break;
case PLDM_RANGE_FIELD_FORMAT_UINT32:
- std::cout << "nominalValue: " << pdr->nominal_value.value_u32
- << std::endl;
- std::cout << "normalMax: " << pdr->normal_max.value_u32
- << std::endl;
- std::cout << "normalMin: " << pdr->normal_min.value_u32
- << std::endl;
- std::cout << "ratedMax: " << pdr->rated_max.value_u32
- << std::endl;
- std::cout << "ratedMin: " << pdr->rated_min.value_u32
- << std::endl;
+ output["nominalValue"] = unsigned(pdr->nominal_value.value_u32);
+ output["normalMax"] = unsigned(pdr->normal_max.value_u32);
+ output["normalMin"] = unsigned(pdr->normal_min.value_u32);
+ output["ratedMax"] = unsigned(pdr->rated_max.value_u32);
+ output["ratedMin"] = unsigned(pdr->rated_min.value_u32);
break;
case PLDM_RANGE_FIELD_FORMAT_SINT32:
- std::cout << "nominalValue: " << pdr->nominal_value.value_s32
- << std::endl;
- std::cout << "normalMax: " << pdr->normal_max.value_s32
- << std::endl;
- std::cout << "normalMin: " << pdr->normal_min.value_s32
- << std::endl;
- std::cout << "ratedMax: " << pdr->rated_max.value_s32
- << std::endl;
- std::cout << "ratedMin: " << pdr->rated_min.value_s32
- << std::endl;
+ output["nominalValue"] = unsigned(pdr->nominal_value.value_s32);
+ output["normalMax"] = unsigned(pdr->normal_max.value_s32);
+ output["normalMin"] = unsigned(pdr->normal_min.value_s32);
+ output["ratedMax"] = unsigned(pdr->rated_max.value_s32);
+ output["ratedMin"] = unsigned(pdr->rated_min.value_s32);
break;
case PLDM_RANGE_FIELD_FORMAT_REAL32:
- std::cout << "nominalValue: " << pdr->nominal_value.value_f32
- << std::endl;
- std::cout << "normalMax: " << pdr->normal_max.value_f32
- << std::endl;
- std::cout << "normalMin: " << pdr->normal_min.value_f32
- << std::endl;
- std::cout << "ratedMax: " << pdr->rated_max.value_f32
- << std::endl;
- std::cout << "ratedMin: " << pdr->rated_min.value_f32
- << std::endl;
+ output["nominalValue"] = unsigned(pdr->nominal_value.value_f32);
+ output["normalMax"] = unsigned(pdr->normal_max.value_f32);
+ output["normalMin"] = unsigned(pdr->normal_min.value_f32);
+ output["ratedMax"] = unsigned(pdr->rated_max.value_f32);
+ output["ratedMin"] = unsigned(pdr->rated_min.value_f32);
break;
default:
break;
}
}
- void printStateEffecterPDR(const uint8_t* data)
+ void printStateEffecterPDR(const uint8_t* data, ordered_json& output)
{
auto pdr = reinterpret_cast<const pldm_state_effecter_pdr*>(data);
- std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle
- << std::endl;
- std::cout << "effecterID: " << pdr->effecter_id << std::endl;
- std::cout << "entityType: " << getEntityName(pdr->entity_type)
- << std::endl;
- std::cout << "entityInstanceNumber: " << pdr->entity_instance
- << std::endl;
- std::cout << "containerID: " << pdr->container_id << std::endl;
- std::cout << "effecterSemanticID: " << pdr->effecter_semantic_id
- << std::endl;
- std::cout << "effecterInit: " << effecterInit[pdr->effecter_init]
- << std::endl;
- std::cout << "effecterDescriptionPDR: "
- << (pdr->has_description_pdr ? "true" : "false") << std::endl;
- std::cout << "compositeEffecterCount: "
- << unsigned(pdr->composite_effecter_count) << std::endl;
+ output["PLDMTerminusHandle"] = pdr->terminus_handle;
+ output["effecterID"] = pdr->effecter_id;
+ output["entityType"] = getEntityName(pdr->entity_type);
+ output["entityInstanceNumber"] = pdr->entity_instance;
+ output["containerID"] = pdr->container_id;
+ output["effecterSemanticID"] = pdr->effecter_semantic_id;
+ output["effecterInit"] = effecterInit[pdr->effecter_init];
+ output["effecterDescriptionPDR"] =
+ (pdr->has_description_pdr ? true : false);
+ output["compositeEffecterCount"] =
+ unsigned(pdr->composite_effecter_count);
auto statesPtr = pdr->possible_states;
auto compositeEffecterCount = pdr->composite_effecter_count;
@@ -537,13 +458,11 @@
auto state =
reinterpret_cast<const state_effecter_possible_states*>(
statesPtr);
- std::cout << "stateSetID: " << getStateSetName(state->state_set_id)
- << std::endl;
- std::cout << "possibleStatesSize: "
- << unsigned(state->possible_states_size) << std::endl;
- std::cout << "possibleStates:";
- printPossibleStates(state->possible_states_size, state->states);
- std::cout << std::endl;
+
+ output["stateSetID"] = getStateSetName(state->state_set_id);
+ output["possibleStatesSize"] = (state->possible_states_size);
+ output["possibleStates"] =
+ printPossibleStates(state->possible_states_size, state->states);
if (compositeEffecterCount)
{
@@ -553,31 +472,28 @@
}
}
- void printTerminusLocatorPDR(const uint8_t* data)
+ void printTerminusLocatorPDR(const uint8_t* data, ordered_json& output)
{
const std::array<std::string_view, 4> terminusLocatorType = {
"UID", "MCTP_EID", "SMBusRelative", "systemSoftware"};
auto pdr = reinterpret_cast<const pldm_terminus_locator_pdr*>(data);
- std::cout << "PLDMTerminusHandle: " << pdr->terminus_handle
- << std::endl;
- std::cout << "validity: " << (pdr->validity ? "valid" : "notValid")
- << std::endl;
- std::cout << "TID: " << unsigned(pdr->tid) << std::endl;
- std::cout << "containerID: " << pdr->container_id << std::endl;
- std::cout << "terminusLocatorType: "
- << terminusLocatorType[pdr->terminus_locator_type]
- << std::endl;
- std::cout << "terminusLocatorValueSize: "
- << unsigned(pdr->terminus_locator_value_size) << std::endl;
+ output["PLDMTerminusHandle"] = pdr->terminus_handle;
+ output["validity"] = (pdr->validity ? "valid" : "notValid");
+ output["TID"] = unsigned(pdr->tid);
+ output["containerID"] = pdr->container_id;
+ output["terminusLocatorType"] =
+ terminusLocatorType[pdr->terminus_locator_type];
+ output["terminusLocatorValueSize"] =
+ unsigned(pdr->terminus_locator_value_size);
if (pdr->terminus_locator_type == PLDM_TERMINUS_LOCATOR_TYPE_MCTP_EID)
{
auto locatorValue =
reinterpret_cast<const pldm_terminus_locator_type_mctp_eid*>(
pdr->terminus_locator_value);
- std::cout << "EID: " << unsigned(locatorValue->eid) << std::endl;
+ output["EID"] = unsigned(locatorValue->eid);
}
}
@@ -589,34 +505,37 @@
return;
}
- std::cout << "nextRecordHandle: " << nextRecordHndl << std::endl;
- std::cout << "responseCount: " << respCnt << std::endl;
+ ordered_json output;
+ output["nextRecordHandle"] = nextRecordHndl;
+ output["responseCount"] = respCnt;
struct pldm_pdr_hdr* pdr = (struct pldm_pdr_hdr*)data;
- printCommonPDRHeader(pdr);
+ printCommonPDRHeader(pdr, output);
+
switch (pdr->type)
{
case PLDM_TERMINUS_LOCATOR_PDR:
- printTerminusLocatorPDR(data);
+ printTerminusLocatorPDR(data, output);
break;
case PLDM_STATE_SENSOR_PDR:
- printStateSensorPDR(data);
+ printStateSensorPDR(data, output);
break;
case PLDM_NUMERIC_EFFECTER_PDR:
- printNumericEffecterPDR(data);
+ printNumericEffecterPDR(data, output);
break;
case PLDM_STATE_EFFECTER_PDR:
- printStateEffecterPDR(data);
+ printStateEffecterPDR(data, output);
break;
case PLDM_PDR_ENTITY_ASSOCIATION:
- printPDREntityAssociation(data);
+ printPDREntityAssociation(data, output);
break;
case PLDM_PDR_FRU_RECORD_SET:
- printPDRFruRecordSet(data);
+ printPDRFruRecordSet(data, output);
break;
default:
break;
}
+ pldmtool::helper::DisplayInJson(output);
}
private:
@@ -707,7 +626,9 @@
return;
}
- std::cout << "SetStateEffecterStates: SUCCESS" << std::endl;
+ ordered_json data;
+ data["Response"] = "SUCCESS";
+ pldmtool::helper::DisplayInJson(data);
}
private:
@@ -787,7 +708,9 @@
return;
}
- std::cout << "SetNumericEffecterValue: SUCCESS" << std::endl;
+ ordered_json data;
+ data["Response"] = "SUCCESS";
+ pldmtool::helper::DisplayInJson(data);
}
private: