-
Notifications
You must be signed in to change notification settings - Fork 1
Wifi UDP class and Begin function #106
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2c48303
libraries/WiFi: WiFiUDP Class added.
IFX-Anusha 3f7a56a
tests/arduino-core-tests: UDP test case.
IFX-Anusha 2945500
libraries/Wire: Changes in socket.begin function.
IFX-Anusha bb343b4
tests/arduino-core-tests: Begin test.
IFX-Anusha 724bd66
libraries/WiFi: Added protocol member via Socket.begin().
jaenrig-ifx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "WiFiUdp.h" | ||
#include <Arduino.h> | ||
|
||
#define udp_assert(cy_ret) if (cy_ret != CY_RSLT_SUCCESS) { \ | ||
_status = SOCKET_STATUS_ERROR; \ | ||
return; \ | ||
} | ||
|
||
#define udp_assert_raise(cy_ret) if (cy_ret != CY_RSLT_SUCCESS) { \ | ||
return cy_ret; \ | ||
} | ||
|
||
WiFiUDP::WiFiUDP() : | ||
client_handle(nullptr), | ||
_status(SOCKET_STATUS_UNINITED), | ||
_last_error(CY_RSLT_SUCCESS), | ||
remote_ip(0, 0, 0, 0), | ||
_port(0) { | ||
} | ||
|
||
uint8_t WiFiUDP::begin(uint16_t port) { | ||
_port = port; | ||
|
||
// Initialize the socket for UDP | ||
socket.begin(SOCKET_PROTOCOL_UDP); | ||
if (socket.status() != SOCKET_STATUS_CREATED) { | ||
return 0; // Return 0 if socket creation fails | ||
} | ||
// Bind the socket to the specified port | ||
socket.bind(port); | ||
if (socket.status() != SOCKET_STATUS_BOUND) { | ||
return 0; // Return 0 if binding fail | ||
|
||
} | ||
return socket.status(); // Return the socket status | ||
} | ||
|
||
|
||
void WiFiUDP::stop() { | ||
|
||
} | ||
|
||
int WiFiUDP::beginPacket(IPAddress ip, uint16_t port) { | ||
return 0; | ||
} | ||
|
||
int WiFiUDP::beginPacket(const char *host, uint16_t port) { | ||
return 0; | ||
} | ||
|
||
int WiFiUDP::endPacket() { | ||
return 0; | ||
} | ||
|
||
size_t WiFiUDP::write(uint8_t) { | ||
return 0; | ||
} | ||
|
||
size_t WiFiUDP::write(const uint8_t *buffer, size_t size) { | ||
return 0; | ||
} | ||
|
||
int WiFiUDP::parsePacket() { | ||
return 0; | ||
} | ||
|
||
int WiFiUDP::available() { | ||
return 0; | ||
} | ||
|
||
int WiFiUDP::read() { | ||
return 0; | ||
} | ||
|
||
int WiFiUDP::read(unsigned char *buffer, size_t len) { | ||
return 0; | ||
} | ||
|
||
int WiFiUDP::read(char *buffer, size_t len) { | ||
return 0; | ||
} | ||
|
||
int WiFiUDP::peek() { | ||
return 0; | ||
} | ||
|
||
void WiFiUDP::flush() { | ||
return; | ||
} | ||
|
||
IPAddress WiFiUDP::remoteIP() { | ||
return IPAddress(); | ||
} | ||
|
||
uint16_t WiFiUDP::remotePort() { | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#ifndef WIFI_UDP_H | ||
#define WIFI_UDP_H | ||
|
||
#include <stdint.h> | ||
#include <string.h> | ||
#include <api/Udp.h> | ||
#include "WiFiClient.h" | ||
#include "WiFi.h" | ||
#include "WiFiServer.h" | ||
#include "SecSocket.h" | ||
|
||
class WiFiUDP: public arduino::UDP { | ||
public: | ||
WiFiUDP(); | ||
uint8_t begin(uint16_t); | ||
|
||
// yet to implement these functions | ||
void stop(); | ||
int beginPacket(IPAddress ip, uint16_t port); | ||
int beginPacket(const char *host, uint16_t port); | ||
int endPacket(); | ||
size_t write(uint8_t); | ||
size_t write(const uint8_t *buffer, size_t size); | ||
|
||
using Print::write; | ||
int parsePacket(); | ||
int available(); | ||
int read(); | ||
int read(unsigned char *buffer, size_t len); | ||
int read(char *buffer, size_t len); | ||
int peek(); | ||
void flush(); | ||
IPAddress remoteIP(); | ||
uint16_t remotePort(); | ||
|
||
|
||
|
||
private: | ||
Socket socket; | ||
|
||
cy_socket_t client_handle; | ||
socket_status_t _status; | ||
cy_rslt_t _last_error; | ||
IPAddress remote_ip; | ||
uint16_t _port; | ||
|
||
}; | ||
|
||
#endif /* WIFI_UDP_H */ |
Submodule arduino-core-tests
updated
13 files
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Socket class is already there. Shouldn´t we extend it for UPD?
When UDP we use recvFrom() and sendTo() instead of recv() and send(). The create() gets different arguments but many other things would be reusable.
And other functions are simply not used for UDP.
https://github.com/Infineon/mtb-example-wifi-udp-client/blob/master/source/udp_client.c
https://github.com/Infineon/mtb-example-threadx-wifi-udp-server/blob/master/udp_server.c