Commit 982af81d authored by Martin Vítek's avatar Martin Vítek

Add ICMP debug

parent 58520618
......@@ -8,6 +8,9 @@
#include "ADC_class.h"
#include "NixieClock.h"
#include "ENC28J60.h"
#include "IP_protocol.h"
#include "ICMP_protocol.h"
#include "UDP_protocol.h"
USART uart(SERCOM1->USART, 500000);
......@@ -194,6 +197,23 @@ void Debug::ip_packet(const IP_packet* packet)
uart.send_new_line();
}
void Debug::icmp_packet(const ICMP_packet* packet)
{
uart.send("[ICMP] ");
switch (packet->type)
{
case ECHO_REPLY: uart.send("Echo reply");
break;
case ECHO_REQUEST: uart.send("Echo request");
break;
default: uart.send("Unkown");
}
uart.send_new_line();
}
void Debug::tx_status(const ENC28J60_namespace::tx_status_vector& status, bool simple/*= true*/)
{
debug.info("TX status vector: ");
......
......@@ -4,6 +4,8 @@
#include "ethernet_frame.h"
#include "ENC28J60.h"
#include "IP_protocol.h"
#include "ICMP_protocol.h"
#include "UDP_protocol.h"
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
......@@ -47,6 +49,7 @@ class Debug
void frame(const ethernet_frame* frame);
void frame_type(const ethernet_frame* frame);
void ip_packet(const IP_packet* packet);
void icmp_packet(const ICMP_packet* packet);
void tx_status(const ENC28J60_namespace::tx_status_vector& status, bool simple=true);
void rx_status(const ENC28J60_namespace::rx_status_vector& status, bool simple=true);
void adc();
......
......@@ -668,19 +668,19 @@ namespace ENC28J60_namespace
//printf_P(PSTR("Revision: "));
switch (read_control_register(EREVID))
{
case B1: debug.info("Revision: B1");
case B1: debug.info("ENC28j60 revision: B1");
break;
case B4: debug.info("Revision: B4");
case B4: debug.info("ENC28j60 revision: B4");
break;
case B5: debug.info("Revision: B5");
case B5: debug.info("ENC28j60 revision: B5");
break;
case B7: debug.info("Revision: B7");
case B7: debug.info("ENC28j60 revision: B7");
break;
default: debug.info("Revision: unknown");
default: debug.info("ENC28j60 revision: unknown");
break;
}
}
......
#include "ICMP_protocol.h"
#include <cstdint>
#include <machine/endian.h>
#include "USART.h"
#include "Debug.h"
ICMP_protocol::ICMP_protocol()
{
}
void ICMP_protocol::decode(const uint8_t* data, const uint16_t length)
{
ICMP_packet* packet = (ICMP_packet*) data;
debug.icmp_packet(packet);
if (packet->type == ECHO_REQUEST)
{
ICMP_echo_packet* echo_packet = (ICMP_echo_packet*) data;
/*
debug.info("Got IPCM echo request");
uart.send("\t\tIdentifier: ");uart.send_dec(__ntohs(echo_packet->identifier));uart.send_new_line();
uart.send("\t\tSequence number: ");uart.send_dec(__ntohs(echo_packet->sequence_number));uart.send_new_line();
*/
}
}
......@@ -48,5 +48,7 @@ class ICMP_protocol
public:
ICMP_protocol();
void decode(const uint8_t* data, const uint16_t length);
};
......@@ -4,10 +4,13 @@
#include "ethernet_frame.h"
#include "NetworkTypes.h"
#include "ICMP_protocol.h"
#include "UDP_protocol.h"
#include "USART.h"
#include "Debug.h"
IP_protocol::IP_protocol(const IP& local_ip): udp(),
IP_protocol::IP_protocol(const IP& local_ip): icmp(),
udp(),
local_ip(local_ip)
{
}
......@@ -25,7 +28,7 @@ void IP_protocol::decode(const ethernet_payload& payload)
switch (packet->protocol)
{
case ICMP:
case ICMP: icmp.decode(packet->data, packet->tl - (packet->ihl*4));
break;
case TCP:
......
......@@ -4,6 +4,7 @@
#include "ethernet_frame.h"
#include "NetworkTypes.h"
#include "ICMP_protocol.h"
#include "UDP_protocol.h"
enum IP_protocols
......@@ -59,6 +60,7 @@ struct IP_packet
class IP_protocol
{
private:
ICMP_protocol icmp;
UDP_protocol udp;
const IP& local_ip;
......
......@@ -109,8 +109,7 @@ int main(void)
//Init network stack and ENC28J60
stack.init();
stack.test_tx();
time_t old = 0;
......
......@@ -256,6 +256,12 @@
<Compile Include="GPIO.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="ICMP_protocol.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="ICMP_protocol.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="IP_protocol.cpp">
<SubType>compile</SubType>
</Compile>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment