This is the multi-page printable view of this section. Click here to print...

Return to the regular view of this page

As of 2025-07-24

packet_tx

Transmission Packet
    This class is a wrapper for the tsTxDataApp structure from the TWENET C library. Objects derived from this class can be obtained via network behaviors or on_tx_comp().
    if (auto&& pkt = the_twelite.network.use<NWK_SIMPLE>().prepare_tx_packet()) {
    	pkt << tx_addr(0x00)
    		<< tx_retry(0x1)
    		<< tx_packet_delay(0,50,10);
    
    	pack_bytes(pkt.get_payload()
    		, make_pair("APP1", 4)
    		, uint8_t(u8DI_BM)
    	);
    
      pkt.transmit();
    }

    Creating the Object

    It is created using the .prepare_tx_packet() method of the network behavior.

    if (auto&& pkt = the_twelite.network.use<NWK_SIMPLE>().prepare_tx_packet()) {
      ...
    }

    In the example above, the object pkt is obtained using the_twelite.network.use<NWK_SIMPLE>(). Although the type is inferred using auto&&, it will be a derived class of packet_tx.

    The pkt object returns true or false depending on whether the transmission queue is available. It returns false if the transmission queue is full and no more requests can be added.

    Transmission Settings

    Various settings, such as the destination address, must be configured for a wireless packet to be delivered. These settings are applied by passing configuration objects as the right-hand value of the << operator.

    pkt << tx_addr(0x00)
    	  << tx_retry(0x1)
      	<< tx_packet_delay(0,50,10);

    The following describes the configuration objects used for setting up transmission.

    tx_addr

    tx_addr(uint32_t addr)

    Specifies the destination address addr. Refer to the network behavior specification for valid address values.

    • <NWK_SIMPLE> If MSB (bit 31 = 0x80000000) is set, it indicates the destination is a serial number of a wireless module. 0x00 to 0xEF indicates an 8-bit logical ID. 0xFE is broadcast to child nodes (0x010xEF), and 0xFF is broadcast to all nodes.

    tx_retry

    tx_retry(uint8_t u8count, bool force_retry = false)

    Specifies the number of retransmissions using u8count. If force_retry is set to true, retransmission will occur regardless of whether the transmission succeeds.

    • <NWK_SIMPLE> Sends the same packet u8count+1 times. The force_retry setting is ignored.

    tx_packet_delay

    tx_packet_delay(uint16_t u16DelayMin,
                    uint16_t u16DelayMax,
                    uint16_t u16RetryDur)

    Configures delay before transmission and retry interval. Specify u16DelayMin and u16DelayMax in milliseconds. Transmission will start at a random point within this interval. Retry interval is specified by u16RetryDur, also in milliseconds.

    • <NWK_SIMPLE> This setting is valid. If the same packet arrives more than one second after the first, it will not be excluded as a duplicate. This can occur due to a long retry interval or delay in relay. Duplicate handling can be configured in <NWK_SIMPLE> initialization.

    tx_process_immediate

    tx_process_immediate()

    Requests that the packet be transmitted as quickly as possible. Transmission is normally triggered by a TickTimer operating every 1ms. This setting forces immediate processing. Has no effect unless used with tx_packet_delay(0,0,0).

    Other packet transmissions in progress will be processed normally.

    • <NWK_SIMPLE> This setting is valid.

    tx_ack_required

    tx_ack_required()

    In wireless packet communication, ACK (acknowledgment) is a short packet returned by the recipient to confirm successful reception. This setting enables ACK-based transmission.

    • <NWK_SIMPLE> This setting is invalid in <NWK_SIMPLE> and causes a compile error. <NWK_SIMPLE> does not support ACK-based communication.

    tx_addr_broadcast

    tx_addr_broadcast()
    

    Specifies broadcast as the destination.

    • <NWK_SIMPLE> This setting is invalid in <NWK_SIMPLE> and results in a compile error. Instead, use tx_addr(0xFF) for general broadcast or tx_addr(0xFE) for broadcast to child nodes.

    tx_packet_type_id

    tx_packet_type_id(uint8_t)

    Specifies the TWENET packet type ID (0 to 7).

    • <NWK_SIMPLE> This setting is invalid in <NWK_SIMPLE> and causes a compile error. The type ID is reserved internally and not user-configurable.