From 002221ccf1a6752d68d8c8f2897de6e42b6d6ade Mon Sep 17 00:00:00 2001 From: Anders Sandstrom Date: Thu, 20 Jan 2022 16:32:18 +0100 Subject: [PATCH] WIP --- ecmc_plugin_grbl/.vscode/settings.json | 7 + ecmc_plugin_grbl/ecmcGrbl.cpp | 104 ++++-- ecmc_plugin_grbl/ecmcGrbl.dbd | 1 + ecmc_plugin_grbl/ecmcGrbl.h | 7 + ecmc_plugin_grbl/ecmcGrblWrap.cpp | 470 ++++--------------------- grbl/grbl_eeprom.c | 88 ++--- grbl/grbl_gcode.c | 1 - grbl/grbl_protocol.c | 3 +- grbl/grbl_serial.c | 1 + grbl/grbl_stepper.c | 1 + iocsh/test.script | 18 + 11 files changed, 223 insertions(+), 478 deletions(-) create mode 100644 ecmc_plugin_grbl/.vscode/settings.json create mode 100644 ecmc_plugin_grbl/ecmcGrbl.dbd diff --git a/ecmc_plugin_grbl/.vscode/settings.json b/ecmc_plugin_grbl/.vscode/settings.json new file mode 100644 index 0000000..bf1b0b1 --- /dev/null +++ b/ecmc_plugin_grbl/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "files.associations": { + "queue": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/ecmc_plugin_grbl/ecmcGrbl.cpp b/ecmc_plugin_grbl/ecmcGrbl.cpp index 3659c2b..82e9704 100644 --- a/ecmc_plugin_grbl/ecmcGrbl.cpp +++ b/ecmc_plugin_grbl/ecmcGrbl.cpp @@ -20,6 +20,7 @@ #include "ecmcAsynPortDriver.h" #include "ecmcAsynPortDriverUtils.h" #include "epicsThread.h" + extern "C" { #include "grbl.h" } @@ -47,6 +48,17 @@ void f_worker_read(void *obj) { grblObj->doReadWorker(); } +// Thread that writes commands to grbl +void f_worker_write(void *obj) { + if(!obj) { + printf("%s/%s:%d: Error: Worker read thread ecmcGrbl object NULL..\n", + __FILE__, __FUNCTION__, __LINE__); + return; + } + ecmcGrbl * grblObj = (ecmcGrbl*)obj; + grblObj->doWriteWorker(); +} + // Start worker for socket connect() void f_worker_main(void *obj) { if(!obj) { @@ -92,7 +104,12 @@ ecmcGrbl::ecmcGrbl(char* configStr, cfgZAxisId_ = -1; cfgSpindleAxisId_ = -1; grblInitDone_ = 0; + + if(!(grblCommandBufferMutex_ = epicsMutexCreate())) { + throw std::runtime_error("Error: Failed create mutex thread for write()."); + } + parseConfigStr(configStr); // Assigns all configs //Check atleast one valid axis @@ -101,17 +118,23 @@ ecmcGrbl::ecmcGrbl(char* configStr, } // Create worker thread for reading socket - std::string threadname = "ecmc." ECMC_PLUGIN_ASYN_PREFIX ".read"; + std::string threadname = "ecmc.grbl.read"; if(epicsThreadCreate(threadname.c_str(), 0, 32768, f_worker_read, this) == NULL) { throw std::runtime_error("Error: Failed create worker thread for read()."); } - // Create worker thread for connecting socket - threadname = "ecmc." ECMC_PLUGIN_ASYN_PREFIX ".main"; + // Create worker thread for main grbl loop + threadname = "ecmc.grbl.main"; if(epicsThreadCreate(threadname.c_str(), 0, 32768, f_worker_main, this) == NULL) { throw std::runtime_error("Error: Failed create worker thread for main()."); } + // Create worker thread for write socket + threadname = "ecmc.grbl.write"; + if(epicsThreadCreate(threadname.c_str(), 0, 32768, f_worker_write, this) == NULL) { + throw std::runtime_error("Error: Failed create worker thread for write()."); + } + // wait for grblInitDone_! printf("Waiting for grbl init.."); while(!grblInitDone_) { @@ -119,9 +142,6 @@ ecmcGrbl::ecmcGrbl(char* configStr, printf("."); } delay_ms(100); - printf("\n"); - printf("\n grbl ready for commands!\n"); - sleep(1); testGrbl(); } @@ -193,6 +213,32 @@ void ecmcGrbl::doReadWorker() { } } +// Write socket worker +void ecmcGrbl::doWriteWorker() { + // simulate serial connection here (need mutex) + printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__); + for(;;) { + if(grblCommandBuffer_.size()>0) { + printf("%s:%s:%d: Command in buffer!!!\n",__FILE__,__FUNCTION__,__LINE__); + epicsMutexLock(grblCommandBufferMutex_); + std::string command = grblCommandBuffer_.front() + '\n'; + grblCommandBuffer_.pop(); + epicsMutexUnlock(grblCommandBufferMutex_); + printf("%s:%s:%d: Command length %d!!!\n",__FILE__,__FUNCTION__,__LINE__,strlen(command.c_str())); + printf("%s:%s:%d: Used bytes %d!!!\n",__FILE__,__FUNCTION__,__LINE__,serial_get_rx_buffer_available()); + // wait for grbl + while(RX_BUFFER_SIZE-serial_get_rx_buffer_available()<=strlen(command.c_str())) { + delay_ms(1); + } + printf("%s:%s:%d: Writing!!\n",__FILE__,__FUNCTION__,__LINE__); + ecmc_write_command_serial(strdup(command.c_str())); + } + else { + delay_ms(5); + } + } +} + // Main grbl worker (copied from grbl main.c) void ecmcGrbl::doMainWorker() { printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__); @@ -282,27 +328,35 @@ std::string ecmcGrbl::to_string(int value) { return os.str(); } +void ecmcGrbl::addCommand(std::string command) { + printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__); + epicsMutexLock(grblCommandBufferMutex_); + grblCommandBuffer_.push(command.c_str()); + epicsMutexUnlock(grblCommandBufferMutex_); + printf("%s:%s:%d: Buffer size %d\n",__FILE__,__FUNCTION__,__LINE__,grblCommandBuffer_.size()); +} + void ecmcGrbl::testGrbl() { // test some commands - printf("Test command:$\n"); - ecmc_write_command_serial("$\n"); - sleep(1); - printf("Test command:G0X10Y100\n"); - ecmc_write_command_serial("G0X10Y100\n"); - sleep(1); - printf("Test command:$G\n"); - ecmc_write_command_serial("$G\n"); - sleep(1); - printf("Test command:G4P4\n"); - ecmc_write_command_serial("G4P4\n"); - printf("Test command:G1X20Y200F20\n"); - ecmc_write_command_serial("G1X20Y200F20\n"); - printf("Test command:G4P4\n"); - ecmc_write_command_serial("G4P4\n"); - printf("Test command:G2X40Y220R20\n"); - ecmc_write_command_serial("G2X40Y220R20\n"); - printf("Test command:$\n"); - ecmc_write_command_serial("$\n"); + //printf("Test command:$\n"); + //ecmc_write_command_serial("$\n"); + //sleep(1); + //printf("Test command:G0X10Y100\n"); + //ecmc_write_command_serial("G0X10Y100\n"); + //sleep(1); + //printf("Test command:$G\n"); + //ecmc_write_command_serial("$G\n"); + //sleep(1); + //printf("Test command:G4P4\n"); + //ecmc_write_command_serial("G4P4\n"); + //printf("Test command:G1X20Y200F20\n"); + //ecmc_write_command_serial("G1X20Y200F20\n"); + //printf("Test command:G4P4\n"); + //ecmc_write_command_serial("G4P4\n"); + //printf("Test command:G2X40Y220R20\n"); + //ecmc_write_command_serial("G2X40Y220R20\n"); + //printf("Test command:$\n"); + //ecmc_write_command_serial("$\n"); } \ No newline at end of file diff --git a/ecmc_plugin_grbl/ecmcGrbl.dbd b/ecmc_plugin_grbl/ecmcGrbl.dbd new file mode 100644 index 0000000..0ed4698 --- /dev/null +++ b/ecmc_plugin_grbl/ecmcGrbl.dbd @@ -0,0 +1 @@ +registrar("ecmcGrblPluginDriverRegister") diff --git a/ecmc_plugin_grbl/ecmcGrbl.h b/ecmc_plugin_grbl/ecmcGrbl.h index 87c77b6..356ad5c 100644 --- a/ecmc_plugin_grbl/ecmcGrbl.h +++ b/ecmc_plugin_grbl/ecmcGrbl.h @@ -17,10 +17,12 @@ #include "ecmcGrblDefs.h" #include "inttypes.h" +#include #include #include #include #include +#include #include class ecmcGrbl : public asynPortDriver { @@ -40,8 +42,11 @@ class ecmcGrbl : public asynPortDriver { void doReadWorker(); void doMainWorker(); + void doWriteWorker(); void grblRTexecute(); + void addCommand(std::string command); + private: void testGrbl(); @@ -57,6 +62,8 @@ class ecmcGrbl : public asynPortDriver { int errorCode_; double exeSampleTimeMs_; int grblInitDone_; + std::queue grblCommandBuffer_; + epicsMutexId grblCommandBufferMutex_; }; #endif /* ECMC_GRBL_H_ */ diff --git a/ecmc_plugin_grbl/ecmcGrblWrap.cpp b/ecmc_plugin_grbl/ecmcGrblWrap.cpp index 90e9d02..e85bfed 100644 --- a/ecmc_plugin_grbl/ecmcGrblWrap.cpp +++ b/ecmc_plugin_grbl/ecmcGrblWrap.cpp @@ -19,6 +19,17 @@ #include "ecmcGrbl.h" #include "ecmcGrblDefs.h" #include "ecmcGrblWrap.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#include + #define ECMC_PLUGIN_MAX_PORTNAME_CHARS 64 #define ECMC_PLUGIN_PORTNAME_PREFIX "PLUGIN.GRBL" @@ -62,415 +73,60 @@ void deleteGrbl() { /** - * EPICS iocsh shell command: ecmcCANOpenAddMaster + * EPICS iocsh shell command: ecmcGrblAddCommand */ -//void ecmcCANOpenAddMasterPrintHelp() { -// printf("\n"); -// printf(" Use ecmcCANOpenAddMaster(, ,....)\n"); -// printf(" : Name of master device.\n"); -// printf(" : CANOpen node id of master.\n"); -// printf(" : Sample time for LSS.\n"); -// printf(" : Sample time for SYNC.\n"); -// printf(" : Sample time for NMT Heartbeat.\n"); -// printf("\n"); -//} -// -//int ecmcCANOpenAddMaster(const char* name, -// int nodeId, -// int lssSampleTimeMs, -// int syncSampleTimeMs, -// int heartSampleTimeMs) { -// -// if(!name) { -// printf("Error: name.\n"); -// ecmcCANOpenAddMasterPrintHelp(); -// return asynError; -// } -// -// if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) { -// ecmcCANOpenAddMasterPrintHelp(); -// return asynSuccess; -// } -// -// if(!grbl) { -// printf("Plugin not initialized/loaded.\n"); -// return asynError; -// } -// -// try { -// grbl->addMaster((uint32_t)nodeId, -// name, -// lssSampleTimeMs, -// syncSampleTimeMs, -// heartSampleTimeMs); -// } -// catch(std::exception& e) { -// printf("Exception: %s. Add master failed.\n",e.what()); -// return asynError; -// } -// -// return asynSuccess; -//} -// -//static const iocshArg initArg0_0 = -//{ "Name", iocshArgString }; -//static const iocshArg initArg1_0 = -//{ "Node Id", iocshArgInt }; -//static const iocshArg initArg2_0 = -//{ "LSS sample time ms", iocshArgInt }; -//static const iocshArg initArg3_0 = -//{ "Sync sample time ms", iocshArgInt }; -//static const iocshArg initArg4_0 = -//{ "NMT Heart sample time ms", iocshArgInt }; -// -//static const iocshArg *const initArgs_0[] = { &initArg0_0, -// &initArg1_0, -// &initArg2_0, -// &initArg3_0, -// &initArg4_0}; -// -//static const iocshFuncDef initFuncDef_0 = { "ecmcCANOpenAddMaster", 5, initArgs_0 }; -//static void initCallFunc_0(const iocshArgBuf *args) { -// ecmcCANOpenAddMaster(args[0].sval, -// args[1].ival, -// args[2].ival, -// args[3].ival, -// args[4].ival); -//} -// -///** -// * EPICS iocsh shell command: ecmcCANOpenAddDevice -//*/ -// -//void ecmcCANOpenAddDevicePrintHelp() { -// printf("\n"); -// printf(" Use ecmcCANOpenAddDevice(, )\n"); -// printf(" : Name of device.\n"); -// printf(" : CANOpen node id of device.\n"); -// printf(" : Timeout for NMT Heartbeat.\n"); -// printf("\n"); -//} -// -//int ecmcCANOpenAddDevice(const char* name, int nodeId,int heartTimeOutMs) { -// if(!name) { -// printf("Error: name.\n"); -// ecmcCANOpenAddDevicePrintHelp(); -// return asynError; -// } -// -// if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) { -// ecmcCANOpenAddDevicePrintHelp(); -// return asynSuccess; -// } -// -// if(!grbl) { -// printf("Plugin not initialized/loaded.\n"); -// return asynError; -// } -// -// if(heartTimeOutMs < 0) { -// printf("Invalid NMT heartbeat timeout.\n"); -// return asynError; -// } -// -// try { -// grbl->addDevice((uint32_t)nodeId,name,heartTimeOutMs); -// } -// catch(std::exception& e) { -// printf("Exception: %s. Add device failed.\n",e.what()); -// return asynError; -// } -// -// return asynSuccess; -//} -// -//static const iocshArg initArg0_1 = -//{ "Name", iocshArgString }; -//static const iocshArg initArg1_1 = -//{ "Node Id", iocshArgInt }; -//static const iocshArg initArg2_1 = -//{ "NMT Heart timeout ms", iocshArgInt }; -// -//static const iocshArg *const initArgs_1[] = { &initArg0_1, -// &initArg1_1, -// &initArg2_1}; -// -//static const iocshFuncDef initFuncDef_1 = { "ecmcCANOpenAddDevice", 3, initArgs_1 }; -//static void initCallFunc_1(const iocshArgBuf *args) { -// ecmcCANOpenAddDevice(args[0].sval, args[1].ival, args[2].ival); -//} -// -///** -// * EPICS iocsh shell command: ecmcCANOpenAddSDO -//*/ -// -//void ecmcCANOpenAddSDOPrintHelp() { -// printf("\n"); -// printf(" Use ecmcCANOpenAddSDO(, ,.....)\n"); -// printf(" : Name of master device.\n"); -// printf(" : CANOpen node id of device/master.\n"); -// printf(" : CANOpen cob id of Tx of slave SDO.\n"); -// printf(" : CANOpen cob id of Rx of slave SDO.\n"); -// printf(" : Direction 1=write and 2=read.\n"); -// printf(" : OD index of SDO.\n"); -// printf(" : OD sub index of SDO.\n"); -// printf(" : OS Size.\n"); -// printf(" : Sample time for read in ms (write is always on demand).\n"); -// printf("\n"); -//} -// -//int ecmcCANOpenAddSDO(const char* name, -// int nodeId, -// int cobIdTx, -// int cobIdRx, -// int dir, -// int ODIndex, -// int ODSubIndex, -// int ODSize, -// int readSampleTimeMs) { -// if(!name) { -// printf("Error: name.\n"); -// ecmcCANOpenAddSDOPrintHelp(); -// return asynError; -// } -// -// if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) { -// ecmcCANOpenAddSDOPrintHelp(); -// return asynSuccess; -// } -// -// if(cobIdRx < 0) { -// printf("Error: invalid cobIdRx.\n"); -// ecmcCANOpenAddSDOPrintHelp(); -// return asynError; -// } -// -// if(cobIdTx < 0) { -// printf("Error: invalid cobIdTx.\n"); -// ecmcCANOpenAddSDOPrintHelp(); -// return asynError; -// } -// -// if(dir > 2 || dir <= 0) { -// printf("Error: invalid dir.\n"); -// ecmcCANOpenAddSDOPrintHelp(); -// return asynError; -// } -// -// if(ODIndex < 0) { -// printf("Error: invalid ODIndex.\n"); -// ecmcCANOpenAddSDOPrintHelp(); -// return asynError; -// } -// -// if(ODSubIndex < 0) { -// printf("Error: invalid ODSubIndex.\n"); -// ecmcCANOpenAddSDOPrintHelp(); -// return asynError; -// } -// -// if(ODSize < 0) { -// printf("Error: invalid ODSize.\n"); -// ecmcCANOpenAddSDOPrintHelp(); -// return asynError; -// } -// -// if(readSampleTimeMs < 0) { -// printf("Error: invalid readSampleTimeMs.\n"); -// ecmcCANOpenAddSDOPrintHelp(); -// return asynError; -// } -// -// ecmc_can_direction tempDir = DIR_READ; -// if(dir == 1) { -// tempDir = DIR_WRITE; -// } -// -// try { -// grbl->addSDO((uint32_t)nodeId, -// cobIdTx, -// cobIdRx, -// tempDir, -// ODIndex, -// ODSubIndex, -// ODSize, -// readSampleTimeMs, -// name); -// -// -// } -// catch(std::exception& e) { -// printf("Exception: %s. Add PDO failed.\n",e.what()); -// return asynError; -// } -// return asynSuccess; -//} -// -//static const iocshArg initArg0_2 = -//{ "Name", iocshArgString }; -//static const iocshArg initArg1_2 = -//{ "Node Id", iocshArgInt }; -//static const iocshArg initArg2_2 = -//{ "COB id TX", iocshArgInt }; -//static const iocshArg initArg3_2 = -//{ "COB id RX", iocshArgInt }; -//static const iocshArg initArg4_2 = -//{ "Direction", iocshArgInt }; -//static const iocshArg initArg5_2 = -//{ "OD Index", iocshArgInt }; -//static const iocshArg initArg6_2 = -//{ "OD sub index", iocshArgInt }; -//static const iocshArg initArg7_2 = -//{ "OD size", iocshArgInt }; -//static const iocshArg initArg8_2 = -//{ "Read sample time ms", iocshArgInt }; -// -//static const iocshArg *const initArgs_2[] = { &initArg0_2, -// &initArg1_2, -// &initArg2_2, -// &initArg3_2, -// &initArg4_2, -// &initArg5_2, -// &initArg6_2, -// &initArg7_2, -// &initArg8_2}; -// -//static const iocshFuncDef initFuncDef_2 = { "ecmcCANOpenAddSDO", 9, initArgs_2 }; -//static void initCallFunc_2(const iocshArgBuf *args) { -// ecmcCANOpenAddSDO(args[0].sval, -// args[1].ival, -// args[2].ival, -// args[3].ival, -// args[4].ival, -// args[5].ival, -// args[6].ival, -// args[7].ival, -// args[8].ival); -//} -// -///** -// * EPICS iocsh shell command: ecmcCANOpenAddPDO -//*/ -//void ecmcCANOpenAddPDOPrintHelp() { -// printf("\n"); -// printf(" Use \"ecmcCANOpenAddPDO(, \n"); -// printf(" : Name of master device.\n"); -// printf(" : CANOpen node id of device/master.\n"); -// printf(" : CANOpen cob id of PDO.\n"); -// printf(" : Direction 1=write and 2=read.\n"); -// printf(" : Size of PDO (max 8 bytes).\n"); -// printf(" : Readtimeout in ms.\n"); -// printf(" : Cycle time for write (if <= 0 then only write on change).\n"); -// printf("\n"); -//} -// -//int ecmcCANOpenAddPDO(const char* name, -// int nodeId, -// int cobId, -// int dir, -// int ODSize, -// int readTimeoutMs, -// int writeCycleMs) { -// if(!name) { -// printf("Error: name.\n"); -// ecmcCANOpenAddPDOPrintHelp(); -// return asynError; -// } -// -// if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) { -// ecmcCANOpenAddPDOPrintHelp(); -// return asynSuccess; -// } -// -// if(dir > 2 || dir <= 0) { -// printf("Error: invalid dir.\n"); -// ecmcCANOpenAddPDOPrintHelp(); -// return asynError; -// } -// -// if(ODSize < 0) { -// printf("Error: invalid ODSize.\n"); -// ecmcCANOpenAddPDOPrintHelp(); -// return asynError; -// } -// -// if(readTimeoutMs < 0) { -// printf("Error: invalid readTimeoutMs.\n"); -// ecmcCANOpenAddPDOPrintHelp(); -// return asynError; -// } -// -// if(writeCycleMs < 0) { -// printf("Error: invalid writeCycleMs.\n"); -// ecmcCANOpenAddPDOPrintHelp(); -// return asynError; -// } -// -// ecmc_can_direction tempDir = DIR_READ; -// if(dir == 1) { -// tempDir = DIR_WRITE; -// } -// -// try { -// grbl->addPDO((uint32_t)nodeId, -// cobId, -// tempDir, -// ODSize, -// readTimeoutMs, -// writeCycleMs,name); -// } -// catch(std::exception& e) { -// printf("Exception: %s. Add PDO failed.\n",e.what()); -// return asynError; -// } -// return asynSuccess; -//} -// -//static const iocshArg initArg0_3 = -//{ "Name", iocshArgString }; -//static const iocshArg initArg1_3 = -//{ "Node Id", iocshArgInt }; -//static const iocshArg initArg2_3 = -//{ "COB Id", iocshArgInt }; -//static const iocshArg initArg3_3 = -//{ "Direction", iocshArgInt }; -//static const iocshArg initArg4_3 = -//{ "ODSize", iocshArgInt }; -//static const iocshArg initArg5_3 = -//{ "Read Timeout ms", iocshArgInt }; -//static const iocshArg initArg6_3 = -//{ "Write cycle ms", iocshArgInt }; -// -//static const iocshArg *const initArgs_3[] = { &initArg0_3, -// &initArg1_3, -// &initArg2_3, -// &initArg3_3, -// &initArg4_3, -// &initArg5_3, -// &initArg6_3 -// }; -// -//static const iocshFuncDef initFuncDef_3 = { "ecmcCANOpenAddPDO", 7, initArgs_3 }; -//static void initCallFunc_3(const iocshArgBuf *args) { -// ecmcCANOpenAddPDO(args[0].sval, -// args[1].ival, -// args[2].ival, -// args[3].ival, -// args[4].ival, -// args[5].ival, -// args[6].ival); -//} -// +void ecmcGrblAddCommandPrintHelp() { + printf("\n"); + printf(" Use ecmcGrblAddCommand()\n"); + printf(" : Grbl command.\n"); + printf("\n"); +} + +int ecmcGrblAddCommand(const char* command) { + + if(!command) { + printf("Error: command.\n"); + ecmcGrblAddCommandPrintHelp(); + return asynError; + } + + if(strcmp(command,"-h") == 0 || strcmp(command,"--help") == 0 ) { + ecmcGrblAddCommandPrintHelp(); + return asynSuccess; + } + + if(!grbl) { + printf("Plugin not initialized/loaded.\n"); + return asynError; + } + + try { + grbl->addCommand(command); + } + catch(std::exception& e) { + printf("Exception: %s. Add command failed.\n",e.what()); + return asynError; + } + + return asynSuccess; +} + +static const iocshArg initArg0_0 = +{ " Grbl Command", iocshArgString }; + +static const iocshArg *const initArgs_0[] = { &initArg0_0}; + +static const iocshFuncDef initFuncDef_0 = { "ecmcGrblAddCommand", 1, initArgs_0 }; +static void initCallFunc_0(const iocshArgBuf *args) { + ecmcGrblAddCommand(args[0].sval); +} + ///** // * Register all functions //*/ -//void ecmcCANPluginDriverRegister(void) { -// iocshRegister(&initFuncDef_0, initCallFunc_0); // ecmcCANOpenAddMaster -// iocshRegister(&initFuncDef_1, initCallFunc_1); // ecmcCANOpenAddDevice -// iocshRegister(&initFuncDef_2, initCallFunc_2); // ecmcCANOpenAddSDO -// iocshRegister(&initFuncDef_3, initCallFunc_3); // ecmcCANOpenAddPDO -//} -// -//epicsExportRegistrar(ecmcCANPluginDriverRegister); -// \ No newline at end of file +void ecmcGrblPluginDriverRegister(void) { + iocshRegister(&initFuncDef_0, initCallFunc_0); // ecmcCANOpenAddMaster +} + +epicsExportRegistrar(ecmcGrblPluginDriverRegister); diff --git a/grbl/grbl_eeprom.c b/grbl/grbl_eeprom.c index c254687..580077a 100644 --- a/grbl/grbl_eeprom.c +++ b/grbl/grbl_eeprom.c @@ -47,56 +47,56 @@ char buffer[EEPROM_MEM_SIZE]; /* Define to reduce code size. */ //#define EEPROM_IGNORE_SELFPROG //!< Remove SPM flag polling. -unsigned char ecmc_mem_to_file(); +//unsigned char ecmc_mem_to_file(); // Init file void ecmc_init_file() { printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__); memset(&buffer[0],0,EEPROM_MEM_SIZE); - ecmc_mem_to_file(); + //ecmc_mem_to_file(); } // Read file to buffer[] -unsigned char ecmc_file_to_mem() -{ - //printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); - - FILE* fh = fopen(EEPROM_DUMMY_FILE, "rd"); - - if (fh == NULL) - { - printf("something went wrong and file could not be opened"); - return 1; - } - unsigned char c = 0; - for (int i = 0; i < EEPROM_MEM_SIZE ; i++) { - // Get the characters - buffer[i] = fgetc(fh); - } - - fclose(fh); - return 0; -} +//unsigned char ecmc_file_to_mem() +//{ +// //printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); +// +// FILE* fh = fopen(EEPROM_DUMMY_FILE, "rd"); +// +// if (fh == NULL) +// { +// printf("something went wrong and file could not be opened"); +// return 1; +// } +// unsigned char c = 0; +// for (int i = 0; i < EEPROM_MEM_SIZE ; i++) { +// // Get the characters +// buffer[i] = fgetc(fh); +// } +// +// fclose(fh); +// return 0; +//} // Write buffer[] to file -unsigned char ecmc_mem_to_file() -{ -// printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); - - FILE* fh = fopen(EEPROM_DUMMY_FILE, "w"); - - if (fh == NULL) - { - printf("something went wrong and file could not be opened"); - return 1; - } - for (int i = 0; i < EEPROM_MEM_SIZE ; i++) { - // Get the characters - fputc (buffer[i], fh); - } - - fclose(fh); - return 0; -} +//unsigned char ecmc_mem_to_file() +//{ +//// printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__); +// +// FILE* fh = fopen(EEPROM_DUMMY_FILE, "w"); +// +// if (fh == NULL) +// { +// printf("something went wrong and file could not be opened"); +// return 1; +// } +// for (int i = 0; i < EEPROM_MEM_SIZE ; i++) { +// // Get the characters +// fputc (buffer[i], fh); +// } +// +// fclose(fh); +// return 0; +//} /*! \brief Read byte from EEPROM. @@ -110,7 +110,7 @@ unsigned char ecmc_mem_to_file() */ unsigned char eeprom_get_char( unsigned int addr ) { - ecmc_file_to_mem(); + //ecmc_file_to_mem(); //printf("%s:%s:%d addr: %ud, value %d..\n",__FILE__,__FUNCTION__,__LINE__,addr,buffer[addr]); return buffer[addr]; @@ -142,9 +142,9 @@ void eeprom_put_char( unsigned int addr, unsigned char new_value ) { //printf("%s:%s:%d addr: %ud, value %d..\n",__FILE__,__FUNCTION__,__LINE__,addr,new_value); - ecmc_file_to_mem(); + //ecmc_file_to_mem(); buffer[addr] = new_value; - ecmc_mem_to_file(); + //ecmc_mem_to_file(); //char old_value; // Old EEPROM value. //char diff_mask; // Difference mask, i.e. old value XOR new value. diff --git a/grbl/grbl_gcode.c b/grbl/grbl_gcode.c index 0a65c31..6b83f8f 100644 --- a/grbl/grbl_gcode.c +++ b/grbl/grbl_gcode.c @@ -57,7 +57,6 @@ void gc_init() void gc_sync_position() { printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__); - system_convert_array_steps_to_mpos(gc_state.position,sys_position); } diff --git a/grbl/grbl_protocol.c b/grbl/grbl_protocol.c index ef50852..5800aab 100644 --- a/grbl/grbl_protocol.c +++ b/grbl/grbl_protocol.c @@ -76,7 +76,8 @@ void protocol_main_loop() for (;;) { // Process one line of incoming serial data, as the data becomes available. Performs an // initial filtering by removing spaces and comments and capitalizing all letters. - while((c = serial_read()) != SERIAL_NO_DATA) { + delay_ms(1); + while((c = serial_read()) != SERIAL_NO_DATA) { if ((c == '\n') || (c == '\r')) { // End of line reached //printf("NEW_CHAR\n"); protocol_execute_realtime(); // Runtime command check point. diff --git a/grbl/grbl_serial.c b/grbl/grbl_serial.c index f093b38..b05eb3a 100644 --- a/grbl/grbl_serial.c +++ b/grbl/grbl_serial.c @@ -215,6 +215,7 @@ void ecmc_write_command_serial(char* line) { for(int i=0; i