Exemplo n.º 1
0
void msgPackFollowUp(void *buf, UInteger16 associatedSequenceId,
  TimeRepresentation *preciseOriginTimestamp, PtpClock *ptpClock)
{
  *(UInteger8*)((char*)buf + 20) = 2;  /* messageType */
  *(Integer32*)((char*)buf + 28) = shift16(flip16(ptpClock->port_id_field), 0) | shift16(flip16(ptpClock->last_general_event_sequence_number), 1);
  *(UInteger8*)((char*)buf + 32) = PTP_FOLLOWUP_MESSAGE;  /* control */
  clearFlag(((char*)buf + 34), PTP_SYNC_BURST);
  clearFlag(((char*)buf + 34), PARENT_STATS);
  
  *(Integer32*)((char*)buf + 40) = shift16(flip16(associatedSequenceId), 1);
  *(Integer32*)((char*)buf + 44) = flip32(preciseOriginTimestamp->seconds);
  *(Integer32*)((char*)buf + 48) = flip32(preciseOriginTimestamp->nanoseconds);
}
Exemplo n.º 2
0
void msgPackHeader(void *buf, PtpClock *ptpClock)
{
  *(Integer32*)((char*)buf + 0) = shift16(flip16(VERSION_PTP), 0) | shift16(flip16(VERSION_NETWORK), 1);
  memcpy(((char*)buf + 4), ptpClock->subdomain_name, 16);
  *(Integer32*)((char*)buf + 20) = shift8(ptpClock->port_communication_technology, 1);
  memcpy(((char*)buf + 22), ptpClock->port_uuid_field, 6);
  
  if(ptpClock->external_timing)
    setFlag(((char*)buf + 34), PTP_EXT_SYNC);
  if(ptpClock->clock_followup_capable)
    setFlag(((char*)buf + 34), PTP_ASSIST);
  if(ptpClock->is_boundary_clock)
    setFlag(((char*)buf + 34), PTP_BOUNDARY_CLOCK);
}
Exemplo n.º 3
0
void msgPackDelayResp(void *buf, MsgHeader *header,
  TimeRepresentation *delayReceiptTimestamp, PtpClock *ptpClock)
{
  *(UInteger8*)((char*)buf + 20) = 2;  /* messageType */
  *(Integer32*)((char*)buf + 28) = shift16(flip16(ptpClock->port_id_field), 0) | shift16(flip16(ptpClock->last_general_event_sequence_number), 1);
  *(UInteger8*)((char*)buf + 32) = PTP_DELAY_RESP_MESSAGE;  /* control */
  clearFlag(((char*)buf + 34), PTP_SYNC_BURST);
  clearFlag(((char*)buf + 34), PARENT_STATS);
  
  *(Integer32*)((char*)buf + 40) = flip32(delayReceiptTimestamp->seconds);
  *(Integer32*)((char*)buf + 44) = flip32(delayReceiptTimestamp->nanoseconds);
  *(Integer32*)((char*)buf + 48) = shift8(header->sourceCommunicationTechnology, 1);
  memcpy((char*)buf + 50, header->sourceUuid, 6);
  *(Integer32*)((char*)buf + 56) = shift16(flip16(header->sourcePortId), 0) | shift16(flip16(header->sequenceId), 1);
}
Exemplo n.º 4
0
UInteger16 msgPackManagement(void *buf, MsgManagement *manage, PtpClock *ptpClock)
{
  *(UInteger8*)((char*)buf + 20) = 2;  /* messageType */
  *(Integer32*)((char*)buf + 28) = shift16(flip16(ptpClock->port_id_field), 0) | shift16(flip16(ptpClock->last_general_event_sequence_number), 1);
  *(UInteger8*)((char*)buf + 32) = PTP_MANAGEMENT_MESSAGE;  /* control */
  clearFlag(((char*)buf + 34), PTP_SYNC_BURST);
  clearFlag(((char*)buf + 34), PARENT_STATS);
  *(Integer32*)((char*)buf + 40) = shift8(manage->targetCommunicationTechnology, 1);
  memcpy((char*)buf + 42, manage->targetUuid, 6);
  *(Integer32*)((char*)buf + 48) = shift16(flip16(manage->targetPortId), 0) | shift16(flip16(MM_STARTING_BOUNDARY_HOPS), 1);
  *(Integer32*)((char*)buf + 52) = shift16(flip16(MM_STARTING_BOUNDARY_HOPS), 0);
  
  *(UInteger8*)((char*)buf + 55) = manage->managementMessageKey;
  
  switch(manage->managementMessageKey)
  {
  case PTP_MM_GET_FOREIGN_DATA_SET:
    *(UInteger16*)((char*)buf + 62) = manage->recordKey;
    *(Integer32*)((char*)buf + 56) = shift16(flip16(4), 1);
    return 64;
    
  default:
    *(Integer32*)((char*)buf + 56) = shift16(flip16(0), 1);
    return 60;
  }
}
void alphaNumeric::scroll(char * string, int time)
{
	int i = 0;

	while(string[i] != '\0')
	{
		shift16(createShiftData(string[i]));
		delay(time);
		i++;
	}
}
Exemplo n.º 6
0
UInteger16 msgPackManagementResponse(void *buf, MsgHeader *header, MsgManagement *manage, PtpClock *ptpClock)
{
  TimeInternal internalTime;
  TimeRepresentation externalTime;
  
  *(UInteger8*)((char*)buf + 20) = 2;  /* messageType */
  *(Integer32*)((char*)buf + 28) = shift16(flip16(ptpClock->port_id_field), 0) | shift16(flip16(ptpClock->last_general_event_sequence_number), 1);
  *(UInteger8*)((char*)buf + 32) = PTP_MANAGEMENT_MESSAGE;  /* control */
  clearFlag(((char*)buf + 34), PTP_SYNC_BURST);
  clearFlag(((char*)buf + 34), PARENT_STATS);
  *(Integer32*)((char*)buf + 40) = shift8(header->sourceCommunicationTechnology, 1);
  memcpy((char*)buf + 42, header->sourceUuid, 6);
  *(Integer32*)((char*)buf + 48) = shift16(flip16(header->sourcePortId), 0) | shift16(flip16(MM_STARTING_BOUNDARY_HOPS), 1);
  *(Integer32*)((char*)buf + 52) = shift16(flip16(manage->startingBoundaryHops - manage->boundaryHops + 1), 0);
  
  switch(manage->managementMessageKey)
  {
  case PTP_MM_OBTAIN_IDENTITY:
    *(UInteger8*)((char*)buf + 55) = PTP_MM_CLOCK_IDENTITY;
    *(Integer32*)((char*)buf + 56) = shift16(flip16(64), 1);
    *(Integer32*)((char*)buf + 60) = shift8(ptpClock->clock_communication_technology, 3);
    memcpy((char*)buf + 64, ptpClock->clock_uuid_field, 6);
    *(Integer32*)((char*)buf + 72) = shift16(flip16(ptpClock->clock_port_id_field), 1);
    memcpy(((char*)buf + 76), MANUFACTURER_ID, 48);
    return 124;
    
  case PTP_MM_GET_DEFAULT_DATA_SET:
    *(UInteger8*)((char*)buf + 55) = PTP_MM_DEFAULT_DATA_SET;
    *(Integer32*)((char*)buf + 56) = shift16(flip16(76), 1);
    *(Integer32*)((char*)buf + 60) = shift8(ptpClock->clock_communication_technology, 3);
    memcpy((char*)buf + 64, ptpClock->clock_uuid_field, 6);
    *(Integer32*)((char*)buf + 72) = shift16(flip16(ptpClock->clock_port_id_field), 1);
    *(Integer32*)((char*)buf + 76) = shift8(ptpClock->clock_stratum, 3);
    memcpy((char*)buf + 80, ptpClock->clock_identifier, 4);
    *(Integer32*)((char*)buf + 84) = shift16(flip16(ptpClock->clock_variance), 1);
    *(Integer32*)((char*)buf + 88) = shift8(ptpClock->clock_followup_capable, 3);
    *(Integer32*)((char*)buf + 92) = shift8(ptpClock->preferred, 3);
    *(Integer32*)((char*)buf + 96) = shift8(ptpClock->initializable, 3);
    *(Integer32*)((char*)buf + 100) = shift8(ptpClock->external_timing, 3);
    *(Integer32*)((char*)buf + 104) = shift8(ptpClock->is_boundary_clock, 3);
    *(Integer32*)((char*)buf + 108) = shift8(ptpClock->sync_interval, 3);
    memcpy((char*)buf + 112, ptpClock->subdomain_name, 16);
    *(Integer32*)((char*)buf + 128) = shift16(flip16(ptpClock->number_ports), 1);
    *(Integer32*)((char*)buf + 132) = shift16(flip16(ptpClock->number_foreign_records), 1);
    return 136;
    
  case PTP_MM_GET_CURRENT_DATA_SET:
    *(UInteger8*)((char*)buf + 55) = PTP_MM_CURRENT_DATA_SET;
    *(Integer32*)((char*)buf + 56) = shift16(flip16(20), 1);
    *(Integer32*)((char*)buf + 60) = shift16(flip16(ptpClock->steps_removed), 1);
    
    fromInternalTime(&ptpClock->offset_from_master, &externalTime, 0);
    *(Integer32*)((char*)buf + 64) = flip32(externalTime.seconds);
    *(Integer32*)((char*)buf + 68) = flip32(externalTime.nanoseconds);
    
    fromInternalTime(&ptpClock->one_way_delay, &externalTime, 0);
    *(Integer32*)((char*)buf + 72) = flip32(externalTime.seconds);
    *(Integer32*)((char*)buf + 76) = flip32(externalTime.nanoseconds);
    return 80;
    
  case PTP_MM_GET_PARENT_DATA_SET:
    *(UInteger8*)((char*)buf + 55) = PTP_MM_PARENT_DATA_SET;
    *(Integer32*)((char*)buf + 56) = shift16(flip16(90), 1);
    *(Integer32*)((char*)buf + 60) = shift8(ptpClock->parent_communication_technology, 3);
    memcpy((char*)buf + 64, ptpClock->parent_uuid, 6);
    *(Integer32*)((char*)buf + 72) = shift16(flip16(ptpClock->parent_port_id), 1);
    *(Integer32*)((char*)buf + 76) = shift16(flip16(ptpClock->parent_last_sync_sequence_number), 1);
    *(Integer32*)((char*)buf + 80) = shift8(ptpClock->parent_followup_capable, 1);
    *(Integer32*)((char*)buf + 84) = shift8(ptpClock->parent_external_timing, 3);
    *(Integer32*)((char*)buf + 88) = shift16(flip16(ptpClock->parent_variance), 1);
    *(Integer32*)((char*)buf + 92) = shift8(ptpClock->parent_stats, 3);
    *(Integer32*)((char*)buf + 96) = shift16(flip16(ptpClock->observed_variance), 1);
    *(Integer32*)((char*)buf + 100) = flip32(ptpClock->observed_drift);
    *(Integer32*)((char*)buf + 104) = shift8(ptpClock->utc_reasonable, 3);
    *(Integer32*)((char*)buf + 108) = shift8(ptpClock->grandmaster_communication_technology, 3);
    memcpy((char*)buf + 112, ptpClock->grandmaster_uuid_field, 6);
    *(Integer32*)((char*)buf + 120) = shift16(flip16(ptpClock->grandmaster_port_id_field), 1);
    *(Integer32*)((char*)buf + 124) = shift8(ptpClock->grandmaster_stratum, 3);
    memcpy((char*)buf + 128, ptpClock->grandmaster_identifier, 4);
    *(Integer32*)((char*)buf + 132) = shift16(flip16(ptpClock->grandmaster_variance), 1);
    *(Integer32*)((char*)buf + 136) = shift8(ptpClock->grandmaster_preferred, 3);
    *(Integer32*)((char*)buf + 140) = shift8(ptpClock->grandmaster_is_boundary_clock, 3);
    *(Integer32*)((char*)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*)((char*)buf + 55) = PTP_MM_NULL;
      *(Integer32*)((char*)buf + 56) = shift16(flip16(0), 1);
      return 0;
    }
    
    *(UInteger8*)((char*)buf + 55) = PTP_MM_PORT_DATA_SET;
    *(Integer32*)((char*)buf + 56) = shift16(flip16(52), 1);
    *(Integer32*)((char*)buf + 60) = shift16(flip16(ptpClock->port_id_field), 1);
    *(Integer32*)((char*)buf + 64) = shift8(ptpClock->port_state, 3);
    *(Integer32*)((char*)buf + 68) = shift16(flip16(ptpClock->last_sync_event_sequence_number), 1);
    *(Integer32*)((char*)buf + 72) = shift16(flip16(ptpClock->last_general_event_sequence_number), 1);
    *(Integer32*)((char*)buf + 76) = shift8(ptpClock->port_communication_technology, 3);
    memcpy((char*)buf + 80, ptpClock->port_uuid_field, 6);
    *(Integer32*)((char*)buf + 88) = shift16(flip16(ptpClock->port_id_field), 1);
    *(Integer32*)((char*)buf + 92) = shift8(ptpClock->burst_enabled, 3);
    *(Integer32*)((char*)buf + 96) = shift8(4, 1) | shift8(2, 2) | shift8(2, 3);
    memcpy((char*)buf + 100, ptpClock->subdomain_address, 4);
    memcpy((char*)buf + 106, ptpClock->event_port_address, 2);
    memcpy((char*)buf + 110, ptpClock->general_port_address, 2);
    return 112;
    
  case PTP_MM_GET_GLOBAL_TIME_DATA_SET:
    *(UInteger8*)((char*)buf + 55) = PTP_MM_GLOBAL_TIME_DATA_SET;
    *(Integer32*)((char*)buf + 56) = shift16(flip16(24), 1);
    
    getTime(&internalTime);
    fromInternalTime(&internalTime, &externalTime, ptpClock->halfEpoch);
    *(Integer32*)((char*)buf + 60) = flip32(externalTime.seconds);
    *(Integer32*)((char*)buf + 64) = flip32(externalTime.nanoseconds);
    
    *(Integer32*)((char*)buf + 68) = shift16(flip16(ptpClock->current_utc_offset), 1);
    *(Integer32*)((char*)buf + 72) = shift8(ptpClock->leap_59, 3);
    *(Integer32*)((char*)buf + 76) = shift8(ptpClock->leap_61, 3);
    *(Integer32*)((char*)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*)((char*)buf + 55) = PTP_MM_NULL;
      *(Integer32*)((char*)buf + 56) = shift16(flip16(0), 1);
      return 0;
    }
    
    *(UInteger8*)((char*)buf + 55) = PTP_MM_FOREIGN_DATA_SET;
    *(Integer32*)((char*)buf + 56) = shift16(flip16(28), 1);
    *(Integer32*)((char*)buf + 60) = shift16(flip16(ptpClock->port_id_field), 1);
    *(Integer32*)((char*)buf + 64) = shift16(flip16(manage->recordKey - 1), 1);
    *(Integer32*)((char*)buf + 68) = shift8(ptpClock->foreign[manage->recordKey - 1].foreign_master_communication_technology, 3);
    memcpy((char*)buf + 72, ptpClock->foreign[manage->recordKey - 1].foreign_master_uuid, 6);
    *(Integer32*)((char*)buf + 80) = shift16(flip16(ptpClock->foreign[manage->recordKey - 1].foreign_master_port_id), 1);
    *(Integer32*)((char*)buf + 84) = shift16(flip16(ptpClock->foreign[manage->recordKey - 1].foreign_master_syncs), 1);
    return 88;
    
  default:
    return 0;
  }
}
Exemplo n.º 7
0
void msgPackDelayReq(void *buf, Boolean burst,
  TimeRepresentation *originTimestamp, PtpClock *ptpClock)
{
  *(UInteger8*)((char*)buf + 20) = 1;  /* messageType */
  *(Integer32*)((char*)buf + 28) = shift16(flip16(ptpClock->port_id_field), 0) | shift16(flip16(ptpClock->last_sync_event_sequence_number), 1);
  *(UInteger8*)((char*)buf + 32) = PTP_DELAY_REQ_MESSAGE;  /* control */
  if(ptpClock->burst_enabled && burst)
    setFlag(((char*)buf + 34), PTP_SYNC_BURST);
  else
    clearFlag(((char*)buf + 34), PTP_SYNC_BURST);
  if(ptpClock->parent_stats)
    setFlag(((char*)buf + 34), PARENT_STATS);
  else
    clearFlag(((char*)buf + 34), PARENT_STATS);
  
  *(Integer32*)((char*)buf + 40) = flip32(originTimestamp->seconds);
  *(Integer32*)((char*)buf + 44) = flip32(originTimestamp->nanoseconds);
  *(Integer32*)((char*)buf + 48) = shift16(flip16(ptpClock->epoch_number), 0) | shift16(flip16(ptpClock->current_utc_offset), 1);
  *(Integer32*)((char*)buf + 52) = shift8(ptpClock->grandmaster_communication_technology, 1);
  memcpy(((char*)buf + 54), ptpClock->grandmaster_uuid_field, 6);
  *(Integer32*)((char*)buf + 60) = shift16(flip16(ptpClock->grandmaster_port_id_field), 0) | shift16(flip16(ptpClock->grandmaster_sequence_number), 1);
  *(Integer32*)((char*)buf + 64) = shift8(ptpClock->grandmaster_stratum, 3);
  memcpy(((char*)buf + 68), ptpClock->grandmaster_identifier, 4);
  *(Integer32*)((char*)buf + 72) = shift16(flip16(ptpClock->grandmaster_variance), 1);
  *(Integer32*)((char*)buf + 76) = shift16(flip16(ptpClock->grandmaster_preferred), 0) | shift16(flip16(ptpClock->grandmaster_is_boundary_clock), 1);
  *(Integer32*)((char*)buf + 80) = shift16(flip16(ptpClock->sync_interval), 1);
  *(Integer32*)((char*)buf + 84) = shift16(flip16(ptpClock->clock_variance), 1);
  *(Integer32*)((char*)buf + 88) = shift16(flip16(ptpClock->steps_removed), 1);
  *(Integer32*)((char*)buf + 92) = shift8(ptpClock->clock_stratum, 3);
  memcpy(((char*)buf + 96), ptpClock->clock_identifier, 4);
  *(Integer32*)((char*)buf + 100) = shift8(ptpClock->parent_communication_technology, 1);
  memcpy(((char*)buf + 102), ptpClock->parent_uuid, 6);
  *(Integer32*)((char*)buf + 108) = shift16(flip16(ptpClock->parent_port_id), 1);
  *(Integer32*)((char*)buf + 112) = shift16(flip16(ptpClock->observed_variance), 1);
  *(Integer32*)((char*)buf + 116) = flip32(ptpClock->observed_drift);
  *(Integer32*)((char*)buf + 120) = shift8(ptpClock->utc_reasonable, 3);
}
void alphaNumeric::print(char toPrint)
{
	uint16_t shiftData = createShiftData(toPrint);
	
	shift16(shiftData);
}
void alphaNumeric::clear(void)
{
	for (int i = 0; i < _displayAmount; i++)
		shift16(0);
}