diff -Nru nonolith-connect-1.2~ppa1/cee/cee.cpp nonolith-connect-1.3~ppa3/cee/cee.cpp --- nonolith-connect-1.2~ppa1/cee/cee.cpp 2012-08-06 19:13:42.000000000 +0000 +++ nonolith-connect-1.3~ppa3/cee/cee.cpp 2012-09-19 18:34:17.000000000 +0000 @@ -217,6 +217,48 @@ } } +JSONNode CEE_device::gpio(bool set, uint8_t dir, uint8_t out){ + uint8_t buf[4]; + JSONNode j; + int r = controlTransfer(0xC0, set?0x21:0x20, out, dir, buf, 4); + j.push_back(JSONNode("status", r)); + j.push_back(JSONNode("in", buf[0])); + j.push_back(JSONNode("dir", buf[1])); + j.push_back(JSONNode("out", buf[2])); + return j; +} + +void CEE_device::handleRESTGPIOCallback(websocketpp::session_ptr client, string postdata){ + try{ + std::map map; + parse_query(postdata, map); + uint8_t dir = map_get_num(map, "dir", 0) & 0xFF; + uint8_t out = map_get_num(map, "out", 0) & 0xFF; + JSONNode j = gpio(true, dir, out); + respondJSON(client, j); + }catch(std::exception& e){ + respondError(client, e); + } +} + +bool CEE_device::handleREST(UrlPath path, websocketpp::session_ptr client){ + if (!path.leaf() && path.matches("gpio")){ + if (client->get_method() == "POST"){ + client->read_http_post_body( + boost::bind( + &CEE_device::handleRESTGPIOCallback, + boost::static_pointer_cast(shared_from_this()), + client, _1)); + }else{ + JSONNode j = gpio(false); + respondJSON(client, j); + } + return true; + }else{ + return StreamingDevice::handleREST(path, client); + } +} + void CEE_device::configure(int mode, double _sampleTime, unsigned samples, bool continuous, bool raw){ pause_capture(); diff -Nru nonolith-connect-1.2~ppa1/cee/cee.hpp nonolith-connect-1.3~ppa3/cee/cee.hpp --- nonolith-connect-1.2~ppa1/cee/cee.hpp 2012-08-06 19:13:42.000000000 +0000 +++ nonolith-connect-1.3~ppa3/cee/cee.hpp 2012-09-19 18:34:17.000000000 +0000 @@ -101,7 +101,10 @@ virtual const string serialno(){return serial;} virtual bool processMessage(ClientConn& session, string& cmd, JSONNode& n); + virtual bool handleREST(UrlPath path, websocketpp::session_ptr client); + virtual void handleRESTGPIOCallback(websocketpp::session_ptr client, string postdata); + JSONNode gpio(bool set, uint8_t dir=0, uint8_t out=0); virtual void setOutput(Channel* channel, OutputSource* source); virtual void setInternalGain(Channel* channel, Stream* stream, int gain); diff -Nru nonolith-connect-1.2~ppa1/dataserver.hpp nonolith-connect-1.3~ppa3/dataserver.hpp --- nonolith-connect-1.2~ppa1/dataserver.hpp 2012-08-06 19:13:42.000000000 +0000 +++ nonolith-connect-1.3~ppa3/dataserver.hpp 2012-09-19 18:34:17.000000000 +0000 @@ -21,6 +21,7 @@ #include "libjson/libjson.h" #include "websocketpp.hpp" void respondJSON(websocketpp::session_ptr client, JSONNode &n, int status=200); +void respondError(websocketpp::session_ptr client, std::exception& e); #include "event.hpp" #include "device.hpp" diff -Nru nonolith-connect-1.2~ppa1/debian/changelog nonolith-connect-1.3~ppa3/debian/changelog --- nonolith-connect-1.2~ppa1/debian/changelog 2012-08-07 19:41:07.000000000 +0000 +++ nonolith-connect-1.3~ppa3/debian/changelog 2012-09-19 18:49:18.000000000 +0000 @@ -1,29 +1,5 @@ -nonolith-connect (1.2~ppa1-2220574~quantal1) quantal; urgency=low +nonolith-connect (1.3~ppa3-b83cb4f2~quantal1) quantal; urgency=low - * Build from git + * Build from git b83cb4f2ce88f44d409f9299902fdff026598306 - -- Kevin Mehall Mon, 06 Aug 2012 13:14:15 -0600 - -nonolith-connect (1.1~ppa1~precise1) unstable; urgency=low - - * Build from git 558ab08a185840b0c020af74e7bddd07ce322ea6 - - -- Kevin Mehall Thu, 15 Mar 2012 16:39:03 -0600 - -nonolith-connect (1.1~beta54~ge2ec3b8~oneiric1) unstable; urgency=low - - * Build from git e2ec3b8d473e94e1859ba2642b094c0dce6a09ad - - -- Kevin Mehall Thu, 15 Mar 2012 10:14:02 -0600 - -nonolith-connect (1.1~beta53~g26a2753~oneiric1) unstable; urgency=low - - * Build from git 26a275399cf6b128536245131e3528a591253ef7 - - -- Kevin Mehall Thu, 15 Mar 2012 10:13:50 -0600 - -nonolith-connect (1.0) unstable; urgency=low - - * Initial Release. - - -- Nonolith Labs Sat, 04 Feb 2012 11:38:57 -0500 + -- Kevin Mehall Thu, 19 Sep 2012 12:35:48 -0600 diff -Nru nonolith-connect-1.2~ppa1/rest_service.cpp nonolith-connect-1.3~ppa3/rest_service.cpp --- nonolith-connect-1.2~ppa1/rest_service.cpp 2012-08-06 19:13:42.000000000 +0000 +++ nonolith-connect-1.3~ppa3/rest_service.cpp 2012-09-19 18:34:17.000000000 +0000 @@ -18,6 +18,14 @@ client->start_http(status, jc); } + +void respondError(websocketpp::session_ptr client, std::exception& e){ + JSONNode j; + j.push_back(JSONNode("error", e.what())); + std::cerr << "Exception while processing request: " << e.what() <(prevSrc); + if (s && relPhase){ + unsigned period = highSamples + lowSamples; + unsigned oldPeriod = s->highSamples + s->lowSamples; + phase += round(float((sample + s->phase)%oldPeriod)/oldPeriod * period) - sample%period; + } + phase = fmod(phase, highSamples+lowSamples); } float high, low; unsigned highSamples, lowSamples; int phase; + bool relPhase; }; struct PeriodicSource: public OutputSource{ @@ -96,7 +114,7 @@ } virtual double getPhaseZeroAfterSample(unsigned sample){ - return (double) sample + period - fmod(sample+phase, period); + return (double) sample + fmod(period - fmod(sample+phase, period), period); } double offset, amplitude, period, phase; @@ -251,7 +269,7 @@ virtual double getPhaseZeroAfterSample(unsigned sample){ unsigned per = period(); - return sample + per - sample % per + phase % per; + return sample + (per - (sample - phase) % per) % per; } int phase; @@ -271,8 +289,8 @@ throw ErrorStringException("Invalid source"); } -OutputSource* makeAdvSquare(unsigned mode, float high, float low, unsigned highSamples, unsigned lowSamples, unsigned phase){ - return new AdvSquareWaveSource(mode, high, low, highSamples, lowSamples, phase); +OutputSource* makeAdvSquare(unsigned mode, float high, float low, unsigned highSamples, unsigned lowSamples, unsigned phase, bool relPhase){ + return new AdvSquareWaveSource(mode, high, low, highSamples, lowSamples, phase, relPhase); } OutputSource* makeArbitraryWaveform(unsigned mode, int phase, ArbWavePoint_vec& values, int repeat_count){ @@ -296,7 +314,8 @@ int highSamples = jsonIntProp(n, "highSamples"); int lowSamples = jsonIntProp(n, "lowSamples"); int phase = jsonIntProp(n, "phase", 0); - r = makeAdvSquare(mode, high, low, highSamples, lowSamples, phase); + bool relPhase = jsonBoolProp(n, "relPhase", true); + r = makeAdvSquare(mode, high, low, highSamples, lowSamples, phase, relPhase); }else if (source == "sine" || source == "triangle" || source == "square"){ float offset = jsonFloatProp(n, "offset"); diff -Nru nonolith-connect-1.2~ppa1/streaming_device/rest_api.cpp nonolith-connect-1.3~ppa3/streaming_device/rest_api.cpp --- nonolith-connect-1.2~ppa1/streaming_device/rest_api.cpp 2012-08-07 18:50:51.000000000 +0000 +++ nonolith-connect-1.3~ppa3/streaming_device/rest_api.cpp 2012-09-19 18:34:17.000000000 +0000 @@ -14,13 +14,6 @@ #include #include -void respondError(websocketpp::session_ptr client, std::exception& e){ - JSONNode j; - j.push_back(JSONNode("error", e.what())); - std::cerr << "Exception while processing request: " << e.what() <(map, "time2", 0.5)/sampleTime; if (time2 <= 0) time2 = 1; int phase = map_get_num(map, "phase", 0)/sampleTime; - sourceObj = makeAdvSquare(modeval, value1, value2, time1, time2, phase); + bool relPhase = (map_get(map, "relPhase", "1") == "1"); + sourceObj = makeAdvSquare(modeval, value1, value2, time1, time2, phase, relPhase); }else if (source == "arb"){ int phase = map_get_num(map, "phase", -1)/sampleTime; diff -Nru nonolith-connect-1.2~ppa1/streaming_device/stream_listener.cpp nonolith-connect-1.3~ppa3/streaming_device/stream_listener.cpp --- nonolith-connect-1.2~ppa1/streaming_device/stream_listener.cpp 2012-03-14 00:14:46.000000000 +0000 +++ nonolith-connect-1.3~ppa3/streaming_device/stream_listener.cpp 2012-09-13 16:48:32.000000000 +0000 @@ -180,27 +180,27 @@ if (newState == true && state == false){ //std::cout << "Trigger at " << index << " " <get(*triggerStream, index-1) << " " << device->get(*triggerStream, index) << std::endl; index += triggerOffset; - triggered = true; - return true; + return (triggered = true); } state = newState; } + + if (triggerForce && index > triggerForceIndex){ + //std::cout << "Forced trigger at " << index << std::endl; + return (triggered = true); + } + }else if (triggerType == OUTSOURCE){ double zero = triggerChannel->source->getPhaseZeroAfterSample(index); - if (!triggerForce || zero <= triggerForceIndex){ + + if (std::isfinite(zero) && device->capture_o >= round(zero)){ index = round(zero) + triggerOffset; triggerSubsampleError = zero - round(zero); - }else if (triggerForceIndex > index){ + return (triggered = true); + }else if (triggerForce && device->capture_i >= triggerForceIndex){ index = triggerForceIndex; + return (triggered = true); } - triggered = true; - return true; - } - - if (triggerForce && index > triggerForceIndex){ - //std::cout << "Forced trigger at " << index << std::endl; - triggered = true; - return true; } return false; diff -Nru nonolith-connect-1.2~ppa1/streaming_device/streaming_device.hpp nonolith-connect-1.3~ppa3/streaming_device/streaming_device.hpp --- nonolith-connect-1.2~ppa1/streaming_device/streaming_device.hpp 2012-08-07 18:50:51.000000000 +0000 +++ nonolith-connect-1.3~ppa3/streaming_device/streaming_device.hpp 2012-09-13 16:48:32.000000000 +0000 @@ -299,7 +299,7 @@ OutputSource *makeConstantSource(unsigned m, float value); OutputSource *makeSource(JSONNode& description); OutputSource* makeSource(unsigned mode, const string& source, float offset, float amplitude, double period, double phase, bool relPhase); -OutputSource* makeAdvSquare(unsigned mode, float high, float low, unsigned highSamples, unsigned lowSamples, unsigned phase); +OutputSource* makeAdvSquare(unsigned mode, float high, float low, unsigned highSamples, unsigned lowSamples, unsigned phase, bool relPhase); OutputSource* makeArbitraryWaveform(unsigned mode, int offset, ArbWavePoint_vec& values, int repeat_count); Stream* findStream(const string& deviceId, const string& channelId, const string& streamId); diff -Nru nonolith-connect-1.2~ppa1/version.cpp nonolith-connect-1.3~ppa3/version.cpp --- nonolith-connect-1.2~ppa1/version.cpp 2012-08-06 19:13:42.000000000 +0000 +++ nonolith-connect-1.3~ppa3/version.cpp 2012-09-13 16:48:32.000000000 +0000 @@ -1,4 +1,4 @@ -const char* server_version="1.2"; +const char* server_version="1.3"; #ifdef GITVERSION diff -Nru nonolith-connect-1.2~ppa1/websocketpp/src/websocket_server_session.cpp nonolith-connect-1.3~ppa3/websocketpp/src/websocket_server_session.cpp --- nonolith-connect-1.2~ppa1/websocketpp/src/websocket_server_session.cpp 2012-08-06 19:13:47.000000000 +0000 +++ nonolith-connect-1.3~ppa3/websocketpp/src/websocket_server_session.cpp 2012-09-13 16:48:38.000000000 +0000 @@ -50,7 +50,7 @@ boost::asio::io_service& io_service, websocketpp::connection_handler_ptr defc, uint64_t buf_size) - : session(io_service,defc,buf_size),m_server(s) {} + : session(io_service,defc,buf_size),m_server(s),m_http_done(false) {} void server_session::on_connect() { read_handshake();