Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 162 lines (137 sloc) 3.4 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
// VLISP - Jan 2012

proto main 0;;
proto earsInit 0;;
proto evalTrame 1;;

#include "src/lib/var"
#include "src/lib/util"
#include "src/lib/cfg"
#include "src/lib/arp"
#include "src/lib/udp"
#include "src/lib/tcp"
#include "src/lib/dns"
#include "src/lib/http"
#include "src/lib/dhcp"
#include "src/lib/wav"
#include "lib/data_helper"
#include "lib/buffer"
#include "src/lib/wifi"

var recordingStartedAt = 0;;
var recSeconds = 0;;

//-------------------- HTTP Endpoints
fun logUrl=
  strcatlist confGetServerUrl::"/api/log.jsp"::nil;;

fun buttonPressedUrl data=
  strcatlist confGetServerUrl::"/api/button-pressed.jsp?duration="::(itoa data)::nil;;

fun recordingFinishedUrl =
  strcatlist confGetServerUrl::"/api/recording-finished.jsp"::nil;;

fun rfidUrl tag=
  strcatlist confGetServerUrl::"/api/rfid.jsp?id="::(webmac tag)::nil;;

fun pingUrl =
  strcatlist confGetServerUrl::"/api/ping.jsp"::nil;;

//-------------------- HTTP

fun _cbdummyhttp http res=
  0;;

fun _cbHttp http res=
  evalTrame res;
  0;;

#include "lib/record"
#include "lib/ping"

fun evalTrame res=
  let parseResponse httpgetcontent res -> bufferlist in
    if bufferlist != nil then
    (
      for l = bufferlist; l != nil; tl l do
      (
        let hd l -> [code val] in
        if code == 12 then // OK
        (
          0
        )
        else if code == 16 then // (RE) INIT
        (
          earsInit;
          0
        )
        else if code == 17 then // LOG
        (
          httprequest "POST" logUrl (strcat "logs=" logs) #_cbdummyhttp HTTP_NORMAL;
          set logs = "";
          0
        )
        else if code == 18 then // ERROR
        (
          0
        )
        else if code == 19 then // REBOOT
        (
          exit
        )
        // led buffers: short 20-24 loop 25-29; 3Byte: short 30-34 loop 35-39
        else if code >= 20 && code <= 39 then
        (
          let code % 10 -> index in
          let 2 * (code / 30) + 1 -> step in
          let index / 5 -> loop in
          _bufferFill index step loop val;
          0
        )
        // ear buffers: short 40-41, loop 42-43
        else if code >= 40 && code <= 43 then
        (
          let code % 10 -> index in
          let 1 -> step in
          let index / 2 -> loop in
          _bufferFill index+10 step loop val;
          0
        )
        // recording start
        else if code == 50 then
        (
          set recSeconds = strget val 0;
          set recSeconds = 1000 * recSeconds;
          recordingStart;
          set recordingStartedAt = time_ms
        )
        // recording stop
        else if code == 51 then
        (
          recordingStop
        )
      )
    )
;;

//inputs
// #include "lib/rfid"
#include "lib/button"

//outputs
#include "lib/led"
#include "lib/ear"

//###############################################
//-------------------- LOOP ---------------------
fun loop=
  wifiRun;
  wifiCheck;

  // checkRFID;
  checkButton;

  setLeds;
  earRead 0;
  earRead 1;

  pingCheck;

  if recording == 1 && recSeconds > 0 && (time_ms - recordingStartedAt) > recSeconds then
  (
    recordingStop
  );
0;;

//###############################################
//-------------------- MAIN ---------------------
fun main=
  confInit;
  wifiInit 0;
  buffersInit 14;
  earsInit;

  loopcb #loop; // 20 p. second

  netstart;
  startdnsclient;

  sndVol 0;
  srand time_ms;
0;;
Something went wrong with that request. Please try again.