SMS message display on LED Matrix board with printer option
Dependencies: AdafruitThermalPrinter HT1632_LedMatrix VodafoneUSBModem mbed-rtos mbed
Diff: main.cpp
- Revision:
- 1:243371cb92c8
- Parent:
- 0:9d29b886d41b
- Child:
- 2:787cbb491f8f
--- a/main.cpp Fri Jan 18 08:41:20 2013 +0000 +++ b/main.cpp Wed Jan 30 16:58:33 2013 +0000 @@ -54,14 +54,14 @@ #endif #ifdef USE_PRINTER #include "AdafruitThermal.h" -//#include "test.h" #endif #define DEBUG 1 #ifdef USE_LED // Cound try to get own number usine USSD request -#define INFO_MSG " Send a message to 07765946942 " +#define INFO_MSG " Send a message to " +//#define INFO_MSG " Send a message to 07765946942 " #endif // Vodafone USSD commands @@ -71,8 +71,6 @@ #ifdef DEBUG -//Serial pc(USBTX, USBRX); // tx, rx -//Serial debug_pc(p13,p14); // tx, rx Serial debug_pc(USBTX, USBRX); // tx, rx #endif @@ -101,6 +99,8 @@ static char msgBuf[MAX_MSG_LENGTH]; #ifdef USE_LED +static char ownNumber[20]; + int crtPos = 0; int msgx = 1; // position on message screen of current character, set to 1 to allow for first scroll bool resetMessage = false; @@ -222,6 +222,62 @@ } } +#ifdef USE_LED +void getOwnNumber(VodafoneUSBModem *_modem, char *numPtr ) +{ + char numBuf[10]; + // Set RTC using received message, format is DD-MMM-YYYY HH:MM + // Month is in text name, e.g. NOV, time is using 24 hour clock. + struct tm t; + int retryCount = 3; + + while( retryCount ) { + sendUSSDCommand( _modem, USSD_COMMAND_OWN_NUMBER, false ); + +#ifdef DEBUG + debug_pc.printf("Own Number received %s\n", newMsgBuf); +#endif + + // Save number in array pointed to be numPtr + + // Terminator + *numPtr = '\0'; + +/* + + + t.tm_sec = 0; // 0-59 + strncpy(numBuf, &newMsgBuf[15], 2 ); + t.tm_min = atoi(numBuf); // 0-59 + strncpy(numBuf, &newMsgBuf[12], 2 ); + t.tm_hour = atoi(numBuf); // 0-23 + strncpy(numBuf, &newMsgBuf[0], 2 ); + t.tm_mday = atoi(numBuf); // 1-31 + strncpy(numBuf, &newMsgBuf[3], 3 ); + t.tm_mon = 0; // 0-11 + for( int i=0; i<12; i++ ) { + if( strncmp( months[i], numBuf, 3 ) == 0 ) { + t.tm_mon = i; // 0-11 + break; + } + } + strncpy(numBuf, &newMsgBuf[9], 2 ); + t.tm_year = 100 + atoi( numBuf ); // year since 1900 + + if( t.tm_year >110 ) { + // convert to timestamp and display + time_t seconds = mktime(&t); + set_time( seconds ); + retryCount = 0; // No more retries, terminate while + } else { + // Failed to set time, decrement tries + retryCount--; + } +*/ + } +} +#endif + void receiveSMS(void const*) { @@ -242,6 +298,11 @@ // debug_pc.printf("Link state Rssi: %d, Registration state %x Bearer %x\n",pRssi,pRegistrationState, pBearer); #endif +#ifdef USE_LED + // Get own number fromt he network + getOwnNumber( &modem, ownNumber ); +#endif + // sprintf(msgBuf, "Link state Rssi: %d, Registration state %x Bearer %x ",pRssi,pRegistrationState, pBearer); #ifdef USE_PRINTER // Check if time already set, if not then get it. Use year = 0 as test @@ -255,7 +316,8 @@ #endif #ifdef USE_LED //strcpy( msgBuf, INFO_MSG ); - setNewMessage( INFO_MSG ); + sprintf(newMsgBuf, "%s %s ", INFO_MSG, ownNumber ); + setNewMessage( newMsgBuf ); led.displayOn(); #endif @@ -291,11 +353,14 @@ #ifdef USE_LED resetMessage = true; } else if ( strncmp( cmdBuf, "INFO", 4 ) == 0 ) { - setNewMessage( INFO_MSG ); +// setNewMessage( INFO_MSG ); + sprintf(newMsgBuf, "%s %s ", INFO_MSG, ownNumber ); + setNewMessage( newMsgBuf ); #endif // } else if ( strncmp( cmdBuf, "DEMO", 4 ) == 0 ) { -// matrixDemo(); -// setNewMessage( INFO_MSG ); +// matrixDemo(); +// sprintf(newMsgBuf, "%s %s ", INFO_MSG, ownNumber ); +// setNewMessage( newMsgBuf ); #ifdef USE_LED } else if ( strncmp( cmdBuf, "CLEAR", 5 ) == 0 ) { setNewMessage( " " );