static void statf(int indent, FTSENT *p) { u_int32_t len, val; int fd, offset; const char *name = NULL; #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2) char *digestbuf; #endif offset = printf("%*s%s%s", indent, "", S_ISDIR(p->fts_statp->st_mode) ? "" : " ", vispath(p->fts_name)); if (offset > (INDENTNAMELEN + indent)) offset = MAXLINELEN; else offset += printf("%*s", (INDENTNAMELEN + indent) - offset, ""); if (!S_ISREG(p->fts_statp->st_mode) && (flavor == F_NETBSD6 || !dflag)) output(indent, &offset, "type=%s", inotype(p->fts_statp->st_mode)); if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid) { if (keys & F_UNAME && (name = user_from_uid(p->fts_statp->st_uid, 1)) != NULL) output(indent, &offset, "uname=%s", name); if (keys & F_UID || (keys & F_UNAME && name == NULL)) output(indent, &offset, "uid=%u", p->fts_statp->st_uid); } if (keys & (F_GID | F_GNAME) && p->fts_statp->st_gid != gid) { if (keys & F_GNAME && (name = group_from_gid(p->fts_statp->st_gid, 1)) != NULL) output(indent, &offset, "gname=%s", name); if (keys & F_GID || (keys & F_GNAME && name == NULL)) output(indent, &offset, "gid=%u", p->fts_statp->st_gid); } if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode) output(indent, &offset, "mode=%#o", p->fts_statp->st_mode & MBITS); if (keys & F_DEV && (S_ISBLK(p->fts_statp->st_mode) || S_ISCHR(p->fts_statp->st_mode))) output(indent, &offset, "device=%#jx", (uintmax_t)p->fts_statp->st_rdev); if (keys & F_NLINK && p->fts_statp->st_nlink != 1) output(indent, &offset, "nlink=%u", p->fts_statp->st_nlink); if (keys & F_SIZE && (flavor == F_FREEBSD9 || S_ISREG(p->fts_statp->st_mode))) output(indent, &offset, "size=%ju", (uintmax_t)p->fts_statp->st_size); if (keys & F_TIME) #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H) output(indent, &offset, "time=%jd.%09ld", (intmax_t)p->fts_statp->st_mtimespec.tv_sec, p->fts_statp->st_mtimespec.tv_nsec); #else output(indent, &offset, "time=%jd.%09ld", (intmax_t)p->fts_statp->st_mtime, (long)0); #endif if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || crc(fd, &val, &len)) mtree_err("%s: %s", p->fts_accpath, strerror(errno)); close(fd); output(indent, &offset, "cksum=%lu", (long)val); } #ifndef NO_MD5 if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = MD5File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: MD5File failed: %s", p->fts_accpath, strerror(errno)); output(indent, &offset, "%s=%s", MD5KEY, digestbuf); free(digestbuf); } #endif /* ! NO_MD5 */ #ifndef NO_RMD160 if (keys & F_RMD160 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = RMD160File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: RMD160File failed: %s", p->fts_accpath, strerror(errno)); output(indent, &offset, "%s=%s", RMD160KEY, digestbuf); free(digestbuf); } #endif /* ! NO_RMD160 */ #ifndef NO_SHA1 if (keys & F_SHA1 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = SHA1File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: SHA1File failed: %s", p->fts_accpath, strerror(errno)); output(indent, &offset, "%s=%s", SHA1KEY, digestbuf); free(digestbuf); } #endif /* ! NO_SHA1 */ #ifndef NO_SHA2 if (keys & F_SHA256 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = SHA256_File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: SHA256_File failed: %s", p->fts_accpath, strerror(errno)); output(indent, &offset, "%s=%s", SHA256KEY, digestbuf); free(digestbuf); } #ifdef SHA384_BLOCK_LENGTH if (keys & F_SHA384 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = SHA384_File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: SHA384_File failed: %s", p->fts_accpath, strerror(errno)); output(indent, &offset, "%s=%s", SHA384KEY, digestbuf); free(digestbuf); } #endif if (keys & F_SHA512 && S_ISREG(p->fts_statp->st_mode)) { if ((digestbuf = SHA512_File(p->fts_accpath, NULL)) == NULL) mtree_err("%s: SHA512_File failed: %s", p->fts_accpath, strerror(errno)); output(indent, &offset, "%s=%s", SHA512KEY, digestbuf); free(digestbuf); } #endif /* ! NO_SHA2 */ if (keys & F_SLINK && (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) output(indent, &offset, "link=%s", vispath(rlink(p->fts_accpath))); #if HAVE_STRUCT_STAT_ST_FLAGS if (keys & F_FLAGS && p->fts_statp->st_flags != flags) { char *str = flags_to_string(p->fts_statp->st_flags, "none"); output(indent, &offset, "flags=%s", str); free(str); } #endif putchar('\n'); }
uint STDCALL ge_load( pbuf in ) { pubyte cur, end, ptemp; uint size; pgehead phead = ( pgehead )buf_ptr( in ); // Проверка заголовка и целостности // Сравниваем с 'GE' с двумя нулями на конце if ( *( puint )phead != GE_STRING )//0x00004547 ) msg( MNotGE | MSG_EXIT ); if ( phead->crc != crc( ( pubyte )phead + 12, phead->size - 12, 0xFFFFFFFF )) msg( MCrcGE | MSG_EXIT ); if ( phead->vermajor != GEVER_MAJOR || phead->verminor > GEVER_MINOR ) msg( MVerGE | MSG_EXIT ); _vm.loadmode = VMLOAD_GE; _vm.icnv = arr_count( &_vm.objtbl ) - KERNEL_COUNT; // print("icnv=%i\n", _vm.icnv ); cur = ( pubyte )phead + phead->headsize; end = ( pubyte )phead + phead->size; while ( cur < end ) { ptemp = cur + 5; // type + flag _vm.ipack = ( *( puint )( cur + 1 )) & GHCOM_PACK ? 1 : 0; size = load_bwd( &ptemp ); ptemp = cur; // print("size=%i type=%i flag = %x\n", size, *cur, *( puint )( cur + 1 ) ); switch ( *cur ) { case OVM_NONE: load_none(); break; case OVM_BYTECODE: load_bytecode( &cur, VMLOAD_GE ); break; case OVM_EXFUNC: load_exfunc( &cur, 0 ); _vm.loadmode = VMLOAD_GE; break; case OVM_TYPE: load_type( &cur ); break; case OVM_GLOBAL: load_global( &cur ); break; case OVM_DEFINE: load_define( &cur ); break; case OVM_IMPORT: load_import( &cur ); break; case OVM_RESOURCE: load_resource( &cur ); break; case OVM_ALIAS: load_alias( &cur ); break; default: msg( MUnkGE | MSG_DVAL, cur - ( pubyte )phead ); } cur = ptemp + size; } _vm.loadmode = VMLOAD_G; _vm.icnv = 0; return 1; }
void wizard2() { int sockfd; int client; struct sockaddr_un serveraddr; struct sockaddr_un clientaddr; struct protocol_web_status protocol_status; unsigned char frame[sizeof(protocol_status)*2]; char protocol_buffer[sizeof(struct protocol_web_control)*2]; int frame_size; int buffer_size; // int i, n; int n; unsigned short crc_data = 0; // unsigned int bits_band; client = sizeof(serveraddr); sockfd = socket(PF_UNIX, SOCK_DGRAM, 0); if(sockfd < 0) { message_dialog("socket error"); exit(0); } bzero(&serveraddr, sizeof(serveraddr)); serveraddr.sun_family = AF_UNIX; strcpy(serveraddr.sun_path, "/tmp/socket_app"); bzero(&clientaddr, sizeof(clientaddr)); clientaddr.sun_family = AF_UNIX; strcpy(clientaddr.sun_path, "/tmp/socket_web"); remove("/tmp/socket_web"); if(bind(sockfd, (struct sockaddr*)&clientaddr, sizeof(clientaddr))) { message_dialog("socket error"); exit(0); } memset(&protocol_status, 0, sizeof(protocol_status)); protocol_status.type = PROTOCOL_STATUS; protocol_buffer_to_frame((void*)&protocol_status,1,frame,&frame_size); sched_yield(); sendto(sockfd, frame, 3, 0,(struct sockaddr*)&serveraddr,client); alarm(30); n = recvfrom(sockfd, frame, sizeof(frame),0,NULL,NULL); alarm(0); protocol_frame_to_buffer(frame,n,(unsigned char*)protocol_buffer,&buffer_size); memmove(&protocol_status,protocol_buffer,buffer_size); // bits_band = (protocol_status.band_select[0]<<16) | (protocol_status.band_select[1]<<8) | (protocol_status.band_select[2]); crc_data = crc((void*)&protocol_status.type, (void*)&protocol_status.crc); if(crc_data != protocol_status.crc) { message_dialog("crc error"); } //=========================== html_page_head(0); // arg==requiredfrom true(1), false(0) printf("%s", "<!-- \n"); printf("%s", "function logout()\n"); printf("%s", "{\n"); printf("%s", " if (document.cookie != \"\") \n"); printf("%s", " {\n"); printf("%s", " thisCookie = document.cookie.split(\"; \")\n"); printf("%s", " expireDate = new Date\n"); printf("%s", " expireDate.setDate(expireDate.getDate()-1)\n"); printf("%s", " for (i=0; i<thisCookie.length; i++) \n"); printf("%s", " {\n"); printf("%s", " document.cookie = thisCookie + \";expires=\" + expireDate.toGMTString()\n"); printf("%s", " }\n"); printf("%s", " }\n"); printf("%s", " location.replace(\"html.cgi?function=logout\");\n"); printf("%s", "}\n"); printf("function CheckCheckObj(CheckObj)\n"); printf("{\n"); printf(" CheckObj.checked=\"true\";\n"); printf(" CheckObj.value=\"1\";\n"); printf("}\n"); printf("function CheckboxEachBand(idx)\n"); printf("{\n"); printf(" CheckCheckObj(form_wizard2.check_band_select);\n"); printf(" var pre_val=false, cnt1=0, cnt2=0, pos1=100, pos2=100, pos3=100;\n"); printf(" var i;\n"); printf(" document.form_wizard2.err_display_line.value=\"\";\n"); printf("\n"); printf(" for(i=0;i<9;i++){\n"); printf(" if(pre_val==false && document.form_wizard2.check_band[i].checked==true){\n"); printf(" if(pos1==100) pos1=i;\n"); printf(" else if(pos2==100) pos2=i;\n"); printf(" else if(pos3==100) pos3=i;\n"); printf(" }\n"); printf(" pre_val=document.form_wizard2.check_band[i].checked\n"); printf(" }\n"); printf("\n"); printf(" if(pos3!=100){\n"); printf(" document.form_wizard2.check_band[(idx-1)/2].checked=!document.form_wizard2.check_band[(idx-1)/2].checked;\n");///// printf(" document.form_wizard2.err_display_line.value=\"Band selection error: Too many band blocks(maximun 2)\";\n"); printf(" return;\n"); printf(" }\n"); printf("\n"); printf(" if(pos1<100){\n"); printf(" for(i=pos1;i<9;i++){\n"); printf(" if(document.form_wizard2.check_band[i].checked==true) cnt1++;\n"); printf(" else break;\n"); printf(" }\n"); printf(" }\n"); printf("\n"); printf(" if(pos2<100){\n"); printf(" for(i=pos2;i<9;i++){\n"); printf(" if(document.form_wizard2.check_band[i].checked==true) cnt2++;\n"); printf(" else break;\n"); printf(" }\n"); printf(" }\n"); printf("\n"); printf(" if(3<cnt1 || 3<cnt2){\n"); printf(" document.form_wizard2.check_band[(idx-1)/2].checked=!document.form_wizard2.check_band[(idx-1)/2].checked;\n");///// printf(" document.form_wizard2.err_display_line.value=\"Band selection error: Too wide bandwidth(maximun 15MHz)\";\n"); printf(" return;\n"); printf(" }\n"); printf(" if(3==cnt1 && 3==cnt2){\n"); printf(" document.form_wizard2.check_band[(idx-1)/2].checked=!document.form_wizard2.check_band[(idx-1)/2].checked;\n");///// printf(" document.form_wizard2.err_display_line.value=\"Band selection error: Invalid selection(15MHz+15MHz is not possible)\";\n"); printf(" return;\n"); printf(" }\n"); printf("}\n"); printf("function CheckBandSelect()\n"); printf("{\n"); printf(" for(i=0;i<3;i++){\n"); printf(" if(form_wizard2.check_band[i].checked==false) form_wizard2.check_band[i].value=0;\n"); printf(" form_wizard2.check_band[i].checked=true;\n"); //if not checked, it will not be submitted printf(" }\n"); printf("}\n"); printf("%s", "\n"); printf("%s", "//--> \n"); printf("%s", "</script>\n"); printf("%s", "\n"); printf("%s", "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); printf("%s", "</head>\n"); printf("%s", "\n"); //==================================================================================================================== printf("%s", "<body bgcolor=\"#FFFFFF\" text=\"#000000\">\n"); printf("%s", "<form name = \"form1\">\n"); //-------------------------------------------------------------------------------- html_menu_head_left(&protocol_status); html_menu_head_gate(&protocol_status,0, 0, "Setup wizard"); printf("%s", "<br>"); //-------------------------------------------------------------------------------- printf("%s", " </form>"); #if 0 printf("%s", " <table width=\"746\" border=\"1\" height=\"50\" bgcolor=\"#ff6699\">\n"); printf("%s", " <tr> \n"); printf("%s", " <td><div align=\"center\"><font color=\"#000000\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">\n"); printf("%s", " <b><font size=\"4\">Configuration setup wizard</font></b></font></div></td>\n"); printf("%s", " </tr>\n"); printf("%s", " </table>\n"); //Setup wizard 1 printf("%s", "<form name=\"form_wizard2\" method=\"POST\" action=\"html.cgi\">\n"); printf("%s", " <input name=\"check_band_select\" type=\"checkbox\" checked value=\"0\" style=\"display:none\">\n"); printf("%s", " <table width=\"746\" border=\"1\" height=\"96\" bgcolor=\"#CCCCCC\">\n"); //Band Select Status printf("%s", "<table width=\"746\" border=\"1\" bgcolor=\"#CCCCCC\">\n"); printf("%s", " <tr> \n"); printf("%s", " <td height=\"29\" colspan=\"9\"><div align=\"left\"></div>\n"); printf("%s", " <div align=\"center\"><font color=\"#000000\" size=\"2\" face=\"Arial, Helvetica, sans-serif\"><strong>Band Select Status</strong></font></div></td>\n"); printf("%s", " </tr>\n"); // printf("%s", "</table>\n"); // printf("%s", "<table width=\"746\" border=\"1\" bgcolor=\"#CCCCCC\">\n"); printf("%s", " <tr bgcolor=\"#FFFFFF\"> \n"); #if 1 printf("%s", " <td><div align=\"center\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">A1</font></div></td>\n"); printf("%s", " <td><div align=\"center\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">A2</font></div></td>\n"); printf("%s", " <td><div align=\"center\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">B1</font></div></td>\n"); printf("%s", " <td><div align=\"center\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">B2</font></div></td>\n"); printf("%s", " <td><div align=\"center\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">C</font></div></td>\n"); printf("%s", " <td><div align=\"center\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">D</font></div></td>\n"); #endif printf("%s", " <td><div align=\"center\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">E</font></div></td>\n"); printf("%s", " <td><div align=\"center\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">F1</font></div></td>\n"); printf("%s", " <td><div align=\"center\"><font size=\"2\" face=\"Arial, Helvetica, sans-serif\">F2</font></div></td>\n"); printf("%s", " </tr>\n"); printf("%s", " <tr bgcolor=\"#FFFFFF\"> \n"); //for(i=12; i<=16; i+=2) for(i=0; i<=16; i+=2) { if((bits_band>>i)&1) { printf(" <td><div align=\"center\"> <font face=\"Arial, Helvetica, sans-serif\"> \n"); printf(" <input type=\"checkbox\" name=\"check_band\" value=\"%d\" checked onClick=\"CheckboxEachBand(value)\"></font></div></td>\n", i+1);// +1 to avoid zero value } else { printf("%s", " <td><div align=\"center\"> <font face=\"Arial, Helvetica, sans-serif\"> \n"); printf(" <input type=\"checkbox\" name=\"check_band\" value=\"%d\" onClick=\"CheckboxEachBand(value)\"></font></div></td>\n", i+1);// +1 to avoid zero value } }
static void statf(int indent, FTSENT *p) { struct group *gr; struct passwd *pw; uint32_t val; off_t len; int fd, offset; char *escaped_name; escaped_name = calloc(1, p->fts_namelen * 4 + 1); if (escaped_name == NULL) errx(1, "statf(): calloc() failed"); strvis(escaped_name, p->fts_name, VIS_WHITE | VIS_OCTAL | VIS_GLOB); if (iflag || S_ISDIR(p->fts_statp->st_mode)) offset = printf("%*s%s", indent, "", escaped_name); else offset = printf("%*s %s", indent, "", escaped_name); free(escaped_name); if (offset > (INDENTNAMELEN + indent)) offset = MAXLINELEN; else offset += printf("%*s", (INDENTNAMELEN + indent) - offset, ""); if (!S_ISREG(p->fts_statp->st_mode) && !dflag) output(indent, &offset, "type=%s", inotype(p->fts_statp->st_mode)); if (p->fts_statp->st_uid != uid) { if (keys & F_UNAME) { pw = getpwuid(p->fts_statp->st_uid); if (pw != NULL) output(indent, &offset, "uname=%s", pw->pw_name); else if (wflag) warnx("Could not get uname for uid=%u", p->fts_statp->st_uid); else errx(1, "Could not get uname for uid=%u", p->fts_statp->st_uid); } if (keys & F_UID) output(indent, &offset, "uid=%u", p->fts_statp->st_uid); } if (p->fts_statp->st_gid != gid) { if (keys & F_GNAME) { gr = getgrgid(p->fts_statp->st_gid); if (gr != NULL) output(indent, &offset, "gname=%s", gr->gr_name); else if (wflag) warnx("Could not get gname for gid=%u", p->fts_statp->st_gid); else errx(1, "Could not get gname for gid=%u", p->fts_statp->st_gid); } if (keys & F_GID) output(indent, &offset, "gid=%u", p->fts_statp->st_gid); } if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode) output(indent, &offset, "mode=%#o", p->fts_statp->st_mode & MBITS); if (keys & F_NLINK && p->fts_statp->st_nlink != 1) output(indent, &offset, "nlink=%u", p->fts_statp->st_nlink); if (keys & F_SIZE) output(indent, &offset, "size=%jd", (intmax_t)p->fts_statp->st_size); if (keys & F_TIME) output(indent, &offset, "time=%ld.%09ld", (long)p->fts_statp->st_mtimespec.tv_sec, p->fts_statp->st_mtimespec.tv_nsec); if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || crc(fd, &val, &len)) err(1, "%s", p->fts_accpath); (void)close(fd); output(indent, &offset, "cksum=%lu", (unsigned long)val); } #ifdef HAVE_OPENSSL_MD5_H if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) { char *digest, buf[33]; digest = MD5_File(p->fts_accpath, buf); if (!digest) err(1, "%s", p->fts_accpath); output(indent, &offset, "md5digest=%s", digest); } #endif /* HAVE_OPENSSL_MD5_H */ #ifdef HAVE_OPENSSL_SHA_H if (keys & F_SHA1 && S_ISREG(p->fts_statp->st_mode)) { char *digest, buf[41]; digest = SHA1_File(p->fts_accpath, buf); if (!digest) err(1, "%s", p->fts_accpath); output(indent, &offset, "sha1digest=%s", digest); } #endif /* HAVE_OPENSSL_SHA_H */ #ifdef HAVE_OPENSSL_RIPEMD_H if (keys & F_RMD160 && S_ISREG(p->fts_statp->st_mode)) { char *digest, buf[41]; digest = RIPEMD160_File(p->fts_accpath, buf); if (!digest) err(1, "%s", p->fts_accpath); output(indent, &offset, "ripemd160digest=%s", digest); } #endif /* HAVE_OPENSSL_RIPEMD_H */ #ifdef HAVE_OPENSSL_SHA_H if (keys & F_SHA256 && S_ISREG(p->fts_statp->st_mode)) { char *digest, buf[65]; digest = SHA256_File(p->fts_accpath, buf); if (!digest) err(1, "%s", p->fts_accpath); output(indent, &offset, "sha256digest=%s", digest); } #endif /* HAVE_OPENSSL_SHA_H */ if (keys & F_SLINK && (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) output(indent, &offset, "link=%s", rlink(p->fts_accpath)); #if 0 if (keys & F_FLAGS && p->fts_statp->st_flags != flags) { fflags = flags_to_string(p->fts_statp->st_flags); output(indent, &offset, "flags=%s", fflags); free(fflags); } #endif (void)putchar('\n'); }
void processPNG(unsigned char* buffer, long lSize, int verbose) { int cur = 0; unsigned char strBuffer[LEN_STR]; printf("\n0x%08X\tpng-signature=", cur); getBytes(buffer, cur, LEN_PNGSIG); puts(""); cur += LEN_PNGSIG; while (cur < lSize) { // Print (LENGTH, TYPE, CRC) for each. long length = getNum(buffer, cur, LEN_CKLENGTH); printf("\n0x%08X\tchunk-length=0x%08lX\t(%ld)", cur, length, length); // CHUNK LENGTH cur += LEN_CKLENGTH; unsigned char type[LEN_HDR]; grabString(buffer, cur, LEN_CKTYPE, type); printf("\n0x%08X\tchunk-type=\'%s\'", cur, type); // CHUNK TYPE int crcBegin = cur; cur += LEN_CKTYPE; if (verbose && (strcmp((char*)type, "IHDR") == 0)) { //if verbose, print expanded IHDR long width = getNum(buffer, cur, LEN_WIDTH); printf("\n0x%08X\twidth=0x%08lX\t(%ld)", cur, width, width); cur += LEN_WIDTH; long height = getNum(buffer, cur, LEN_HEIGHT); printf("\n0x%08X\theight=0x%08lX\t(%ld)", cur, height, height); cur += LEN_HEIGHT; printf("\n0x%08X\tbit-depth=%ld", cur, getNum(buffer, cur, LEN_BITDEPTH)); cur += LEN_BITDEPTH; long colorType = getNum(buffer, cur, LEN_COLORTYPE); strColorType(colorType, strBuffer); // Stores type description in strBuffer printf("\n0x%08X\tcolor-type=%ld \t(%s)", cur, colorType, strBuffer); cur += LEN_COLORTYPE; long compressMethod = getNum(buffer, cur, LEN_COMPRESS); strCompress(compressMethod, strBuffer); printf("\n0x%08X\tcompression-method=%ld \t(%s)", cur, compressMethod, strBuffer); cur += LEN_COMPRESS; long filterMethod = getNum(buffer, cur, LEN_FILTER); strFilter(filterMethod, strBuffer); printf("\n0x%08X\tfilter-method=%ld \t(%s)", cur, filterMethod, strBuffer); cur += LEN_FILTER; long interlaceMethod = getNum(buffer, cur, LEN_INTERLACE); strInterlace(interlaceMethod, strBuffer); printf("\n0x%08X\tinterlace-method=%ld \t(%s)", cur, interlaceMethod, strBuffer); cur += LEN_INTERLACE; } int crcLen = LEN_CKTYPE + length; unsigned char crcInput[crcLen]; grabBytes(buffer, crcBegin, crcLen, crcInput); cur = crcBegin + crcLen; long crcCode = getNum(buffer, cur, LEN_CRC); long crcComputed = crc(crcInput, crcLen); char* crcResult = "CRC FAILED"; if (crcCode == crcComputed) crcResult = "CRC OK!"; printf("\n0x%08X\tcrc-code=0x%08lX", cur, crcCode); printf("\n>> (CRC CHECK) crc-computed=0x%08lX \t=>\t%s\n\n", crcComputed, crcResult); cur += LEN_CRC; } }
//65=6'07" //65=4'30" //58=3'57" //55=3'40" //50=3'25" //20=1'20" //14=0'58" //10=0'40" // 8=0'32" void waiting_page(unsigned int time, char *title, char *message, char *alarm, char page_id) { struct protocol_web_status protocol_status; int sockfd; int client; struct sockaddr_un serveraddr; struct sockaddr_un clientaddr; unsigned char frame[sizeof(protocol_status)*2]; int frame_size; int buffer_size; char protocol_buffer[sizeof(protocol_status)*2]; int i, n; unsigned short crc_data; char page_name[64]; client = sizeof(serveraddr); sockfd = socket(PF_UNIX, SOCK_DGRAM, 0); if(sockfd < 0) { message_dialog("socket error"); exit(0); } bzero(&serveraddr, sizeof(serveraddr)); serveraddr.sun_family = AF_UNIX; strcpy(serveraddr.sun_path, "/tmp/socket_app"); bzero(&clientaddr, sizeof(clientaddr)); clientaddr.sun_family = AF_UNIX; strcpy(clientaddr.sun_path, "/tmp/socket_web"); remove("/tmp/socket_web"); if(bind(sockfd, (struct sockaddr*)&clientaddr, sizeof(clientaddr))) { message_dialog("socket error"); exit(0); } memset(&protocol_status, 0, sizeof(protocol_status)); protocol_status.type = PROTOCOL_STATUS; protocol_buffer_to_frame((void*)&protocol_status, 1,frame, &frame_size); sched_yield(); sendto(sockfd, frame, 3,0,(struct sockaddr*)&serveraddr, client); n = recvfrom(sockfd, frame, sizeof(frame), 0, NULL, NULL); protocol_frame_to_buffer(frame, n, (unsigned char*)protocol_buffer, &buffer_size); memmove(&protocol_status,protocol_buffer,buffer_size); crc_data = crc((void*)&protocol_status.type, (void*)&protocol_status.crc); if(crc_data != protocol_status.crc) message_dialog("crc error"); if(time) { //================================ html_page_head(1); // arg==requiredfrom true(1), false(0) #if 0 printf("Content-type: text/html\r\n\r\n"); printf("<font face=\"Courier New\"><font size=1><font size=2><html>\n"); printf("<head>\n"); printf("<title>Sprint SmartCell</title>\n"); printf("\n"); printf("<script language=\"JavaScript\">\n"); printf("<!--\n"); printf("<!-- Begin\n"); printf("var requiredfrom = \"html.cgi\"; // required prev. page\n"); printf("if (document.referrer.indexOf(requiredfrom) == -1) {\n"); printf("alert(\"Sorry! You should register to access. Please go back to log-in.\" );\n"); printf("window.location=requiredfrom;\n"); printf("}\n"); printf("\n"); printf("// End -->\n"); printf("\n"); #endif printf("%s%d%s", "var loadtime=",time,"; // timer set\n"); printf("var linkactive=\"Click result\";\n"); printf("var doload=0;var doing=0;var loadsize=1;\n"); printf("\n"); // create_ajax_code(); printf("%s", "function logout()\n"); printf("%s", "{\n"); printf("%s", " if (document.cookie != \"\") \n"); printf("%s", " {\n"); printf("%s", " thisCookie = document.cookie.split(\"; \")\n"); printf("%s", " expireDate = new Date\n"); printf("%s", " expireDate.setDate(expireDate.getDate()-1)\n"); printf("%s", " for (i=0; i<thisCookie.length; i++) \n"); printf("%s", " {\n"); printf("%s", " document.cookie = thisCookie + \";expires=\" + expireDate.toGMTString()\n"); printf("%s", " }\n"); printf("%s", " }\n"); printf("%s", " location.replace(\"html.cgi?function=logout\");\n"); printf("%s", "}\n"); printf("%s", "\n"); switch(page_id) { default: case PAGE_logout: sprintf(page_name, "logout"); break; case PAGE_list: sprintf(page_name, "list"); break; case PAGE_tree_status: sprintf(page_name, "tree_status"); break; case PAGE_status: sprintf(page_name, "status"); break; case PAGE_tree_rfconfig: case PAGE_rfconfig: sprintf(page_name, "rfconfig"); break; case PAGE_rfconfig_1: sprintf(page_name, "rfconfig_1"); break; case PAGE_rfconfig_2: sprintf(page_name, "rfconfig_2"); break; case PAGE_rfconfig_3: sprintf(page_name, "rfconfig_3"); break; case PAGE_alarm_config: sprintf(page_name, "alarm_config"); break; case PAGE_alarm_config_1: sprintf(page_name, "alarm_config_1"); break; case PAGE_alarm_config_2: sprintf(page_name, "alarm_config_2"); break; case PAGE_alarm_config_3: sprintf(page_name, "alarm_config_3"); break; case PAGE_communication: sprintf(page_name, "communications"); break; case PAGE_usermanagement: sprintf(page_name, "usermanagement"); break; case PAGE_logs: sprintf(page_name, "logs"); break; case PAGE_alarmlogs_1: sprintf(page_name, "alarm_log"); break; case PAGE_alarmlogs_2: sprintf(page_name, "alarm_log2"); break; case PAGE_alarmlogs_3: sprintf(page_name, "alarm_log3"); break; case PAGE_alarmlogs_4: sprintf(page_name, "alarm_log4"); break; case PAGE_troubleshooting: sprintf(page_name, "troubleshooting"); break; case PAGE_system_download: sprintf(page_name, "system_download"); break; case PAGE_reset: sprintf(page_name, "reset"); break; case PAGE_reset_module: sprintf(page_name, "reset_module"); break; case PAGE_systemreset: sprintf(page_name, "systemreset"); break; case PAGE_factory_default_select: sprintf(page_name, "factory_default_select"); break; case PAGE_factory_default: sprintf(page_name, "factory_default"); break; case PAGE_default_rf: sprintf(page_name, "default_rf"); break; case PAGE_default_alarm: sprintf(page_name, "default_alarm"); break; case PAGE_modem_activate: sprintf(page_name, "modem_activate"); break; case PAGE_default_user: sprintf(page_name, "default_user"); break; case PAGE_default_communication: sprintf(page_name, "default_communication"); break; case PAGE_transfer_except: sprintf(page_name, "transfer_except"); break; case PAGE_transfer_except_download: sprintf(page_name, "transfer_except_download"); break; case PAGE_transfer_except_upload: sprintf(page_name, "transfer_except_upload"); break; case PAGE_upload_waiting: sprintf(page_name, "upload_waiting"); break; case PAGE_summary_page: sprintf(page_name, "summary_page"); break; case PAGE_wizard1: sprintf(page_name, "wizard1"); break; case PAGE_wizard2: sprintf(page_name, "wizard2"); break; case PAGE_fake_alarm_1: sprintf(page_name, "fake_alarm_config"); break; case PAGE_fake_alarm_2: sprintf(page_name, "fake_alarm_config_1"); break; case PAGE_fake_alarm_3: sprintf(page_name, "fake_alarm_config_2"); break; case PAGE_fake_alarm_4: sprintf(page_name, "fake_alarm_config_3"); break; } printf("%s", "function cont() \n"); printf("%s", "{\n"); printf("%s", " if (doload==0 & loadsize>1) \n"); printf("%s", " loadsize=loadsize -1;\n"); printf("%s", " \n"); printf("%s", " if (doload==1 & loadsize<loadtime*20) \n"); // printf("%s", " loadsize=loadsize- -1;\n"); printf("%s", " loadsize=loadsize +1;\n"); printf("%s", " \n"); printf("%s", " loader.width=Math.round(loadsize/(loadtime*20)*(loadarea.width-2-(loadarea.border*2)));\n"); printf("%s", " \n"); printf("%s", " if (loadsize>1 & loadsize<loadtime*20) \n"); printf("%s", " {\n"); printf("%s", " setTimeout('cont()', 0300); \n"); printf("%s", " doing=1\n"); printf("%s", " }\n"); printf("%s", " else\n"); printf("%s", " {\n"); printf("%s", " doing=0\n"); printf("%s", " }\n"); printf("%s", " \n"); printf("%s", " if (loadsize>=loadtime*20)\n"); printf("%s", " {\n"); if(page_id==PAGE_logout) printf( " document.location.replace(\"html.cgi\"); \n"); else printf( " document.location.replace(\"html.cgi?function=%s\"); \n", page_name); printf("%s", " }\n"); printf("%s", "}\n"); printf("%s", "function loading() \n"); printf("%s", "{\n"); printf("%s", " doload=1;\n"); printf("%s", " if (doing==0) \n"); printf("%s", " cont();\n"); printf("%s", "}\n"); printf("%s", "\n"); printf("%s", "\n"); printf("%s", "//-->\n"); printf("%s", "</script>\n"); printf("%s", "\n"); printf("%s", "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"); printf("%s", "</head>\n"); printf("%s", "\n"); printf("%s", "<body bgcolor=\"#FFFFFF\" text=\"#000000\" onload=\"loading(); \">\n"); //=============================================================================== printf("%s", "<form name = \"form1\">\n"); html_menu_head_gate(&protocol_status, 1, 0, title); printf("%s", " </form>"); //================================ //=========1024*768 end=========== //================================ printf("%s%s%s", "<p align=center><b><font color=\"#000000\" size=\"4\" face=\"Arial, Helvetica, sans-serif\">", message," ...\n"); // printf("%s", "</font></b><table border=\"2\" id=\"loadarea\" cellspacing=\"0\" width=\"400\" cellpadding=\"0\" ><tr><td>\n"); printf("%s", "</font></b><table border=\"2\" id=\"loadarea\" cellspacing=\"0\" width=\"500\" cellpadding=\"0\" ><tr><td>\n"); // printf("%s", "</font></b><table border=\"2\" id=\"loadarea\" cellspacing=\"0\" width=\"600\" cellpadding=\"0\" ><tr><td>\n"); printf("%s", "<table width=\"1\" height=\"30\" id=\"loader\" bgcolor=\"#000000\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><font color=\"blue\"> </font></td></tr></table></td></tr></table>\n"); if(alarm != NULL) { printf("%s", " <p><p align=\"center\">\n"); printf("%s%s%s", " <font face=\"Arial, Helvetica, sans-serif\" size=\"3\"><b><font color=\"#FF0000\" size=\"4\">", alarm, "</font></a></b></font>\n"); } printf("%s", "\n"); for(i=0;i<1000;i++) printf(" "); printf("%s", "</body>\n"); printf("%s", "</html>\n"); } // alarm(0); if(sockfd) close(sockfd); }
/// Character Received - add it to our command /// \param c the next character to process void gcode_parse_char(uint8_t c) { // uppercase if (c >= 'a' && c <= 'z') c &= ~32; // process previous field if (last_field) { // check if we're seeing a new field or end of line // any character will start a new field, even invalid/unknown ones if ((c >= 'A' && c <= 'Z') || c == '*' || (c == 10) || (c == 13)) { switch (last_field) { case 'G': next_target.G = read_digit.mantissa; if (debug_flags & DEBUG_ECHO) serwrite_uint8(next_target.G); break; case 'M': next_target.M = read_digit.mantissa; if (debug_flags & DEBUG_ECHO) serwrite_uint8(next_target.M); break; case 'X': if (next_target.option_inches) next_target.target.X = decfloat_to_int(&read_digit, STEPS_PER_IN_X, 1); else next_target.target.X = decfloat_to_int(&read_digit, STEPS_PER_M_X, 1000); if (debug_flags & DEBUG_ECHO) serwrite_int32(next_target.target.X); break; case 'Y': if (next_target.option_inches) next_target.target.Y = decfloat_to_int(&read_digit, STEPS_PER_IN_Y, 1); else next_target.target.Y = decfloat_to_int(&read_digit, STEPS_PER_M_Y, 1000); if (debug_flags & DEBUG_ECHO) serwrite_int32(next_target.target.Y); break; case 'Z': if (next_target.option_inches) next_target.target.Z = decfloat_to_int(&read_digit, STEPS_PER_IN_Z, 1); else next_target.target.Z = decfloat_to_int(&read_digit, STEPS_PER_M_Z, 1000); if (debug_flags & DEBUG_ECHO) serwrite_int32(next_target.target.Z); break; case 'E': if (next_target.option_inches) next_target.target.E = decfloat_to_int(&read_digit, STEPS_PER_IN_E, 1); else next_target.target.E = decfloat_to_int(&read_digit, STEPS_PER_M_E, 1000); if (debug_flags & DEBUG_ECHO) serwrite_uint32(next_target.target.E); break; case 'F': // just use raw integer, we need move distance and n_steps to convert it to a useful value, so wait until we have those to convert it if (next_target.option_inches) next_target.target.F = decfloat_to_int(&read_digit, 254, 10); else next_target.target.F = decfloat_to_int(&read_digit, 1, 1); if (debug_flags & DEBUG_ECHO) serwrite_uint32(next_target.target.F); break; case 'S': // if this is temperature, multiply by 4 to convert to quarter-degree units // cosmetically this should be done in the temperature section, // but it takes less code, less memory and loses no precision if we do it here instead if ((next_target.M == 104) || (next_target.M == 109) || (next_target.M == 140)) next_target.S = decfloat_to_int(&read_digit, 4, 1); // if this is heater PID stuff, multiply by PID_SCALE because we divide by PID_SCALE later on else if ((next_target.M >= 130) && (next_target.M <= 132)) next_target.S = decfloat_to_int(&read_digit, PID_SCALE, 1); else next_target.S = decfloat_to_int(&read_digit, 1, 1); if (debug_flags & DEBUG_ECHO) serwrite_uint16(next_target.S); break; case 'P': next_target.P = decfloat_to_int(&read_digit, 1, 1); if (debug_flags & DEBUG_ECHO) serwrite_uint16(next_target.P); break; case 'T': next_target.T = read_digit.mantissa; if (debug_flags & DEBUG_ECHO) serwrite_uint8(next_target.T); break; case 'N': next_target.N = decfloat_to_int(&read_digit, 1, 1); if (debug_flags & DEBUG_ECHO) serwrite_uint32(next_target.N); break; case '*': next_target.checksum_read = decfloat_to_int(&read_digit, 1, 1); if (debug_flags & DEBUG_ECHO) serwrite_uint8(next_target.checksum_read); break; } // reset for next field last_field = 0; read_digit.sign = read_digit.mantissa = read_digit.exponent = 0; } } // skip comments if (next_target.seen_semi_comment == 0 && next_target.seen_parens_comment == 0) { // new field? if ((c >= 'A' && c <= 'Z') || c == '*') { last_field = c; if (debug_flags & DEBUG_ECHO) serial_writechar(c); } // process character switch (c) { // each currently known command is either G or M, so preserve previous G/M unless a new one has appeared // FIXME: same for T command case 'G': next_target.seen_G = 1; next_target.seen_M = 0; next_target.M = 0; break; case 'M': next_target.seen_M = 1; next_target.seen_G = 0; next_target.G = 0; break; case 'X': next_target.seen_X = 1; break; case 'Y': next_target.seen_Y = 1; break; case 'Z': next_target.seen_Z = 1; break; case 'E': next_target.seen_E = 1; break; case 'F': next_target.seen_F = 1; break; case 'S': next_target.seen_S = 1; break; case 'P': next_target.seen_P = 1; break; case 'T': next_target.seen_T = 1; break; case 'N': next_target.seen_N = 1; break; case '*': next_target.seen_checksum = 1; break; // comments case ';': next_target.seen_semi_comment = 1; break; case '(': next_target.seen_parens_comment = 1; break; // now for some numeracy case '-': read_digit.sign = 1; // force sign to be at start of number, so 1-2 = -2 instead of -12 read_digit.exponent = 0; read_digit.mantissa = 0; break; case '.': if (read_digit.exponent == 0) read_digit.exponent = 1; break; #ifdef DEBUG case ' ': case '\t': case 10: case 13: // ignore break; #endif default: // can't do ranges in switch..case, so process actual digits here. if (c >= '0' && c <= '9') { if (read_digit.exponent < DECFLOAT_EXP_MAX && ((next_target.option_inches == 0 && read_digit.mantissa < DECFLOAT_MANT_MM_MAX) || (next_target.option_inches && read_digit.mantissa < DECFLOAT_MANT_IN_MAX))) { // this is simply mantissa = (mantissa * 10) + atoi(c) in different clothes read_digit.mantissa = (read_digit.mantissa << 3) + (read_digit.mantissa << 1) + (c - '0'); if (read_digit.exponent) read_digit.exponent++; } } #ifdef DEBUG else { // invalid serial_writechar('?'); serial_writechar(c); serial_writechar('?'); } #endif } } else if ( next_target.seen_parens_comment == 1 && c == ')') next_target.seen_parens_comment = 0; // recognize stuff after a (comment) if (next_target.seen_checksum == 0) next_target.checksum_calculated = crc(next_target.checksum_calculated, c); // end of line if ((c == 10) || (c == 13)) { if (debug_flags & DEBUG_ECHO) serial_writechar(c); if ( #ifdef REQUIRE_LINENUMBER ((next_target.N >= next_target.N_expected) && (next_target.seen_N == 1)) || (next_target.seen_M && (next_target.M == 110)) #else 1 #endif ) { if ( #ifdef REQUIRE_CHECKSUM ((next_target.checksum_calculated == next_target.checksum_read) && (next_target.seen_checksum == 1)) #else ((next_target.checksum_calculated == next_target.checksum_read) || (next_target.seen_checksum == 0)) #endif ) { // process serial_writestr_P(PSTR("ok ")); process_gcode_command(); serial_writestr_P(PSTR("\n")); // expect next line number if (next_target.seen_N == 1) next_target.N_expected = next_target.N + 1; } else { sersendf_P(PSTR("rs N%ld Expected checksum %d\n"), next_target.N_expected, next_target.checksum_calculated); // request_resend(); } } else { sersendf_P(PSTR("rs N%ld Expected line number %ld\n"), next_target.N_expected, next_target.N_expected); // request_resend(); } // reset variables next_target.seen_X = next_target.seen_Y = next_target.seen_Z = \ next_target.seen_E = next_target.seen_F = next_target.seen_S = \ next_target.seen_P = next_target.seen_T = next_target.seen_N = \ next_target.seen_M = next_target.seen_checksum = next_target.seen_semi_comment = \ next_target.seen_parens_comment = next_target.checksum_read = \ next_target.checksum_calculated = 0; // last_field and read_digit are reset above already // assume a G1 by default next_target.seen_G = 1; next_target.G = 1; if (next_target.option_relative) { next_target.target.X = next_target.target.Y = next_target.target.Z = 0; } // E always relative next_target.target.E = 0; } }
void gcode_parse_char(uint8_t c) { uint8_t save_ch; #ifdef ASTERISK_IN_CHECKSUM_INCLUDED if (next_target.seen_checksum == 0) next_target.checksum_calculated = crc(next_target.checksum_calculated, c); #endif save_ch = c; // uppercase if (c >= 'a' && c <= 'z') c &= ~32; // process previous field if (last_field) { // check if we're seeing a new field or end of line // any character will start a new field, even invalid/unknown ones if ((c >= 'A' && c <= 'Z') || c == '*' || (c == 10) || (c == 13)) { // before using value, apply the sign if (read_digit.sign) value = -value; switch (last_field) { case 'G': next_target.G = value; break; case 'M': next_target.M = value; // this is a bit hacky since string parameters don't fit in general G code syntax // NB: filename MUST start with a letter and MUST NOT contain spaces // letters will also be converted to uppercase if ( (next_target.M == 23) || (next_target.M == 28) ) { next_target.getting_string = 1; } break; case 'X': if (next_target.option_inches) next_target.target.x = inch_to_mm(value); else next_target.target.x = value; break; case 'Y': if (next_target.option_inches) next_target.target.y = inch_to_mm(value); else next_target.target.y = value; break; case 'Z': if (next_target.option_inches) next_target.target.z = inch_to_mm(value); else next_target.target.z = value; break; case 'E': if (next_target.option_inches) next_target.target.e = inch_to_mm(value); else next_target.target.e = value; break; case 'F': if (next_target.option_inches) next_target.target.feed_rate = inch_to_mm(value); else next_target.target.feed_rate = value; break; case 'S': next_target.S = value; break; case 'P': // if this is dwell, multiply by 1000 to convert seconds to milliseconds if (next_target.G == 4) next_target.P = value * 1000.0; else next_target.P = value; break; case 'N': next_target.N = value; break; case '*': next_target.checksum_read = value; break; } // reset for next field last_field = 0; read_digit.sign = read_digit.exponent = 0; value = 0; } } if (next_target.getting_string) { if ((c == 10) || (c == 13) || ( c == ' ') || ( c == '*')) next_target.getting_string = 0; else { if (next_target.chpos < sizeof(next_target.filename)) { next_target.filename [next_target.chpos++] = c; next_target.filename [next_target.chpos] = 0; } } } // skip comments, filenames if (next_target.seen_semi_comment == 0 && next_target.seen_parens_comment == 0 && next_target.getting_string == 0) { // new field? if ((c >= 'A' && c <= 'Z') || c == '*') { last_field = c; } // process character switch (c) { // each currently known command is either G or M, so preserve previous G/M unless a new one has appeared // FIXME: same for T command case 'G': next_target.seen_G = 1; next_target.seen_M = 0; next_target.M = 0; break; case 'M': next_target.seen_M = 1; next_target.seen_G = 0; next_target.G = 0; break; case 'X': next_target.seen_X = 1; break; case 'Y': next_target.seen_Y = 1; break; case 'Z': next_target.seen_Z = 1; break; case 'E': next_target.seen_E = 1; break; case 'F': next_target.seen_F = 1; break; case 'S': next_target.seen_S = 1; break; case 'P': next_target.seen_P = 1; break; case 'N': next_target.seen_N = 1; break; case '*': next_target.seen_checksum = 1; break; // comments case ';': case '^': next_target.seen_semi_comment = 1; break; case '(': next_target.seen_parens_comment = 1; break; // now for some numeracy case '-': read_digit.sign = 1; // force sign to be at start of number, so 1-2 = -2 instead of -12 read_digit.exponent = 0; break; case '.': if (read_digit.exponent == 0) read_digit.exponent = 1; break; default: // can't do ranges in switch..case, so process actual digits here if (c >= '0' && c <= '9') { if (read_digit.exponent == 0) { value = value * 10 + (c - '0'); } else value += (double)(c - '0') / power(10, read_digit.exponent); if (read_digit.exponent) read_digit.exponent++; } } } else if ( next_target.seen_parens_comment == 1 && c == ')') next_target.seen_parens_comment = 0; // recognize stuff after a (comment) #ifndef ASTERISK_IN_CHECKSUM_INCLUDED if (next_target.seen_checksum == 0) next_target.checksum_calculated = crc(next_target.checksum_calculated, save_ch); #endif }
ECode CxxSourceCrcTask::operator()() { const auto& path = apply_visitor(doim::vst::path(), cxxSource()); defer(LOGEX(tags(), "{} for {} is {:x}", depth() == EDepth::kOne ? "Crc" : "Deep Crc", path, mCrcsum)); auto origin = apply_visitor([](auto const& element) { return element->origin(); }, cxxSource()); if (!apply_visitor(vst::isNullptr, origin)) { if (origin.type() == typeid(doim::ProtobufFileSPtr)) { auto originTask = ProtobufFileCrcTask::valid(boost::get<doim::ProtobufFileSPtr>(origin)); gTPool->ensureScheduled(originTask); EHTest(originTask->join()); mCrcsum = originTask->crc(); } else ASSERT(false); EHEnd; } if (depth() == EDepth::kOne) { EHTest(one()); EHEnd; } auto crcTask = valid(EDepth::kOne, cxxSource(), currentIncludeDirectory()); gTPool->ensureScheduled(crcTask); auto headersTask = CxxSourceHeadersTask::valid(CxxSourceHeadersTask::EDepth::kAll, cxxSource(), currentIncludeDirectory()); gTPool->ensureScheduled(headersTask); EHTest(headersTask->join()); const auto& headersInfo = headersTask->headersInfo(); std::vector<CxxSourceCrcTaskSPtr> tasks; tasks.reserve(headersInfo.size() + 1); tasks.push_back(crcTask); for (const auto& headerInfo : headersInfo) { if (headerInfo.mHeader->type() == doim::CxxHeader::EType::kSystem) continue; auto task = CxxSourceCrcTask::valid(CxxSourceCrcTask::EDepth::kOne, headerInfo.mHeader, headerInfo.mIncludeDirectory); task::gTPool->ensureScheduled(task); tasks.push_back(task); } auto group = tpool::TaskGroup::make(task::gTPool, 0, tasks); task::gTPool->ensureScheduled(group); EHTest(group->join()); unordered_set<math::Crcsum> crcs; math::Crcsum x = 0; for (const auto& task : tasks) { auto n = task->crc(); if (n == 0) { mCrcsum = 0; EHEnd; } auto unique = crcs.insert(n).second; if (!unique) EHBan(kTooMany, "There are at least two items with the same crc"); x ^= n; } mCrcsum = math::obfuscate(x); EHEnd; }
uint STDCALL ge_save( pvmEngine pThis, char* fileName, char* isSave) { gehead head; pgehead phead; uint i, ii, count; pvmobj pvmo; buf out; str filename; if ( setjmp( pThis->stack_state) == -1 ) return 0; str_init( pThis, &filename ); str_copyzero( pThis, &filename, fileName ); buf_init( pThis, &out ); pThis->gesave = &out; buf_reserve( pThis, &out, 0x1ffff ); *( puint )&head.idname = GE_STRING;//0x00004547; // строка GE head.flags = 0; head.crc = 0; head.headsize = sizeof( gehead ); head.size = 0; head.vermajor = GEVER_MAJOR; head.verminor = GEVER_MINOR; buf_append( pThis, &out, ( pubyte )&head, sizeof( gehead )); // Save resources at the first ! gesave_resource(pThis); count = arr_count( pThis, &pThis->_vm.objtbl ); for ( i = KERNEL_COUNT; i < count ; i++ ) { if(isSave && isSave[i] == 0) { /* gesave_addubyte( pThis, OVM_NONE ); gesave_adduint( pThis, GHCOM_PACK); gesave_bwd( pThis, 6 );*/ pThis->popravka ++; continue; } pvmo = ( pvmobj )PCMD( i ); pvmo->id -= pThis->popravka; //@init @delete @array @oftype @index -не удалять имена if(pThis->isDelName&&(pvmo->flag&GHCOM_NAME)&&pvmo->name&&lstrcmpA("@init",pvmo->name)&& lstrcmpA("@delete",pvmo->name)&&lstrcmpA("@array",pvmo->name)&& lstrcmpA("@oftype",pvmo->name)&&lstrcmpA("@index",pvmo->name)) { pvmo->flag &= ~GHCOM_NAME; }else if(pvmo->name) pvmo->flag |= ~GHCOM_NAME; gesave_head( pThis, pvmo->type, pvmo->flag & GHCOM_NAME ? pvmo->name : NULL, pvmo->flag ); switch ( pvmo->type ) { case OVM_NONE: break; case OVM_BYTECODE: gesave_bytecode( pThis, ( povmbcode )pvmo ); break; case OVM_EXFUNC: ((povmfunc)pvmo)->import = ((pvmobj)PCMD(((povmfunc)pvmo)->import))->id; gesave_exfunc( pThis, ( povmfunc )pvmo ); break; case OVM_TYPE: { for(ii = 0; ii<((povmtype)pvmo)->count; ii++) { if(pThis->isDelName) ((povmtype)pvmo)->children[ii].flag &=~GHCOM_NAME; else if(((povmtype)pvmo)->children[ii].name) ((povmtype)pvmo)->children[ii].flag |=GHCOM_NAME; } gesave_type( pThis, ( povmtype )pvmo ); }break; case OVM_GLOBAL: gesave_var( pThis, (( povmglobal )pvmo)->type ); break; case OVM_DEFINE: gesave_define( pThis, ( povmdefine )pvmo ); break; case OVM_IMPORT: gesave_import( pThis, ( povmimport )pvmo ); break; case OVM_ALIAS: gesave_bwd( pThis, (( povmalias )pvmo)->idlink ); break; } gesave_finish(pThis); } // Specify the full size and crc phead = ( pgehead )buf_ptr( pThis, &out ); phead->size = buf_len( pThis, &out ); phead->crc = crc( pThis, ( pubyte )phead + 12, phead->size - 12, 0xFFFFFFFF ); buf2file( pThis, &filename, &out ); buf_delete( pThis, &out ); str_delete( pThis, &filename ); return 1; }
UBYTE pwm_send(UBYTE *resp, UBYTE len, UBYTE *msg, UBYTE msg_len) { UBYTE ret,i,j; UBYTE message[20]; UBYTE done; if (msg_len>6) { printf("Error: PWM message allows only 7 bytes\n\r"); return 0; } //OK we need to build the message message[0]=0x61; message[1]=0x6A; message[2]=0xF1; for(i=0; i<msg_len; i++) { message[3+i]=msg[i]; } i=3+i; message[i]=crc(message,i); i++; /* printf("Sending: "); for(ret=0; ret<i; ret++) { printf("%X ",message[ret]); } */ //now we can send message for(j=0; j<3; j++) { ret=pwm_put(message,i,2000); if (ret==i) break; } if(ret!=i) { printf("Error: PWM message sending problems %d\n\r",ret); return 0; } //now lets get response //delay_us(500); //printf("calling PWM get\n\r"); //ret=pwm_get(resp,len,2000); done=0; i=0; while(!done) { ret=pwm_rx(resp,len,2000); if (ret>5) { if (resp[0]==0x41) done=1; } i++; if (i>20) done=1; } //ret=pwm_rx(resp,len,2000); //ret=pwm_rx(resp,len,2000); /* printf("\tRx: "); for(i=0; i<ret; i++) { printf("%X ",resp[i]); } printf("\n\r"); */ return ret; }
int compare(NODE *s, FTSENT *p) { u_int32_t len, val; #if HAVE_STRUCT_STAT_ST_FLAGS u_int32_t flags; #endif int fd, label; const char *cp, *tab; #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2) char *digestbuf; #endif tab = NULL; label = 0; switch(s->type) { case F_BLOCK: if (!S_ISBLK(p->fts_statp->st_mode)) goto typeerr; break; case F_CHAR: if (!S_ISCHR(p->fts_statp->st_mode)) goto typeerr; break; case F_DIR: if (!S_ISDIR(p->fts_statp->st_mode)) goto typeerr; break; case F_FIFO: if (!S_ISFIFO(p->fts_statp->st_mode)) goto typeerr; break; case F_FILE: if (!S_ISREG(p->fts_statp->st_mode)) goto typeerr; break; case F_LINK: if (!S_ISLNK(p->fts_statp->st_mode)) goto typeerr; break; #ifdef S_ISSOCK case F_SOCK: if (!S_ISSOCK(p->fts_statp->st_mode)) goto typeerr; break; #endif typeerr: LABEL; printf("\ttype (%s, %s)\n", nodetype(s->type), inotype(p->fts_statp->st_mode)); return (label); } if (mtree_Wflag) goto afterpermwhack; #if HAVE_STRUCT_STAT_ST_FLAGS if (iflag && !uflag) { if (s->flags & F_FLAGS) SETFLAGS(p->fts_statp->st_flags, SP_FLGS); return (label); } if (mflag && !uflag) { if (s->flags & F_FLAGS) CLEARFLAGS(p->fts_statp->st_flags, SP_FLGS); return (label); } #endif if (s->flags & F_DEV && (s->type == F_BLOCK || s->type == F_CHAR) && s->st_rdev != p->fts_statp->st_rdev) { LABEL; printf("%sdevice (%#llx, %#llx", tab, (long long)s->st_rdev, (long long)p->fts_statp->st_rdev); if (uflag) { if ((unlink(p->fts_accpath) == -1) || (mknod(p->fts_accpath, s->st_mode | nodetoino(s->type), s->st_rdev) == -1) || (lchown(p->fts_accpath, p->fts_statp->st_uid, p->fts_statp->st_gid) == -1) ) printf(", not modified: %s)\n", strerror(errno)); else printf(", modified)\n"); } else printf(")\n"); tab = "\t"; } /* Set the uid/gid first, then set the mode. */ if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) { LABEL; printf("%suser (%lu, %lu", tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid); if (uflag) { if (lchown(p->fts_accpath, s->st_uid, -1)) printf(", not modified: %s)\n", strerror(errno)); else printf(", modified)\n"); } else printf(")\n"); tab = "\t"; } if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) { LABEL; printf("%sgid (%lu, %lu", tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid); if (uflag) { if (lchown(p->fts_accpath, -1, s->st_gid)) printf(", not modified: %s)\n", strerror(errno)); else printf(", modified)\n"); } else printf(")\n"); tab = "\t"; } if (s->flags & F_MODE && s->st_mode != (p->fts_statp->st_mode & MBITS)) { if (lflag) { mode_t tmode, mode; tmode = s->st_mode; mode = p->fts_statp->st_mode & MBITS; /* * if none of the suid/sgid/etc bits are set, * then if the mode is a subset of the target, * skip. */ if (!((tmode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) || (mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)))) if ((mode | tmode) == tmode) goto skip; } LABEL; printf("%spermissions (%#lo, %#lo", tab, (u_long)s->st_mode, (u_long)p->fts_statp->st_mode & MBITS); if (uflag) { if (lchmod(p->fts_accpath, s->st_mode)) printf(", not modified: %s)\n", strerror(errno)); else printf(", modified)\n"); } else printf(")\n"); tab = "\t"; skip: ; } if (s->flags & F_NLINK && s->type != F_DIR && s->st_nlink != p->fts_statp->st_nlink) { LABEL; printf("%slink count (%lu, %lu)\n", tab, (u_long)s->st_nlink, (u_long)p->fts_statp->st_nlink); tab = "\t"; } if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) { LABEL; printf("%ssize (%lld, %lld)\n", tab, (long long)s->st_size, (long long)p->fts_statp->st_size); tab = "\t"; } /* * XXX * Since utimes(2) only takes a timeval, there's no point in * comparing the low bits of the timespec nanosecond field. This * will only result in mismatches that we can never fix. * * Doesn't display microsecond differences. */ if (s->flags & F_TIME) { struct timeval tv[2]; struct stat *ps = p->fts_statp; time_t smtime = s->st_mtimespec.tv_sec; #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H) time_t pmtime = ps->st_mtimespec.tv_sec; TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec); TIMESPEC_TO_TIMEVAL(&tv[1], &ps->st_mtimespec); #else time_t pmtime = (time_t)ps->st_mtime; tv[0].tv_sec = smtime; tv[0].tv_usec = 0; tv[1].tv_sec = pmtime; tv[1].tv_usec = 0; #endif if (tv[0].tv_sec != tv[1].tv_sec || tv[0].tv_usec != tv[1].tv_usec) { LABEL; printf("%smodification time (%.24s, ", tab, ctime(&smtime)); printf("%.24s", ctime(&pmtime)); if (tflag) { tv[1] = tv[0]; if (utimes(p->fts_accpath, tv)) printf(", not modified: %s)\n", strerror(errno)); else printf(", modified)\n"); } else printf(")\n"); tab = "\t"; } } #if HAVE_STRUCT_STAT_ST_FLAGS /* * XXX * since lchflags(2) will reset file times, the utimes() above * may have been useless! oh well, we'd rather have correct * flags, rather than times? */ if ((s->flags & F_FLAGS) && ((s->st_flags != p->fts_statp->st_flags) || mflag || iflag)) { if (s->st_flags != p->fts_statp->st_flags) { char *f_s; LABEL; f_s = flags_to_string(s->st_flags, "none"); printf("%sflags (\"%s\" is not ", tab, f_s); free(f_s); f_s = flags_to_string(p->fts_statp->st_flags, "none"); printf("\"%s\"", f_s); free(f_s); } if (uflag) { if (iflag) SETFLAGS(0, CH_MASK); else if (mflag) CLEARFLAGS(0, SP_FLGS); else SETFLAGS(0, (~SP_FLGS & CH_MASK)); } else printf(")\n"); tab = "\t"; } #endif /* HAVE_STRUCT_STAT_ST_FLAGS */ /* * from this point, no more permission checking or whacking * occurs, only checking of stuff like checksums and symlinks. */ afterpermwhack: if (s->flags & F_CKSUM) { if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0) { LABEL; printf("%scksum: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else if (crc(fd, &val, &len)) { close(fd); LABEL; printf("%scksum: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else { close(fd); if (s->cksum != val) { LABEL; printf("%scksum (%lu, %lu)\n", tab, s->cksum, (unsigned long)val); } tab = "\t"; } } #ifndef NO_MD5 if (s->flags & F_MD5) { if ((digestbuf = MD5File(p->fts_accpath, NULL)) == NULL) { LABEL; printf("%s%s: %s: %s\n", tab, MD5KEY, p->fts_accpath, strerror(errno)); tab = "\t"; } else { if (strcmp(s->md5digest, digestbuf)) { LABEL; printf("%s%s (0x%s, 0x%s)\n", tab, MD5KEY, s->md5digest, digestbuf); } tab = "\t"; free(digestbuf); } } #endif /* ! NO_MD5 */ #ifndef NO_RMD160 if (s->flags & F_RMD160) { if ((digestbuf = RMD160File(p->fts_accpath, NULL)) == NULL) { LABEL; printf("%s%s: %s: %s\n", tab, RMD160KEY, p->fts_accpath, strerror(errno)); tab = "\t"; } else { if (strcmp(s->rmd160digest, digestbuf)) { LABEL; printf("%s%s (0x%s, 0x%s)\n", tab, RMD160KEY, s->rmd160digest, digestbuf); } tab = "\t"; free(digestbuf); } } #endif /* ! NO_RMD160 */ #ifndef NO_SHA1 if (s->flags & F_SHA1) { if ((digestbuf = SHA1File(p->fts_accpath, NULL)) == NULL) { LABEL; printf("%s%s: %s: %s\n", tab, SHA1KEY, p->fts_accpath, strerror(errno)); tab = "\t"; } else { if (strcmp(s->sha1digest, digestbuf)) { LABEL; printf("%s%s (0x%s, 0x%s)\n", tab, SHA1KEY, s->sha1digest, digestbuf); } tab = "\t"; free(digestbuf); } } #endif /* ! NO_SHA1 */ #ifndef NO_SHA2 if (s->flags & F_SHA256) { if ((digestbuf = SHA256_File(p->fts_accpath, NULL)) == NULL) { LABEL; printf("%s%s: %s: %s\n", tab, SHA256KEY, p->fts_accpath, strerror(errno)); tab = "\t"; } else { if (strcmp(s->sha256digest, digestbuf)) { LABEL; printf("%s%s (0x%s, 0x%s)\n", tab, SHA256KEY, s->sha256digest, digestbuf); } tab = "\t"; free(digestbuf); } } #ifdef SHA384_BLOCK_LENGTH if (s->flags & F_SHA384) { if ((digestbuf = SHA384_File(p->fts_accpath, NULL)) == NULL) { LABEL; printf("%s%s: %s: %s\n", tab, SHA384KEY, p->fts_accpath, strerror(errno)); tab = "\t"; } else { if (strcmp(s->sha384digest, digestbuf)) { LABEL; printf("%s%s (0x%s, 0x%s)\n", tab, SHA384KEY, s->sha384digest, digestbuf); } tab = "\t"; free(digestbuf); } } #endif if (s->flags & F_SHA512) { if ((digestbuf = SHA512_File(p->fts_accpath, NULL)) == NULL) { LABEL; printf("%s%s: %s: %s\n", tab, SHA512KEY, p->fts_accpath, strerror(errno)); tab = "\t"; } else { if (strcmp(s->sha512digest, digestbuf)) { LABEL; printf("%s%s (0x%s, 0x%s)\n", tab, SHA512KEY, s->sha512digest, digestbuf); } tab = "\t"; free(digestbuf); } } #endif /* ! NO_SHA2 */ if (s->flags & F_SLINK && strcmp(cp = rlink(p->fts_accpath), s->slink)) { LABEL; printf("%slink ref (%s, %s", tab, cp, s->slink); if (uflag) { if ((unlink(p->fts_accpath) == -1) || (symlink(s->slink, p->fts_accpath) == -1) ) printf(", not modified: %s)\n", strerror(errno)); else printf(", modified)\n"); } else printf(")\n"); } return (label); }
static void statf(FTSENT *p) { u_int32_t len, val; int fd, indent; const char *name; #if !defined(NO_MD5) || !defined(NO_RMD160) || !defined(NO_SHA1) || !defined(NO_SHA2) char digestbuf[MAXHASHLEN + 1]; #endif indent = printf("%s%s", S_ISDIR(p->fts_statp->st_mode) ? "" : " ", vispath(p->fts_name)); if (indent > INDENTNAMELEN) indent = MAXLINELEN; else indent += printf("%*s", INDENTNAMELEN - indent, ""); if (!S_ISREG(p->fts_statp->st_mode)) output(&indent, "type=%s", inotype(p->fts_statp->st_mode)); if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid) { if (keys & F_UNAME && (name = user_from_uid(p->fts_statp->st_uid, 1)) != NULL) output(&indent, "uname=%s", name); else /* if (keys & F_UID) */ output(&indent, "uid=%u", p->fts_statp->st_uid); } if (keys & (F_GID | F_GNAME) && p->fts_statp->st_gid != gid) { if (keys & F_GNAME && (name = group_from_gid(p->fts_statp->st_gid, 1)) != NULL) output(&indent, "gname=%s", name); else /* if (keys & F_GID) */ output(&indent, "gid=%u", p->fts_statp->st_gid); } if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode) output(&indent, "mode=%#o", p->fts_statp->st_mode & MBITS); if (keys & F_DEV && (S_ISBLK(p->fts_statp->st_mode) || S_ISCHR(p->fts_statp->st_mode))) output(&indent, "device=%#x", p->fts_statp->st_rdev); if (keys & F_NLINK && p->fts_statp->st_nlink != 1) output(&indent, "nlink=%u", p->fts_statp->st_nlink); if (keys & F_SIZE && S_ISREG(p->fts_statp->st_mode)) output(&indent, "size=%lld", (long long)p->fts_statp->st_size); #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H) if (keys & F_TIME) output(&indent, "time=%ld.%ld", (long)p->fts_statp->st_mtimespec.tv_sec, p->fts_statp->st_mtimespec.tv_nsec); #else output(&indent, "time=%ld.%ld", p->fts_statp->st_mtime, 0); #endif if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 || crc(fd, &val, &len)) mtree_err("%s: %s", p->fts_accpath, strerror(errno)); close(fd); output(&indent, "cksum=%lu", (long)val); } #ifndef NO_MD5 if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) { if (MD5File(p->fts_accpath, digestbuf) == NULL) mtree_err("%s: %s", p->fts_accpath, "MD5File"); output(&indent, "md5=%s", digestbuf); } #endif /* ! NO_MD5 */ #ifndef NO_RMD160 if (keys & F_RMD160 && S_ISREG(p->fts_statp->st_mode)) { if (RMD160File(p->fts_accpath, digestbuf) == NULL) mtree_err("%s: %s", p->fts_accpath, "RMD160File"); output(&indent, "rmd160=%s", digestbuf); } #endif /* ! NO_RMD160 */ #ifndef NO_SHA1 if (keys & F_SHA1 && S_ISREG(p->fts_statp->st_mode)) { if (SHA1File(p->fts_accpath, digestbuf) == NULL) mtree_err("%s: %s", p->fts_accpath, "SHA1File"); output(&indent, "sha1=%s", digestbuf); } #endif /* ! NO_SHA1 */ #ifndef NO_SHA2 if (keys & F_SHA256 && S_ISREG(p->fts_statp->st_mode)) { if (SHA256_File(p->fts_accpath, digestbuf) == NULL) mtree_err("%s: %s", p->fts_accpath, "SHA256_File"); output(&indent, "sha256=%s", digestbuf); } if (keys & F_SHA384 && S_ISREG(p->fts_statp->st_mode)) { if (SHA384_File(p->fts_accpath, digestbuf) == NULL) mtree_err("%s: %s", p->fts_accpath, "SHA384_File"); output(&indent, "sha384=%s", digestbuf); } if (keys & F_SHA512 && S_ISREG(p->fts_statp->st_mode)) { if (SHA512_File(p->fts_accpath, digestbuf) == NULL) mtree_err("%s: %s", p->fts_accpath, "SHA512_File"); output(&indent, "sha512=%s", digestbuf); } #endif /* ! NO_SHA2 */ if (keys & F_SLINK && (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) output(&indent, "link=%s", vispath(rlink(p->fts_accpath))); #if HAVE_STRUCT_STAT_ST_FLAGS if (keys & F_FLAGS && p->fts_statp->st_flags != flags) output(&indent, "flags=%s", flags_to_string(p->fts_statp->st_flags, "none")); #endif putchar('\n'); }
INT16U rtu_data_anlys( int *dest_p, unsigned char *source_p, INT16U data_start_address, INT16U fr_lenth) { unsigned short crc_result, crc_tmp; unsigned char tmp1, tmp2, shift; crc_tmp = *(source_p + fr_lenth-2); // crc 第一字节 crc_tmp = crc_tmp * 256 + *( source_p+fr_lenth-1); // CRC 值 crc_result = crc(source_p, fr_lenth-2); // 计算CRC 值 if ( crc_tmp != crc_result ) // CRC 校验正确 { //hld_reg[0x31]++; return -1; } switch ( *(source_p+1) ) // 功能码 { case READ_COIL: //读取继电器状态 for ( tmp1=0; tmp1<*( source_p+2); tmp1++) { shift = 1; for ( tmp2=0; tmp2<8; tmp2++) { //*( source_p+3)只是第一个字节,后面的字节呢?应该是*( source_p+tmp1+3) *(dest_p+data_start_address+tmp1*8+tmp2) = shift & *( source_p+3); *( source_p+3) >>= 1; } } break; case READ_DI: //读取开关量输入 for ( tmp1=0; tmp1<*( source_p+2); tmp1++) { shift = 1; for (tmp2=0; tmp2<8; tmp2 ++) { //同上,有问题? *(dest_p+data_start_address+tmp1*8+tmp2) = shift & *( source_p+3); *( source_p+3)>>=1; } } break; case READ_HLD_REG: //读取保持寄存器 for ( tmp1=0; tmp1<*( source_p+2); tmp1+=2) { *(dest_p + data_start_address+ tmp1/2)= *( source_p+tmp1+3)*256 + *( source_p+tmp1+4) ; } break ; case 4: //读取模拟量输入 for ( tmp1=0; tmp1<*( source_p+2); tmp1+=2) { *(dest_p + data_start_address+ tmp1/2) = *( source_p+tmp1+3)*256 + *( source_p+tmp1+4) ; } break; case PROTOCOL_EXCEPTION: return -1*PROTOCOL_ERR; //break; default: return -1*PROTOCOL_ERR; // break; } return 0; }
/** Character received - add it to our command. \param c The next character to process. \return Whether end of line was reached. This parser operates character by character, so there's no need for a buffer holding the entire line of G-code. */ uint8_t gcode_parse_char(uint8_t c) { uint8_t checksum_char = c; // uppercase if (c >= 'a' && c <= 'z') c &= ~32; #ifdef SIMULATOR sim_gcode_ch(c); #endif // An asterisk is a quasi-EOL and always ends all fields. if (c == '*') { next_target.seen_semi_comment = next_target.seen_parens_comment = next_target.read_string = 0; } // Skip comments and strings. if (next_target.seen_semi_comment == 0 && next_target.seen_parens_comment == 0 && next_target.read_string == 0 ) { // Check if the field has ended. Either by a new field, space or EOL. if (last_field && (c < '0' || c > '9') && c != '.') { switch (last_field) { case 'G': next_target.G = read_digit.mantissa; if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_uint8(next_target.G); break; case 'M': next_target.M = read_digit.mantissa; #ifdef SD if (next_target.M == 23) { // SD card command with a filename. next_target.read_string = 1; // Reset by string handler or EOL. str_buf_ptr = 0; last_field = 0; } #endif if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_uint8(next_target.M); break; case 'X': if (next_target.option_inches) next_target.target.axis[X] = decfloat_to_int(&read_digit, 25400); else next_target.target.axis[X] = decfloat_to_int(&read_digit, 1000); if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_int32(next_target.target.axis[X]); break; case 'Y': if (next_target.option_inches) next_target.target.axis[Y] = decfloat_to_int(&read_digit, 25400); else next_target.target.axis[Y] = decfloat_to_int(&read_digit, 1000); if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_int32(next_target.target.axis[Y]); break; case 'Z': if (next_target.option_inches) next_target.target.axis[Z] = decfloat_to_int(&read_digit, 25400); else next_target.target.axis[Z] = decfloat_to_int(&read_digit, 1000); if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_int32(next_target.target.axis[Z]); break; case 'E': if (next_target.option_inches) next_target.target.axis[E] = decfloat_to_int(&read_digit, 25400); else next_target.target.axis[E] = decfloat_to_int(&read_digit, 1000); if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_int32(next_target.target.axis[E]); break; case 'F': // just use raw integer, we need move distance and n_steps to convert it to a useful value, so wait until we have those to convert it if (next_target.option_inches) next_target.target.F = decfloat_to_int(&read_digit, 25400); else next_target.target.F = decfloat_to_int(&read_digit, 1); if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_uint32(next_target.target.F); break; case 'S': // if this is temperature, multiply by 4 to convert to quarter-degree units // cosmetically this should be done in the temperature section, // but it takes less code, less memory and loses no precision if we do it here instead if ((next_target.M == 104) || (next_target.M == 109) || (next_target.M == 140)) next_target.S = decfloat_to_int(&read_digit, 4); // if this is heater PID stuff, multiply by PID_SCALE because we divide by PID_SCALE later on else if ((next_target.M >= 130) && (next_target.M <= 132)) next_target.S = decfloat_to_int(&read_digit, PID_SCALE); else next_target.S = decfloat_to_int(&read_digit, 1); if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_int32(next_target.S); break; case 'P': next_target.P = decfloat_to_int(&read_digit, 1); if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_uint16(next_target.P); break; case 'T': next_target.T = read_digit.mantissa; if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_uint8(next_target.T); break; case 'N': next_target.N = decfloat_to_int(&read_digit, 1); if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_uint32(next_target.N); break; case '*': next_target.checksum_read = decfloat_to_int(&read_digit, 1); if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serwrite_uint8(next_target.checksum_read); break; } } // new field? if ((c >= 'A' && c <= 'Z') || c == '*') { last_field = c; read_digit.sign = read_digit.mantissa = read_digit.exponent = 0; if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serial_writechar(c); } // process character // Can't do ranges in switch..case, so process actual digits here. // Do it early, as there are many more digits than characters expected. if (c >= '0' && c <= '9') { if (read_digit.exponent < DECFLOAT_EXP_MAX + 1 && ((next_target.option_inches == 0 && read_digit.mantissa < DECFLOAT_MANT_MM_MAX) || (next_target.option_inches && read_digit.mantissa < DECFLOAT_MANT_IN_MAX))) { // this is simply mantissa = (mantissa * 10) + atoi(c) in different clothes read_digit.mantissa = (read_digit.mantissa << 3) + (read_digit.mantissa << 1) + (c - '0'); if (read_digit.exponent) read_digit.exponent++; } } else { switch (c) { // Each currently known command is either G or M, so preserve // previous G/M unless a new one has appeared. // FIXME: same for T command case 'G': next_target.seen_G = 1; next_target.seen_M = 0; next_target.M = 0; break; case 'M': next_target.seen_M = 1; next_target.seen_G = 0; next_target.G = 0; break; case 'X': next_target.seen_X = 1; break; case 'Y': next_target.seen_Y = 1; break; case 'Z': next_target.seen_Z = 1; break; case 'E': next_target.seen_E = 1; break; case 'F': next_target.seen_F = 1; break; case 'S': next_target.seen_S = 1; break; case 'P': next_target.seen_P = 1; break; case 'T': next_target.seen_T = 1; break; case 'N': next_target.seen_N = 1; break; case '*': next_target.seen_checksum = 1; break; // comments case ';': next_target.seen_semi_comment = 1; // Reset by EOL. break; case '(': next_target.seen_parens_comment = 1; // Reset by ')' or EOL. break; // now for some numeracy case '-': read_digit.sign = 1; // force sign to be at start of number, so 1-2 = -2 instead of -12 read_digit.exponent = 0; read_digit.mantissa = 0; break; case '.': if (read_digit.exponent == 0) read_digit.exponent = 1; break; #ifdef DEBUG case ' ': case '\t': case 10: case 13: // ignore break; #endif default: #ifdef DEBUG // invalid serial_writechar('?'); serial_writechar(c); serial_writechar('?'); #endif break; } } } else if ( next_target.seen_parens_comment == 1 && c == ')') next_target.seen_parens_comment = 0; // recognize stuff after a (comment) if (next_target.seen_checksum == 0) next_target.checksum_calculated = crc(next_target.checksum_calculated, checksum_char); // end of line if ((c == 10) || (c == 13)) { if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) serial_writechar(c); // Assume G1 for unspecified movements. if ( ! next_target.seen_G && ! next_target.seen_M && ! next_target.seen_T && (next_target.seen_X || next_target.seen_Y || next_target.seen_Z || next_target.seen_E || next_target.seen_F)) { next_target.seen_G = 1; next_target.G = 1; } if ( #ifdef REQUIRE_LINENUMBER ((next_target.N >= next_target.N_expected) && (next_target.seen_N == 1)) || (next_target.seen_M && (next_target.M == 110)) #else 1 #endif ) { if ( #ifdef REQUIRE_CHECKSUM ((next_target.checksum_calculated == next_target.checksum_read) && (next_target.seen_checksum == 1)) #else ((next_target.checksum_calculated == next_target.checksum_read) || (next_target.seen_checksum == 0)) #endif ) { // process process_gcode_command(); // Acknowledgement ("ok") is sent in the main loop, in mendel.c. // expect next line number if (next_target.seen_N == 1) next_target.N_expected = next_target.N + 1; } else { sersendf_P(PSTR("rs N%ld Expected checksum %d\n"), next_target.N_expected, next_target.checksum_calculated); // request_resend(); } } else { sersendf_P(PSTR("rs N%ld Expected line number %ld\n"), next_target.N_expected, next_target.N_expected); // request_resend(); } // reset variables next_target.seen_X = next_target.seen_Y = next_target.seen_Z = \ next_target.seen_E = next_target.seen_F = next_target.seen_S = \ next_target.seen_P = next_target.seen_T = next_target.seen_N = \ next_target.seen_G = next_target.seen_M = next_target.seen_checksum = \ next_target.seen_semi_comment = next_target.seen_parens_comment = \ next_target.read_string = next_target.checksum_read = \ next_target.checksum_calculated = 0; last_field = 0; read_digit.sign = read_digit.mantissa = read_digit.exponent = 0; if (next_target.option_all_relative) { next_target.target.axis[X] = next_target.target.axis[Y] = next_target.target.axis[Z] = 0; } if (next_target.option_all_relative || next_target.option_e_relative) { next_target.target.axis[E] = 0; } return 1; } #ifdef SD // Handle string reading. After checking for EOL. if (next_target.read_string) { if (c == ' ') { if (str_buf_ptr) next_target.read_string = 0; } else if (str_buf_ptr < STR_BUF_LEN) { gcode_str_buf[str_buf_ptr] = c; str_buf_ptr++; gcode_str_buf[str_buf_ptr] = '\0'; } } #endif /* SD */ return 0; }
static void handle_data(unsigned char *data, ssize_t len) { ssize_t i; static unsigned char buf[BUFSIZE]; static unsigned int idx = 0; static int datactr = 0; static int8_t pseqno; static uint8_t seqno; uint8_t crc8; int16_t temp; uint16_t rh; FILE *templog = NULL; char filename[PATH_MAX]; #ifdef USE_DATABASE char query[128]; #endif struct tm *tmp; time_t t; char timestr[64]; static enum { STX1, STX2, ADDR, TYPE, DATA, CRC } state = STX1; for (i = 0; i < len; ++i) { /* Make sure that we don't read more data than fits in the read buffer. * If too many bytes are read we reset the state machine and wait for * another message. */ if (idx >= sizeof(buf)) { state = STX1; idx = 0; } switch (state) { case STX1: if (data[i] == STX) { memset(&buf, 0, sizeof(buf)); buf[idx++] = data[i]; state = STX2; } break; case STX2: if (data[i] == STX) { buf[idx++] = data[i]; state = ADDR; } break; case ADDR: buf[idx++] = data[i]; seqno = (data[i] & 0xf0) >> 4; state = TYPE; break; case TYPE: buf[idx++] = data[i]; datactr = 0; state = DATA; break; case DATA: buf[idx++] = data[i]; if (++datactr == 4) state = CRC; break; case CRC: buf[idx++] = data[i]; crc8 = crc(buf, idx-1); if (crc8 == buf[idx-1]) { temp = (buf[4] << 8) | buf[5]; rh = (buf[6] << 8) | buf[7]; //printf("Temperature: %0.1f degC, RH = %0.1f%%\nSeqno = %u\n", (float)temp/10.0f, (float)rh/10.0f, seqno); t = time(NULL); tmp = localtime(&t); if (tmp != NULL) { strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", tmp); } /* Print the long-term log file */ snprintf(filename, PATH_MAX, "templog_%u.csv", buf[2] & 0x0f); templog = fopen(filename, "a+"); if (templog) { if (seqno != pseqno) { printf("%s: %02u: Temperature: %0.1f degC, RH = %0.1f%%, seqno = %u\n", timestr, buf[2] & 0x0f, (float)temp/10.0f, (float)rh/10.0f, seqno); fprintf(templog, "%s,%02u,%02u,%0.1f,%0.1f\n", timestr, buf[2] & 0x0f, seqno, (float)temp/10.0f, (float)rh/10.0f); fclose(templog); #ifdef USE_DATABASE snprintf(query, sizeof(query), "INSERT INTO templog VALUES(%u, '%s', %0.1f, %0.1f)", buf[2] & 0x0f, timestr, (float)temp/10.0f, (float)rh/10.0f); if (mysql_query(con, query)) printf("Failed to insert into database\n"); #endif pseqno = seqno; } } else { printf("Failed to open '%s' for writing data\n", filename); } /* Print the last known value to file in a format that Domoticz understands */ snprintf(filename, PATH_MAX, "temp_rh_current_%u.csv", buf[2] & 0x0f); templog = fopen(filename, "w+"); if (templog) { fprintf(templog, "%0.1f;%0.1f\n", (float)temp/10.0f, (float)rh/10.0f); fclose(templog); } else { printf("Failed to open '%s' for writing data. Errno = %d\n", filename, errno); } } else { printf("Message CRC failed\n"); } state = STX1; idx = 0; break; } } }
static void statf(int indent, FTSENT *p) { struct group *gr; struct passwd *pw; u_int32_t len, val; int fd, offset; char *name, *escaped_name; size_t esc_len; esc_len = p->fts_namelen * 4 + 1; escaped_name = malloc(esc_len); if (escaped_name == NULL) error("statf: %s", strerror(errno)); strnvis(escaped_name, p->fts_name, esc_len, VIS_WHITE | VIS_OCTAL | VIS_GLOB); if (iflag || S_ISDIR(p->fts_statp->st_mode)) offset = printf("%*s%s", indent, "", escaped_name); else offset = printf("%*s %s", indent, "", escaped_name); free(escaped_name); if (offset > (INDENTNAMELEN + indent)) offset = MAXLINELEN; else offset += printf("%*s", (INDENTNAMELEN + indent) - offset, ""); if (!S_ISREG(p->fts_statp->st_mode) && !dflag) output(indent, &offset, "type=%s", inotype(p->fts_statp->st_mode)); if (p->fts_statp->st_uid != uid) { if (keys & F_UNAME) { if ((pw = getpwuid(p->fts_statp->st_uid)) != NULL) { output(indent, &offset, "uname=%s", pw->pw_name); } else { error("could not get uname for uid=%u", p->fts_statp->st_uid); } } if (keys & F_UID) output(indent, &offset, "uid=%u", p->fts_statp->st_uid); } if (p->fts_statp->st_gid != gid) { if (keys & F_GNAME) { if ((gr = getgrgid(p->fts_statp->st_gid)) != NULL) { output(indent, &offset, "gname=%s", gr->gr_name); } else { error("could not get gname for gid=%u", p->fts_statp->st_gid); } } if (keys & F_GID) output(indent, &offset, "gid=%u", p->fts_statp->st_gid); } if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode) output(indent, &offset, "mode=%#o", p->fts_statp->st_mode & MBITS); if (keys & F_NLINK && p->fts_statp->st_nlink != 1) output(indent, &offset, "nlink=%u", p->fts_statp->st_nlink); if (keys & F_SIZE && S_ISREG(p->fts_statp->st_mode)) output(indent, &offset, "size=%qd", p->fts_statp->st_size); if (keys & F_TIME) output(indent, &offset, "time=%lld.%ld", (long long)p->fts_statp->st_mtimespec.tv_sec, p->fts_statp->st_mtimespec.tv_nsec); if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) { if ((fd = open(p->fts_accpath, MTREE_O_FLAGS, 0)) < 0 || crc(fd, &val, &len)) error("%s: %s", p->fts_accpath, strerror(errno)); (void)close(fd); output(indent, &offset, "cksum=%lu", val); } if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) { char *md5digest, buf[MD5_DIGEST_STRING_LENGTH]; md5digest = MD5File(p->fts_accpath,buf); if (!md5digest) error("%s: %s", p->fts_accpath, strerror(errno)); else output(indent, &offset, "md5digest=%s", md5digest); } if (keys & F_RMD160 && S_ISREG(p->fts_statp->st_mode)) { char *rmd160digest, buf[RMD160_DIGEST_STRING_LENGTH]; rmd160digest = RMD160File(p->fts_accpath,buf); if (!rmd160digest) error("%s: %s", p->fts_accpath, strerror(errno)); else output(indent, &offset, "rmd160digest=%s", rmd160digest); } if (keys & F_SHA1 && S_ISREG(p->fts_statp->st_mode)) { char *sha1digest, buf[SHA1_DIGEST_STRING_LENGTH]; sha1digest = SHA1File(p->fts_accpath,buf); if (!sha1digest) error("%s: %s", p->fts_accpath, strerror(errno)); else output(indent, &offset, "sha1digest=%s", sha1digest); } if (keys & F_SHA256 && S_ISREG(p->fts_statp->st_mode)) { char *sha256digest, buf[SHA256_DIGEST_STRING_LENGTH]; sha256digest = SHA256File(p->fts_accpath,buf); if (!sha256digest) error("%s: %s", p->fts_accpath, strerror(errno)); else output(indent, &offset, "sha256digest=%s", sha256digest); } if (keys & F_SLINK && (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { name = rlink(p->fts_accpath); esc_len = strlen(name) * 4 + 1; escaped_name = malloc(esc_len); if (escaped_name == NULL) error("statf: %s", strerror(errno)); strnvis(escaped_name, name, esc_len, VIS_WHITE | VIS_OCTAL); output(indent, &offset, "link=%s", escaped_name); free(escaped_name); } if (keys & F_FLAGS && !S_ISLNK(p->fts_statp->st_mode)) { char *file_flags; file_flags = fflagstostr(p->fts_statp->st_flags); if (file_flags == NULL) error("%s", strerror(errno)); if (*file_flags != '\0') output(indent, &offset, "flags=%s", file_flags); else output(indent, &offset, "flags=none"); free(file_flags); } (void)putchar('\n'); }
int StopNWait::sendMsg (MSG_TYPE msg, ACK_TYPE *slast) { ackbuff ack; msgbuff msg_temp; ACK_TYPE rnext = !(*slast); struct msqid_ds msg_info; #ifdef MANUAL_ERROR float prob_error; #endif signal(SIGALRM, alarm_dummy); ack.mtype = 1; msg_temp.mtype = 1; // append the slast msg_temp.msg = msg << SLAST_SIZE; msg_temp.msg += *slast; // apply theoretical error and CRC msg_temp.msg = msg_temp.msg << CRC_SIZE; msg_temp.msg += crc(msg_temp.msg); #ifdef AUTO_ERROR msg_temp.msg = apply_error(msg_temp.msg, PROB_ERROR); #endif #ifdef MANUAL_ERROR cout << "Error chance (0-1): "; cin >> prob_error; msg_temp.msg = apply_error(msg_temp.msg, prob_error); #endif // send the package to the transmition mean buffer cout << "Sending message: " << msg_temp.msg << endl; if (msgsnd(inputChannelId, &msg_temp, sizeof(msgbuff), 0) < 0) { cout << "Error sending package through the msg queue: " << strerror(errno) << endl; exit(1); } // clean the ack buffer, if filled with old ack's if (timeout > 0) { msgctl(outputChannelId, IPC_STAT, &msg_info); if (msg_info.msg_qnum > 0) { cout << "ack flushed: " << ack.ack << " - number or msgs: " << msg_info.msg_qnum << endl; if (msgrcv(outputChannelId, &ack, sizeof(ackbuff), 0, 0) < 0) { cout << "Message Queue error: " << strerror(errno) << endl; exit(1); } } timeout = 0; } // wait for the ack or the timeout cout << "Waiting for the acknowledge" << endl; alarm(TIMEOUT); if (msgrcv(outputChannelId, &ack, sizeof(ackbuff), 0, 0) < 0) if (errno != EINTR){ cout << "Message Queue error: " << strerror(errno) << endl; exit(1); } cout << "ack received: " << ack.ack << endl; // treat the result of an ack if (alarm(0) > 0) { // crc on the ack if (crc(ack.ack) != 0) cout << "Acknowledge failed on CRC check" << endl; // extract slast from the ack and check it else if (EXTRACT_RNEXT(ack.ack) != rnext) cout << "Received wrong acknowledge - expected " << rnext << " but instead " << (EXTRACT_RNEXT(ack.ack)) << endl; else { cout << "Received correct acknowledge" << endl; // update slast *slast = rnext; return true; } } // treat the result of a timeout else { cout << "Timeout!" << endl; timeout++; } return false; }
CBuffer2* CBuffer2::Fetch( CBuffer2** ppRecvBuffer, DWORD dwBytes, CRC32* pcrc ) { crc( pcrc ); // m_pcrc m_pTail += dwBytes; ASSERT( m_pTail <= m_lpBufMax ); int nRemnant; LPBYTE ptr = GetReadableBuffer( &nRemnant ); CBuffer2* pOld = NULL, *pBuffer; u_long uPacketSize; DWORD dwCrc, dwDataSize; byte digest[4]; u_long uHdrSize = CBuffer2::GetHdrSize( (BOOL)pcrc ); while( 1 ) { if( nRemnant < (int)( uHdrSize ) ) { if( cb > 0 ) { pOld = *ppRecvBuffer; pOld->m_pTail -= nRemnant; // remove remnant from old buffer pBuffer = new CBuffer2; ASSERT( pBuffer->m_pTail + nRemnant <= pBuffer->m_lpBufMax ); memcpy( pBuffer->m_pTail, ptr, nRemnant ); pBuffer->m_pTail += nRemnant; *ppRecvBuffer = pBuffer; } return pOld; } else { if( pcrc ) { dwCrc = *(UNALIGNED LPDWORD)ptr; dwDataSize = ntohs( *(UNALIGNED LPWORD)( ptr + sizeof(DWORD) ) ) -2; pcrc->Restart(); pcrc->Update( (const byte*)( &dwDataSize ), sizeof(DWORD) ); pcrc->Final( digest ); if( *(UNALIGNED LPDWORD)digest != dwCrc ) { WSASetLastError( ERROR_BAD_NET_NAME ); return NULL; } dwCrc = *(UNALIGNED LPDWORD)( ptr + sizeof(DWORD) + sizeof(WORD) ); uPacketSize = uHdrSize + dwDataSize; } else { uPacketSize = uHdrSize + ntohs( *(UNALIGNED LPWORD)ptr ) - 2; } if( nRemnant < (int)( uPacketSize ) ) { if( (int)( uPacketSize ) > (*ppRecvBuffer)->GetSize() ) { pOld = *ppRecvBuffer; pBuffer = new CBuffer2( uPacketSize ); } else { if( (*ppRecvBuffer)->cb > 0 ) { pOld = *ppRecvBuffer; pBuffer = new CBuffer2; } } if( pOld ) { ASSERT( pBuffer->m_pTail + nRemnant <= pBuffer->m_lpBufMax ); memcpy( pBuffer->m_pTail, ptr, nRemnant ); // if( nRemnant > 0 ) // { // ASSERT( CBuffer::IsHeader( *ptr ) ); // } pBuffer->m_pTail += nRemnant; *ppRecvBuffer = pBuffer; } return pOld; } else // completion { if( pcrc ) { pcrc->Restart(); pcrc->Update( (const byte*)( ptr + uHdrSize ), dwDataSize ); pcrc->Final( digest ); if( *(UNALIGNED LPDWORD)digest != dwCrc ) { WSASetLastError( ERROR_BAD_NET_NAME ); return NULL; } } (*ppRecvBuffer)->cb++; nRemnant -= ( uPacketSize ); ptr += ( uPacketSize ); } } } return NULL; }
uint32_t crc(const T& t) { return crc(&t, sizeof(t)); }
int compare(char *name, NODE *s, FTSENT *p) { u_int32_t len, val; int fd, label; char *cp, *tab = ""; label = 0; switch(s->type) { case F_BLOCK: if (!S_ISBLK(p->fts_statp->st_mode)) goto typeerr; break; case F_CHAR: if (!S_ISCHR(p->fts_statp->st_mode)) goto typeerr; break; case F_DIR: if (!S_ISDIR(p->fts_statp->st_mode)) goto typeerr; break; case F_FIFO: if (!S_ISFIFO(p->fts_statp->st_mode)) goto typeerr; break; case F_FILE: if (!S_ISREG(p->fts_statp->st_mode)) goto typeerr; break; case F_LINK: if (!S_ISLNK(p->fts_statp->st_mode)) goto typeerr; break; case F_SOCK: if (!S_ISSOCK(p->fts_statp->st_mode)) { typeerr: LABEL; (void)printf("\ttype (%s, %s)\n", ftype(s->type), inotype(p->fts_statp->st_mode)); } break; } /* Set the uid/gid first, then set the mode. */ if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) { LABEL; (void)printf("%suser (%u, %u", tab, s->st_uid, p->fts_statp->st_uid); if (uflag) if (chown(p->fts_accpath, s->st_uid, -1)) (void)printf(", not modified: %s)\n", strerror(errno)); else (void)printf(", modified)\n"); else (void)printf(")\n"); tab = "\t"; } if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) { LABEL; (void)printf("%sgid (%u, %u", tab, s->st_gid, p->fts_statp->st_gid); if (uflag) if (chown(p->fts_accpath, -1, s->st_gid)) (void)printf(", not modified: %s)\n", strerror(errno)); else (void)printf(", modified)\n"); else (void)printf(")\n"); tab = "\t"; } if (s->flags & F_MODE && s->st_mode != (p->fts_statp->st_mode & MBITS)) { if (lflag) { mode_t tmode, mode; tmode = s->st_mode; mode = p->fts_statp->st_mode & MBITS; /* * if none of the suid/sgid/etc bits are set, * then if the mode is a subset of the target, * skip. */ if (!((tmode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) || (mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)))) if ((mode | tmode) == tmode) goto skip; } LABEL; (void)printf("%spermissions (%#o, %#o", tab, s->st_mode, p->fts_statp->st_mode & MBITS); if (uflag) if (chmod(p->fts_accpath, s->st_mode)) (void)printf(", not modified: %s)\n", strerror(errno)); else (void)printf(", modified)\n"); else (void)printf(")\n"); tab = "\t"; skip: ; } if (s->flags & F_NLINK && s->type != F_DIR && s->st_nlink != p->fts_statp->st_nlink) { LABEL; (void)printf("%slink count (%u, %u)\n", tab, s->st_nlink, p->fts_statp->st_nlink); tab = "\t"; } if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) { LABEL; (void)printf("%ssize (%qd, %qd)\n", tab, s->st_size, p->fts_statp->st_size); tab = "\t"; } /* * XXX * Since utimes(2) only takes a timeval, there's no point in * comparing the low bits of the timespec nanosecond field. This * will only result in mismatches that we can never fix. * * Doesn't display microsecond differences. */ if (s->flags & F_TIME) { struct timeval tv[2]; TIMESPEC_TO_TIMEVAL(&tv[0], &s->st_mtimespec); TIMESPEC_TO_TIMEVAL(&tv[1], &p->fts_statp->st_mtimespec); if (tv[0].tv_sec != tv[1].tv_sec || tv[0].tv_usec != tv[1].tv_usec) { LABEL; (void)printf("%smodification time (%.24s, ", tab, ctime(&s->st_mtimespec.tv_sec)); (void)printf("%.24s", ctime(&p->fts_statp->st_mtimespec.tv_sec)); if (tflag) { tv[1] = tv[0]; if (utimes(p->fts_accpath, tv)) (void)printf(", not modified: %s)\n", strerror(errno)); else (void)printf(", modified)\n"); } else (void)printf(")\n"); tab = "\t"; } } if (s->flags & F_CKSUM) { if ((fd = open(p->fts_accpath, MTREE_O_FLAGS, 0)) < 0) { LABEL; (void)printf("%scksum: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else if (crc(fd, &val, &len)) { (void)close(fd); LABEL; (void)printf("%scksum: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else { (void)close(fd); if (s->cksum != val) { LABEL; (void)printf("%scksum (%u, %u)\n", tab, s->cksum, val); } tab = "\t"; } } if (s->flags & F_MD5) { char *new_digest, buf[MD5_DIGEST_STRING_LENGTH]; new_digest = MD5File(p->fts_accpath, buf); if (!new_digest) { LABEL; printf("%sMD5File: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else if (strcmp(new_digest, s->md5digest)) { LABEL; printf("%sMD5 (%s, %s)\n", tab, s->md5digest, new_digest); tab = "\t"; } } if (s->flags & F_RMD160) { char *new_digest, buf[RMD160_DIGEST_STRING_LENGTH]; new_digest = RMD160File(p->fts_accpath, buf); if (!new_digest) { LABEL; printf("%sRMD160File: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else if (strcmp(new_digest, s->rmd160digest)) { LABEL; printf("%sRMD160 (%s, %s)\n", tab, s->rmd160digest, new_digest); tab = "\t"; } } if (s->flags & F_SHA1) { char *new_digest, buf[SHA1_DIGEST_STRING_LENGTH]; new_digest = SHA1File(p->fts_accpath, buf); if (!new_digest) { LABEL; printf("%sSHA1File: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else if (strcmp(new_digest, s->sha1digest)) { LABEL; printf("%sSHA1 (%s, %s)\n", tab, s->sha1digest, new_digest); tab = "\t"; } } if (s->flags & F_SHA256) { char *new_digest, buf[SHA256_DIGEST_STRING_LENGTH]; new_digest = SHA256File(p->fts_accpath, buf); if (!new_digest) { LABEL; printf("%sSHA256File: %s: %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; } else if (strcmp(new_digest, s->sha256digest)) { LABEL; printf("%sSHA256 (%s, %s)\n", tab, s->sha256digest, new_digest); tab = "\t"; } } if (s->flags & F_SLINK && strcmp(cp = rlink(name), s->slink)) { LABEL; (void)printf("%slink ref (%s, %s)\n", tab, cp, s->slink); } if (s->flags & F_FLAGS && s->file_flags != p->fts_statp->st_flags) { char *db_flags = NULL; char *cur_flags = NULL; if ((db_flags = fflagstostr(s->file_flags)) == NULL || (cur_flags = fflagstostr(p->fts_statp->st_flags)) == NULL) { LABEL; (void)printf("%sflags: %s %s\n", tab, p->fts_accpath, strerror(errno)); tab = "\t"; free(db_flags); free(cur_flags); } else { LABEL; REPLACE_COMMA(db_flags); REPLACE_COMMA(cur_flags); printf("%sflags (%s, %s", tab, (*db_flags == '\0') ? "-" : db_flags, (*cur_flags == '\0') ? "-" : cur_flags); tab = "\t"; if (uflag) if (chflags(p->fts_accpath, s->file_flags)) (void)printf(", not modified: %s)\n", strerror(errno)); else (void)printf(", modified)\n"); else (void)printf(")\n"); tab = "\t"; free(db_flags); free(cur_flags); } } return (label); }
uint32_t string_crc(const char* s) { return crc(s, strlen(s)); }
/******************************************************************* * FUNCTION: CommandParse * AUTHOR = TRAMPAS STERN * FILE = command.c * DATE = 1/25/2004 4:03:03 PM * * PARAMETERS: Takes the command line string * * DESCRIPTION: parses the command line and returns Command ID * * RETURNS: Command ID, and * * *******************************************************************/ UINT CommandParse(CHAR *str) { CHAR *ptr; CHAR *ptr2; UINT i; CHAR cmd[MAX_STRING]; CHAR buff[MAX_CMD_LENGTH]; CHAR argv[MAX_ARGS][MAX_ARG_LENGTH]; //CHAR *ptrArgv[MAX_ARGS]; UINT numArgs; //first we need find command and arguments ptr=strchr(str,' '); //find first char if (ptr==0) { //we have two options, frist whole thing is command //second bad command if(strlen(str)>0) ptr=str+strlen(str); else return 0; //bad command } //copy string to command buffer. i=0; ptr2=str; while(ptr!=0 && ptr!=ptr2 && i<(MAX_CMD_LENGTH-1)) { buff[i++]=*ptr2++; } buff[i]=0; //now buff contains the command let's get the args numArgs=0; while(*ptr!=0 && *ptr==' ') ptr++; //increment pointer past ' ' if (*ptr!=0) { ptr2=strchr(ptr,' '); if (ptr2==0) { //we have two options, frist whole thing is command //second bad command if(strlen(ptr)>0) ptr2=ptr+strlen(ptr); } while(ptr2!=0 && numArgs<MAX_ARGS) { int j; j=0; while (ptr2!=ptr && j<(MAX_ARG_LENGTH-1)) { argv[numArgs][j++]=*ptr++; } argv[numArgs][j++]=0; numArgs++; ptr2=0; if (*ptr!=0) { while(*ptr!=0 && *ptr==' ') ptr++; //increment pointer past ' ' ptr2=strchr(ptr,' '); if (ptr2==0) { //we have two options, frist whole thing is command //second bad command if(strlen(ptr)>0) ptr2=ptr+strlen(ptr); } } } } /* for(i=0; i<MAX_ARGS; i++) { ptrArgv[i]=argv[i]; } //now let's parse the command for(i=1; i<NUM_COMMANDS; i++) { if (strcmp((const char *)buff,(const char *)strCommands[i])==0) return (*ptrCommands[i])(numArgs,ptrArgv); } */ sprintf(cmd,"exit"); if (strcmp(buff,cmd)==0) { CommandExit=1; } sprintf(cmd,"ver"); if (strcmp(buff,cmd)==0) { printf("software v%d.%02d",VER_MAJOR,VER_MINOR); } sprintf(cmd,"hwver"); if (strcmp(buff,cmd)==0) { printf("hardware v%d",HW_VER); } sprintf(cmd,"logb"); if (strcmp(buff,cmd)==0) { datalog_bin(); } sprintf(cmd,"vpwmon"); if (strcmp(buff,cmd)==0) { vpw_montior(); } sprintf(cmd,"log"); if (strcmp(buff,cmd)==0) { datalog(); } sprintf(cmd,"pwmhigh"); if (strcmp(buff,cmd)==0) { output_high(PIN_F5); } sprintf(cmd,"pwmlow"); if (strcmp(buff,cmd)==0) { output_low(PIN_F5); } sprintf(cmd,"pwmmon"); if (strcmp(buff,cmd)==0) { pwm_monitor(); } sprintf(cmd,"pwmread"); if (strcmp(buff,cmd)==0) { while(!kbhit()) { printf("PWM bus=%d\n\r",PWM_IN); } getch2(); } sprintf(cmd,"5baud"); if (strcmp(buff,cmd)==0) { UBYTE keys[2]; printf("%lu ",iso_5baud(keys,2,0x33)); printf("%X %X\n\r",keys[0],keys[1]); } sprintf(cmd,"crc"); if (strcmp(buff,cmd)==0) { UBYTE data[20]; UBYTE temp; for (i=0; i<numArgs; i++) { //we need to parse ASCII temp=ascii2hex(argv[i]); data[i]=temp; } for (temp=0; temp<numArgs; temp++) { printf("%X ",data[temp]); } printf("\n\r"); fprintf(STDIN,"CRC %X\n\r",crc(data,numArgs)); } sprintf(cmd,"csum"); if (strcmp(buff,cmd)==0) { UBYTE data[20]; UBYTE temp; for (i=0; i<numArgs; i++) { //we need to parse ASCII temp=ascii2hex(argv[i]); data[i]=temp; } for (temp=0; temp<numArgs; temp++) { printf("%X ",data[temp]); } printf("\n\r"); fprintf(STDIN,"CheckSum %X\n\r",checksum(data,numArgs)); } sprintf(cmd, "vagcom"); if (strcmp(buff,cmd)==0) { //we need to monitor the serial port // when port goes high drive k-line accordingly } sprintf(cmd, "vag"); if (strcmp(buff,cmd)==0) { UBYTE data[60]; UBYTE resp[20]; UBYTE ret; UBYTE i; UBYTE block; //first lets init communications ret=iso_5baud(data,2,0x01); data[2]=0; while(data[2]!=0x09) { //get block from ECM ret=vagGetBlock(data,60); for(i=0; i<ret; i++) { printf("%X ",data[i]); } printf("\n\r"); //now build ack block=data[1]+1; resp[0]=data[1]+1; resp[1]=0x09; vagPutBlock(resp,2); block++; } ret=vagGetBlock(data,60); for(i=0; i<ret; i++) { printf("%X ",data[i]); } printf("\n\r"); block=data[1]+1; printf("Test block "); for(i=0; i<numArgs; i++) { resp[i+1]=ascii2hex(argv[i]); printf("%X ",resp[i+1]); } printf("\n\r"); //now lets see what happens if we send a block request for block 02 resp[0]=block; //resp[1]=code; vagPutBlock(resp,numArgs+1); data[2]=0; while(data[2]!=0x09) { //get block from ECM ret=vagGetBlock(data,60); for(i=0; i<ret; i++) { printf("%X ",data[i]); } printf("\n\r"); //now build ack block=data[1]+1; resp[0]=data[1]+1; resp[1]=0x09; vagPutBlock(resp,2); block++; } } sprintf(cmd,"isosend"); if (strcmp(buff,cmd)==0) { UBYTE data[60]; UBYTE resp[20]; UBYTE i; UBYTE temp; printf("hit key to stop\n\r"); //we need to copy args to data for (i=0; i<numArgs; i++) { //we need to parse ASCII temp=ascii2hex(argv[i]); data[i]=temp; } //printf("\n\r"); while(!kbhit()) { temp=iso_send(resp, 60, data, numArgs,0x33); printf("response %u\n\r",temp); for (i=0; i<temp; i++) { printf("%X ",resp[i]); } printf("\n\r"); } while(kbhit()) getch2(); } sprintf(cmd,"pwmsend"); if (strcmp(buff,cmd)==0) { UBYTE data[60]; UBYTE resp[20]; UBYTE i; UBYTE temp; printf("hit key to stop\n\r"); //we need to copy args to data for (i=0; i<numArgs; i++) { //we need to parse ASCII temp=ascii2hex(argv[i]); data[i]=temp; //printf("args %x %s\n\r",temp,argv[i]); } //printf("\n\r"); while(!kbhit()) { temp=pwm_send(resp, 60, data, numArgs); printf("response %u\n\r",temp); for (i=0; i<temp; i++) { printf("%X ",resp[i]); } printf("\n\r"); } while(kbhit()) getch2(); } /* sprintf(cmd,"flashread"); if (strcmp(buff,cmd)==0) { UDWORD addr; addr=atoi32(argv[0]); printf("*%lu=%X\n\r",addr,flash_read(addr)); } sprintf(cmd,"flashbufread"); if (strcmp(buff,cmd)==0) { UDWORD addr; addr=atoi32(argv[0]); printf("*%lu=%X\n\r",addr,flash_buf_read(addr)); } */ sprintf(cmd,"flasherase"); if (strcmp(buff,cmd)==0) { flash_erase(); printf("Done\n\r"); } /* sprintf(cmd,"flashput"); if (strcmp(buff,cmd)==0) { UDWORD addr; UBYTE data; addr=atoi32(argv[0]); data=atoi(argv[1]); printf("Putting *%lu=%X\n\r",addr,data); data=flash_put(addr,data); printf("returned %x\n\r",data); } */ sprintf(cmd,"vpwsend"); if (strcmp(buff,cmd)==0) { UBYTE data[60]; UBYTE resp[20]; UBYTE i; UBYTE temp; printf("hit key to stop\n\r"); //we need to copy args to data for (i=0; i<numArgs; i++) { //we need to parse ASCII temp=ascii2hex(argv[i]); data[i]=temp; } //printf("\n\r"); while(!kbhit()) { temp=vpw_send(resp, 60, data, numArgs); printf("response %u\n\r",temp); for (i=0; i<temp; i++) { printf("%X ",resp[i]); } printf("\n\r"); } while(kbhit()) getch2(); } sprintf(cmd,"isomon"); if (strcmp(buff,cmd)==0) { while (!kbhit()) iso_monitor(); while(kbhit()) getch2(); } sprintf(cmd,"isoput"); if (strcmp(buff,cmd)==0) { UBYTE temp; printf("ISO Put test\n\r"); printf("press any key to stop\n\r"); temp=0x03; while (!kbhit()) iso_put(&temp,1,20); while(kbhit()) getch2(); } sprintf(cmd,"vpwhigh"); if (strcmp(buff,cmd)==0) { UBYTE temp; printf("VPW high test\n\r"); printf("press any key to stop\n\r"); temp=0x03; output_high(VPW_OUT); while (!kbhit()){ printf("VPW_IN=%u\n\r",VPW_IN); } while(kbhit()) getch2(); output_low(VPW_OUT); } sprintf(cmd,"isohigh"); if (strcmp(buff,cmd)==0) { UBYTE temp; printf("ISO high test\n\r"); printf("press any key to stop\n\r"); temp=0x03; K_HIGH; while (!kbhit()){ printf("ISO_IN=%u\n\r",K_IN); } while(kbhit()) getch2(); K_LOW; } sprintf(cmd,"isolow"); if (strcmp(buff,cmd)==0) { UBYTE temp; printf("ISO low test\n\r"); printf("press any key to stop\n\r"); temp=0x03; K_LOW; while (!kbhit()){ printf("ISO_IN=%u\n\r",K_IN); } while(kbhit()) getch2(); K_HIGH; } sprintf(cmd,"vpwlow"); if (strcmp(buff,cmd)==0) { UBYTE temp; printf("VPW low test\n\r"); printf("press any key to stop\n\r"); temp=0x03; output_low(VPW_OUT); while (!kbhit()){ printf("VPW_IN=%u\n\r",VPW_IN); } while(kbhit()) getch2(); output_low(VPW_OUT); } sprintf(cmd,"flashpgm"); if (strcmp(buff,cmd)==0) { //UBYTE ret; printf("Start Xmodem download to unit of flash"); delay_ms(250); Flash_serial_program(0); } sprintf(cmd,"flashpcodes"); if (strcmp(buff,cmd)==0) { //UBYTE ret; printf("Start Xmodem download to unit of P codes"); delay_ms(250); Flash_serial_program(PCODE_FLASH_START); } sprintf(cmd,"flashccodes"); if (strcmp(buff,cmd)==0) { //UBYTE ret; printf("Start Xmodem download to unit of C codes"); delay_ms(250); Flash_serial_program(CCODE_FLASH_START); } sprintf(cmd,"flashbcodes"); if (strcmp(buff,cmd)==0) { //UBYTE ret; printf("Start Xmodem download to unit of B codes"); delay_ms(250); Flash_serial_program(BCODE_FLASH_START); } sprintf(cmd,"flashucodes"); if (strcmp(buff,cmd)==0) { //UBYTE ret; printf("Start Xmodem download to unit of U codes"); delay_ms(250); Flash_serial_program(UCODE_FLASH_START); } sprintf(cmd,"flashfirm"); if (strcmp(buff,cmd)==0) { UWORD i; printf("Erasing Firmware\n\r"); for(i=(FIRM_FLASH_START>>8); i<(FLASH_MAX_PAGES>>8); i++) { //sprintf(temp,"%lu",i); //LCD_print2(temp,2); //printf("Erasing Page %lu\n\r",i); if (flash_erase_page(i)!=0) return 1; } printf("Start Xmodem download to unit of Firmware"); delay_ms(250); Flash_serial_program(FIRM_FLASH_START); delay_ms(250); printf("Checking Firmware\n\r"); if (FirmwareCheck(FIRM_FLASH_START)==0) { printf("Updating Firmware\n\r"); FirmwareUpdate(FIRM_FLASH_START); }else { printf("Firmware not correct, try reloading\n\r"); } }
/// Character Received - add it to our command /// \param c the next character to process void gcode_parse_char(uint8_t c) { // uppercase if (c >= 'a' && c <= 'z') c &= ~32; // process previous field if (last_field) { // check if we're seeing a new field or end of line // any character will start a new field, even invalid/unknown ones if ((c >= 'A' && c <= 'Z') || c == '*' || (c == 10) || (c == 13)) { switch (last_field) { case 'G': next_target.G = parse_number.AsInt( false ); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_uint8(next_target.G); break; case 'M': next_target.M = parse_number.AsInt( false ); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_uint8(next_target.M); break; case 'X': next_target.target.X = parse_number.AsPosition( next_target.option_inches ); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_int32(next_target.target.X); break; case 'Y': next_target.target.Y = parse_number.AsPosition( next_target.option_inches ); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_int32(next_target.target.Y); break; case 'Z': next_target.target.Z = parse_number.AsPosition( next_target.option_inches ); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_int32(next_target.target.Z); break; case 'E': next_target.target.E = parse_number.AsPosition( next_target.option_inches ); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_uint32(next_target.target.E); break; case 'F': // just use raw integer, we need move distance and n_steps to convert it to a useful value, so wait until we have those to convert it next_target.target.F = parse_number.AsInt( next_target.option_inches ); //if (next_target.option_inches) // next_target.target.F = decfloat_to_int(&read_digit, 25400, 1); //else // next_target.target.F = decfloat_to_int(&read_digit, 1, 0); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_uint32(next_target.target.F); break; case 'S': // if this is temperature, multiply by 4 to convert to quarter-degree units // cosmetically this should be done in the temperature section, // but it takes less code, less memory and loses no precision if we do it here instead if ((next_target.M == 104) || (next_target.M == 109) || (next_target.M == 140)) next_target.S = parse_number.AsScaledInt( 4 ); //decfloat_to_int(&read_digit, 4, 0); // if this is heater PID stuff, multiply by PID_SCALE because we divide by PID_SCALE later on else if ((next_target.M >= 130) && (next_target.M <= 132)) next_target.S = parse_number.AsScaledInt( PID_SCALE );// decfloat_to_int(&read_digit, PID_SCALE, 0); else next_target.S = parse_number.AsInt( false ); //decfloat_to_int(&read_digit, 1, 0); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_uint16(next_target.S); break; case 'P': next_target.P = parse_number.AsInt( false ); //decfloat_to_int(&read_digit, 1, 0); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_uint16(next_target.P); break; case 'T': next_target.T = parse_number.AsInt( false ); //read_digit.mantissa; //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_uint8(next_target.T); break; case 'N': next_target.N = parse_number.AsInt( false ); //decfloat_to_int(&read_digit, 1, 0); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_uint32(next_target.N); break; case '*': next_target.checksum_read = parse_number.AsInt( false ); //decfloat_to_int(&read_digit, 1, 0); //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serwrite_uint8(next_target.checksum_read); break; } // reset for next field last_field = 0; parse_number.Clear(); } } // skip comments if (next_target.seen_semi_comment == 0 && next_target.seen_parens_comment == 0) { // new field? if ((c >= 'A' && c <= 'Z') || c == '*') { last_field = c; //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serial_writechar(c); } // process character switch (c) { // each currently known command is either G or M, so preserve previous G/M unless a new one has appeared // FIXME: same for T command case 'G': next_target.seen_G = 1; next_target.seen_M = 0; next_target.M = 0; break; case 'M': next_target.seen_M = 1; next_target.seen_G = 0; next_target.G = 0; break; case 'X': next_target.seen_X = 1; break; case 'Y': next_target.seen_Y = 1; break; case 'Z': next_target.seen_Z = 1; break; case 'E': next_target.seen_E = 1; break; case 'F': next_target.seen_F = 1; break; case 'S': next_target.seen_S = 1; break; case 'P': next_target.seen_P = 1; break; case 'T': next_target.seen_T = 1; break; case 'N': next_target.seen_N = 1; break; case '*': next_target.seen_checksum = 1; break; // comments case ';': next_target.seen_semi_comment = 1; break; case '(': next_target.seen_parens_comment = 1; break; // now for some numeracy case '-': parse_number.AddChar(c); break; case '.': parse_number.AddChar(c); break; #ifdef DEBUG case ' ': case '\t': case 10: case 13: // ignore break; #endif default: parse_number.AddChar(c); } } else if ( next_target.seen_parens_comment == 1 && c == ')') next_target.seen_parens_comment = 0; // recognize stuff after a (comment) if (next_target.seen_checksum == 0) next_target.checksum_calculated = crc(next_target.checksum_calculated, c); // end of line if ((c == 10) || (c == 13)) { //if (DEBUG_ECHO && (debug_flags & DEBUG_ECHO)) // serial_writechar(c); if ( #ifdef REQUIRE_LINENUMBER ((next_target.N >= next_target.N_expected) && (next_target.seen_N == 1)) || (next_target.seen_M && (next_target.M == 110)) #else 1 #endif ) { if ( #ifdef REQUIRE_CHECKSUM ((next_target.checksum_calculated == next_target.checksum_read) && (next_target.seen_checksum == 1)) #else ((next_target.checksum_calculated == next_target.checksum_read) || (next_target.seen_checksum == 0)) #endif ) { // process // teacup waits until after the processing of the gcode to send the eol... // FIXME - what to do here... serial_writestr_P(PSTR("ok ")); process_gcode_command(); serial_writechar('\n'); // expect next line number if (next_target.seen_N == 1) next_target.N_expected = next_target.N + 1; } else { sersendf_P(PSTR("rs N%ld Expected checksum %d\n"), next_target.N_expected, next_target.checksum_calculated); // request_resend(); } } else { sersendf_P(PSTR("rs N%ld Expected line number %ld\n"), next_target.N_expected, next_target.N_expected); // request_resend(); } // reset variables next_target.seen_X = next_target.seen_Y = next_target.seen_Z = \ next_target.seen_E = next_target.seen_F = next_target.seen_S = \ next_target.seen_P = next_target.seen_T = next_target.seen_N = \ next_target.seen_M = next_target.seen_checksum = next_target.seen_semi_comment = \ next_target.seen_parens_comment = next_target.checksum_read = \ next_target.checksum_calculated = 0; // last_field and read_digit are reset above already // assume a G1 by default next_target.seen_G = 1; next_target.G = 1; if (next_target.option_relative) { next_target.target.X = next_target.target.Y = next_target.target.Z = 0; #ifdef E_ABSOLUTE next_target.target.E = 0; #endif } #ifndef E_ABSOLUTE // E always relative next_target.target.E = 0; #endif } }