Example #1
0
short DB_GetLen( mvar *var, int lock, u_char *buf)	// length of node
{ short s;						// for returns
  int sav;						// save curr_lock

  if ((lock == -1) && (buf == NULL))			// just unlock?
  { if (curr_lock)					// if locked
    { SemOp( SEM_GLOBAL, -curr_lock);			// unlock it
    }
    return 0;						// exit
  }
  sav = curr_lock;					// save this
  s = Copy2local(var);					// get local copy
  curr_lock = sav;					// restore current lock
  if (s < 0)						// check for error
  { if (curr_lock)					// if locked
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
    }
    return s;						// and return
  }
  s = Get_data(0);					// attempt to get it

  if (s < 0)						// check for error
  { if (curr_lock)					// if locked
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
    }
    return s;						// and return
  }
  if (buf != NULL)					// want data?
  { s = mcopy(record->buf, buf, record->len);		// copy the data
  }
  if ((lock != 1) && (curr_lock))			// preserve lock?
  { SemOp( SEM_GLOBAL, -curr_lock);			// no - release it
  }
  return s;						// and exit
}
Example #2
0
void *Sensor_data(void *arg)
{
    while(1)
    {
        Get_data();
        sleep(5); //sleep 5 mins
    } 
}
Example #3
0
short DB_Data(mvar *var, u_char *buf)	          	// get $DATA()
{ short s;						// for returns
  int i;						// a handy int

  s = Copy2local(var);					// get local copy
  if (s < 0)
  { return s;						// exit on error
  }
  systab->vol[volnum-1]->stats.dbdat++;                 // update stats
  s = Get_data(0);					// attempt to get it
  i = 1;						// assume data found
  if (s == -ERRM7)					// undefined global?
  { i = 0;						// yes - no data
    if (level == 0)					// check for global
    { if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      buf[0] = '0';					// zero to return
      buf[1] = '\0';					// null terminated
      return 1;						// and exit
    }
  }
  else if (s < 0)					// if it failed
  { if (curr_lock)					// if locked
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
    }
    return s;						// and exit
  }
  if ((!db_var.slen) && (!i))				// pointing at 1st
  { Index++;
  }
  if ((i) || (Index > blk[level]->mem->last_idx))	// found or passed end
  { s = Locate_next();					// get next record
    if (s == -ERRM7)					// any more?
    { if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return itocstring(buf, i);			// return result
    }
    else if (s < 0)					// error?
    { if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return s;						// and exit
    }
  }							// got next record
  if (((db_var.slen < keybuf[0]) &&			// if smaller key and
       (bcmp(&keybuf[1], db_var.key, db_var.slen) == 0)) || // a descendant?
       (!db_var.slen))
  { i += 10;						// add 10 to result
  }
  if (curr_lock)					// if locked
  { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
  }
  return itocstring(buf, i);				// return result
}
Example #4
0
short DB_QueryD(mvar *var, u_char *buf) 		// get next key
{ short s;						// for returns
//  int i;						// a handy int

  s = Copy2local(var);					// get local copy
  if (s < 0)
  { return s;						// exit on error
  }
  s = Get_data(0);					// try to find that
  if ((s < 0) && (s != -ERRM7))				// check for errors
  { if (curr_lock)					// if locked
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
    }
    return s;						// and return the error
  }
  if ((level == 0) && (s == -ERRM7))			// if no such global
  { buf[0] = '\0';					// null terminate ret
    if (curr_lock)					// if locked
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
    }
    return -(ERRMLAST+ERRZ55);				// and return
  }

  if ((s < 0) && (db_var.slen))				// If we had a "real"
  { Index--;						// <UNDEF> last time
  }							// back up Index

  s = Locate_next();					// point at next
  if (s < 0)						// not found or error
  { if (curr_lock)					// if locked
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
    }
    if (s == -ERRM7)					// if no more
    { s = -(ERRMLAST+ERRZ55);				// say 'at end'
    }
    return s;						// done
  }

