From 1b3a0906777e587b24575f0fb53ff846c6287054 Mon Sep 17 00:00:00 2001 From: mbutaye Date: Wed, 7 Feb 2018 14:18:51 +0100 Subject: [PATCH] Ajout des fichiers mbed --- Mbed_compiler/Capteur_pollution/CurrentTimeService.h | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Mbed_compiler/Capteur_pollution/EnvironmentalSensingService.h | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Mbed_compiler/Capteur_pollution/LocationAndNavigationService.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Mbed_compiler/Capteur_pollution/Nucleo_BLE_API.zip | Bin 0 -> 53652 bytes Mbed_compiler/Capteur_pollution/Nucleo_BLE_BlueNRG.zip | Bin 0 -> 66953 bytes Mbed_compiler/Capteur_pollution/PollutionService.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Mbed_compiler/Capteur_pollution/README.md | 34 ++++++++++++++++++++++++++++++++++ Mbed_compiler/Capteur_pollution/main.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Mbed_compiler/OLD_Read_GPS/main.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Mbed_compiler/Read_GPS_UART/GPSDevice.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Mbed_compiler/Read_GPS_UART/main.cpp | 39 +++++++++++++++++++++++++++++++++++++++ Mbed_compiler/Read_Humidity_I2C/HumidityDevice.h | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Mbed_compiler/Read_Humidity_I2C/main.cpp | 35 +++++++++++++++++++++++++++++++++++ Mbed_compiler/Read_Pollution_Sensor/PollutionDevice.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Mbed_compiler/Read_Pollution_Sensor/main.cpp | 25 +++++++++++++++++++++++++ Mbed_compiler/Read_Pressure_I2C/LPS22HB.zip | Bin 0 -> 3816 bytes Mbed_compiler/Read_Pressure_I2C/main.cpp | 15 +++++++++++++++ Mbed_compiler/Read_RTC_I2C/RTCDevice.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ Mbed_compiler/Read_RTC_I2C/main.cpp | 29 +++++++++++++++++++++++++++++ 19 files changed, 993 insertions(+), 0 deletions(-) create mode 100644 Mbed_compiler/Capteur_pollution/CurrentTimeService.h create mode 100644 Mbed_compiler/Capteur_pollution/EnvironmentalSensingService.h create mode 100644 Mbed_compiler/Capteur_pollution/LocationAndNavigationService.h create mode 100644 Mbed_compiler/Capteur_pollution/Nucleo_BLE_API.zip create mode 100644 Mbed_compiler/Capteur_pollution/Nucleo_BLE_BlueNRG.zip create mode 100644 Mbed_compiler/Capteur_pollution/PollutionService.h create mode 100644 Mbed_compiler/Capteur_pollution/README.md create mode 100644 Mbed_compiler/Capteur_pollution/main.cpp create mode 100644 Mbed_compiler/OLD_Read_GPS/main.cpp create mode 100644 Mbed_compiler/Read_GPS_UART/GPSDevice.h create mode 100644 Mbed_compiler/Read_GPS_UART/main.cpp create mode 100644 Mbed_compiler/Read_Humidity_I2C/HumidityDevice.h create mode 100644 Mbed_compiler/Read_Humidity_I2C/main.cpp create mode 100644 Mbed_compiler/Read_Pollution_Sensor/PollutionDevice.h create mode 100644 Mbed_compiler/Read_Pollution_Sensor/main.cpp create mode 100644 Mbed_compiler/Read_Pressure_I2C/LPS22HB.zip create mode 100644 Mbed_compiler/Read_Pressure_I2C/main.cpp create mode 100644 Mbed_compiler/Read_RTC_I2C/RTCDevice.h create mode 100644 Mbed_compiler/Read_RTC_I2C/main.cpp diff --git a/Mbed_compiler/Capteur_pollution/CurrentTimeService.h b/Mbed_compiler/Capteur_pollution/CurrentTimeService.h new file mode 100644 index 0000000..a2f9f86 --- /dev/null +++ b/Mbed_compiler/Capteur_pollution/CurrentTimeService.h @@ -0,0 +1,89 @@ +#ifndef __BLE_CURRENT_TIME_SERVICE_H__ +#define __BLE_CURRENT_TIME_SERVICE_H__ + +#include "BLEDevice.h" + +/** +* @class CurrentTimeService +* @brief BLE Time Service. This service provides the current time and date. +* Service: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.current_time.xml +* Date Time: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.date_time.xml +* Day of Week: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.day_of_week.xml +*/ +class CurrentTimeService { +public: + const static uint16_t UUID_CURRENT_TIME_SERVICE = 0x1805; + const static uint16_t UUID_DATE_TIME_CHAR = 0x2A08; + const static uint16_t UUID_DAY_OF_WEEK_CHAR = 0x2A09; + + typedef uint8_t DayOfWeekType_t; + typedef struct DateTimeType_t{ + uint16_t year; + uint8_t month; + uint8_t day; + uint8_t hours; + uint8_t minutes; + uint8_t seconds; + } DateTimeType_t; + + /** + * @brief CurrentTimeService constructor. + * @param ble Reference to BLE device. + */ + CurrentTimeService(BLEDevice& _ble) : + ble(_ble), + dateTimeCharacteristic(UUID_DATE_TIME_CHAR, &dateTime, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), + dayOfWeekCharacteristic(UUID_DAY_OF_WEEK_CHAR, &dayOfWeek, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) + { + static bool serviceAdded = false; /* We should only ever need to add the information service once. */ + if (serviceAdded) { + return; + } + + GattCharacteristic *charTable[] = { &dateTimeCharacteristic, + &dayOfWeekCharacteristic }; + + GattService currentTimeService(UUID_CURRENT_TIME_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); + + ble.addService(currentTimeService); + serviceAdded = true; + } + + /** + * @brief Update date time characteristic. + * @param newDateTimeVal New date time measurement. + */ + void updateDateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hours, uint8_t minutes, uint8_t seconds) + { + dateTime = (DateTimeType_t) { + (uint16_t)year, + (uint8_t)month, + (uint8_t)day, + (uint8_t)hours, + (uint8_t)minutes, + (uint8_t)seconds + }; + ble.updateCharacteristicValue(dateTimeCharacteristic.getValueHandle(), (uint8_t *) &dateTime, sizeof(DateTimeType_t)); + } + + /** + * @brief Update day of week characteristic. + * @param newDayOfWeekVal New day of week measurement. + */ + void updateDayOfWeek(DayOfWeekType_t day) + { + dayOfWeek = (DayOfWeekType_t)day; + ble.updateCharacteristicValue(dayOfWeekCharacteristic.getValueHandle(), (uint8_t *) &dayOfWeek, sizeof(DayOfWeekType_t)); + } + +private: + BLEDevice& ble; + + DateTimeType_t dateTime; + DayOfWeekType_t dayOfWeek; + + ReadOnlyGattCharacteristic dateTimeCharacteristic; + ReadOnlyGattCharacteristic dayOfWeekCharacteristic; +}; + +#endif /* #ifndef __BLE_CURRENT_TIME_SERVICE_H__*/ \ No newline at end of file diff --git a/Mbed_compiler/Capteur_pollution/EnvironmentalSensingService.h b/Mbed_compiler/Capteur_pollution/EnvironmentalSensingService.h new file mode 100644 index 0000000..3cf221d --- /dev/null +++ b/Mbed_compiler/Capteur_pollution/EnvironmentalSensingService.h @@ -0,0 +1,94 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __BLE_ENVIRONMENTAL_SENSING_SERVICE_H__ +#define __BLE_ENVIRONMENTAL_SENSING_SERVICE_H__ + +#include "BLEDevice.h" + +/** +* @class EnvironmentalSensingService +* @brief BLE Environmental Service. This service provides temperature, humidity and pressure measurement. +* Service: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.environmental_sensing.xml +* Temperature: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.temperature.xml +* Humidity: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.humidity.xml +* Pressure: https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.pressure.xml +*/ +class EnvironmentalSensingService { +public: + const static uint16_t UUID_ENVIRONMENTAL_SENSING_SERVICE = 0x181A; + const static uint16_t UUID_HUMIDITY_CHAR = 0x2A6F; + const static uint16_t UUID_PRESSURE_CHAR = 0x2A6D; + + typedef uint16_t HumidityType_t; + typedef uint32_t PressureType_t; + + /** + * @brief EnvironmentalService constructor. + * @param ble Reference to BLE device. + */ + EnvironmentalSensingService(BLEDevice& _ble) : + ble(_ble), + humidityCharacteristic(UUID_HUMIDITY_CHAR, &humidity, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), + pressureCharacteristic(UUID_PRESSURE_CHAR, &pressure, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) + { + static bool serviceAdded = false; /* We should only ever need to add the information service once. */ + if (serviceAdded) { + return; + } + + GattCharacteristic *charTable[] = { &pressureCharacteristic, + &humidityCharacteristic + }; + + GattService environmentalSensingService(UUID_ENVIRONMENTAL_SENSING_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); + + ble.addService(environmentalSensingService); + serviceAdded = true; + } + + /** + * @brief Update humidity characteristic. + * @param newHumidityVal New humidity measurement. + */ + void updateHumidity(double newHumidityVal) + { + humidity = (HumidityType_t) (newHumidityVal * 100); + ble.updateCharacteristicValue(humidityCharacteristic.getValueHandle(), (uint8_t *) &humidity, sizeof(HumidityType_t)); + } + + /** + * @brief Update pressure characteristic. + * @param newPressureVal New pressure measurement. + */ + void updatePressure(double newPressureVal) + { + pressure = (PressureType_t) (newPressureVal * 10); + ble.updateCharacteristicValue(pressureCharacteristic.getValueHandle(), (uint8_t *) &pressure, sizeof(PressureType_t)); + } + + +private: + BLEDevice& ble; + + HumidityType_t humidity; + PressureType_t pressure; + + ReadOnlyGattCharacteristic humidityCharacteristic; + ReadOnlyGattCharacteristic pressureCharacteristic; +}; + +#endif /* #ifndef __BLE_ENVIRONMENTAL_SENSING_SERVICE_H__*/ \ No newline at end of file diff --git a/Mbed_compiler/Capteur_pollution/LocationAndNavigationService.h b/Mbed_compiler/Capteur_pollution/LocationAndNavigationService.h new file mode 100644 index 0000000..1886e31 --- /dev/null +++ b/Mbed_compiler/Capteur_pollution/LocationAndNavigationService.h @@ -0,0 +1,76 @@ +#ifndef __BLE_LOCATION_AND_NAVIGATION_SERVICE_H__ +#define __BLE_LOCATION_AND_NAVIGATION_SERVICE_H__ + +#include "BLEDevice.h" + +/** +* @class LocationAndNavigationService +* @brief BLE Location and Navigation Service. This service provides location. +* Service: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.location_and_navigation.xml +* LN Feature: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.ln_feature.xml +* Location and Speed: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.location_and_speed.xml +*/ +class LocationAndNavigationService { +public: + const static uint16_t UUID_LOCATION_AND_NAVIGATION_SERVICE = 0x1819; + const static uint16_t UUID_LN_FEATURE_CHAR = 0x2A6A; + const static uint16_t UUID_LOCATION_AND_SPEED_CHAR = 0x2A67; + + typedef struct LocationAndSpeedType_t{ + uint16_t flags; + int32_t latitude; + int32_t longitude; + int32_t altitude; + } LocationAndSpeedType_t; + typedef uint32_t LNFeatureType_t; + + /** + * @brief LocationAndNavigationService constructor. + * @param ble Reference to BLE device. + */ + LocationAndNavigationService(BLEDevice& _ble, LNFeatureType_t features) : + ble(_ble), + lnFeature(features), + lnFeatureCharacteristic(UUID_LN_FEATURE_CHAR, &lnFeature), + locationAndSpeedCharacteristic(UUID_LOCATION_AND_SPEED_CHAR, &locationAndSpeed, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) + { + static bool serviceAdded = false; /* We should only ever need to add the information service once. */ + if (serviceAdded) { + return; + } + + GattCharacteristic *charTable[] = { &lnFeatureCharacteristic, + &locationAndSpeedCharacteristic }; + + GattService locationAndNavigationService(UUID_LOCATION_AND_NAVIGATION_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); + + ble.addService(locationAndNavigationService); + serviceAdded = true; + } + + /** + * @brief Update location and speed characteristic. + * @param newLocationAndSpeedVal New location and speed measurement. + */ + void updateLocationAndSpeed(uint16_t flags, double latitude, double longitude, double altitude) + { + locationAndSpeed = (LocationAndSpeedType_t) { + (uint16_t)flags, + (int32_t)(latitude * 100000), + (int32_t)(longitude * 100000), + (int32_t)(altitude * 100) + }; + ble.updateCharacteristicValue(locationAndSpeedCharacteristic.getValueHandle(), (uint8_t *) &locationAndSpeed, sizeof(LocationAndSpeedType_t)); + } + +private: + BLEDevice& ble; + + LNFeatureType_t lnFeature; + LocationAndSpeedType_t locationAndSpeed; + + ReadOnlyGattCharacteristic lnFeatureCharacteristic; + ReadOnlyGattCharacteristic locationAndSpeedCharacteristic; +}; + +#endif /* #ifndef __BLE_LOCATION_AND_NAVIGATION_SERVICE_H__*/ \ No newline at end of file diff --git a/Mbed_compiler/Capteur_pollution/Nucleo_BLE_API.zip b/Mbed_compiler/Capteur_pollution/Nucleo_BLE_API.zip new file mode 100644 index 0000000..56fa207 Binary files /dev/null and b/Mbed_compiler/Capteur_pollution/Nucleo_BLE_API.zip differ diff --git a/Mbed_compiler/Capteur_pollution/Nucleo_BLE_BlueNRG.zip b/Mbed_compiler/Capteur_pollution/Nucleo_BLE_BlueNRG.zip new file mode 100644 index 0000000..cbc5474 Binary files /dev/null and b/Mbed_compiler/Capteur_pollution/Nucleo_BLE_BlueNRG.zip differ diff --git a/Mbed_compiler/Capteur_pollution/PollutionService.h b/Mbed_compiler/Capteur_pollution/PollutionService.h new file mode 100644 index 0000000..4414d04 --- /dev/null +++ b/Mbed_compiler/Capteur_pollution/PollutionService.h @@ -0,0 +1,67 @@ +#ifndef __BLE_POLLUTION_SERVICE_H__ +#define __BLE_POLLUTION_SERVICE_H__ + +#include "BLEDevice.h" + +/* Pollution Service */ +class PollutionService { +public: + const static uint16_t UUID_POLLUTION_SERVICE = 0xA000; + const static uint16_t UUID_POLLUTION_LEVEL_CHAR = 0xA001; + const static uint16_t UUID_TEMPERATURE_CHAR = 0x2A6E; + + typedef int16_t TemperatureType_t; + typedef uint8_t PollutionLevelType_t; + + PollutionService(BLEDevice &_ble, PollutionLevelType_t level) : + ble(_ble), + pollutionLevel(level), + pollutionLevelCharacteristic(UUID_POLLUTION_LEVEL_CHAR, &pollutionLevel, sizeof(pollutionLevel), sizeof(pollutionLevel), + GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY), + temperatureCharacteristic(UUID_TEMPERATURE_CHAR, &temperature, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { + + static bool serviceAdded = false; /* We should only ever need to add the service once. */ + if (serviceAdded) { + return; + } + + GattCharacteristic *charTable[] = {&pollutionLevelCharacteristic, + &temperatureCharacteristic }; + GattService pollutionService(UUID_POLLUTION_SERVICE, charTable, sizeof(charTable) / sizeof(GattCharacteristic *)); + + ble.addService(pollutionService); + serviceAdded = true; + } + + /** + * Update the pollution level with a new value. Valid values range from + * 0..100. Anything outside this range will be ignored. + * @param newLevel New level. + */ + void updatePollutionLevel(uint8_t newLevel) { + pollutionLevel = newLevel; + ble.updateCharacteristicValue(pollutionLevelCharacteristic.getValueAttribute().getHandle(), &pollutionLevel, 1); + } + + /** + * @brief Update temperature characteristic. + * @param newTemperatureVal New temperature measurement. + */ + void updateTemperature(double newTemperatureVal) + { + temperature = (TemperatureType_t) (newTemperatureVal * 100); + ble.updateCharacteristicValue(temperatureCharacteristic.getValueHandle(), (uint8_t *) &temperature, sizeof(TemperatureType_t)); + } + + +private: + BLEDevice &ble; + + TemperatureType_t temperature; + PollutionLevelType_t pollutionLevel; + + GattCharacteristic pollutionLevelCharacteristic; + ReadOnlyGattCharacteristic temperatureCharacteristic; +}; + +#endif /* #ifndef __BLE_POLLUTION_SERVICE_H__*/ diff --git a/Mbed_compiler/Capteur_pollution/README.md b/Mbed_compiler/Capteur_pollution/README.md new file mode 100644 index 0000000..f55bc1a --- /dev/null +++ b/Mbed_compiler/Capteur_pollution/README.md @@ -0,0 +1,34 @@ +# Programme pour la connexion Bluetooth de la carte du capteur de pollution + +## Informations pour la connexion avec l'application Android : +* Particules de pollution et température : +** Pollution Service : *0xA000* +** Pollution Level Characteristic : *0xA001* +** Temperature Characteristic : *0x2A6E* +* Humidité et Pression atmosphérique : +** Environmental Service : *0x181A* **(Service officiel)** +** Humidity Characteristic : *0x2A6F* +** Pressure Characteristic : *0x2A6D* +* Position géographique : +** LocationAndNavigationService : *0x1819* **(Service officiel)** +** Location and Speed Characteristic : *0x2A67* +* Temps et heure : +** CurrentTimeService : *0x1805* **(Service officiel)** +** DateTime Characteristic : *0x2A08* +** Day of Week Characteristic : *0x2A09* +* Appearance : Pollution Particles Sensor : *0x6000* + +## Informations diverses sur le programme : +* Le nom de l'application ne peut pas contenir plus de 14 caractères, sinon il +devient par défaut ST_BTL_DEV. + +##Pour rajouter/modifier des services : +* **uuid16_list** contient la liste des services auxquels souscrire. +* Les services sont déclarés dans le fichier **GattService.h** du dossier **public**. +* Les variables des services sont déclarés dans le main (pollution, battery, ...). +* Les classes associées se trouvent dans le dossier **services**. +* Les informations concernant l'apparence de l'objet connecté sont déclarées dans le +fichier **GapAdvertisingData.h** du dossier **public**. +* Les caractéristiques sont déclarées dans le fichier **GattCharacteristic.h** +du dossier **public**. +* Les services ne peuvent contenir plus de 2 caractéristiques à la fois. \ No newline at end of file diff --git a/Mbed_compiler/Capteur_pollution/main.cpp b/Mbed_compiler/Capteur_pollution/main.cpp new file mode 100644 index 0000000..3c75cf6 --- /dev/null +++ b/Mbed_compiler/Capteur_pollution/main.cpp @@ -0,0 +1,108 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "mbed.h" +#include "BLEDevice.h" +#include "PollutionService.h" +#include "EnvironmentalSensingService.h" +#include "LocationAndNavigationService.h" +#include "CurrentTimeService.h" +#include "BatteryService.h" +#include "DeviceInformationService.h" +#include "Utils.h" + +BLEDevice ble; +DigitalOut led1(LED1); + +const static char DEVICE_NAME[] = "Pollution"; +static const uint16_t uuid16_list[] = {0xFFFF, + PollutionService::UUID_POLLUTION_SERVICE, + EnvironmentalSensingService::UUID_ENVIRONMENTAL_SENSING_SERVICE, + LocationAndNavigationService::UUID_LOCATION_AND_NAVIGATION_SERVICE, + CurrentTimeService::UUID_CURRENT_TIME_SERVICE, + GattService::UUID_BATTERY_SERVICE, + GattService::UUID_DEVICE_INFORMATION_SERVICE}; +static volatile bool triggerSensorPolling = false; + + +void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) +{ + DEBUG("Disconnected!\n\r"); + DEBUG("Restarting the advertising process\n\r"); + ble.startAdvertising(); // restart advertising +} + +void connectionCallback(Gap::Handle_t handle, const Gap::ConnectionParams_t *reason) +{ + DEBUG("Connected\r\n"); +} + +void periodicCallback(void) +{ + led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */ + triggerSensorPolling = true; +} + +int main(void) +{ + led1 = 1; + Ticker ticker; + ticker.attach(periodicCallback, 1); + + DEBUG("Initialising \n\r"); + ble.init(); + ble.onDisconnection(disconnectionCallback); + ble.onConnection(connectionCallback); + + /* Setup services. */ + PollutionService pollutionService(ble, 76); + EnvironmentalSensingService environmentalSensingService(ble); + LocationAndNavigationService locationAndNavigationService(ble, 0x0C0400); + CurrentTimeService currentTimeService(ble); + BatteryService batteryService(ble, 61); + DeviceInformationService deviceInfoService(ble, "ST", "Nucleo", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); + + /* Setup advertising. */ + /* BREDR_NOT_SUPPORTED means classic bluetooth not supported; + * LE_GENERAL_DISCOVERABLE means that this peripheral can be + * discovered by any BLE scanner--i.e. any phone. */ + ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); + ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); + ble.accumulateAdvertisingPayload(GapAdvertisingData::POLLUTION_PARTICLES_SENSOR); + ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); + ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); + ble.setAdvertisingInterval(1000); /* 1000ms; in multiples of 0.625ms. */ + ble.startAdvertising(); + + while (true) + { + if (triggerSensorPolling) + { + triggerSensorPolling = false; + pollutionService.updatePollutionLevel(73); + pollutionService.updateTemperature(25.76); + environmentalSensingService.updateHumidity(15.2); + environmentalSensingService.updatePressure(3.5); + locationAndNavigationService.updateLocationAndSpeed(0x0C00, 4836.5375, 00740.9373, 200.2); + currentTimeService.updateDateTime(2018, 02, 02, 16, 29, 45); + currentTimeService.updateDayOfWeek(5); + } + else + { + ble.waitForEvent(); + } + } +} diff --git a/Mbed_compiler/OLD_Read_GPS/main.cpp b/Mbed_compiler/OLD_Read_GPS/main.cpp new file mode 100644 index 0000000..3551c7e --- /dev/null +++ b/Mbed_compiler/OLD_Read_GPS/main.cpp @@ -0,0 +1,63 @@ +#include "mbed.h" + +#define LENGTH 112 +#define BAUD 9600 + +I2C i2c(D14, D15, BAUD); +DigitalOut led1(LED1); +Serial pc(SERIAL_TX, SERIAL_RX); + +unsigned char adress_DSGPM;//= 0xD0, 0xD1, 0xD2 ou 0xD3 en fonction des jumpers branchés sur le GPS +char data[LENGTH]; + +bool findGPSDevices(); + +int main() +{ + pc.printf("starting..."); + + if(findGPSDevices()){ + char BaseReg_Address = 0; + char cmd[1]={BaseReg_Address}; + + while(1) + { + led1 = 1; + wait(0.2); + i2c.write(adress_DSGPM, cmd, 1); + i2c.read(adress_DSGPM, data, LENGTH); + pc.printf("Time : %d%d:%d%d:%d%d\n", data[0], data[1], data[2], data[3], data[4], data[5]); + pc.printf("Date : %d%d/%d%d/%d%d%d%d\n", data[6], data[7], data[8], data[9], data[10], data[11], data[12], data[13]); + pc.printf("Latitude : %d%d degres\n", data[14], data[15]); + pc.printf("Longitude : %d%d%d degres\n", data[23], data[24], data[25]); + pc.printf("Altitude : %d%d%d%d%d metres\n\n", data[39], data[40], data[41], data[42], data[43]); + led1 = 0; + wait(0.5); + } + } +} + +/* + * Permet de trouver les GPS et leurs adresses. Assigne une adresse trouvée à + * la variable 'adress_DSGPM'. + */ +bool findGPSDevices() { + int count = 0; + bool res = false; + + pc.printf("Searching for I2C devices...\n"); + for (int address=0xD0; address<0xD7; address+=2) + { + if (!i2c.write(address, NULL, 0)) //0 est renvoyé = GPS trouvé + { + pc.printf(" - I2C device found at address 0x%02X\n", address); + adress_DSGPM = address; + res = true; + count++; + } + + } + pc.printf("%d devices found\n\n", count); + return res; +} + diff --git a/Mbed_compiler/Read_GPS_UART/GPSDevice.h b/Mbed_compiler/Read_GPS_UART/GPSDevice.h new file mode 100644 index 0000000..2c116f6 --- /dev/null +++ b/Mbed_compiler/Read_GPS_UART/GPSDevice.h @@ -0,0 +1,92 @@ +#ifndef __GPS_DEVICE_H__ +#define __GPS_DEVICE_H__ + +#include "mbed.h" +#define GPGGA "GPGGA" + +class GPSDevice { +public: + const static int length = 80; + const static int baud = 9600; + + GPSDevice(Serial *uart) : uart(uart) {} + + /* + * Permet de savoir si on lit le début de la trame associée au GPS. + */ + bool canBeRead() { + return uart->readable() && uart->getc() == '$'; + } + + /* + * Permet de déterminer le type de trame du GPS. + */ + void readType(char type[6]){ + uart->scanf("%5s", &type); + } + + /* + * Permet de lire la trame du GPS de type GGA. + */ + void readGPGGA() { + char msg[100]; + + while (uart->getc() != ','); //waits for first comma then copies info + uart->scanf("%s", &msg); + + char *tok = strtok(msg, ","); //begins isolating fields of information delimited by a comma + int comma = 0; + while(tok != NULL){ + comma++; + switch (comma) { + case 1: UTC = tok; break; //GMT time in seconds, saves pointer to string + case 2: lat = tok; break; //latitude + case 3: latl = tok; break; //lat letter, (N or S) + case 4: lon = tok; break; //longitude + case 5: lonl = tok; break; //lon letter (W or E) + case 6: valid = tok; break; //valid + } + + tok = strtok(NULL, ","); + } + } + + /* + * Permet de vérifier que la trame lue est valide. + */ + bool isReadValid() { + return atoi(valid) == 1 || atoi(valid) == 2 || atoi(valid) == 3; + } + + char* getUTC() { + return UTC; + } + + char* getLatitude() { + if(strcmp(latl, "N")){ + return lat; + } else { + char *newLat = ""; + strcpy(newLat, "-"); + strncat(lat, newLat, sizeof(lat)/sizeof(lat[0])); + return newLat; + } + } + + char* getLongitude() { + if(strcmp(lonl, "E")){ + return lon; + } else { + char *newLon = ""; + strcpy(newLon, "-"); + strncat(lon, newLon, sizeof(lon)/sizeof(lon[0])); + return newLon; + } + } + +private: + Serial *uart; + char *UTC, *lat, *latl, *lon, *lonl, *valid; +}; + +#endif /* #ifndef __GPS_DEVICE_H__*/ \ No newline at end of file diff --git a/Mbed_compiler/Read_GPS_UART/main.cpp b/Mbed_compiler/Read_GPS_UART/main.cpp new file mode 100644 index 0000000..4830d25 --- /dev/null +++ b/Mbed_compiler/Read_GPS_UART/main.cpp @@ -0,0 +1,39 @@ +#include "mbed.h" +#include "GPSDevice.h" + +#define LENGTH 80 +#define BAUD 9600 + +DigitalOut led1(LED1); +Serial pc(USBTX, USBRX, BAUD); +Serial uart(D8, D2, BAUD); + +void readGPGGA(); + +int main() +{ + pc.printf("starting..."); + GPSDevice gpsDevice(&uart); + + while(1) { + char type[6]; + if (gpsDevice.canBeRead()){ + gpsDevice.readType(type); + + if (strcmp(type, GPGGA) == 0) { + gpsDevice.readGPGGA(); + + if(gpsDevice.isReadValid()) { + pc.printf("Time : %s\n", gpsDevice.getUTC()); + pc.printf("Latitude : %s N\n", gpsDevice.getLatitude()); + pc.printf("Longitude : %s E\n", gpsDevice.getLongitude()); + } + } + led1 = !led1; + } + } +} + + + + diff --git a/Mbed_compiler/Read_Humidity_I2C/HumidityDevice.h b/Mbed_compiler/Read_Humidity_I2C/HumidityDevice.h new file mode 100644 index 0000000..516cb5e --- /dev/null +++ b/Mbed_compiler/Read_Humidity_I2C/HumidityDevice.h @@ -0,0 +1,98 @@ +#ifndef __HUMIDITY_DEVICE_H__ +#define __HUMIDITY_DEVICE_H__ + +#include "mbed.h" + +class HumidityDevice { +public: + const static char configReg_Address = 0x02; + const static char device_address = 0x80; + int length; + + HumidityDevice(Serial *serial, I2C *i2c, bool shouldReadTemperature) : serial(serial), i2c(i2c), + shouldReadTemperature(shouldReadTemperature) { + if(shouldReadTemperature){ + length = 4; + triggerMes_Address = 0x00; + } else { + length = 2; + triggerMes_Address = 0x01; + } + + powRes = pow((double)2, (double)16); + } + + /* + * Permet de lire le capteur d'humidité et d'obtenir ses valeurs. + */ + void read(char data[]) { + char cmd[1]={triggerMes_Address}; + i2c->write(address_found, cmd, 1); + wait(0.2); + i2c->read(address_found, data, length); + + if(shouldReadTemperature){ + temp = (float((data[0] << 8)| data[1]) / powRes) * 165 - 40; + hum = (float((data[2] << 8)| data[3]) / powRes) * 100; + } else { + hum = (float((data[0] << 8)| data[1]) / powRes) * 100; + } + } + + /* + * Permet de trouver le capteur d'humidité et son adresse. Assigne une adresse trouvée à + * la variable 'adress_found'. + */ + bool find() { + int count = 0; + bool res = false; + + serial->printf("Searching for I2C devices...\n"); + if (!i2c->write(device_address, NULL, 0)) //0 est renvoyé = capteur trouvé + { + serial->printf(" - I2C device found at address 0x%02X\n", device_address); + address_found = device_address; + res = true; + count++; + } + serial->printf("%d devices found\n\n", count); + return res; + } + + /* + * Permet de configurer le capteur d'humidité. + */ + void setup() { + serial->printf("setting up device...\n"); + char cmd[3] = {configReg_Address, 0x00, 0x00}; + if(shouldReadTemperature){ + cmd[1] = 0x10; + } + i2c->write(address_found, cmd, 3); + serial->printf("finished set up\n"); + } + + float getTemperature(){ + return temp; + } + + float getHumidity() { + return hum; + } + + bool hasReadTemperature() { + return shouldReadTemperature; + } + + +private: + unsigned char address_found; + char triggerMes_Address; + Serial *serial; + I2C *i2c; + bool shouldReadTemperature; + float hum, temp; + float powRes; +}; + +#endif /* #ifndef __HUMIDITY_DEVICE_H__*/ \ No newline at end of file diff --git a/Mbed_compiler/Read_Humidity_I2C/main.cpp b/Mbed_compiler/Read_Humidity_I2C/main.cpp new file mode 100644 index 0000000..591a7fa --- /dev/null +++ b/Mbed_compiler/Read_Humidity_I2C/main.cpp @@ -0,0 +1,35 @@ +#include "mbed.h" +#include "HumidityDevice.h" + +#define ADDRESS 0x80 + +I2C i2c(D14, D15); +DigitalOut led1(LED1); +Serial pc(SERIAL_TX, SERIAL_RX); + +int main() +{ + pc.printf("starting..."); + HumidityDevice humidityDevice(&pc, &i2c, true); + + if(humidityDevice.find()){ + humidityDevice.setup(); + + while(1) + { + led1 = 1; + + char *data; + humidityDevice.read(data); + + if(humidityDevice.hasReadTemperature()){ + pc.printf("Temperature : %f\n", humidityDevice.getTemperature()); + pc.printf("Humidite : %f\n", humidityDevice.getHumidity()); + } else { + pc.printf("Humidite : %f\n", humidityDevice.getHumidity()); + } + led1 = 0; + wait(0.5); + } + } +} diff --git a/Mbed_compiler/Read_Pollution_Sensor/PollutionDevice.h b/Mbed_compiler/Read_Pollution_Sensor/PollutionDevice.h new file mode 100644 index 0000000..eef5535 --- /dev/null +++ b/Mbed_compiler/Read_Pollution_Sensor/PollutionDevice.h @@ -0,0 +1,79 @@ +#ifndef __POLLUTION_DEVICE_H__ +#define __POLLUTION_DEVICE_H__ + +#include "mbed.h" + +class PollutionDevice { +public: + const static int length = 31; + const static int baud = 9600; + + PollutionDevice(Serial *uart) : uart(uart), PM01Value(0), PM2_5Value(0), PM10Value(0) {} + + /* + * Permet de savoir si on lit le début de la trame associée au GPS. + */ + bool canBeRead() { + return uart->readable() && uart->getc() == 0x42; + } + + /* + * Permet de lire la trame du capteur de pollution. + */ + void read() { + char buf[length]; + + for(int i = 0; i < length; i++){ + buf[i]=uart->getc(); + } // full packet now in buffer. + + if(buf[0] == 0x4d){ + if(checkValue(buf, length)){ + PM01Value=((buf[3]<<8) + buf[4]); //count PM1.0 value of the air detector module + PM2_5Value=((buf[5]<<8) + buf[6]);//count PM2.5 value of the air detector module + PM10Value=((buf[7]<<8) + buf[8]); //count PM10 value of the air detector module + } + } + } + + int getPM01() + { + return PM01Value; + } + + int getPM2_5() + { + return PM2_5Value; + } + + int getPM10() + { + return PM10Value; + } + +private: + Serial *uart; + int PM01Value; //define PM1.0 value of the air detector module + int PM2_5Value; //define PM2.5 value of the air detector module + int PM10Value; //define PM10 value of the air detector module + + bool checkValue(char *buffer, char length) + { + bool flag = false; + int sum = 0; + + for(int i = 0; i < (length - 2); i++){ + sum = sum + buffer[i]; + } + sum = sum + 0x42; //0x42 : Le premier caractère qui n'est pas dans le buffer + + if(sum == ((buffer[length - 2] << 8) + buffer[length - 1])) //check the serial data + { + sum = 0; + flag = true; + } + return flag; + } +}; + +#endif /* #ifndef __POLLUTION_DEVICE_H__*/ \ No newline at end of file diff --git a/Mbed_compiler/Read_Pollution_Sensor/main.cpp b/Mbed_compiler/Read_Pollution_Sensor/main.cpp new file mode 100644 index 0000000..21fa6c9 --- /dev/null +++ b/Mbed_compiler/Read_Pollution_Sensor/main.cpp @@ -0,0 +1,25 @@ +#include "mbed.h" +#include "PollutionDevice.h" + +DigitalOut led1(LED1); +Serial pc(USBTX, USBRX, PollutionDevice::baud); +Serial uart(D8, D2, PollutionDevice::baud); + +int main() +{ + pc.printf("starting...\n\n"); + PollutionDevice pollutionDevice(&uart); + + while(1) { + if(pollutionDevice.canBeRead()){ + pollutionDevice.read(); + pc.printf("PM1.0: %d ug/m3\nPM2.5: %d ug/m3\nPM10: %d ug/m3\n\n", pollutionDevice.getPM01(), pollutionDevice.getPM2_5(), pollutionDevice.getPM10()); + + led1 = !led1; + } + } +} + + + + diff --git a/Mbed_compiler/Read_Pressure_I2C/LPS22HB.zip b/Mbed_compiler/Read_Pressure_I2C/LPS22HB.zip new file mode 100644 index 0000000..cad3e3e Binary files /dev/null and b/Mbed_compiler/Read_Pressure_I2C/LPS22HB.zip differ diff --git a/Mbed_compiler/Read_Pressure_I2C/main.cpp b/Mbed_compiler/Read_Pressure_I2C/main.cpp new file mode 100644 index 0000000..b9e786b --- /dev/null +++ b/Mbed_compiler/Read_Pressure_I2C/main.cpp @@ -0,0 +1,15 @@ +#include "mbed.h" +#include "LPS22HB.h" + +// I2C Communication +I2C i2c(D14, D15); // SDA, SCL +LPS22HB baro(i2c, LPS22HB_G_CHIP_ADDR); +Serial pc(SERIAL_TX, SERIAL_RX); + +int main() { + while( true){ + baro.get(); + pc.printf("Pressure: 0x%6.1f, Temperature: 0x%+4.1f\r\n", baro.pressure(), baro.temperature()); + wait(1.0); + } +} \ No newline at end of file diff --git a/Mbed_compiler/Read_RTC_I2C/RTCDevice.h b/Mbed_compiler/Read_RTC_I2C/RTCDevice.h new file mode 100644 index 0000000..fa493b0 --- /dev/null +++ b/Mbed_compiler/Read_RTC_I2C/RTCDevice.h @@ -0,0 +1,50 @@ +#ifndef __RTC_DEVICE_H__ +#define __RTC_DEVICE_H__ + +#include "mbed.h" + +class RTCDevice { +public: + const static char firstReg_Address = 0x02; + const static char device_address = 0xA2; + const static int length = 7; + + RTCDevice(Serial *serial, I2C *i2c) : serial(serial), i2c(i2c) {} + + /* + * Permet de lire le RTC et d'obtenir la date et l'heure. + */ + void read(char data[]) { + char cmd[1]={firstReg_Address}; + i2c->write(address_found, cmd, 1); + wait(0.2); + i2c->read(address_found, data, length); + } + + /* + * Permet de trouver le RTC et son adresse. Assigne une adresse trouvée à + * la variable 'adress_found'. + */ + bool find() { + int count = 0; + bool res = false; + + serial->printf("Searching for I2C devices...\n"); + if (!i2c->write(device_address, NULL, 0)) //0 est renvoyé = capteur trouvé + { + serial->printf(" - I2C device found at address 0x%02X\n", device_address); + address_found = device_address; + res = true; + count++; + } + serial->printf("%d devices found\n\n", count); + return res; + } + +private: + unsigned char address_found; + Serial *serial; + I2C *i2c; +}; + +#endif /* #ifndef __RTC_DEVICE_H__*/ \ No newline at end of file diff --git a/Mbed_compiler/Read_RTC_I2C/main.cpp b/Mbed_compiler/Read_RTC_I2C/main.cpp new file mode 100644 index 0000000..2720dfa --- /dev/null +++ b/Mbed_compiler/Read_RTC_I2C/main.cpp @@ -0,0 +1,29 @@ +#include "mbed.h" +#include "RTCDevice.h" + +I2C i2c(D14, D15); +DigitalOut led1(LED1); +Serial pc(SERIAL_TX, SERIAL_RX); + +char data[RTCDevice::length]; + +int main() +{ + pc.printf("starting..."); + RTCDevice rtcDevice(&pc, &i2c); + + if(rtcDevice.find()){ + while(1) + { + led1 = 1; + + rtcDevice.read(data); + pc.printf("Time : %d%d:%d%d:%d%d\n", data[2] & 0x30 >> 4, data[2] & 0x0F, data[1] & 0x70 >> 4, data[1] & 0x0F, data[0] & 0x70 >> 4, data[0] & 0x0F); + pc.printf("Date : %d%d/%d%d/20%d%d\n", data[3] & 0x30 >> 4, data[3] & 0x0F, data[5] & 0x10 >> 4, data[5] & 0x0F, data[6] & 0xF0 >> 4, data[6] & 0x0F); + + led1 = 0; + wait(0.5); + } + } +} + -- libgit2 0.21.2