Exemple #1
0
void createStock() {
    char name[51];
    int val,i;
    printf("\nEnter the name of the stock that you want to create:");
    scanf("%s",name);
    printf("Enter the base price for the stock:");
    scanf("%d",&val);
    setSignal('w');
    FILE *f=fopen("common/stocks.dat","r");
    fread(stocks,sizeof(struct stock),MAX_STOCKS,f);
    fclose(f);
    for(i=0; i<MAX_STOCKS; i++) {
        if(strcmp(stocks[i].name,"")==0) {
            strcpy(stocks[i].name,name);
            stocks[i].baseVal=val;
            stocks[i].currVal=val;
            break;
        }
    }
    f=fopen("common/stocks.dat","w+");
    fwrite(stocks,sizeof(struct stock),MAX_STOCKS,f);
    fclose(f);
    printf("\nStock created successfully!\n");
    printf("\nPress enter to continue...\n");
    getchar();
    getchar();
    setSignal('\0');
}
Exemple #2
0
/*
 * sets up the logging pipe and forks off the logger process 
 */
void startLogging(int level, int thread) {

  // if we're a client, just open the log and
  // don't start a logger.
  if (! thread ) {
     OPENLOG(level);
    return;
  }
    
  pipe(logfds);
  int             lpid;

  lpid = fork();

  if (lpid == 0) {
    close(logfds[1]);           /* close write end */
    setSignal(SIGINT, SIG_IGN, 0);
    setSignal(SIGTERM, SIG_IGN, 0);
    setSignal(SIGHUP, SIG_IGN, 0);

    runLogger(logfds[0], level);

    close(logfds[0]);
    exit(0);
  } else if (lpid > 0) {
    close(logfds[0]);           /* close read end */
    log_w_stream = fdopen(logfds[1], "w");
    return;
  } else {
    fprintf(stderr, "*** fork of logger proc failed\n");
    abort();
  }
}
Exemple #3
0
void getGraph() {
    char cmp[51];
    printf("Enter the name of the company whose stock you want to get: ");
    scanf("%s",cmp);
    setSignal('w');
    int i,found=0;
    FILE *f=fopen("common/stocks.dat","r+");
    fread(stocks,sizeof(struct stock),MAX_STOCKS,f);
    for(i=0; i<MAX_STOCKS; i++) {
        if(strcmp(stocks[i].name,cmp)==0) {
            FILE *fp=fopen("common/plot","w+");
            fprintf(fp,"plot \"common/records/%s.txt\" with line\npause -1 \"Press enter to continue...\"",stocks[i].name);
            fclose(fp);
            system("gnuplot common/plot");
            found=1;
            break;
        }
    }
    if(!found) {
        printf("\nThe stock for the company doesn't exist!\n");
        printf("\nPress enter to continue...\n");
        getchar();
        getchar();
    }
    setSignal('\0');
}
Exemple #4
0
bool PyrMean::update()
{
  const bool rv = Node::update();
  if (!rv) return false;
  
  cv::Mat in = getImage("in");
  if (in.empty()) return true;

  cv::Mat out_3;

  cv::Mat in_3 = cv::Mat(in.size(), CV_8UC3, cv::Scalar(0));  
  // just calling reshape(4) doesn't do the channel reassignment like this does
  int ch[] = {0,0, 1,1, 2,2};
  cv::mixChannels(&in, 1, &in_3, 1, ch, 3 );

  int max_level = getSignal("max_level");
  if (max_level > 4) { max_level = 4; setSignal("max_level", max_level); }
  if (max_level < 0) { max_level = 0; setSignal("max_level", max_level); }
  
  cv::pyrMeanShiftFiltering(in_3, out_3, 
      getSignal("sp"), getSignal("sr"),
      max_level,
      cv::TermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS, getSignal("term"), 5)
      );

  cv::Mat out = cv::Mat(out_3.size(), CV_8UC4, cv::Scalar(0));  
  cv::mixChannels(&out_3, 1, &out, 1, ch, 3 );

  setImage("out", out);

}
  bool Output::update()
  {
    if (!ImageNode::update()) return false;
  
    cv::Mat in = getImage("in");
    if (in.empty()) return true;

    if (!ximage) return true;
   
    XWindowAttributes xwAttr;
    Status ret = XGetWindowAttributes( display, win, &xwAttr );
    int screen_w = xwAttr.width;
    int screen_h = xwAttr.height;
    setSignal("disp_w", screen_w);
    setSignal("disp_h", screen_h);

    // TBD is this necessary or does X do it for me if the window is resized?
    cv::Size sz = cv::Size(screen_w, screen_h);
    cv::Mat scaled;
    cv::resize(in, scaled, sz, 0, 0, cv::INTER_NEAREST );
   
    XDestroyImage(ximage);
    ximage = XGetImage(display, DefaultRootWindow(display), 0, 0, screen_w, screen_h, AllPlanes, ZPixmap);

    bm::matToXImage(scaled, ximage, win, *display, *screen);
  
    bool window_decorations_on = getSignal("decor");
    setSignal("decor", window_decorations_on);

    bm::setWindowDecorations(display, win, window_decorations_on);
  }
