bool manageMessage(
char
*
readStr,
int
readSize){
#if
0
if
(strstr((
const
char
*
)readStr,
"M29"
)
!
=
0
)
{
if
(
!
verification_flag)
{
break
;
}
if
(transfer_state
!
=
TRANSFER_IDLE)
{
rcv_end_flag
=
true
;
net_print((
const
uint8_t
*
)
"ok\n"
, strlen((
const
char
*
)
"ok\n"
));
break
;
}
}
#endif
DEBUG_PRINT(F(
"transfer_file_flag "
));
DEBUG_PRINTLN(transfer_file_flag);
DEBUG_PRINT(F(
"verification_flag "
));
DEBUG_PRINTLN(verification_flag);
DEBUG_PRINT(F(
"readStr "
));
DEBUG_PRINTLN(readStr);
DEBUG_PRINT(F(
"readSize "
));
DEBUG_PRINTLN(readSize);
if
(transfer_file_flag)
{
if
(
!
verification_flag)
{
return
false
;
}
if
(gFileFifo.left() >
=
readSize)
{
gFileFifo.push((
char
*
)readStr, readSize);
transfer_frags
+
=
readSize;
}
}
else
{
if
(verification_flag)
{
int
j
=
0
;
char
cmd_line[
100
]
=
{
0
};
String gcodeM3
=
""
;
#if
0
if
(transfer_state
=
=
TRANSFER_BEGIN)
{
if
(strstr((
const
char
*
)readStr,
"M110"
)
!
=
0
)
{
file_fragment
=
0
;
rcv_end_flag
=
false
;
transfer_file_flag
=
true
;
if
(package_file_first(filePath)
=
=
0
)
{
}
else
{
transfer_file_flag
=
false
;
transfer_state
=
TRANSFER_IDLE;
}
net_print((
const
uint8_t
*
)
"ok\n"
, strlen((
const
char
*
)
"ok\n"
));
break
;
}
}
#endif
init_queue(
&
cmd_queue);
cmd_index
=
0
;
memset(cmd_fifo,
0
,
sizeof
(cmd_fifo));
while
(j < readSize)
{
if
((readStr[j]
=
=
'\r'
)
|
|
(readStr[j]
=
=
'\n'
))
{
if
((cmd_index) >
1
)
{
cmd_fifo[cmd_index]
=
'\n'
;
cmd_index
+
+
;
push_queue(
&
cmd_queue, cmd_fifo, cmd_index);
}
memset(cmd_fifo,
0
,
sizeof
(cmd_fifo));
cmd_index
=
0
;
}
else
if
(readStr[j]
=
=
'\0'
)
break
;
else
{
if
(cmd_index >
=
sizeof
(cmd_fifo))
{
memset(cmd_fifo,
0
,
sizeof
(cmd_fifo));
cmd_index
=
0
;
}
cmd_fifo[cmd_index]
=
readStr[j];
cmd_index
+
+
;
}
j
+
+
;
do_transfer();
yield();
}
while
(pop_queue(
&
cmd_queue, cmd_line,
sizeof
(cmd_line)) >
=
0
)
{
#if
0
point
=
strstr((
const
char
*
)cmd_line,
"M28 "
);
if
(point
!
=
0
)
{
if
((strstr((
const
char
*
)cmd_line,
".g"
)
|
|
strstr((
const
char
*
)cmd_line,
".G"
)))
{
int
index
=
0
;
char
*
fileName;
point
+
=
3
;
while
(
*
(point
+
index)
=
=
' '
)
index
+
+
;
memcpy((
char
*
)filePath, (
const
char
*
)(point
+
index), readSize
-
(
int
)(point
+
index
-
(
int
)(
&
cmd_line[
0
])));
gFileFifo.reset();
transfer_frags
=
0
;
transfer_state
=
TRANSFER_BEGIN;
sprintf((
char
*
)dbgStr,
"Writing to file:%s\n"
, (
char
*
)filePath);
net_print((
const
uint8_t
*
)dbgStr, strlen((
const
char
*
)dbgStr));
}
}
else
#endif
{
if
((strchr((
const
char
*
)cmd_line,
'G'
)
!
=
0
)
|
|
(strchr((
const
char
*
)cmd_line,
'M'
)
!
=
0
)
|
|
(strchr((
const
char
*
)cmd_line,
'T'
)
!
=
0
))
{
if
(strchr((
const
char
*
)cmd_line,
'\n'
)
!
=
0
)
{
String gcode((
const
char
*
)cmd_line);
if
(gcode.startsWith(
"M998"
)
&
&
(M3_TYPE
=
=
ROBIN))
{
net_print((
const
uint8_t
*
)
"ok\r\n"
, strlen((
const
char
*
)
"ok\r\n"
));
}
else
if
(gcode.startsWith(
"M997"
))
{
if
(gPrinterInf.print_state
=
=
PRINTER_IDLE)
strcpy((
char
*
)dbgStr,
"M997 IDLE\r\n"
);
else
if
(gPrinterInf.print_state
=
=
PRINTER_PRINTING)
strcpy((
char
*
)dbgStr,
"M997 PRINTING\r\n"
);
else
if
(gPrinterInf.print_state
=
=
PRINTER_PAUSE)
strcpy((
char
*
)dbgStr,
"M997 PAUSE\r\n"
);
else
strcpy((
char
*
)dbgStr,
"M997 NOT CONNECTED\r\n"
);
}
else
if
(gcode.startsWith(
"M27"
))
{
memset(dbgStr,
0
,
sizeof
(dbgStr));
sprintf((
char
*
)dbgStr,
"M27 %d\r\n"
, gPrinterInf.print_file_inf.print_rate);
}
else
if
(gcode.startsWith(
"M992"
))
{
memset(dbgStr,
0
,
sizeof
(dbgStr));
sprintf((
char
*
)dbgStr,
"M992 %02d:%02d:%02d\r\n"
,
gPrinterInf.print_file_inf.print_hours, gPrinterInf.print_file_inf.print_mins, gPrinterInf.print_file_inf.print_seconds);
}
else
if
(gcode.startsWith(
"M994"
))
{
memset(dbgStr,
0
,
sizeof
(dbgStr));
sprintf((
char
*
)dbgStr,
"M994 %s;%d\r\n"
,
gPrinterInf.print_file_inf.file_name.c_str(), gPrinterInf.print_file_inf.file_size);
}
else
if
(gcode.startsWith(
"M115"
))
{
memset(dbgStr,
0
,
sizeof
(dbgStr));
if
(M3_TYPE
=
=
ROBIN)
strcpy((
char
*
)dbgStr,
"FIRMWARE_NAME:Robin\r\n"
);
else
if
(M3_TYPE
=
=
TFT28)
strcpy((
char
*
)dbgStr,
"FIRMWARE_NAME:TFT28/32\r\n"
);
else
if
(M3_TYPE
=
=
TFT24)
strcpy((
char
*
)dbgStr,
"FIRMWARE_NAME:TFT24\r\n"
);
}
else
{
DEBUG_PRINT(F(
"GCODE COMMANDS "
));
DEBUG_PRINTLN(gcode);
if
(gPrinterInf.print_state
=
=
PRINTER_IDLE)
{
if
(gcode.startsWith(
"M23"
)
|
|
gcode.startsWith(
"M24"
))
{
gPrinterInf.print_state
=
PRINTER_PRINTING;
gPrinterInf.print_file_inf.file_name
=
""
;
gPrinterInf.print_file_inf.file_size
=
0
;
gPrinterInf.print_file_inf.print_rate
=
0
;
gPrinterInf.print_file_inf.print_hours
=
0
;
gPrinterInf.print_file_inf.print_mins
=
0
;
gPrinterInf.print_file_inf.print_seconds
=
0
;
printFinishFlag
=
false
;
}
}
gcodeM3.concat(gcode);
}
}
}
}
if
(strlen((
const
char
*
)dbgStr) >
0
)
{
net_print((
const
uint8_t
*
)
"ok\r\n"
, strlen((
const
char
*
)
"ok\r\n"
));
net_print((
const
uint8_t
*
) dbgStr, strlen((
const
char
*
)dbgStr));
memset(dbgStr,
0
,
sizeof
(dbgStr));
}
do_transfer();
yield();
}
if
(gcodeM3.length() >
2
)
{
package_gcode(gcodeM3,
true
);
do_transfer();
socket_busy_stamp
=
millis
();
}
}
}
return
true
;
}