Embedded System Design 2 - Project
cable.h File Reference

Cable checking functionality. More...

#include <stdbool.h>
#include "datatypes.h"

Go to the source code of this file.

Functions

bool checkCable (MeasurementData_t data)
 Method to check if the wire is broken. More...
 

Detailed Description

Cable checking functionality.

Version
2.1
Author
Brecht Van Eeckhoudt

License

Copyright (C) 2019 - Brecht Van Eeckhoudt

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

A copy of the GNU General Public License can be found in the LICENSE file along with this source code.


Some methods use code obtained from examples from Silicon Labs' GitHub. These sections are licensed under the Silabs License Agreement. See the file "Silabs_License_Agreement.txt" for details. Before using this software for any purpose, you must agree to the terms of that agreement.

Definition in file cable.h.

Function Documentation

◆ checkCable()

bool checkCable ( MeasurementData_t  data)

Method to check if the wire is broken.

Parameters
[in]dataThe struct which contains the measurements to send using LoRaWAN.
Returns
  • true - Measurements have been send so the index has to be set back to zero.
  • false - No LoRaWAN message has been send.

Definition at line 92 of file cable.c.

93 {
94  /* Check if the cable is broken */
95  if (!checkCable_internal())
96  {
97  /* Only send a message 4 times */
98  if (cableBrokenSendTimes < 4)
99  {
100 
101 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
102  dbcrit("Cable broken! Sending the data ...");
103 #endif /* DEBUG_DBPRINT */
104 
105  initLoRaWAN(); /* Initialize LoRaWAN functionality */
106 
107  sendCableBroken(true); /* Send the LoRaWAN message */
108  sendMeasurements(data); /* Send the measurements */
109 
110  disableLoRaWAN(); /* Disable RN2483 */
111 
112  cableBrokenSendTimes++; /* Increment the counter */
113 
114  return (true);
115  }
116  else
117  {
118 
119 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
120  dbcrit("Cable broken but no longer sending the data");
121 #endif /* DEBUG_DBPRINT */
122 
123  return (false);
124  }
125  }
126  else
127  {
128 
129 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
130  dbinfo("Cable still intact");
131 #endif /* DEBUG_DBPRINT */
132 
133  return (false);
134  }
135 }
static bool checkCable_internal(void)
Method to check if the wire is broken.
Definition: cable.c:154
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:503
void sendMeasurements(MeasurementData_t data)
Send measured battery voltages and internal and external temperatures to the cloud using LoRaWAN...
void sendCableBroken(bool cableBroken)
Send a packet to the cloud using LoRaWAN to indicate that the cable is broken.
void disableLoRaWAN(void)
Disable LoRaWAN functionality.
void initLoRaWAN(void)
Initialize LoRaWAN functionality.
Definition: lora_wrappers.c:92
uint8_t cableBrokenSendTimes
Definition: cable.c:74
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:539