Skip to content

Commit

Permalink
change storageUnit variable long int to int64_t
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzzoQM committed Nov 24, 2023
1 parent 3d7fb0e commit 2c5280d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ void DataStorageUnitBase::integrateDataStatus(double currentTime){
//! - if a dataNode exists in storedData vector, integrate and add to current amount
if (index != -1) {
//! Only perform if this operation will not take the sum below zero
if ((this->storedData[(size_t) index].dataInstanceSum + it->baudRate * (this->currentTimestep)) >= 0) {
this->storedData[(size_t) index].dataInstanceSum += round(it->baudRate * (this->currentTimestep));
if ((this->storedData[(size_t) index].dataInstanceSum + it->baudRate * this->currentTimestep) >= 0) {
this->storedData[(size_t) index].dataInstanceSum += round(it->baudRate * this->currentTimestep);
}
//! - if a dataNode does not exist in storedData, add it to storedData, integrate baud rate, and add amount
}
Expand Down Expand Up @@ -213,7 +213,7 @@ int DataStorageUnitBase::messageInStoredData(DataNodeUsageMsgPayload *tmpNodeMsg
/*! Sums all of the data in the storedData vector
@return double
*/
long long int DataStorageUnitBase::sumAllData(){
int64_t DataStorageUnitBase::sumAllData(){
double dataSum = 0;

std::vector<dataInstance>::iterator it;
Expand Down Expand Up @@ -253,7 +253,7 @@ bool DataStorageUnitBase::customReadMessages()
@param data //Amount of data to add to the partition
@return void
*/
void DataStorageUnitBase::setDataBuffer(std::string partitionName, long long int data)
void DataStorageUnitBase::setDataBuffer(std::string partitionName, int64_t data)
{
dataInstance tmpDataInstance;

Expand Down Expand Up @@ -288,4 +288,4 @@ void DataStorageUnitBase::setDataBuffer(std::string partitionName, long long int

//! - Sum all data in storedData vector
this->storedDataSum = this->sumAllData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

struct dataInstance {
char dataInstanceName[128]; //!< data instance name
long long int dataInstanceSum; //!< data instance sum value, bits
int64_t dataInstanceSum; //!< data instance sum value, bits
}; //!< Struct for instances of data stored in a buffer. Includes names and amounts.

/*! @brief on-board data handling base class */
Expand All @@ -45,7 +45,7 @@ class DataStorageUnitBase: public SysModel {
void Reset(uint64_t CurrentSimNanos);
void addDataNodeToModel(Message<DataNodeUsageMsgPayload> *tmpNodeMsg); //!< Adds dataNode to the storageUnit
void UpdateState(uint64_t CurrentSimNanos);
void setDataBuffer(std::string partitionName, long long int data); //!< Adds/removes the data from the partitionName partition once
void setDataBuffer(std::string partitionName, int64_t data); //!< Adds/removes the data from the partitionName partition once

protected:
void writeMessages(uint64_t CurrentClock);
Expand All @@ -55,18 +55,18 @@ class DataStorageUnitBase: public SysModel {
virtual void customWriteMessages(uint64_t CurrentClock); //!< custom Write method, similar to customSelfInit.
virtual bool customReadMessages(); //!< Custom read method, similar to customSelfInit; returns `true' by default.
int messageInStoredData(DataNodeUsageMsgPayload *tmpNodeMsg); //!< Returns index of the dataName if it's already in storedData
long long int sumAllData(); //!< Sums all of the data in the storedData vector
int64_t sumAllData(); //!< Sums all of the data in the storedData vector

public:
std::vector<ReadFunctor<DataNodeUsageMsgPayload>> nodeDataUseInMsgs; //!< Vector of data node input message names
Message<DataStorageStatusMsgPayload> storageUnitDataOutMsg; //!< Vector of message names to be written out by the storage unit
long long int storageCapacity; //!< Storage capacity of the storage unit
int64_t storageCapacity; //!< Storage capacity of the storage unit
BSKLogger bskLogger; //!< logging variable

protected:
DataStorageStatusMsgPayload storageStatusMsg; //!< class variable
std::vector<DataNodeUsageMsgPayload> nodeBaudMsgs; //!< class variable
long long int storedDataSum; //!< [bits] Stored data in bits.
int64_t storedDataSum; //!< [bits] Stored data in bits.
std::vector<dataInstance> storedData; //!< Vector of data. Represents the makeup of the data buffer.
double previousTime; //!< Previous time used for integration
double currentTimestep;//!< [s] Timestep duration in seconds.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ void PartitionedStorageUnit::addPartition(std::string dataName){
@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){
void PartitionedStorageUnit::setDataBuffer(std::vector<std::string> partitionNames, std::vector<int64_t> data){

for (int i = 0; i < partitionNames.size(); i++)
{
PartitionedStorageUnit::DataStorageUnitBase::setDataBuffer(partitionNames[i], data[i]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +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
void setDataBuffer(std::vector<std::string> partitionNames, std::vector<int64_t> 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 @@ -39,15 +39,15 @@ from Basilisk.architecture.swig_common_model import *
// 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) int64_t {
$1 = static_cast<int64_t>(PyFloat_AsDouble($input));
}
%typemap(in) std::vector<long long int> (std::vector<long long int> temp) {
%typemap(in) std::vector<int64_t> (std::vector<int64_t> 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)));
temp.push_back(static_cast<int64_t>(PyFloat_AsDouble(item)));
}
$1 = temp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ void SimpleStorageUnit::integrateDataStatus(double currentTime){
}
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 += round(it->baudRate * (this->currentTimestep));
if ((this->storedData[0].dataInstanceSum + it->baudRate * this->currentTimestep) >= 0){
this->storedData[0].dataInstanceSum += round(it->baudRate * this->currentTimestep);
}
}
this->netBaud += it->baudRate;
Expand All @@ -84,7 +84,7 @@ void SimpleStorageUnit::integrateDataStatus(double currentTime){
@param data //Data to be added to the "STORED DATA" partition
@return void
*/
void SimpleStorageUnit::setDataBuffer(long long int data){
void SimpleStorageUnit::setDataBuffer(int64_t data){
std::string partitionName = "STORED DATA";
SimpleStorageUnit::DataStorageUnitBase::setDataBuffer(partitionName, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +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
void setDataBuffer(int64_t 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 @@ -36,8 +36,8 @@ from Basilisk.architecture.swig_common_model import *
//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));
%typemap(in) int64_t {
$1 = static_cast<int64_t>(PyFloat_AsDouble($input));
}

%include "simulation/onboardDataHandling/_GeneralModuleFiles/dataStorageUnitBase.h"
Expand Down

0 comments on commit 2c5280d

Please sign in to comment.