18 #include <pia/transport/transport_Protocol.h> 20 #include <pia/transport/transport_ProtocolEvent.h> 21 #if NN_PIA_TRANSPORT_V3 22 #include <pia/common/common_PacketDefine.h> 24 #include <pia/common/common_ProtocolMessageOld.h> 26 #include <pia/transport/transport_definitions.h> 37 class ZlibUncompressor;
103 PIA_PROTOCOL_TYPE_INFO(nn::pia::transport::PROTOCOL_TYPE_SYNC);
107 static const u8 FRAME_DELAY_MAX = 32;
110 static const u32 DATA_ID_NUM = 16;
113 static const u32 RESERVED_DATA_ID_NUM = 1;
114 static const u32 RESERVED_DATA_ID_CHANGE_DELAY = DATA_ID_NUM + 0;
116 static const u32 SEND_SKIP_MAX = 2;
117 static const u32 DATA_FIRST_SEND_COUNT = 3;
119 static const u32 COMPRESSION_LEVEL_NONE = 0;
120 static const u32 COMPRESSION_LEVEL_LOW = 1;
121 static const u32 COMPRESSION_LEVEL_MIDDLE = 5;
122 static const u32 COMPRESSION_LEVEL_HIGH = 9;
143 size_t m_DataUnitSize[DATA_ID_NUM + RESERVED_DATA_ID_NUM];
187 size_t GetDataUnitSizeMax()
const;
221 size_t GetDataSize(u32 dataId)
const;
231 return static_cast<u32
>(m_MaxDelay);
241 return static_cast<u32
>(m_Delay);
252 return static_cast<u32
>(m_TimeoutFrame);
273 nn::Result SetSendPeriod(u32 sendPeriod);
324 nn::Result Start(bit32 usingDataIdBitmap, u32 delay, u32 sendPeriod);
382 nn::Result EndAlone();
398 nn::Result GetEndFrameNo(
StationId stationId, u32* endFrameNo)
const;
405 STATE_NOT_SYNCHRONIZED = 0,
437 bool NeedSetData()
const;
454 bool NeedSetData(u32 dataId)
const;
468 bool CanGetData()
const;
479 u32 GetFrameNo()
const;
489 bool CheckEntry(
StationId stationId)
const;
500 bit32 GetUsingDataIdBitmap(
StationId stationId)
const;
508 END_REASON_NOTHING = 0,
543 nn::Result SetData(u32 dataId,
const void* cpData);
564 return this->GetData(stationId, dataId, pBuffer, 0);
589 nn::Result GetData(
StationId stationId, u32 dataId,
void* pBuffer, u32 frameOffset)
const;
606 const void* GetDataPtr(
StationId stationId, u32 dataId)
const;
621 u32 GetReceivedDataNum(
StationId stationId)
const;
638 s32 EstimateLeadingFrameNum(
StationId stationId, u32 frameRate)
const;
658 nn::Result RequestToChangeDelay(u32 newDelay);
675 return this->GetIsNoDataFrame(isNoDataFrame, 0);
693 nn::Result GetIsNoDataFrame(
bool* isNoDataFrame, u32 frameOffset)
const;
704 u32 GetMaxFrameOffsetDecidedIfNoDataFrameOrNot()
const;
717 size_t CalcMaxSyncDataSizeSentInOnePacket(u32 delay, u32 dataIdNum);
731 nn::Result StepWithoutSetData();
746 nn::Result EndSetDataInNoProcessFrame();
754 s32 GetSetDataOffset()
756 return m_SetDataOffset;
765 void SetIsUsingReceivedDataCheck(
bool isUsingReceivedDataCheck);
781 virtual nn::Result Startup(
StationIndex myStationIndex);
789 virtual void Cleanup();
799 virtual nn::Result Dispatch();
814 virtual nn::Result UpdateProtocolEvent(
const transport::ProtocolEvent& event);
823 virtual void Trace(u64 flag)
const;
837 u32 m_UsingDataIdBitmap;
839 u32 m_PreparedFrameNo;
840 bit32 m_ReceivedDataBitmap;
842 u32 m_LastReceiveStepCount;
846 bool m_IsEndAloneInCurrentSession;
851 return (m_StationNum > 0);
853 bool IsInCommunication()
const 860 void DispatchReceive();
861 void ReceiveStartMessage(
StationIndex stationIndex, u16 syncId, u32 usingDataIdBitmap, s32 delay, bit16 connectedStationBitmap);
862 void ReceiveEndMessage(
StationIndex stationIndex, u16 syncId);
863 void ReceiveStartEndMessage(
StationIndex stationIndex, u16 syncId);
864 void ReceiveEndAloneMessage(
StationIndex stationIndex, u16 syncId, u32 endFrameNo);
865 void ReceiveStartAckMessage(
StationIndex stationIndex, u16 syncId);
866 void ReceiveEndAckMessage(
StationIndex stationIndex, u16 syncId);
867 void ReceiveEndAloneAckMessage(
StationIndex stationIndex, u16 syncId);
868 void ReceiveDataMessage(
StationIndex stationIndex, u16 syncId,
const void* cpMessage,
size_t size,
bool isCompressedData);
871 bool SendCommand(
StationIndex stationIndex,
int type, u16 syncId = 0);
872 bool SendCommandMulti(u32 destBmp,
int type);
874 void ResetSendDataFrameNo();
875 bool CreateDataChunk(
size_t* pSize,
bool forceDisableDataCompression =
false);
877 void UpdatePreparedFrameNo();
878 void UpdateReceivedDataBitmap();
879 bool IsAllReceivedData(u32 sendDataFrameNo);
881 u64 MakeSendFrameBitmap(u32 dataFirstSendCount)
const;
882 bool IsSendFrameNo(u32 sendDataFrameNo);
883 u32* GetSendProcessCountPtr(u32 frameNo)
885 return &m_paSendProcessCnt[GetDataBufferIdx(m_LocalStationIndex, frameNo)];
889 const StationInfo* GetStationInfo(
StationIndex stationIndex)
const 891 return const_cast<SyncProtocol*
>(
this)->GetStationInfo(stationIndex);
894 int GetDataBufferIdx(
StationIndex stationIndex, u32 frameNo)
const;
896 u32* GetValidDataFlag(
StationIndex stationIndex, u32 frameNo)
898 return &m_paValidDataFlag[stationIndex * m_BufferFrameNum + GetDataBufferIdx(stationIndex, frameNo)];
900 const u32* GetValidDataFlag(
StationIndex stationIndex, u32 frameNo)
const 902 return const_cast<SyncProtocol*
>(
this)->GetValidDataFlag(stationIndex, frameNo);
905 u32* GetNoDataFrameFlag(u32 frameNo)
907 return &m_paNoDataFrameFlag[GetDataBufferIdx(m_LocalStationIndex, frameNo)];
909 const u32* GetNoDataFrameFlag(u32 frameNo)
const 911 return const_cast<SyncProtocol*
>(
this)->GetNoDataFrameFlag(frameNo);
914 void* GetDataBuffer(
StationIndex stationIndex, u32 frameNo, u32 dataId)
916 PIA_ASSERT(dataId < DATA_ID_NUM + RESERVED_DATA_ID_NUM);
917 return &m_pDataBuffer[(stationIndex * m_BufferFrameNum + GetDataBufferIdx(stationIndex, frameNo)) * m_TotalDataSize + m_DataInfo[dataId].m_Offset];
919 const void* GetDataBuffer(
StationIndex stationIndex, u32 frameNo, u32 dataId)
const 921 return const_cast<SyncProtocol*
>(
this)->GetDataBuffer(stationIndex, frameNo, dataId);
925 nn::Result ChangeDelay(u32 newDelay);
926 bool IsUsingChangeDelay()
const 928 return m_DataInfo[RESERVED_DATA_ID_CHANGE_DELAY].m_Size != 0;
933 void CheckEndedAlone();
935 bit16 CalcConnectedStationBitmap()
const;
939 nn::Result GetData(
StationIndex stationIndex, u32 dataId,
void* pBuffer)
const 941 return this->GetData(stationIndex, dataId, pBuffer, 0);
943 nn::Result GetData(
StationIndex stationIndex, u32 dataId,
void* pBuffer, u32 frameOffset)
const;
944 bit32 GetUsingDataIdBitmap(
StationIndex stationIndex)
const;
952 #if NN_PIA_TRANSPORT_V3 953 static const u32 cMessageBufferSize = common::PROTOCOL_MESSGAE_PAYLOAD_SIZE_MAX /
sizeof(u32) *
sizeof(u32);
955 static const u32 cMessageBufferSize = common::ProtocolMessageOld::MESSAGE_SIZE_MAX /
sizeof(u32) *
sizeof(u32);
957 u32 m_MessageBuffer[cMessageBufferSize /
sizeof(u32)];
958 u32* m_pCompressedMessageBuffer;
960 StationInfo* m_paStationInfo;
961 u32* m_paValidDataFlag;
962 u32* m_paNoDataFrameFlag;
970 } m_DataInfo[DATA_ID_NUM + RESERVED_DATA_ID_NUM];
976 s32 m_BufferFrameNum;
980 u32 m_CurrentFrameNo;
981 u32 m_PreparedFrameNo;
982 bit32 m_ReceivedDataBitmap;
983 bool m_IsUsingReceivedDataCheck;
985 s32 m_CurrentDataBufferIdx;
990 u32 m_StepCountOffset;
993 bool m_IsSendEndAlone;
994 u32 m_ParticipantBmp;
995 u32 m_SendStartDestBmp;
996 u32 m_SendEndDestBmp;
997 u32 m_SendEndAloneDestBmp;
998 u32 m_SendDataFrameNo;
1000 bool m_IsResetSendData;
1004 u32 m_ChangeDelayRequestFrameNo;
1007 s32 m_SetDataOffset;
1010 bool m_IsStepWithoutSetData;
1013 bool m_IsEnableDataCompression;
1014 u32 m_DataCompressionLevel;
1015 static const u32 cZlibCompressorWindowBits = 12;
1016 static const u32 cZlibCompressorMemLevel = 5;
1017 static const u32 cZlibCompressorWorkMemorySize = 38596;
1018 common::ZlibCompressor* m_pZlibCompressor;
1019 u32* m_paZlibCompressorMemory;
1020 common::ZlibUncompressor* m_pZlibUncompressor;
1021 u32* m_paZlibUncompressorMemory;
1026 u32 m_SameDataCount;
1027 u32 m_PreSendFrameNoMin;
1028 u32 m_PreSendFrameNoMax;
1031 u32* m_paSendProcessCnt;
1032 u32 m_SendProcessFrameNoMin;
1033 u32 m_SendProcessFrameNoMax;
1034 u32 m_DataFirstSendCount;
1035 u64 m_SendFrameBitmap;
1038 u8 m_MonitoringMinDelay;
1039 u8 m_MonitoringMaxDelay;
1040 u8 m_MonitoringMinSendPeriod;
1041 u8 m_MonitoringMaxSendPeriod;
1042 u32 m_MonitoringStepCount;
1043 u32 m_MonitoringPreSendFrameNoMaxBuf;
1044 u32 m_MonitoringResendCountedFrameNoMax;
1045 u8 m_MonitoringResendFrameCnt;
1046 u8 m_MonitoringMaxResendFrameNum;
void Finalize(void)
Finalizes the common module.
Communication ended because no data was received for Setting::m_TimeoutFrame frames.
Definition: sync_SyncProtocol.h:512
StationIndex
Enumerates StationIndex values.
Definition: platformCtr.h:44
Definition of the StationId identifying the station within the session.
Definition: types.h:33
u32 m_TimeoutFrame
Ends synchronization due to a timeout if packets cannot be received consecutively for the specified n...
Definition: sync_SyncProtocol.h:158
Synchronization is starting. Although the data to send must be set, it cannot yet be retrieved...
Definition: sync_SyncProtocol.h:407
ID indicating a station that is not present in the session.
Definition: platformCtr.h:59
EndReason
Represents the reason why synchronization was ended.
Definition: sync_SyncProtocol.h:506
Stores settings specified during initialization.
Definition: sync_SyncProtocol.h:128
bool IsInitialized(void)
Indicates whether the common module is initialized.
nn::Result GetIsNoDataFrame(bool *isNoDataFrame) const
Gets whether synchronization data cannot be retrieved for this frame.
Definition: sync_SyncProtocol.h:673
u32 m_MaxDelay
Defines the maximum number of frames of input delay.
Definition: sync_SyncProtocol.h:152
State
Represents the current state of synchronization.
Definition: sync_SyncProtocol.h:403
u32 m_DataCompressionLevel
Sets the compression level for synchronized data.
Definition: sync_SyncProtocol.h:174
This protocol is used for synchronized communication. Full mesh is the only network topology type t...
Definition: sync_SyncProtocol.h:78
nn::Result Initialize(void *pMem, u32 size)
Initializes the common module.
u32 GetSendPeriod() const
Gets the send interval specified to the Start function.
Definition: sync_SyncProtocol.h:261
State GetState() const
Gets the current state of synchronization.
Definition: sync_SyncProtocol.h:419
Protocol base class.
Definition: transport_Protocol.h:44
bool m_IsUsingChangeDelay
Enables or disables use of the change delay feature while communication is synchronized.
Definition: sync_SyncProtocol.h:163
Start synchronization and wait for other stations to start synchronization.
Definition: sync_SyncProtocol.h:406
Communication ended because of a call to the End function by the station.
Definition: sync_SyncProtocol.h:509
Communication ended because there was a change in the stations in the session.
Definition: sync_SyncProtocol.h:511
nn::Result GetData(StationId stationId, u32 dataId, void *pBuffer) const
Gets the data received during synchronization.
Definition: sync_SyncProtocol.h:562
u32 GetTimeoutFrame() const
Gets the timeout setting specified in the Initialize function.
Definition: sync_SyncProtocol.h:250
Synchronization is ending.
Definition: sync_SyncProtocol.h:409
u32 GetMaxDelay() const
Gets the maximum input delay specified to the Initialize function.
Definition: sync_SyncProtocol.h:229
Synchronization is active. The data to send must be set, and it can be retrieved. ...
Definition: sync_SyncProtocol.h:408
u32 GetDelay() const
Gets the input delay actually specified.
Definition: sync_SyncProtocol.h:239
Communication ended because another station ended synchronization.
Definition: sync_SyncProtocol.h:510