Browse Source

Перехват вывода символов

pull/1/head
Sergey 5 years ago
parent
commit
9319c80be3
  1. 2
      Marlin/Configuration_adv.h
  2. 27
      Marlin/src/core/serial.h
  3. 5
      Marlin/src/gcode/gcode.cpp
  4. 3
      Marlin/src/gcode/queue.cpp
  5. 157
      Marlin/src/module/mks_wifi/mks_wifi.cpp
  6. 11
      Marlin/src/module/mks_wifi/mks_wifi.h
  7. 1
      Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h

2
Marlin/Configuration_adv.h

@ -2750,7 +2750,7 @@
/**
* Include capabilities in M115 output
*/
#define EXTENDED_CAPABILITIES_REPORT
//#define EXTENDED_CAPABILITIES_REPORT
/**
* Expected Printer Check

27
Marlin/src/core/serial.h

@ -22,7 +22,8 @@
#pragma once
#include "../inc/MarlinConfig.h"
#include "../module/mks_wifi/mks_wifi.h"
#include <stdio.h>
/**
* Define debug bit-masks
*/
@ -66,9 +67,26 @@ extern uint8_t marlin_debug_flags;
#define PORT_REDIRECT(p) _PORT_REDIRECT(1,p)
#define PORT_RESTORE() _PORT_RESTORE(1)
#if ENABLED(MKS_WIFI)
#define SERIAL_ECHO(x) do{ \
if (!serial_port_index || serial_port_index == SERIAL_BOTH) SERIAL_OUT(print, x); \
if ( serial_port_index) mks_println(x); \
}while(0)
#else
#define SERIAL_ECHO(x) SERIAL_OUT(print, x)
#endif
#define SERIAL_ECHO_F(V...) SERIAL_OUT(print, V)
#if ENABLED(MKS_WIFI)
#define SERIAL_ECHOLN(x) do{ \
if (!serial_port_index || serial_port_index == SERIAL_BOTH) SERIAL_OUT(println, x); \
if ( serial_port_index) mks_println_ln(x); \
}while(0)
#else
#define SERIAL_ECHOLN(x) SERIAL_OUT(println, x)
#endif
#define SERIAL_PRINT(x,b) SERIAL_OUT(print, x, b)
#define SERIAL_PRINTLN(x,b) SERIAL_OUT(println, x, b)
#define SERIAL_PRINTF(V...) SERIAL_OUT(printf, V)
@ -96,7 +114,14 @@ extern uint8_t marlin_debug_flags;
#define _CHAR_9(a,V...) do{ _CHAR_1(a); _CHAR_8(V); }while(0)
#define _CHAR_10(a,V...) do{ _CHAR_1(a); _CHAR_9(V); }while(0)
#if ENABLED(MKS_WIFI)
#define SERIAL_CHAR(V...) do{ \
if (!serial_port_index || serial_port_index == SERIAL_BOTH) _CHAR_N(NUM_ARGS(V),V); \
if ( serial_port_index) mks_wifi_out(NUM_ARGS(V),V); \
}while(0)
#else
#define SERIAL_CHAR(V...) _CHAR_N(NUM_ARGS(V),V)
#endif
// Print up to 12 pairs of values. Odd elements auto-wrapped in PSTR().
#define __SEP_N(N,V...) _SEP_##N(V)

5
Marlin/src/gcode/gcode.cpp

@ -851,6 +851,11 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 422: M422(); break; // M422: Set Z Stepper automatic alignment position using probe
#endif
#if ENABLED(MKS_WIFI)
case 991: M105(); return;
#endif
#if ENABLED(PLATFORM_M997_SUPPORT)
case 997: M997(); break; // M997: Perform in-application firmware update
#endif

3
Marlin/src/gcode/queue.cpp

