Exemple #1
0
void pong(uint16_t src)
{
    int trans_ok = cc1100_send_csmaca(src, protocol_id, 2, pipa->payload,
                                      sizeof(pipa->payload));

    if(trans_ok < 0) {
        print_failed();
    }
}
Exemple #2
0
void ping(radio_address_t addr, uint8_t channr){
	cc1100_set_packet_handler(protocol_id, pong_handler);
	cc1100_set_channel(channr);
	cc1100_set_address(r_address);
	while(1){
		start = swtimer_now();
		int trans_ok = cc1100_send_csmaca(addr,
			protocol_id,2,pipa->payload,sizeof(pipa->payload));
		if(trans_ok < 0)
			print_failed();
		ktimer_wait(500000);
	}
}
Exemple #3
0
/*
 * @brief Sends a radio packet to the receiver
 *
 * @param t     The transceiver device
 * @param pkt   Generic pointer to the packet (use ieee802154_packet_t for
 *              AT86RF231, CC2420, and MC1322X)
 *
 * @return A negative value if operation failed, 0 or the number of bytes sent otherwise.
 */
static int8_t send_packet(transceiver_type_t t, void *pkt)
{
    int8_t res = -1;
#if MODULE_AT86RF231 || MODULE_CC2420 || MODULE_MC1322X
    ieee802154_packet_t *p = (ieee802154_packet_t *)pkt;
    DEBUG("transceiver: Send packet to ");
#if ENABLE_DEBUG

    for (size_t i = 0; i < 8; i++) {
        printf("%02x ", p->frame.dest_addr[i]);
    }

    printf("\n");
#endif
#else
    radio_packet_t *p = (radio_packet_t *)pkt;
    DEBUG("transceiver: Send packet to %" PRIu16 "\n", p->dst);
    for (size_t i = 0; i < p->length; i++) {
        DEBUG("%02x ", p->data[i]);
    }

    DEBUG("\n");
#endif

#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY))
    cc110x_packet_t cc110x_pkt;
#endif
#ifdef MODULE_MC1322X
    maca_packet_t *maca_pkt = maca_get_free_packet();
#endif

#ifdef MODULE_CC2420
    cc2420_packet_t cc2420_pkt;
#endif

#ifdef MODULE_AT86RF231
    at86rf231_packet_t at86rf231_pkt;
#endif

    switch (t) {
        case TRANSCEIVER_CC1100:
#if (defined(MODULE_CC110X) || defined(MODULE_CC110X_LEGACY))
            cc110x_pkt.length = p->length + CC1100_HEADER_LENGTH;
            cc110x_pkt.address = p->dst;
            cc110x_pkt.flags = 0;
            memcpy(cc110x_pkt.data, p->data, p->length);
            res = cc110x_send(&cc110x_pkt);
#elif MODULE_CC110X_LEGACY_CSMA
            memcpy(cc1100_pkt, p->data, p->length);

            res = cc1100_send_csmaca(p->dst, 4, 0, (char *) cc1100_pkt, p->length);
            DEBUG("transceiver: snd_ret (%u) = %i\n", p->length, res);
#else
            puts("Unknown transceiver");
#endif
            break;
#ifdef MODULE_CC2420

        case TRANSCEIVER_CC2420:
            memcpy(&cc2420_pkt.frame, &p->frame, sizeof(ieee802154_frame_t));
            cc2420_pkt.length = p->frame.payload_len + IEEE_802154_FCS_LEN;
            res = cc2420_send(&cc2420_pkt);
            break;
#endif
#ifdef MODULE_MC1322X

        case TRANSCEIVER_MC1322X:
            maca_pkt->length = p->length;
            memcpy(maca_pkt->data, &p->frame, p->length);
            maca_set_tx_packet(maca_pkt);
            res = 1;
            break;
#endif
#ifdef MODULE_NATIVENET

        case TRANSCEIVER_NATIVE:
            res = nativenet_send(p);
            break;
#endif
#ifdef MODULE_AT86RF231

        case TRANSCEIVER_AT86RF231:
            memcpy(&at86rf231_pkt.frame, &p->frame, sizeof(ieee802154_frame_t));
            at86rf231_pkt.length = p->frame.payload_len + IEEE_802154_FCS_LEN;
            res = at86rf231_send(&at86rf231_pkt);
            break;
#endif

        default:
            puts("Unknown transceiver");
            break;
    }

    return res;
}