Esempio n. 1
0
        public static void Main()
        {
            bool switchToBootLoader = false;

            var mode = SystemUpdate.GetMode();

            if (mode == SystemUpdate.SystemUpdateMode.NonFormatted)
            {
                // This erases the application!
                Debug.Print("SystemUpdate.EnableBootLoader - formatting !!!!!!");
                SystemUpdate.EnableBootloader();
            }

            if (mode == SystemUpdate.SystemUpdateMode.Bootloader)
            {
                // Switch to application mode.
                Debug.Print("SystemUpdate.AccessApplication");
                SystemUpdate.AccessApplication();
            }

            if (mode == SystemUpdate.SystemUpdateMode.Application)
            {
                // Developer use only: Switch to BootLoader
                if (switchToBootLoader)
                {
                    SystemUpdate.AccessBootloader();
                }
            }

            // LED - Flashing for 5 seconds.
            LED.State = LED.LedState.FlashingData;
            Thread.Sleep(5000);

            // LED - switch on.
            LED.State = LED.LedState.On;

            // Start PDA comms thread.
            PDA.Start();

            // Start meter comms thread.
            EMR3.Start();

            while (true)
            {
                // Sleep a second
                Thread.Sleep(1000);
            }
        }
Esempio n. 2
0
        public static void ProcessMessage(string message)
        {
            lock (lockObj)
            {
                try
                {
                    string json = "{\"Command\": \"\", \"Result\": -99}";

                    Debug.Print("Received: " + message);

                    // Check EMR3 thread is running.
                    while (EMR3.IsRunning() == false)
                    {
                        Thread.Sleep(250);
                    }

                    // Check message is valid.
                    string[] parts = message.Split(new char[] { ',' });

                    // Check there is at least one part
                    if (parts.Length >= 1)
                    {
                        switch (parts[0])
                        {
                        case "BL":      // Bootloader.
                            SystemUpdate.AccessBootloader();
                            break;

                        case "Gv":      // Get Version.
                            json = "{\"Command\": \"Gv\", \"Result\": 0, \"Version\": " + Program.MajorVersion + "." + Program.MinorVersion + ", \"Model\": \"" + Program.Model + "\"}";
                            break;

                        case "Gf":      // Get features.
                            EMR3.GetFeatures(out json);
                            break;

                        case "Gt":      // Get temperature.
                            EMR3.GetTemperature(out json);
                            break;

                        case "Gs":      // Get status.
                            EMR3.GetStatus(out json);
                            break;

                        case "Gpl":      // Get preset litres.
                            EMR3.GetPreset(out json);
                            break;

                        case "Grl":      // Get realtime litres.
                            EMR3.GetRealtime(out json);
                            break;

                        case "Gtc":      // Get transaction count
                            EMR3.GetTranCount(out json);
                            break;

                        case "Gtr":      // Get transaction record
                            if (parts.Length == 2)
                            {
                                EMR3.GetTran(parts[1], out json);
                            }
                            break;

                        case "Spl":     // Set polling.
                            if (parts.Length == 2)
                            {
                                EMR3.SetPolling(parts[1], out json);
                            }
                            break;

                        case "Sp":      // Set preset.
                            if (parts.Length == 2)
                            {
                                EMR3.SetPreset(parts[1], out json);
                            }
                            break;

                        case "NOP":
                            json = "{\"Command\": \"NOP\", \"Result\": 0}";
                            break;

                        default:
                            json = "{\"Command\": \"" + parts[0] + "\", \"Result\": -99}";
                            break;
                        }
                    }

                    // Send reply to PDA.
                    SendMessage(json);

                    Debug.Print("PDA sent: " + json);
                }
                catch (Exception ex)
                {
                    Debug.Print("PDA.ProcessMessage: Exception " + ex.Message);
                }
            }
        }