@ -440,13 +440,10 @@ void GCodeQueue::get_serial_commands() {
if(i == MKS_WIFI_SERIAL_NUM){
if(mks_wifi_input(c)){
continue;
}else{
DEBUG("Char to Marlin");
};
}
if (ISEOL(serial_char)) {
// Reset our state, continue if the line was empty
if (process_line_done(serial_input_state[i], serial_line_buffer[i], serial_count[i]))
continue;

157
Marlin/src/module/mks_wifi/mks_wifi.cpp

@ -2,6 +2,17 @@
ESP_PROTOC_FRAME esp_frame;
uint8_t mks_buffer[ESP_PACKET_DATA_MAX_SIZE];
uint8_t mks_out_buffer[ESP_PACKET_DATA_MAX_SIZE];
uint8_t esp_packet[ESP_PACKET_DATA_MAX_SIZE];
/*
const char home_ssid[] = "MikroTik2";
const char home_passwd[] = "vg3Apswqvg3Aps";
*/
const char wifi_ap[]="bus_station";
const char wifi_key[]="RAnRZj2JQbSMD5djh3";
const uint8_t wifi_mode_sel=0;
void mks_wifi_init(void){
@ -11,11 +22,46 @@ void mks_wifi_init(void){
safe_delay(2000);
WRITE(MKS_WIFI_IO_RST, HIGH);
// safe_delay(2000);
// mks_wifi_set_param();
// SET_INPUT_PULLUP(MKS_WIFI_IO0);
// attachInterrupt(MKS_WIFI_IO0, mks_wifi_io0_irq, FALLING);
}
void mks_wifi_set_param(void){
char buf_to_wifi[256];
int index_to_wifi = 0;
int data_offset = 4;
int apLen = strlen((const char *)wifi_ap);
int keyLen = strlen((const char *)wifi_key);
memset(buf_to_wifi, 0, sizeof(buf_to_wifi));
index_to_wifi = 0;
buf_to_wifi[data_offset] = wifi_mode_sel;
buf_to_wifi[data_offset + 1] = apLen;
strncpy(&buf_to_wifi[data_offset + 2], (const char *)wifi_ap, apLen);
buf_to_wifi[data_offset + apLen + 2] = keyLen;
strncpy(&buf_to_wifi[data_offset + apLen + 3], (const char *)wifi_key, keyLen);
buf_to_wifi[data_offset + apLen + keyLen + 3] = ESP_PROTOC_TAIL;
DEBUG("Tail index %d",(data_offset + apLen + keyLen + 3));
index_to_wifi = apLen + keyLen + 3;
buf_to_wifi[0] = ESP_PROTOC_HEAD;
buf_to_wifi[1] = 0;
buf_to_wifi[2] = index_to_wifi & 0xff;
buf_to_wifi[3] = (index_to_wifi >> 8) & 0xff;
DEBUG("Sending config %d",(uint32_t)(5 + index_to_wifi));
for( uint32_t i=0; i< (uint32_t)(5 + index_to_wifi); i++){
while(MYSERIAL1.availableForWrite() == 0){NOP;};
MYSERIAL1.write(buf_to_wifi[i]);
}
}
/* Тестовая функция на обработчик EXTI прерывания */
void mks_wifi_io0_irq(void){
INFO("IO0 Irq");
@ -35,6 +81,7 @@ uint8_t mks_wifi_input(uint8_t data){
static uint16_t payload_size=ESP_PACKET_DATA_MAX_SIZE;
uint8_t ret_val=1;
if(data == ESP_PROTOC_HEAD){
payload_size = ESP_PACKET_DATA_MAX_SIZE;
packet_start_flag=1;
@ -68,7 +115,7 @@ uint8_t mks_wifi_input(uint8_t data){
/* Если в пакете G-Сode, отдаем payload дальше в обработчик марлина */
if((packet_type == ESP_TYPE_GCODE) &&
(packet_index >= 4) &&
(packet_index < (payload_size+5))
(packet_index < payload_size+5)
){
ret_val=0;
}
@ -94,7 +141,7 @@ void mks_wifi_parse_packet(ESP_PROTOC_FRAME *packet){
}
break;
case ESP_TYPE_GCODE:
DEBUG("[Gcode] %s",packet->data);
//DEBUG("[Gcode] %s",packet->data);
break;
case ESP_TYPE_FILE_FIRST:
DEBUG("[FILE_FIRST]");
@ -114,3 +161,107 @@ void mks_wifi_parse_packet(ESP_PROTOC_FRAME *packet){
}
void mks_wifi_out(uint8_t count, ...){
static uint16_t line_index=0;
va_list args;
uint8_t data;
uint16_t datalen;
uint16_t packet_size;
va_start(args, count);
while (count--) {
data = va_arg(args, unsigned);
if(data == 0x0a){
if(mks_out_buffer[line_index-1] == 't'){
DEBUG("Line");
}
//сформировать пакет
datalen=strnlen((char *)mks_out_buffer,ESP_PACKET_DATA_MAX_SIZE);
packet_size=mks_wifi_build_packet(esp_packet,ESP_TYPE_FILE_FIRST,mks_out_buffer,datalen);
//выпихнуть в uart
mks_wifi_send(esp_packet, packet_size);
DEBUG("%s",mks_out_buffer);
//очистить буфер
memset(mks_out_buffer,0,ESP_SERIAL_OUT_MAX_SIZE);
//сбросить индекс
line_index=0;
}else{
mks_out_buffer[line_index++]=data;
}
if(line_index >= ESP_SERIAL_OUT_MAX_SIZE){
DEBUG("Max line size");
line_index=0;
}
}
va_end(args);
}
void mks_println(const char *s){
uint16_t datalen;
uint16_t packet_size;
DEBUG("%s",s);
//сформировать пакет
datalen=strnlen((char *)mks_out_buffer,ESP_PACKET_DATA_MAX_SIZE);
packet_size=mks_wifi_build_packet(esp_packet,ESP_TYPE_FILE_FIRST,mks_out_buffer,datalen);
//выпихнуть в uart
mks_wifi_send(esp_packet, packet_size);
}
void mks_println_ln(const char *s){
DEBUG("NEW LN %s");
}
void mks_println_ln(float f){
DEBUG("NEW LN float %d",(uint32_t)f);
}
uint16_t mks_wifi_build_packet(uint8_t *packet, uint8_t type, uint8_t *data, uint16_t count){
uint16_t packet_size;
memset(packet,0,ESP_PACKET_DATA_MAX_SIZE);
packet[0] = ESP_PROTOC_HEAD;
packet[1] = type;
*((uint16_t *)&packet[2]) = count + 2; //Два байта на 0x0d 0x0a
for(uint32_t i=0; i < count; i++){
packet[i+4]=data[i];
}
packet_size = count + 4;
packet[count + 4] = 0x0d;
packet[count + 5] = 0x0a;
packet_size = count + 6; //Два байта на 0x0d 0x0a
packet[packet_size] = ESP_PROTOC_TAIL;
return packet_size;
}
void mks_wifi_send(uint8_t *packet, uint16_t size){
for( uint32_t i=0; i < (uint32_t)(size); i++){
MYSERIAL1.write(packet[i]);
}
}
void mks_println(int i){
DEBUG("int %d",i);
SERIAL_OUT(print, i);
}

11
Marlin/src/module/mks_wifi/mks_wifi.h

@ -26,6 +26,7 @@ typedef struct
#define ESP_TYPE_WIFI_LIST (uint8_t)0x4
#define ESP_PACKET_DATA_MAX_SIZE 1024
#define ESP_SERIAL_OUT_MAX_SIZE 1024
#define ESP_NET_WIFI_CONNECTED (uint8_t)0x0A
#define ESP_NET_WIFI_EXCEPTION (uint8_t)0x0E
@ -37,5 +38,15 @@ void mks_wifi_init(void);
void mks_wifi_io0_irq(void);
uint8_t mks_wifi_input(uint8_t data);
void mks_wifi_parse_packet(ESP_PROTOC_FRAME *packet);
void mks_wifi_set_param(void);
void mks_wifi_out(uint8_t count, ...);
void mks_println(const char *s);
void mks_println(int i);
uint16_t mks_wifi_build_packet(uint8_t *packet, uint8_t type, uint8_t *data, uint16_t count);
void mks_wifi_send(uint8_t *packet, uint16_t size);
void mks_println_ln(const char *s);
void mks_println_ln(float);
#endif

1
Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h

@ -158,6 +158,7 @@
#define MKS_WIFI
#ifdef MKS_WIFI
#undef PLATFORM_M997_SUPPORT
#define MKS_WIFI_IO0 PA8
#define MKS_WIFI_IO4 PC7
#define MKS_WIFI_IO_RST PA5

Loading…
Cancel
Save