- reducing the count of calling MakeParam function

This commit is contained in:
sadtale 2016-03-31 21:58:43 +09:00
parent f81f17c559
commit 738b68b6e4
8 changed files with 32 additions and 10 deletions

View File

@ -30,6 +30,7 @@ private:
std::map<UINT8_T, UINT8_T *> data_list_; // <id, data>
bool last_result_;
bool is_param_changed_;
UINT8_T *param_;

View File

@ -29,6 +29,8 @@ private:
std::map<UINT8_T, UINT16_T> length_list_; // <id, data_length>
std::map<UINT8_T, UINT8_T *> data_list_; // <id, data>
bool is_param_changed_;
UINT8_T *param_;
UINT16_T param_length_;

View File

@ -28,6 +28,7 @@ private:
std::map<UINT8_T, UINT8_T* > data_list_; // <id, data>
bool last_result_;
bool is_param_changed_;
UINT8_T *param_;
UINT16_T start_address_;

View File

@ -27,6 +27,8 @@ private:
std::vector<UINT8_T> id_list_;
std::map<UINT8_T, UINT8_T* > data_list_; // <id, data>
bool is_param_changed_;
UINT8_T *param_;
UINT16_T start_address_;
UINT16_T data_length_;

View File

@ -15,6 +15,7 @@ GroupBulkRead::GroupBulkRead(PortHandler *port, PacketHandler *ph)
: port_(port),
ph_(ph),
last_result_(false),
is_param_changed_(false),
param_(0)
{
ClearParam();
@ -65,7 +66,7 @@ bool GroupBulkRead::AddParam(UINT8_T id, UINT16_T start_address, UINT16_T data_l
address_list_[id] = start_address;
data_list_[id] = new UINT8_T[data_length];
MakeParam();
is_param_changed_ = true;
return true;
}
@ -81,7 +82,7 @@ void GroupBulkRead::RemoveParam(UINT8_T id)
delete[] data_list_[id];
data_list_.erase(id);
MakeParam();
is_param_changed_ = true;
}
void GroupBulkRead::ClearParam()
@ -106,6 +107,9 @@ int GroupBulkRead::TxPacket()
if(id_list_.size() == 0)
return COMM_NOT_AVAILABLE;
if(is_param_changed_ == true)
MakeParam();
if(ph_->GetProtocolVersion() == 1.0)
return ph_->BulkReadTx(port_, param_, id_list_.size() * 3);
else // 2.0

View File

@ -13,6 +13,7 @@ using namespace ROBOTIS;
GroupBulkWrite::GroupBulkWrite(PortHandler *port, PacketHandler *ph)
: port_(port),
ph_(ph),
is_param_changed_(false),
param_(0),
param_length_(0)
{
@ -66,7 +67,7 @@ bool GroupBulkWrite::AddParam(UINT8_T id, UINT16_T start_address, UINT16_T data_
for(int _c = 0; _c < data_length; _c++)
data_list_[id][_c] = data[_c];
MakeParam();
is_param_changed_ = true;
return true;
}
void GroupBulkWrite::RemoveParam(UINT8_T id)
@ -84,7 +85,7 @@ void GroupBulkWrite::RemoveParam(UINT8_T id)
delete[] data_list_[id];
data_list_.erase(id);
MakeParam();
is_param_changed_ = true;
}
bool GroupBulkWrite::ChangeParam(UINT8_T id, UINT16_T start_address, UINT16_T data_length, UINT8_T *data)
{
@ -102,7 +103,7 @@ bool GroupBulkWrite::ChangeParam(UINT8_T id, UINT16_T start_address, UINT16_T da
for(int _c = 0; _c < data_length; _c++)
data_list_[id][_c] = data[_c];
MakeParam();
is_param_changed_ = true;
return true;
}
void GroupBulkWrite::ClearParam()
@ -129,5 +130,8 @@ int GroupBulkWrite::TxPacket()
if(ph_->GetProtocolVersion() == 1.0 || id_list_.size() == 0)
return COMM_NOT_AVAILABLE;
if(is_param_changed_ == true)
MakeParam();
return ph_->BulkWriteTxOnly(port_, param_, param_length_);
}

View File

@ -14,6 +14,7 @@ GroupSyncRead::GroupSyncRead(PortHandler *port, PacketHandler *ph, UINT16_T star
: port_(port),
ph_(ph),
last_result_(false),
is_param_changed_(false),
param_(0),
start_address_(start_address),
data_length_(data_length)
@ -48,7 +49,7 @@ bool GroupSyncRead::AddParam(UINT8_T id)
id_list_.push_back(id);
data_list_[id] = new UINT8_T[data_length_];
MakeParam();
is_param_changed_ = true;
return true;
}
void GroupSyncRead::RemoveParam(UINT8_T id)
@ -64,7 +65,7 @@ void GroupSyncRead::RemoveParam(UINT8_T id)
delete[] data_list_[id];
data_list_.erase(id);
MakeParam();
is_param_changed_ = true;
}
void GroupSyncRead::ClearParam()
{
@ -89,6 +90,9 @@ int GroupSyncRead::TxPacket()
if(ph_->GetProtocolVersion() == 1.0 || id_list_.size() == 0)
return COMM_NOT_AVAILABLE;
if(is_param_changed_ == true)
MakeParam();
return ph_->SyncReadTx(port_, start_address_, data_length_, param_, (UINT16_T)id_list_.size() * 1);
}

View File

@ -13,6 +13,7 @@ using namespace ROBOTIS;
GroupSyncWrite::GroupSyncWrite(PortHandler *port, PacketHandler *ph, UINT16_T start_address, UINT16_T data_length)
: port_(port),
ph_(ph),
is_param_changed_(false),
param_(0),
start_address_(start_address),
data_length_(data_length)
@ -54,7 +55,7 @@ bool GroupSyncWrite::AddParam(UINT8_T id, UINT8_T *data)
for(int _c = 0; _c < data_length_; _c++)
data_list_[id][_c] = data[_c];
MakeParam();
is_param_changed_ = true;
return true;
}
@ -68,7 +69,7 @@ void GroupSyncWrite::RemoveParam(UINT8_T id)
delete[] data_list_[id];
data_list_.erase(id);
MakeParam();
is_param_changed_ = true;
}
bool GroupSyncWrite::ChangeParam(UINT8_T id, UINT8_T *data)
@ -82,7 +83,7 @@ bool GroupSyncWrite::ChangeParam(UINT8_T id, UINT8_T *data)
for(int _c = 0; _c < data_length_; _c++)
data_list_[id][_c] = data[_c];
MakeParam();
is_param_changed_ = true;
return true;
}
@ -106,5 +107,8 @@ int GroupSyncWrite::TxPacket()
if(id_list_.size() == 0)
return COMM_NOT_AVAILABLE;
if(is_param_changed_ == true)
MakeParam();
return ph_->SyncWriteTxOnly(port_, start_address_, data_length_, param_, id_list_.size() * (1 + data_length_));
}