public IMU(enums.IC_type type) { icType = type; for (int i = 0; i < amountIMUAtributes; i++) { data[i] = new IMUData(); } }
public Inclino(enums.IC_type type) { icType = type; for (int i = 0; i < amountInclinoAtributes; i++) { data[i] = new InclinoData(); } }
void dataReceiver() { while (AsyncReceive.MessageReadbuffer + 1 == AsyncReceive.dataMessageCounter) { Thread.Sleep(1); } AsyncReceive.dataMessage[] messages = AsyncReceive.messageBuffer[AsyncReceive.MessageReadbuffer]; AsyncReceive.MessageReadbuffer++; if (AsyncReceive.MessageReadbuffer == 1000) { AsyncReceive.MessageReadbuffer = 0; } for (int i = 0; i < messages.Length; i++) { if (messages[i].Sensor_Id == 0 || messages[i].Data_type == 0) { break; } if (messages[i].data == 0) { } else if ((enums.Data_type)messages[i].Data_type == enums.Data_type.TEMP) { if ((tempRead & (1 << messages[i].Sensor_Id)) == 0) { tempCounter++; enums.IC_type ic_type = determineSensorType(messages[i].Sensor_Id); influx17.addData(messages[i].Sensor_Id, (enums.Data_type)messages[i].Data_type, dataProcessor.calculateTempDegrees(messages[i].data, ic_type), ic_type); tempRead |= (1 << (messages[i].Sensor_Id)); } } else if ((enums.Data_type)messages[i].Data_type == enums.Data_type.BARO) { if (!Baroread) { Baroread = true; influx17.addData(messages[i].Sensor_Id, (enums.Data_type)messages[i].Data_type, messages[i].data, determineSensorType(messages[i].Sensor_Id)); } } else if ((messages[i].Sensor_Id > 0) & (messages[i].Sensor_Id < 20)) { dataProcessor.addData(messages[i].Sensor_Id, messages[i].Data_type, messages[i].data); //Console.WriteLine("Sensor data: Sensor_Id {0}, Data type {1}, data {2:X}", messages[i].Sensor_Id, messages[i].Data_type, messages[i].data); } else { Console.WriteLine("Data Invalid: Sensor_Id {0}, Data type {1}, data {2}", messages[i].Sensor_Id, messages[i].Data_type, messages[i].data); } } testcounterAmountMessages++; }
//Send a single datapackage to the database public int addData(int sensor_id, enums.Data_type data_type, double data, enums.IC_type ic_type) { LineProtocolPayload payload = new LineProtocolPayload(); var fields = new Dictionary <string, object>(); fields.Add("Raw", data); var tags = new Dictionary <string, string> { { "id", ((enums.Sensor_Id)sensor_id).ToString() }, { "ic_type", ic_type.ToString() }, { "data_type", data_type.ToString() }, }; payload.Add(new LineProtocolPoint("sensor_measurement", new ReadOnlyDictionary <string, object>(fields), tags)); client.WriteAsync(payload); return(0); }
public double calculateTempDegrees(int temp, enums.IC_type ic_type) { // BMI055 //The slope of the temperature sensor is 0.5K/LSB, it's center temperature is 23 degrees Celcius when temp = 0x00 //Temp value is 8 bits if (ic_type == enums.IC_type.BMI55) { sbyte BMI055Temp = (sbyte)temp; return(23 + 0.5 * BMI055Temp); } else if (ic_type == enums.IC_type.BMI085) { // Temperature Sensor slope // typ = 0.125 // Units K/LSB byte msb = (byte)(temp >> 8); byte lsb = (byte)(temp); int BMI085Temp_int11 = (msb * 8) + (lsb / 32); if (BMI085Temp_int11 > 1023) { BMI085Temp_int11 -= 2048; } double test = BMI085Temp_int11 * 0.125 + 23; return(BMI085Temp_int11 * 0.125 + 23); } else if (ic_type == enums.IC_type.LMS6DSO) { //16bit Resolution //Temperature sensitivity 256 LSB/°C //The output of the temperature sensor is 0 LSB (typ.) at 25 °C short LMS6DSOTemp_int16 = (short)temp; double temperature = 25 + (LMS6DSOTemp_int16 / 256); return(25 + (LMS6DSOTemp_int16 / 256)); } return(1); }
//Convert packagedata to min, max, AVG, AVG_Error data which are puten in a influxdb LineProtocolPoint format public static LineProtocolPoint convertToPoint(int sensor_id, enums.Data_type data_type, Data data, enums.IC_type ic_type, string measurement)//naam aanpassen naar iets algemeneererdere iets niet alleen IMU { var fields = new Dictionary <string, object>(); fields.Add("Min_value", data.determineMin()); fields.Add("Max_value", data.determineMax()); fields.Add("AVG_value", data.calcAverage()); fields.Add("ERROR_AVG_value", data.calcAverageError()); if (fields.Count == 0) { return(null); } var tags = new Dictionary <string, string> { { "id", ((enums.Sensor_Id)sensor_id).ToString() }, { "ic_type", ic_type.ToString() }, { "data_type", data_type.ToString() }, }; //Console.WriteLine("Sensor_id {0}, data_type {1}, Min Value {2}, Max value {3}, AVG_value {4}, ERROR_AVG_Value {5}", sensor_id, data_type,data.determineMin(),data.determineMax(),data.calcAverage(),data.calcAverageError()); return(new LineProtocolPoint(measurement, new ReadOnlyDictionary <string, object>(fields), tags)); }