mbed Phone Platform
Dependencies: ulaw mbed ConfigFile
Diff: IpLine.cpp
- Revision:
- 6:bd62b12de751
- Parent:
- 5:30e2847d241b
--- a/IpLine.cpp Thu Jan 20 13:50:10 2011 +0000 +++ b/IpLine.cpp Fri Jan 21 16:06:15 2011 +0000 @@ -8,25 +8,18 @@ #define NET_TIMEOUT (FREQ * 3) #define PACKET_IDENT 0x6465626d // "mbed" -IpLine::IpLine (AnalogOut p_dac, AnalogIn p_adc) : dac(p_dac), adc(p_adc), dial(DIAL_SIZE), dabuf(DATA_SIZE * 4), adbuf(DATA_SIZE * 2) +IpLine::IpLine (EthernetNetIf *p_eth, AnalogOut p_dac, AnalogIn p_adc) : dac(p_dac), adc(p_adc), dial(DIAL_SIZE), dabuf(DATA_SIZE * 4), adbuf(DATA_SIZE * 2) , led_y(p25), led_g(p26), eth_link(P1_25), eth_speed(P1_26) { - EthernetErr r; mode = ModeOff; status = StatusNone; timeout = 0; packet_num = 1; dataskip = 0; + timerled = 0; - // dhcp - eth = new EthernetNetIf; -// eth = new EthernetNetIf(IpAddr(192,168,10,200), IpAddr(255,255,255,0), IpAddr(0,0,0,0), IpAddr(0,0,0,0)); + eth = p_eth; led_g = eth_link ? 0 : 1; - r = eth->setup(); - if (r) { - printf("Error %d in setup.\n", r); - return; - } udpsock = new UDPSocket; udpsock->setOnEvent(this, &IpLine::onLisnerEvent); @@ -54,7 +47,7 @@ if (! dabuf.get(c)) { dac.write_u16(ulaw2pcm(c)); } else { - dac.write_u16(gaussian()); + //dac.write_u16(gaussian()); } dataskip = 1; } @@ -65,11 +58,16 @@ } // adc - adbuf.put(pcm2ulaw(adc.read_u16())); -// adbuf.put(adc.read_u16() >> 8); + if (wait) { + wait --; + } else { + adbuf.put(pcm2ulaw(adc.read_u16())); +// adbuf.put(adc.read_u16() >> 8); + } } if (timeout > 1) timeout --; + if (timerled > 0) timerled --; } /// network @@ -78,7 +76,7 @@ Net::poll(); led_g = eth_link ? 0 : 1; - led_y = 0; + if (! timerled) led_y = 0; if (mode == ModeTalk && adbuf.use() >= DATA_SIZE) { // send @@ -117,8 +115,9 @@ if (e != UDPSOCKET_READABLE) return; // get data - led_g = 0; len = udpsock->recvfrom((char *)&packet, sizeof(struct ipline_packet), &recv); + led_y = 1; + timerled = FREQ / 10; if (packet.header.ident != PACKET_IDENT) return; @@ -146,8 +145,7 @@ case ModeRing: // ring --> onhook, dial if (mode == ModeReady) { - dial.put(1); - dial.put(10); + dial.put(11); dial.put(packet.header.target); dial.put(12); hook = HookOn; @@ -174,11 +172,12 @@ // send ack send(&packet.header); -/* + for (int i = 0; i < len; i ++) { printf(" %02x", ((char *)&packet)[i]); } -*/ + printf("\r\n"); + } } @@ -187,6 +186,7 @@ void IpLine::send (struct ipline_header *header) { led_y = 1; + timerled = FREQ / 10; header->ident = PACKET_IDENT; if (! header->num) { header->num = packet_num; @@ -201,6 +201,7 @@ void IpLine::send (struct ipline_packet *packet) { led_y = 1; + timerled = FREQ / 10; packet->header.ident = PACKET_IDENT; if (! packet->header.num) { packet->header.num = packet_num; @@ -214,6 +215,8 @@ int IpLine::enter (enum Mode newmode) { struct ipline_header header; + if (eth_link) return -1; // link down + mode = newmode; status = StatusOk; @@ -222,6 +225,7 @@ hook = HookOff; adbuf.clear(); dabuf.clear(); + wait = FREQ / 2; break; case ModeBT: