Mark download data as const.

Remove redundant code.
[07-sdo-up-download]
This commit is contained in:
Gavin Lambert 2014-05-31 18:08:27 +12:00
parent e3e96acb69
commit d9a93ffa24
6 changed files with 18 additions and 29 deletions

View File

@ -815,7 +815,7 @@ int ecrt_master_sdo_download(
uint16_t slave_position, /**< Slave position. */
uint16_t index, /**< Index of the SDO. */
uint8_t subindex, /**< Subindex of the SDO. */
uint8_t *data, /**< Data buffer to download. */
const uint8_t *data, /**< Data buffer to download. */
size_t data_size, /**< Size of the data buffer. */
uint32_t *abort_code /**< Abort code of the SDO download. */
);
@ -834,7 +834,7 @@ int ecrt_master_sdo_download_complete(
ec_master_t *master, /**< EtherCAT master. */
uint16_t slave_position, /**< Slave position. */
uint16_t index, /**< Index of the SDO. */
uint8_t *data, /**< Data buffer to download. */
const uint8_t *data, /**< Data buffer to download. */
size_t data_size, /**< Size of the data buffer. */
uint32_t *abort_code /**< Abort code of the SDO download. */
);

View File

@ -390,7 +390,7 @@ int ecrt_master_get_pdo_entry(ec_master_t *master, uint16_t slave_position,
/****************************************************************************/
int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position,
uint16_t index, uint8_t subindex, uint8_t *data,
uint16_t index, uint8_t subindex, const uint8_t *data,
size_t data_size, uint32_t *abort_code)
{
ec_ioctl_slave_sdo_download_t download;
@ -419,7 +419,7 @@ int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position,
/****************************************************************************/
int ecrt_master_sdo_download_complete(ec_master_t *master,
uint16_t slave_position, uint16_t index, uint8_t *data,
uint16_t slave_position, uint16_t index, const uint8_t *data,
size_t data_size, uint32_t *abort_code)
{
ec_ioctl_slave_sdo_download_t download;

View File

@ -864,7 +864,7 @@ static ATTRIBUTES int ec_ioctl_slave_sdo_download(
return -ENOMEM;
}
if (copy_from_user(sdo_data, (void __user *) data.data, data.data_size)) {
if (copy_from_user(sdo_data, (const void __user *) data.data, data.data_size)) {
kfree(sdo_data);
return -EFAULT;
}

View File

@ -400,7 +400,7 @@ typedef struct {
uint8_t sdo_entry_subindex;
uint8_t complete_access;
size_t data_size;
uint8_t *data;
const uint8_t *data;
// outputs
uint32_t abort_code;

View File

@ -2849,7 +2849,7 @@ uint32_t ecrt_master_sync_monitor_process(ec_master_t *master)
/*****************************************************************************/
int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position,
uint16_t index, uint8_t subindex, uint8_t *data,
uint16_t index, uint8_t subindex, const uint8_t *data,
size_t data_size, uint32_t *abort_code)
{
ec_sdo_request_t request;
@ -2933,7 +2933,7 @@ int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position,
/*****************************************************************************/
int ecrt_master_sdo_download_complete(ec_master_t *master,
uint16_t slave_position, uint16_t index, uint8_t *data,
uint16_t slave_position, uint16_t index, const uint8_t *data,
size_t data_size, uint32_t *abort_code)
{
ec_sdo_request_t request;

View File

@ -173,16 +173,17 @@ void CommandDownload::execute(const StringVector &args)
throwCommandException(err);
}
data.data_size = contents.size();
data.data = new uint8_t[data.data_size + 1];
uint8_t *sdo_data = new uint8_t[data.data_size + 1];
data.data = sdo_data;
try {
data.data_size = interpretAsType(
dataType, contents, data.data, data.data_size);
dataType, contents, sdo_data, data.data_size);
} catch (SizeException &e) {
delete [] data.data;
delete [] sdo_data;
throwCommandException(e.what());
} catch (ios::failure &e) {
delete [] data.data;
delete [] sdo_data;
err << "Invalid value argument '" << args[2]
<< "' for type '" << dataType->name << "'!";
throwInvalidUsageException(err);
@ -195,35 +196,23 @@ void CommandDownload::execute(const StringVector &args)
data.data_size = DefaultBufferSize;
}
data.data = new uint8_t[data.data_size + 1];
uint8_t *sdo_data = new uint8_t[data.data_size + 1];
data.data = sdo_data;
try {
data.data_size = interpretAsType(
dataType, args[valueIndex], data.data, data.data_size);
dataType, args[valueIndex], sdo_data, data.data_size);
} catch (SizeException &e) {
delete [] data.data;
delete [] sdo_data;
throwCommandException(e.what());
} catch (ios::failure &e) {
delete [] data.data;
delete [] sdo_data;
err << "Invalid value argument '" << args[2]
<< "' for type '" << dataType->name << "'!";
throwInvalidUsageException(err);
}
}
try {
data.data_size = interpretAsType(
dataType, args[valueIndex], data.data, data.data_size);
} catch (SizeException &e) {
delete [] data.data;
throwCommandException(e.what());
} catch (ios::failure &e) {
delete [] data.data;
err << "Invalid value argument '" << args[2]
<< "' for type '" << dataType->name << "'!";
throwInvalidUsageException(err);
}
try {
m.sdoDownload(&data);
} catch (MasterDeviceSdoAbortException &e) {