Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/506 set data buffer method in storage unit #507

Merged
merged 4 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ void DataStorageUnitBase::Reset(uint64_t CurrentSimNanos)
{
this->previousTime = 0;

//! - Zero out the partitions
for(uint64_t i = 0; i < this->storedData.size(); i++){
this->storedData[i].dataInstanceSum = 0.0;
}

//! - call the custom environment module reset method
customReset(CurrentSimNanos);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
@return void;
*/
PartitionedStorageUnit::PartitionedStorageUnit(){
this->storageCapacity = -1.0;
this->storedDataSum = 0.0;
this->storageCapacity = 0;
this->storedDataSum = 0;
return;
}

Expand All @@ -45,7 +45,7 @@ PartitionedStorageUnit::~PartitionedStorageUnit(){
@return void
*/
void PartitionedStorageUnit::customReset(uint64_t currentClock){
if (this->storageCapacity <= 0.0) {
if (this->storageCapacity <= 0) {
bskLogger.bskLog(BSK_INFORMATION, "The storageCapacity variable must be set to a positive value.");
}
return;
Expand All @@ -58,7 +58,20 @@ void PartitionedStorageUnit::customReset(uint64_t currentClock){
void PartitionedStorageUnit::addPartition(std::string dataName){
dataInstance tmpDataInstance;
strncpy(tmpDataInstance.dataInstanceName, dataName.c_str(), sizeof(tmpDataInstance.dataInstanceName));
tmpDataInstance.dataInstanceSum = 0.0;
tmpDataInstance.dataInstanceSum = 0;
this->storedData.push_back(tmpDataInstance);
return;
}

/*! Adds a specific amount of data to the specified partitions once
@param partitionNames //Vector of partition names
@param data //Vector of data to be added to each partition in partitionNames
@return void
*/
void PartitionedStorageUnit::setDataBuffer(std::vector<std::string> partitionNames, std::vector<long long int> data){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be int64_t also, (assuming I'm not missing something here...I could be :) )


for (int i = 0; i < partitionNames.size(); i++)
{
PartitionedStorageUnit::DataStorageUnitBase::setDataBuffer(partitionNames[i], data[i]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line here as well

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PartitionedStorageUnit: public DataStorageUnitBase {
PartitionedStorageUnit();
~PartitionedStorageUnit();
void addPartition(std::string dataName);
void setDataBuffer(std::vector<std::string> partitionNames, std::vector<long long int> data); //!< Adds/removes the data from the partitionNames partitions

private:
void customReset(uint64_t CurrentClock) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,25 @@ from Basilisk.architecture.swig_common_model import *
%include "sys_model.i"
%include "std_vector.i"
%include "cstring.i"
%include "swig_common_model.i"
%include "stdint.i"

//When using scientific notation in Python (1E9), it is interpreted as float
// giving a type error when assigning storageCapacity or adding data through
// setDataBuffer. This maps that float and vector of floats to long int in
// C++ in this module.
%typemap(in) long long int {
$1 = static_cast<long long int>(PyFloat_AsDouble($input));
}
%typemap(in) std::vector<long long int> (std::vector<long long int> temp) {
size_t size = PyList_Size($input);
temp.reserve(size);
for (size_t i = 0; i < size; ++i) {
PyObject* item = PyList_GetItem($input, i);
temp.push_back(static_cast<long long int>(PyFloat_AsDouble(item)));
}
$1 = temp;
}

%include "simulation/onboardDataHandling/_GeneralModuleFiles/dataStorageUnitBase.h"
%include "partitionedStorageUnit.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
@return void
*/
SimpleStorageUnit::SimpleStorageUnit(){
this->storageCapacity = -1.0;
this->storedDataSum = 0.0;
this->storageCapacity = 0;
this->storedDataSum = 0;
return;
}

Expand All @@ -43,7 +43,7 @@ SimpleStorageUnit::~SimpleStorageUnit(){
@param currentClock
*/
void SimpleStorageUnit::customReset(uint64_t currentClock){
if (this->storageCapacity <= 0.0) {
if (this->storageCapacity <= 0) {
bskLogger.bskLog(BSK_INFORMATION, "The storageCapacity variable must be set to a positive value.");
}
return;
Expand All @@ -63,10 +63,10 @@ void SimpleStorageUnit::integrateDataStatus(double currentTime){
if (storedData.size() == 0){
this->storedData.push_back({{'S','T','O','R','E','D',' ','D','A','T','A'}, 0});
}
else if ((this->storedDataSum < this->storageCapacity) || (it->baudRate <= 0)){
else if ((this->storedDataSum + round(it->baudRate * this->currentTimestep) < this->storageCapacity) || (it->baudRate <= 0)){
//! - Only perform the operation if it will not result in less than 0 data
if ((this->storedData[0].dataInstanceSum + it->baudRate * (this->currentTimestep)) >= 0){
this->storedData[0].dataInstanceSum += it->baudRate * (this->currentTimestep);
this->storedData[0].dataInstanceSum += round(it->baudRate * (this->currentTimestep));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The braces around this->currentTimestep are redundant and can be removed.

}
}
this->netBaud += it->baudRate;
Expand All @@ -79,3 +79,12 @@ void SimpleStorageUnit::integrateDataStatus(double currentTime){
this->previousTime = currentTime;
return;
}

/*! Adds a specific amount of data to the storedData vector once
@param data //Data to be added to the "STORED DATA" partition
@return void
*/
void SimpleStorageUnit::setDataBuffer(long long int data){
std::string partitionName = "STORED DATA";
SimpleStorageUnit::DataStorageUnitBase::setDataBuffer(partitionName, data);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is missing a new line at its end. You can see that github is alerting you of this fact with the little red circle containing a dash, just to the left above this comment.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SimpleStorageUnit: public DataStorageUnitBase {
public:
SimpleStorageUnit();
~SimpleStorageUnit();
void setDataBuffer(long long int data); //!< Method to add/remove data from the storage unit once

private:
void customReset(uint64_t CurrentClock); //!< Custom Reset method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ from Basilisk.architecture.swig_common_model import *
%include "sys_model.i"
%include "stdint.i"

//When using scientific notation in Python (1E9), it is interpreted as float
// giving a type error when assigning storageCapacity or using setDataBuffer.
// This maps that float to long int in C++ in this module.
%typemap(in) long long int {
$1 = static_cast<long long int>(PyFloat_AsDouble($input));
}

%include "simulation/onboardDataHandling/_GeneralModuleFiles/dataStorageUnitBase.h"
%include "simpleStorageUnit.h"
%include "architecture/msgPayloadDefC/DataNodeUsageMsgPayload.h"
Expand Down