int main(int argc,char* argv[]) { int opt; int fd; char *device=NULL; char *baudrate=NULL; while ((opt = getopt(argc, argv, "d:b:-:")) != -1) { switch (opt) { case 'd': //dbg_printf("-d %s\n",optarg); device=optarg; dbg_printf("-d %s\n",device); break; case 'b': //dbg_printf("-b %s\n",optarg); baudrate=optarg; dbg_printf("-b %s\n",baudrate); break; case '-': //dbg_printf("- %s\n",optarg); if(strcmp(optarg,"help")==0) { printf( "Usage : [-d device] [-b] baudrate\n"); printf( " %s -d /dev/ttyUSB0 -b 38400 \n",argv[0]); return 0; } break; case '?': default: /* '?' */ fprintf(stderr, "Usage: %s [-d device] [-b] baudrate\n", argv[0]); exit(EXIT_FAILURE); } } fd = uartInit(fd, device==NULL ? serial_name: device , baudrate==NULL ? 115200 : atoi(baudrate)); while ( 1 ) { int i; short readLen = 0; //memset(sendUartBuf, 0, sizeof(sendUartBuf)); memset( rcvUartBuf, 0, sizeof( rcvUartBuf ) ); memset( input, 0, sizeof( input ) ); memset( output, 0, sizeof( output ) ); //printf( "Atcmd no include start, length, checkSum, end \n" ); printf( "j: join device, l: leave device, s : Show ,d: device list, E : Exit program \n" ); printf( " Enter Atcmd : " ); scanf( "%s", input ); //if input "s" then command "s", s : Show if(input[0]=='j'||input[0]=='J'&&input[1]==0) /* j: join device */ { printf(" Enter Mac Address : "); scanf( "%s", macAddress ); strcat(output,joinNetworkHead); strcat(output,macAddress); strcat(output,joinNetworkTail); //printf("output = %s\n",output); //printf("output len = %d\n",strlen(output)); memcpy(input,output,strlen(output)); } else if(input[0]=='l'||input[0]=='L'&&input[1]==0) /* l: leave device */ { printf(" Enter Mac Address : "); scanf( "%s", macAddress ); strcat(output,leaveNetworkHead); strcat(output,macAddress); strcat(output,leaveNetworkTail); //printf("output = %s\n",output); //printf("output len = %d\n",strlen(output)); memcpy(input,output,strlen(output));; } else if(input[0]=='e'||input[0]=='E'&&input[1]==0) { printf(" Exit Program\n"); return 0; } else if(input[0]=='c'||input[0]=='C'&&input[1]==0) { printf(" enter continue \n"); continue; } else if(input[0]=='d'||input[0]=='D'&&input[1]==0) { printf(" enter continue \n"); memcpy(input,deviceList,strlen(deviceList)); } int write_count=0; len = strlen(input); dbg_printf("inputlen= %d\n",len); input[len++]='\r'; input[len++]='\n'; dbg_printf("inputlen= %d\n",strlen(input)); #if 0 for(i=0; i<strlen(input); i++) { write_count = write( fd, &input[i], 1); //printf("%d",write_count++); } #else printf( "***********************************Start****************************\n\n" ); dataDump(input,strlen(input)); write(fd, input,strlen(input)); #endif printf( "\n" ); sleep( 1 ); readLen = read ( fd, rcvUartBuf, uartAck ); printf("readLen = %d\n",readLen); #if 0 printf( "[Response]: " ) for ( i = 0; i < uartAck; i++ ) { printf( "%02X", rcvUartBuf[i] ); } #endif printf( "\n\n" ); printf( "[Response]: " ); for ( i = 0; i < readLen; i++ ) { printf( "%C", rcvUartBuf[i] ); } printf( "\n**********************************End*****************************\n\n" ); } return 0; }
/* * Emit Mole data dump signal * @param uint8 moduleIndex * @param uint8 channelIndex * @param uint16 size * @param QVector<double> sample * @param QVector<double> data */ void Mole::emitDataDump(uint8 moduleIndex, uint8 channelIndex, QVector<double> samples, QVector<double> data) { emit dataDump(moduleIndex, channelIndex, samples, data); }
int main(int argc,char* argv[]) { int opt; int fd=0; char *device=NULL; char *baudrate=NULL; while ((opt = getopt(argc, argv, "d:b:-:")) != -1) { switch (opt) { case 'd': device=optarg; dbg_printf("-d %s\n",device); break; case 'b': baudrate=optarg; dbg_printf("-b %s\n",baudrate); break; case '-': if(strcmp(optarg,"help")==0) { printf( "Usage : [-d device] [-b] baudrate\n"); printf( " %s -d /dev/ttyUSB0 -b 38400 \n",argv[0]); return 0; } break; case '?': default: /* '?' */ fprintf(stderr, "Usage: %s [-d device] [-b] baudrate\n", argv[0]); exit(EXIT_FAILURE); } } fd = uartInit(fd, device==NULL ? serial_name: device , baudrate==NULL ? 19200 : atoi(baudrate)); while ( 1 ) { int i; short readLen = 0; memset( rcvUartBuf, 0, sizeof( rcvUartBuf ) ); memset( input, 0, sizeof( input ) ); printf( "Atcmd no include start, length, checkSum, end \n" ); printf( "Enter Atcmd : " ); scanf( "%s", input ); if((input[0]=='q' || input[0]=='Q') && input[1]==0 ) { printf(" enter quit \n"); return 0; } else if(input[0]=='s'|| (input[0]=='S'&&input[1]==0) ) { printf(" enter Show \n"); dataDump(fd,rcvUartBuf); continue; } /*DEBUG*/ #ifdef RYAN_DEBUG len = ( strlen( input ) / 2 ); inlen = strlen( input ); printf( "inlen = %X\n", inlen ); #endif printf( "[T]: " ); for ( i = 0; i < inlen; i++ ) { if ( input[i] < 58 ) /*0~9 字元轉數字 0~9*/ input[i] -= 48; if ( input[i] > 64 && input[i] < 71 ) /*A~F 字元轉數字 A~F*/ input[i] -= 55; if ( input[i] > 96 && input[i] < 103 ) /*a~f 字元轉數字 a~f*/ input[i] -= 87; output[i] = input[i]; #ifdef RYAN_DEBUG printf( "%X", output[i] ); //debug #endif } outlen = inlen; for ( i = 0; i < outlen/2; i++ ) { output[i] = ( output[i * 2] << 4 ) | ( output[( i * 2 ) + 1] ); printf( "%02X", output[i] ); } printf( "\n" ); printf( "outlen = %X ", outlen ); sum = CheckSum ( output, outlen, len ); printf( "len= %x ", len ); printf( "checksum= %x \n", sum ); sendUartBuf[0] = 0x02; sendUartBuf[1] = 0x00; sendUartBuf[2] = outlen; for ( i = 0, j = 0; i < outlen + 5; i++, j++ ) { sendUartBuf[i + 3] = output[j]; } sendUartBuf[i - 2] = sum; sendUartBuf[i - 1] = 0x03; printf( "sendUartBuf = : " ); for ( i = 0; i < len + 5; i++ ) { printf( "%02X", sendUartBuf[i] ); } #ifdef RYAN_DEBUG printf( "\n sendbuf outlen = %d\n", outlen + 5 ); write( fd, &sendUartBuf, outlen + 5 ); #endif printf( "\n" ); sleep( 5 ); /* read reponse */ readLen = read ( fd, rcvUartBuf, uartAck ); printf( "***********************************Start****************************\n\n" ); printf( "[R]: " ); for ( i = 0; i < uartAck; i++ ) { printf( "%02X", rcvUartBuf[i] ); } printf( "\n\n" ); printf( "[Parse]: " ); for ( i = 0; i < uartAck; i++ ) { printf( "%C", rcvUartBuf[i] ); } printf( "\n**********************************End*****************************\n\n" ); } return 0; }
int main(int argc, char *argv[]){ FILE *arch; char line[100], *word[6]; int count, x, y; //license license(); if (argc < 3) { printf("I need the modelname too\n"); exit(1); } if (argc == 5) { printf("I did it\n"); adjust = atof(argv[4]); } strcpy(modelname,argv[3]); //access obj file arch=fopen(argv[1],"r"); if(arch==NULL){ printf("Error: file not found or file unavailable\n\n"); exit(1); } else{ while(!feof(arch)){ //read line fgets(line,100,arch); //parse tokens for(count=0; count<6; count++){ word[count]= count==0 ? strtok(line," ") : strtok(NULL," "); if(word[count]==NULL){ word[count-1]=strtok(word[count-1],"\n"); break; } } //process data if(word[0]!=NULL){ if(strcmp(word[0],"v")==0){ newVertex(word); } else if(strcmp(word[0],"vt")==0){ newTexture(word); } else if(strcmp(word[0],"vn")==0){ newNormal(word); } else if(strcmp(word[0],"f")==0){ makeFace(word); } else{ //skip } } } fclose(arch); //save to file arch=fopen(argv[2],"w"); if(arch==NULL){ printf("Error: File creation unsuccessful\n\n"); } else{ fprintf(arch,"//Generated through PatchObj v.1.0 by Patricio Figueroa\n\n"); dataDump(arch); fclose(arch); } } printf("Success!\n\n"); return 0; }