Exemple #6
0
int main()
{
	struct sigaction new_usr1_action, old_usr1_action, new_usr2_action, old_usr2_action,
	new_usr3_action, old_usr3_action;

	printf("Process pid = %i\n", getpid());

	setSignal(SIGUSR1, &new_usr1_action, &old_usr1_action);
	setSignal(SIGUSR2, &new_usr2_action, &old_usr2_action);
	setSignal(SIGINT,  &new_usr3_action, &old_usr3_action);

	if ((kill(getpid(), SIGUSR1)) == -1)
	{
		printf("Signal send with error!\n");
	}
	else
	{
		printf("Signal send OK!\n");
	}

	sleep(5);

	restoreSignal(SIGUSR1,&old_usr1_action);
	restoreSignal(SIGUSR2,&old_usr2_action);
	restoreSignal(SIGINT, &old_usr3_action);

	return 0;
}
Exemple #7
0
PyrMean::PyrMean(const std::string name) : ImageNode(name)
{
  cv::Mat in;
  setImage("in", in);
  setSignal("sp", 30);
  setSignal("sr", 30);
  setSignal("max_level", 2);
  // TBD TERMCRIT
  setSignal("term", 2);
}
Exemple #8
0
ScreenCap::ScreenCap(const std::string name) :ImageNode(name)
{
  display = NULL;
  screen = NULL;
  xImageSample = NULL;

  display = XOpenDisplay(NULL); // Open first (-best) display
  if (display == NULL) {
    LOG(ERROR) << name << " bad display";
    return;
  }

  screen = DefaultScreenOfDisplay(display);
  if (screen == NULL) {
    LOG(ERROR) << name << " bad screen";
    return;
  }

  Window wid = DefaultRootWindow( display );
  if ( 0 > wid ) {
    LOG(ERROR) << "Failed to obtain the root windows Id "
        "of the default screen of given display.\n";
    return;
  }

  XWindowAttributes xwAttr;
  Status ret = XGetWindowAttributes( display, wid, &xwAttr );
  screen_w = xwAttr.width;
  screen_h = xwAttr.height;

  LOG(INFO) << name << " screen w h " << CLVAL << screen_w << " " << screen_h << CLNRM;
  // The starting pixels / offset (x,y) to take the screenshot from
  int startX = 0;
  int startY = 0;

  // The size of the area (width,height) to take a screenshot of
  int widthX = Config::inst()->im_width; //screen->width / 4, heightY = screen->height / 4; 
  int heightY = Config::inst()->im_height;
  
  cv::Mat out = cv::Mat(cv::Size(widthX, heightY), CV_8UC4);
  out = cv::Scalar(50,50,200);

  setSignal("startX", startX);
  setSignal("startY", startY);
  setSignal("widthX", widthX);
  setSignal("heightY", heightY);

  setImage("out", out);
}
Exemple #9
0
void Motor::setup ()
{
	pinMode( _dirPin, OUTPUT );
	pinMode( _speedPin, OUTPUT );
	setDirection(0);
	setSignal(0);
}
Exemple #10
0
int main() {

    unsigned char data1 = 0x0;
    unsigned char data2 = 0x0;
    unsigned char dataCounter = 0;

    cpuInit();

    for(;;) {
        // first data packet
        if (parserState && dataCounter == 0) {
            data1 = readData();
            dataCounter++;
        }
        // second data packet
        if (parserState && dataCounter == 1) {
            data2 = readData();
            dataCounter = 0;
        }
        // if first and second are the same and address
        // is my address change value
        if (address == MyAddr && data1 == data2) {
            setSignal(data1);
        }
        // kanal 255 is a programmming mode
        if (address == 0xff && data1 == data2) {
            doProgramingMode(data2);
        }
    }
}
bool Bezier::update()
{
  //if (!ImageNode::update()) return false;
  if (!Node::update()) return false;

  cv::Mat out = cv::Mat(cv::Size(Config::inst()->im_width, Config::inst()->im_height), MAT_FORMAT_C3);
  out = cv::Scalar(0,0,0);

  std::vector<cv::Point2f> control_points;
  control_points.push_back( cv::Point2f( getSignal("x0"), getSignal("y0") ));
  control_points.push_back( cv::Point2f( getSignal("x1"), getSignal("y1") ));
  control_points.push_back( cv::Point2f( getSignal("x2"), getSignal("y2") ));
  control_points.push_back( cv::Point2f( getSignal("x3"), getSignal("y3") ));
  
  int num = getSignal("num");
  if (num < 2) { num = 2;
    setSignal("num", num);
  }

  std::vector<cv::Point2f> bezier_points;
  getBezier(control_points, bezier_points, num);

  for (int i = 1; i < bezier_points.size(); i++) {
    cv::line(out, bezier_points[i-1], bezier_points[i], cv::Scalar(255, 255, 255), 2, CV_AA ); 
  }

  setImage("out", out);

  return true;
}
Exemple #12
0
Contour::Contour(const std::string name) : ImageNode(name)
{
  cv::Mat tmp;
  setImage("in", tmp);
  setSignal("epsilon" , 3.0);

//setSignal("mode",0);
}
Exemple #13
0
/* Funkcja testująca funkcjonalność widżetu.
 * Wywoływana przyciskiem "test()".
 * Wywołuje modealne okienko wyboru pliku.
 * Trzeba wskazać poprawny plik z sygnałem EKG,
 * możliwy do wczytania przez bibliotekę WFDB,
 * czyli jeden z trzech plików: .dat .hea .atr
 * o współnym przedrostku zgodnym z jakimś id wewnątrz.
 * Plik zostanie wczytany i wyświetlone zostaną dane
 * z obu kanałów.
 * Zaznaczenie fragmenu wykresu myszą przybliża go.
 * Można wtedy przewijać wykres środkowym przyciskiem myszy.
 * Oddala się prawym, ew. z wciśniętym klawiszem Ctrl (jest bug).
 */
