18#define __USE_MINGW_ANSI_STDIO 1
24#include <zephyr/drivers/i2c.h>
27#include "ncs_version.h"
28#include <bluetooth/services/nus.h>
29#include <zephyr/drivers/uart.h>
30#include <zephyr/pm/device.h>
166 "HDC2080 - temperature/Humidty Sensor(I2C 0x40)",
167 "W25Q64JV - 64MB Flash memory(SPI CS1)",
168 "BME688 - Gas/Pressure/temperature/Humidty Sensor(SPI CS2)",
217 "adc - display Battery voltage AIN0",
219 "batmon - <0 | 1> enable or disable Battery monitor",
220 "bme688 <n> - read n sample from BME688",
221 "bme688cs <0 | 1> - display/set BME688 CS",
222 "datetime save data/time from gateway"
223 "deviceid - display Device ID",
224 "deviceinfo - display device information",
225 "customer [X]- display/set customer",
227 "dutycycle [0 <minutes> | 1-7] - 0=minutes,1=2min,2=1min,3=10secs,4=5secs,5=1secs,6=.5secs,7=.2secs",
228 "flasherase - erase entire memory",
229 "flasherasesector - [sector] erase 256K Byte sector X (default 0) range ( 0 -> 31)",
230 "flashfillpage [page data length] - fill length pages with data starting at page",
231 "flashid - display serial flash ID",
232 "flashnss <0 | 1> - set SPI NSS",
233 "flashparameters - list the saved flash parameters",
234 "flashreadpage [page length] - read length pages starting at page",
235 "flashstatus - display serial flash status registers",
236 "flashwritepage page address data - write data to address in page",
241 "group [X]- display/set group",
242 "help [c] - display list of valid commands starting with c",
243 "humidity- display humidity",
244 "i2cread [add reg length] - read length bytes from I2C address starting at r",
245 "i2cwrite add reg data length - write byte to I2C address at reg",
246 "ignorebme688 [0 | 1] - display set ignore BME688 flag",
247 "location [X]- display/set location",
248 "manualtrigger [0 | 1] - display set manual trigger flag",
249 "nouart0 [0/1] - display/set No UART0",
250 "publishnow- publish a BLE payload now",
251 "rescan - rescan for connected devices",
252 "reset [x]- reset the board any paramter causes a WDT reset",
253 "resetCause - display reason for last reset ",
254 "saved [clear | n] [count]- display count saved flash JSON packets or clear all saved packets",
255 "sensorid [X]- display/set sensor ID",
256 "sensorname - display/set sensor name",
257 "sensors - display available sensors",
258 "silent [0 | 1]- display/set silent flag",
259 "temp- display sensor temperatures ",
260 "version - display version information",
420 if (((line[0] ==
'a') || (line[0] ==
'A')) && ((line[1] ==
't') || (line[1] ==
'T')))
422 if (strlen(line) != 0) {
423 myPrintk(
"Unknown cmd: %s\r\nType help for list of valid commands\r\n", line);
446 int len = strlen(line);
452 for (i = 0; i < len; i++) {
454 if (line[i] ==
' ') {
465 myPrintk(
"%d %c %02X\r\n",i,line[i],line[i]);
494 myPrintk(
"Valid Commands (%c)\r\n", c);
495 for (i = 0; 1; i++) {
542 myPrintk(
"Error in adc sampling: %d\n", err);
564 myPrintk(
"format batmon <0 | 1>\r\n");
571 myPrintk(
"Battery Monitor: %s\r\n", i ?
"Enabled" :
"Disabled");
593 myPrintk(
"Sample\tTemperature(deg C)\tPressure(Pa)\tHumidity(%%)\tGas resistance(ohm)\tStatus\n");
594 for (i = 0; i < count; i++) {
618 myPrintk(
"format bme688cs 0/1\r\n");
633 myPrintk(
"BME688CS: %d\r\n", bme688cs);
674 buffer[i++] = num % 10 +
'0';
680 *str++ = buffer[--i];
740 k_sleep(K_SECONDS(2));
746 k_sleep(K_SECONDS(2));
752 k_sleep(K_SECONDS(2));
758 k_sleep(K_SECONDS(2));
764 k_sleep(K_SECONDS(2));
780 k_sleep(K_SECONDS(2));
782 sprintf(str1,
"nRF52832");
783 myPrintkS(
"Board Version: %s\r\n", str1);
787 k_sleep(K_SECONDS(2));
790 myPrintkS(
"Hardware Version: %s\r\n", str1);
794 k_sleep(K_SECONDS(2));
796 sprintf(str1,
"nRF52832");
801 k_sleep(K_SECONDS(2));
807 myPrintkW(
"Manual trigger Enabled. Waiting for datetime command from gateway.\r\n");
825 if ((hdcCode > 0) && (hdcCode <= 7)) {
831 myPrintk(
"format dutycycle [HDC2080 Setting 1-7] [minutes > 2 if setting == 0]");
845 myPrintk(
"format dutycycle [HDC2080 Setting 1-7] [minutes > 2 if setting == 0]");
853 strcpy(str,
"2 Minutes");
857 strcpy(str,
"1 Minute");
861 strcpy(str,
"10 Seconds");
865 strcpy(str,
"5 Seconds");
869 strcpy(str,
"1 Second");
873 strcpy(str,
".5 Seconds");
877 strcpy(str,
".2 Seconds");
897 myPrintk(
"Flash Erase complete\r\n");
924 myPrintk(
"format flasherasesector [sector]");
929 myPrintk(
"Sector address %d >= 32\r\n", address);
934 myPrintk(
"Flash Sector %d Erase complete\r\n", address);
967 myPrintk(
"format flashFill [address][data] [length]");
971 if (address >= 32768) {
972 myPrintk(
"Page address %d >= 32768\r\n", address);
976 for (i = 0; i < length; i++, address++) {
977 myPrintk(
"flashFill page: 0x%X data: 0x%02X\r\n", address, data);
994 uint8_t flashIDIn[5];
997 myPrintk(
"Flash ID: 0x%02X 0x%02X 0x%02X\r\n", flashIDIn[0], flashIDIn[1], flashIDIn[2]);
1013 myPrintk(
"format flashnss 0/1\r\n");
1026 myPrintk(
"flashnss: %d\r\n", flashNSS);
1053 if (address >= 32768) {
1054 myPrintk(
"Page address %d >= 32768\r\n", address);
1059 for (k = 0; k < length; k++, address++) {
1061 myPrintk(
"Read Page 0x%X\r\n", address);
1064 for (i = 0; i < 256; i++) {
1065 if ((i % 0x10) == 0) {
1067 sprintf(str,
"0x%06X ", (
unsigned int)(address * 256) + i);
1070 myPrintk(str,
" %s\r\n0x%06X ", ascii, (
unsigned int)(address * 256) + i);
1071 for (j = 0; j <
sizeof(ascii); j++) {
1079 ascii[i % 0x10] =
'.';
1100 uint8_t flashStatusIn[3];
1103 myPrintk(
"Flash Status 0x%02X 0x%02X 0x%02X\r\n", flashStatusIn[0], flashStatusIn[1], flashStatusIn[2]);
1105 myPrintk(
"%sBusy\r\n", flashStatusIn[0] & 0x01 ?
"" :
"Not ");
1106 myPrintk(
"Write %sabled\r\n", flashStatusIn[0] & 0x02 ?
"en" :
"dis");
1107 myPrintk(
"Block Protect %d\r\n", (flashStatusIn[0] & 0x1C) >> 2);
1108 myPrintk(
"%s Protect\r\n", flashStatusIn[0] & 0x20 ?
"Bottom" :
"Top");
1109 myPrintk(
"%sK Blocks\r\n", flashStatusIn[0] & 0x40 ?
"4" :
"64");
1110 myPrintk(
"Status Register%s Protected\r\n", flashStatusIn[0] & 0x80 ?
"" :
" Not");
1111 myPrintk(
"\r\nStatus register 2\r\n");
1112 myPrintk(
"Status Register %sLocked\r\n", flashStatusIn[1] & 0x01 ?
"" :
"Not ");
1113 myPrintk(
"QSPI %sEnabled\r\n", flashStatusIn[1] & 0x02 ?
"" :
"Not ");
1114 myPrintk(
"Lock Bits %d\r\n", (flashStatusIn[1] & 0x38) >> 3);
1115 myPrintk(
"Complement Protect %d\r\n", flashStatusIn[1] & 0x40);
1116 myPrintk(
"Suspend Status %d\r\n", flashStatusIn[1] & 0x80);
1117 myPrintk(
"\r\nStatus register 3\r\n");
1118 myPrintk(
"Write protect Selection %d\r\n", flashStatusIn[2] & 0x04);
1119 myPrintk(
"Drive Stength %d\r\n", (flashStatusIn[2] & 0x60) >> 5);
1135 uint8_t dataArray[2];
1139 myPrintk(
"format flashWrite page address data\r\n");
1149 if (page >= 32768) {
1150 myPrintk(
"Page %d >= 32768\r\n", page);
1153 if (address >= 256) {
1154 myPrintk(
"Address %d >= 256\r\n", address);
1158 dataArray[0] = data;
1159 myPrintk(
"flashwrite page: 0x%X address: 0x%02X data: 0x%02X\r\n", page, address, dataArray[0]);
1163 myPrintk(
"flashwrite complete\r\n");
1212 myPrintk(
"Humidity (%%)\r\nDevice\tCurrent\tLow\tHigh\r\n");
1225 myPrintk(
"No Humidity sensor connected\r\n");
1238 int i2cAddress, i2cRegister, length, i;
1258 datas[0] = i2cRegister;
1259 i2c_write(
i2c_dev, datas, 1, i2cAddress);
1262 i2c_read(
i2c_dev, datas, length, 0x40);
1263 myPrintk(
"I2C Read Address: 0x%02X Reg: 0x%02X Length: %d\r\n", (
unsigned int)i2cAddress, (
int)i2cRegister, (
int)length);
1264 for (i = 0; i < length; i++) {
1265 myPrintk(
"0x%02X 0x%02X\r\n", (
unsigned int)(i2cRegister + i), datas[i]);
1279 int i2cAddress, i2cRegister, data;
1281 uint8_t dataArray[4];
1298 dataArray[0] = i2cRegister;
1299 dataArray[1] = data;
1301 i2c_write(
i2c_dev, dataArray, 2, i2cAddress);
1302 myPrintk(
"I2C write Address: 0x%02X Reg: 0x%02X data: 0x%02X\r\n", (
unsigned int)i2cAddress, (
int)i2cRegister, (
int)data);
1319 printk(
"format nouart0 [0/1]\n");
1328 k_sleep(K_SECONDS(3));
1335 myPrintkW(
"UART0 RX Disable Failed: %d\r\n", err);
1338 myPrintkW(
"UART0 SUSPEND: %d\r\n", err);
1344 err = pm_device_action_run(
uart0_dev, PM_DEVICE_ACTION_SUSPEND);
1348 err = pm_device_action_run(
uart0_dev, PM_DEVICE_ACTION_RESUME);
1353 myPrintkE(
"UART device is not ready\r\n");
1358 k_sleep(K_SECONDS(5));
1387 myPrintk(
"Ignore BME688: %s\r\n", i ?
"Enabled" :
"Disabled");
1395 myPrintk(
"format ignorebme688 [0 | 1]\r\n");
1435 myPrintk(
"Manual Trigger: %s\r\n", i ?
"Enabled" :
"Disabled");
1443 myPrintk(
"format manualtrigger [0 | 1]\r\n");
1457 myPrintk(
"Send BLE data immediately\r\n");
1473 myPrintk(
"Software Reset the board\r\n");
1474#if defined(CONFIG_REBOOT)
1479 myPrintk(
"Forced WDT reset of the processor. WDT feed Stopped!\r\n");
1511 myPrintk(
"format saved [clear/n] [len]\r\n");
1519 myPrintkI(
"Saved JSON Packets Cleared\r\n");
1522 for (
int i = 0; i < sectorCount; i++) {
1546 for (i = 0; i < j; i++) {
1613 for (i = 0; 1; i++) {
1645 myPrintk(
"Silent: %s\r\n", i ?
"Enabled" :
"Disabled");
1653 myPrintk(
"format silent [0 | 1]\r\n");
1670 myPrintk(
"Temperature (deg C)\r\nDevice\tCurrent\tLow\tHigh\r\n");
1681 myPrintk(
"No Temperature sensor connected\r\n");
1699#ifndef CONFIG_SERIAL
1705 myPrintk(
"Built:%s %s\r\n", __DATE__, __TIME__);
1706 if (IS_ENABLED(CONFIG_LTE_NETWORK_MODE_LTE_M)) {
1707 myPrintk(
"GPS not available!\r\n");
1709 if (IS_ENABLED(CONFIG_LTE_NETWORK_MODE_LTE_M_GPS)) {
void setRate(int rate)
Sets the automatic measurement frequency.
float readLowTempThreshold(void)
Reads the low temperature threshold currently set in the sensor.
float readHighTempThreshold(void)
Reads the high temperature threshold currently set in the sensor.
float readHumidity(void)
Reads the relative humidity from the HDC2080 sensor.
void triggerMeasurement(void)
Manually triggers a single measurement cycle.
float readHighHumidityThreshold(void)
Reads the high humidity threshold currently set in the sensor.
float readLowHumidityThreshold(void)
Reads the low humidity threshold currently set in the sensor.
void disableInterrupt(void)
Disables the physical interrupt/DRDY pin (sets to High-Z).
float readTemp(void)
Reads the temperature data from the HDC2080 sensor.
W25Q64JV driver header file.
int getBME688Data(int count, uint8_t quiet)
Triggers and retrieves measurement data from the BME688.
uint8_t flashReadIn[MAX_FLASH_BYTES]
flashParametersStruct flashParameters
working valuses of flash parameters in RAM
uint32_t sensorTypePresentAll
float adc_voltage[2]
last ADC voltage read [0] battery
const struct gpio_dt_spec spics2n
uint8_t sendingDeviceInfo
flag to indicate sending device info in BLE packet instead of sensor data
uint8_t stopWDTFeed
stop Watch Dog Timer feed causing a WDT interrupt for testing
long long gatewayDateTime
char * cmdLineParameter[MAX_PARAMETERS]
array of pointers to command line parameter strings
struct bme68x_data BME688Data
const struct gpio_dt_spec spics1n
void cliFlashID()
CLI command to read and display the unique Flash memory ID.
void cliADC()
CLI command to sample and display the ADC voltage.
void cliVersion()
CLI command to display firmware, hardware, and SDK version information.
void cliCustomer()
CLI command to set or display the customer name in flash parameters.
int8_t getCLICmd(char *line)
parses command line to find position of command in validCLICmds array.
void cliSensors()
CLI command to list all supported sensors and their detection status.
void cliFlashFillPage()
CLI command to fill one or more flash pages with a specific 32-bit data pattern.
void cliDateTime()
CLI command to set or display the gateway epoch timestamp.
void cliSensorName()
CLI command to set or display the human-readable sensor name.
void cliFlashErase()
CLI command to erase the entire external flash memory.
void cliBME688()
CLI command to read and display data from the BME688 sensor.
void cliFlashEraseSector()
CLI command to erase a specific 4KB sector of the external flash.
void cliI2CWrite()
CLI command to write data to a specific I2C device register.
COMMANDS
< vaild command indexes
void cliDutyCycle()
CLI command to configure the sensor data sampling interval.
void cliBME688CS()
CLI command to manually control the BME688 SPI Chip Select (CS) pin.
void displayHelp(char c)
displays a list of all available CLI commands
void cliIgnoreBME688()
CLI command to set or display the ignore BME688 flag.
void cliLocation()
CLI command to set or display the sensor's physical location.
char const * validCLICmds[]
array of valid commands - case insensitive
static char lineTmp[LINE_SIZE]
tempory line saved
#define LINE_SIZE
maximum number of characters on a CLI line
void cliSilent()
CLI command to set or display the silent mode flag.
void cliSaved()
CLI command to manage and display JSON packets saved in external flash.
void cliPublishNow()
CLI command to trigger an immediate sensor data publication.
void cliDeviceInfo()
Transmit comprehensive device information over BLE NUS service.
void cliDeviceID()
Display the unique device identifier string.
void cliHelp()
CLI command to display help information for available commands.
void cliHumidity()
CLI command to display humidity data from connected sensors.
void cliSensorID()
CLI command to set or display the unique sensor ID.
void cliFlashNSS()
CLI command to manually toggle the SPI Chip Select (NSS) for the Flash memory.
void executeCmd(char *line)
executes the command in line array.
void cliReset()
CLI command to reset the processor.
void cliManualTrigger(void)
CLI command to set or display the manual trigger mode flag.
char const * helpMessages[]
array of help messages
void cliFlashWritePage()
CLI command to write a single byte of data to a specific address within a flash page.
void cliI2CRead()
CLI command to read data from an I2C device.
void cliResetCause()
CLI command to display the reason for the last processor reset.
char * sensorTypeNames[]
sensor types and state (present = 1)
void cliTemperature()
CLI command to display temperature data from connected sensors.
void cliGroup()
CLI command to set or display the sensor group name.
void cliFlashStatus()
CLI command to read and display the status registers of the external flash.
void int64_to_string(int64_t num, char *str)
Converts a 64-bit signed integer to a null-terminated string.
void cliBatMon()
CLI command to enable or disable the battery monitor hardware.
void cliFlashReadPage()
CLI command to read and display the contents of external flash pages.
#define MAX_NUMBER_BLE_PACKETS
int myPrintk(char *restrict fmt,...)
void displayFlashxParameters(void)
displays the NV flash parameters.
void flashxClearParameters(void)
clears/initializes the flash parameters in RAM
#define VERSION_DATE_EXT2
#define VERSION_DATE_EXT3
int myPrintkS(char *restrict fmt,...)
prints a status message to the UART
void flashxWritePage(uint32_t page, uint32_t address, uint8_t *data, uint16_t count)
writes data to address in serial flash over the SPI bus.
void readNVFlashxID(uint8_t *flashId)
reads the NV Flash ID over the SPI bus.
struct k_sem uart_rx_disabled_sem
struct k_sem hdc_rdy_seen
int adc_sample(void)
get a single reading from ADC channel
#define FLASHPARAMETERSTART
int myPrintkI(char *restrict fmt,...)
prints an information message to the UART
void flashxReadPage(uint32_t address, uint8_t *flashRead)
reads a 256 byte page over the SPI bus.
#define EXPAND_AND_STR(x)
const struct device *const i2c_dev
get the device structure for the I2C device defined by I2C_DEV_NODE
int myPrintkE(char *restrict fmt,...)
prints an error message to the UART
#define VERSION_DATE_EXT1
void flashxEraseSector(uint32_t address)
erases a 256K byte sector over the SPI bus.
void flashxFillPage(uint32_t address, uint16_t data)
fills a 256 byte page with data over the SPI bus.
const struct gpio_dt_spec baten
get the GPIO specification for the BATEN pin defined by BATEN_NODE
void rescan(void)
rescan all I2C and SPI devices
const struct device *const uart0_dev
void setFlashxParameters(uint8_t display)
loads the NV Flash parameters from teh RAM flash parameters
void flashxErase(void)
erases the entire 8 Mb over the SPI bus.
void readNVFlashxStatus(uint8_t *flashStatus)
reads the 3 NV Flash status registers over the SPI bus.
int myPrintkW(char *restrict fmt,...)
prints a warning message to the UART
void error(void)
Function to handle fatal errors This function is called when a fatal error occurs in the system....