WORKS but need cleanup
This commit is contained in:
@@ -391,6 +391,7 @@ bool ecmcGrbl::WriteGCodeSuccess() {
|
||||
setReset(0);
|
||||
setReset(1);
|
||||
setReset(0);
|
||||
printf("SOMETHING BAD HAPPEND!!!!\n");
|
||||
grblCommandBufferIndex_ = 0;
|
||||
return false; // for loop
|
||||
}
|
||||
@@ -398,6 +399,7 @@ bool ecmcGrbl::WriteGCodeSuccess() {
|
||||
grblCommandBufferIndex_++;
|
||||
}
|
||||
else {
|
||||
printf("NO MORE COMMANDS in buffer!!!\n");
|
||||
if( ( (grblCommandBufferIndex_ >= grblCommandBuffer_.size()) || !executeCmd_) && grblInitDone_) {
|
||||
writerBusy_ = 0;
|
||||
return true; // code executed once
|
||||
@@ -411,18 +413,17 @@ bool ecmcGrbl::WriteGCodeSuccess() {
|
||||
}
|
||||
|
||||
void ecmcGrbl::grblWriteCommand(std::string command) {
|
||||
|
||||
// wait for grbl
|
||||
while(serial_get_rx_buffer_available() <= strlen(command.c_str())+1) {
|
||||
delay_ms(1);
|
||||
while(serial_get_rx_buffer_available() <= strlen(command.c_str()+1)) {
|
||||
printf("WAITING for freee in buffer %d %d\n",serial_get_rx_buffer_available(),strlen(command.c_str()+1));
|
||||
delay_ms(1000);
|
||||
}
|
||||
ecmc_write_command_serial(strdup(command.c_str()));
|
||||
if(cfgDbgMode_){
|
||||
printf("GRBL: INFO: Write command (command[%d] = %s)\n",
|
||||
grblCommandBufferIndex_,
|
||||
command.c_str());
|
||||
}
|
||||
|
||||
ecmc_write_command_serial(strdup(command.c_str()));
|
||||
}
|
||||
|
||||
grblReplyType ecmcGrbl::grblReadReply() {
|
||||
@@ -438,7 +439,7 @@ void ecmcGrbl::grblWriteCommand(std::string command) {
|
||||
if(c == '\n'&& reply.length() > 1) {
|
||||
if(reply.find(ECMC_PLUGIN_GRBL_GRBL_OK_STRING) != std::string::npos) {
|
||||
if(cfgDbgMode_){
|
||||
printf("GRBL: INFO: Reply OK\n");
|
||||
printf("GRBL: INFO: Reply OK (%s)\n",reply.c_str());
|
||||
}
|
||||
return ECMC_GRBL_REPLY_OK;
|
||||
} else if(reply.find(ECMC_PLUGIN_GRBL_GRBL_ERR_STRING) != std::string::npos) {
|
||||
@@ -986,8 +987,11 @@ void ecmcGrbl::addConfig(std::string command) {
|
||||
__FILE__,__FUNCTION__,__LINE__,ECMC_PLUGIN_CONFIG_ERROR_CODE);
|
||||
return;
|
||||
}
|
||||
|
||||
commandStrip+='\n';
|
||||
|
||||
epicsMutexLock(grblConfigBufferMutex_);
|
||||
|
||||
grblConfigBuffer_.push_back(commandStrip.c_str());
|
||||
epicsMutexUnlock(grblConfigBufferMutex_);
|
||||
if(cfgDbgMode_){
|
||||
|
||||
@@ -69,6 +69,10 @@ void gc_sync_position()
|
||||
uint8_t gc_execute_line(char *line)
|
||||
{
|
||||
PRINTF_DEBUG("");
|
||||
printf("gc_execute_line: %s\n",line);
|
||||
if(strlen(line)<2) {
|
||||
return(STATUS_OK);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------------------
|
||||
STEP 1: Initialize parser block struct and copy current g-code state modes. The parser
|
||||
|
||||
@@ -80,7 +80,7 @@ void protocol_main_loop()
|
||||
delay_us(100); // added for ecmc
|
||||
while((c = serial_read()) != SERIAL_NO_DATA) {
|
||||
if ((c == '\n') || (c == '\r')) { // End of line reached
|
||||
|
||||
|
||||
protocol_execute_realtime(); // Runtime command check point.
|
||||
if (sys.abort) { return; } // Bail to calling function upon system abort
|
||||
|
||||
@@ -93,7 +93,7 @@ void protocol_main_loop()
|
||||
if (line_flags & LINE_FLAG_OVERFLOW) {
|
||||
// Report line overflow error.
|
||||
report_status_message(STATUS_OVERFLOW);
|
||||
} else if (line[0] == 0) {
|
||||
} else if (line[0] == 0 || line[0]== '0') {
|
||||
// Empty or comment line. For syncing purposes.
|
||||
report_status_message(STATUS_OK);
|
||||
} else if (line[0] == '$') {
|
||||
@@ -104,7 +104,11 @@ void protocol_main_loop()
|
||||
report_status_message(STATUS_SYSTEM_GC_LOCK);
|
||||
} else {
|
||||
// Parse and execute g-code block.
|
||||
report_status_message(gc_execute_line(line));
|
||||
printf("protocol: Line to gc_execute %s\n",line);
|
||||
if(strlen(line)>1) {
|
||||
|
||||
report_status_message(gc_execute_line(line));
|
||||
}
|
||||
}
|
||||
|
||||
// Reset tracking data for next line.
|
||||
|
||||
@@ -106,6 +106,7 @@ uint16_t serial_get_tx_buffer_count()
|
||||
void serial_init()
|
||||
{
|
||||
printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
memset(&serial_rx_buffer[0],0,RX_RING_BUFFER);
|
||||
// Create some mutexes to ensure safe communication
|
||||
if(!(serialRxBufferMutex = epicsMutexCreate())) {
|
||||
printf("%s:%s:%d: Failed create serialRxBufferMutex\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
@@ -203,15 +204,17 @@ uint8_t serial_read()
|
||||
uint16_t tail = serial_rx_buffer_tail; // Temporary serial_rx_buffer_tail (to optimize for volatile)
|
||||
if (serial_rx_buffer_head == tail) {
|
||||
MUTEX_UNLOCK(serialRxBufferMutex);
|
||||
//printf("tail %u, head %u, available %u\n",serial_rx_buffer_tail,serial_rx_buffer_head,serial_get_rx_buffer_available());
|
||||
return SERIAL_NO_DATA;
|
||||
} else {
|
||||
uint8_t data = serial_rx_buffer[tail];
|
||||
serial_rx_buffer[tail]=0;
|
||||
|
||||
tail++;
|
||||
if (tail == RX_RING_BUFFER) {
|
||||
tail = 0;
|
||||
}
|
||||
|
||||
//printf("tail %u, head %u, available %u\n",serial_rx_buffer_tail,serial_rx_buffer_head,serial_get_rx_buffer_available());
|
||||
serial_rx_buffer_tail = tail;
|
||||
MUTEX_UNLOCK(serialRxBufferMutex);
|
||||
return data;
|
||||
@@ -270,10 +273,10 @@ void ecmc_add_char_to_buffer(char data)
|
||||
if (next_head == RX_RING_BUFFER) { next_head = 0; }
|
||||
|
||||
// Write data to buffer unless it is full.
|
||||
if (next_head != serial_rx_buffer_tail) {
|
||||
//if (next_head != serial_rx_buffer_tail) {
|
||||
serial_rx_buffer[serial_rx_buffer_head] = data;
|
||||
serial_rx_buffer_head = next_head;
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -285,11 +288,24 @@ void ecmc_write_command_serial(char* line) {
|
||||
for(i=0; i<strlen(line);i++) {
|
||||
ecmc_add_char_to_buffer(line[i]);
|
||||
}
|
||||
ecmc_add_char_to_buffer('\n');
|
||||
MUTEX_UNLOCK(serialRxBufferMutex);
|
||||
if(enableDebugPrintouts) {
|
||||
printf("Added: %s",line);
|
||||
|
||||
//ecmc_add_char_to_buffer('\n');
|
||||
|
||||
printf("Serial Buffer tail %u head %u, avail %u\n",serial_rx_buffer_tail,serial_rx_buffer_head,serial_get_rx_buffer_available());
|
||||
for(i = 0;i<RX_RING_BUFFER;i++) {
|
||||
if(serial_rx_buffer[i]==0) {
|
||||
printf("x");
|
||||
} else if ( serial_rx_buffer[i]=='\n' || serial_rx_buffer[i]=='\r' ) {
|
||||
printf("r");
|
||||
} else {
|
||||
printf("%c",serial_rx_buffer[i]);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
MUTEX_UNLOCK(serialRxBufferMutex);
|
||||
//if(enableDebugPrintouts) {
|
||||
printf("Added: %s\n", line);
|
||||
//}
|
||||
free(line);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#ifndef serial_h
|
||||
#define serial_h
|
||||
|
||||
#define RX_BUFFER_SIZE 100
|
||||
|
||||
#ifndef RX_BUFFER_SIZE
|
||||
#define RX_BUFFER_SIZE 128
|
||||
@@ -34,10 +35,6 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//#define RX_BUFFER_SIZE 1024
|
||||
//#define TX_BUFFER_SIZE 1024
|
||||
|
||||
#define SERIAL_NO_DATA 0xff
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user