24 #include "EthernetLink.h"
25 #include <PJONDefines.h>
28 #ifndef ETCP_RECEIVE_TIME
29 #define ETCP_RECEIVE_TIME 0
36 uint16_t last_send_result = PJON_FAIL;
40 uint8_t *incoming_packet_buf_ptr = NULL;
41 uint16_t current_buffer_size = 0;
42 uint16_t incoming_packet_size = 0;
44 static void static_receiver(
46 const uint8_t *payload,
52 ((
EthernetTCP*)callback_object)->receiver(
id, payload, length);
57 void receiver(uint8_t ,
const uint8_t *payload, uint16_t length)
59 if(length <= current_buffer_size && incoming_packet_buf_ptr != NULL) {
60 memcpy(incoming_packet_buf_ptr, payload, length);
61 incoming_packet_size = length;
68 link.set_receiver(static_receiver,
this);
72 WSAStartup(MAKEWORD(2, 2), &wsaData);
87 uint32_t back_off(uint8_t attempts)
89 return 10000ul*attempts;
96 bool begin(uint8_t = 0)
106 return link.device_id() != 0;
112 static uint8_t get_max_attempts()
120 static uint16_t get_receive_time()
122 return ETCP_RECEIVE_TIME;
128 void handle_collision() { };
133 uint16_t receive_frame(uint8_t *
data, uint16_t max_length)
136 incoming_packet_buf_ptr =
data;
137 current_buffer_size = max_length;
138 incoming_packet_size = 0;
141 uint16_t result = link.receive();
144 uint16_t received_packet_size = incoming_packet_size;
145 incoming_packet_buf_ptr = NULL;
146 incoming_packet_size = 0;
148 return result == PJON_ACK ? received_packet_size : PJON_FAIL;
154 uint16_t receive_response()
156 return last_send_result;
162 void send_response(uint8_t )
169 void send_frame(uint8_t *
data, uint16_t length)
173 link.send((uint8_t)
data[0], (
const uint8_t*)
data, length);