void Ecg2Ch::test()
{
    QString fileName = QFileDialog::getOpenFileName(this);
    ECGController *controller = new ECGController;
    controller->readFile(fileName.toStdString()); // why?
    setSignal(&(controller->raw_signal));
    redraw();
    delete controller;
}
Exemple #14
0
ContourFlip::ContourFlip(const std::string name) : Contour(name)
{
  cv::Mat tmp;
  setImage("to_flip", tmp); // the image that will be flipped based on the contour found in in
  //setSignal("mode",0);
  setImage("flipped", tmp, true);
  setImage("dist", tmp, true);
  setImage("mapx", tmp, true);
  setImage("mapy", tmp, true);

  setSignal("border", 0, false, ROLL, 0, 4);
  setSignal("mode", 0, false, ROLL, 0, 4);

  initRemaps(base_x, base_y);
    
  off_x = cv::Mat( Config::inst()->getImSize(), CV_32FC1);
  off_y = off_x.clone();
}
Bezier::Bezier()
{
  setSignal("x0",10);
  setSignal("y0",10);
  
  setSignal("x1",100);
  setSignal("y1",50);
  
  setSignal("x2",200);
  setSignal("y2",50);
  
  setSignal("x3",300);
  setSignal("y3",150);

  setSignal("num", 4);
}
Exemple #16
0
void quit() { //code to quit the client - this asks to option to quit the server as well
    char chr;
    printf("Stop the server as well? (y/n) ");
    getchar();
    chr=getchar();
    if(chr=='y') {
        setRunning(0);
        setSignal('q');// passing the quit signal to the server
    }
    q=1;
}
Exemple #17
0
/*
 * sets up the logging pipe and forks off the logger process 
 */