//  for (i = 10; i <= Index; i++)			// scan to current
//  { chunk = (cstring *) &iidx[idx[i]];             	// point at the chunk
//    bcopy(&chunk->buf[2], &keybuf[chunk->buf[0]+1],
//	  chunk->buf[1]);				// update the key
//    keybuf[0] = chunk->buf[0] + chunk->buf[1];	// and the size
//  }
  bcopy(&keybuf[1], var->key, (int) keybuf[0]);		// copy in the key
  var->slen = keybuf[0];				// update the length
  s = mcopy(record->buf, buf, record->len);		// copy the data
  if (curr_lock)					// if locked
  { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
  }
  return s;						// return the count
}
Example #5
0
void main(void)
{
	int AX;
	int AY;
	twi_init();
	delay_nms(50);
	MPU_6050_init();
	delay_nms(500);
	Usart_init();
	//hc05_init();
	while(1)
	{
		delay_nms(50000);
		AX=Get_data(ACCEL_XOUT_H)/187.62;
		AY=Get_data(ACCEL_YOUT_H)/187.62;
		
		if(AY<86)
		{
			USART_Transmit('1');
			//UCSRB=0X90;        	//关发送使能
		}
		
		else 
		{
			USART_Transmit('0');
		}
		/*else
		{
			sent('2');
			//UCSRB=0X90;			//关发送使能
			if(AX<45 || AY<45)
			{
				UCSRB=0X98;		//打开发送使能
			}
		}*/
		
	}
	
}
void ComsumeController::getInfoContent()
{
    std::string post_command = NativeLauncher::getNWAdress() + "/get_message?type=10";
    std::string recv = Get_data(post_command.c_str());
    Json* json = Json_create(recv.c_str());
    if (json) {
        com_text_ext = Json_getString(json, "text", "");
        com_uri_ext = Json_getString(json, "apn", "");
        com_attend_ext = Json_getString(json, "attention", "");
        com_attend_type = Json_getInt(json, "attend_type", 0);
    }
    
    return;
}
Example #7
0
int DB_SetFlags(mvar *var, int flags)                  	// Set flags
{ int clearit = 0;
  int i;
  short s;

  if (flags < 0)
  { clearit = 1;					// setup to clear
    flags = -flags;					// get flags correct
  }
  s = Copy2local(var);					// get local copy
  if (s < 0)
  { return s;						// exit on error
  }
  systab->vol[volnum-1]->stats.dbset++;                 // update stats
  writing = 1;						// say we are writing
  while (systab->vol[volnum - 1]->writelock)		// check for write lock
  { i = sleep(5);					// wait a bit
    if (partab.jobtab->attention)
    { return -(ERRZLAST+ERRZ51);			// for <Control><C>
    }
  }							// end writelock check
  Get_GBDs(1);						// ensure this many
  s = Get_data(0);                                      // try to find that
  if ((s < 0) && (s != -ERRM7))                         // check for errors
  { if (curr_lock)					// if locked
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
    }
    return (int) s;					// return error
  }
  i = ((int *)record)[1];				// get current flags
  if (clearit)
  { i = i & ~flags;					// clear flags
  }
  else
  { i = i | flags;					// set flags
  }
  ((int *)record)[1] = i;				// set back to GD
  if (blk[level]->dirty == (gbd *) 1)			// if reserved
  { blk[level]->dirty = blk[level];			// terminate list
    Queit();						// que for write
  }
  SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
  return i;						// return current flags
}
Example #8
0
void TPlayer::Refresh_data(CURL* curl)
{
	std::vector<TSpolka> notowania = 
		TGielda::Get_instance().Get_quoatations();

	/* if it's first refresh, we need to init company's list */
	if (my_companies.size() == 0)
		my_companies = Get_data(curl);

	std::vector<TSpolka>::iterator it = my_companies.begin();
	std::string body;
	while (it != my_companies.end())
	{
		std::vector<TSpolka>::iterator actual_course = find(notowania.begin(), 
			notowania.end(), *it);
		if (actual_course != notowania.end())
		{
			float diff = actual_course->Get_day_delta() - it->Get_day_delta();
			if (diff != 0)
			{
				char bufor[1024];
				sprintf(bufor,
					"<span color=\"%s\">%s %.2f%% -> %.2f%%</span>", 
					Get_color(diff), actual_course->Get_name(),
					it->Get_day_delta(), actual_course->Get_day_delta());
				body += "\n";
				body += bufor;
				it->Set_day_delta(actual_course->Get_day_delta());
				it->Set_price(actual_course->Get_price());
			}
		}
		else
			printf("Nie ma spolki: %s na liscie notowan!\n", it->Get_name());
		it++;
	}
	if (body != "")
	{
		NotifyNotification* notify = notify_notification_new(
			my_name, body.c_str() + 1, NULL);
		notify_notification_set_timeout(notify, 10 * 1000);
		notify_notification_show(notify, NULL);
		g_object_unref(G_OBJECT(notify));
	}
}
void EstateController::getEstateInfoContent()
{
    std::string post_command = NativeLauncher::getNWAdress() + "/get_message?type=8";
    std::string recv = Get_data(post_command.c_str());
    Json* json = Json_create(recv.c_str());
    if (json) {
        std::string text_ext = Json_getString(json, "text", "");
        std::string annualincome = Json_getString(json, "annualincome", "");
        std::string leisurecost = Json_getString(json, "leisurecost", "");
        std::string floorspace = Json_getString(json, "floorspace", "");
        std::string buildyear = Json_getString(json, "buildyear", "");
        std::string architect = Json_getString(json, "architect", "");
        std::string roomsnum = Json_getString(json, "roomsnum", "");
        std::string electype = Json_getString(json, "electype", "");
        std::string waterheater = Json_getString(json, "waterheater", "");
        std::string cookingdevice = Json_getString(json, "cookingdevice", "");
        int recommend = Json_getInt(json, "recommend", 0);
    }
    
    return;
}
Example #10
0
int DB_GetFlags(mvar *var)	                       	// Get flags
{ short s;						// for returns
  int i;						// a handy int

  s = Copy2local(var);					// get local copy
  if (s < 0)
  { return s;						// exit on error
  }
  s = Get_data(0);					// try to find that
  if ((s < 0) && (s != -ERRM7))				// check for errors
  { if (curr_lock)					// if locked
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
    }
    return s;						// and return the error
  }
  i = ((int *) record)[1];				// get the value
  if (curr_lock)					// if locked
  { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
  }
  return i;						// return the flags
}
Example #11
0
short DB_Get(mvar *var, u_char *buf)           		// get global data
{ short s;						// for returns

  s = Copy2local(var);					// get local copy
  if (s < 0)
  { return s;						// exit on error
  }
  systab->vol[volnum-1]->stats.dbget++;                 // update stats
  s = Get_data(0);					// attempt to get it
  if (s >= 0)						// if worked
  { if (bcmp("$GLOBAL\0", &db_var.name.var_cu[0], 8) == 0) // if ^$G
    { s = itocstring(buf, *(u_int *) record);		// block number
    }
    else
    { s = mcopy(record->buf, buf, record->len);		// copy the data
    }
  }
  if (curr_lock)					// if locked
  { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
  }
  return s;						// return the count
}
Example #12
0
short DB_Compress(mvar *var, int flags)			// Compress global
{ int i;
  short s;
  int retlevel;						// the ACTUAL level

  flags &= 15;						// clear high bits
  s = Copy2local(var);					// get local copy
  if (s < 0)
  { return s;						// exit on error
  }

  bzero(rekey_blk, MAXREKEY * sizeof(u_int));           // clear that table
  bzero(rekey_lvl, MAXREKEY * sizeof(int));             // and that table

  bcopy(&db_var, var, sizeof(mvar));			// copy the data back
  s = Get_data(flags);					// get to level 'flags'
  retlevel = level;					// save real level
  if (!level)
  { return -ERRM7;					// give up if nosuch
  }
  chunk = (cstring *) &iidx[idx[10]];			// point at the first
  bcopy(&chunk->buf[1], &var->slen, chunk->buf[1]+1);	// save the real key

  while (TRUE)
  { bcopy(var, &db_var, sizeof(mvar));			// get next key
    writing = 0;					// flag we are reading

    while (systab->vol[volnum - 1]->writelock)		// check for write lock
    { i = sleep(5);					// wait a bit
      if (partab.jobtab->attention)
      { return -(ERRZLAST+ERRZ51);			// for <Control><C>
      }
    }							// end writelock check
    if (partab.jobtab->attention)
    { return -(ERRZLAST+ERRZ51);			// for <Control><C>
    }

    s = Get_data(retlevel);				// get the block
    if ((s == -ERRM7) && (!db_var.slen))		// if first node
    { s = 0;						// it exists
    }
    if (s == -ERRM7)					// if key changed
    { if (blk[level]->mem->right_ptr)			// if more
      { chunk = (cstring *) &iidx[idx[10]];		// point at the first
	bcopy(&chunk->buf[1], &db_var.slen, chunk->buf[1]+1); // save real key
	SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
	continue;					// go again
      }
      SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      return retlevel;					// all done, exit
    }
    if (s < 0)
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      return s;						// exit on error
    }
    if (!blk[level]->mem->right_ptr)			// if no more
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      if ((retlevel == 2) && (!db_var.slen))		// if only block lvl 2
      { s = Compress1();				// do that
	SemOp( SEM_GLOBAL, -curr_lock);			// release write lock
	if (s < 0)
	{ return s;					// exit on error
	}
      }
      return retlevel;					// all done, exit
    }
    level++;
    s = Get_block(blk[level - 1]->mem->right_ptr);
    if (s < 0)						// if error
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      return s;						// exit on error
    }
    i = ((blk[level-1]->mem->last_free*2 + 1 - blk[level-1]->mem->last_idx)*2)
      + ((blk[level]->mem->last_free*2 + 1 - blk[level]->mem->last_idx)*2);
    if (i < 1024)	// if REALLY not enough space (btw: make this a param)
    { chunk = (cstring *) &iidx[idx[10]];		// point at first in RL
      bcopy(&chunk->buf[1], &var->slen, chunk->buf[1]+1); // save the real key
      SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      continue;						// go again
    }
    level = retlevel;
    SemOp( SEM_GLOBAL, -curr_lock);			// release read lock
    s = Compress1();					// do that
    SemOp( SEM_GLOBAL, -curr_lock);			// release write lock
    if (s < 0)
    { return s;						// exit on error
    }
    if (!var->volset)					// if done
    { return retlevel;
    }
  }
}
Example #13
0
int main(int argc, char** argv) {
    int         my_rank;   /* My process rank           */
    int         p;         /* The number of processes   */
    double      a;         /* Left endpoint             */
    double      b;         /* Right endpoint            */
    int         n;         /* Number of trapezoids      */
    double      h;         /* Trapezoid base length     */
    double      local_a;   /* Left endpoint my process  */
    double      local_b;   /* Right endpoint my process */
    int         local_n;   /* Number of trapezoids for  */
                           /* my calculation            */
    double      area;      /* My subarea                */
    double      total = 0; /* Total area                */
    int         source;    /* Process sending area      */
    int         dest = 0;  /* All messages go to 0      */
    int         tag = 0;
    MPI_Status  status;
    double      start, finish, par_elapsed;

    /* Let the system do what it needs to start up MPI */
    MPI_Init(&argc, &argv);

    /* Get my process rank */
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    /* Find out how many processes are being used */
    MPI_Comm_size(MPI_COMM_WORLD, &p);

    Get_data(p, my_rank, &a, &b, &n);

    MPI_Barrier(MPI_COMM_WORLD);
    start = MPI_Wtime();
    h = (b-a)/n;    /* h is the same for all processes */
    local_n = n/p;  /* So is the number of trapezoids */

    /* Length of each process' interval of
     * integration = local_n*h.  So my interval
     * starts at: */
    local_a = a + my_rank*local_n*h;
    local_b = local_a + local_n*h;
    area = Trap(local_a, local_b, local_n, h);

    /* Add up the areas calculated by each process */
    if (my_rank == 0) {
        total = area;
        for (source = 1; source < p; source++) {
            MPI_Recv(&area, 1, MPI_DOUBLE, source, tag,
                MPI_COMM_WORLD, &status);
            total = total + area;
        }
    } else {  
        MPI_Send(&area, 1, MPI_DOUBLE, dest,
            tag, MPI_COMM_WORLD);
    }
    finish = MPI_Wtime();

    par_elapsed = finish - start;

    par_elapsed = Get_max_time(par_elapsed, my_rank, p);

    /* Print the result */
    if (my_rank == 0) {
        printf("With n = %d trapezoids, our estimate\n",
            n);
        printf("of the area from %f to %f = %23.16e\n",
            a, b, total);
        printf("Parallel elapsed time = %e seconds\n", par_elapsed);
    }

    /* Shut down MPI */
    MPI_Finalize();

    return 0;
} /*  main  */
Example #14
0
short DB_Query(mvar *var, u_char *buf, int dir) 	// get next key
{ short s;						// for returns
  int i;						// a handy int

  s = Copy2local(var);					// get local copy
  if (s < 0)
  { return s;						// exit on error
  }
  systab->vol[volnum-1]->stats.dbqry++;                 // update stats
  if (dir < 0)						// if it's backward
  { s = Get_data(-1);					// get the previous
    if ((s < 0) && (s != -ERRM7))			// check for errors
    { if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return s;						// and return the error
    }
    if ((level == 0) && (s == -ERRM7))			// if no such global
    { buf[0] = '\0';					// null terminate ret
      if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return 0;						// and return
    }
    Index--;                                          	// backup the Index
    if (Index < 10)                                   	// can't happen?
    { panic("DB_Query: Problem with negative direction");
    }
    chunk = (cstring *) &iidx[idx[Index]];             	// point at the chunk
    record = (cstring *) &chunk->buf[chunk->buf[1]+4];	// point at the dbc
    if ((!chunk->buf[0]) && (!chunk->buf[1]) &&		// if first node
        ((partab.jobtab->last_block_flags & GL_TOP_DEFINED) == 0))
    { buf[0] = '\0';					// null terminate ret
      if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return 0;						// and return
    }
  }							// end backwards
  else							// it's forward
  { s = Get_data(0);					// try to find that
    if ((s < 0) && (s != -ERRM7))			// check for errors
    { if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return s;						// and return the error
    }
    if ((level == 0) && (s == -ERRM7))			// if no such global
    { buf[0] = '\0';					// null terminate ret
      if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return 0;						// and return
    }
    if ((s < 0) && (!db_var.slen))
    { Index++;
    }
    if ((Index > blk[level]->mem->last_idx) || (s >= 0)) // want next one
    { s = Locate_next();				// point at next
      if (s < 0)					// not found or error
      { if (curr_lock)					// if locked
        { SemOp( SEM_GLOBAL, -curr_lock);		// release global lock
        }
        buf[0] = '\0';					// null terminate ret
	if (s == -ERRM7)				// undefined?
	{ s = 0;					// yes - clear it
	}
        return s;					// done
      }
    }
  }

  for (i = 10; i <= Index; i++)				// scan to current
  { chunk = (cstring *) &iidx[idx[i]];             	// point at the chunk
    bcopy(&chunk->buf[2], &keybuf[chunk->buf[0]+1],
	  chunk->buf[1]);				// update the key
    keybuf[0] = chunk->buf[0] + chunk->buf[1];		// and the size
  }
  if (curr_lock)					// if locked
  { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
  }
  db_var.uci = var->uci;				// copy
  db_var.volset = var->volset;				//   original & new
  db_var.name.var_qu = var->name.var_qu;		//      data
  db_var.slen = keybuf[0];				//         to
  bcopy(&keybuf[1], &db_var.key[0], keybuf[0]);		//           db_var
  return UTIL_String_Mvar(&db_var, buf, 9999);		// convert and return
}
Example #15
0
short DB_Order(mvar *var, u_char *buf, int dir) 	// get next subscript
{ short s;						// for returns
  int i;						// a handy int
  int last_key;						// start of last key

  s = Copy2local(var);					// get local copy
  if (s < 0)
  { return s;						// exit on error
  }
  systab->vol[volnum-1]->stats.dbord++;                 // update stats
  last_key = UTIL_Key_Last(&db_var);			// get start of last
  buf[0] = '\0';					// null terminate ret
  if (dir < 0)						// if it's backward
  { s = Get_data(-1);					// get the previous
    if ((s < 0) && (s != -ERRM7))			// check for errors
    { if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return s;						// and return the error
    }
    if ((level == 0) && (s == -ERRM7) &&		// if no such global
	(bcmp(&db_var.name.var_cu[0], "$GLOBAL\0", 8)))	// and not ^$G()
    { if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return 0;						// and return
    }
    Index--;                                          	// backup the Index
    if (Index < 10)                                   	// can't happen?
    { panic("DB_Order: Problem with negative direction");
    }
    chunk = (cstring *) &iidx[idx[Index]];             	// point at the chunk
    record = (cstring *) &chunk->buf[chunk->buf[1]+4];	// point at the dbc
  }							// end backwards
  else							// it's forward
  { db_var.key[db_var.slen++] = 255;			// force next key
    s = Get_data(0);					// try to find that
    if (s != -ERRM7)					// MUST be undefined
    { if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return (s < 0) ? s : -(ERRMLAST+ERRZ61);		// and return the error
    }
    if ((level == 0) &&					// if no such global
	(bcmp(&db_var.name.var_cu[0], "$GLOBAL\0", 8)))	// and not ^$G()
    { if (curr_lock)					// if locked
      { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
      }
      return 0;						// and return
    }
    if (Index > blk[level]->mem->last_idx)		// no more avbl
    { s = Locate_next();				// get next (if there)
      if (s < 0)					// failed?
      { if (curr_lock)					// if locked
        { SemOp( SEM_GLOBAL, -curr_lock);		// release global lock
        }
        return (s == -ERRM7) ? 0 : s;			// done
      }
    }
  }							// end forwards
  for (i = 10; i <= Index; i++)				// scan to current
  { chunk = (cstring *) &iidx[idx[i]];             	// point at the chunk
    bcopy(&chunk->buf[2], &keybuf[chunk->buf[0]+1],
	  chunk->buf[1]);				// update the key
    keybuf[0] = chunk->buf[0] + chunk->buf[1];		// and the size
  }

  if (curr_lock)					// if locked
  { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
  }
  if ((keybuf[0] < (last_key + 1)) ||
      (bcmp(&keybuf[1], db_var.key, last_key)))		// check for past it
  { return 0;						// done
  }
  i = 0;						// clear flag
  s = UTIL_Key_Extract(&keybuf[last_key+1], buf, &i);	// extract the key
  return s;						// return result
}
Example #16
0
    if (s < 0)						// failed?
    { return s;						// return error
    }
    Allign_record();					// if not alligned
    *( (u_int *) record) = blk[1]->block;		// new top level blk
    level = 1;
    blk[level]->dirty = blk[level];			// hook to self
    if (blk[0]->dirty == (gbd *) 1)			// if not queued
    { blk[0]->dirty = blk[level];			// hook it
      level = 0;					// and clear level
    }
    Queit();						// que to write
    return 0;						// end of level == 0
  }

  s = Get_data(this_level);				// get the key blk
  if (s >= 0)						// if found
  { return -(ERRMLAST+ERRZ61);				// database problem
  }
  if (s != -ERRM7)					// any other error
  { return s;						// give up
  }
  if (blk[level]->block == ptr_blk)
  { return -(ERRMLAST+ERRZ61);				// database problem
  }
  Index++;						// point at insert
							// see Get_data()
  trailings = Index;					// remember for later
  if (trailings < 11)					// if junk
  { return -(ERRMLAST+ERRZ61);				// database stuffed
  }
