diff --git a/endpoint/endpoint_diagnose.adef b/endpoint/endpoint_diagnose.adef new file mode 100644 index 00000000..6241c5e2 --- /dev/null +++ b/endpoint/endpoint_diagnose.adef @@ -0,0 +1,20 @@ +executables: +{ + endpoint_diagnose = ( endpoint_diagnoseComp ) +} + +processes: +{ + run: + { + (endpoint_diagnose) + } +} + +bindings: +{ + endpoint_diagnose.endpoint_diagnoseComp.le_gnss -> positioningService.le_gnss + endpoint_diagnose.endpoint_diagnoseComp.le_mrc -> modemService.le_mrc +} + +start: manual diff --git a/endpoint/endpoint_diagnoseComp/Component.cdef b/endpoint/endpoint_diagnoseComp/Component.cdef new file mode 100644 index 00000000..0ce04b99 --- /dev/null +++ b/endpoint/endpoint_diagnoseComp/Component.cdef @@ -0,0 +1,18 @@ +requires: +{ + api: + { + modemServices/le_mrc.api + positioning/le_gnss.api + } +} + +sources: +{ + endpoint_diagnose.c +} + +cflags: +{ + -g -O0 +} diff --git a/endpoint/endpoint_diagnoseComp/endpoint_diagnose.c b/endpoint/endpoint_diagnoseComp/endpoint_diagnose.c new file mode 100644 index 00000000..2b243d02 --- /dev/null +++ b/endpoint/endpoint_diagnoseComp/endpoint_diagnose.c @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2019-2020 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + +#include "endpoint_diagnose.h" + +#include "legato.h" +#include "le_gnss_interface.h" +#include "le_mrc_interface.h" + +COMPONENT_INIT { + + char time_str[30]; + size_t copied_bytes = 0; + int32_t latitude = 0, longitude = 0, accuracy = 0; + uint32_t quality = 0; + le_gnss_SampleRef_t position_sample; + le_gnss_State_t gnss_state; + le_result_t result; + + // GPS state checking and activation + gnss_state = le_gnss_GetState(); + if (gnss_state != LE_GNSS_STATE_ACTIVE) { + le_gnss_Start(); + le_gnss_Enable(); + } + + while(1) { + // Signal strength + result = le_mrc_GetSignalQual(&quality); + if (result == LE_OK) { + LE_INFO("Signal strength: %d\n", quality); + } else { + LE_ERROR("Fail to get signal strength\n"); + } + + // GPS + position_sample = le_gnss_GetLastSampleRef(); + result = le_gnss_GetLocation(position_sample, &latitude, &longitude, &accuracy); + if (result == LE_OK) { + LE_INFO("Latitude: %lf, Longitude: %lf, Horizontal accuracy: %d\n", (double)latitude / 1000000, (double)longitude / 1000000, accuracy); + } else if (result == LE_FAULT) { + LE_ERROR("Fail to get location data\n"); + } else if (result == LE_OUT_OF_RANGE) { + LE_ERROR("At least one retrieved value is invalid (set to INT32_MAX)\n"); + LE_INFO("Latitude: %lf, Longitude: %lf, Horizontal accuracy: %d\n", (double)latitude / 1000000, (double)longitude / 1000000, accuracy); + } + + // Time + result = le_clk_GetLocalDateTimeString(LE_CLK_STRING_FORMAT_DATE_TIME, time_str, sizeof(time_str), &copied_bytes); + if (result == LE_OK) { + LE_INFO("Time: %s\n", time_str); + } else if (result == LE_OVERFLOW) { + LE_ERROR("Overflow of time string\n"); + } + + sleep(1); + } + +} diff --git a/endpoint/endpoint_diagnoseComp/endpoint_diagnose.h b/endpoint/endpoint_diagnoseComp/endpoint_diagnose.h new file mode 100644 index 00000000..fad5587b --- /dev/null +++ b/endpoint/endpoint_diagnoseComp/endpoint_diagnose.h @@ -0,0 +1,12 @@ +/* + * Copyright (C) 2019-2020 BiiLabs Co., Ltd. and Contributors + * All Rights Reserved. + * This is free software; you can redistribute it and/or modify it under the + * terms of the MIT license. A copy of the license can be found in the file + * "LICENSE" at the root of this distribution. + */ + +#ifndef ENDPOINT_DIAGNOSE_H +#define ENDPOINT_DIAGNOSE_H + +#endif // ENDPOINT_DIAGNOSE_H