コード例 #1
0
ファイル: ethos.c プロジェクト: MichelRottleuthner/RIOT
static int _recv(netdev_t *netdev, void *buf, size_t len, void* info)
{
    (void) info;
    ethos_t * dev = (ethos_t *) netdev;

    if (buf) {
        if (len < dev->last_framesize) {
            DEBUG("ethos _recv(): receive buffer too small.\n");
            return -1;
        }

        len = dev->last_framesize;
        dev->last_framesize = 0;

        if ((tsrb_get(&dev->inbuf, buf, len) != (int)len)) {
            DEBUG("ethos _recv(): inbuf doesn't contain enough bytes.\n");
            return -1;
        }

        return (int)len;
    }
    else {
        return dev->last_framesize;
    }
}
コード例 #2
0
ファイル: ethos.c プロジェクト: MichelRottleuthner/RIOT
static void _end_of_frame(ethos_t *dev)
{
    switch(dev->frametype) {
        case ETHOS_FRAME_TYPE_DATA:
            if (dev->framesize) {
                dev->last_framesize = dev->framesize;
                dev->netdev.event_callback((netdev_t*) dev, NETDEV_EVENT_ISR);
            }
            break;
        case ETHOS_FRAME_TYPE_HELLO:
            ethos_send_frame(dev, dev->mac_addr, 6, ETHOS_FRAME_TYPE_HELLO_REPLY);
            /* fall through */
        case ETHOS_FRAME_TYPE_HELLO_REPLY:
            if (dev->framesize == 6) {
                tsrb_get(&dev->inbuf, (char*)dev->remote_mac_addr, 6);
            }
            break;
    }

    _reset_state(dev);
}
コード例 #3
0
ファイル: ethos.c プロジェクト: amagnasco/RIOT
static int _recv(netdev2_t *netdev, char* buf, int len, void* info)
{
    (void) info;
    ethos_t * dev = (ethos_t *) netdev;

    if (buf) {
        if (len != dev->last_framesize) {
            DEBUG("ethos _recv(): unmatched receive buffer size.");
            return -1;
        }

        dev->last_framesize = 0;

        if ((tsrb_get(&dev->inbuf, buf, len) != len)) {
            DEBUG("ethos _recv(): inbuf doesn't contain enough bytes.");
            return -1;
        }

        return len;
    }
    else {
        return dev->last_framesize;
    }
}