Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using Microsoft.SPOT;
- using Microsoft.SPOT.Presentation;
- using Microsoft.SPOT.Presentation.Controls;
- using Microsoft.SPOT.Presentation.Media;
- using Microsoft.SPOT.Touch;
- using Gadgeteer.Networking;
- using GT = Gadgeteer;
- using GTM = Gadgeteer.Modules;
- using Gadgeteer.Modules.GHIElectronics;
- using Gadgeteer.Modules.Seeed;
- namespace Gadgeteer_GPS_Cellular_Request_01
- {
- public partial class Program
- {
- GT.Timer timer = new GT.Timer(5000);
- bool gpsPositionHasBeenReceived = false;
- void ProgramStarted()
- {
- gps.InvalidPositionReceived += new GTM.Seeed.GPS.InvalidPositionReceivedHandler(gps_InvalidPositionReceived);
- gps.PositionReceived += new GTM.Seeed.GPS.PositionReceivedHandler(gps_PositionReceived);
- gps.NMEASentenceReceived += new GPS.NMEASentenceReceivedHandler(gps_NMEASentenceReceived);
- // create a timer robot
- timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
- timer.Start();
- // create a button watching robot to fire off button pressed instructions
- //button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
- //button.ButtonPressed += new Button.ButtonEventHandler(resetButton_ButtonPressed);
- button.ButtonPressed+=new Button.ButtonEventHandler(button_ButtonPressed);
- button.TurnLEDOff();
- //
- cellularRadio.DebugPrintEnabled = true;
- cellularRadio.PowerOn(5);
- cellularRadio.SmsReceived += new CellularRadio.SmsReceivedHandler(cellularRadio_NewSMSEvent);
- cellularRadio.ModuleInitialized += new CellularRadio.ModuleInitializedHandler(cellularRadio_ModuleInitialized);
- // tell everyone that you have started
- Debug.Print("Program Started");
- }
- /*void button_ButtonPressed(Button sender, Button.ButtonState state)
- {
- Debug.Print("GPS last position " + gps.LastPosition + " age " + gps.LastValidPositionAge);
- }*/
- void timer_Tick(GT.Timer timer)
- {
- Debug.Print("GPS last position " + gps.LastPosition + " age " + gps.LastValidPositionAge);
- }
- void gps_InvalidPositionReceived(GTM.Seeed.GPS sender)
- {
- Debug.Print("Invalid position");
- }
- void gps_PositionReceived(GTM.Seeed.GPS sender, GTM.Seeed.GPS.Position position)
- {
- gpsPositionHasBeenReceived = true;
- Debug.Print(position);
- }
- void gps_NMEASentenceReceived(GPS sender, string nmeaSentence)
- {
- if (!gpsPositionHasBeenReceived)
- {
- Debug.Print("NMEA Sentence: " + nmeaSentence);
- }
- }
- void cellularRadio_NewSMSEvent(CellularRadio sender, CellularRadio.Sms message)
- {
- if (message != null)
- {
- Debug.Print("NEW SMS");
- Debug.Print("FROM: " + message.TelephoneNumber);
- Debug.Print("MSG: " + message.TextMessage);
- Debug.Print("WHEN: " + message.Timestamp);
- Debug.Print("STATUS: " + message.Status);
- Debug.Print("POS:" + message.Index);
- // remove extra '+'
- message.TelephoneNumber = message.TelephoneNumber.Trim('+');
- if (cellularRadio.SendSms(message.TelephoneNumber, gps.LastPosition) != GTM.Seeed.CellularRadio.ReturnedState.OK)
- {
- Debug.Print("Retrieve clock failed");
- }
- }
- }
- void button_ButtonPressed(Button sender, Button.ButtonState state)
- {
- if (cellularRadio.SendSms("1401***8678", "Send me a text and I'll tell you where I am! Regards, Gadgeteer") != GTM.Seeed.CellularRadio.ReturnedState.OK)
- {
- Debug.Print("Retrieve clock failed");
- }
- }
- void cellularRadio_SMSReady(CellularRadio sender, CellularRadio.Sms message)
- {
- if (message != null)
- {
- Debug.Print("RETRIEVED");
- Debug.Print("FROM: " + message.TelephoneNumber);
- Debug.Print("MSG: " + message.TextMessage);
- Debug.Print("WHEN: " + message.Timestamp);
- Debug.Print("STATUS: " + message.Status);
- Debug.Print("POS:" + message.Index);
- }
- }
- void cellularRadio_PhoneActivityRetrieved(CellularRadio sender, CellularRadio.PhoneActivityType activity)
- {
- Debug.Print("Activity: " + activity);
- }
- void cellularRadio_ModuleInitialized(CellularRadio sender)
- {
- Debug.Print("MODULE INITIALIZED");
- button.TurnLEDOn();
- }
- void cellularRadio_NoCarrierEvent(CellularRadio sender)
- {
- Debug.Print("NO CARRIER EVENT");
- }
- void cellularRadio_ConnectedLineEvent(CellularRadio sender, string number)
- {
- Debug.Print("CONNECTED: " + number);
- }
- void cellularRadio_SMSListReady(CellularRadio sender, System.Collections.ArrayList smsList)
- {
- if (smsList != null)
- {
- Debug.Print("SMS LIST");
- foreach (GTM.Seeed.CellularRadio.Sms message in smsList)
- {
- Debug.Print("FROM: " + message.TelephoneNumber);
- Debug.Print("MSG: " + message.TextMessage);
- Debug.Print("WHEN: " + message.Timestamp);
- Debug.Print("STATUS: " + message.Status + "\n");
- Debug.Print("POS:" + message.Index);
- }
- }
- }
- void cellularRadio_OperatorReady(CellularRadio sender, string operatorName)
- {
- if (operatorName != null)
- Debug.Print("OPERATOR: " + operatorName);
- else
- Debug.Print("NO OPERATOR WAS FOUND");
- }
- void cellularRadio_SignalStrengthReady(CellularRadio sender, CellularRadio.SignalStrengthType signalStrength)
- {
- Debug.Print("SIGNAL STRENGTH: " + signalStrength);
- }
- void cellularRadio_ClockReady(CellularRadio sender, DateTime clock)
- {
- Debug.Print("CLOCK: " + clock.ToString("r"));
- }
- void cellularRadio_ContactReady(CellularRadio sender, CellularRadio.Contact contact)
- {
- Debug.Print("NAME: " + contact.name);
- Debug.Print("TEL: " + contact.telephoneNumber);
- }
- void cellularRadio_IncomingCall(CellularRadio sender, string caller)
- {
- Debug.Print("NEW CALL: " + caller);
- }
- void cellularRadio_NetworkRegistrationEvent(CellularRadio sender, CellularRadio.NetworkRegistrationState networkState)
- {
- Debug.Print("NETWORK EVENT " + networkState);
- }
- void secondButton_ButtonPressed(Button sender, Button.ButtonState state)
- {
- Debug.Print("BUTTON BEGIN");
- /*
- * Power ON test
- */
- //cellularRadio.PowerOn = false;
- //cellularRadio.PowerOn = false;
- // cellularRadio.PowerOn = true;
- // cellularRadio.PowerOn = true;
- /*
- * PIN Event Test
- */
- cellularRadio.SendATCommand("AT+CPIN?");
- /*
- * Network Event Test
- */
- cellularRadio.SendATCommand("AT+CREG?");
- /*
- * SMS Test
- */
- //cellularRadio.SendSms("1591***2620", "HELLO");
- //cellularRadio.SendSms("447801***396", "HELLO");
- /*
- * Receive Voice Call Test
- */
- //if (!button.IsLedOn)
- //{
- // cellularRadio.PickUp();
- // button.TurnLEDOn();
- //}
- //else
- //{
- // cellularRadio.HangUp();
- // button.TurnLEDOff();
- //}
- /*
- * Make voice call Test
- */
- cellularRadio.Dial("*cell*");
- /*
- * Read SMS Test
- */
- //cellularRadio.RetrieveSms(1,true);
- /*
- * Delete SMS Test
- */
- //cellularRadio.DeleteSMS(1);
- /*
- * Redial Test
- */
- //cellularRadio.Dial("159919620");
- //Thread.Sleep(3000);
- //cellularRadio.HangUp();
- //Thread.Sleep(3000);
- //cellularRadio.Redial();
- /*
- * Phone Activity Test
- */
- //cellularRadio.RequestPhoneActivity();
- /*
- * Phonebook Test
- */
- //cellularRadio.SaveContact( 1,"447527202098", "Eduardo");
- //Thread.Sleep(1000);
- //cellularRadio.RequestContact(1);
- /*
- * Clock test
- */
- //cellularRadio.RequestClock();
- /*
- * IMEI test
- */
- //if (cellularRadio.RetrieveImei() != GTM.Seeed.CellularRadio.ReturnedState.OK)
- //{
- // Debug.Print("Retrieve IMEI failed");
- //}
- /*
- * Signal Strength Test
- */
- //cellularRadio.RequestSignalStrength();
- /*
- * Operator Test
- */
- //cellularRadio.RequestOperator();
- /*
- * Get unread test
- */
- //cellularRadio.RequestSMSList(GTM.Seeed.CellularRadio.SMSState.All);
- /*
- * Attach GPRS Test
- */
- //cellularRadio.AttachGPRS("orangeinternet", "", "");
- //cellularRadio.SendATCommand("AT+CIPSTATUS");
- /*
- * Delete all sms test
- */
- //cellularRadio.RetrieveSmsList(CellularRadio.SmsState.All);
- //Thread.Sleep(1000);
- //cellularRadio.DeleteAllSms();
- //Thread.Sleep(1000);
- //cellularRadio.RetrieveSmsList(CellularRadio.SmsState.All);
- Debug.Print("BUTTON END");
- }
- void cellularRadio_PINEvent(CellularRadio sender, CellularRadio.PINState pinState)
- {
- Debug.Print("PIN: " + pinState);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment