mbed Phone Platform
Dependencies: ulaw mbed ConfigFile
Diff: main.cpp
- Revision:
- 6:bd62b12de751
- Parent:
- 5:30e2847d241b
--- a/main.cpp Thu Jan 20 13:50:10 2011 +0000 +++ b/main.cpp Fri Jan 21 16:06:15 2011 +0000 @@ -9,10 +9,13 @@ */ #include "mbed.h" +#include "EthernetNetIf.h" #include "phone.h" #include "Line.h" #include "IpLine.h" +EthernetNetIf *eth; + Serial pc(USBTX, USBRX); Ticker ticker; @@ -23,32 +26,19 @@ DigitalOut mixlocal(p21), mixline(p22), micsp(p23); Line line1(p12, p13, p11, dac); Line line2(p14, p15, p16, dac); -IpLine ipline(dac, adc); - -volatile int timeout; -int dialcount; -char dial[DIAL_SIZE]; -enum PhoneType activesrc, activedest; +IpLine *ipline; -struct PhoneBook phonebook[PB_SIZE] = { - {{1, 10, 1}, PhoneLine1, ""}, - {{1, 10, 2}, PhoneLine2, ""}, - {{1, 10, 3}, PhoneMicSp, ""}, - {{2, 10, 1}, PhoneLine1, "192.168.1.2"}, - {{2, 10, 2}, PhoneLine2, "192.168.1.2"}, - {{2, 10, 3}, PhoneMicSp, "192.168.1.2"} -/* - {{2, 10, 1}, PhoneLine1, "192.168.10.100"}, - {{2, 10, 2}, PhoneLine2, "192.168.10.100"}, - {{2, 10, 3}, PhoneMicSp, "192.168.10.100"} -*/ -}; - +volatile int timeout, dialcount, useipline; +volatile enum PhoneType activesrc, activedest; +char dial[DIAL_SIZE]; +struct PhoneBook phonebook[PB_SIZE]; void int_sample () { line1.intr(); line2.intr(); - ipline.intr(); + if (useipline) { + ipline->intr(); + } if (timeout) timeout --; } @@ -56,15 +46,21 @@ int getpb (enum PhoneType *target, char *hostname) { int i, j; + if (dial[0] == 11 && dial[1] >= 1 && dial[1] <= 3) { + *target = (enum PhoneType)dial[1]; + hostname[0] = 0; + return 1; + } + 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) { + if (phonebook[i].dial[j] == 0 && dial[j] == 0) { *target = phonebook[i].target; strncpy(hostname, phonebook[i].hostname, HOSTNAME_SIZE); return 1; } + if (phonebook[i].dial[j] == 0 || dial[j] == 0 || + j >= dialcount || phonebook[i].dial[j] != dial[j]) break; } } @@ -105,7 +101,7 @@ return micsp.enter(mode); */ case PhoneIpLine: - return ipline.enter(mode); + return ipline->enter(mode); } return 0; } @@ -122,7 +118,7 @@ return micsp.scan(type); */ case PhoneIpLine: - return ipline.scan(type); + return ipline->scan(type); } return 0; } @@ -162,12 +158,15 @@ char buf[HOSTNAME_SIZE]; enum PhoneType p; // call + dial[dialcount] = 0; if (getpb(&p, buf)) { +printf("-> %d %s\r\n", p, buf); if (buf[0] == 0) { activedest = p; - } else { + } else + if (useipline) { activedest = PhoneIpLine; - ipline.settarget(p, buf); + ipline->settarget(p, buf); } enterline(num, ModeCall); enterline(activedest, ModeRing); @@ -257,20 +256,29 @@ int i; timeout = 0; + useipline = 0; dialcount = 0; activesrc = PhoneNone; activedest = PhoneNone; + + config(); + line1.enter(ModeReady); line2.enter(ModeReady); - ipline.enter(ModeReady); + if (useipline) { + ipline = new IpLine(eth, dac, adc); + ipline->enter(ModeReady); + } // NVIC_SetPriority(TIMER3_IRQn, 0); // preemption=1, sub-priority=1 ticker.attach_us(&int_sample, 1000000 / FREQ); for (;;) { - led1 = 1; - ipline.poll(); - led1 = 0; + if (useipline) { + led1 = 1; + ipline->poll(); + led1 = 0; + } led2 = 1; line1.poll(); led2 = 0; @@ -288,10 +296,12 @@ 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)); + if (useipline) { + i = scanline(PhoneIpLine, ScanMode); + checkline(PhoneIpLine); + if (i != scanline(PhoneIpLine, ScanMode)) + pc.printf("(3) %d -> %d\r\n", i, scanline(PhoneIpLine, ScanMode)); + } } }