From 78d81269c23e7a2c390d6c12fa346e411eb5a0e5 Mon Sep 17 00:00:00 2001 From: psychegr Date: Sat, 20 Aug 2016 02:16:15 +0300 Subject: [PATCH 1/6] Add UDP Debug in debugf() and os_printf() --- sming_global.h | 41 +++++++++++++++++++++ udpDebug.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ udpDebug.h | 11 ++++++ 3 files changed, 150 insertions(+) create mode 100644 sming_global.h create mode 100644 udpDebug.c create mode 100644 udpDebug.h diff --git a/sming_global.h b/sming_global.h new file mode 100644 index 0000000..7c4c2bb --- /dev/null +++ b/sming_global.h @@ -0,0 +1,41 @@ +// Based on mziwisky espmissingincludes.h && ESP8266_IoT_SDK_Programming Guide_v0.9.1.pdf && ESP SDK defines + +#ifndef __SMING_GOLBAL_H__ +#define __SMING_GLOBAL_H__ + +#include +#include +#include + +#include "limits.h" + +#include +#include +#include + +#include "sming/include/sming_config.h" + +#include "sming/system/m_printf.h" +#include "sming/system/udpDebug.h" + +#define __ESP8266_EX__ // System definition ESP8266 SOC +#define __UDP_DEBUG__ +//#define __SERIAL_DEBUG__ + +//#define IRAM_ATTR __attribute__((section(".iram.text"))) +#define __forceinline __attribute__((always_inline)) inline +#define STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed)) +#define STORE_ATTR __attribute__((aligned(4))) + +//#undef assert +#if defined(__SERIAL_DEBUG__) +#define debugf(fmt, ...) m_printf(fmt"\r\n", ##__VA_ARGS__) +#elif defined(__UDP_DEBUG__) +#define debugf(fmt, ...) m_printf_udp(fmt"\r\n", ##__VA_ARGS__) +#endif +//#define assert(condition) if (!(condition)) SYSTEM_ERROR("ASSERT: %s %d", __FUNCTION__, __LINE__) +#define SYSTEM_ERROR(fmt, ...) printf("ERROR: " fmt "\r\n", ##__VA_ARGS__) + +typedef signed short file_t; + +#endif diff --git a/udpDebug.c b/udpDebug.c new file mode 100644 index 0000000..afb5b00 --- /dev/null +++ b/udpDebug.c @@ -0,0 +1,98 @@ +/* +Code to redirect both os_printf and debugf to UDP connection. +Created for use with Sming and SmingRTOS +Padelis Floudas 2016 +*/ + +#include "udpDebug.h" +#include "../include/sming_global.h" +#include "../core/stringconversion.h" +#include "../include/lwip_includes.h" + +#define debugPort 5000 +#define DBG_BUFFER_LEN 256 +#define MPRINTF_BUF_SIZE 256 + +char dbgBuffer[DBG_BUFFER_LEN]; +uint8_t dbg_BufferLen = 0; + +/* +tx_udp_char + +This function is for use with os_install_putc1(); +The original serial function sends each character separately. +To make this work with UDP connection i have to add each character to the char array +and when the NULL char is received, i send the packet. +*/ + +void tx_udp_char(char c) +{ + dbgBuffer[dbg_BufferLen++] = c; // add the character to the array + // and increase the index + + // check for NULL character and send + if(((c == 0x0A) && (dbg_BufferLen > 1)) || (dbg_BufferLen == DBG_BUFFER_LEN)) + { + struct udp_pcb *pcb; + struct pbuf *p; + struct ip_addr dst; + + pcb = udp_new(); + + // if there was an error creating the pcb then return + if(pcb == NULL) { + return; + } + p = pbuf_alloc(PBUF_TRANSPORT, dbg_BufferLen, PBUF_RAM); + memcpy(p->payload, dbgBuffer, dbg_BufferLen); + IP4_ADDR(&dst,192,168,4,255); + udp_sendto(pcb, p, &dst, debugPort); + pbuf_free(p); + + dbg_BufferLen = 0; + } +} + +/* +m_printf_udp + +This fuction replaces the Sming m_printf() function +It is used in the same way as in Sming +*/ +int m_printf_udp(const char *fmt, ...) +{ + char buf[MPRINTF_BUF_SIZE], *tmp; + va_list args; + struct udp_pcb *pcb; + struct pbuf *p; + struct ip_addr dst; + + va_start(args, fmt); + m_vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + // find the null character + tmp = buf; + int len = 0; + while (*tmp) + { + tmp++; + len++; + } + // len holds the size of the string that we want to send. + + pcb = udp_new(); + + // if there was an error creating the pcb then return + if(pcb == NULL) { + return 0; + } + + p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); // allocate memory for the buffer + memcpy(p->payload, buf, len); // copy data to buffer + IP4_ADDR(&dst,192,168,4,255); // create IP address + udp_sendto(pcb, p, &dst, debugPort); // broadcast message + pbuf_free(p); // free memory + + return 1; +} diff --git a/udpDebug.h b/udpDebug.h new file mode 100644 index 0000000..21a3943 --- /dev/null +++ b/udpDebug.h @@ -0,0 +1,11 @@ + +#ifdef __cplusplus +extern "C" { +#endif + +void tx_udp_char(char c); +int m_printf_udp(const char *fmt, ...); + +#ifdef __cplusplus +} +#endif From 452614e1e5e778975a6917567b11c4ed5ce87516 Mon Sep 17 00:00:00 2001 From: psychegr Date: Sat, 20 Aug 2016 02:22:54 +0300 Subject: [PATCH 2/6] Delete udpDebug.c --- udpDebug.c | 98 ------------------------------------------------------ 1 file changed, 98 deletions(-) delete mode 100644 udpDebug.c diff --git a/udpDebug.c b/udpDebug.c deleted file mode 100644 index afb5b00..0000000 --- a/udpDebug.c +++ /dev/null @@ -1,98 +0,0 @@ -/* -Code to redirect both os_printf and debugf to UDP connection. -Created for use with Sming and SmingRTOS -Padelis Floudas 2016 -*/ - -#include "udpDebug.h" -#include "../include/sming_global.h" -#include "../core/stringconversion.h" -#include "../include/lwip_includes.h" - -#define debugPort 5000 -#define DBG_BUFFER_LEN 256 -#define MPRINTF_BUF_SIZE 256 - -char dbgBuffer[DBG_BUFFER_LEN]; -uint8_t dbg_BufferLen = 0; - -/* -tx_udp_char - -This function is for use with os_install_putc1(); -The original serial function sends each character separately. -To make this work with UDP connection i have to add each character to the char array -and when the NULL char is received, i send the packet. -*/ - -void tx_udp_char(char c) -{ - dbgBuffer[dbg_BufferLen++] = c; // add the character to the array - // and increase the index - - // check for NULL character and send - if(((c == 0x0A) && (dbg_BufferLen > 1)) || (dbg_BufferLen == DBG_BUFFER_LEN)) - { - struct udp_pcb *pcb; - struct pbuf *p; - struct ip_addr dst; - - pcb = udp_new(); - - // if there was an error creating the pcb then return - if(pcb == NULL) { - return; - } - p = pbuf_alloc(PBUF_TRANSPORT, dbg_BufferLen, PBUF_RAM); - memcpy(p->payload, dbgBuffer, dbg_BufferLen); - IP4_ADDR(&dst,192,168,4,255); - udp_sendto(pcb, p, &dst, debugPort); - pbuf_free(p); - - dbg_BufferLen = 0; - } -} - -/* -m_printf_udp - -This fuction replaces the Sming m_printf() function -It is used in the same way as in Sming -*/ -int m_printf_udp(const char *fmt, ...) -{ - char buf[MPRINTF_BUF_SIZE], *tmp; - va_list args; - struct udp_pcb *pcb; - struct pbuf *p; - struct ip_addr dst; - - va_start(args, fmt); - m_vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - - // find the null character - tmp = buf; - int len = 0; - while (*tmp) - { - tmp++; - len++; - } - // len holds the size of the string that we want to send. - - pcb = udp_new(); - - // if there was an error creating the pcb then return - if(pcb == NULL) { - return 0; - } - - p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); // allocate memory for the buffer - memcpy(p->payload, buf, len); // copy data to buffer - IP4_ADDR(&dst,192,168,4,255); // create IP address - udp_sendto(pcb, p, &dst, debugPort); // broadcast message - pbuf_free(p); // free memory - - return 1; -} From 05314beea5227b3e03b6252407aa41553e739511 Mon Sep 17 00:00:00 2001 From: psychegr Date: Sat, 20 Aug 2016 02:23:04 +0300 Subject: [PATCH 3/6] Delete sming_global.h --- sming_global.h | 41 ----------------------------------------- 1 file changed, 41 deletions(-) delete mode 100644 sming_global.h diff --git a/sming_global.h b/sming_global.h deleted file mode 100644 index 7c4c2bb..0000000 --- a/sming_global.h +++ /dev/null @@ -1,41 +0,0 @@ -// Based on mziwisky espmissingincludes.h && ESP8266_IoT_SDK_Programming Guide_v0.9.1.pdf && ESP SDK defines - -#ifndef __SMING_GOLBAL_H__ -#define __SMING_GLOBAL_H__ - -#include -#include -#include - -#include "limits.h" - -#include -#include -#include - -#include "sming/include/sming_config.h" - -#include "sming/system/m_printf.h" -#include "sming/system/udpDebug.h" - -#define __ESP8266_EX__ // System definition ESP8266 SOC -#define __UDP_DEBUG__ -//#define __SERIAL_DEBUG__ - -//#define IRAM_ATTR __attribute__((section(".iram.text"))) -#define __forceinline __attribute__((always_inline)) inline -#define STORE_TYPEDEF_ATTR __attribute__((aligned(4),packed)) -#define STORE_ATTR __attribute__((aligned(4))) - -//#undef assert -#if defined(__SERIAL_DEBUG__) -#define debugf(fmt, ...) m_printf(fmt"\r\n", ##__VA_ARGS__) -#elif defined(__UDP_DEBUG__) -#define debugf(fmt, ...) m_printf_udp(fmt"\r\n", ##__VA_ARGS__) -#endif -//#define assert(condition) if (!(condition)) SYSTEM_ERROR("ASSERT: %s %d", __FUNCTION__, __LINE__) -#define SYSTEM_ERROR(fmt, ...) printf("ERROR: " fmt "\r\n", ##__VA_ARGS__) - -typedef signed short file_t; - -#endif From 3d0a1ad032df064e515610867443500d95f93d7a Mon Sep 17 00:00:00 2001 From: psychegr Date: Sat, 20 Aug 2016 02:23:11 +0300 Subject: [PATCH 4/6] Delete udpDebug.h --- udpDebug.h | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 udpDebug.h diff --git a/udpDebug.h b/udpDebug.h deleted file mode 100644 index 21a3943..0000000 --- a/udpDebug.h +++ /dev/null @@ -1,11 +0,0 @@ - -#ifdef __cplusplus -extern "C" { -#endif - -void tx_udp_char(char c); -int m_printf_udp(const char *fmt, ...); - -#ifdef __cplusplus -} -#endif From d76c35f13200bf42da97bc2230d324a6c07fd4fa Mon Sep 17 00:00:00 2001 From: psychegr Date: Sat, 20 Aug 2016 02:23:52 +0300 Subject: [PATCH 5/6] Add UDP Debug in debugf() and os_printf() --- sming/sming/system/udpDebug.c | 98 +++++++++++++++++++++++++++++++++++ sming/sming/system/udpDebug.h | 11 ++++ 2 files changed, 109 insertions(+) create mode 100644 sming/sming/system/udpDebug.c create mode 100644 sming/sming/system/udpDebug.h diff --git a/sming/sming/system/udpDebug.c b/sming/sming/system/udpDebug.c new file mode 100644 index 0000000..afb5b00 --- /dev/null +++ b/sming/sming/system/udpDebug.c @@ -0,0 +1,98 @@ +/* +Code to redirect both os_printf and debugf to UDP connection. +Created for use with Sming and SmingRTOS +Padelis Floudas 2016 +*/ + +#include "udpDebug.h" +#include "../include/sming_global.h" +#include "../core/stringconversion.h" +#include "../include/lwip_includes.h" + +#define debugPort 5000 +#define DBG_BUFFER_LEN 256 +#define MPRINTF_BUF_SIZE 256 + +char dbgBuffer[DBG_BUFFER_LEN]; +uint8_t dbg_BufferLen = 0; + +/* +tx_udp_char + +This function is for use with os_install_putc1(); +The original serial function sends each character separately. +To make this work with UDP connection i have to add each character to the char array +and when the NULL char is received, i send the packet. +*/ + +void tx_udp_char(char c) +{ + dbgBuffer[dbg_BufferLen++] = c; // add the character to the array + // and increase the index + + // check for NULL character and send + if(((c == 0x0A) && (dbg_BufferLen > 1)) || (dbg_BufferLen == DBG_BUFFER_LEN)) + { + struct udp_pcb *pcb; + struct pbuf *p; + struct ip_addr dst; + + pcb = udp_new(); + + // if there was an error creating the pcb then return + if(pcb == NULL) { + return; + } + p = pbuf_alloc(PBUF_TRANSPORT, dbg_BufferLen, PBUF_RAM); + memcpy(p->payload, dbgBuffer, dbg_BufferLen); + IP4_ADDR(&dst,192,168,4,255); + udp_sendto(pcb, p, &dst, debugPort); + pbuf_free(p); + + dbg_BufferLen = 0; + } +} + +/* +m_printf_udp + +This fuction replaces the Sming m_printf() function +It is used in the same way as in Sming +*/ +int m_printf_udp(const char *fmt, ...) +{ + char buf[MPRINTF_BUF_SIZE], *tmp; + va_list args; + struct udp_pcb *pcb; + struct pbuf *p; + struct ip_addr dst; + + va_start(args, fmt); + m_vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + // find the null character + tmp = buf; + int len = 0; + while (*tmp) + { + tmp++; + len++; + } + // len holds the size of the string that we want to send. + + pcb = udp_new(); + + // if there was an error creating the pcb then return + if(pcb == NULL) { + return 0; + } + + p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM); // allocate memory for the buffer + memcpy(p->payload, buf, len); // copy data to buffer + IP4_ADDR(&dst,192,168,4,255); // create IP address + udp_sendto(pcb, p, &dst, debugPort); // broadcast message + pbuf_free(p); // free memory + + return 1; +} diff --git a/sming/sming/system/udpDebug.h b/sming/sming/system/udpDebug.h new file mode 100644 index 0000000..21a3943 --- /dev/null +++ b/sming/sming/system/udpDebug.h @@ -0,0 +1,11 @@ + +#ifdef __cplusplus +extern "C" { +#endif + +void tx_udp_char(char c); +int m_printf_udp(const char *fmt, ...); + +#ifdef __cplusplus +} +#endif From 3704506fa750a9119732d1b989ea53222826be3d Mon Sep 17 00:00:00 2001 From: psychegr Date: Sat, 20 Aug 2016 02:24:30 +0300 Subject: [PATCH 6/6] Add UDP Debug in debugf() and os_printf() --- sming/sming/include/sming_global.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sming/sming/include/sming_global.h b/sming/sming/include/sming_global.h index 9c5c982..7c4c2bb 100644 --- a/sming/sming/include/sming_global.h +++ b/sming/sming/include/sming_global.h @@ -16,8 +16,11 @@ #include "sming/include/sming_config.h" #include "sming/system/m_printf.h" +#include "sming/system/udpDebug.h" #define __ESP8266_EX__ // System definition ESP8266 SOC +#define __UDP_DEBUG__ +//#define __SERIAL_DEBUG__ //#define IRAM_ATTR __attribute__((section(".iram.text"))) #define __forceinline __attribute__((always_inline)) inline @@ -25,7 +28,11 @@ #define STORE_ATTR __attribute__((aligned(4))) //#undef assert -#define debugf(fmt, ...) m_printf(fmt"\r\n", ##__VA_ARGS__) +#if defined(__SERIAL_DEBUG__) +#define debugf(fmt, ...) m_printf(fmt"\r\n", ##__VA_ARGS__) +#elif defined(__UDP_DEBUG__) +#define debugf(fmt, ...) m_printf_udp(fmt"\r\n", ##__VA_ARGS__) +#endif //#define assert(condition) if (!(condition)) SYSTEM_ERROR("ASSERT: %s %d", __FUNCTION__, __LINE__) #define SYSTEM_ERROR(fmt, ...) printf("ERROR: " fmt "\r\n", ##__VA_ARGS__)