本文整理汇总了C++中Gcode::prepare_cached_values方法的典型用法代码示例。如果您正苦于以下问题:C++ Gcode::prepare_cached_values方法的具体用法?C++ Gcode::prepare_cached_values怎么用?C++ Gcode::prepare_cached_values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gcode
的用法示例。
在下文中一共展示了Gcode::prepare_cached_values方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_console_line_received
// When a command is received, if it is a Gcode, dispatch it as an object via an event
void GcodeDispatch::on_console_line_received(void * line){
SerialMessage new_message = *static_cast<SerialMessage*>(line);
string possible_command = new_message.message;
char first_char = possible_command[0];
int ln = 0;
int cs = 0;
if( first_char == 'G' || first_char == 'M' || first_char == 'T' || first_char == 'N' ){
//Get linenumber
if( first_char == 'N' ){
Gcode full_line = Gcode(possible_command, new_message.stream);
ln = (int) full_line.get_value('N');
int chksum = (int) full_line.get_value('*');
//Catch message if it is M110: Set Current Line Number
if( full_line.has_letter('M') ){
if( ((int) full_line.get_value('M')) == 110 ){
currentline = ln;
new_message.stream->printf("ok\r\n");
return;
}
}
//Strip checksum value from possible_command
size_t chkpos = possible_command.find_first_of("*");
possible_command = possible_command.substr(0, chkpos);
//Calculate checksum
if( chkpos != string::npos ){
for(auto c = possible_command.cbegin(); *c != '*' && c != possible_command.cend(); c++)
cs = cs ^ *c;
cs &= 0xff; // Defensive programming...
cs -= chksum;
}
//Strip line number value from possible_command
size_t lnsize = possible_command.find_first_not_of("N0123456789.,- ");
possible_command = possible_command.substr(lnsize);
}else{
//Assume checks succeeded
cs = 0x00;
ln = currentline + 1;
}
//Remove comments
size_t comment = possible_command.find_first_of(";(");
if( comment != string::npos ){ possible_command = possible_command.substr(0, comment); }
//If checksum passes then process message, else request resend
int nextline = currentline + 1;
if( cs == 0x00 && ln == nextline ){
if( first_char == 'N' ) {
currentline = nextline;
}
while(possible_command.size() > 0) {
size_t nextcmd = possible_command.find_first_of("GMT", possible_command.find_first_of("GMT")+1);
string single_command;
if(nextcmd == string::npos) {
single_command = possible_command;
possible_command = "";
}
else {
single_command = possible_command.substr(0,nextcmd);
possible_command = possible_command.substr(nextcmd);
}
//Prepare gcode for dispatch
Gcode* gcode = new Gcode(single_command, new_message.stream);
gcode->prepare_cached_values();
// printf("dispatch %p: '%s' G%d M%d...", gcode, gcode->command.c_str(), gcode->g, gcode->m);
//Dispatch message!
this->kernel->call_event(ON_GCODE_RECEIVED, gcode );
if (gcode->add_nl)
new_message.stream->printf("\r\n");
if ( return_error_on_unhandled_gcode == true && gcode->accepted_by_module == false)
new_message.stream->printf("ok (command unclaimed)\r\n");
else if(!gcode->txt_after_ok.empty()) {
new_message.stream->printf("ok %s\r\n", gcode->txt_after_ok.c_str());
gcode->txt_after_ok.clear();
}else
new_message.stream->printf("ok\r\n");
delete gcode;
}
}else{
//Request resend
new_message.stream->printf("rs N%d\r\n", nextline);
}
// Ignore comments and blank lines
}else if( first_char == ';' || first_char == '(' || first_char == ' ' || first_char == '\n' || first_char == '\r' ){
new_message.stream->printf("ok\r\n");
}
}