this will take a image from C328 serial camera and store those images in mbed flash as html and this html page is uploaded into the server at ip:192.168.1.2

Dependencies:   mbed

Committer:
mitesh2patel
Date:
Wed Dec 15 15:01:56 2010 +0000
Revision:
0:e1a0471e5ffb

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mitesh2patel 0:e1a0471e5ffb 1 // myrpc.cpp
mitesh2patel 0:e1a0471e5ffb 2 //
mitesh2patel 0:e1a0471e5ffb 3 // Based on:
mitesh2patel 0:e1a0471e5ffb 4 // http://mbed.org/projects/cookbook/svn/Servo/trunk/Servo.h
mitesh2patel 0:e1a0471e5ffb 5 // http://mbed.org/projects/cookbook/svn/Servo/trunk/Servo.cpp
mitesh2patel 0:e1a0471e5ffb 6 // http://mbed.org/forum/topic/234/
mitesh2patel 0:e1a0471e5ffb 7
mitesh2patel 0:e1a0471e5ffb 8 #include "myrpc.h"
mitesh2patel 0:e1a0471e5ffb 9 #ifdef MBED_RPC
mitesh2patel 0:e1a0471e5ffb 10 #include "rpc.h"
mitesh2patel 0:e1a0471e5ffb 11 #endif
mitesh2patel 0:e1a0471e5ffb 12
mitesh2patel 0:e1a0471e5ffb 13 #include "SNTPClient.h"
mitesh2patel 0:e1a0471e5ffb 14
mitesh2patel 0:e1a0471e5ffb 15 extern int gDebug;
mitesh2patel 0:e1a0471e5ffb 16
mitesh2patel 0:e1a0471e5ffb 17 namespace mbed {
mitesh2patel 0:e1a0471e5ffb 18
mitesh2patel 0:e1a0471e5ffb 19 myrpc::myrpc(PinName pin, const char *name) : Base(name), _pin(pin) {}
mitesh2patel 0:e1a0471e5ffb 20
mitesh2patel 0:e1a0471e5ffb 21 void myrpc::debug(int val) {
mitesh2patel 0:e1a0471e5ffb 22 gDebug=val;
mitesh2patel 0:e1a0471e5ffb 23 printf("Debug is %s\r\n", gDebug ? "ON" : "OFF");
mitesh2patel 0:e1a0471e5ffb 24 }
mitesh2patel 0:e1a0471e5ffb 25
mitesh2patel 0:e1a0471e5ffb 26 void myrpc::blink(int n) {
mitesh2patel 0:e1a0471e5ffb 27 for (int i=0; i<n; i++) {
mitesh2patel 0:e1a0471e5ffb 28 _pin = 1;
mitesh2patel 0:e1a0471e5ffb 29 wait(0.2);
mitesh2patel 0:e1a0471e5ffb 30 _pin = 0;
mitesh2patel 0:e1a0471e5ffb 31 wait(0.2);
mitesh2patel 0:e1a0471e5ffb 32 }
mitesh2patel 0:e1a0471e5ffb 33 }
mitesh2patel 0:e1a0471e5ffb 34
mitesh2patel 0:e1a0471e5ffb 35
mitesh2patel 0:e1a0471e5ffb 36 char *myrpc::echo(const char * in) {
mitesh2patel 0:e1a0471e5ffb 37 printf("DEBUG myrpc::echo() IN=%s\r\n",in);
mitesh2patel 0:e1a0471e5ffb 38 sprintf(_buffer, "%s", in);
mitesh2patel 0:e1a0471e5ffb 39 return _buffer;
mitesh2patel 0:e1a0471e5ffb 40 }
mitesh2patel 0:e1a0471e5ffb 41
mitesh2patel 0:e1a0471e5ffb 42 void myrpc::settime(const char *t) {
mitesh2patel 0:e1a0471e5ffb 43 time_t seconds = time(NULL);
mitesh2patel 0:e1a0471e5ffb 44 if (seconds == (unsigned)-1 || seconds == 0) {
mitesh2patel 0:e1a0471e5ffb 45 seconds = 1256729737; // Set RTC time to Wed, 28 Oct 2009 11:35:37
mitesh2patel 0:e1a0471e5ffb 46 }
mitesh2patel 0:e1a0471e5ffb 47 // set_time(seconds);
mitesh2patel 0:e1a0471e5ffb 48 SNTPSetTime(seconds);
mitesh2patel 0:e1a0471e5ffb 49 strftime(_buffer, sizeof(_buffer), "%A %m/%d/%Y %H:%M:%S", localtime(&seconds));
mitesh2patel 0:e1a0471e5ffb 50 printf("settime(%s) seconds=%d datetime=%s\r\n", t, seconds, _buffer);
mitesh2patel 0:e1a0471e5ffb 51 }
mitesh2patel 0:e1a0471e5ffb 52 char *myrpc::gettime(const char *fmt="%A %m/%d/%Y %H:%M:%S") {
mitesh2patel 0:e1a0471e5ffb 53 // time_t seconds = time(NULL);
mitesh2patel 0:e1a0471e5ffb 54 time_t seconds = SNTPTime();
mitesh2patel 0:e1a0471e5ffb 55 //printf("Time as seconds since January 1, 1970 = %d\r\n", seconds);
mitesh2patel 0:e1a0471e5ffb 56 //printf("Time as a basic string = %s\r\n", ctime(&seconds));
mitesh2patel 0:e1a0471e5ffb 57 if (!fmt || !fmt[0])
mitesh2patel 0:e1a0471e5ffb 58 fmt = "%A %m/%d/%Y %H:%M:%S";
mitesh2patel 0:e1a0471e5ffb 59 strftime(_buffer, sizeof(_buffer), fmt, localtime(&seconds));
mitesh2patel 0:e1a0471e5ffb 60 return _buffer;
mitesh2patel 0:e1a0471e5ffb 61 }
mitesh2patel 0:e1a0471e5ffb 62
mitesh2patel 0:e1a0471e5ffb 63 #ifdef MBED_RPC
mitesh2patel 0:e1a0471e5ffb 64 const rpc_method *myrpc::get_rpc_methods() {
mitesh2patel 0:e1a0471e5ffb 65 static const rpc_method rpc_methods[] = {
mitesh2patel 0:e1a0471e5ffb 66 { "debug", rpc_method_caller<myrpc, int, &myrpc::debug> },
mitesh2patel 0:e1a0471e5ffb 67 { "blink", rpc_method_caller<myrpc, int, &myrpc::blink> },
mitesh2patel 0:e1a0471e5ffb 68 { "echo", rpc_method_caller<char *, myrpc, const char *, &myrpc::echo> },
mitesh2patel 0:e1a0471e5ffb 69 { "settime", rpc_method_caller<myrpc, const char *, &myrpc::settime> },
mitesh2patel 0:e1a0471e5ffb 70 { "gettime", rpc_method_caller<char *, myrpc, const char *, &myrpc::gettime> },
mitesh2patel 0:e1a0471e5ffb 71 RPC_METHOD_SUPER(Base)
mitesh2patel 0:e1a0471e5ffb 72 };
mitesh2patel 0:e1a0471e5ffb 73 return rpc_methods;
mitesh2patel 0:e1a0471e5ffb 74 }
mitesh2patel 0:e1a0471e5ffb 75 rpc_class *myrpc::get_rpc_class() {
mitesh2patel 0:e1a0471e5ffb 76 static const rpc_function funcs[] = {
mitesh2patel 0:e1a0471e5ffb 77 "new", rpc_function_caller<const char*, PinName, const char*, &Base::construct<myrpc,PinName,const char*> >,
mitesh2patel 0:e1a0471e5ffb 78 RPC_METHOD_END
mitesh2patel 0:e1a0471e5ffb 79 };
mitesh2patel 0:e1a0471e5ffb 80 static rpc_class c = { "myrpc", funcs, NULL };
mitesh2patel 0:e1a0471e5ffb 81 return &c;
mitesh2patel 0:e1a0471e5ffb 82 }
mitesh2patel 0:e1a0471e5ffb 83 #endif
mitesh2patel 0:e1a0471e5ffb 84
mitesh2patel 0:e1a0471e5ffb 85 } // namespace mbed