public void SetMode(DeviceOperationModes mode, double load, double gradient) { lock (pvars) { this.mode = mode; this.load = load; this.gradient = gradient; } }
/* ---------------------------------------------------------------------- * LOW LEVEL DEVICE IO ROUTINES - PORT TO QIODEVICE REQUIRED BEFORE COMMIT * * * HIGH LEVEL IO * int sendCommand() - writes a command to the device * int readMessage() - reads an inbound message * * LOW LEVEL IO * openPort() - opens serial device and configures it * closePort() - closes serial device and releases resources * rawRead() - non-blocking read of inbound data * rawWrite() - non-blocking write of outbound data * discover() - check if a ct is attached to the port specified * ---------------------------------------------------------------------- */ public bool SendCommand(DeviceOperationModes mode) { switch (mode) { case DeviceOperationModes.Ergo: return(RawWrite(ERGO_Command, 56)); case DeviceOperationModes.SpinScan: return(RawWrite(SS_Command, 56)); default: return(false); } }
public Computrainer(string device) { devicePower = deviceHeartRate = deviceCadence = deviceSpeed = deviceRRC = 0; for (int i = 0; i < 24; i++) { spinData[i] = 0; } mode = DefaultMode; load = DefaultLoad; gradient = DefaultGradient; deviceCalibrated = false; deviceHRConnected = false; deviceCadenceConnected = false; Device = device; deviceStatus = 0; Buffer.BlockCopy(ERGO_Command, 0, ergo_command, 0, 56); Buffer.BlockCopy(SS_Command, 0, ss_command, 0, 56); }
public void PrepareCommand(DeviceOperationModes mode, double value) { byte crc, load; int gradient; switch (mode) { case DeviceOperationModes.Ergo: load = Convert.ToByte(value); crc = CalcCRC(load); // BYTE 0 - 49 is b0, 53 is b4, 54 is b5, 55 is b6 ERGO_Command[49] = Convert.ToByte(crc >> 1); // set byte 0 // BYTE 4 - command and highbyte ERGO_Command[53] = 0x40; // set command ERGO_Command[53] |= Convert.ToByte((load & (2048 + 1024 + 512)) >> 9); // BYTE 5 - low 7 ERGO_Command[54] = 0; ERGO_Command[54] |= Convert.ToByte((load & (128 + 64 + 32 + 16 + 8 + 4 + 2)) >> 1); // BYTE 6 - sync + z set ERGO_Command[55] = 128 + 64; // low bit of supplement in bit 6 (32) ERGO_Command[55] |= Convert.ToByte((crc & 1) == 0 ? 0 : 32); // ? 32 : 0; // Bit 2 (0x02) is low bit of high byte in load (bit 9 0x256) ERGO_Command[55] |= Convert.ToByte((load & 256) == 0 ? 0 : 2); // ? 2 : 0; // Bit 1 (0x01) is low bit of low byte in load (but 1 0x01) ERGO_Command[55] |= Convert.ToByte(load & 1); break; case DeviceOperationModes.SpinScan: break; default: break; } }