00001 #include <iostream>
00002 #include "SerialPort.h"
00003 #include "pdu.h"
00004
00005 using namespace std;
00006 using std::string;
00007 using namespace SerialPorts;
00008
00009 int main (int argc, char *argv[], char *envp[]) {
00010
00011
00012 string resultingPDU;
00013 pdu MyPDU;
00014 char *buf_message = argv[2];
00015 char *buf_telnr = argv[1];
00016
00017
00018
00019
00020
00021 cout << "-------------------------------------------" << endl;
00022 cout << "Get and print arguments:" << endl;
00023
00024 if ( argc != 3 ) {
00025 cout << endl;
00026 cout << "USAGE: Please provide exact 2 arguments." << endl;
00027 cout << " The 1st argument should be an internationan cell phone number." << endl;
00028 cout << " The 2nd argument should be you SMS message." << endl;
00029 cout << endl;
00030 cout << "EXAMPLE: sendsms +32478306445 \'hello there!\'" << endl;
00031 return 1;
00032 }
00033
00034 cout << "Number of arguments: " << argc - 1 << endl;
00035 cout << "Telephone: " << buf_telnr << endl;
00036 cout << "Message: " << buf_message << endl;
00037
00038
00039
00040
00041
00042 cout << "-------------------------------------------" << endl;
00043 cout << "PDU API test-runs:" << endl;
00044
00045
00046
00047
00048
00049
00050 cout << MyPDU.setText(buf_message) << endl;
00051
00052 cout << MyPDU.setSender(buf_telnr) << endl;
00053 resultingPDU = MyPDU.encodePDU();
00054
00055 int pdulenght = ((resultingPDU.length()/2) - 1);
00056
00057 cout << "AT command and lenght: " << "AT+CMGS=" << pdulenght << endl;
00058 cout << "Encoded PDU: " << resultingPDU << endl;
00059 MyPDU.parsePDU(resultingPDU);
00060 cout << "Decoding the encoded PDU back: " << MyPDU.getText() << endl;
00061 return 0;
00062
00063
00064
00065
00066
00067 cout << "-------------------------------------------" << endl;
00068 cout << "Serial-Port API test-runs:" << endl;
00069
00070 SerialPort MyPort;
00071 char buf1[30];
00072
00073
00074 char buf3[5];
00075
00076
00077 MyPort.open("/dev/rfcomm0");
00078
00079 cout << "Baud: " << MyPort.setBaudRate(BAUD_9600) << endl;
00080 cout << "CS: " << MyPort.setCharSize(CHAR_SIZE_8) << endl;
00081 cout << "Parity: " << MyPort.setParity(PARITY_NONE) << endl;
00082 cout << "Stopbits: " << MyPort.setStopBits(1) << endl;
00083 cout << "Flow Control:" << MyPort.setFlowControl(FLOW_CONTROL_NONE) << endl;
00084
00085
00086
00087 sprintf(buf1,"AT+CMGS=%d%c%c", pdulenght, (char)0x0D, (char)0x0A);
00088
00089
00090
00091
00092
00093 char *buf2 = strdup(resultingPDU.c_str());
00094 sprintf(buf3,"%c", (char)0x1A);
00095
00096 cout << "START.. sending" << endl;
00097 cout << "Written: " << MyPort.write(buf1, strlen(buf1)) << " characters" << endl;
00098 usleep(1000000);
00099 cout << "Written: " << MyPort.write(buf2, strlen(buf2)) << " characters" << endl;
00100 usleep(1000000);
00101 cout << "Written: " << MyPort.write(buf3, strlen(buf3)) << " characters" << endl;
00102 cout << "Status: " << MyPort.status() << "\n";
00103
00104
00105 free (buf2);
00106
00107
00108
00109
00110
00111 cout << "-------------------------------------------" << endl;
00112 cout << "Get device returnvalues:" << endl;
00113
00114 int bytes;
00115 int prompt = 1;
00116 string returnval;
00117
00118
00119
00120
00121 usleep(4000000);
00122 if ( MyPort.dataWaiting() > 0) {
00123 bytes = MyPort.dataWaiting();
00124 returnval = MyPort.readBytes(bytes);
00125 cout << "Return-bytes: " << bytes << endl;
00126 cout << "Return-val: " << returnval << endl;
00127 }
00128
00129
00130
00131
00132 MyPort.close();
00133
00134
00135
00136
00137
00138 return 0;
00139
00140 }