Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos mbed VodafoneUSBModem_bleedingedge
main.cpp@7:316c2dac06a5, 2012-09-16 (annotated)
- Committer:
- nherriot
- Date:
- Sun Sep 16 10:53:33 2012 +0000
- Revision:
- 7:316c2dac06a5
- Parent:
- 6:5a892c3d738e
- Child:
- 8:1b4e84f4c451
changing door controller to sense it's state using the proximity switch
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nherriot | 0:5136cdfaebd0 | 1 | /* net_sms_test.cpp */ |
| nherriot | 0:5136cdfaebd0 | 2 | /* |
| nherriot | 0:5136cdfaebd0 | 3 | Copyright (C) 2012 ARM Limited. |
| nherriot | 0:5136cdfaebd0 | 4 | |
| nherriot | 0:5136cdfaebd0 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
| nherriot | 0:5136cdfaebd0 | 6 | this software and associated documentation files (the "Software"), to deal in |
| nherriot | 0:5136cdfaebd0 | 7 | the Software without restriction, including without limitation the rights to |
| nherriot | 0:5136cdfaebd0 | 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| nherriot | 0:5136cdfaebd0 | 9 | of the Software, and to permit persons to whom the Software is furnished to do |
| nherriot | 0:5136cdfaebd0 | 10 | so, subject to the following conditions: |
| nherriot | 0:5136cdfaebd0 | 11 | |
| nherriot | 0:5136cdfaebd0 | 12 | The above copyright notice and this permission notice shall be included in all |
| nherriot | 0:5136cdfaebd0 | 13 | copies or substantial portions of the Software. |
| nherriot | 0:5136cdfaebd0 | 14 | |
| nherriot | 0:5136cdfaebd0 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| nherriot | 0:5136cdfaebd0 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| nherriot | 0:5136cdfaebd0 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| nherriot | 0:5136cdfaebd0 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| nherriot | 0:5136cdfaebd0 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| nherriot | 0:5136cdfaebd0 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| nherriot | 0:5136cdfaebd0 | 21 | SOFTWARE. |
| nherriot | 0:5136cdfaebd0 | 22 | */ |
| nherriot | 0:5136cdfaebd0 | 23 | |
| nherriot | 0:5136cdfaebd0 | 24 | #define __DEBUG__ 4 //Maximum verbosity |
| nherriot | 0:5136cdfaebd0 | 25 | #ifndef __MODULE__ |
| nherriot | 6:5a892c3d738e | 26 | // #define __MODULE__ "net_voda_k3770_test.cpp" |
| nherriot | 0:5136cdfaebd0 | 27 | #endif |
| nherriot | 0:5136cdfaebd0 | 28 | |
| nherriot | 0:5136cdfaebd0 | 29 | #define MY_PHONE_NUMBER "+447717275049" |
| nherriot | 0:5136cdfaebd0 | 30 | |
| nherriot | 0:5136cdfaebd0 | 31 | #include "core/fwk.h" |
| nherriot | 0:5136cdfaebd0 | 32 | #include "mbed.h" |
| nherriot | 0:5136cdfaebd0 | 33 | #include "rtos.h" |
| nherriot | 6:5a892c3d738e | 34 | #include "VodafoneK3770.h" |
| nherriot | 0:5136cdfaebd0 | 35 | |
| nherriot | 2:bcc9256ecaab | 36 | #include <string> |
| nherriot | 2:bcc9256ecaab | 37 | |
| nherriot | 0:5136cdfaebd0 | 38 | extern "C" void HardFault_Handler() { |
| nherriot | 0:5136cdfaebd0 | 39 | error("Hard Fault!\n"); |
| nherriot | 0:5136cdfaebd0 | 40 | } |
| nherriot | 0:5136cdfaebd0 | 41 | |
| nherriot | 7:316c2dac06a5 | 42 | DigitalOut led1(LED1); |
| nherriot | 7:316c2dac06a5 | 43 | DigitalOut led2(LED2); |
| nherriot | 7:316c2dac06a5 | 44 | DigitalOut led3(LED3); |
| nherriot | 7:316c2dac06a5 | 45 | DigitalOut led4(LED4); |
| nherriot | 7:316c2dac06a5 | 46 | DigitalOut doorContactorRelay(p5); // create a digital pin object to control the door contactor relay |
| nherriot | 7:316c2dac06a5 | 47 | DigitalIn doorProximitySwitch(p20); // create a digital pin object to sense door position proximity switch |
| nherriot | 3:0a8eebcb0acf | 48 | |
| nherriot | 0:5136cdfaebd0 | 49 | |
| nherriot | 0:5136cdfaebd0 | 50 | void test(void const*) { |
| nherriot | 7:316c2dac06a5 | 51 | VodafoneK3770 connectionManager; // create a connection manager object |
| nherriot | 0:5136cdfaebd0 | 52 | |
| nherriot | 1:3c9d0c9dffa4 | 53 | DBG("Hello world and Vodafone K3770 test program!"); |
| nherriot | 0:5136cdfaebd0 | 54 | |
| nherriot | 7:316c2dac06a5 | 55 | connectionManager.sendSM(MY_PHONE_NUMBER, "Hello from mbed door controller:)"); |
| nherriot | 0:5136cdfaebd0 | 56 | |
| nherriot | 0:5136cdfaebd0 | 57 | while(true) |
| nherriot | 0:5136cdfaebd0 | 58 | { |
| nherriot | 0:5136cdfaebd0 | 59 | char num[17]; |
| nherriot | 7:316c2dac06a5 | 60 | char msg[160]; |
| nherriot | 0:5136cdfaebd0 | 61 | size_t count; |
| nherriot | 3:0a8eebcb0acf | 62 | if (doorOpen) |
| nherriot | 3:0a8eebcb0acf | 63 | { |
| nherriot | 3:0a8eebcb0acf | 64 | doorOpen = 0; |
| nherriot | 4:99bbdfe42ae0 | 65 | led3=0; |
| nherriot | 3:0a8eebcb0acf | 66 | |
| nherriot | 3:0a8eebcb0acf | 67 | } |
| nherriot | 7:316c2dac06a5 | 68 | int ret = connectionManager.getSMCount(&count); // check to see if there is an incoming SMS message |
| nherriot | 0:5136cdfaebd0 | 69 | if(ret) |
| nherriot | 0:5136cdfaebd0 | 70 | { |
| nherriot | 0:5136cdfaebd0 | 71 | WARN("getSMCount returned %d", ret); |
| nherriot | 0:5136cdfaebd0 | 72 | Thread::wait(3000); |
| nherriot | 0:5136cdfaebd0 | 73 | continue; |
| nherriot | 0:5136cdfaebd0 | 74 | } |
| nherriot | 7:316c2dac06a5 | 75 | if( count > 0) // if there are messages in the mailbox start pulling them off the queue |
| nherriot | 0:5136cdfaebd0 | 76 | { |
| nherriot | 0:5136cdfaebd0 | 77 | DBG("%d SMS to read", count); |
| nherriot | 7:316c2dac06a5 | 78 | ret = connectionManager.getSM(num, msg, 64); |
| nherriot | 0:5136cdfaebd0 | 79 | if(ret) |
| nherriot | 0:5136cdfaebd0 | 80 | { |
| nherriot | 0:5136cdfaebd0 | 81 | WARN("getSM returned %d", ret); |
| nherriot | 0:5136cdfaebd0 | 82 | Thread::wait(3000); |
| nherriot | 0:5136cdfaebd0 | 83 | continue; |
| nherriot | 0:5136cdfaebd0 | 84 | } |
| nherriot | 0:5136cdfaebd0 | 85 | |
| nherriot | 6:5a892c3d738e | 86 | DBG("The message is from number: %s and the message is: \"%s\"", num, msg); |
| nherriot | 6:5a892c3d738e | 87 | |
| nherriot | 6:5a892c3d738e | 88 | if (strcmp (msg, "open") ==0) { |
| nherriot | 2:bcc9256ecaab | 89 | DBG("The SMS message indicates I should open the door"); |
| nherriot | 7:316c2dac06a5 | 90 | |
| nherriot | 7:316c2dac06a5 | 91 | // check the door is not already open if it is do nothing and send a warning back to the sender |
| nherriot | 7:316c2dac06a5 | 92 | // for this door the switch 'true' then its closed - we have to have an active signal to show it's securely closed |
| nherriot | 7:316c2dac06a5 | 93 | if ( doorProximitySwitch.read() == 0) |
| nherriot | 7:316c2dac06a5 | 94 | { |
| nherriot | 7:316c2dac06a5 | 95 | DBG("The door is already open - so I'll do nothing"); |
| nherriot | 7:316c2dac06a5 | 96 | connectionManager.sendsm(num, " WARNING - The door is already open sir! "); |
| nherriot | 7:316c2dac06a5 | 97 | } |
| nherriot | 7:316c2dac06a5 | 98 | else |
| nherriot | 7:316c2dac06a5 | 99 | { |
| nherriot | 7:316c2dac06a5 | 100 | doorContactorRelay = 1; |
| nherriot | 7:316c2dac06a5 | 101 | led3 = 1; |
| nherriot | 7:316c2dac06a5 | 102 | DBG("The relay has been activated to open the door"); |
| nherriot | 7:316c2dac06a5 | 103 | connectionManager.sendsm(num, " Door open sir... Welcome home! " ); |
| nherriot | 6:5a892c3d738e | 104 | } else { |
| nherriot | 2:bcc9256ecaab | 105 | DBG("The SMS message is not recognized"); |
| nherriot | 7:316c2dac06a5 | 106 | connectionManager.sendSM(num, " Wrong password sir... Try 'open' and I'll open! ;-) "); |
| nherriot | 2:bcc9256ecaab | 107 | } |
| nherriot | 2:bcc9256ecaab | 108 | |
| nherriot | 2:bcc9256ecaab | 109 | |
| nherriot | 2:bcc9256ecaab | 110 | |
| nherriot | 0:5136cdfaebd0 | 111 | } |
| nherriot | 6:5a892c3d738e | 112 | Thread::wait(500); |
| nherriot | 0:5136cdfaebd0 | 113 | } |
| nherriot | 0:5136cdfaebd0 | 114 | |
| nherriot | 0:5136cdfaebd0 | 115 | } |
| nherriot | 0:5136cdfaebd0 | 116 | |
| nherriot | 0:5136cdfaebd0 | 117 | void keepAlive(void const*) { |
| nherriot | 0:5136cdfaebd0 | 118 | while(1) |
| nherriot | 0:5136cdfaebd0 | 119 | { |
| nherriot | 0:5136cdfaebd0 | 120 | led1=!led1; |
| nherriot | 0:5136cdfaebd0 | 121 | Thread::wait(500); |
| nherriot | 0:5136cdfaebd0 | 122 | } |
| nherriot | 0:5136cdfaebd0 | 123 | } |
| nherriot | 0:5136cdfaebd0 | 124 | |
| nherriot | 0:5136cdfaebd0 | 125 | void tick() |
| nherriot | 0:5136cdfaebd0 | 126 | { |
| nherriot | 0:5136cdfaebd0 | 127 | led4=!led4; |
| nherriot | 0:5136cdfaebd0 | 128 | } |
| nherriot | 0:5136cdfaebd0 | 129 | |
| nherriot | 0:5136cdfaebd0 | 130 | int main() { |
| nherriot | 0:5136cdfaebd0 | 131 | Ticker t; |
| nherriot | 0:5136cdfaebd0 | 132 | t.attach(tick,1); |
| nherriot | 0:5136cdfaebd0 | 133 | DBG_INIT(); |
| nherriot | 0:5136cdfaebd0 | 134 | |
| nherriot | 0:5136cdfaebd0 | 135 | Thread testTask(test, NULL, osPriorityNormal, 1024*4); |
| nherriot | 6:5a892c3d738e | 136 | // keepAlive(NULL); |
| nherriot | 0:5136cdfaebd0 | 137 | |
| nherriot | 0:5136cdfaebd0 | 138 | |
| nherriot | 0:5136cdfaebd0 | 139 | return 0; |
| nherriot | 0:5136cdfaebd0 | 140 | } |

