⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msg.c

📁 IEEE1588 Protocol,用于同步局域网各站点时间
💻 C
📖 第 1 页 / 共 3 页
字号:
  *(Integer32*)(buf + 80) = shift16(flip16(ptpClock->sync_interval), 1);  *(Integer32*)(buf + 84) = shift16(flip16(ptpClock->clock_variance), 1);  *(Integer32*)(buf + 88) = shift16(flip16(ptpClock->steps_removed), 1);  *(Integer32*)(buf + 92) = shift8(ptpClock->clock_stratum, 3);  memcpy((buf + 96), ptpClock->clock_identifier, 4);  *(Integer32*)(buf + 100) = shift8(ptpClock->parent_communication_technology, 1);  memcpy((buf + 102), ptpClock->parent_uuid, 6);  *(Integer32*)(buf + 108) = shift16(flip16(ptpClock->parent_port_id), 1);  *(Integer32*)(buf + 112) = shift16(flip16(ptpClock->observed_variance), 1);  *(Integer32*)(buf + 116) = flip32(ptpClock->observed_drift);  *(Integer32*)(buf + 120) = shift8(ptpClock->utc_reasonable, 3);}void msgPackFollowUp(void *buf, UInteger16 associatedSequenceId,  TimeRepresentation *preciseOriginTimestamp, PtpClock *ptpClock){  *(UInteger8*)(buf + 20) = 2;  /* messageType */  *(Integer32*)(buf + 28) = shift16(flip16(ptpClock->port_id_field), 0) | shift16(flip16(ptpClock->last_general_event_sequence_number), 1);  *(UInteger8*)(buf + 32) = PTP_FOLLOWUP_MESSAGE;  /* control */  clearFlag((buf + 34), PTP_SYNC_BURST);  clearFlag((buf + 34), PARENT_STATS);    *(Integer32*)(buf + 40) = shift16(flip16(associatedSequenceId), 1);  *(Integer32*)(buf + 44) = flip32(preciseOriginTimestamp->seconds);  *(Integer32*)(buf + 48) = flip32(preciseOriginTimestamp->nanoseconds);}void msgPackDelayResp(void *buf, MsgHeader *header,  TimeRepresentation *delayReceiptTimestamp, PtpClock *ptpClock){  *(UInteger8*)(buf + 20) = 2;  /* messageType */  *(Integer32*)(buf + 28) = shift16(flip16(ptpClock->port_id_field), 0) | shift16(flip16(ptpClock->last_general_event_sequence_number), 1);  *(UInteger8*)(buf + 32) = PTP_DELAY_RESP_MESSAGE;  /* control */  clearFlag((buf + 34), PTP_SYNC_BURST);  clearFlag((buf + 34), PARENT_STATS);    *(Integer32*)(buf + 40) = flip32(delayReceiptTimestamp->seconds);  *(Integer32*)(buf + 44) = flip32(delayReceiptTimestamp->nanoseconds);  *(Integer32*)(buf + 48) = shift8(header->sourceCommunicationTechnology, 1);  memcpy(buf + 50, header->sourceUuid, 6);  *(Integer32*)(buf + 56) = shift16(flip16(header->sourcePortId), 0) | shift16(flip16(header->sequenceId), 1);}UInteger16 msgPackManagement(void *buf, MsgManagement *manage, PtpClock *ptpClock){  *(UInteger8*)(buf + 20) = 2;  /* messageType */  *(Integer32*)(buf + 28) = shift16(flip16(ptpClock->port_id_field), 0) | shift16(flip16(ptpClock->last_general_event_sequence_number), 1);  *(UInteger8*)(buf + 32) = PTP_MANAGEMENT_MESSAGE;  /* control */  clearFlag((buf + 34), PTP_SYNC_BURST);  clearFlag((buf + 34), PARENT_STATS);  *(Integer32*)(buf + 40) = shift8(manage->targetCommunicationTechnology, 1);  memcpy(buf + 42, manage->targetUuid, 6);  *(Integer32*)(buf + 48) = shift16(flip16(manage->targetPortId), 0) | shift16(flip16(MM_STARTING_BOUNDARY_HOPS), 1);  *(Integer32*)(buf + 52) = shift16(flip16(MM_STARTING_BOUNDARY_HOPS), 0);    *(UInteger8*)(buf + 55) = manage->managementMessageKey;    switch(manage->managementMessageKey)  {  case PTP_MM_GET_FOREIGN_DATA_SET:    *(UInteger16*)(buf + 62) = manage->recordKey;    *(Integer32*)(buf + 56) = shift16(flip16(4), 1);    return 64;      default:    *(Integer32*)(buf + 56) = shift16(flip16(0), 1);    return 60;  }}UInteger16 msgPackManagementResponse(void *buf, MsgHeader *header, MsgManagement *manage, PtpClock *ptpClock){  TimeInternal internalTime;  TimeRepresentation externalTime;    *(UInteger8*)(buf + 20) = 2;  /* messageType */  *(Integer32*)(buf + 28) = shift16(flip16(ptpClock->port_id_field), 0) | shift16(flip16(ptpClock->last_general_event_sequence_number), 1);  *(UInteger8*)(buf + 32) = PTP_MANAGEMENT_MESSAGE;  /* control */  clearFlag((buf + 34), PTP_SYNC_BURST);  clearFlag((buf + 34), PARENT_STATS);  *(Integer32*)(buf + 40) = shift8(header->sourceCommunicationTechnology, 1);  memcpy(buf + 42, header->sourceUuid, 6);  *(Integer32*)(buf + 48) = shift16(flip16(header->sourcePortId), 0) | shift16(flip16(MM_STARTING_BOUNDARY_HOPS), 1);  *(Integer32*)(buf + 52) = shift16(flip16(manage->startingBoundaryHops - manage->boundaryHops + 1), 0);    switch(manage->managementMessageKey)  {  case PTP_MM_OBTAIN_IDENTITY:    *(UInteger8*)(buf + 55) = PTP_MM_CLOCK_IDENTITY;    *(Integer32*)(buf + 56) = shift16(flip16(64), 1);    *(Integer32*)(buf + 60) = shift8(ptpClock->clock_communication_technology, 3);    memcpy(buf + 64, ptpClock->clock_uuid_field, 6);    *(Integer32*)(buf + 72) = shift16(flip16(ptpClock->clock_port_id_field), 1);    memcpy((buf + 76), MANUFACTURER_ID, 48);    return 124;      case PTP_MM_GET_DEFAULT_DATA_SET:    *(UInteger8*)(buf + 55) = PTP_MM_DEFAULT_DATA_SET;    *(Integer32*)(buf + 56) = shift16(flip16(76), 1);    *(Integer32*)(buf + 60) = shift8(ptpClock->clock_communication_technology, 3);    memcpy(buf + 64, ptpClock->clock_uuid_field, 6);    *(Integer32*)(buf + 72) = shift16(flip16(ptpClock->clock_port_id_field), 1);    *(Integer32*)(buf + 76) = shift8(ptpClock->clock_stratum, 3);    memcpy(buf + 80, ptpClock->clock_identifier, 4);    *(Integer32*)(buf + 84) = shift16(flip16(ptpClock->clock_variance), 1);    *(Integer32*)(buf + 88) = shift8(ptpClock->clock_followup_capable, 3);    *(Integer32*)(buf + 92) = shift8(ptpClock->preferred, 3);    *(Integer32*)(buf + 96) = shift8(ptpClock->initializable, 3);    *(Integer32*)(buf + 100) = shift8(ptpClock->external_timing, 3);    *(Integer32*)(buf + 104) = shift8(ptpClock->is_boundary_clock, 3);    *(Integer32*)(buf + 108) = shift8(ptpClock->sync_interval, 3);    memcpy(buf + 112, ptpClock->subdomain_name, 16);    *(Integer32*)(buf + 128) = shift16(flip16(ptpClock->number_ports), 1);    *(Integer32*)(buf + 132) = shift16(flip16(ptpClock->number_foreign_records), 1);    return 136;      case PTP_MM_GET_CURRENT_DATA_SET:    *(UInteger8*)(buf + 55) = PTP_MM_CURRENT_DATA_SET;    *(Integer32*)(buf + 56) = shift16(flip16(20), 1);    *(Integer32*)(buf + 60) = shift16(flip16(ptpClock->steps_removed), 1);        fromInternalTime(&ptpClock->offset_from_master, &externalTime, 0);    *(Integer32*)(buf + 64) = flip32(externalTime.seconds);    *(Integer32*)(buf + 68) = flip32(externalTime.nanoseconds);        fromInternalTime(&ptpClock->one_way_delay, &externalTime, 0);    *(Integer32*)(buf + 72) = flip32(externalTime.seconds);    *(Integer32*)(buf + 76) = flip32(externalTime.nanoseconds);    return 80;      case PTP_MM_GET_PARENT_DATA_SET:    *(UInteger8*)(buf + 55) = PTP_MM_PARENT_DATA_SET;    *(Integer32*)(buf + 56) = shift16(flip16(90), 1);    *(Integer32*)(buf + 60) = shift8(ptpClock->parent_communication_technology, 3);    memcpy(buf + 64, ptpClock->parent_uuid, 6);    *(Integer32*)(buf + 72) = shift16(flip16(ptpClock->parent_port_id), 1);    *(Integer32*)(buf + 76) = shift16(flip16(ptpClock->parent_last_sync_sequence_number), 1);    *(Integer32*)(buf + 80) = shift8(ptpClock->parent_followup_capable, 1);    *(Integer32*)(buf + 84) = shift8(ptpClock->parent_external_timing, 3);    *(Integer32*)(buf + 88) = shift16(flip16(ptpClock->parent_variance), 1);    *(Integer32*)(buf + 92) = shift8(ptpClock->parent_stats, 3);    *(Integer32*)(buf + 96) = shift16(flip16(ptpClock->observed_variance), 1);    *(Integer32*)(buf + 100) = flip32(ptpClock->observed_drift);    *(Integer32*)(buf + 104) = shift8(ptpClock->utc_reasonable, 3);    *(Integer32*)(buf + 108) = shift8(ptpClock->grandmaster_communication_technology, 3);    memcpy(buf + 112, ptpClock->grandmaster_uuid_field, 6);    *(Integer32*)(buf + 120) = shift16(flip16(ptpClock->grandmaster_port_id_field), 1);    *(Integer32*)(buf + 124) = shift8(ptpClock->grandmaster_stratum, 3);    memcpy(buf + 128, ptpClock->grandmaster_identifier, 4);    *(Integer32*)(buf + 132) = shift16(flip16(ptpClock->grandmaster_variance), 1);    *(Integer32*)(buf + 136) = shift8(ptpClock->grandmaster_preferred, 3);    *(Integer32*)(buf + 140) = shift8(ptpClock->grandmaster_is_boundary_clock, 3);    *(Integer32*)(buf + 144) = shift16(flip16(ptpClock->grandmaster_sequence_number), 1);    return 148;      case PTP_MM_GET_PORT_DATA_SET:    if(manage->targetPortId && manage->targetPortId != ptpClock->port_id_field)    {      *(UInteger8*)(buf + 55) = PTP_MM_NULL;      *(Integer32*)(buf + 56) = shift16(flip16(0), 1);      return 0;    }        *(UInteger8*)(buf + 55) = PTP_MM_PORT_DATA_SET;    *(Integer32*)(buf + 56) = shift16(flip16(52), 1);    *(Integer32*)(buf + 60) = shift16(flip16(ptpClock->port_id_field), 1);    *(Integer32*)(buf + 64) = shift8(ptpClock->port_state, 3);    *(Integer32*)(buf + 68) = shift16(flip16(ptpClock->last_sync_event_sequence_number), 1);    *(Integer32*)(buf + 72) = shift16(flip16(ptpClock->last_general_event_sequence_number), 1);    *(Integer32*)(buf + 76) = shift8(ptpClock->port_communication_technology, 3);    memcpy(buf + 80, ptpClock->port_uuid_field, 6);    *(Integer32*)(buf + 88) = shift16(flip16(ptpClock->port_id_field), 1);    *(Integer32*)(buf + 92) = shift8(ptpClock->burst_enabled, 3);    *(Integer32*)(buf + 96) = shift8(4, 1) | shift8(2, 2) | shift8(2, 3);    memcpy(buf + 100, ptpClock->subdomain_address, 4);    memcpy(buf + 106, ptpClock->event_port_address, 2);    memcpy(buf + 110, ptpClock->general_port_address, 2);    return 112;      case PTP_MM_GET_GLOBAL_TIME_DATA_SET:    *(UInteger8*)(buf + 55) = PTP_MM_GLOBAL_TIME_DATA_SET;    *(Integer32*)(buf + 56) = shift16(flip16(24), 1);        getTime(&internalTime);    fromInternalTime(&internalTime, &externalTime, ptpClock->halfEpoch);    *(Integer32*)(buf + 60) = flip32(externalTime.seconds);    *(Integer32*)(buf + 64) = flip32(externalTime.nanoseconds);        *(Integer32*)(buf + 68) = shift16(flip16(ptpClock->current_utc_offset), 1);    *(Integer32*)(buf + 72) = shift8(ptpClock->leap_59, 3);    *(Integer32*)(buf + 76) = shift8(ptpClock->leap_61, 3);    *(Integer32*)(buf + 80) = shift16(flip16(ptpClock->epoch_number), 1);    return 84;      case PTP_MM_GET_FOREIGN_DATA_SET:    if((manage->targetPortId && manage->targetPortId != ptpClock->port_id_field)      || !manage->recordKey || manage->recordKey > ptpClock->number_foreign_records)    {      *(UInteger8*)(buf + 55) = PTP_MM_NULL;      *(Integer32*)(buf + 56) = shift16(flip16(0), 1);      return 0;    }        *(UInteger8*)(buf + 55) = PTP_MM_FOREIGN_DATA_SET;    *(Integer32*)(buf + 56) = shift16(flip16(28), 1);    *(Integer32*)(buf + 60) = shift16(flip16(ptpClock->port_id_field), 1);    *(Integer32*)(buf + 64) = shift16(flip16(manage->recordKey - 1), 1);    *(Integer32*)(buf + 68) = shift8(ptpClock->foreign[manage->recordKey - 1].foreign_master_communication_technology, 3);    memcpy(buf + 72, ptpClock->foreign[manage->recordKey - 1].foreign_master_uuid, 6);    *(Integer32*)(buf + 80) = shift16(flip16(ptpClock->foreign[manage->recordKey - 1].foreign_master_port_id), 1);    *(Integer32*)(buf + 84) = shift16(flip16(ptpClock->foreign[manage->recordKey - 1].foreign_master_syncs), 1);    return 88;      default:    return 0;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -