예제 #1
0
void dump_cache(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {

	if (hardware->dmi.cache_count == 0) {
			CREATE_NEW_OBJECT;
				add_s("dmi.warning","No cache structure found");
			FLUSH_OBJECT;
			return;
	}

	for (int cache=0; cache<hardware->dmi.cache_count;cache++) {
		CREATE_NEW_OBJECT;
		add_i("Cache", cache);
		add_s("dmi.cache.socket_designation", hardware->dmi.cache[cache].socket_designation);
		add_s("dmi.cache.configuration", hardware->dmi.cache[cache].configuration);
		add_s("dmi.cache.mode", hardware->dmi.cache[cache].mode);
		add_s("dmi.cache.location", hardware->dmi.cache[cache].location);
		add_i("dmi.cache.installed_size (KB)", hardware->dmi.cache[cache].installed_size);
		add_i("dmi.cache.max_size (KB)", hardware->dmi.cache[cache].max_size);
		add_s("dmi.cache.supported_sram_types", hardware->dmi.cache[cache].supported_sram_types);
		add_s("dmi.cache.installed_sram_types", hardware->dmi.cache[cache].installed_sram_types);
		add_i("dmi.cache.speed (ns)", hardware->dmi.cache[cache].speed);
		add_s("dmi.cache.error_correction_type", hardware->dmi.cache[cache].error_correction_type);
		add_s("dmi.cache.system_type", hardware->dmi.cache[cache].system_type);
		add_s("dmi.cache.associativity", hardware->dmi.cache[cache].associativity);
		FLUSH_OBJECT;
	}
}
예제 #2
0
void dump_vesa(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {

	CREATE_NEW_OBJECT;
	add_hb(is_vesa_valid);
	if (hardware->is_vesa_valid) {
		char buffer[64]={0};
		snprintf(buffer,sizeof(buffer),"%d.%d", hardware->vesa.major_version, hardware->vesa.minor_version);
		add_s("vesa.version",buffer);
		add_hs(vesa.vendor);
		add_hs(vesa.product);
		add_hs(vesa.product_revision);
		add_hi(vesa.software_rev);
		memset(buffer,0,sizeof(buffer));
		snprintf(buffer,sizeof(buffer),"%d KB",hardware->vesa.total_memory*64);
		add_s("vesa.memory",buffer);
		add_i("vesa.modes",hardware->vesa.vmi_count);
		FLUSH_OBJECT;
		for (int i = 0; i < hardware->vesa.vmi_count; i++) {
		        struct vesa_mode_info *mi = &hardware->vesa.vmi[i].mi;
		        if ((mi->h_res == 0) || (mi->v_res == 0))
				continue;
			CREATE_NEW_OBJECT;
			memset(buffer,0,sizeof(buffer));
			snprintf(buffer,sizeof(buffer),"0x%04x",hardware->vesa.vmi[i].mode + 0x200);
			add_s("vesa.kernel_mode",buffer);
			add_i("vesa.hres",mi->h_res);
			add_i("vesa.vres",mi->v_res);
			add_i("vesa.bpp",mi->bpp);
			FLUSH_OBJECT;
		}
	} else {
		FLUSH_OBJECT;
	}
	to_cpio("vesa");
}
예제 #3
0
void dump_memory_modules(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {

	if (hardware->dmi.memory_module_count == 0) {
			CREATE_NEW_OBJECT;
				add_s("dmi.warning","No memory module structure found");
			FLUSH_OBJECT;
			return;
	}

	for (int module=0; module<hardware->dmi.memory_module_count;module++) {
		if (hardware->dmi.memory_module[module].filled == false) {
			char msg[64]={0};
			snprintf(msg,sizeof(msg),"Module %d doesn't contain any information", module);

			CREATE_NEW_OBJECT;
				add_s("dmi.warning",msg);
			FLUSH_OBJECT;
			continue;
		}

		CREATE_NEW_OBJECT;
		add_i("Memory module", module);
		add_s("dmi.memory_module.socket_designation", hardware->dmi.memory_module[module].socket_designation);
		add_s("dmi.memory_module.bank_connections", hardware->dmi.memory_module[module].bank_connections);
		add_s("dmi.memory_module.speed", hardware->dmi.memory_module[module].speed);
		add_s("dmi.memory_module.type", hardware->dmi.memory_module[module].type);
		add_s("dmi.memory_module.installed_size", hardware->dmi.memory_module[module].installed_size);
		add_s("dmi.memory_module.enabled_size", hardware->dmi.memory_module[module].enabled_size);
		add_s("dmi.memory_module.error_status", hardware->dmi.memory_module[module].error_status);
		FLUSH_OBJECT;
	}
}
예제 #4
0
void dump_memory_size(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {
	CREATE_NEW_OBJECT;
		add_s("dmi.item","memory size");
		add_i("dmi.memory_size (KB)",hardware->detected_memory_size);
		add_i("dmi.memory_size (MB)",(hardware->detected_memory_size + (1 << 9)) >> 10);
	FLUSH_OBJECT;
}
예제 #5
0
void dump_base_board(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {

	if (hardware->dmi.base_board.filled == false) {
		CREATE_NEW_OBJECT;
			add_s("dmi.warning","no base_board structure found");
		FLUSH_OBJECT;
		return;
	}

	CREATE_NEW_OBJECT;
	add_s("dmi.item","base_board");
	add_hs(dmi.base_board.manufacturer);
	add_hs(dmi.base_board.product_name);
	add_hs(dmi.base_board.version);
	add_hs(dmi.base_board.serial);
	add_hs(dmi.base_board.asset_tag);
	add_hs(dmi.base_board.location);
	add_hs(dmi.base_board.type);
	for (int i = 0; i < BASE_BOARD_NB_ELEMENTS; i++) {
		if (((bool *) (&hardware->dmi.base_board.features))[i] == true) {
			add_s("dmi.base_board.features",(char *)base_board_features_strings[i]);
		}
	}

	for (unsigned int i = 0; i < sizeof hardware->dmi.base_board.devices_information /
		         sizeof *hardware->dmi.base_board.devices_information; i++) {
	        if (strlen(hardware->dmi.base_board.devices_information[i].type)) {
			add_s("dmi.base_board.devices_information.type", hardware->dmi.base_board.devices_information[i].type);
			add_i("dmi.base_board.devices_information.status", hardware->dmi.base_board.devices_information[i].status);
			add_s("dmi.base_board.devices_information.description", hardware->dmi.base_board.devices_information[i].description);
		}
	}
	FLUSH_OBJECT;
}
예제 #6
0
int main() {

	printf("start testing\n"); 

	int from = -100, to = 100; 
	for (int i = from; i <= to; i++) {
		assert(0 - i == negate(i)); 
		assert(((i % 2) == 0) == is_even(i)); 
		assert(i * 2 == multiply_by_two(i)); 
		if (is_even(i)) {
			assert(i / 2 == divide_by_two(i)); 
		}
	}

	for (int i = from;i <= to; i++) {
		for (int j = from; j <= to; j++) {
			assert(i + j == add_i(i, j)); 
			assert(i - j == subtract(i, j)); 
			assert(i * j == multiply(i, j)); 
		}
	}

	printf("end testing\n"); 
	return 0; 
}
예제 #7
0
int main(int argc, char *argv[]) {
    int resul;

    if (argc != NARGS) {
       printf ("Uso: calc [arg1] [op] [arg2], onde arg1 e arg são inteiros e op é +, -, x, / \n");
       exit(0);
    }

    switch (*argv[2]) {
    case '+': resul = add_i(atoi(argv[1]), atoi(argv[3]));
              break;
    case '-': resul = sub_i(atoi(argv[1]), atoi(argv[3]));
              break;
    case 'x': resul = mul_i(atoi(argv[1]), atoi(argv[3]));
              break;
    case '/': resul = div_i(atoi(argv[1]), atoi(argv[3]));
              break;       
    default:
         printf("Operação inválida!\n");
         printf ("Uso: calc [arg1] [op] [arg2], onde arg1 e arg são inteiros e op é +, -, x, / \n");
         exit(0);
    }
    
    printf("     = %d\n", resul);
    exit(0);
}
예제 #8
0
void dump_memory_banks(struct s_hardware *hardware, ZZJSON_CONFIG *config, ZZJSON **item) {

	if (hardware->dmi.memory_count == 0) {
			CREATE_NEW_OBJECT;
				add_s("dmi.warning","No memory bank structure found");
			FLUSH_OBJECT;
			return;
	}

	for (int bank=0; bank<hardware->dmi.memory_count;bank++) {

		if (hardware->dmi.memory[bank].filled == false) {
			char msg[64]={0};
			snprintf(msg,sizeof(msg),"Bank %d doesn't contain any information", bank);

			CREATE_NEW_OBJECT;
				add_s("dmi.warning",msg);
			FLUSH_OBJECT;
			continue;
		}

		CREATE_NEW_OBJECT;
		add_i("Memory Bank", bank);
		add_s("dmi.memory.form_factor", hardware->dmi.memory[bank].form_factor);
		add_s("dmi.memory.type", hardware->dmi.memory[bank].type);
		add_s("dmi.memory.type_detail", hardware->dmi.memory[bank].type_detail);
		add_s("dmi.memory.speed", hardware->dmi.memory[bank].speed);
		add_s("dmi.memory.size", hardware->dmi.memory[bank].size);
		add_s("dmi.memory.device_set", hardware->dmi.memory[bank].device_set);
		add_s("dmi.memory.device_locator", hardware->dmi.memory[bank].device_locator);
		add_s("dmi.memory.bank_locator", hardware->dmi.memory[bank].bank_locator);
		add_s("dmi.memory.total_width", hardware->dmi.memory[bank].total_width);
		add_s("dmi.memory.data_width", hardware->dmi.memory[bank].data_width);
		add_s("dmi.memory.error", hardware->dmi.memory[bank].error);
		add_s("dmi.memory.vendor", hardware->dmi.memory[bank].manufacturer);
		add_s("dmi.memory.serial", hardware->dmi.memory[bank].serial);
		add_s("dmi.memory.asset_tag", hardware->dmi.memory[bank].asset_tag);
		add_s("dmi.memory.part_number", hardware->dmi.memory[bank].part_number);
		FLUSH_OBJECT;
	}
}
예제 #9
0
//helper function for ray terrain intersection
static bool cellIntersect(float h1, float h2, float h3, float h4,
                          float X, float Y,
                          const std::tuple<float, float, float> &nDir, float dirLen,
                          const WFMath::Point<3> &sPt,
                          WFMath::Point<3> &intersection,
                          std::tuple<float, float, float> &normal, float &par)
{
  //ray plane intersection roughly using the following:
  //parametric ray eqn:  p=po + par V
  //plane eqn: p dot N + d = 0
  //
  //intersection:
  // -par = (po dot N + d ) / (V dot N)
  //
  //
  // effectively we calculate the ray parametric variable for the
  // intersection of the plane corresponding to each triangle
  // then clip them by endpints of the ray, and by the sides of the square
  // and by the diagonal
  //
  // if they both still intersect, then we choose the earlier intersection


  //intersection points for top and bottom triangles
  WFMath::Point<3> topInt, botInt;

  //point to use in plane equation for both triangles
  std::tuple<float, float, float> p0 = std::tuple<float, float, float>(X, Y, h1);

  // square is broken into two triangles
  // top triangle |/
  bool topIntersected = false;
  std::tuple<float, float, float> topNormal(h2 - h3, h1 - h2, 1.0);
  normalise_i(topNormal);
  float t = dot(nDir, topNormal);

  decltype(t) topP = 0.0;

  if ((t > 1e-7) || (t < -1e-7))
  {
    topP = -(dot(std::tuple<float, float, float>(sPt[0], sPt[1], sPt[2]), topNormal)
             - dot(topNormal, p0)) / t;
    topInt = translate(sPt, scale(nDir, topP));
    //check the intersection is inside the triangle, and within the ray extents
    if ((topP <= dirLen) && (topP > 0.0) &&
        (topInt[0] >= X ) && (topInt[1] <= Y + 1 ) &&
        ((topInt[0] - topInt[1]) <= (X - Y)) )
    {
      topIntersected = true;
    }
  }

  // bottom triangle /|
  bool botIntersected = false;
  std::tuple<float, float, float> botNormal(h1 - h4, h4 - h3, 1.0);
  normalise_i(botNormal);
  auto b = dot(nDir, botNormal);
  decltype(b) botP = 0.0;

  if ((b > 1e-7) || (b < -1e-7))
  {
    botP = -(dot(std::tuple<float, float, float>(sPt[0], sPt[1], sPt[2]), botNormal)
             - dot(botNormal, p0)) / b;
    botInt = translate(sPt, scale(nDir, botP));
    //check the intersection is inside the triangle, and within the ray extents
    if ((botP <= dirLen) && (botP > 0.0) &&
        (botInt[0] <= X + 1 ) && (botInt[1] >= Y ) &&
        ((botInt[0] - botInt[1]) >= (X - Y)) )
    {
      botIntersected = true;
    }
  }

  if (topIntersected && botIntersected)     //intersection with both
  {
    if (botP <= topP)
    {
      intersection = botInt;
      normal = botNormal;
      par = botP / dirLen;
      if (botP == topP)
      {
        add_i(normal, topNormal);
        normalise_i(normal);
      }
      return true;
    }
    else
    {
      intersection = topInt;
      normal = topNormal;
      par = topP / dirLen;
      return true;
    }
  }
  else if (topIntersected)     //intersection with top
  {
    intersection = topInt;
    normal = topNormal;
    par = topP / dirLen;
    return true;
  }
  else if (botIntersected)     //intersection with bot
  {
    intersection = botInt;
    normal = botNormal;
    par = botP / dirLen;
    return true;
  }

  return false;
}
예제 #10
0
int main(int argc, char *argv[]){
	// printf("Hello world\n");
	printf("%d", add_i(1, 2));
	return 0;
}