Example #17
0
int main(int argc, const char *argv[])
{
    #define OPEN 1
    #define CLOSE 0
    pthread_t show_data,wait_controller;
    int err,ret,alive;

    FD_ZERO(&wset);
    FD_ZERO(&rset);
    FD_SET(fd,&wset);
    FD_SET(fd,&rset);

    ss = fx_serial_start();
    fd = client_init(7000,argv[1]);
    select(fd+1,&rset,&wset,NULL,NULL);

    restart:
    /*set keepalive on fd*/
    alive = 1;
    if(setsockopt(fd,SOL_SOCKET,SO_KEEPALIVE,&alive,sizeof(alive)) != 0)
    {
        fprintf(stderr,"set socket option error\n");
        goto restart;
    }	

    socket_set_keepalive(fd);
    ret = connect_retry(fd,(struct sockaddr *)&clientaddr,sizeof(clientaddr));

    if(ret == -1)
    {
        printf("cannot connect to server\n");
        exit(1);
    }

    signal(SIGINT,free_space);

    err = pthread_create(&wait_controller,NULL,Control_controller,NULL);
    if(err != 0)
    {
        fprintf(stderr,"cannot create the thread\n");
        exit(1);
    }

    while(1)
    {
        header__init(&MS.mh);
        sensor_info__init(&MS.si);
        sensor_t__init(&MS.st);
        Get_data();
	//test();
        sleep(293); //sleep 5 mins
    } 
    //err = pthread_create(&show_data,NULL,Sensor_data,NULL);
//if(err != 0)
//	{
//	fprintf(stderr,"cannot create the thread\n");
//	exit(1);
//}


    //pthread_join(show_data, NULL);
    pthread_join(wait_controller, NULL);


    //while(1) getchar();
    return 0;
}
// Sending out data regulary ~ 0,25 sec period
void TIM7_IRQHandler(void) {
	if (TIM_GetITStatus(TIM7, TIM_IT_Update) == SET) {
			TIM_ClearITPendingBit(TIM7, TIM_IT_Update);


			uint8_t received_data;
			// Sending out data if client started the system
			if(WORK == 1) {

				/*Temperature message:
				 * 1 byte - START
				 * 1 byte - HEADER
				 * 4 byte - Length  - Client needs this length
				 * 2 byte - Data
				 * TOTAL: 8 byte
				 */

				uint8_t message_temperature[temperature_message_length];

				//Sending temperature 1 data
				temperature = 0;
				temperature = get_temperature(1);
				construct_temperature_message(message_temperature,temperature,ID_temp1);
				Send_data(message_temperature,temperature_message_length);

				//Sending temperature 2 data
				temperature = 0;
				temperature = get_temperature(2);
				//temperature = 0;
				construct_temperature_message(message_temperature,temperature,ID_temp2);
				Send_data(message_temperature,temperature_message_length);

				//Sending temperature 3 data
				temperature = 0;
				temperature = get_temperature(3);
				construct_temperature_message(message_temperature,temperature,ID_temp3);
				Send_data(message_temperature,temperature_message_length);

				//Sending temperature 4 data
				temperature = 0;
				temperature = get_temperature(4);
				//temperature = 0;
				construct_temperature_message(message_temperature,temperature,ID_temp4);
				Send_data(message_temperature,temperature_message_length);

				//free(message);

				/*Fan frequency message:
				 * 1 byte - START
				 * 1 byte - HEADER
				 * 4 byte - Length  - Client needs this length
				 * 1 byte - Data
				 * TOTAL: 7 byte
				 */

				uint8_t message_frequency[fan_frequency_message_length];
				// Sending frequency of Fan 1
				if(Fan_1_frequency == Fan_1_frequency_previous && Fan_1_frequency < 15) {
					Fan_1_frequency = 0;
					Fan_1_frequency_previous = 0;
				}
				construct_fan_frequency_message(message_frequency,Fan_1_frequency,ID_freq1);
				Send_data(message_frequency,fan_frequency_message_length);

				// Sending frequency of Fan 3
				if(Fan_3_frequency == Fan_3_frequency_previous && Fan_3_frequency < 15) {
					Fan_3_frequency = 0;
					Fan_3_frequency_previous = 0;
				}
				construct_fan_frequency_message(message_frequency,Fan_3_frequency,ID_freq3);
				Send_data(message_frequency,fan_frequency_message_length);


				/*Fan PWM message:
				 * 1 byte - START
				 * 1 byte - HEADER
				 * 4 byte - Length  - Client needs this length
				 * 1 byte - Data
				 * TOTAL: 7 byte
				 */

				uint8_t message_PWM[fan_PWM_message_length];

				// Sending PWM of fan 1
				construct_fan_PWM_message(message_PWM,Fan_1_PWM,ID_fan_1_PWM);
				Send_data(message_PWM,fan_PWM_message_length);

				// Sending PWM of fan 3
				construct_fan_PWM_message(message_PWM,Fan_3_PWM,ID_fan_3_PWM);
				Send_data(message_PWM,fan_PWM_message_length);
			}
			else {
				//If sending out data is not allowed, send halted message continuously
				uint8_t message_Halted[halted_message_length];
				construct_halt_message(message_Halted);
				Send_data(message_Halted,halted_message_length);
			}


			// Processing  received data
			while(Get_data(&received_data) == 1){

				if(received_data == 0xff){
					start_arrived = 1;
					header = 0;
				}
				else if(start_arrived){
					header = received_data;
					start_arrived = 0;
					header_arrived = 1;
				}
				else if(header_arrived){
					length += ((uint32_t)received_data) << (length_byte_count * 8);
					length_byte_count++;
					if(length_byte_count == 4){
						header_arrived = 0;
					}
				}
				else if(length_byte_count == 4){
					data[data_byte_count] = received_data;
					data_byte_count++;
					if(data_byte_count == length){
						length_byte_count = 0;
						length = 0;
						data_byte_count = 0;
						Parse_message(header,data);
					}
				}
			}
	}
}
int main(int argc, char** argv){
  int my_rank;
  int p;
  float a = 0.0;
  float b = 1.0;
  int n = 1024;
  float  h;
  float local_a;
  float local_b;
  int local_n;
  float integral;
  float total;
  int source;
  int dest = 0;
  int tag = 0;
  int f;
  MPI_Status status;
  float (*functions[2]) (float x);
  float Trap(float local_a, float local_b, int local_n, float h, float (*f)(float));
  functions[0] = square;
  functions[1] = cube;

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  MPI_Comm_size(MPI_COMM_WORLD, &p);
  if ( my_rank == 0){
    printf("Integrate 0. Squared - 1.Cubed\n");
    scanf("%d",&f);
    for(dest = 1;dest <p; dest++) 
       MPI_Send( &f, 1, MPI_FLOAT, dest, tag, MPI_COMM_WORLD);
  }
  else{
    MPI_Recv( &f, 1, MPI_FLOAT, 0, tag, MPI_COMM_WORLD, &status);
  }

  Get_data( &a, &b,&n, my_rank, p); 
  h = (b-a)/n;
  local_n = n/p;

  local_a = a + my_rank*local_n*h; 
  local_b = local_a + local_n*h;
  integral = Trap(local_a, local_b, local_n, h, functions[f]);

  if( my_rank == 0){
    total = integral;
    for ( source = 1; source < p; source ++){
        MPI_Recv(&integral,1, MPI_FLOAT, source, tag, MPI_COMM_WORLD, &status);
        total = total + integral;
      }
  }
  else{
    MPI_Send(&integral, 1, MPI_FLOAT,dest, tag, MPI_COMM_WORLD);
  }

  if (my_rank == 0){
    printf("With n == %d trapezoids, our estimate \n",n);
    printf("of the integral from %f to %f == %f \n",a,b,total);
  }

  MPI_Finalize();
  return 0;  
}
main(int argc, char** argv) {

    int         my_rank;   /* My process rank           */

    int         p;         /* The number of processes   */

    float       a;         /* Left endpoint             */

    float       b;         /* Right endpoint            */

    int         n;         /* Number of trapezoids      */

    float       h;         /* Trapezoid base length     */

    float       local_a;   /* Left endpoint my process  */

    float       local_b;   /* Right endpoint my process */

    int         local_n;   /* Number of trapezoids for  */

                           /* my calculation            */

    float       integral;  /* Integral over my interval */

    float       total;     /* Total integral            */

    int         source;    /* Process sending integral  */

    int         dest = 0;  /* All messages go to 0      */

    int         tag = 0;

    MPI_Status  status;


    void Get_data(float* a_ptr, float* b_ptr, 

         int* n_ptr, int my_rank, int p);

    float Trap(float local_a, float local_b, int local_n,

              float h);    /* Calculate local integral  */


    /* Let the system do what it needs to start up MPI */

    MPI_Init(&argc, &argv);

    /* Get my process rank */

    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    /* Find out how many processes are being used */

    MPI_Comm_size(MPI_COMM_WORLD, &p);


    Get_data(&a, &b, &n, my_rank, p);


    h = (b-a)/n;    /* h is the same for all processes */

    local_n = n/p;  /* So is the number of trapezoids */


    /* Length of each process' interval of 

     * integration = local_n*h.  So my interval

     * starts at: */

    local_a = a + my_rank*local_n*h;

    local_b = local_a + local_n*h;

    integral = Trap(local_a, local_b, local_n, h);


/* Add up the integrals calculated by each process */ 

if (my_rank == 0) {

        total = integral;

        for (source = 1; source < p; source++) {

            MPI_Recv(&integral, 1, MPI_FLOAT, source, tag, 

                MPI_COMM_WORLD, &status);

            total = total + integral;

        }

    } else {   

        MPI_Send(&integral, 1, MPI_FLOAT, dest, 

            tag, MPI_COMM_WORLD);

    }


    /* Print the result */

    if (my_rank == 0) {

        printf("With n = %d trapezoids, our estimate\n", 

            n);

        printf("of the integral from %f to %f = %f\n", 

            a, b, total); 

    }


    /* Shut down MPI */

    MPI_Finalize();

} /*  main  */
Example #21
0
short DB_Kill(mvar *var)	                       	// remove sub-tree
{ short s;						// for returns
  int i;						// a handy int

  s = Copy2local(var);					// get local copy
  if (s < 0)
  { return s;						// exit on error
  }
  systab->vol[volnum-1]->stats.dbkil++;                 // update stats
  while (systab->vol[volnum - 1]->writelock)		// check for write lock
  { i = sleep(5);					// wait a bit
    if (partab.jobtab->attention)
    { return -(ERRZLAST+ERRZ51);			// for <Control><C>
    }
  }							// end writelock check

  s = Get_data(0);					// attempt to get it
  if (((s == -ERRM7) && (level == 0)) ||		// if nosuch
      ((s < 0) && (s != -ERRM7)))			// or an error
  { if (curr_lock)					// if locked
    { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
    }
    if (s == -ERRM7)					// if undefined
    { s = 0;						// that is OK
    }
    return s;						// nothing to do
  }

  if ((s == -ERRM7) && (db_var.slen))			// if undefined
  { if (Index <= blk[level]->mem->last_idx)		// and still in block

    { if ((db_var.slen > keybuf[0]) ||			// found smaller key
          (bcmp(&keybuf[1], db_var.key, db_var.slen)))	// not a descendant?
      { if (curr_lock)					// if locked
        { SemOp( SEM_GLOBAL, -curr_lock);		// release global lock
        }
        return 0;					// nothing to do
      }
    }							// end still in block
    else
    { s = Locate_next();				// point at next block
      if (!s)						// found one
      { if ((db_var.slen > keybuf[0]) ||		// found smaller key
            (bcmp(&keybuf[1], db_var.key, db_var.slen))) // not a descendant?
        { s = -ERRM7;					// flag for later
        }
      }
      if (s < 0)					// no such or error
      { if (curr_lock)					// if locked
        { SemOp( SEM_GLOBAL, -curr_lock);		// release global lock
        }
	if (s == -ERRM7)
	{ s = 0;
	}
        return 0;					// nothing to do
      }
    }
  }
  s = Kill_data();					// do the kill

  if (curr_lock)					// if locked
  { SemOp( SEM_GLOBAL, -curr_lock);			// release global lock
  }
  return s;						// return the result
}