资源简介
1588协议的源代码,完整的实现,里边有比较详细的文档。enjoy yourself
代码片段和文件信息
/* arith.c */
#include “ptpd.h“
void integer64_to_internalTime(Integer64 bigintTimeInternal *internal)
{
int s_msb;
double ns_msb;
double temp;
int entire;
char *p_lsb*p_msb;
Boolean negative = FALSE;
p_lsb=&bigint.lsb;
p_msb=&bigint.msb;
/*Test if bigint is a negative number*/
negative = ((bigint.msb & 0x80000000) == 0x80000000);
if (!negative)
{
/*Positive case*/
/*fractional nanoseconds are excluded (see 5.3.2)*/
bigint.lsb = bigint.lsb>>16;
/*copy two least significant octet of msb to most significant octet of lsb*/
*(p_lsb+2)=*p_msb;
*(p_lsb+3)=*(p_msb+1);
bigint.msb = bigint.msb>>16;
internal->nanoseconds = bigint.lsb % 1000000000;
internal->seconds = bigint.lsb / 1000000000;
/*(2^32 / 10^9) = 4294967296*/
s_msb = 4*bigint.msb;
ns_msb = 0.294967296*(double)bigint.msb;
entire = (int)ns_msb;
s_msb += entire;
ns_msb -= entire;
ns_msb *= 1000000000;
internal->nanoseconds = (float)internal->nanoseconds + (float)ns_msb;
internal->seconds += s_msb;
normalizeTime(internal);
}
/*End of positive Case*/
else
{ /*Negative case*/
/*Take the two complement*/
bigint.lsb = ~bigint.lsb;
bigint.msb = ~bigint.msb;
if (bigint.lsb == 0xffffffff){
bigint.lsb = 0;
bigint.msb++;
}
else{
bigint.lsb++;
}
/*fractional nanoseconds are excluded (see 5.3.2)*/
bigint.lsb = bigint.lsb>>16;
/*copy two least significant octet of msb to most significant octet of lsb*/
*(p_lsb+2)=*p_msb;
*(p_lsb+3)=*(p_msb+1);
bigint.msb = bigint.msb>>16;
internal->nanoseconds = bigint.lsb % 1000000000;
internal->seconds = bigint.lsb / 1000000000;
/*(2^32 / 10^9) = 4294967296*/
s_msb = 4*bigint.msb;
ns_msb = 0.294967296*(double)bigint.msb;
entire = (int)ns_msb;
s_msb += entire;
ns_msb -= entire;
ns_msb *= 1000000000;
internal->nanoseconds = (float)internal->nanoseconds + (float)ns_msb;
internal->seconds += s_msb;
normalizeTime(internal);
internal->nanoseconds = -internal->nanoseconds;
internal->seconds = -internal->seconds;
}
/*End of negative Case*/
}
void fromInternalTime(TimeInternal *internal Timestamp *external)
{
/*fromInternalTime is only used to convert time given by the system to a timestamp
* As a consequence no negative value can normally be found in (internal)
* Note that offsets are also represented with TimeInternal structure and can be negative
* but offset are never convert into Timestamp so there is no problem here.*/
if ((internal->seconds & ~INT_MAX) || (internal->nanoseconds & ~INT_MAX))
{
DBG(“Negative value canno‘t be converted into timestamp \n“);
return;
}
else
{
external->secondsField.lsb = internal->seconds;
external->nanosecondsField = internal->nanoseconds;
external->secondsField.msb = 0;
}
}
void toInternalTime(TimeInternal *internal Timestamp *external)
{
/*Program will
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 958 2010-03-17 05:07 ptpv2d-rc1\COPYRIGHT
文件 1396 2010-03-17 04:57 ptpv2d-rc1\README
文件 860 2010-03-17 04:57 ptpv2d-rc1\RELEASE_NOTES
文件 478 2010-03-17 04:57 ptpv2d-rc1\tools\filter_response.m
文件 1987 2010-03-17 04:57 ptpv2d-rc1\tools\offset_stats.m
文件 4036 2010-03-17 04:57 ptpv2d-rc1\src\arith.c
文件 11783 2010-03-17 04:57 ptpv2d-rc1\src\bmc.c
文件 4054 2010-03-17 04:57 ptpv2d-rc1\src\constants.h
文件 9187 2010-05-21 10:39 ptpv2d-rc1\src\datatypes.h
文件 13945 2010-03-17 04:57 ptpv2d-rc1\src\display.c
文件 63409 2010-03-17 04:57 ptpv2d-rc1\src\Doxyfile
文件 607 2010-03-17 04:57 ptpv2d-rc1\src\Makefile
文件 38561 2010-03-17 04:57 ptpv2d-rc1\src\protocol.c
文件 2453 2010-03-17 04:57 ptpv2d-rc1\src\ptpd.8
文件 1404 2010-03-17 04:57 ptpv2d-rc1\src\ptpd.c
文件 3431 2010-03-17 04:57 ptpv2d-rc1\src\ptpd.h
文件 2102 2010-03-17 04:57 ptpv2d-rc1\src\dep\constants_dep.h
文件 1619 2010-03-17 04:57 ptpv2d-rc1\src\dep\datatypes_dep.h
文件 13028 2010-03-17 04:57 ptpv2d-rc1\src\dep\msg.c
文件 19776 2010-03-17 04:57 ptpv2d-rc1\src\dep\net.c
文件 5049 2010-03-17 04:57 ptpv2d-rc1\src\dep\ptpd_dep.h
文件 7870 2010-03-17 04:57 ptpv2d-rc1\src\dep\servo.c
文件 6193 2010-03-17 04:57 ptpv2d-rc1\src\dep\startup.c
文件 2566 2010-03-17 04:57 ptpv2d-rc1\src\dep\sys.c
文件 1661 2010-03-17 04:57 ptpv2d-rc1\src\dep\timer.c
文件 272225 2010-03-17 05:08 ptpv2d-rc1\doc\IEEE1588v1_vs_IEEE1588v2.pdf
文件 3604766 2010-05-21 16:17 ptpv2d-rc1\doc\IEEE1588协议分析与实现.nh
文件 163245 2010-05-13 09:57 ptpv2d-rc1\doc\ix1588V2.pdf
文件 718848 2010-05-21 17:01 ptpv2d-rc1\doc\移植需要.wps
目录 0 2010-05-22 21:33 ptpv2d-rc1\src\dep
............此处省略7个文件信息
相关资源
- 1588时间同步解决方案
- stm32f107 ieee1588
- IEEE1588-2019英文版
- Verilog Ieee 1588
- IEEE1588V2中文_网络测量和控制系统的精
- IEEE1588v2中文资料
- IEEE1588协议原文
- stm32f107在rt-thread上实现1588协议 ptpv2
- 论文研究-基于卡尔曼滤波与PID控制的
- 1588协议代码
- 1588 时钟同步原理
- IEEE1588协议
- NTP服务器与PTP服务器的区别.pdf
- 1588 V2中文资料
- IEEE 1588 ptp 代码实现
- IEEE 1588(PTPv2)精确时钟同步协议抓包
- PTP协议_IEEE1588_V2_中文版
- IEEE1588实现代码
- 1588网络同步协议中文版本完整版
- IEEE1588-2008V2.pdf(清晰版,非扫描)
评论
共有 条评论