mbed Phone Platform
Dependencies: ulaw mbed ConfigFile
Diff: main.cpp
- Revision:
- 1:0f82c574096f
- Parent:
- 0:f18953137cb4
- Child:
- 2:e37117117e79
--- a/main.cpp Mon Dec 20 22:55:29 2010 +0000 +++ b/main.cpp Sun Dec 26 15:49:07 2010 +0000 @@ -8,7 +8,9 @@ * @brief mbed Phone Platform */ #include "mbed.h" +#include "phone.h" #include "Line.h" +#include "IpLine.h" Serial pc(USBTX, USBRX); Ticker ticker; @@ -29,15 +31,38 @@ char dial[DIAL_SIZE]; enum PhoneType activesrc, activedest; +struct PhoneBook phonebook[PB_SIZE] = { + {{1, 10, 1}, PhoneLine1, ""}, + {{1, 10, 2}, PhoneLine2, ""}, + {{1, 10, 3}, PhoneMicSp, ""}, + {{2, 10, 1}, PhoneLine1, "192.168.0.4"}, + {{2, 10, 2}, PhoneLine2, "192.168.0.4"}, + {{2, 10, 3}, PhoneMicSp, "192.168.0.4"} +}; + + void int_sample () { if (timeout) timeout --; line1.poll(); line2.poll(); -// Net::poll(); } -int dialbook () { - return PhoneLine2; +int getpb (enum PhoneType *target, char *hostname) { + int i, j; + + for (i = 0; i < PB_SIZE; i ++) { + for (j = 0; j < DIAL_SIZE; j ++) { + if (phonebook[i].dial[j] == 0 || dial[j] == 0 || + j >= dialcount || phonebook[i].dial[j] != dial[j]) break; + if (j == dialcount - 1) { + *target = phonebook[i].target; + strncpy(hostname, phonebook[i].hostname, 30); + return 1; + } + } + } + + return 0; } void enteranalog (enum PhoneType target) { @@ -129,11 +154,22 @@ timeout = FREQ * 5; } if ((! timeout && dialcount > 0) || dialcount >= DIAL_SIZE) { + char buf[30]; + enum PhoneType p; // call - activedest = (enum PhoneType)dialbook(); - enterline(num, ModeCall); - enterline(activedest, ModeRing); - timeout = FREQ * 10; + if (getpb(&p, buf)) { + if (buf[0] == 0) { + activedest = p; + } else { + activedest = PhoneIpLine; +// ipline.settarget(i, buf); + } + enterline(num, ModeCall); + enterline(activedest, ModeRing); + timeout = FREQ * 10; + } else { + enterline(num, ModeBT); + } } break; @@ -151,7 +187,7 @@ enterline(activedest, ModeDisconnect); break; } - if (scanline(num, ScanStatus) == StatusOk) { + if (scanline(activedest, ScanStatus) == StatusOk) { // ok call, ring back tone enterline(num, ModeRBT); } @@ -187,7 +223,7 @@ activesrc = PhoneNone; break; } - if (scanline(num, ScanStatus) == StatusNg) { + if (scanline(activedest, ScanStatus) == StatusNg) { // disconnect enterline(num, ModeBT); } @@ -212,8 +248,6 @@ int main () { - int i, len; - char buf[MTU]; timeout = 0; dialcount = 0;