Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

56 lines
1.1KB

  1. #if ARDUINO >= 100
  2. #include "Arduino.h"
  3. #include "IPAddress.h"
  4. IPAddress::IPAddress()
  5. {
  6. _address.dword = 0;
  7. }
  8. IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
  9. {
  10. _address.bytes[0] = first_octet;
  11. _address.bytes[1] = second_octet;
  12. _address.bytes[2] = third_octet;
  13. _address.bytes[3] = fourth_octet;
  14. }
  15. IPAddress::IPAddress(uint32_t address)
  16. {
  17. _address.dword = address;
  18. }
  19. IPAddress::IPAddress(const uint8_t *address)
  20. {
  21. memcpy(_address.bytes, address, sizeof(_address));
  22. }
  23. IPAddress& IPAddress::operator=(const uint8_t *address)
  24. {
  25. memcpy(_address.bytes, address, sizeof(_address.bytes));
  26. return *this;
  27. }
  28. IPAddress& IPAddress::operator=(uint32_t address)
  29. {
  30. _address.dword = address;
  31. return *this;
  32. }
  33. bool IPAddress::operator==(const uint8_t* addr)
  34. {
  35. return memcmp(addr, _address.bytes, sizeof(_address.bytes)) == 0;
  36. }
  37. size_t IPAddress::printTo(Print& p) const
  38. {
  39. for (int i= 0; i < 3; i++) {
  40. p.print(_address.bytes[i], DEC);
  41. p.print('.');
  42. }
  43. p.print(_address.bytes[3], DEC);
  44. return 4;
  45. }
  46. #endif