Welcome to mirror list, hosted at ThFree Co, Russian Federation.

WiFiSocket.h « ESP8266WiFi « Networking « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 923f702065455767ce5f40305d60b878dfb481af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * WiFiSocket.h
 *
 *  Created on: 22 Apr 2017
 *      Author: David
 */

#ifndef SRC_NETWORKING_WIFISOCKET_H_
#define SRC_NETWORKING_WIFISOCKET_H_

#include "RepRapFirmware.h"
#include "Networking/NetworkDefs.h"
#include "Networking/Socket.h"


class WiFiInterface;

class WiFiSocket : public Socket
{
public:
	WiFiSocket(NetworkInterface *iface) noexcept;
	void Init(SocketNumber n) noexcept;
	int State() const noexcept { return (int)state; }				// used only for reporting debug info, hence the 'int' return
	void Poll() noexcept;
	void Close() noexcept;
	bool IsClosing() const noexcept { return (state == SocketState::closing); }
	void Terminate() noexcept;
	void TerminateAndDisable() noexcept { Terminate(); }
	bool ReadChar(char& c) noexcept;
	bool ReadBuffer(const uint8_t *&buffer, size_t &len) noexcept;
	void Taken(size_t len) noexcept;
	bool CanRead() const noexcept;
	bool CanSend() const noexcept;
	size_t Send(const uint8_t *data, size_t length) noexcept;
	void Send() noexcept;
	void SetNeedsPolling() noexcept { needsPolling = true; }
	bool NeedsPolling() const noexcept;

private:
	enum class SocketState : uint8_t
	{
		inactive,
		waitingForResponder,
		connected,
		clientDisconnecting,
		closing,
		broken
	};

	WiFiInterface *GetInterface() const noexcept;
	void ReceiveData(uint16_t bytesAvailable) noexcept;
	void DiscardReceivedData() noexcept;

	NetworkBuffer *receivedData;						// List of buffers holding received data
	uint32_t whenConnected;
	uint16_t txBufferSpace;								// How much free transmit buffer space the WiFi mofule reported
	SocketNumber socketNum;								// The WiFi socket number we are using
	SocketState state;
	bool needsPolling;
};

#endif /* SRC_NETWORKING_WIFISOCKET_H_ */