Beispiel #1
0
////////////////////////////////////////////////////
// READ CONFIG FRM EEPROM
void storage_read_patch()
{
	if(eeprom_read(0) != MAGIC_COOKIE) {
		return;
	}
	int len = 0;
	int storage_ofs = 1;
	storage_read(global_storage(&len), len, &storage_ofs);
	storage_read(stack_storage(&len), len, &storage_ofs);
	storage_read(cv_storage(&len), len, &storage_ofs);
	storage_read(gate_storage(&len), len, &storage_ofs);
}
Beispiel #2
0
void init_socials() {
  // create the social table
  social_table = newHashtable();

  // open up the storage set
  STORAGE_SET       *set = storage_read(SOCIALS_FILE);
  STORAGE_SET_LIST *list = read_list(set, "socials");
  STORAGE_SET    *social = NULL;

  // parse all of the socials
  while( (social = storage_list_next(list)) != NULL)
    add_social(socialRead(social));
  
  // close the storage set
  storage_close(set);

  // add all of the socials to the command table
  HASH_ITERATOR *hash_i = newHashIterator(social_table);
  const char       *cmd = NULL;
  SOCIAL_DATA     *data = NULL;

  ITERATE_HASH(cmd, data, hash_i) {
    add_cmd(cmd, NULL, cmd_social, "player", FALSE);
    if(data->min_pos == POS_SITTING)
      add_cmd_check(cmd, chk_conscious);
    else if(data->min_pos == POS_STANDING)
      add_cmd_check(cmd, chk_can_move);
    else if(data->max_pos == POS_STANDING)
      add_cmd_check(cmd, chk_grounded);
  } deleteHashIterator(hash_i);
Beispiel #3
0
//
// initialize a new storage set
int PyStorageSet_init(PyStorageSet *self, PyObject *args, PyObject *kwds) {
  static char *kwlist[] = {"file", NULL};
  char            *file = NULL;

  // get the universal id
  if (!PyArg_ParseTupleAndKeywords(args, kwds, "|s", kwlist, &file)) {
    PyErr_Format(PyExc_TypeError,
		 "Storage Set initializers may only take filename args.");
    return -1;
  }

  // if we have a filename, load up the storage set there
  if(file != NULL) {
    self->set = storage_read(file);
    // the file doesn't exist... just make a blank storage set
    if(self->set == NULL)
      self->set = new_storage_set();
  }
  // no argument... make a new storage set
  else
    self->set = new_storage_set();

  // no errors
  return 0;
}
Beispiel #4
0
sp_read_ret_t *sp_read_1_svc(sp_read_arg_t * args, struct svc_req * req) {
    static sp_read_ret_t ret;
    uint32_t psize;
    storage_t *st = 0;
    DEBUG_FUNCTION;

    START_PROFILING_IO(read,
            args->nrb * rozofs_psizes[args->tid] * sizeof (bin_t));

    xdr_free((xdrproc_t) xdr_sp_read_ret_t, (char *) &ret);
    ret.status = SP_FAILURE;

    if ((st = storaged_lookup(args->sid)) == 0) {
        ret.sp_read_ret_t_u.error = errno;
        goto out;
    }
    psize = rozofs_psizes[args->tid];
    ret.sp_read_ret_t_u.bins.bins_len = args->nrb * psize * sizeof (bin_t);
    ret.sp_read_ret_t_u.bins.bins_val =
        (char *) xmalloc(args->nrb * psize * sizeof (bin_t));
    if (storage_read
        (st, args->fid, args->tid, args->bid, args->nrb,
         (bin_t *) ret.sp_read_ret_t_u.bins.bins_val) != 0) {
        ret.sp_read_ret_t_u.error = errno;
        goto out;
    }
    ret.status = SP_SUCCESS;

out:
    STOP_PROFILING(read);
    return &ret;
}
Beispiel #5
0
uint8_t storage_load_settings() {
	uint8_t buffer[STORAGE_SIZE];

	uint8_t success = storage_read(buffer, 0, sizeof(buffer)) == 1;
	if (success) {
		uint8_t offset = 0;
		for (uint8_t i=0; i<module_count; i++) {
			if (storage_is_storage_cleared()) {
				memcpy(storage_modules[i]->settings, storage_modules[i]->defaults, storage_modules[i]->size);
			} else {
				memcpy(storage_modules[i]->settings, buffer+offset, storage_modules[i]->size);
			}
			storage_modules[i]->onLoad();
			offset += storage_modules[i]->size;
		}
	}
	return success;
}
// Read data area at index
void data_services_read_index(void)
{
	// If beyond end of table return to waiting.
	if (data_services_table_index >= mavlink_parameter_block_count)
	{
		data_service_state = DATA_SERVICE_STATE_WAITING;
		if (data_services_user_callback != NULL) data_services_user_callback(true);
		data_services_user_callback = NULL;
		return;
	}

	uint16_t service_flags = mavlink_parameter_blocks[data_services_table_index].data_storage_flags;

	// Check the serialise flags to see if this table entry should be loaded
	if ((service_flags & data_services_serialize_flags) | (data_services_serialize_flags & STORAGE_FLAG_ALL))
	{
		uint16_t handle = mavlink_parameter_blocks[data_services_table_index].data_storage_area;
		uint16_t size = data_services_calc_item_size(data_services_table_index);
		uint16_t type = DATA_STORAGE_CHECKSUM_STRUCT; //mavlink_parameter_blocks[data_services_table_index].data_type;
	
		// TODO: Check here if data handle is ok 
	
		if (type == DATA_STORAGE_CHECKSUM_STRUCT)
		{
			if (storage_read(handle, data_services_buffer, size, &data_services_read_callback) == true)
			{
				data_service_state = DATA_SERVICE_STATE_READ_WAITING;
			}
			return;
		}
	}
	else
	{
		if (data_services_do_all_areas == true)
			data_services_table_index++;
		else
		{
			if (data_services_user_callback != NULL) data_services_user_callback(false);
			data_services_user_callback = NULL;
			data_service_state = DATA_SERVICE_STATE_WAITING;
		}
	}
}
Beispiel #7
0
//
// pre-emptively, we're preparing for very large persistent world (1mil+rooms).
// Something like this, it would be real nice to have database storage for.
// Alas, we're using flat files... so we're going to have to do some pretty
// creative hashing, so the folders don't overflow and become impossible to
// access. make two layers of directories, each with 500 folders. That will
// give us 4 room files to a folder, for a 1mil room persistent world. 
ROOM_DATA *worldGetPersistentRoom(WORLD_DATA *world, const char *key) {
  static char fname[MAX_BUFFER];
  if(!*key)
    return NULL;

  *fname = '\0';
  sprintf(fname, "%s/persistent/%lu/%lu/%s", 
	  worldGetPath(world),
	  pearson_hash8_1(key) % WORLD_BINS, 
	  pearson_hash8_2(key) % WORLD_BINS,
	  key);

  if(!file_exists(fname))
    return NULL;
  else {
    // log_string("%-30s get persistent: %s", key, fname);
    STORAGE_SET *set = storage_read(fname);
    ROOM_DATA  *room = roomRead(set);
    storage_close(set);
    worldPutRoom(world, key, room);
    room_to_game(room);
    return room;
  }
}
Beispiel #8
0
static inline void
main_menue (uint8_t cmd)
{
  TLogfileBeaconPacket pkt;

  /* ignore non-printable characters */
  if (cmd <= ' ')
    return;
  /* show key pressed */
  debug_printf ("%c\n", cmd);
  /* map lower case to upper case */
  if (cmd > 'a' && cmd < 'z')
    cmd -= ('a' - 'A');

  switch (cmd)
    {
    case '?':
    case 'H':
      debug_printf ("\n"
		    " *****************************************************\n"
		    " * OpenBeacon Tag - Bluetooth Console\n"
		    " *                  Version v" PROGRAM_VERSION "\n"
		    " * (C) 2011 Milosch Meriac <*****@*****.**>\n"
		    " *****************************************************\n"
		    " * H,?          - this help screen\n"
		    " * S            - Show device status\n"
		    " *\n"
		    " * E            - Erase Storage\n"
		    " * W            - Test Write Storage\n"
		    " * R            - Test Read Storage\n"
		    " * F            - Test WriteFill Storage\n"
		    " * M            - write 3 times and read them\n"
		    " *****************************************************\n"
		    "\n");
      break;
    case 'S':
      debug_printf ("\n"
		    " *****************************************************\n"
		    " * OpenBeacon Status Information                     *\n"
		    " *****************************************************\n");
      show_version ();
      spi_status ();
      acc_status ();
      storage_status ();
      debug_printf (" *****************************************************\n"
		    "\n");
      break;
  



    case 'M' :
	{
	uint32_t counter;
	debug_printf ("\nErasing Storage...\n\n");
	storage_erase ();
	debug_printf ("\nWriting Khalil 3 times...\n");
	counter = 0;
	const char data[] = "Khalil";
	const uint8_t buffer[32];
	while(counter < 3)
	{
	  storage_write (counter*sizeof(buffer), sizeof (buffer), &data);
	  counter ++;
	}
	debug_printf ("\n[DONE]\n");

	debug_printf("\n reading the data...\n");

	counter = 0;

	while(counter < 3)
	{
	storage_read (counter*sizeof(buffer), counter*sizeof(buffer) + sizeof (buffer), &buffer);
	hex_dump (buffer,0,sizeof (buffer));
	counter++;
	}

	break;
      }



    case 'E':
      debug_printf ("\nErasing Storage...\n\n");
      storage_erase ();
      g_storage_items = 0;
      break;

    case 'W':
      {
	const char hello[] = "Hello World!";
	debug_printf ("\n * writing '%s' (%i bytes)\n", hello,
		      sizeof (hello));
	storage_write (0, sizeof (hello), &hello);
      }
      break;

    case 'R':
      {
	const uint8_t buffer[32];
	debug_printf ("\n * reading %i bytes\n", sizeof (buffer));
	storage_read (0, sizeof (buffer), &buffer);
	hex_dump (buffer, 0, sizeof (buffer));
      }
      break;

    case 'F':
      {
	uint32_t counter;
	debug_printf ("\nErasing Storage...\n\n");
	storage_erase ();
	debug_printf ("\nFilling Storage...\n");
	counter = 0;
	while(counter < LOGFILE_STORAGE_SIZE)
	{
	  pkt.time = htonl(counter);
	  pkt.oid = htons(counter / sizeof(pkt));
	  pkt.strength = (counter / sizeof(pkt)) % MAX_POWER_LEVELS;
	  pkt.crc = crc8 (((uint8_t *) & pkt), sizeof (pkt) - sizeof (pkt.crc));
	  storage_write (counter, sizeof (pkt), &pkt);

	  counter += sizeof(pkt);
	}
	debug_printf ("\n[DONE]\n");
	break;
      }

    default:
      debug_printf ("Unknown command '%c' - please press 'H' for help \n",
		    cmd);
    }
  debug_printf ("\n# ");
}
Beispiel #9
0
void sp_read_1_svc_nb(void * pt, rozorpc_srv_ctx_t *req_ctx_p) {
    sp_read_arg_t * args = (sp_read_arg_t *) pt;
    static sp_read_ret_t ret;
    storage_t *st = 0;

    START_PROFILING_IO(read, args->nb_proj * rozofs_get_max_psize(args->layout)
            * sizeof (bin_t));
            
    ret.status = SP_FAILURE;            
    /*
    ** allocate a buffer for the response
    */
    req_ctx_p->xmitBuf = ruc_buf_getBuffer(storage_xmit_buffer_pool_p);
    if (req_ctx_p->xmitBuf == NULL)
    {
      severe("Out of memory STORAGE_NORTH_LARGE_POOL");
      ret.sp_read_ret_t_u.error = ENOMEM;
      req_ctx_p->xmitBuf  = req_ctx_p->recv_buf;
      req_ctx_p->recv_buf = NULL;
      goto error;         
    }


    // Get the storage for the couple (cid;sid)
    if ((st = storaged_lookup(args->cid, args->sid)) == 0) {
        ret.sp_read_ret_t_u.error = errno;
        goto error;
    }

    /*
    ** set the pointer to the bins
    */
    int position = storage_get_position_of_first_byte2write_from_read_req();
    uint8_t *pbuf = (uint8_t*)ruc_buf_getPayload(req_ctx_p->xmitBuf);     
    /*
    ** clear the length of the bins and set the pointer where data must be returned
    */  
    ret.sp_read_ret_t_u.rsp.bins.bins_val =(char *)(pbuf+position);  ;
    ret.sp_read_ret_t_u.rsp.bins.bins_len = 0;
#if 0 // for future usage with distributed cache 
    /*
    ** clear the optimization array
    */
    ret.sp_read_ret_t_u.rsp.optim.optim_val = (char*)sp_optim;
    ret.sp_read_ret_t_u.rsp.optim.optim_len = 0;
#endif    
    // Read projections
    if (storage_read(st, args->layout, (sid_t *) args->dist_set, args->spare,
            (unsigned char *) args->fid, args->bid, args->nb_proj,
            (bin_t *) ret.sp_read_ret_t_u.rsp.bins.bins_val,
            (size_t *) & ret.sp_read_ret_t_u.rsp.bins.bins_len,
            &ret.sp_read_ret_t_u.rsp.file_size) != 0) {
        ret.sp_read_ret_t_u.error = errno;
        goto error;
    }

    ret.status = SP_SUCCESS;
    storaged_srv_forward_read_success(req_ctx_p,&ret);
    /*
    ** check the case of the readahead
    */
    storage_check_readahead();
    goto out;
    
error:
    rozorpc_srv_forward_reply(req_ctx_p,(char*)&ret); 
    /*
    ** release the context
    */
out:
    rozorpc_srv_release_context(req_ctx_p);
    STOP_PROFILING(read);
    return ;
}