vedderb / bldc

The VESC motor control firmware
2.09k stars 1.31k forks source link

Redundant copy of buffer #627

Open CronusElectronics opened 1 year ago

CronusElectronics commented 1 year ago

In int VescUart::packSendPayload(uint8_t * payload, int lenPay) there seems to be a redundant copy of the paylaod buffer.

memcpy(messageSend + count, payload, lenPay); count += lenPay;

messageSend[count++] = (uint8_t)(crcPayload >> 8);
messageSend[count++] = (uint8_t)(crcPayload & 0xFF);
messageSend[count++] = 3;
// messageSend[count] = NULL;

if(debugPort!=NULL){
    debugPort->print("Package to send: "); serialPrint(messageSend, count);
}

// Sending package
if( serialPort != NULL )
    serialPort->write(messageSend, count);

Why not simply send the payaod buffer then send the CRC saving memory and (more improtantly to me) clock cycles.

serialPort->write(payload, lenPay); serialPort->write((uint8_t)(crcPayload >> 8)); serialPort->write((uint8_t)(crcPayload & 0xFF));

kalvdans commented 1 year ago

harder to debug if you remove the debug possibility?

CronusElectronics commented 1 year ago

harder to debug if you remove the debug possibility? Hi, I was not suggesting that the debug was removed (I just ommited it for brevity).