diff --git a/df_datalink_sp/src/networking/link_layer/link_layer.h b/df_datalink_sp/src/networking/link_layer/link_layer.h index 8f75034..5c40d68 100644 --- a/df_datalink_sp/src/networking/link_layer/link_layer.h +++ b/df_datalink_sp/src/networking/link_layer/link_layer.h @@ -152,6 +152,7 @@ int32_t L2_SetupNextSlot(L2_INST *instPtr, L2_TOR_TYPE txrxMode, L2_FRAME_TYPE f void L2_FrameInsertChunk(uint8_t *frame, size_t offset, size_t bytes, const void *chunk); void L2_FrameGetChunk(uint8_t *frame, size_t offset, size_t bytes, void *chunk); int32_t L2_CrcAppend(uint8_t *dataBuff, uint32_t dataLen, uint32_t crcPos, L2_CRC_TYPE crcType); +static int32_t L2_CrcGen(uint8_t *dataBuff, uint32_t dataLen, L2_CRC_TYPE crcType, uint32_t *crc); bool L2_CrcCheck(uint8_t *dataBuff, uint32_t dataLen, L2_CRC_TYPE crcType); /** @} LinkLayer_Framing*/ @@ -170,7 +171,6 @@ int32_t L2_RescheduleEventAfter(L2_INST *instPtr, L2_SCHD_EVENT *schdEvent, uint * @defgroup LinkLayer_Scan * @{ */ -int32_t L2_Scan_Init(L2_SCAN_FSM **scanFSMPtr); void L2_Scan_RefreashScanTable(L2_INST *instPtr); void L2_Scan_Reset(L2_SCAN_FSM *scanFSMPtr); void L2_Scan_Destroy(L2_SCAN_FSM *scanFSMPtr); diff --git a/df_datalink_sp/src/networking/link_layer/msg_def.h b/df_datalink_sp/src/networking/link_layer/msg_def.h index 6c03db3..63dadc7 100644 --- a/df_datalink_sp/src/networking/link_layer/msg_def.h +++ b/df_datalink_sp/src/networking/link_layer/msg_def.h @@ -23,105 +23,154 @@ #ifndef __L2_MSG_DEF_H_ #define __L2_MSG_DEF_H_ -#define L2_PACK_LEN_MAX 512 // bytes +#define L2_PACK_LEN_MAX 2048 // bytes + +#define L2_PAYLOAD_LEN_ADV 17 +#define L2_PAYLOAD_LEN_ACK 9 +#define L2_PAYLOAD_LEN_SVC_128K 42 +#define L2_PAYLOAD_LEN_SVC_512K 267 +#define L2_PAYLOAD_LEN_SVC_2M 1222 +#define L2_MSG_CRC_LEN 1 -#define L2_ADV_PACK_LEN 28 // bytes -#define L2_CMF_PACK_LEN 268 // bytes -#define L2_SVC_PACK_LEN 268 // bytes -// Common structure: // [bytes] [name] -// 4 fame number +// 1 udu number +// 10 crypto sync word +// 8 message authentication code +// 4 frame number // 1 slot number // 1 source id // 1 destination id // 1 message type -#define L2_MSG_FRAME_NUM 0 +#define L2_MSG_UDU_NUM 0 +#define L2_MSG_UDU_NUM_LEN 1 +#define L2_MSG_SYNC_WORD 1 +#define L2_MSG_SYNC_WORD_LEN 10 +#define L2_MSG_AUTH_CODE 11 +#define L2_MSG_AUTH_CODE_LEN 8 +#define L2_MSG_FRAME_NUM 19 #define L2_MSG_FRAME_NUM_LEN 4 -#define L2_MSG_SLOT_NUM 4 +#define L2_MSG_SLOT_NUM 23 #define L2_MSG_SLOT_NUM_LEN 1 -#define L2_MSG_SRC_ID 5 +#define L2_MSG_SRC_ID 24 #define L2_MSG_SRC_ID_LEN 1 -#define L2_MSG_DST_ID 6 +#define L2_MSG_DST_ID 25 #define L2_MSG_DST_ID_LEN 1 -#define L2_MSG_TYPE 7 +#define L2_MSG_TYPE 26 #define L2_MSG_TYPE_LEN 1 -#define L2_MSG_PAYLOAD 8 +#define L2_MSG_PAYLOAD 27 -// advertisement payload structure: -// [bytes] [name] -// 4 position x -// 4 position y -// 4 position z -// 4 net start time -// 2 crc -#define L2_MSG_ADV_SRC_POSX 8 -#define L2_MSG_ADV_SRC_POSX_LEN 4 -#define L2_MSG_ADV_SRC_POSY 12 -#define L2_MSG_ADV_SRC_POSY_LEN 4 -#define L2_MSG_ADV_SRC_POSZ 16 -#define L2_MSG_ADV_SRC_POSZ_LEN 4 -#define L2_MSG_ADV_SRC_NETSTART_TIME 20 -#define L2_MSG_ADV_SRC_NETSTART_TIME_LEN 4 -#define L2_MSG_ADV_SVC_CRC 26 -#define L2_MSG_ADV_SVC_CRC_LEN 2 +#pragma pack(push, 1) // Force 1-byte alignment -// confirm payload structure: -// [bytes] [name] -// 4 position x -// 4 position y -// 4 position z -// 4 speed x -// 4 speed y -// 4 speed z -// 2 crc -#define L2_MSG_CFM_SRC_POSX 8 -#define L2_MSG_CFM_SRC_POSX_LEN 4 -#define L2_MSG_CFM_SRC_POSY 12 -#define L2_MSG_CFM_SRC_POSY_LEN 4 -#define L2_MSG_CFM_SRC_POSZ 16 -#define L2_MSG_CFM_SRC_POSZ_LEN 4 -#define L2_MSG_CFM_SRC_SPEEDX 20 -#define L2_MSG_CFM_SRC_SPEEDX_LEN 4 -#define L2_MSG_CFM_SRC_SPEEDY 24 -#define L2_MSG_CFM_SRC_SPEEDY_LEN 4 -#define L2_MSG_CFM_SRC_SPEEDZ 28 -#define L2_MSG_CFM_SRC_SPEEDZ_LEN 4 -#define L2_MSG_CFM_PAYLOAD_ID 32 -#define L2_MSG_CFM_PAYLOAD_ID_LEN 4 -#define L2_MSG_CFM_PAYLOAD 36 -#define L2_MSG_CFM_PAYLOAD_LEN 230 -#define L2_MSG_CFM_CRC 266 -#define L2_MSG_CFM_CRC_LEN 2 +/** + * @struct L2_MSG_COMMON + * @brief Link layer common message header, 27 byte / 216 bit in total. + */ +typedef struct +{ + uint8_t uduNum; ///< udu (user data unit) number per pdu (packet data unit) + struct + { + uint8_t cryptoSyncWord[10]; + uint8_t msgAuthCode[8]; + } MSG_KEY; -// service payload structure: -// [bytes] [name] -// 4 position x -// 4 position y -// 4 position z -// 4 speed x -// 4 speed y -// 4 speed z -// 234 payload -// 2 crc -#define L2_MSG_SVC_SRC_POSX 8 -#define L2_MSG_SVC_SRC_POSX_LEN 4 -#define L2_MSG_SVC_SRC_POSY 12 -#define L2_MSG_SVC_SRC_POSY_LEN 4 -#define L2_MSG_SVC_SRC_POSZ 16 -#define L2_MSG_SVC_SRC_POSZ_LEN 4 -#define L2_MSG_SVC_SRC_SPEEDX 20 -#define L2_MSG_SVC_SRC_SPEEDX_LEN 4 -#define L2_MSG_SVC_SRC_SPEEDY 24 -#define L2_MSG_SVC_SRC_SPEEDY_LEN 4 -#define L2_MSG_SVC_SRC_SPEEDZ 28 -#define L2_MSG_SVC_SRC_SPEEDZ_LEN 4 -#define L2_MSG_SVC_PAYLOAD_ID 32 -#define L2_MSG_SVC_PAYLOAD_ID_LEN 4 -#define L2_MSG_SVC_PAYLOAD 36 -#define L2_MSG_SVC_PAYLOAD_LEN 230 -#define L2_MSG_SVC_CRC 266 -#define L2_MSG_SVC_CRC_LEN 2 + uint32_t frameNum; ///< frame number + uint8_t slotNum; ///< slot number + uint8_t src; ///< source id + uint8_t dst; ///< destination id + uint8_t msgType; ///< message type +} L2_MSG_COMMON; + +/** + * @struct L2_MSG_ADV + * @brief Link layer advertise message definition, 65 byte / 520 bit in total. + */ +typedef struct +{ + L2_MSG_COMMON *common; ///< common message header + double srcPosX; ///< position x + double srcPosY; ///< position y + double srcPosZ; ///< position z + uint32_t srcNetStatTime;///< net start time + uint32_t advDataId; ///< advertise payload id + uint8_t advData[17]; ///< advertise payload data + uint8_t crc; ///< crc +} L2_MSG_ADV; + +/** + * @struct L2_MSG_ACK + * @brief Link layer acknowledge message definition, 65 byte / 520 bit in total. + */ +typedef struct +{ + L2_MSG_COMMON *common; ///< common message header + double srcPosX; ///< position x + double srcPosY; ///< position y + double srcPosZ; ///< position z + double srcSpeedX; ///< speed x + double srcSpeedY; ///< speed y + double srcSpeedZ; ///< speed z + uint32_t ackDataId; ///< acknowledge payload id + uint8_t ackData[9]; ///< acknowledge payload data + uint8_t crc; ///< crc +} L2_MSG_ACK; + +/** + * @struct L2_MSG_SVC_128K + * @brief Link layer 128 kbps service message definition, 98 byte / 784 bit in total. + */ +typedef struct +{ + L2_MSG_COMMON *common; ///< common message header + double srcPosX; ///< position x + double srcPosY; ///< position y + double srcPosZ; ///< position z + double srcSpeedX; ///< speed x + double srcSpeedY; ///< speed y + double srcSpeedZ; ///< speed z + uint32_t svcDataId; ///< service payload id + uint8_t svcData[42]; ///< service payload data + uint8_t crc; ///< crc +} L2_MSG_SVC_128K; + +/** + * @struct L2_MSG_SVC_512K + * @brief Link layer 512 kbps service message definition, 323 byte / 2584 bit in total. + */ +typedef struct +{ + L2_MSG_COMMON *common; ///< common message header + double srcPosX; ///< position x + double srcPosY; ///< position y + double srcPosZ; ///< position z + double srcSpeedX; ///< speed x + double srcSpeedY; ///< speed y + double srcSpeedZ; ///< speed z + uint32_t svcDataId; ///< service payload id + uint8_t svcData[267]; ///< service payload data + uint8_t crc; ///< crc +} L2_MSG_SVC_512K; + +/** + * @struct L2_MSG_SVC_2M + * @brief Link layer 2 Mbps service message definition, 1278 byte / 10224 bit in total. + */ +typedef struct +{ + L2_MSG_COMMON *common; ///< common message header + double srcPosX; ///< position x + double srcPosY; ///< position y + double srcPosZ; ///< position z + double srcSpeedX; ///< speed x + double srcSpeedY; ///< speed y + double srcSpeedZ; ///< speed z + uint32_t svcDataId; ///< service payload id + uint8_t svcData[1222]; ///< service payload data + uint8_t crc; ///< crc +} L2_MSG_SVC_2M; + +#pragma pack(pop) // Restore original packing #endif //__L2_MSG_DEF_H_ diff --git a/df_datalink_sp/src/networking/link_layer/routine_table.c b/df_datalink_sp/src/networking/link_layer/routine_table.c index 9f69fc3..45ff6a3 100644 --- a/df_datalink_sp/src/networking/link_layer/routine_table.c +++ b/df_datalink_sp/src/networking/link_layer/routine_table.c @@ -25,238 +25,289 @@ #include "link_layer.h" #include "link_layer_types.h" -L2_RTNE_TABLE_ENTRY intraScanSubT[L2_SLOTS_PER_FRAME] = { -// SubFrame 0 - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - -// SubFrame 1 - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - -// SubFrame 2 - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - -// SubFrame 3 - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x00, 0x01, 0xFF}, - {L2_SLOT_SCAN, 0x01, 0x01, 0xFF}, - {L2_SLOT_ADVERTISE, 0x00, 0x01, 0xFF}, - {L2_SLOT_ADVERTISE, 0x01, 0x01, 0xFF}, - {L2_SLOT_ADVERTISE, 0x02, 0x01, 0xFF}, - {L2_SLOT_ADVERTISE, 0x03, 0x01, 0xFF}, +L2_RTNE_TABLE_ENTRY innerScanSubT[L2_SLOTS_PER_FRAME] = +{ + // 36 slots: advertise of antenna-1 ~ antenna-3 + // 12 slots: idle for no antenna-4 + // 2 slots: service slot, set to idle + {L2_SLOT_ADVERTISE, 0x00, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x01, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x02, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x03, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x04, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x05, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x06, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x07, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x08, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x09, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x0A, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x0B, 0x01, L2_BROADCAST_ID1}, + {L2_SLOT_ADVERTISE, 0x00, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x01, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x02, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x03, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x04, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x05, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x06, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x07, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x08, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x09, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x0A, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x0B, 0x01, L2_BROADCAST_ID2}, + {L2_SLOT_ADVERTISE, 0x00, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x01, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x02, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x03, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x04, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x05, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x06, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x07, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x08, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x09, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x0A, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_ADVERTISE, 0x0B, 0x01, L2_BROADCAST_ID3}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, -// SubFrame 4 - {L2_SLOT_CONFIRM, 0x00, 0x01, 0xFF}, - {L2_SLOT_CONFIRM, 0x01, 0x01, 0xFF}, - {L2_SLOT_CONFIRM, 0x02, 0x01, 0xFF}, - {L2_SLOT_CONFIRM, 0x03, 0x01, 0xFF}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_CONFIRM, 0x00, 0x01, 0xFF}, - {L2_SLOT_CONFIRM, 0x01, 0x01, 0xFF}, - {L2_SLOT_CONFIRM, 0x02, 0x01, 0xFF}, - {L2_SLOT_CONFIRM, 0x03, 0x01, 0xFF}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_CONFIRM, 0x00, 0xFF, 0x01}, - {L2_SLOT_CONFIRM, 0x01, 0xFF, 0x01}, - {L2_SLOT_CONFIRM, 0x02, 0xFF, 0x01}, - {L2_SLOT_CONFIRM, 0x03, 0xFF, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_CONFIRM, 0x00, 0xFF, 0x01}, - {L2_SLOT_CONFIRM, 0x01, 0xFF, 0x01}, - {L2_SLOT_CONFIRM, 0x02, 0xFF, 0x01}, - {L2_SLOT_CONFIRM, 0x03, 0xFF, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, -}; + // 36 slots: acknowledge of member nodes + // 14 slots: service + {L2_SLOT_ACKNOWLEDGE, 0x00, 0x02, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x01, 0x02, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x02, 0x02, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x03, 0x02, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x00, 0x03, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x01, 0x03, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x02, 0x03, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x03, 0x03, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x00, 0x04, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x01, 0x04, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x02, 0x04, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x03, 0x04, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x00, 0x05, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x01, 0x05, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x02, 0x05, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x03, 0x05, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x00, 0x06, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x01, 0x06, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x02, 0x06, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x03, 0x06, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x00, 0x07, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x01, 0x07, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x02, 0x07, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x03, 0x07, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x00, 0x08, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x01, 0x08, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x02, 0x08, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x03, 0x08, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x00, 0x09, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x01, 0x09, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x02, 0x09, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x03, 0x09, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x00, 0x0A, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x01, 0x0A, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x02, 0x0A, 0x01}, + {L2_SLOT_ACKNOWLEDGE, 0x03, 0x0A, 0x01}, + {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, + {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, + {L2_SLOT_SERVICE, 0x00, 0x01, 0x03}, + {L2_SLOT_SERVICE, 0x01, 0x01, 0x03}, + {L2_SLOT_SERVICE, 0x00, 0x01, 0x04}, + {L2_SLOT_SERVICE, 0x01, 0x01, 0x04}, + {L2_SLOT_SERVICE, 0x00, 0x01, 0x05}, + {L2_SLOT_SERVICE, 0x01, 0x01, 0x05}, + {L2_SLOT_SERVICE, 0x00, 0x01, 0x06}, + {L2_SLOT_SERVICE, 0x01, 0x01, 0x06}, + {L2_SLOT_SERVICE, 0x00, 0x01, 0x07}, + {L2_SLOT_SERVICE, 0x01, 0x01, 0x07}, + {L2_SLOT_SERVICE, 0x00, 0x01, 0x08}, + {L2_SLOT_SERVICE, 0x01, 0x01, 0x08}, -L2_RTNE_TABLE_ENTRY normalSub[L2_SLOTS_PER_FRAME] = { -// SubFrame 0 - {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x02, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x03, 0x01, 0x02}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + // 12 slots: network management, head <--> node + // 18 slots: message distribution, head ---> node + // 12 slots: rtt, head <--> node + // 8 slots: service + {L2_SLOT_MANAGE, 0x00, 0x01, 0x02}, + {L2_SLOT_MANAGE, 0x01, 0x01, 0x02}, + {L2_SLOT_MANAGE, 0x00, 0x01, 0x03}, + {L2_SLOT_MANAGE, 0x01, 0x01, 0x03}, + {L2_SLOT_MANAGE, 0x00, 0x01, 0x04}, + {L2_SLOT_MANAGE, 0x01, 0x01, 0x04}, + {L2_SLOT_MANAGE, 0x00, 0x02, 0x01}, + {L2_SLOT_MANAGE, 0x01, 0x02, 0x01}, + {L2_SLOT_MANAGE, 0x00, 0x03, 0x01}, + {L2_SLOT_MANAGE, 0x01, 0x03, 0x01}, + {L2_SLOT_MANAGE, 0x00, 0x04, 0x01}, + {L2_SLOT_MANAGE, 0x01, 0x04, 0x01}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x02}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x02}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x03}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x03}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x04}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x04}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x05}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x05}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x06}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x06}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x07}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x07}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x08}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x08}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x09}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x09}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x0A}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x0A}, + {L2_SLOT_RTT, 0x00, 0x01, 0x02}, + {L2_SLOT_RTT, 0x01, 0x01, 0x02}, + {L2_SLOT_RTT, 0x00, 0x01, 0x03}, + {L2_SLOT_RTT, 0x01, 0x01, 0x03}, + {L2_SLOT_RTT, 0x00, 0x01, 0x04}, + {L2_SLOT_RTT, 0x01, 0x01, 0x04}, + {L2_SLOT_RTT, 0x00, 0x02, 0x01}, + {L2_SLOT_RTT, 0x01, 0x02, 0x01}, + {L2_SLOT_RTT, 0x00, 0x03, 0x01}, + {L2_SLOT_RTT, 0x01, 0x03, 0x01}, + {L2_SLOT_RTT, 0x00, 0x04, 0x01}, + {L2_SLOT_RTT, 0x01, 0x04, 0x01}, + {L2_SLOT_SERVICE, 0x00, 0x01, 0x09}, + {L2_SLOT_SERVICE, 0x01, 0x01, 0x09}, + {L2_SLOT_SERVICE, 0x00, 0x01, 0x0A}, + {L2_SLOT_SERVICE, 0x01, 0x01, 0x0A}, + {L2_SLOT_SERVICE, 0x00, 0x01, 0x0B}, + {L2_SLOT_SERVICE, 0x01, 0x01, 0x0B}, {L2_SLOT_SERVICE, 0x00, 0x02, 0x01}, {L2_SLOT_SERVICE, 0x01, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x02, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x03, 0x02, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x02, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x03, 0x01, 0x02}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x01, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x02, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x03, 0x02, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, -// SubFrame 1 - {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x02, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x03, 0x01, 0x02}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x01, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x02, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x03, 0x02, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x02, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x03, 0x01, 0x02}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x01, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x02, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x03, 0x02, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + // 12 slots: network management, head <--> node + // 18 slots: message distribution, head ---> node + // 12 slots: rtt, head <--> node + // 8 slots: service + {L2_SLOT_MANAGE, 0x00, 0x01, 0x05}, + {L2_SLOT_MANAGE, 0x01, 0x01, 0x05}, + {L2_SLOT_MANAGE, 0x00, 0x01, 0x06}, + {L2_SLOT_MANAGE, 0x01, 0x01, 0x06}, + {L2_SLOT_MANAGE, 0x00, 0x01, 0x07}, + {L2_SLOT_MANAGE, 0x01, 0x01, 0x07}, + {L2_SLOT_MANAGE, 0x00, 0x05, 0x01}, + {L2_SLOT_MANAGE, 0x01, 0x05, 0x01}, + {L2_SLOT_MANAGE, 0x00, 0x06, 0x01}, + {L2_SLOT_MANAGE, 0x01, 0x06, 0x01}, + {L2_SLOT_MANAGE, 0x00, 0x07, 0x01}, + {L2_SLOT_MANAGE, 0x01, 0x07, 0x01}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x02}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x02}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x03}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x03}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x04}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x04}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x05}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x05}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x06}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x06}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x07}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x07}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x08}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x08}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x09}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x09}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x0A}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x0A}, + {L2_SLOT_RTT, 0x00, 0x01, 0x05}, + {L2_SLOT_RTT, 0x01, 0x01, 0x05}, + {L2_SLOT_RTT, 0x00, 0x01, 0x06}, + {L2_SLOT_RTT, 0x01, 0x01, 0x06}, + {L2_SLOT_RTT, 0x00, 0x01, 0x07}, + {L2_SLOT_RTT, 0x01, 0x01, 0x07}, + {L2_SLOT_RTT, 0x00, 0x05, 0x01}, + {L2_SLOT_RTT, 0x01, 0x05, 0x01}, + {L2_SLOT_RTT, 0x00, 0x06, 0x01}, + {L2_SLOT_RTT, 0x01, 0x06, 0x01}, + {L2_SLOT_RTT, 0x00, 0x07, 0x01}, + {L2_SLOT_RTT, 0x01, 0x07, 0x01}, + {L2_SLOT_SERVICE, 0x00, 0x03, 0x01}, + {L2_SLOT_SERVICE, 0x01, 0x03, 0x01}, + {L2_SLOT_SERVICE, 0x00, 0x04, 0x01}, + {L2_SLOT_SERVICE, 0x01, 0x04, 0x01}, + {L2_SLOT_SERVICE, 0x00, 0x05, 0x01}, + {L2_SLOT_SERVICE, 0x01, 0x05, 0x01}, + {L2_SLOT_SERVICE, 0x00, 0x06, 0x01}, + {L2_SLOT_SERVICE, 0x01, 0x06, 0x01}, -// SubFrame 2 - {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x02, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x03, 0x01, 0x02}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x01, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x02, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x03, 0x02, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x02, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x03, 0x01, 0x02}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x01, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x02, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x03, 0x02, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - -// SubFrame 3 - {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x02, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x03, 0x01, 0x02}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x01, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x02, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x03, 0x02, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x02, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x03, 0x01, 0x02}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x01, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x02, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x03, 0x02, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - -// SubFrame 4 - {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x02, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x03, 0x01, 0x02}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x01, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x02, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x03, 0x02, 0x01}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x01, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x02, 0x01, 0x02}, - {L2_SLOT_SERVICE, 0x03, 0x01, 0x02}, - {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, - {L2_SLOT_SERVICE, 0x00, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x01, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x02, 0x02, 0x01}, - {L2_SLOT_SERVICE, 0x03, 0x02, 0x01}, + // 12 slots: network management, head <--> node + // 18 slots: message distribution, head ---> node + // 12 slots: rtt, head <--> node + // 8 slots: service, with one slot idle + {L2_SLOT_MANAGE, 0x00, 0x01, 0x08}, + {L2_SLOT_MANAGE, 0x01, 0x01, 0x08}, + {L2_SLOT_MANAGE, 0x00, 0x01, 0x09}, + {L2_SLOT_MANAGE, 0x01, 0x01, 0x09}, + {L2_SLOT_MANAGE, 0x00, 0x01, 0x0A}, + {L2_SLOT_MANAGE, 0x01, 0x01, 0x0A}, + {L2_SLOT_MANAGE, 0x00, 0x08, 0x01}, + {L2_SLOT_MANAGE, 0x01, 0x08, 0x01}, + {L2_SLOT_MANAGE, 0x00, 0x09, 0x01}, + {L2_SLOT_MANAGE, 0x01, 0x09, 0x01}, + {L2_SLOT_MANAGE, 0x00, 0x0A, 0x01}, + {L2_SLOT_MANAGE, 0x01, 0x0A, 0x01}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x02}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x02}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x03}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x03}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x04}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x04}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x05}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x05}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x06}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x06}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x07}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x07}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x08}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x08}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x09}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x09}, + {L2_SLOT_DISTRIBUTE, 0x00, 0x01, 0x0A}, + {L2_SLOT_DISTRIBUTE, 0x01, 0x01, 0x0A}, + {L2_SLOT_RTT, 0x00, 0x01, 0x08}, + {L2_SLOT_RTT, 0x01, 0x01, 0x08}, + {L2_SLOT_RTT, 0x00, 0x01, 0x09}, + {L2_SLOT_RTT, 0x01, 0x01, 0x09}, + {L2_SLOT_RTT, 0x00, 0x01, 0x0A}, + {L2_SLOT_RTT, 0x01, 0x01, 0x0A}, + {L2_SLOT_RTT, 0x00, 0x08, 0x01}, + {L2_SLOT_RTT, 0x01, 0x08, 0x01}, + {L2_SLOT_RTT, 0x00, 0x09, 0x01}, + {L2_SLOT_RTT, 0x01, 0x09, 0x01}, + {L2_SLOT_RTT, 0x00, 0x0A, 0x01}, + {L2_SLOT_RTT, 0x01, 0x0A, 0x01}, + {L2_SLOT_SERVICE, 0x00, 0x08, 0x01}, + {L2_SLOT_SERVICE, 0x01, 0x08, 0x01}, + {L2_SLOT_SERVICE, 0x00, 0x09, 0x01}, + {L2_SLOT_SERVICE, 0x01, 0x09, 0x01}, + {L2_SLOT_SERVICE, 0x00, 0x0A, 0x01}, + {L2_SLOT_SERVICE, 0x01, 0x0A, 0x01}, {L2_SLOT_IDLE, 0x00, 0x00, 0x00}, + {L2_SLOT_IDLE, 0x00, 0x00, 0x00} }; L2_RTNE_TABLE_ENTRY *initTable[L2_INIT_RTNE_PERIOD] = { - intraScanSubT + innerScanSubT }; L2_RTNE_TABLE_ENTRY *normalTable[L2_NORMAL_RTNE_PERIOD] = { - normalSub + innerScanSubT }; /** @} RoutineTable*/ diff --git a/df_datalink_sp/src/networking/link_layer/scan.c b/df_datalink_sp/src/networking/link_layer/scan.c index 8480e2b..c403a92 100644 --- a/df_datalink_sp/src/networking/link_layer/scan.c +++ b/df_datalink_sp/src/networking/link_layer/scan.c @@ -57,89 +57,100 @@ static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t dst ASSERT(instPtr != NULL); int32_t Status; uint32_t dataChunk; - uint8_t *buff = instPtr->sendPktData; - if ((type < L2_ADV_FRAME) || (type > L2_CFM_FRAME)) + if ((type < L2_FRAME_ADV) || (type > L2_FRAME_ACK)) { DBG_ERROR("Unexpected frame type: %" PRId8 ".\n", type); return EPARAM; } - // Common section of link layer package - dataChunk = L2_GetNextFrameNum(instPtr); - L2_FrameInsertChunk(buff, L2_MSG_FRAME_NUM, L2_MSG_FRAME_NUM_LEN, &dataChunk); - dataChunk = L2_GetNextSlotNum(instPtr); - L2_FrameInsertChunk(buff, L2_MSG_SLOT_NUM, L2_MSG_SLOT_NUM_LEN, &dataChunk); - dataChunk = L2_GetNodeId(instPtr); - L2_FrameInsertChunk(buff, L2_MSG_SRC_ID, L2_MSG_SRC_ID_LEN, &dataChunk); - dataChunk = dstId; - L2_FrameInsertChunk(buff, L2_MSG_DST_ID, L2_MSG_DST_ID_LEN, &dataChunk); switch (type) { case L2_FRAME_ADV: { - dataChunk = L2_FRAME_ADV; - L2_FrameInsertChunk(buff, L2_MSG_TYPE, L2_MSG_TYPE_LEN, &dataChunk); + L2_MSG_ADV *message = calloc(sizeof(L2_MSG_ADV)); + + // Common section of link layer package + message->common->frameNum = L2_GetNextFrameNum(instPtr); + message->common->slotNum = L2_GetNextSlotNum(instPtr); + message->common->src = L2_GetNodeId(instPtr); + message->common->dst = dstId; + message->common->msgType = L2_FRAME_ADV; - SysMonitor_GetSysinfo(&(instPtr->sysInfo)); // insert position and speed info - L2_FrameInsertChunk(buff, L2_MSG_ADV_SRC_POSX, L2_MSG_ADV_SRC_POSX_LEN, &(instPtr->sysInfo.posX)); - L2_FrameInsertChunk(buff, L2_MSG_ADV_SRC_POSY, L2_MSG_ADV_SRC_POSY_LEN, &(instPtr->sysInfo.posY)); - L2_FrameInsertChunk(buff, L2_MSG_ADV_SRC_POSZ, L2_MSG_ADV_SRC_POSZ_LEN, &(instPtr->sysInfo.posZ)); + SysMonitor_GetSysinfo(&(instPtr->sysInfo)); + message->srcPosX = &(instPtr->sysInfo.posX); + message->srcPosY = &(instPtr->sysInfo.posY); + message->srcPosZ = &(instPtr->sysInfo.posZ); // Insert net start time - L2_FrameInsertChunk(buff, L2_MSG_ADV_SRC_NETSTART_TIME, L2_MSG_ADV_SRC_NETSTART_TIME_LEN, &(instPtr->netStartTime)); + message->srcNetStatTime = &(instPtr->netStartTime); + + // Packing extra payload + SysMonitor_GetSendPayload(message->advData, message->advDataId, L2_PAYLOAD_LEN_ADV); + if (message->ackDataId == DATA_ID_NONE) + { + memset(message->ackData, 0xAA, L2_PAYLOAD_LEN_ADV); + } // Append CRC - Status = L2_CrcAppend(buff, L2_ADV_PACK_LEN - L2_MSG_ADV_SVC_CRC_LEN, L2_MSG_ADV_SVC_CRC, L2_CRC16_1021); + uint32_t crcVal; + Status = L2_CrcGen(message, Phy_GetFrameLen(L2_L2frame2L1frame(L2_FRAME_ADV)) - L2_MSG_CRC_LEN, L2_CRC8_31, &crcVal); if (Status != SUCCESS) { - DBG_ERROR("Fail to append CRC, error code: %" PRId32 ".\n", Status); return Status; } + message->crc = crcVal; + + instPtr->sendPktData = message; + + // Logging... + memcpy(instPtr->log.txLog.data, message, Phy_GetFrameLen(L2_L2frame2L1frame(L2_FRAME_ADV))); + instPtr->log.txLog.dataId = message->ackDataId; + + free(message); break; } case L2_FRAME_ACK: { - dataChunk = L2_FRAME_ACK; - L2_FrameInsertChunk(buff, L2_MSG_TYPE, L2_MSG_TYPE_LEN, &dataChunk); + L2_MSG_ACK *message = calloc(sizeof(L2_MSG_ACK)); + + // Common section of link layer package + message->common->frameNum = L2_GetNextFrameNum(instPtr); + message->common->slotNum = L2_GetNextSlotNum(instPtr); + message->common->src = L2_GetNodeId(instPtr); + message->common->dst = dstId; + message->common.msgType = L2_FRAME_ADV; - SysMonitor_GetSysinfo(&(instPtr->sysInfo)); // insert position and speed info - L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_POSX, L2_MSG_CFM_SRC_POSX_LEN, &(instPtr->sysInfo.posX)); - L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_POSY, L2_MSG_CFM_SRC_POSY_LEN, &(instPtr->sysInfo.posY)); - L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_POSZ, L2_MSG_CFM_SRC_POSZ_LEN, &(instPtr->sysInfo.posZ)); - L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_SPEEDX, L2_MSG_CFM_SRC_SPEEDX_LEN, &(instPtr->sysInfo.vX)); - L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_SPEEDY, L2_MSG_CFM_SRC_SPEEDY_LEN, &(instPtr->sysInfo.vY)); - L2_FrameInsertChunk(buff, L2_MSG_CFM_SRC_SPEEDZ, L2_MSG_CFM_SRC_SPEEDZ_LEN, &(instPtr->sysInfo.vZ)); + SysMonitor_GetSysinfo(&(instPtr->sysInfo)); + message->srcPosX = &(instPtr->sysInfo.posX); + message->srcPosY = &(instPtr->sysInfo.posY); + message->srcPosZ = &(instPtr->sysInfo.posZ); + message->srcSpeedX = &(instPtr->&(instPtr->sysInfo.vX)); + message->srcSpeedY = &(instPtr->&(instPtr->sysInfo.vY)); + message->srcSpeedZ = &(instPtr->&(instPtr->sysInfo.vZ)); // Packing extra payload - uint32_t dataId; - if (L2_GetNodeType(instPtr) == L2_NODE_HEAD) + SysMonitor_GetSendPayload(message->ackData, message->ackDataId, L2_PAYLOAD_LEN_ACK); + if (message->ackDataId == DATA_ID_NONE) { - SysMonitor_GetSendPayload(buff + L2_MSG_CFM_PAYLOAD, &dataId, PAYLOAD_LEN_FLJ_TX); - } - else - { - SysMonitor_GetSendPayload(buff + L2_MSG_CFM_PAYLOAD, &dataId, PAYLOAD_LEN_LJ_TX); - } - - L2_FrameInsertChunk(buff, L2_MSG_CFM_PAYLOAD_ID, L2_MSG_CFM_PAYLOAD_ID_LEN, &dataId); - if (dataId == DATA_ID_NONE) - { - memset(buff + L2_MSG_CFM_PAYLOAD, 0xAA, L2_MSG_CFM_PAYLOAD_LEN); + memset(message->ackData, 0xAA, L2_PAYLOAD_LEN_ACK); } // Append CRC - Status = L2_CrcAppend(buff, L2_CMF_PACK_LEN - L2_MSG_CFM_CRC_LEN, L2_MSG_CFM_CRC, L2_CRC16_1021); + uint32_t crcVal; + Status = L2_CrcGen(message, Phy_GetFrameLen(L2_L2frame2L1frame(L2_FRAME_ACK)) - L2_MSG_CRC_LEN, L2_CRC8_31, &crcVal); if (Status != SUCCESS) { - DBG_ERROR("Fail to append CRC, error code: %" PRId32 ".\n", Status); return Status; } + message->crc = crcVal; // Logging... - memcpy(instPtr->log.txLog.data, buff, L2_CMF_PACK_LEN); - instPtr->log.txLog.dataId = dataId; + memcpy(instPtr->log.txLog.data, message, Phy_GetFrameLen(L2_L2frame2L1frame(L2_FRAME_ACK))); + instPtr->log.txLog.dataId = message->ackDataId; + + free(message); break; } default: @@ -233,17 +244,6 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg) .msg = NULL }; (void)AssertL2Event(instPtr, &l2Event); - - // Assert update routine event... - L2_RTNE_CONFIG newRtneConfig = {0}; - L2_EVENT rtneUpEvent = - { - .event = L2_ROUTINE_UPDATE, - .msg = &newRtneConfig - }; - newRtneConfig.rtneTable = initTable; - newRtneConfig.rtnePrd = ARRAY_SIZE(initTable); - (void)AssertL2Event(instPtr, &rtneUpEvent); } // Time sync. L2_TimeAdjust(instPtr, &(instPtr->log.timeDev)); @@ -400,7 +400,6 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry) antIndex = L2_AntId2AntIndex(rtneEntry->dst); // antenna selection based on broadcast id in routing table torState = L2_TOR_TX; // head node transmits messages in advertise slot - memset(instPtr->sendPktData, 0xAA, L2_PACK_LEN_MAX); if (ScanMsg_Packing(instPtr, L2_FRAME_ADV, rtneEntry->dst) != SUCCESS) { return FAILURE; @@ -432,7 +431,6 @@ int32_t L2_Scan_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntry) antIndex = commNode->nodeInfo.antIndex; // antenna selection based on node list torState = L2_TOR_TX; // member node transmits message in acknowledge slot - memset(instPtr->sendPktData, 0xAA, L2_PACK_LEN_MAX); if (ScanMsg_Packing(instPtr, L2_FRAME_ACK, rtneEntry->dst) != SUCCESS) { return FAILURE; diff --git a/df_datalink_sp/src/networking/phy_layer/phy_antenna.c b/df_datalink_sp/src/networking/phy_layer/phy_antenna.c index 8aec99e..88be1b9 100644 --- a/df_datalink_sp/src/networking/phy_layer/phy_antenna.c +++ b/df_datalink_sp/src/networking/phy_layer/phy_antenna.c @@ -333,28 +333,37 @@ void Phy_SetRxAntIndex(PHY_INST *instPtr, PHY_ANT_INDEX antRxIndex) { ASSERT(instPtr != NULL); - switch (antRxIndex) + if (instPtr->antConfig.antControl.antMode == ANT_MODE_RX_AJ) + { + switch (antRxIndex) + { + case PHY_ANT_INDEX_1: + instPtr->antConfig.antControl.antRx1En = ANT_ENABLE; + instPtr->antConfig.antControl.antRx2En = ANT_DISABLE; + instPtr->antConfig.antControl.antRx3En = ANT_DISABLE; + break; + case PHY_ANT_INDEX_2: + instPtr->antConfig.antControl.antRx1En = ANT_DISABLE; + instPtr->antConfig.antControl.antRx2En = ANT_ENABLE; + instPtr->antConfig.antControl.antRx3En = ANT_DISABLE; + break; + case PHY_ANT_INDEX_3: + instPtr->antConfig.antControl.antRx1En = ANT_DISABLE; + instPtr->antConfig.antControl.antRx2En = ANT_DISABLE; + instPtr->antConfig.antControl.antRx3En = ANT_ENABLE; + break; + default: + instPtr->antConfig.antControl.antRx1En = ANT_DISABLE; + instPtr->antConfig.antControl.antRx2En = ANT_DISABLE; + instPtr->antConfig.antControl.antRx3En = ANT_DISABLE; + break; + } + } + else { - case PHY_ANT_INDEX_1: - instPtr->antConfig.antControl.antRx1En = ANT_ENABLE; - instPtr->antConfig.antControl.antRx2En = ANT_DISABLE; - instPtr->antConfig.antControl.antRx3En = ANT_DISABLE; - break; - case PHY_ANT_INDEX_2: - instPtr->antConfig.antControl.antRx1En = ANT_DISABLE; - instPtr->antConfig.antControl.antRx2En = ANT_ENABLE; - instPtr->antConfig.antControl.antRx3En = ANT_DISABLE; - break; - case PHY_ANT_INDEX_3: - instPtr->antConfig.antControl.antRx1En = ANT_DISABLE; - instPtr->antConfig.antControl.antRx2En = ANT_DISABLE; - instPtr->antConfig.antControl.antRx3En = ANT_ENABLE; - break; - default: instPtr->antConfig.antControl.antRx1En = ANT_DISABLE; instPtr->antConfig.antControl.antRx2En = ANT_DISABLE; instPtr->antConfig.antControl.antRx3En = ANT_DISABLE; - break; } } diff --git a/df_datalink_sp/src/networking/phy_layer/phy_layer.c b/df_datalink_sp/src/networking/phy_layer/phy_layer.c index 25fa5b5..36ad869 100644 --- a/df_datalink_sp/src/networking/phy_layer/phy_layer.c +++ b/df_datalink_sp/src/networking/phy_layer/phy_layer.c @@ -34,7 +34,7 @@ * @{ */ #define PHY_TIME_WORD_H_MAX UINT32_MAX -#define PHY_TIME_WORD_L_MAX 0x0007A120 // 5ms/10ns +#define PHY_TIME_WORD_L_MAX 200000U // 2 ms/10 ns #define L1_FRAME_LEN_MAX (16384 / 8) // byte #define L1_FRAME_ADV_24MS_LEN (520 / 8) // byte diff --git a/df_datalink_sp/src/networking/phy_layer/phy_layer.h b/df_datalink_sp/src/networking/phy_layer/phy_layer.h index 3383446..28ea689 100644 --- a/df_datalink_sp/src/networking/phy_layer/phy_layer.h +++ b/df_datalink_sp/src/networking/phy_layer/phy_layer.h @@ -47,7 +47,7 @@ #define L1_FRAME_128KBPS_4MS_HOPS 33U #define L1_FRAME_512KBPS_4MS_HOPS 36U #define L1_FRAME_2MBPS_4MS_HOPS 38U -#define PHY_LOG_EXPIRE 40U // 50*5ms +#define PHY_LOG_EXPIRE 50U // number of 2 ms slot /** @} */ /***************** Macros (Inline Functions) Definitions *********************/ /**************************** Type Definitions *******************************/ diff --git a/df_datalink_sp/src/time_ctrl/time_ctrl.c b/df_datalink_sp/src/time_ctrl/time_ctrl.c index 09bd10e..64fe9b1 100644 --- a/df_datalink_sp/src/time_ctrl/time_ctrl.c +++ b/df_datalink_sp/src/time_ctrl/time_ctrl.c @@ -146,7 +146,7 @@ void TimeCtrl_ResetLow(TMC_INST *instPtr) /*****************************************************************************/ /** - * @brief Get current time integer value. + * @brief Get current time integer value (2 ms counter). * * @param instPtr a pointer to time controller instance * diff --git a/df_datalink_sp/src/time_ctrl/time_ctrl.h b/df_datalink_sp/src/time_ctrl/time_ctrl.h index 80e9257..32ba7bc 100644 --- a/df_datalink_sp/src/time_ctrl/time_ctrl.h +++ b/df_datalink_sp/src/time_ctrl/time_ctrl.h @@ -21,7 +21,7 @@ /***************************** Include Files *********************************/ #include /************************** Constant Definitions *****************************/ -#define TIME_FRAC_MAX 500000 // how many 10ns in a 5ms +#define TIME_FRAC_MAX 200000 // how many 10ns in a 2 ms /***************** Macros (Inline Functions) Definitions *********************/ /**************************** Type Definitions *******************************/ /** @@ -44,8 +44,8 @@ typedef uint32_t TIME_INT; */ typedef struct { - TIME_INT int_part; ///< 5ms each LSB - TIME_FRAC frac_part; ///< 10ns each LSB + TIME_INT int_part; ///< 2 ms each LSB + TIME_FRAC frac_part; ///< 10 ns each LSB } TIME_WORD; /**