float to uint64 conversion
This commit is contained in:
@@ -85,8 +85,8 @@ namespace display::ui::hostblock
|
|||||||
|
|
||||||
// ===== Memory bar =====
|
// ===== Memory bar =====
|
||||||
float memValue, swapValue = 0.0f;
|
float memValue, swapValue = 0.0f;
|
||||||
if (metrics.memory.mem_total > 0)
|
if (metrics.memory.memory.total > 0)
|
||||||
memValue = metrics.memory.mem_used / metrics.memory.mem_total;
|
memValue = metrics.memory.memory.used / metrics.memory.memory.total;
|
||||||
|
|
||||||
memBar.draw(
|
memBar.draw(
|
||||||
fb,
|
fb,
|
||||||
@@ -96,16 +96,16 @@ namespace display::ui::hostblock
|
|||||||
text.drawTextOutlined(fb,
|
text.drawTextOutlined(fb,
|
||||||
x + MEM_BAR_TEXT_PADDING_X,
|
x + MEM_BAR_TEXT_PADDING_X,
|
||||||
cursorY + 8,
|
cursorY + 8,
|
||||||
"MEM: " + display::ui::text::formatFloat(metrics.memory.mem_used / 1073741824) + "/" + display::ui::text::formatFloat(metrics.memory.mem_total / 1073741824),
|
"MEM: " + display::ui::text::formatFloat(metrics.memory.memory.used / 1073741824) + "/" + display::ui::text::formatFloat(metrics.memory.memory.total / 1073741824),
|
||||||
display::ui::theme::text::TEXT,
|
display::ui::theme::text::TEXT,
|
||||||
display::ui::theme::text::OUTLINE,
|
display::ui::theme::text::OUTLINE,
|
||||||
display::ui::text::Font{"PixelFive-Regular", 5});
|
display::ui::text::Font{"PixelFive-Regular", 5});
|
||||||
|
|
||||||
cursorY += MEM_BAR_HEIGHT + SECTION_GAP;
|
cursorY += MEM_BAR_HEIGHT + SECTION_GAP;
|
||||||
|
|
||||||
if (metrics.memory.swap_total > 0)
|
if (metrics.memory.swap.total > 0)
|
||||||
{
|
{
|
||||||
swapValue = metrics.memory.swap_used / metrics.memory.swap_total;
|
swapValue = metrics.memory.swap.used / metrics.memory.swap.total;
|
||||||
|
|
||||||
memBar.draw(
|
memBar.draw(
|
||||||
fb,
|
fb,
|
||||||
@@ -115,7 +115,7 @@ namespace display::ui::hostblock
|
|||||||
text.drawTextOutlined(fb,
|
text.drawTextOutlined(fb,
|
||||||
x + MEM_BAR_TEXT_PADDING_X,
|
x + MEM_BAR_TEXT_PADDING_X,
|
||||||
cursorY + 8,
|
cursorY + 8,
|
||||||
"SWP: " + display::ui::text::formatFloat(metrics.memory.swap_used / 1073741824) + "/" + display::ui::text::formatFloat(metrics.memory.swap_total / 1073741824),
|
"SWP: " + display::ui::text::formatFloat(metrics.memory.swap.used / 1073741824) + "/" + display::ui::text::formatFloat(metrics.memory.swap.total / 1073741824),
|
||||||
display::ui::theme::text::TEXT,
|
display::ui::theme::text::TEXT,
|
||||||
display::ui::theme::text::OUTLINE,
|
display::ui::theme::text::OUTLINE,
|
||||||
display::ui::text::Font{"PixelFive-Regular", 5});
|
display::ui::text::Font{"PixelFive-Regular", 5});
|
||||||
@@ -131,13 +131,13 @@ namespace display::ui::hostblock
|
|||||||
int by = cursorY +
|
int by = cursorY +
|
||||||
i * (MEM_BAR_HEIGHT + SECTION_GAP);
|
i * (MEM_BAR_HEIGHT + SECTION_GAP);
|
||||||
|
|
||||||
float value = std::clamp(metrics.disks[i].used / metrics.disks[i].total, 0.0f, 1.0f);
|
float value = std::clamp(static_cast<float>(metrics.disks[i].metrics.used) / metrics.disks[i].metrics.total, 0.0f, 1.0f);
|
||||||
|
|
||||||
memBar.draw(fb, x + PADDING, by, value);
|
memBar.draw(fb, x + PADDING, by, value);
|
||||||
text.drawTextOutlined(fb,
|
text.drawTextOutlined(fb,
|
||||||
x + MEM_BAR_TEXT_PADDING_X,
|
x + MEM_BAR_TEXT_PADDING_X,
|
||||||
by + 8,
|
by + 8,
|
||||||
"D/" + metrics.disks[i].name + ": " + display::ui::text::formatFloat(metrics.disks[i].used / 1073741824) + "/" + display::ui::text::formatFloat(metrics.disks[i].total / 1073741824),
|
"D/" + metrics.disks[i].name + ": " + display::ui::text::formatFloat(metrics.disks[i].metrics.used / 1073741824) + "/" + display::ui::text::formatFloat(metrics.disks[i].metrics.total / 1073741824),
|
||||||
display::ui::theme::text::TEXT,
|
display::ui::theme::text::TEXT,
|
||||||
display::ui::theme::text::OUTLINE,
|
display::ui::theme::text::OUTLINE,
|
||||||
display::ui::text::Font{"PixelFive-Regular", 5});
|
display::ui::text::Font{"PixelFive-Regular", 5});
|
||||||
|
|||||||
+11
-11
@@ -117,12 +117,12 @@ namespace metrics
|
|||||||
}
|
}
|
||||||
|
|
||||||
Memory memory;
|
Memory memory;
|
||||||
memory.mem_total = mem_total;
|
memory.memory.total = mem_total;
|
||||||
memory.mem_available = mem_available;
|
memory.memory.available = mem_available;
|
||||||
memory.mem_used = mem_total - mem_available;
|
memory.memory.used = mem_total - mem_available;
|
||||||
memory.swap_total = swap_total;
|
memory.swap.total = swap_total;
|
||||||
memory.swap_available = swap_available;
|
memory.swap.available = swap_available;
|
||||||
memory.swap_used = swap_total - swap_available;
|
memory.swap.used = swap_total - swap_available;
|
||||||
return memory;
|
return memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,15 +137,15 @@ namespace metrics
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t total = static_cast<uint64_t>(vfs.f_blocks) * vfs.f_frsize;
|
uint64_t total = static_cast<uint64_t>(vfs.f_blocks) * vfs.f_frsize;
|
||||||
uint64_t free = static_cast<uint64_t>(vfs.f_bavail) * vfs.f_frsize;
|
uint64_t available = static_cast<uint64_t>(vfs.f_bavail) * vfs.f_frsize;
|
||||||
uint64_t used = total - free;
|
uint64_t used = total - available;
|
||||||
|
|
||||||
Disk d;
|
Disk d;
|
||||||
d.name = disk.at(0);
|
d.name = disk.at(0);
|
||||||
d.path = disk.at(1);
|
d.path = disk.at(1);
|
||||||
d.total = total;
|
d.metrics.total = total;
|
||||||
d.free = free;
|
d.metrics.available = available;
|
||||||
d.used = used;
|
d.metrics.used = used;
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "metrics/MemoryMetrics.h"
|
||||||
|
|
||||||
namespace metrics
|
namespace metrics
|
||||||
{
|
{
|
||||||
@@ -7,8 +8,6 @@ namespace metrics
|
|||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string path;
|
std::string path;
|
||||||
float used;
|
MemoryMetrics metrics;
|
||||||
float free;
|
|
||||||
float total;
|
|
||||||
};
|
};
|
||||||
} // namespace metrics
|
} // namespace metrics
|
||||||
|
|||||||
+22
-15
@@ -41,10 +41,12 @@ namespace metrics
|
|||||||
buf.writeFloat(f);
|
buf.writeFloat(f);
|
||||||
|
|
||||||
// Memory
|
// Memory
|
||||||
buf.writeFloat(memory.mem_used);
|
buf.writeUint64(memory.memory.used);
|
||||||
buf.writeFloat(memory.mem_total);
|
buf.writeUint64(memory.memory.available);
|
||||||
buf.writeFloat(memory.swap_used);
|
buf.writeUint64(memory.memory.total);
|
||||||
buf.writeFloat(memory.swap_total);
|
buf.writeUint64(memory.swap.used);
|
||||||
|
buf.writeUint64(memory.swap.available);
|
||||||
|
buf.writeUint64(memory.swap.total);
|
||||||
|
|
||||||
// Disks
|
// Disks
|
||||||
buf.writeUint8(static_cast<uint8_t>(disks.size()));
|
buf.writeUint8(static_cast<uint8_t>(disks.size()));
|
||||||
@@ -52,8 +54,9 @@ namespace metrics
|
|||||||
{
|
{
|
||||||
buf.writeString(d.name);
|
buf.writeString(d.name);
|
||||||
buf.writeString(d.path);
|
buf.writeString(d.path);
|
||||||
buf.writeFloat(d.used);
|
buf.writeUint64(d.metrics.used);
|
||||||
buf.writeFloat(d.total);
|
buf.writeUint64(d.metrics.available);
|
||||||
|
buf.writeUint64(d.metrics.total);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.data();
|
return buf.data();
|
||||||
@@ -80,10 +83,12 @@ namespace metrics
|
|||||||
h.cpu.coreLoads.push_back(buf.readFloat());
|
h.cpu.coreLoads.push_back(buf.readFloat());
|
||||||
|
|
||||||
// Memory
|
// Memory
|
||||||
h.memory.mem_used = buf.readFloat();
|
h.memory.memory.used = buf.readUint64();
|
||||||
h.memory.mem_total = buf.readFloat();
|
h.memory.memory.available = buf.readUint64();
|
||||||
h.memory.swap_used = buf.readFloat();
|
h.memory.memory.total = buf.readUint64();
|
||||||
h.memory.swap_total = buf.readFloat();
|
h.memory.swap.used = buf.readUint64();
|
||||||
|
h.memory.swap.available = buf.readUint64();
|
||||||
|
h.memory.swap.total = buf.readUint64();
|
||||||
|
|
||||||
// Disks
|
// Disks
|
||||||
uint8_t numDisks = buf.readUint8();
|
uint8_t numDisks = buf.readUint8();
|
||||||
@@ -91,11 +96,13 @@ namespace metrics
|
|||||||
h.disks.reserve(numDisks);
|
h.disks.reserve(numDisks);
|
||||||
for (uint8_t i = 0; i < numDisks; ++i)
|
for (uint8_t i = 0; i < numDisks; ++i)
|
||||||
{
|
{
|
||||||
std::string name = buf.readString();
|
Disk disk;
|
||||||
std::string path = buf.readString();
|
disk.name = buf.readString();
|
||||||
float used = buf.readFloat();
|
disk.path = buf.readString();
|
||||||
float total = buf.readFloat();
|
disk.metrics.used = buf.readUint64();
|
||||||
h.disks.push_back({name, path, used, total});
|
disk.metrics.available = buf.readUint64();
|
||||||
|
disk.metrics.total = buf.readUint64();
|
||||||
|
h.disks.push_back(disk);
|
||||||
}
|
}
|
||||||
|
|
||||||
return h;
|
return h;
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "metrics/MemoryMetrics.h"
|
||||||
|
|
||||||
namespace metrics
|
namespace metrics
|
||||||
{
|
{
|
||||||
struct Memory
|
struct Memory
|
||||||
{
|
{
|
||||||
float mem_used;
|
MemoryMetrics memory;
|
||||||
float mem_available;
|
MemoryMetrics swap;
|
||||||
float mem_total;
|
|
||||||
float swap_used;
|
|
||||||
float swap_total;
|
|
||||||
float swap_available;
|
|
||||||
};
|
};
|
||||||
} // namespace metrics
|
} // namespace metrics
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace metrics
|
||||||
|
{
|
||||||
|
struct MemoryMetrics
|
||||||
|
{
|
||||||
|
uint64_t used;
|
||||||
|
uint64_t available;
|
||||||
|
uint64_t total;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace metrics
|
||||||
@@ -7,6 +7,13 @@ namespace network
|
|||||||
buffer.push_back(v);
|
buffer.push_back(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Buffer::writeUint16(uint16_t v)
|
||||||
|
{
|
||||||
|
uint16_t net = htons(v);
|
||||||
|
auto p = reinterpret_cast<uint8_t *>(&net);
|
||||||
|
buffer.insert(buffer.end(), p, p + sizeof(net));
|
||||||
|
}
|
||||||
|
|
||||||
void Buffer::writeUint32(uint32_t v)
|
void Buffer::writeUint32(uint32_t v)
|
||||||
{
|
{
|
||||||
uint32_t net = htonl(v);
|
uint32_t net = htonl(v);
|
||||||
@@ -14,6 +21,37 @@ namespace network
|
|||||||
buffer.insert(buffer.end(), p, p + sizeof(net));
|
buffer.insert(buffer.end(), p, p + sizeof(net));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Buffer::writeUint64(uint64_t v)
|
||||||
|
{
|
||||||
|
uint32_t high = htonl(static_cast<uint32_t>(v >> 32));
|
||||||
|
uint32_t low = htonl(static_cast<uint32_t>(v & 0xFFFFFFFF));
|
||||||
|
writeUint32(high);
|
||||||
|
writeUint32(low);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Buffer::writeInt8(int8_t v)
|
||||||
|
{
|
||||||
|
buffer.push_back(static_cast<uint8_t>(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Buffer::writeInt16(int16_t v)
|
||||||
|
{
|
||||||
|
uint16_t net = htons(static_cast<uint16_t>(v));
|
||||||
|
auto p = reinterpret_cast<uint8_t *>(&net);
|
||||||
|
buffer.insert(buffer.end(), p, p + sizeof(net));
|
||||||
|
}
|
||||||
|
void Buffer::writeInt32(int32_t v)
|
||||||
|
{
|
||||||
|
uint32_t net = htonl(static_cast<uint32_t>(v));
|
||||||
|
auto p = reinterpret_cast<uint8_t *>(&net);
|
||||||
|
buffer.insert(buffer.end(), p, p + sizeof(net));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Buffer::writeInt64(int64_t v)
|
||||||
|
{
|
||||||
|
writeUint64(static_cast<uint64_t>(v));
|
||||||
|
}
|
||||||
|
|
||||||
void Buffer::writeFloat(float f)
|
void Buffer::writeFloat(float f)
|
||||||
{
|
{
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
@@ -41,6 +79,14 @@ namespace network
|
|||||||
checkRemaining(1);
|
checkRemaining(1);
|
||||||
return buffer[pos++];
|
return buffer[pos++];
|
||||||
}
|
}
|
||||||
|
uint16_t Buffer::readUint16()
|
||||||
|
{
|
||||||
|
checkRemaining(2);
|
||||||
|
uint16_t tmp;
|
||||||
|
std::memcpy(&tmp, &buffer[pos], sizeof(tmp));
|
||||||
|
pos += 2;
|
||||||
|
return ntohs(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t Buffer::readUint32()
|
uint32_t Buffer::readUint32()
|
||||||
{
|
{
|
||||||
@@ -51,6 +97,42 @@ namespace network
|
|||||||
return ntohl(tmp);
|
return ntohl(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t Buffer::readUint64()
|
||||||
|
{
|
||||||
|
checkRemaining(8);
|
||||||
|
uint32_t high = readUint32();
|
||||||
|
uint32_t low = readUint32();
|
||||||
|
return (static_cast<uint64_t>(high) << 32) | low;
|
||||||
|
}
|
||||||
|
|
||||||
|
int8_t Buffer::readInt8()
|
||||||
|
{
|
||||||
|
checkRemaining(1);
|
||||||
|
return static_cast<int8_t>(buffer[pos++]);
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t Buffer::readInt16()
|
||||||
|
{
|
||||||
|
checkRemaining(2);
|
||||||
|
int16_t tmp;
|
||||||
|
std::memcpy(&tmp, &buffer[pos], sizeof(tmp));
|
||||||
|
pos += 2;
|
||||||
|
return static_cast<int16_t>(ntohs(static_cast<uint16_t>(tmp)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t Buffer::readInt32()
|
||||||
|
{
|
||||||
|
checkRemaining(4);
|
||||||
|
int32_t tmp;
|
||||||
|
std::memcpy(&tmp, &buffer[pos], sizeof(tmp));
|
||||||
|
pos += 4;
|
||||||
|
return static_cast<int32_t>(ntohl(static_cast<uint32_t>(tmp)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t Buffer::readInt64()
|
||||||
|
{
|
||||||
|
return static_cast<int64_t>(readUint64());
|
||||||
|
}
|
||||||
float Buffer::readFloat()
|
float Buffer::readFloat()
|
||||||
{
|
{
|
||||||
uint32_t tmp = readUint32();
|
uint32_t tmp = readUint32();
|
||||||
|
|||||||
@@ -16,12 +16,24 @@ namespace network
|
|||||||
// --- Writing ---
|
// --- Writing ---
|
||||||
void writeUint8(uint8_t v);
|
void writeUint8(uint8_t v);
|
||||||
void writeUint32(uint32_t v);
|
void writeUint32(uint32_t v);
|
||||||
|
void writeUint16(uint16_t v);
|
||||||
|
void writeUint64(uint64_t v);
|
||||||
|
void writeInt8(int8_t v);
|
||||||
|
void writeInt32(int32_t v);
|
||||||
|
void writeInt16(int16_t v);
|
||||||
|
void writeInt64(int64_t v);
|
||||||
void writeFloat(float f);
|
void writeFloat(float f);
|
||||||
void writeBytes(const uint8_t *data, size_t len);
|
void writeBytes(const uint8_t *data, size_t len);
|
||||||
void writeString(const std::string &s);
|
void writeString(const std::string &s);
|
||||||
// --- Reading ---
|
// --- Reading ---
|
||||||
uint8_t readUint8();
|
uint8_t readUint8();
|
||||||
|
uint16_t readUint16();
|
||||||
uint32_t readUint32();
|
uint32_t readUint32();
|
||||||
|
uint64_t readUint64();
|
||||||
|
int8_t readInt8();
|
||||||
|
int16_t readInt16();
|
||||||
|
int32_t readInt32();
|
||||||
|
int64_t readInt64();
|
||||||
float readFloat();
|
float readFloat();
|
||||||
std::string readString();
|
std::string readString();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user