Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

STM32 DatagramSocket.available always returns -22 #592

Open
christiansiegel opened this issue Aug 15, 2016 · 0 comments
Open

STM32 DatagramSocket.available always returns -22 #592

christiansiegel opened this issue Aug 15, 2016 · 0 comments

Comments

@christiansiegel
Copy link

The STM32 DatagramSocket provides the overloaded _SocketBase.available, which calls FreeRTOS_recvcount(). This method is only applicable to TCP sockets (see FreeRTOS doc) and otherwise returns EINVAL.

Example:

import 'dart:dartino.ffi';
import 'dart:dartino' show sleep;
import 'package:socket/socket.dart';
import 'package:stm32/ethernet.dart';

main() {
  if (Foreign.platform == Foreign.FREERTOS) initializeNetwork();

  DatagramSocket sock = new DatagramSocket.bind("0.0.0.0", 6000);

  print("receiving...");

  while (true) {
    if (sock.available <= 0) continue; // this is always true on STM32
    Datagram datagram = sock.receive();
    if (datagram != null) print("${datagram.sender.toString()}");
  }
}

void initializeNetwork() {
  if (!ethernet.initializeNetworkStack(
      const InternetAddress(const <int>[192, 168, 0, 10]),
      const InternetAddress(const <int>[255, 255, 255, 0]),
      const InternetAddress(const <int>[192, 168, 0, 1]),
      const InternetAddress(const <int>[8, 8, 8, 8]))) {
    throw "Failed to initialize network stack";
  }
  while (NetworkInterface.list().first.addresses.isEmpty) {
    sleep(10);
  }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants