Skip to content

Commit 3ab0cf9

Browse files
authored
Merge pull request #1 from SampleEnvironment/dev
Dev
2 parents 4e254ad + bf2be1c commit 3ab0cf9

14 files changed

+589
-97
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.vs/*
2+
3+
4+
*.d
5+
*.o
6+
*.eep
7+
*.hex
8+
*.elf
9+
*.lss
10+
*.map
11+
*.srec
12+
*.mk
13+
Makefile

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "avr-util-library"]
22
path = avr-util-library
3-
url = git@github.com:SampleEnvironment/avr-util-library.git
3+
url = https://github.com/SampleEnvironment/avr-util-library.git

DispAdapter.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#ifdef GCM_old_disp
2727

2828
#include "disp/gcm_old_lcd_driver.h"
29-
#include "StringPixelCoordTabble_old.h"
29+
#include "StringPixelCoordTable_old.h"
3030
#endif
3131

3232
#ifdef ili9341
@@ -223,7 +223,7 @@ void paint_Main(void){
223223

224224

225225

226-
void paint_Value(uint64_t val,ROW_NAME row,uint8_t precision, uint8_t min_width,char* unit){
226+
void paint_Value(double val,ROW_NAME row,uint8_t precision, uint8_t min_width,char* unit){
227227
#ifdef ili9341
228228
char numberbuffer[30];
229229
dtostrf(((double)val)/pow(10,precision),min_width,precision,numberbuffer);
@@ -390,8 +390,14 @@ void displayTemPreVol(void){
390390
paint_string_row("",TEMP,1,"",white);
391391
sensor_err = 0;
392392
}
393-
394-
paint_Value( options.Temperature_value - 2732,TEMP, 1, 4, "°C");
393+
if (!options.T_Compensation_enable && !connected.BMP)
394+
{
395+
paint_string_row("/",TEMP,0,"",white);
396+
}
397+
else
398+
{
399+
paint_Value( ((double)options.Temperature_value) - 2732,TEMP, 1, 4, "°C");
400+
}
395401
}
396402
else{
397403

@@ -402,7 +408,13 @@ void displayTemPreVol(void){
402408
//PRESSURE
403409
if(!(options.p_Compensation_enable && (CHECK_ERROR(TEMPPRESS_ERROR))))
404410
{
405-
paint_Value(options.Pressure_value,PRESS, 1, 6, "mbar");
411+
if (!options.p_Compensation_enable && !connected.BMP)
412+
{
413+
paint_string_row("/",PRESS,0,"",white);
414+
}else{
415+
paint_Value(options.Pressure_value,PRESS, 1, 6, "mbar");
416+
}
417+
406418
}
407419
else{
408420

DispAdapter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void setInitScreen(uint16_t fore, uint16_t back, uint8_t nextLine, uint8_t FontN
8383
void paint_info_line(char * line, _Bool update);
8484
void paint_string_row_col(char *text,ROW_NAME row,uint8_t col, uint16_t color);
8585
void paint_string_row(char *text,ROW_NAME row,uint8_t update,char* unit,uint16_t color);
86-
void paint_Value(uint64_t val,ROW_NAME row,uint8_t precision, uint8_t min_width,char* unit);
86+
void paint_Value(double val,ROW_NAME row,uint8_t precision, uint8_t min_width,char* unit);
8787
void paint_Error(char* text, ROW_NAME row);
8888
void paint_Main(void);
8989
void InitScreen_AddLine_ili(const char* Text, const char FirstLine);

Gascounter_main.c

Lines changed: 72 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
#ifdef GCM_old_disp
4747
#include "disp/gcm_old_lcd_driver.h"
48-
#include "StringPixelCoordTabble_old.h"
48+
#include "StringPixelCoordTable_old.h"
4949
#endif
5050

5151
#ifdef ili9341
@@ -108,7 +108,7 @@ deltaType delta = {.Volume_since_last_send = 0,.Pressure_since_last_send = 0,.t_
108108
*
109109
* Timestamps and Pressurevalues for last send/display-reset/ping - Event
110110
*/
111-
lastType last= {.Pressure_on_send = 0,.time_send = 0,.time_display_reset = 0, .time_Pressure_Temp_meas = 0,.time_valid_time_reading = 0};
111+
lastType last= {.Pressure_on_send = 0,.time_send = 0,.time_display_reset = 0, .time_Pressure_Temp_meas = 0,.time_valid_time_reading = 0, .Status_on_Send = 0};
112112

113113

114114

@@ -327,7 +327,8 @@ uint8_t EEMEM Fun_trace_array[FUNTRACE_ARRAY_SIZE+FUNTRACE_HEADER_LEN]; //eepro
327327

328328
uint16_t EEMEM funtrace_was_activated; //word in eeprom to indicate that funtrace was activated
329329

330-
330+
uint16_t EEMEM eeSC_mask;
331+
uint8_t EEMEM eeSC_already_sent_from_server;
331332

332333

333334

@@ -447,6 +448,8 @@ void Collect_Measurement_Data(void){
447448
// network error is not reset on send/store
448449
if(BIT_CHECK(get_status(),NETWORK_ERROR)){BIT_SET(curr_Stat,status_bit_Network_err_91);}
449450

451+
452+
last.Status_on_Send = status_reset_on_send;
450453

451454

452455
sendbuffer[22] = curr_Stat;
@@ -636,18 +639,32 @@ void init(void)
636639
}
637640
else
638641
{
639-
642+
#ifdef ili9341
643+
Print_add_Line(STR_INIT_PRESS_ERR,2);
644+
#endif
645+
#ifdef GCM_old_disp
646+
Print_add_Line(STR_INIT_PRESS_ERR,0);
647+
#endif
640648
connected.BMP = 0;
641649
connected.BMP_on_Startup = 0;
642650
connected.TWI = 1;
643651
BMP_Temperature = 0;
644652
BMP_Pressure = 0;
645-
Print_add_Line(" ",0);
653+
//Print_add_Line(" ",0);
646654

647655
}
648656

649657

650-
xbee_init(&paint_info_line,NULL,0);
658+
uint16_t SC_mask = eeprom_read_word(&eeSC_mask);
659+
uint8_t SC_aleady_sent_from_server = eeprom_read_byte(&eeSC_already_sent_from_server);
660+
661+
if(SC_aleady_sent_from_server == SC_already_received_Pattern){
662+
xbee_init(&paint_info_line,NULL,0,SC_mask);
663+
}else
664+
{
665+
xbee_init(&paint_info_line,NULL,0,SC_MASK_DEFAULT);
666+
}
667+
651668

652669
xbee_hardware_version();
653670
Print_add_Line(STR_INIT_DONE,0);
@@ -1211,7 +1228,43 @@ void execute_server_CMDS(uint8_t reply_id){
12111228
sendbuffer[0] = 0;
12121229
xbee_send_message(SET_PING_INTERVALL_CMD,sendbuffer,1);
12131230
break;
1231+
1232+
case SET_SC_XBEE_MASK:;
1233+
uint16_t SC_mask = (frameBuffer[reply_id].data[0]<<8) + frameBuffer[reply_id].data[1];
12141234

1235+
if(!(SC_mask & 0xE001)){
1236+
// write new sc mask to eeprom
1237+
eeprom_update_word(&eeSC_mask, SC_mask);
1238+
eeprom_update_byte(&eeSC_already_sent_from_server,SC_already_received_Pattern);
1239+
1240+
//refresh xbee parameters
1241+
xbee_init(&paint_info_line,NULL,0,SC_mask);
1242+
xbee_Set_Scan_Channels(xbee.ScanChannels);
1243+
xbee_WR();
1244+
1245+
//Send Status Ack
1246+
sendbuffer[0] = 0;
1247+
xbee_send_message(SET_SC_XBEE_MASK,sendbuffer,1);
1248+
}else{
1249+
//Send Status Ack
1250+
sendbuffer[0] = 1;
1251+
xbee_send_message(SET_SC_XBEE_MASK,sendbuffer,1);
1252+
}
1253+
break;
1254+
1255+
case GET_SC_XBEE_MASK:
1256+
;
1257+
1258+
sendbuffer[0] = xbee.ScanChannels >> 8;
1259+
sendbuffer[1] = xbee.ScanChannels;
1260+
1261+
1262+
xbee_send_message(GET_SC_XBEE_MASK, sendbuffer,2);
1263+
1264+
break;
1265+
1266+
1267+
12151268

12161269

12171270
#ifdef USE_LAN
@@ -1236,7 +1289,7 @@ void execute_server_CMDS(uint8_t reply_id){
12361289
xbee.CoordIdentifier[NI_len] = '\0';
12371290

12381291
xbee_pseudo_send_AT_response( 'N', 'I', 0, sendbuffer, 0);
1239-
1292+
break;
12401293
default:;
12411294
uint8_t AT_Code = frameBuffer[reply_id].type;
12421295

@@ -1246,12 +1299,12 @@ void execute_server_CMDS(uint8_t reply_id){
12461299
{
12471300

12481301

1249-
xbee_pseudo_send_AT_response(
1250-
AT_Lut[(uint8_t)(AT_Code-AT_START)][0], // translate AT_code back to At ASCII chars
1251-
AT_Lut[(uint8_t)(AT_Code-AT_START)][1],
1252-
1, // Status == 1 --> atcommand not known
1253-
sendbuffer,
1254-
0); // empty payload
1302+
xbee_pseudo_send_AT_response(
1303+
AT_Lut[(uint8_t)(AT_Code-AT_START)][0], // translate AT_code back to At ASCII chars
1304+
AT_Lut[(uint8_t)(AT_Code-AT_START)][1],
1305+
1, // Status == 1 --> atcommand not known
1306+
sendbuffer,
1307+
0); // empty payload
12551308
}
12561309

12571310
break;
@@ -1673,7 +1726,7 @@ int main(void)
16731726
while(1)
16741727
{
16751728
delta_t = count_t_elapsed - time_first_try;
1676-
if(delta_t > 60)
1729+
if(delta_t > WAITTIME_COORDINATOR_ACTIVATION)
16771730
{
16781731
Print_add_Line("...failed!",0);
16791732
Print_add_Line("offline mode",0);
@@ -1821,7 +1874,7 @@ int main(void)
18211874
char boundsstr[100];
18221875
for(uint8_t i = 0;i < StartStat.bound_err_counter; i++ ){
18231876
uint8_t errVal = StartStat.boundsErrors[i];
1824-
1877+
18251878

18261879
sprintf(boundsstr,STR_RANGE_ERROR,
18271880
StartStat.optStrings[errVal],
@@ -2029,11 +2082,12 @@ int main(void)
20292082

20302083

20312084
if((delta.t_send >= options.t_transmission_max * 60)|| //
2032-
(delta.t_send >= options.t_transmission_min && delta.Volume_since_last_send > options.delta_V)||
2033-
(delta.t_send >= options.t_transmission_min && delta.Pressure_since_last_send > options.delta_p)||
2034-
(delta.t_send >= options.t_transmission_min && status_reset_on_send) )
2085+
(delta.t_send >= options.t_transmission_min && delta.Volume_since_last_send >= options.delta_V)||
2086+
(delta.t_send >= options.t_transmission_min && delta.Pressure_since_last_send >= options.delta_p)||
2087+
(delta.t_send >= options.t_transmission_min && status_reset_on_send && status_reset_on_send != last.Status_on_Send) )
20352088
{
20362089

2090+
20372091

20382092

20392093
Collect_Measurement_Data();

Gascounter_main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#define MEASUREMENT_MESSAGE_LENGTH 23 /**< @brief Number of Bytes that makes up one Measurement Message*/
3737
#define NUMBER_LOGIN_BYTES 36 /**< @brief Number of Bytes in login Message from Server */
3838

39+
#define WAITTIME_COORDINATOR_ACTIVATION 300
3940
//#define COM_TIMEOUT_TIME 10 /**< @brief Communication Timeout-period in Seconds */
4041

4142

@@ -148,6 +149,7 @@ typedef struct {
148149
* Absolute Times/Pressure of the last time an action was executetd i.e: Pinging the Server
149150
*/
150151
typedef struct {
152+
uint16_t Status_on_Send;
151153
uint32_t Pressure_on_send; /**< @brief Pressure the last time Data was sent/stored to the Server/memory (in 0.1 mbar)*/
152154
uint32_t time_send; /**< @brief Absolute time of last sending of Data*/
153155
uint32_t time_display_reset; /**< @brief Absolute time of last Display Reset*/

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Gascounter-module
2+
Firmware for *Gascounter Modules*, that monitor the flow through gasmeters. They are meant to be used in conjunction with [Helium Management](https://github.com/SampleEnvironment/Helium-Management) application.
3+
4+
## Getting started
5+
### Requisities
6+
In order to start developing/testing/flashing Firmware you will need:
7+
- [Microchip Studio](https://www.microchip.com/en-us/tools-resources/develop/microchip-studio)
8+
- A debugger for example *Atmel Power debugger*
9+
- Gascounter Module
10+
- Adapter from 6-Pin connector on Powerdebugger to 10-Pin on *gascounter module* specified [here](https://user-images.githubusercontent.com/85115389/188656912-2c82639d-4e30-490b-87a6-de65de5cbdc6.jpg)
11+
12+
13+
14+
### Preparations
15+
Before first compiling the project in Microchip Studio the submodule of the avr-library needs to be initialized:
16+
```
17+
git submodule update --init
18+
```
19+
20+
### Choosing a Release
21+
In order to generate a executable Firmware of a specific release, `git tag` will list all available releases and
22+
```git checkout --recurse-submodules vX.XXX```
23+
will load the release specified by `vX.XXX` (for example `v2.213`).
24+
25+
### Build configurations (from v2.212):
26+
Build configurations are used to generate firmware binarys that are meant for the same device Type, but with varying Hardware, for example the display that is used. Build configuration names for gascounter modules have the following Format `'DisplayType'-'NetworkInterface'`, and can be set via the dropdown menu depicted in the screenshot below.
27+
28+
![build_configurations](https://user-images.githubusercontent.com/85115389/198265129-1811f6dd-a333-4995-9eb3-8800d6aded16.png)
29+
30+
31+
32+
| Display Type | Description |
33+
|--------------|--------------------------------------------------------|
34+
| GCM_old_disp | old LC-display with low resolution |
35+
| ili9341 | Newer 2.2" rgb Display with a resolution of 240x320px |
36+
37+
| Network Interface | Description |
38+
|-------------------|---------------------------------------------------------------------------------------------------------|
39+
| XBEE | Gascounter-module communicates via an xbee module with the server |
40+
| LAN | Gascountermodule emulates an Xbee module and sends messages directly over Ethernet via an X-Port Module |
41+
42+
43+
44+
45+
For further Information please refer to the [Wiki](https://github.com/SampleEnvironment/gascounter-module/wiki) pages
46+

StringPixelCoordTable_ili9341.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@
112112
#define STR_INIT_CLOCK_ERR "Init DS3231M RTC ...error"
113113
#define STR_INIT_PRESS "Init BMP085"
114114
#define STR_INIT_PRESS_SUCC "Init BMP085 ...success"
115+
#define STR_INIT_PRESS_ERR "Init BMP085 not connected"
115116
#define STR_INIT_DONE "Init done"
116117

117118

118119

119120
// Strings
120121

121-
#define STR_INIT_OFFLINE "Init Offline"
122+
#define STR_INIT_OFFLINE "Network Err"
122123
#define STR_INIT_OFFLINE_MESSAGE "Network connection \ncould not be establishedon startup\n\nNetworkstatus:\n%s"
123124
#define STR_NO_COORDINATOR_FOUND "No Coordinator found"
124125
#define STR_NO_SERVER_FOUND "No Server found"

StringPixelCoordTable_old.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* StringPixelCoordTabble_old.h
3+
*
4+
* Created: 24.06.2022 19:35:49
5+
* Author: qfj
6+
*/
7+
8+
9+
#ifndef STRINGPIXELCOORDTABBLE_OLD_H_
10+
#define STRINGPIXELCOORDTABBLE_OLD_H_
11+
12+
13+
14+
// INIT STRINGS
15+
#define STR_HZB_GASCOUNTER "HZB Gascount"
16+
#define STR_LAN_VARIANT "LAN-VARIANT"
17+
#define STR_XBEE_VARIANT "XBEE-VARIANT"
18+
#define STR_INIT_START "Init start"
19+
#define STR_INIT_PORTS "Init ports"
20+
#define STR_INIT_TIMER "Init timer"
21+
#define STR_INIT_INTERRUPTS "Init interr."
22+
#define STR_INIT_USART "Init usart"
23+
#define STR_INIT_I2C "Init I2C"
24+
#define STR_INIT_CLOCK "Init Clock"
25+
#define STR_INIT_CLOCK_SUCC "...success"
26+
#define STR_INIT_CLOCK_ERR "...error"
27+
#define STR_INIT_PRESS "Init Press"
28+
#define STR_INIT_PRESS_SUCC "...success"
29+
#define STR_INIT_PRESS_ERR "...error"
30+
#define STR_INIT_DONE "Init done"
31+
32+
// ERROR STRINGS
33+
#define STR_INIT_OFFLINE "Netw. Err"
34+
#define STR_INIT_OFFLINE_MESSAGE "Network connection error\n%s"
35+
#define STR_NO_COORDINATOR_FOUND "No Coord."
36+
#define STR_NO_SERVER_FOUND "No Server"
37+
38+
#define STR_OPTIONS_LENGTH "Opt. len Err"
39+
#define STR_OPTIONS_LENGTH_MESSAGE "expected:%i\nreceived:%i"
40+
41+
#define STR_OPTION_RANGE_ERR "Bounds Err."
42+
#define STR_OPTION_RANGE_ERR_MESSAGE " "
43+
#define STR_RANGE_ERROR "%s\nr:%lu\ne:[%lu..%lu]\n"
44+
45+
#define STR_BMP_SENSOR_ERROR "BMP Error"
46+
#define STR_BMP_SENSOR_ERROR_MESSAGE "Temp. Press.Sensor not connected"
47+
48+
#define STR_RTC_ERROR "RTC ERROR"
49+
#define STR_RTC_ERROR_MESSAGE "Realtime clock not initialized"
50+
51+
52+
#endif /* STRINGPIXELCOORDTABBLE_OLD_H_ */

0 commit comments

Comments
 (0)