-
1Step 1
MSP430G2231 Code:
For a starting point I used this excellent project from Stefan Wendler. MSP430G2231 Software UART. The code below replaces main.c from his “timer-a-uart” branch.
#include <msp430.h>
#include <legacymsp430.h>
#include "uart.h"#define BUTTON BIT3 // Port 1.3
#define REDLED BIT0 // Port 1.0
#define GRNLED BIT6 // Port 1.6void uart_rx_isr(unsigned char c) {
uart_putc(c);
P1OUT ^= (REDLED + GRNLED); // flip LED output
}int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
DCOCTL = 0x00; // Set DCOCLK to 1MHz
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;// LED initial setup
P1DIR |= REDLED + GRNLED; // set P1.0 and P1.6 as output (1) pins
P1OUT |= REDLED; // Enable REDLED
P1OUT &= ~GRNLED; // Disable GRNLED// Button setup
P1DIR &= ~BUTTON; // button is an input
P1OUT |= BUTTON; // pull-up resistor
P1REN |= BUTTON; // resistor enabled
P1IES |= BUTTON; // interrupt on low-to-high transition
P1IE |= BUTTON; // interrupt enableuart_init();
// register ISR called when data was received
uart_set_rx_isr_ptr(uart_rx_isr);__enable_interrupt();
uart_puts("\n\r***************\n\r");
uart_puts("MSP430 softuart\n\r");
uart_puts("***************\n\r\n\r");while(1) {
}
}interrupt(PORT1_VECTOR) port1_isr(void) {
P1IFG = 0; // reset interrupt
uart_putc('[');
}I also included some code from TI MSP-430 LaunchPad Button & LED-Blinking Demo.
-
2Step 2
Python Code:
import serial import subprocess ser = serial.Serial() ser.port = "/dev/ttyACM0" ser.baudrate = 9600 ser.open() value = 0 blinkcount = 10 while 1: p = subprocess.Popen(["linphonecsh", "status", "hook"], stdout=subprocess.PIPE) result = p.communicate()[0] if "hook" in result : continue else : if blinkcount > 9 : ser.write("n") blinkcount = 0 else : blinkcount = blinkcount + 1 continue value = ser.read(); if value == "[": p = subprocess.Popen(["linphonecsh", "generic", "answer"], stdout=subprocess.PIPE)
This project is very portable. It could be used to signal a results from any program that can be poled from the command line. Or execute any designated command on a button press.
-
3Step 3
Yate(Yet Another Telephony Engine):
Answering Google Voice calls that are forwarded to Google chat is tricky if you don't want to use the Gmail chat application. I found the most functional results were achieved by using Yate, to create an SIP server that handles the communication with Googles servers.
These tutorial will get you up and running with your own SIP server. The first tutorial shows a fuller installation, but the second is a little newer so they are both useful. Google Voice Calls Through Yate server - using your SIP account & Yate Server: Free Google Voice Calling. On Ubuntu 12.04 you will need a newer version of Yate then is in the repositories. Check out this PPA ppa:vpol/yate. Make sure you install all the packages; yate, yate-qt4, yate-core, yate-openh323, libyate4.3.0.
At the end of the first tutorial there is a section "SIP account logged in YateClient". For some extra explanation on this section. Run Yate Client then in the setting menu select accounts. Now click new and fill out the form like this.
use provider = none
protocol = -sip-
username = username
password = something
server = 192.168.0.5These same settings can be used to register your SIP server with Empathy to send and receive calls, or with other softphones.
-
4Step 4
Linphonec and Linphonecsh:
This is the softphone I used to interact with the python program. It is a little particular to get working so here are some directions. First run linphonec once to create a .linphonerc configuration file in your home folder. You can just type quit into the terminal after it starts. Edit .linphonerc find sip_port=5060 and change it to something like sip_port=5061. Now initialize the linphonecsh daemon like this “linphonecsh init -c .linphonerc”. Finally register your SIP server with linphonecsh. “linphonecsh register --username username --host 192.168.0.5 --password something”
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.