コード例 #1
0
ファイル: Application.cs プロジェクト: Cycli/Cycli
        public static void Main(string[] args)
        {
            _Lease = new Lease();
              _outputDatum = new InterfaceDatum();
              _datumLock = new ReaderWriterLockSlim();
              uint ticks = 0;
              uint pedalRotations = 0;
              _userName = args[1];
              _password = args[2];

              if (args[0] == @"Test")
              {
            _pollServer = new Timer(SendDataToServer, null, 0, POLL_INTERVAL);

            Random rnd = new Random();
            ushort pwrCount = 0;
            while (1 == 1)
            {
              int delay = 500 + rnd.Next(40);
              Thread.Sleep(delay);
              ticks += (uint)delay;

              SensorPayload p = new SensorPayload();
              p.Type = "hrm";
              p.Data.Add("bpm", (ushort)(70 + rnd.Next(20)));
              p.Data.Add("ticks", (ushort)(ticks % 65536));
              SensorMessageReceived(null, p);

              pedalRotations += 1;
              p = new SensorPayload();
              p.Type = "spcd";
              p.Data.Add("wheelTicks", (ushort)((uint)(0.6 * ticks) % 65536));
              p.Data.Add("wheelRotations", (ushort)(pedalRotations % 65536));
              p.Data.Add("pedalTicks", (ushort)(ticks % 65536));
              p.Data.Add("pedalRotations", (ushort)(pedalRotations % 65536));
               SensorMessageReceived(null, p);
               p = new SensorPayload();
               pwrCount++;
               p.Type = "power";
               p.Data.Add("power", (ushort)(170+rnd.Next(20)));
               p.Data.Add("powerCount",1);
               SensorMessageReceived(null, p);

            }
              }
              else
              {
            Device UsbStick = new Device();
            UsbStick.Initialise();
            Sensor hrm = new HRMSensor(UsbStick);
            Sensor speedCadence = new SpeedCadenceSensor(UsbStick);
            hrm.SensorMessage += new SensorMessageHandler(SensorMessageReceived);
            speedCadence.SensorMessage += new SensorMessageHandler(SensorMessageReceived);

            _pollServer = new Timer(SendDataToServer, null, 2000, POLL_INTERVAL);

            UsbStick.Start();
              }
              //
        }
コード例 #2
0
ファイル: Application.cs プロジェクト: Cycli/Cycli
 private static void SendData()
 {
     using (var httpClient = new HttpClient()
       {
     BaseAddress = new Uri(serverAddress)
       })
       {
     DateTime startTime = DateTime.UtcNow;
     var response = httpClient.PutAsJsonAsync<InterfaceDatum>(appPath + "api/messages/putdatum/" + _outputDatum.userId, _outputDatum).Result;
     Console.WriteLine(string.Format("{0}",DateTime.UtcNow.Subtract(startTime)));
     if (response.StatusCode != HttpStatusCode.NoContent)
     {
       UserCredentials u = new UserCredentials();
       u.username = _userName;
       u.password = _password;
       Console.WriteLine("Authorising " + u.username);
       response = httpClient.PostAsJsonAsync<UserCredentials>(appPath + "api/credential/getlease/", u).Result;
       if (response.StatusCode == HttpStatusCode.OK)
       {
     Console.WriteLine("Authorised " + u.username);
     _Lease = response.Content.ReadAsAsync<Lease>().Result;
       }
     }
     else
     {
     }
       }
 }