void
startLogging(int level, int thread)
{
  // if we're a client, just open the log and
  // don't start a logger.
  if (! thread ) {
    OPENLOG(level);
    return;
  }

  pipe(logfds);
  int             lpid;
  lpid = fork();

  if (lpid == 0) {
    close(logfds[1]);           /* close write end */
    setSignal(SIGINT, SIG_IGN, 0);
    setSignal(SIGTERM, SIG_IGN, 0);
    setSignal(SIGHUP, SIG_IGN, 0);
    setSignal(SIGUSR2, SIG_IGN, 0);

    /* Label the process by modifying the cmdline */
    extern void append2Argv(char *appendstr);
    extern unsigned int labelProcs;
    if (labelProcs) {
      append2Argv("-proc:Logger");
    }

    runLogger(logfds[0], level);

    close(logfds[0]);
    exit(0);
  } else if (lpid > 0) {
    close(logfds[0]);           /* close read end */
    log_w_stream = fdopen(logfds[1], "w");
    return;
  } else {
    fprintf(stderr, "*** fork of logger proc failed\n");
    abort();
  }
}
Exemple #18
0
void availablestocks() {
    setSignal('w');
    int i;
    FILE *f=fopen("common/stocks.dat","r+");
    fread(stocks,sizeof(struct stock),MAX_STOCKS,f);
    for(i=0; i<MAX_STOCKS; i++) {
        if (strcmp(stocks [i].name,"")==0)
            break;
        else
            printf("%s\n",stocks[i].name);
    }
}
Exemple #19
0
float* ofxFftw::ifft(float* input) {
	// assume the phase is 0
	memset(&(ifftIn[bins]), 0, sizeof(float) * bins);
	// directly copy amplitude as real component
	memcpy(ifftIn, input, sizeof(float) * bins);

	fftwf_execute(ifftPlan);

	setSignal(ifftOut);
	signalReady = false;

	return getSignal();
}
Exemple #20
0
void TimeDialog::Set(){
  int t;
  if (!myset->text().isEmpty()){
    if (mybox->currentIndex() == 0) {
      if (myfirsttimerid != 0) {
        killTimer(myfirsttimerid);
      }
      t = myset->text().toInt();
      myfirsttimerid = startTimer(t);
      emit(setSignal());
    } else {
      if (mybox->currentIndex() == 1) {
        if (mysecondtimerid != 0) {
          killTimer(mysecondtimerid);
        }
        t = myset->text().toInt();
        mysecondtimerid = startTimer(t);
        emit(setSignal());
      }
    }
  }
}
Exemple #21
0
void getQuote() { //function fetches the current value of stock in the market
    char cmp[51];
    printf("Enter the name of the company whose stock you want to get: ");
    scanf("%s",cmp);
    setSignal('w');// setting the wait signal on server to prevent file-locking conflicts
    int i,found=0;
    FILE *f=fopen("common/stocks.dat","r+");
    fread(stocks,sizeof(struct stock),MAX_STOCKS,f);
    for(i=0; i<MAX_STOCKS; i++) {
        if(strcmp(stocks[i].name,cmp)==0) {
            printf("\nThe current stock value of %s is: %d\n",stocks[i].name,stocks[i].currVal);
            found=1;
            break;
        }
    }
    if(!found)
        printf("\nThe stock for the company doesn't exist!\n");
    printf("\nPress enter to continue...\n");
    getchar();
    getchar();
    setSignal('\0');// setting the null signal on the server
}
Exemple #22
0
/**
TBD is most of same functionality perhaps with higher performance provided by
pyrMeanShiftFiltering?  It seems different in parameters but the result might end up looking very similar.

My manual method still may be useful for exposing some internal data for use elsewhere in the graph.
*/
Cluster::Cluster(const std::string name) : ImageNode(name)
{
  cv::Mat tmp;
  setImage("in", tmp);
	setSignal("dist_weight", 0.5);
  setSignal("margin", 0.3);
  setSignal("num", 3);
  setSignal("wrap",0);
  setSignal("manhat",0);
  setSignal("time", 0);
}
void MUXSender(BCSPStack * stack)
{
	Packet * pkt = null ;

	while(1) 
	{
		//wait for the slip-sender to be available - (the slip-sender only has one packet
		//slot rather than a queue to prevent problems with window-rollbacks.

		if (stack->SLIPInputPacket) SYNCBLKwaitSignal(stack,&stack->SLIPSendAvailableSignal) ;

		//we prefer to send an unreliable packet if one is available
		pkt=ASYNCBLKgetPacketFromBuffer(stack,&stack->MUXUnreliableInput) ;


		//otherwise, we'll take a reliable one if one is available
		if (!pkt) pkt = ASYNCBLKremoveFirstUnsentPacketFromWindow(stack,&stack->theXMITWindow) ;

		//the last resort is to send a dedicated ack packet but we only need 
		//to do this if an ack is definitely required
		if (!pkt)
		{
			if (!stack->ackRequired) SYNCBLKwaitSignal(stack,&stack->txackSignal) ; 
			//blocking on the signal has the side-effect of also blocking on the
			//previous conditions so we'll be woken up by anything
			stack->ackRequired = false ;
			pkt = &stack->theAckPacket ; //use the dedicated ack packet
		}

		//ok - at this point we have a packet and we're intent on sending it

		setAck(pkt, stack->txack) ; //set the correct acknowledgement number
		
		//add the checksum to the header after setting crc
		if (stack->configuration->useCRC) setPacketHasCRC(pkt) ;
		setPacketChecksum(pkt) ;

		//pass it on to SLIP layer
        // JBS: no GetTickCount on POSIX
        //   BTRACE5(MUX,"MUX sending pkt %p seq %d ack %d len %d time %d\n",pkt,getSeq(pkt),getAck(pkt),getLength(pkt), GetTickCount() ) ;
		BTRACE4(MUX,"MUX sending pkt %p seq %d ack %d len %d\n",pkt,getSeq(pkt),getAck(pkt),getLength(pkt)) ;
		
		stack->SLIPInputPacket = pkt ;
		setSignal(stack,&stack->MUXHasPacketForSLIPSignal) ;
	}
}
Exemple #24
0
  Output::Output(const std::string name) :
    ImageNode(name),
    ximage(NULL),
    display(NULL)
  { 
    cv::Mat out; setImage("in",out);

    setSignal("decor",1, false, SATURATE, 0, 1); // TBD make a SATURATE_INTEGER, or ROLL_INTEGER type?
    setSignal("mode", 0, false, ROLL, 0, 4);

    setSignal("x", Config::inst()->ui_width, false, SATURATE, 0, 1e6); // TBD FLT_MAX instead of 1e6?
    setSignal("y", 0, false, SATURATE, 0, 1e6);
    setSignal("w", Config::inst()->out_width,  false, SATURATE, 1, 1e6);
    setSignal("h", Config::inst()->out_height, false, SATURATE, 1, 1e6);
  }
