Shop OBEX P1 Docs P2 Docs Learn Events
Spinneret code hangs — Parallax Forums

Spinneret code hangs

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
edited 2011-03-21 06:55 in Accessories
I've been having rather more than intermittent problems with my Spinneret servers hanging. Here's the main loop that one of my servers uses to get requests:
  repeat
    if (request := server.request0)
      if (strcomp(request, string("/index")) or strcomp(request, string("/")))
        main_page
      elseif (strcomp(request, string("/temp_chart.bmp")))
        do_chart(TEMP)
      elseif (strcomp(request, string("/light_chart.bmp")))
        do_chart(LIGHT)
      else
        server.not_found
    if (cnt - time => clkfreq * SAMPLE_INTERVAL)
      !outa[LED]
      ttemp += sense.temp_fahrenheit
      tlight += sense.ambient_light
      ifnot (nsamples := (nsamples + 1) // PLOT_INTERVAL)
        cht[TEMP].add_datum(ttemp * 10 / PLOT_INTERVAL)
        cht[LIGHT].add_datum(sense.log(tlight / PLOT_INTERVAL) * 1000 / sense.log(10))
        ttemp~
        tlight~
      time += clkfreq * SAMPLE_INTERVAL    

Here's the wrapper code that it calls:
PUB request

  repeat until get_request
  return parse(@data)

PUB request0

  if (get_request)
    return parse(@data)
  else
    return false

PUB get_request : packet_size | time

  ifnot w5100.SocketTCPestablished(0)
    return
  ifnot (lookdown(get_status : $14, $16, $17, $11))
    socket_reset
    return
  time := cnt
  repeat until (cnt - time > timeout)
    if (packet_size := W5100.rxTCP(0, @data))
      data[packet_size]~
      return
  socket_reset
  return
      
PRI get_status : status

  w5100.readIND(w5100#_S0_SR, @status, 1)

PRI socket_reset

  socket_close
  socket_open

PRI socket_open

  w5100.SocketOpen(0, W5100#_TCPPROTO, port, port, @client)
  waitcnt(clkfreq / 4 + cnt)
  w5100.SocketTCPlisten(0)
  waitcnt(clkfreq / 4 + cnt)

PRI socket_close

  w5100.SocketTCPdisconnect(0)
  waitcnt(clkfreq / 40 + cnt)
  w5100.SocketClose(0)

Right now, I know the main loop is running, because the yellow LED is flashing on and off. But it's not recognizing requests. The sniffer shows that every SYN that comes in is being answered by the W5100 with a RST.

-Phil

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-03-21 06:55
    Phil, Do you know status register value at the time of hang or the the status register values right before it hangs? I've had a couple of locks where everything looks fine in the log. The last pages viewed where simply static pages. My initial thought was I need better logging to figure out what series of events occurred. Maybe look at another W5100 register?
Sign In or Register to comment.