Web radiation monitoring system.

Dependencies:   EthernetNetIf TextLCD mbed HTTPServer

Files at this revision

API Documentation at this revision

Comitter:
moritams
Date:
Tue May 24 10:53:04 2011 +0000
Commit message:
prototype. ver0.0

Changed in this revision

EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
HTTPServer.lib Show annotated file Show diff for this revision Revisions of this file
RPCInterface.lib Show annotated file Show diff for this revision Revisions of this file
SimpleHandler.cpp Show annotated file Show diff for this revision Revisions of this file
SimpleHandler.h Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r de8fcaf0fc9b EthernetNetIf.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Tue May 24 10:53:04 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
diff -r 000000000000 -r de8fcaf0fc9b HTTPServer.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPServer.lib	Tue May 24 10:53:04 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPServer/#d753966e4d97
diff -r 000000000000 -r de8fcaf0fc9b RPCInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RPCInterface.lib	Tue May 24 10:53:04 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/MichaelW/code/RPCInterface/#a9e2c45097c8
diff -r 000000000000 -r de8fcaf0fc9b SimpleHandler.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleHandler.cpp	Tue May 24 10:53:04 2011 +0000
@@ -0,0 +1,72 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "SimpleHandler.h"
+
+//#define __DEBUG
+#include "dbg/dbg.h"
+
+SimpleHandler::SimpleHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket) : HTTPRequestHandler(rootPath, path, pTCPSocket)
+{}
+
+SimpleHandler::~SimpleHandler()
+{
+  DBG("Handler destroyed\r\n");
+}
+
+void SimpleHandler::doGet()
+{
+  DBG("In SimpleHandler::doGet()\r\n");
+  const char* resp = "Hello world !";
+  setContentLen( strlen(resp) );
+  respHeaders()["Connection"] = "close";
+  writeData(resp, strlen(resp));
+  DBG("Exit SimpleHandler::doGet()\r\n");
+}
+
+void SimpleHandler::doPost()
+{
+
+}
+
+void SimpleHandler::doHead()
+{
+
+}
+
+  
+void SimpleHandler::onReadable() //Data has been read
+{
+
+}
+
+void SimpleHandler::onWriteable() //Data has been written & buf is free
+{
+  DBG("SimpleHandler::onWriteable() event\r\n");
+  close(); //Data written, we can close the connection
+}
+
+void SimpleHandler::onClose() //Connection is closing
+{
+  //Nothing to do
+}
diff -r 000000000000 -r de8fcaf0fc9b SimpleHandler.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SimpleHandler.h	Tue May 24 10:53:04 2011 +0000
@@ -0,0 +1,47 @@
+
+/*
+Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef SIMPLE_HANDLER_H
+#define SIMPLE_HANDLER_H
+
+#include "../HTTPRequestHandler.h"
+
+class SimpleHandler : public HTTPRequestHandler
+{
+public:
+  SimpleHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket);
+  virtual ~SimpleHandler();
+
+//protected:
+  static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocket* pTCPSocket) { return new SimpleHandler(rootPath, path, pTCPSocket); } //if we ever could do static virtual functions, this would be one
+
+  virtual void doGet();
+  virtual void doPost();
+  virtual void doHead();
+  
+  virtual void onReadable(); //Data has been read
+  virtual void onWriteable(); //Data has been written & buf is free
+  virtual void onClose(); //Connection is closing
+};
+
+#endif
diff -r 000000000000 -r de8fcaf0fc9b TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Tue May 24 10:53:04 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 000000000000 -r de8fcaf0fc9b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 24 10:53:04 2011 +0000
@@ -0,0 +1,157 @@
+// Hello World! for the TextLCD
+ 
+#include "mbed.h"
+#include "TextLCD.h"
+#include "EthernetNetIf.h"
+#include "HTTPServer.h"
+#include "ipaddr.h"
+#include "RPCVariable.h"
+
+IpAddr ip(192,168,1,121);
+IpAddr netmask(255,255,255,0);
+IpAddr gateway(192,168,1,1);
+IpAddr dns(192,168,1,1);
+
+EthernetNetIf eth(ip,netmask,gateway,dns);  
+HTTPServer svr;
+
+DigitalOut led1(LED1);
+
+InterruptIn geigerIn(p5);
+
+TextLCD lcd(p24, p26, p27, p28, p29, p30); // rs, e, d4-d7
+
+unsigned int count = 0;
+unsigned int prev_count = 0;
+unsigned int i = 0;
+
+
+class MyHandler : public HTTPRequestHandler
+{
+public:
+  MyHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket);
+  virtual ~MyHandler();
+
+//protected:
+  static inline HTTPRequestHandler* inst(const char* rootPath, const char* path, TCPSocket* pTCPSocket) { return new MyHandler(rootPath, path, pTCPSocket); } //if we ever could do static virtual functions, this would be one
+
+  virtual void doGet();
+  virtual void doPost();
+  virtual void doHead();
+  
+  virtual void onReadable(); //Data has been read
+  virtual void onWriteable(); //Data has been written & buf is free
+  virtual void onClose(); //Connection is closing
+};
+
+MyHandler::MyHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket) : HTTPRequestHandler(rootPath, path, pTCPSocket)
+{
+}
+
+MyHandler::~MyHandler()
+{
+}
+
+void MyHandler::doGet()
+{
+  const char* resp = "Hello world !";
+  char a[64];
+  sprintf(a, "%d CPM.\n\0", ::prev_count);
+  //setContentLen( strlen(resp) );
+  setContentLen( strlen(a) );
+
+  respHeaders()["Connection"] = "close";
+
+  //writeData(resp, strlen(resp));
+  writeData(a, strlen(a));
+
+}
+
+void MyHandler::doPost()
+{
+
+}
+
+void MyHandler::doHead()
+{
+
+}
+
+  
+void MyHandler::onReadable() //Data has been read
+{
+
+}
+
+void MyHandler::onWriteable() //Data has been written & buf is free
+{
+  close(); //Data written, we can close the connection
+}
+
+void MyHandler::onClose() //Connection is closing
+{
+  //Nothing to do
+}
+
+
+void radioactive()
+{
+  count = count + 1;
+}
+
+void count_minutes()
+{
+    lcd.locate(0, 0);
+    lcd.printf("%04dCPM ", count); lcd.printf("%02dsec", i);
+    lcd.locate(0, 1);
+    lcd.printf("Prev. %04dCPM ", prev_count);
+    
+    i = i + 1;
+      
+    if(i > 59)
+    {
+      i = 0;
+      prev_count = count;
+      count = 0;
+    }
+}
+
+int main() {
+
+  // Count variables clear.
+  count = 0;
+  prev_count = 0;
+
+  lcd.cls();
+  lcd.locate(0, 0);
+
+  geigerIn.fall(&radioactive);
+
+  EthernetErr ethErr = eth.setup();
+  if(ethErr)
+  {
+    return -1;
+  }
+  
+  svr.addHandler<SimpleHandler>("/"); //Default handler
+  svr.addHandler<MyHandler>("/geiger"); 
+
+  svr.bind(80);
+
+  Ticker tick;
+  tick.attach(count_minutes, 1);   
+  
+  Timer tm;
+  tm.start();
+  //Listen indefinitely
+  while(true)
+  {
+    Net::poll();
+    if(tm.read()>.5)
+    {
+      led1=!led1; //Show that we are alive
+      tm.start();
+    }
+  }
+
+}
\ No newline at end of file
diff -r 000000000000 -r de8fcaf0fc9b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue May 24 10:53:04 2011 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e