Exemple #25
0
void Output::init()
{
  ImageNode::init();
  cv::Mat out;
  setImage("in", out);

  setSignal("decor", 1, false, SATURATE, 0, 1); // TBD make a SATURATE_INTEGER, or ROLL_INTEGER type?
  setSignal("mode", 0, false, ROLL, 0, 4);

  setSignal("x", Config::inst()->ui_width, false, SATURATE, 0, 1e6); // TBD FLT_MAX instead of 1e6?
  setSignal("y", 0, false, SATURATE, 0, 1e6);
  setSignal("w", Config::inst()->out_width,  false, SATURATE, 1, 1e6);
  setSignal("h", Config::inst()->out_height, false, SATURATE, 1, 1e6);

}
Exemple #26
0
float* ofxFftw::ifft(float* a, float* b, fftMode mode) {
	if(mode == OF_FFT_POLAR) {
		setAmplitude(a);
		setPhase(b);
		updateCartesian();
	} else if(mode == OF_FFT_CARTESIAN) {
		setReal(a);
		setImaginary(b);
	}

	memcpy(ifftIn, amplitude, sizeof(float) * bins);
	for(int i = 1; i < signalSize; i++)
		ifftIn[signalSize - i] = phase[i];

	fftwf_execute(ifftPlan);

	setSignal(ifftOut);
	signalReady = false;

	return getSignal();
}
int executeCommand(int in, int out, char **argv){
	pid_t pid;

  if ((pid = fork ()) == 0){
		int value;
		setSignal(1);
    if (in != 0){
      dup2 (in, 0);
      close (in);
    }

    if (out != 1){
      dup2 (out, 1);
      close (out);
    }

    value = execvp (*argv, argv);
		handleErrno(errno, argv[0]);
		return value;
  }

  return pid;
}
int QSignalTransition::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QAbstractTransition::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QObject**>(_v) = senderObject(); break;
        case 1: *reinterpret_cast< QByteArray*>(_v) = signal(); break;
        }
        _id -= 2;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setSenderObject(*reinterpret_cast< QObject**>(_v)); break;
        case 1: setSignal(*reinterpret_cast< QByteArray*>(_v)); break;
        }
        _id -= 2;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 2;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Exemple #29
0
bool ScreenCap::update()
{
  if (!Node::update()) return false;
  
  if ((display == NULL) || (screen == NULL)) { return false; }

  int startX  = getSignal("startX");
  int startY  = getSignal("startY");
  int widthX  = getSignal("widthX");
  int heightY = getSignal("heightY");

  if (startX < 0) startX = 0;
  if (startY < 0) startY = 0;

  // Need to check against resolution
  if ((startX + widthX) > screen_w) {
    // TBD need to more intelligently cap these
    if (screen_w > widthX) {
      startX = screen_w - widthX;
    } else {
      startX = 0;
      widthX = Config::inst()->im_width;
    }
  }

  if ((startY + heightY) > screen_h) {
    // TBD need to more intelligently cap these
    if (screen_h > heightY) {
      startY = screen_h - heightY;
    } else {
      startY = 0;
      heightY = Config::inst()->im_height;
    }
  }
 
  setSignal("startX", startX);
  setSignal("startY", startY);
  setSignal("widthX", widthX);
  setSignal("heightY", heightY);

  xImageSample = XGetImage(display, DefaultRootWindow(display), 
      startX, startY, widthX, heightY, AllPlanes, ZPixmap);
  
  // Check for bad null pointers
  if (xImageSample == NULL) { 
    LOG(ERROR) << "Error taking screenshot!";
    return false;
  }

  //    col.pixel = XGetPixel(image, x, y); // Get pixel at x,y
  cv::Mat tmp = XImage2OpenCVImage(*xImageSample, *display, *screen);

  // To get the color values of the (sub-)image (can be slow, there are alternatives)
  //    XQueryColor(display, DefaultColormap(display, DefaultScreen(display)), &col); 

  // Always clean up your mess
  XDestroyImage(xImageSample);
  //XCloseDisplay(display);

  if (tmp.empty()) return false;
 
  // resize
  cv::Size sz = Config::inst()->getImSize();
  cv::Mat tmp1;
  cv::resize(tmp, tmp1, sz, 0, 0, cv::INTER_NEAREST );
  setImage("out", tmp);

  setDirty(); 
 
  return true;
}
void FinalMessagePage::actionPerformed( GUIComponent *inTarget ) {
    if( inTarget == &mQuitButton ) {
        setSignal( "quit" );
        }
    }