qCNC 0.82-alpha
/home/trilog/Desktop/project/gui/Final/src/libtse.cpp
Go to the documentation of this file.
00001 
00041 #include "global_includes.h"
00042 #include "libtse.h"
00043 
00044 
00045 
00046 
00047 void AppendtoList(gcode_linkedL *firstptr, double x, double y, double z, gcode_linkedL *lastptr) {
00048     gcode_linkedL *temp;
00049     if (firstptr == NULL) {
00050         firstptr = new gcode_linkedL;
00051         firstptr->x = x;
00052         firstptr->y = y;
00053         firstptr->z = z;
00054         firstptr->next = NULL;
00055     }
00056     else {
00057         lastptr=firstptr;
00058         while (lastptr->next != NULL)
00059             lastptr = lastptr->next;
00060 
00061         temp = new gcode_linkedL;
00062         temp->x = x;
00063         temp->y = y;
00064         temp->z = z;
00065         temp->next = NULL;
00066         lastptr->next = temp;
00067     }
00068 }
00069 
00070 void get_settings(gui_settings * temps) {
00071     //gui_settings temps;
00072     QString str;
00073     QStringList slit;
00074     int istss = 0;
00075     QFile ftcpset(TCP_SETTINGS_TSS);
00076     QFile fserialset(SERIAL_SETTINGS_TSS);
00077     QFile fprogset(PROG_SETTINGS_TSS);
00078 
00079     ftcpset.open(QIODevice::ReadOnly);
00080     fserialset.open(QIODevice::ReadOnly);
00081     fprogset.open(QIODevice::ReadOnly);
00082 
00083     QTextStream fst(&ftcpset);    // read the data serialized from the file
00084     QTextStream fss(&fserialset);    // read the data serialized from the file
00085     QTextStream fsp(&fprogset);    // read the data serialized from the file
00086      //for tcp
00087     str.clear();
00088     istss = 0;
00089     if (ftcpset.isOpen()) {
00090 
00091         while (!fst.atEnd()) {
00092             str=fst.readLine();
00093             if (str[0] == '#') {
00094                 continue;
00095             }
00096             else {
00097                 slit=str.split("|");
00098 
00099                if (slit.at(0) == "INET_ADD") {
00100                     temps->TCPaddress = slit.at(1);
00101                 }
00102                 else if (slit.at(0) == "INET_PORT") {
00103                     temps->TCPport = slit.at(1).toInt();
00104                 }
00105                 else if (slit.at(0) == "INET_DEL") {
00106                     temps->TCPStdtimeout = slit.at(1).toInt();
00107                 }
00108                  if (slit.at(0) == "TSS")
00109                     istss = 1;
00110 
00111             }
00112 
00113 
00114         }
00115         if (istss != 1) {
00116             //QMessageBox::information(this, "Error! Corrupt settingsfile","Your Settingsfile is corrupted. It WILL be rewritten");
00117             qDebug() << "get_settings | libtse : no valid config found. setting defaults. if changes occure, defaults will be overwritten";
00118             temps->TCPaddress = "127.0.0.1";
00119             temps->TCPport = 6666;
00120             temps->TCPStdtimeout = 100;
00121         }
00122 
00123     }
00124 istss = 0;
00125     //for serial
00126     if (fserialset.isOpen()) {
00127         str.clear();
00128 
00129         while (!fss.atEnd()) {
00130             str=fss.readLine();
00131             if (str[0] == '#') {
00132                 continue;
00133             }
00134             else {
00135                 slit=str.split("|");
00136                if (slit.at(0) == "SERIAL_DEV") {
00137                     temps->SerialDevice = slit.at(1);
00138                 }
00139                 if (slit.at(0) == "TSS")
00140                     istss = 1;
00141             }
00142 
00143 
00144         }
00145         if (istss != 1) {
00146             //QMessageBox::information(this, "Error! Corrupt settingsfile","Your Settingsfile is corrupted. It WILL be rewritten");
00147             qDebug() << "get_settings | libtse : no valid config found. setting defaults. if changes occure, defaults will be overwritten";
00148             temps->SerialDevice = "/dev/ttyUSB0";
00149         }
00150 
00151     }
00152 
00153     //for program
00154     istss = 0;
00155     if (fprogset.isOpen()) {
00156         str.clear();
00157 
00158         while (!fsp.atEnd()) {
00159             str=fsp.readLine();
00160             if (str[0] == '#') {
00161                 continue;
00162             }
00163             else {
00164                 slit=str.split("|");
00165                 if (slit.at(0) == "PROG_enLOG") {
00166                     temps->Progenlog = slit.at(1).toInt();
00167                 }
00168                 else if (slit.at(0) == "PROG_LOGP") {
00169                     temps->Proglogpath = slit.at(1);
00170                 }
00171                 else if (slit.at(0) == "PROG_UARTDB") {
00172                     temps->Progenuartdb = slit.at(1).toInt();
00173                 }
00174                 else if (slit.at(0) == "PROG_CNCkill") {
00175                     temps->Progenkill = slit.at(1).toInt();
00176                 }
00177                 if (slit.at(0) == "TSS")
00178                     istss = 1;
00179 
00180             }
00181 
00182 
00183         }
00184         if (istss != 1) {
00185             //QMessageBox::information(this, "Error! Corrupt settingsfile","Your Settingsfile is corrupted. It WILL be rewritten");
00186             qDebug() << "get_settings | libtse : no valid config found. setting defaults. if changes occure, defaults will be overwritten";
00187             temps->Progenkill = 0;
00188             temps->Progenlog = 0;
00189             temps->Progenuartdb = 0;
00190             temps->Proglogpath = "";
00191         }
00192 
00193     }
00194    // return &temps;
00195 }
00196 
00197 
00198 int TCP_controll(int time_passed, int *sock, int CNC_mode, int CNC_process, protocol *tosend,  int *constat) {
00199     protocol temp;
00200     protocol *received = new protocol;
00201     int cntr = 0;
00202     if ( *constat == 0) { //init
00203         temp.status = 200;
00204         temp.x = 78;
00205         write_socket(sock,&temp);
00206         while (1) {
00207             read_socket(sock,received);
00208             if ( received->status == 200 && received->x == 101) {
00209                 *constat = 99;
00210                 break;
00211             }
00212         }
00213     }
00214     else if (*constat > 0) {
00215         if (time_passed > 1000) {
00216             temp.status = 200;
00217             temp.x = 199;
00218             write_socket(sock,&temp);
00219             while (1) {
00220                 read_socket(sock, received);
00221                 if (received->status == 200 && received->x == 999) {
00222                     *constat = 99;
00223                     break;
00224                 }
00225                 else if (cntr >6000000 ) {
00226                     break;
00227                 }
00228                 else {
00229                     //connected = -1;
00230                     return -1;
00231                 }
00232                 cntr++;
00233             }
00234         }
00235 
00236         if (CNC_process == 1) { //starting now
00237             while(1) {
00238                 temp.status = 200;
00239                 temp.x = 50;
00240                 write_socket(sock, &temp);
00241                 while (1) {
00242                     read_socket(sock, received);
00243                     if (received->status == 200 && received->x == 101) {
00244                         return 11;
00245 
00246                     }
00247                 }
00248                 if ( CNC_process >=1) {
00249                     break;
00250                 }
00251             }
00252         }
00253         if (CNC_process == 2) { //send coordinates
00254             write_socket(sock, tosend);
00255             while (1) {
00256                 time_passed--;
00257                 read_socket(sock, received);
00258                 if (received->status == 200 && received->x == 30) {
00259                     return 0;
00260                 }
00261                 else if (received->status == 200 && received->x == 60) {
00262                     return 55;
00263                 }
00264             }
00265         }
00266         if (CNC_process == 9) { //kill
00267             temp.status = 99;
00268             temp.x =99;
00269             time_passed--;
00270             write_socket(sock, &temp);
00271             while (1) {
00272                 read_socket(sock,received);
00273                 if ( received->status == 200 && received->x == 101) {
00274                     return 20;
00275                 }
00276             }
00277         }
00278         if (CNC_process == 5) { //pause
00279             temp.status = 99;
00280             temp.x =199;
00281             time_passed--;
00282             write_socket(sock, &temp);
00283             while (1) {
00284                 read_socket(sock,received);
00285                 if ( received->status == 200 && received->x == 101) {
00286                     return 25;
00287                 }
00288             }
00289         }
00290         if (CNC_process == 23) { //reset
00291             temp.status = 99;
00292             temp.x =0;
00293             time_passed--;
00294             write_socket(sock, &temp);
00295             while (1) {
00296                 read_socket(sock,received);
00297                 if ( received->status == 200 && received->x == 101) {
00298                     return 27;
00299                 }
00300             }
00301         }
00302         if (CNC_process == 55) { //call to resume
00303             temp.status = 99;
00304             temp.x =201;
00305             time_passed--;
00306             write_socket(sock, &temp);
00307             while (1) {
00308                 read_socket(sock,received);
00309                 if ( received->status == 200 && received->x == 101) {
00310                     return 50;
00311                 }
00312             }
00313         }
00314         if (CNC_mode == 1) { //File_mode
00315             temp.status = 15;
00316             temp.x =15;
00317             time_passed--;
00318             write_socket(sock, &temp);
00319             while (1) {
00320                 read_socket(sock,received);
00321                 if ( received->status == 200 && received->x == 101) {
00322                     return 34;
00323                 }
00324             }
00325         }
00326         if (CNC_mode == 3) { //standalone mode
00327             temp.status = 15;
00328             temp.x =9;
00329             time_passed--;
00330             write_socket(sock, &temp);
00331             while (1) {
00332                 read_socket(sock,received);
00333                 if ( received->status == 200 && received->x == 101) {
00334                     return 36;
00335                 }
00336             }
00337         }
00338         if (CNC_mode == 2) { //kill
00339             temp.status = 15;
00340             temp.x =6;
00341             time_passed--;
00342             write_socket(sock, &temp);
00343             while (1) {
00344                 read_socket(sock,received);
00345                 if ( received->status == 200 && received->x == 101) {
00346                     return 35;
00347                 }
00348             }
00349         }
00350 
00351 
00352 
00353     }
00354     return 666;
00355 
00356 }
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines