forked from TaraHoleInIt/SLIP8266
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmydebug.cpp
More file actions
67 lines (56 loc) · 1.81 KB
/
mydebug.cpp
File metadata and controls
67 lines (56 loc) · 1.81 KB
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
63
64
65
66
67
#include <ESP8266WiFi.h>
#include <lwip/netif.h>
#include <lwip/err.h>
#include <stdarg.h>
#include "ether.h"
#include "ipv4.h"
#include "util.h"
#include "slip.h"
#include "mydebug.h"
extern "C" {
#include <netif/wlan_lwip_if.h>
#include <lwip/inet_chksum.h>
#include <user_interface.h>
}
/*
* Sends a printf formatted string and arguments to the serial port.
*/
int DebugPrintf_UART( const char* Message, ... ) {
char DebugTextBuffer[ 512 ];
int Length = 0;
va_list Argp;
va_start( Argp, Message );
Length = vsnprintf( DebugTextBuffer, sizeof( DebugTextBuffer ), Message, Argp );
va_end( Argp );
Serial1.write( DebugTextBuffer );
return Length;
}
/*
* Sends a printf formatted string and arugments over WiFi with an ethertype of 0xBEEF.
*/
int DebugPrintf_EtherFrame( const char* Message, ... ) {
char DebugTextBuffer[ 512 ];
struct EtherFrame* FrameHeader = ( struct EtherFrame* ) DebugTextBuffer;
int Length = 0;
int Offset = 0;
va_list Argp;
Offset = PrepareEthernetHeader( FrameHeader, OurMACAddress, BroadcastMACAddress, 0xBEEF );
va_start( Argp, Message );
Length = vsnprintf( &DebugTextBuffer[ Offset ], sizeof( DebugTextBuffer ) - Offset, Message, Argp );
va_end( Argp );
EtherWrite( ( uint8_t* ) DebugTextBuffer, Offset + Length + 1 );
return Length;
}
/*
* Sends a printf formatted string and arguments as a UDP broadcast to port 7810.
*/
int DebugPrintf_UDP( const char* Message, ... ) {
char DebugTextBuffer[ 512 ];
int Length = 0;
va_list Argp;
va_start( Argp, Message );
Length = vsnprintf( DebugTextBuffer, sizeof( DebugTextBuffer ), Message, Argp );
va_end( Argp );
UDP_BuildOutgoingPacket( OurIPAddress, IPAddress( 192, 168, 2, 255 ), 7810, ( const uint8_t* ) DebugTextBuffer, Length + 1 );
return Length;
}