MdGpsSerial::MdGpsSerial() { #if defined (Q_OS_ANDROID) setupPort("",""); #else setupPort(); #endif }
/*! @param aDevName [in] Serial port device file name @return Sesnor's communication handler Returns NULL if failed */ tPort* scipConnect(char *aDevName) { tPort *port; int ret; fprintf(stdout,"Connecting at 19200 bps ...\n"); port=openPort(aDevName,19200); ret=scipTryComm(port); switch(ret){ case 1: case 2: fprintf(stdout,"Connected at 19200 bps\n\n"); return port; default: fprintf(stdout,"Could not connect at 19200 bps\n\n"); break; } fprintf(stdout,"Connecting at 57600 bps ...\n"); if(setupPort(fileno(port->dev),57600)!=EXIT_SUCCESS){ perror("Could not set terminal parameters "); return NULL; } ret=scipTryComm(port); switch(ret){ case 1: case 2: fprintf(stdout,"Connected at 57600 bps\n\n"); return port; default: fprintf(stdout,"Could not connect at 57600 bps\n\n"); break; } fprintf(stdout,"Connecting at 115200 bps ...\n"); if(setupPort(fileno(port->dev),115200)!=EXIT_SUCCESS){ perror("Could not set terminal parameters "); return NULL; } ret=scipTryComm(port); switch(ret){ case 1: case 2: fprintf(stdout,"Connected at 115200 bps\n\n"); return port; default: fprintf(stdout,"Could not connect at 115200 bps\n\n"); break; } return NULL; }
void init(void (*byteReceivedCallback)(uint8_t data)) { setupPort(); setBaudRate(9600); itsByteReceivedCallback = byteReceivedCallback; }
void MdQextSerialCom::togglePort() { if ( port ) { if ( port->isOpen() ) closePort(); else { openPort(); } } else { setupPort(); } }
MBOOL StereoNodeImpl:: onStart() { FUNC_START; MBOOL ret = MFALSE; MSize rgbSize = getRgbImgSize(); vector<HwPortConfig_t> lHwPortCfg; HwPortConfig_t cfgImg = { mapToPortID(STEREO_IMG), eImgFmt_YV12, getAlgoImgSize(), MRect( MPoint(0, 0), getAlgoImgSize() ) }; HwPortConfig_t cfgRgb = { mapToPortID(STEREO_RGB), eImgFmt_ARGB8888, rgbSize, MRect( MPoint(0, 0), rgbSize ) }; // if( !setupPort(mbCfgImgo, mbCfgFeo, mbCfgRgb ) ) goto lbExit; // if ( mbCfgImgo ) lHwPortCfg.push_back(cfgImg); // if ( mbCfgRgb ) lHwPortCfg.push_back(cfgRgb); // CAM_TRACE_BEGIN("alloc"); if( !allocBuffers(lHwPortCfg) ) { MY_LOGE("alloc buffers failed"); goto lbExit; } CAM_TRACE_END(); // muPostFrameCnt = 0; muEnqFrameCnt = 0; muDeqFrameCnt = 0; // ret = MTRUE; lbExit: FUNC_END; return ret; }
int main(int argc, char **argv) { int xsvferrcode = 0; printf("BeagleBone Black JTAG programming utility v0.5\n\n\r"); if(setFile(argv[1])) { printf("file open error !\n\r"); return -1; } setupPort(); xsvf_setup(); xsvferrcode = xsvfExecute(); if(xsvferrcode == XSVF_ERROR_NONE) printf("\n\r-> JTAG programming DONE !\n\r"); else printf("\n\r->JTAG programming FAILED ! - XSVF errocode = %d\n\r", xsvferrcode); return 0; }
void ThreadFunc(Params* params) { printf("=========================================================================\n"); printf(" SubThread %ld is watching over %s port \n", GetCurrentThreadId(), params->gszPort); printf("=========================================================================\n"); HANDLE hComm = openPort(params->gszPort); if (hComm == INVALID_HANDLE_VALUE) { printf("failed to open serial port %s \n", params->gszPort); return; } else { printf("serial port %s opened \n", params->gszPort); if (setupPort(hComm)) { // all sensors use the same calibration matrix and offset while(isCalibratorInitialized == false) { if(isCalibratorBeingInitialized == true) continue; isCalibratorBeingInitialized = true; printf("\n************** please rotate your sensor with port %s *************\n", params->gszPort); initCalibrator(hComm); } printf("======================= Now collect test data!! =================== \n"); SqQueue * queue = create_empty_queue(); char rawDataFileName[60]; //The file stores raw data char correctedDataFileName[60]; //The file stores corrected magnetic data printf("======================== THE TEST ====================== \n"); sprintf(rawDataFileName, "C:/Users/xing/Desktop/%s_Raw_Mag_Data.txt",params->gszPort); sprintf(correctedDataFileName, "C:/Users/xing/Desktop/%s_Corrected_Mag_Data.txt",params->gszPort); //the models of the four gestures char *gestureModel[DTW_NUM] = {"./gesture_model/target.txt" ,"./gesture_model/point.txt" ,"./gesture_model/rotate_right.txt" ,"./gesture_model/rotate_left.txt" ,"./gesture_model/slide_over.txt" ,"./activity_model/stand_up.txt" ,"./activity_model/sit_down.txt" ,"./activity_model/walk.txt"}; //the tresholds of four model gestures double threshold[DTW_NUM] = {TARGET_THRESHOLD,POINT_THRESHOLD,ROTATE_RIGHT_THRESHOLD,ROTATE_LEFT_THRESHOLD ,SLIDE_OVER_THRESHOLD,STAND_UP_THRESHOLD,SIT_DOWN_THRESHOLD,WALK_THRESHOLD}; //the time limit of four model gestures double timeLimit[DTW_NUM] = {TARGET_TIMELIMIT,POINT_TIMELIMIT,ROTATE_RIGHT_TIMELIMIT,ROTATE_LEFT_TIMELIMIT ,SLIDE_OVER_TIMELIMIT,STAND_UP_TIMELIMIT,SIT_DOWN_TIMELIMIT,WALK_TIMELIMIT}; //initialize the four models and their GestureRecognitionProcess //the order is : //0->point //1->rotate right //2->rotate left //3->slide over OriginalGesture *og[DTW_NUM]; GRProcess grp[DTW_NUM]; int gt = 0; for(gt = 0; gt < DTW_NUM; gt++) { og[gt] = read_file_to_init_original_gesture(gestureModel[gt]); int m = og[gt]->m; //Pay attention to Free memory !!! double *distanceArray = (double *)malloc(sizeof(double) * (m + 1)); double *distanceArrayLast = (double *)malloc(sizeof(double) * (m + 1)); int *startArray = (int *)malloc(sizeof(int) * (m + 1)); int *startArrayLast = (int *)malloc(sizeof(int) * (m + 1)); long int *timeArray = (long int *)malloc(sizeof(long int) * (m + 1)); long int *timeArrayLast = (long int *)malloc(sizeof(long int) * (m + 1)); double dmin = DBL_MAX; int te = 1; int ts = 1; int k = 0; for(k = 0; k <= m; k++) { distanceArrayLast[k] = DBL_MAX; startArrayLast[k] = 0; timeArrayLast[k] = 0; } grp[gt].distanceArray = distanceArray; grp[gt].distanceArrayLast = distanceArrayLast; grp[gt].dmin = dmin; grp[gt].originalGesture = *(og[gt]); grp[gt].startArray = startArray; grp[gt].startArrayLast = startArrayLast; grp[gt].timeArray = timeArray; grp[gt].timeArrayLast = timeArrayLast; grp[gt].threshold = threshold[gt]; grp[gt].te = te; grp[gt].ts = ts; grp[gt].times = 0; grp[gt].times = 0; grp[gt].type = gt; grp[gt].timeLimit = timeLimit[gt]; } //Before read, flush the buffer. purgePort(hComm); int trueNum = 0; bool hasTarget = false; DataHeadNode *targetHead = create_list_with_head(); PktData pktData; int i; for(i = 0; i < params->magDataNum; i ++) { pktData = blockingReadOnePacket(hComm); if(equals(pktData, ZERO_PKT)) { continue; } //Notice: it will override original raw data if queue is full int position = add_to_queue(queue, pktData); //input the current data into the SPRING if(SPRING(pktData, &grp[0],position, queue) == TARGET_TYPE) { trueNum++; add_to_list_head(targetHead, pktData); } if(trueNum >= 20) { /** compute target using the list of the target data list */ printf("\n!!!!!!!!!!!!!!!!!!!!!!%s target selected!!!!!!!!!!!!!!!!!!\n", params->gszPort); trueNum = 0; clear_list(targetHead); hasTarget = true; } if(hasTarget) { int l = 0; for(l = 1; l <= 4; l++) { SPRING(pktData, &grp[l],position, queue); } } //compare_list_and_delete_queue(queue,startList,4); } int magLen = get_queue_length(queue); printf("Actual mag data length: %d\n", magLen); //This is the same heading in Cali.mat double heading[magLen]; write_queue_to_file(rawDataFileName, queue); calibrateMagData(queue->magXData, queue->magYData, queue->magZData, heading, magLen); write_mag_to_file(correctedDataFileName, queue->magXData, queue->magYData, queue->magZData, heading, magLen); //clear_queue(queue); printf("\nSee %s \nand %s\nfor more detail!\n",rawDataFileName, correctedDataFileName); free_queue(queue); free_list(targetHead); } closePort(hComm); } }
bool MdQextSerialCom::changePortSettings (QString sport, QString speed) { closePort(); setupPort (sport, speed); qDebug() << "changed serial port to " << sport; return true; }