mbed Phone Platform
Dependencies: ulaw mbed ConfigFile
Diff: main.cpp
- Revision:
- 2:e37117117e79
- Parent:
- 1:0f82c574096f
- Child:
- 3:1d5dc4107558
--- a/main.cpp Sun Dec 26 15:49:07 2010 +0000 +++ b/main.cpp Wed Jan 05 15:43:53 2011 +0000 @@ -4,9 +4,10 @@ * Released under the MIT License: http://mbed.org/license/mit */ -/** @file +/** @file main.cpp * @brief mbed Phone Platform */ + #include "mbed.h" #include "phone.h" #include "Line.h" @@ -22,6 +23,7 @@ DigitalOut mixlocal(p21), mixline(p22), micsp(p23); Line line1(p12, p13, p11, dac); Line line2(p14, p15, p16, dac); +IpLine ipline(dac, adc); DigitalOut led_y(p25), led_g(p26); DigitalIn eth_link(P1_25), eth_speed(P1_26); @@ -35,16 +37,23 @@ {{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"} + {{2, 10, 1}, PhoneLine1, "192.168.0.3"}, + {{2, 10, 2}, PhoneLine2, "192.168.0.3"}, + {{2, 10, 3}, PhoneMicSp, "192.168.0.3"} +/* + {{2, 10, 1}, PhoneLine1, "192.168.10.100"}, + {{2, 10, 2}, PhoneLine2, "192.168.10.100"}, + {{2, 10, 3}, PhoneMicSp, "192.168.10.100"} +*/ }; void int_sample () { + line1.intr(); + line2.intr(); + ipline.intr(); + if (timeout) timeout --; - line1.poll(); - line2.poll(); } int getpb (enum PhoneType *target, char *hostname) { @@ -77,6 +86,7 @@ switch (target) { case PhoneLine1: case PhoneLine2: + case PhoneIpLine: mixline = 1; break; case PhoneMicSp: @@ -96,10 +106,9 @@ /* case PhoneMicSp: return micsp.enter(mode); +*/ case PhoneIpLine: - ipline.target(dial[1]); return ipline.enter(mode); -*/ } return 0; } @@ -114,10 +123,9 @@ /* case PhoneMicSp: return micsp.scan(type); +*/ case PhoneIpLine: - ipline.target(dial[1]); return ipline.scan(type); -*/ } return 0; } @@ -145,15 +153,15 @@ break; } i = scanline(num, ScanDial); - if (i > 0) { + if (i > 0 && i < 12) { // detect dial dial[dialcount] = i; dialcount ++; pc.printf(" [ %d ] ", i); if (scanline(num, ScanMode) == ModeDT) enterline(num, ModeDial); - timeout = FREQ * 5; + timeout = DIAL_TIMEOUT; } - if ((! timeout && dialcount > 0) || dialcount >= DIAL_SIZE) { + if ((! timeout && dialcount > 0) || dialcount >= DIAL_SIZE || i >= 12) { char buf[30]; enum PhoneType p; // call @@ -162,11 +170,11 @@ activedest = p; } else { activedest = PhoneIpLine; -// ipline.settarget(i, buf); + ipline.settarget(p, buf); } enterline(num, ModeCall); enterline(activedest, ModeRing); - timeout = FREQ * 10; + timeout = CALL_TIMEOUT; } else { enterline(num, ModeBT); } @@ -181,16 +189,17 @@ activesrc = PhoneNone; break; } - if (timeout == 0) { + i = scanline(activedest, ScanStatus); + if (i == StatusOk) { + // ok call, ring back tone + enterline(num, ModeRBT); + } + if (timeout == 0 || i == StatusNg) { // timeout, busy enterline(num, ModeBT); enterline(activedest, ModeDisconnect); break; } - if (scanline(activedest, ScanStatus) == StatusOk) { - // ok call, ring back tone - enterline(num, ModeRBT); - } break; case ModeRBT: @@ -206,7 +215,7 @@ if (scanline(num, ScanHook) == HookOn) { // on hook, connect if (num == PhoneIpLine || activesrc == PhoneIpLine) { - enteranalog(activesrc); + enteranalog(PhoneIpLine); } else { enteranalog(PhoneNone); } @@ -248,23 +257,55 @@ int main () { - + int i; + timeout = 0; dialcount = 0; activesrc = PhoneNone; activedest = PhoneNone; line1.enter(ModeReady); line2.enter(ModeReady); + ipline.enter(ModeReady); ticker.attach_us(&int_sample, 1000000 / FREQ); for (;;) { - pc.printf("1: %d - ", scanline(PhoneLine1, ScanMode)); + ipline.poll(); + + i = scanline(PhoneLine1, ScanMode); checkline(PhoneLine1); - pc.printf("%d / ", scanline(PhoneLine1, ScanMode)); - pc.printf("2: %d - ", scanline(PhoneLine2, ScanMode)); + if (i != scanline(PhoneLine1, ScanMode)) + pc.printf("(1) %d -> %d\r\n", i, scanline(PhoneLine1, ScanMode)); + + i = scanline(PhoneLine2, ScanMode); checkline(PhoneLine2); - pc.printf("%d\r\n", scanline(PhoneLine2, ScanMode)); - wait(0.2); + if (i != scanline(PhoneLine2, ScanMode)) + pc.printf("(2) %d -> %d\r\n", i, scanline(PhoneLine2, ScanMode)); + + i = scanline(PhoneIpLine, ScanMode); + checkline(PhoneIpLine); + if (i != scanline(PhoneIpLine, ScanMode)) + pc.printf("(3) %d -> %d\r\n", i, scanline(PhoneIpLine, ScanMode)); + + // debug + if(pc.readable()) { + if (pc.getc() == 'a') { + char buf[30]; + enum PhoneType p; + dial[0] = 2; + dial[1] = 10; + dial[2] = 1; + dialcount = 3; + if (getpb(&p, buf)) { + if (buf[0] != 0) { + activedest = PhoneIpLine; + ipline.settarget(p, buf); + enterline(PhoneLine1, ModeCall); + enterline(activedest, ModeRing); + } + } + } + } + } }