java - 在溢出的情况下我们如何扩展数据包?
问题描述
我的帧大小固定为 7 个值(t_i,{1..7} 中的 i)。每个值存储在 2 个字节上(最大值为 = 2^(16) -1 = 65 535)并除以分辨率因子 10000,即 6.5535ms 作为最大值 (0xFFFF)。超出这些值,2 个字节不再足够,计数器溢出。
在我的测试用例中,我经常遇到溢出,尤其是当我使用非常低的频率时
例如:频率 = 400Hz 和 t_1 = 1ms => t_7 = 1 + 6 * 1/400 = 16 ms > 6.5535 ms
为了处理这个溢出,到目前为止所做的是我们允许溢出,因为它在解码过程中是可检测的。
为了检测此溢出,计算了 2 个连续 (t_i) 之间的时间增量,以查看结果是否低于最大值(0xFFFF 相当于 6.5535 ms),在这种情况下,存在溢出(计数器并根据定义增长,衰变表明异常)。
我正在考虑在溢出的情况下扩展框架(x2)。我该如何继续这样做?
绕过计数器溢出问题的现有行:
if (timeCounterInMs > 2000000000) { // 2000000000 is the value to be substracted to the counter to transform long into double
timeCounterInMs -= 2000000000;
isCounterOverFlow = true;
} else {
isCounterOverFlow = false;
}
currentIndexInBytes += 4;
body[index++] = timeCounterInMs; // body of the frame
for (int j = 0; j < 7; j++) {
long timeInTimeRatio = /*transform bytes to long*/;
currentIndexInBytes += 2;
body[index++] = timeInTimeRatio;
if (timeInTimeRatio == 0 && j != 0) {
// the end of the packet
} else {
if (timeInTimeRatio <= theLastValueInPacket && j != 0) { // If the time counter declay => overflow and start to zero
timeInTimeRatio = timeInTimeRatio + 65536; // 0xFFFF = 65536
}
}
谢谢
解决方案
推荐阅读
- angular - 使用 Karma 进行角度测试
- android - 根据 if 语句更改视图的背景颜色
- c# - 如何使用 C# 创建强制文件保存位置?
- postgresql - EXTRACT INTO 多行 (PostgreSQL)
- python - Scrapy / 如何选择直接嵌套到 span 中的数据
- javascript - 如何显示和隐藏一个
- 面板内?
- amazon-cloudformation - Use CAPABILITY_AUTO_EXPAND for nested stacks on CloudFormation
- reactjs - reactJS 从外部存储库打开一个 .pdf 文件
- typescript - 在 nativescript 应用程序设置中存储一系列收藏夹
- ios - NSExtension - Share - Limit type only to video or only to pictures