Skip to content

zephyrCommon: Add Print::write(const uint8_t*, size_t) default implementation #57

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

Merged
merged 1 commit into from
Oct 12, 2022

Conversation

soburi
Copy link
Member

@soburi soburi commented Sep 24, 2022

When compile with enabling CONFIG_DEBUG option,
the Print::write virtual function failed to link.

This implementation is usually not used.
Because the override implementation that implements by the subclass will be used.

Signed-off-by: TOKITA Hiroshi tokita.hiroshi@fujitsu.com

Copy link
Collaborator

@DhruvaG2000 DhruvaG2000 left a comment

Choose a reason for hiding this comment

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

In my opinion this should go into cores/arduino/zephyrSerial.cpp.
At the moment we are not really very well integrating the Arduino Core API in serial aspect, so perhaps you may want to drop the arduino::Print and use arduino::ZephyrSerial:: and also add the write in respective header file where we write the func prototypes.

When compile with enabling CONFIG_DEBUG option,
the Print::write virtual function failed to link.

This implementation is usually not used.
Because the override implementation that implements
by the subclass will be used.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
@soburi
Copy link
Member Author

soburi commented Sep 25, 2022

@DhruvaG2000

In my opinion this should go into cores/arduino/zephyrSerial.cpp.

The Print class is also used by (TCP) Client class, UDP class, and also user-defined classes via the Stream class.
I think it should not be placed in zephyrSerial because it has no relation to the Serial class.

I rewrited it to splitting into the new file named 'zephyrPrint.cpp'.
Please review it.

}

return i;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, so this seems to be taken from here

size_t Print::write(const uint8_t *buffer, size_t size)
{
  size_t n = 0;
  while (size--) {
    if (write(*buffer++)) n++;
    else break;
  }
  return n;
}

but with for loop instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

One confirmation.
Is it okayto copy from GPL?

Copy link
Collaborator

@DhruvaG2000 DhruvaG2000 Sep 25, 2022

Choose a reason for hiding this comment

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

Not really, I think this way that you have done is also okay.

@DhruvaG2000 DhruvaG2000 requested a review from szczys September 25, 2022 12:43
@DhruvaG2000
Copy link
Collaborator

Seems like this file can in future have a similar structure to original Print.cpp
Perhaps we can even consider migrating ZephyrSerial entirely to use this file itself.
@szczys and @alvarowolfx I would love to hear your thoughts on this

Copy link
Collaborator

@DhruvaG2000 DhruvaG2000 left a comment

Choose a reason for hiding this comment

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

Looks like a good starting point to me.
Built locally, LGTM.

@DhruvaG2000 DhruvaG2000 added the enhancement New feature or request label Oct 5, 2022
@DhruvaG2000 DhruvaG2000 merged commit b8d9c60 into zephyrproject-rtos:main Oct 12, 2022
@DhruvaG2000
Copy link
Collaborator

Been too long since approved, I do not see any nacks, hence merging.

@soburi soburi deleted the write_default_impl branch October 23, 2022 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants