From 95619387248f41acb3b93617e625945cab8cb2ce Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 19 Apr 2019 13:54:56 -0400 Subject: [PATCH 001/194] added date and frame printing for curl --- afsk/ax25.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/afsk/ax25.c b/afsk/ax25.c index 15b127c2..b4de7278 100644 --- a/afsk/ax25.c +++ b/afsk/ax25.c @@ -20,6 +20,7 @@ #include "ax25.h" #include +#include #include "ax5043.h" #include "status.h" @@ -88,6 +89,19 @@ int ax25_tx_frame(ax25_conf_t *hax25, ax5043_conf_t *hax, memcpy(__tx_buffer, hax25->addr_field, hax25->addr_field_len); memcpy(__tx_buffer + hax25->addr_field_len, payload, len); + + printf("\n"); + time_t t = time(NULL); + struct tm tm = *localtime(&t); + + printf("curl --data \"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 4, tm.tm_min, tm.tm_sec); + int jj; + for(jj = 0; jj < 118; jj++) { + printf("%02x",__tx_buffer[jj]); + } + printf("&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/\n\n"); + + return ax5043_tx_frame(hax, __tx_buffer, len + hax25->addr_field_len, hax25->preamble_len, hax25->postable_len, 1000); From 80549a39c1c4153955cf456331909b8931c79fc1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 19 Apr 2019 14:21:51 -0400 Subject: [PATCH 002/194] added stdio.h --- afsk/ax25.c | 1 + 1 file changed, 1 insertion(+) diff --git a/afsk/ax25.c b/afsk/ax25.c index b4de7278..462aad13 100644 --- a/afsk/ax25.c +++ b/afsk/ax25.c @@ -21,6 +21,7 @@ #include "ax25.h" #include #include +#include #include "ax5043.h" #include "status.h" From 304b366370d3d692e623b3cd3092a072dad1b15b Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Fri, 19 Apr 2019 14:52:20 -0400 Subject: [PATCH 003/194] linked with libcurl4-openssl-dev --- Makefile | 14 +++++++------- afsk/ax25.c | 22 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 6b5d00dc..186e357b 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ radiocw: cw/cw_main.o radiocw: afsk/ax25.o radiocw: afsk/ax5043.o radiocw: afsk/send_afsk.o - gcc -o radiocw -L./ afsk/ax25.o afsk/ax5043.o afsk/send_afsk.o cw/cw_main.o -lwiringPi -lax5043 + gcc -o radiocw -L./ afsk/ax25.o afsk/ax5043.o afsk/send_afsk.o cw/cw_main.o -lwiringPi -lax5043 -lcurl radiopiglatin: libax5043.a radiopiglatin: piglatin/piglatin_main.o @@ -59,32 +59,32 @@ radiopiglatin: piglatin/piglatin_main.o testax5043tx: libax5043.a testax5043tx: transmit/transmit_main.o - gcc -o testax5043tx -pedantic -Wall -Wextra -L./ transmit/transmit_main.o -lwiringPi -lax5043 + gcc -o testax5043tx -pedantic -Wall -Wextra -L./ transmit/transmit_main.o -lwiringPi -lax5043 testax5043rx: libax5043.a testax5043rx: receive/receive_main.o - gcc -o testax5043rx -pedantic -Wall -Wextra -L./ receive/receive_main.o -lwiringPi -lax5043 + gcc -o testax5043rx -pedantic -Wall -Wextra -L./ receive/receive_main.o -lwiringPi -lax5043 -lcurl testax5043init: libax5043.a testax5043init: init/init_main.o - gcc -o testax5043init -pedantic -Wall -Wextra -L./ init/init_main.o -lwiringPi -lax5043 + gcc -o testax5043init -pedantic -Wall -Wextra -L./ init/init_main.o -lwiringPi -lax5043 -lcurl testax50432freq: libax5043.a testax50432freq: transmit2freq/transmit2freq_main.o - gcc -o testax50432freq -pedantic -Wall -Wextra -L./ transmit2freq/transmit2freq_main.o -lwiringPi -lax5043 + gcc -o testax50432freq -pedantic -Wall -Wextra -L./ transmit2freq/transmit2freq_main.o -lwiringPi -lax5043 -lcurl testafsktx: libax5043.a testafsktx: afsktx/ax25.o testafsktx: afsktx/ax5043.o testafsktx: afsktx/main.o - gcc -o testafsktx -pedantic -Wall -Wextra -L./ afsktx/ax25.o afsktx/ax5043.o afsktx/main.o -lwiringPi -lax5043 + gcc -o testafsktx -pedantic -Wall -Wextra -L./ afsktx/ax25.o afsktx/ax5043.o afsktx/main.o -lwiringPi -lax5043 -lcurl radioafsk: libax5043.a radioafsk: afsk/ax25.o radioafsk: afsk/ax5043.o radioafsk: afsk/main.o radioafsk: afsk/ina219.h - gcc -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o -lwiringPi -lax5043 + gcc -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o -lwiringPi -lax5043 -lcurl ax5043/generated/configcommon.o: ax5043/generated/configcommon.c diff --git a/afsk/ax25.c b/afsk/ax25.c index 462aad13..66588ed4 100644 --- a/afsk/ax25.c +++ b/afsk/ax25.c @@ -18,6 +18,7 @@ * along with this program. If not, see . */ +#include #include "ax25.h" #include #include @@ -102,7 +103,26 @@ int ax25_tx_frame(ax25_conf_t *hax25, ax5043_conf_t *hax, } printf("&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/\n\n"); - + CURL *curl; + CURLcode res; + + curl = curl_easy_init(); + if(curl) { + //curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); + curl_easy_setopt(curl, CURLOPT_URL, "https://db.satnogs.org/api/telemetry/"); + /* example.com is redirected, so we tell libcurl to follow redirection */ + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + + /* Perform the request, res will get the return code */ + res = curl_easy_perform(curl); + /* Check for errors */ + if(res != CURLE_OK) + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); + + /* always cleanup */ + curl_easy_cleanup(curl); + } return ax5043_tx_frame(hax, __tx_buffer, len + hax25->addr_field_len, hax25->preamble_len, hax25->postable_len, 1000); From aacade364ffb1cfdc9c6270f8e48a00a3675d49e Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Fri, 19 Apr 2019 15:43:00 -0400 Subject: [PATCH 004/194] almost working curl --- afsk/ax25.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/afsk/ax25.c b/afsk/ax25.c index 66588ed4..8b42ca90 100644 --- a/afsk/ax25.c +++ b/afsk/ax25.c @@ -93,15 +93,28 @@ int ax25_tx_frame(ax25_conf_t *hax25, ax5043_conf_t *hax, memcpy(__tx_buffer + hax25->addr_field_len, payload, len); printf("\n"); + + char post_data[512]; + char hex_data[118]; + char hex_octet[4]; time_t t = time(NULL); struct tm tm = *localtime(&t); + memset(post_data,0,strlen(post_data)); + memset(hex_data,0,strlen(hex_data)); + printf("1:%s\n",post_data); - printf("curl --data \"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 4, tm.tm_min, tm.tm_sec); int jj; for(jj = 0; jj < 118; jj++) { - printf("%02x",__tx_buffer[jj]); + sprintf(hex_octet, "%02x",__tx_buffer[jj]); + strcat(hex_data, hex_octet); } - printf("&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/\n\n"); + memset(post_data,0,strlen(post_data)); + printf("2:%s\n",post_data); + + //sprintf(post_data,"curl --data \"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 4, tm.tm_min, tm.tm_sec, hex_data); + sprintf(post_data,"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 4, tm.tm_min, tm.tm_sec, hex_data); + //printf("%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/\n\n", hex_data); + printf("3:%s\n",post_data); CURL *curl; CURLcode res; @@ -110,6 +123,12 @@ int ax25_tx_frame(ax25_conf_t *hax25, ax5043_conf_t *hax, if(curl) { //curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); curl_easy_setopt(curl, CURLOPT_URL, "https://db.satnogs.org/api/telemetry/"); + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data); + + /* if we don't provide POSTFIELDSIZE, libcurl will strlen() by + itself */ + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(post_data)); + /* example.com is redirected, so we tell libcurl to follow redirection */ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); From f2f21cea26859619241b02cd06de78653df5c37c Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Fri, 19 Apr 2019 15:52:06 -0400 Subject: [PATCH 005/194] still trying to get curl to work --- afsk/ax25.c | 1 + 1 file changed, 1 insertion(+) diff --git a/afsk/ax25.c b/afsk/ax25.c index 8b42ca90..c41f52a6 100644 --- a/afsk/ax25.c +++ b/afsk/ax25.c @@ -119,6 +119,7 @@ int ax25_tx_frame(ax25_conf_t *hax25, ax5043_conf_t *hax, CURL *curl; CURLcode res; + curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { //curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); From 7f0ec0d1e893b51bfbc3cca877be5527ae223065 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Fri, 19 Apr 2019 17:25:28 -0400 Subject: [PATCH 006/194] curl seems to work --- afsk/ax25.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/afsk/ax25.c b/afsk/ax25.c index c41f52a6..d4b2bc23 100644 --- a/afsk/ax25.c +++ b/afsk/ax25.c @@ -94,27 +94,27 @@ int ax25_tx_frame(ax25_conf_t *hax25, ax5043_conf_t *hax, printf("\n"); - char post_data[512]; - char hex_data[118]; + char post_data[1024]; + char hex_data[512]; char hex_octet[4]; time_t t = time(NULL); struct tm tm = *localtime(&t); memset(post_data,0,strlen(post_data)); memset(hex_data,0,strlen(hex_data)); - printf("1:%s\n",post_data); + //printf("1:%s\n",post_data); int jj; for(jj = 0; jj < 118; jj++) { sprintf(hex_octet, "%02x",__tx_buffer[jj]); strcat(hex_data, hex_octet); } - memset(post_data,0,strlen(post_data)); - printf("2:%s\n",post_data); + //memset(post_data,0,strlen(post_data)); + //printf("2:%s\n",post_data); //sprintf(post_data,"curl --data \"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 4, tm.tm_min, tm.tm_sec, hex_data); sprintf(post_data,"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 4, tm.tm_min, tm.tm_sec, hex_data); //printf("%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/\n\n", hex_data); - printf("3:%s\n",post_data); + printf("curl post data: %s\n",post_data); CURL *curl; CURLcode res; From be415f1fab25ad1c469934556ab775ad467f4814 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 9 May 2019 17:49:40 -0400 Subject: [PATCH 007/194] fixed -Z telem bug --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index ea4a98fd..f452efeb 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -368,8 +368,8 @@ int get_tlm(int tlm[][5]) { wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue); wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, config); wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue); - z_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; - z_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; + z_current = wiringPiI2CReadReg16(z_fd, INA219_REG_CURRENT) / x_currentDivider; + z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; } printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n", current, power, y_current, y_power, z_current, z_power); From 773b7b90b326528a95406fd804d8a82705442c2d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 26 May 2019 18:04:00 -0400 Subject: [PATCH 008/194] added modulo 24 to UTC calculation bug --- afsk/ax25.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/ax25.c b/afsk/ax25.c index d4b2bc23..f597ae12 100644 --- a/afsk/ax25.c +++ b/afsk/ax25.c @@ -112,7 +112,7 @@ int ax25_tx_frame(ax25_conf_t *hax25, ax5043_conf_t *hax, //printf("2:%s\n",post_data); //sprintf(post_data,"curl --data \"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 4, tm.tm_min, tm.tm_sec, hex_data); - sprintf(post_data,"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 4, tm.tm_min, tm.tm_sec, hex_data); + sprintf(post_data,"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, (tm.tm_hour + 4) % 24, tm.tm_min, tm.tm_sec, hex_data); //printf("%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/\n\n", hex_data); printf("curl post data: %s\n",post_data); From 2d8d802da52ffcef04f91d6c6d4b427aee233421 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Sat, 6 Jul 2019 02:23:55 -0400 Subject: [PATCH 009/194] testing c code not working --- afsk/main.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 4f90184a..1c83776d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -150,14 +150,14 @@ int main(void) { // new INA219 current reading code - x_calValue = 8192; - x_powerMultiplier = 1; - x_currentDivider = 20; - config = INA219_CONFIG_BVOLTAGERANGE_16V | - INA219_CONFIG_GAIN_40MV | + x_calValue = 4096; //8192; + x_powerMultiplier = 2; + x_currentDivider = 10; + config = INA219_CONFIG_BVOLTAGERANGE_32V | + INA219_CONFIG_GAIN_320MV | // 40MV | INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_4S_2130US | - //INA219_CONFIG_SADCRES_12BIT_1S_532US | + // INA219_CONFIG_SADCRES_12BIT_4S_2130US | + INA219_CONFIG_SADCRES_12BIT_1S_532US | INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; if ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0) @@ -201,7 +201,7 @@ int main(void) { fprintf(stderr,"INFO: Getting TLM Data\n"); - //get_tlm(tlm); + get_tlm(tlm); fprintf(stderr,"INFO: Preparing X.25 packet\n"); @@ -358,6 +358,18 @@ int get_tlm(int tlm[][5]) { if (x_fd != -1) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config); + int blink; + for (blink = 1; blink < 20 ;blink++) { + delay(500); + int shuntVolts = wiringPiI2CReadReg16(x_fd, INA219_REG_SHUNTVOLTAGE); // * 0.01; + delay(500); + int busVolts = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE); // * 0.001; + busVolts = (int16_t)((busVolts >> 3) * 4); + double volts = busVolts * 0.001 + shuntVolts * 0.01; + + printf("********** -X 0x40 volts %4.2f busvoltage %d shutVoltage %d\n", volts, busVolts, shuntVolts); + delay(500); + } wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; From 45970c7b62f867d3d969e1409f076f65afe8bd5c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 02:29:51 -0400 Subject: [PATCH 010/194] added Adafruit_INA219 --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6ea66e39..1109edf5 100644 --- a/Makefile +++ b/Makefile @@ -84,8 +84,11 @@ radioafsk: afsk/ax25.o radioafsk: afsk/ax5043.o radioafsk: afsk/main.o radioafsk: afsk/ina219.h - gcc -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o -lwiringPi -lax5043 +radioafsk: Adafruit_INA219/Adafruit_INA219.o + gcc -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o Adafruit_INA219/Adafruit_INA219.o -lwiringPi -lax5043 +Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.h + cd Adafruit_INA219; gcc -I -pedantic -Wconversion -Wall -Wextra -c Adafruit_INA219.c; cd .. ax5043/generated/configcommon.o: ax5043/generated/configcommon.c ax5043/generated/configcommon.o: ax5043/generated/configrx.h From 3be2f3b5baa9ba68f454d1a348faa686c3f5ac56 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 02:54:27 -0400 Subject: [PATCH 011/194] Update Makefile --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 1109edf5..209a58bc 100644 --- a/Makefile +++ b/Makefile @@ -85,8 +85,10 @@ radioafsk: afsk/ax5043.o radioafsk: afsk/main.o radioafsk: afsk/ina219.h radioafsk: Adafruit_INA219/Adafruit_INA219.o +radioafsk: Adafruit_INA219/Adafruit_INA219.h gcc -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o Adafruit_INA219/Adafruit_INA219.o -lwiringPi -lax5043 +Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.c Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.h cd Adafruit_INA219; gcc -I -pedantic -Wconversion -Wall -Wextra -c Adafruit_INA219.c; cd .. From 9e0e42617e7da10235f672e2be45d5d823b3d06b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 03:19:36 -0400 Subject: [PATCH 012/194] added calls to Adafruit_INA219 libs --- afsk/main.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 1c83776d..3ca10c39 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -356,23 +356,34 @@ int get_tlm(int tlm[][5]) { // read i2c current sensors // double current = 0, power = 0, y_current = 0, y_power = 0, z_current = 0, z_power = 0; if (x_fd != -1) { - wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); - wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config); +// wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); +// wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config); + + setCalibration_16V_400mA(x_fd); + int blink; for (blink = 1; blink < 20 ;blink++) { - delay(500); +/* delay(500); int shuntVolts = wiringPiI2CReadReg16(x_fd, INA219_REG_SHUNTVOLTAGE); // * 0.01; delay(500); int busVolts = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE); // * 0.001; busVolts = (int16_t)((busVolts >> 3) * 4); double volts = busVolts * 0.001 + shuntVolts * 0.01; - + printf("********** -X 0x40 volts %4.2f busvoltage %d shutVoltage %d\n", volts, busVolts, shuntVolts); +*/ + float shuntVolts = getShuntVoltage_mV(x_fd); + float busVolts = getBusVoltage_V(x_fd); + current = getCurrent_mA(x_fd); + power = getPower_mW(x_fd); + + printf("********** -X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n", busVolts, shuntVolts, current, power); + delay(500); } - wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); - current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; - power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; +// wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); +// current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; +// power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, config); wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); From 34481f4eb4c53dfcd30be86351123971d0e6060e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 03:21:19 -0400 Subject: [PATCH 013/194] Update main.c --- afsk/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/afsk/main.c b/afsk/main.c index 3ca10c39..0cfcc657 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -35,6 +35,7 @@ #include #include #include "ina219.h" +#include "Adafruit_INA219/Adafruit_INA219.h" // Put your callsign here #define CALLSIGN "KU2Y" From 96d3b910a1f6bb13c064e483612d18bcd300444e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 03:22:32 -0400 Subject: [PATCH 014/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 0cfcc657..6761c312 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -35,7 +35,7 @@ #include #include #include "ina219.h" -#include "Adafruit_INA219/Adafruit_INA219.h" +#include "../Adafruit_INA219/Adafruit_INA219.h" // Put your callsign here #define CALLSIGN "KU2Y" From 341356bf33de8b0ed08a7bcfa0caeda852a8a016 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 03:24:40 -0400 Subject: [PATCH 015/194] Update main.c --- afsk/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 6761c312..c548f9db 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -35,7 +35,6 @@ #include #include #include "ina219.h" -#include "../Adafruit_INA219/Adafruit_INA219.h" // Put your callsign here #define CALLSIGN "KU2Y" @@ -70,6 +69,15 @@ int get_tlm(int tlm[][5]); long int timestamp; void config_x25(); void trans_x25(); +void setCalibration_32V_2A(int fd); +void setCalibration_32V_1A(int fd); +void setCalibration_16V_400mA(int fd); +float getBusVoltage_V(int fd); +float getShuntVoltage_mV(int fd); +float getCurrent_mA(int fd); +float getPower_mW(int fd); +void powerSave(int fd, int on); + //long int timestamp; int tempSensor; From d6e1eceb5c74e1314ca5468cf1c239c4c363371e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 03:47:52 -0400 Subject: [PATCH 016/194] Update main.c --- afsk/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index c548f9db..87634eb2 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -177,7 +177,9 @@ int main(void) { z_fd = -1; } else { - x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); +// x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); + x_fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); + fprintf("stderr,Opening of -X fd %d\n", x_fd); y_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); printf("Opening of -Y fd %d\n", y_fd); From b893833d6cdc894fe7f2fa53135bda595584a978 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 15:33:48 -0400 Subject: [PATCH 017/194] Update main.c --- afsk/main.c | 62 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 87634eb2..0b8ce484 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -61,6 +61,16 @@ #define POWER 2 #define VBATT 15 +#define PLUS_X 0 +#define PLUS_Y 1 +#define PLUS_Z 2 +#define BAT 3 +#define MINUS_X 4 +#define MINUS_Y 5 +#define MINUS_Z 6 +#define BUS 7 +#define OFF -1 + ax5043_conf_t hax5043; ax25_conf_t hax25; @@ -93,6 +103,7 @@ int x_currentDivider; int x_calValue; int y_fd; // I2C bus 0 address 0x41 int z_fd; // I2C bos 0 address 0x44 +int sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 int main(void) { @@ -185,6 +196,36 @@ int main(void) { printf("Opening of -Y fd %d\n", y_fd); z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); printf("Opening of -Z fd %d\n", z_fd); + + if (open("/dev/i2c-1", O_RDWR)) > 0) // Test if I2C Bus 1 is present + { + sensor[PLUS_X] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); + sensor[PLUS_Y] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x41); + sensor[PLUS_Z] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x44); + sensor[BAT] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x45); + sensor[BUS] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a); + } else + { + sensor[PLUS_X] = OFF; + sensor[PLUS_Y] = OFF; + sensor[PLUS_Z] = OFF; + sensor[BAT] = OFF; + sensor[BUS] = OFF; + } + if (open("/dev/i2c-0", O_RDWR)) > 0) // Test if I2C Bus 0 is present + { + sensor[MINUS_X] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); + sensor[MINUS_Y] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); + sensor[MINUS_Z] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); + + } else + { + sensor[MINUS_X] = OFF; + sensor[MINUS_Y] = OFF; + sensor[MINUS_Z] = OFF; + } + + } int ret; @@ -365,15 +406,15 @@ int get_tlm(int tlm[][5]) { } */ // read i2c current sensors // - double current = 0, power = 0, y_current = 0, y_power = 0, z_current = 0, z_power = 0; + double current = 0, voltage = 0, power = 0, y_current = 0, y_voltage, y_power = 0, z_current = 0, z_voltage = 0, z_power = 0; if (x_fd != -1) { // wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); // wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config); setCalibration_16V_400mA(x_fd); - int blink; - for (blink = 1; blink < 20 ;blink++) { +// int blink; +// for (blink = 1; blink < 20 ;blink++) { /* delay(500); int shuntVolts = wiringPiI2CReadReg16(x_fd, INA219_REG_SHUNTVOLTAGE); // * 0.01; delay(500); @@ -387,14 +428,14 @@ int get_tlm(int tlm[][5]) { float busVolts = getBusVoltage_V(x_fd); current = getCurrent_mA(x_fd); power = getPower_mW(x_fd); - - printf("********** -X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n", busVolts, shuntVolts, current, power); + voltage = shuntVolts + busVolts; + printf("-X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n", busVolts, shuntVolts, current, power); - delay(500); - } -// wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); -// current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; -// power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; +// delay(500); + // } +/* wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); + current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; + power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, config); wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); @@ -405,6 +446,7 @@ int get_tlm(int tlm[][5]) { wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue); z_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; z_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; +*/ } printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n", current, power, y_current, y_power, z_current, z_power); From e4cbde2f88b74b3f085e3ce1127a8cea3dbac125 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 15:41:58 -0400 Subject: [PATCH 018/194] Update main.c --- afsk/main.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 0b8ce484..3b4d4f3a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -104,6 +104,7 @@ int x_calValue; int y_fd; // I2C bus 0 address 0x41 int z_fd; // I2C bos 0 address 0x44 int sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 +float voltsBus[8], voltsShunt[8], current[8], power[8]; int main(void) { @@ -430,7 +431,30 @@ int get_tlm(int tlm[][5]) { power = getPower_mW(x_fd); voltage = shuntVolts + busVolts; printf("-X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n", busVolts, shuntVolts, current, power); - + + int count; + for (count = 0; count < 8; count++) + { + if (sensor[count] != OFF) + { + voltsShunt[count] = getShuntVoltage_mV(sensor[count]); + voltsBus[count] = getBusVoltage_V(sensor[count]); + current[count] = getCurrent_mA(sensor[count]; + power[count] = getPower_mW(sensor[count]); + } + else + { + voltsShunt[count] = 0; + voltsBus[count] = 0; + current[count] = 0; + power[count] = 0; + } + } + + + + + // delay(500); // } /* wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); From 5d3131276eee0ac8049302243e2a3935785a648f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 15:59:09 -0400 Subject: [PATCH 019/194] Update main.c --- afsk/main.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 3b4d4f3a..dabd2b3a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -437,7 +437,8 @@ int get_tlm(int tlm[][5]) { { if (sensor[count] != OFF) { - voltsShunt[count] = getShuntVoltage_mV(sensor[count]); + setCalibration_16V_400mA(sensor[count]); + voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; voltsBus[count] = getBusVoltage_V(sensor[count]); current[count] = getCurrent_mA(sensor[count]; power[count] = getPower_mW(sensor[count]); @@ -449,11 +450,10 @@ int get_tlm(int tlm[][5]) { current[count] = 0; power[count] = 0; } - } - - - - + printf(" sensor[%d] voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", + count, busVolts[count], voltsShunt[count], current[count], power[count]); + } + // delay(500); // } @@ -470,11 +470,10 @@ int get_tlm(int tlm[][5]) { wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue); z_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; z_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; -*/ } printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n", current, power, y_current, y_power, z_current, z_power); - +*/ // printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL)); tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENT], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi From 61c3790ad3a7dc7239c63bbd277dc419c775e1aa Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 16:00:31 -0400 Subject: [PATCH 020/194] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index dabd2b3a..133b68d8 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -198,7 +198,7 @@ int main(void) { z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); printf("Opening of -Z fd %d\n", z_fd); - if (open("/dev/i2c-1", O_RDWR)) > 0) // Test if I2C Bus 1 is present + if ((open("/dev/i2c-1", O_RDWR)) > 0) // Test if I2C Bus 1 is present { sensor[PLUS_X] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); sensor[PLUS_Y] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x41); @@ -213,7 +213,7 @@ int main(void) { sensor[BAT] = OFF; sensor[BUS] = OFF; } - if (open("/dev/i2c-0", O_RDWR)) > 0) // Test if I2C Bus 0 is present + if ((open("/dev/i2c-0", O_RDWR)) > 0) // Test if I2C Bus 0 is present { sensor[MINUS_X] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); sensor[MINUS_Y] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); From 0d51b4646568fb0889098018396c2f2c7f7cd947 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 16:02:11 -0400 Subject: [PATCH 021/194] Update main.c --- afsk/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 133b68d8..ffe98214 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -197,9 +197,11 @@ int main(void) { printf("Opening of -Y fd %d\n", y_fd); z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); printf("Opening of -Z fd %d\n", z_fd); - - if ((open("/dev/i2c-1", O_RDWR)) > 0) // Test if I2C Bus 1 is present + + int test; + if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present { + close(test); sensor[PLUS_X] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); sensor[PLUS_Y] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x41); sensor[PLUS_Z] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x44); @@ -213,8 +215,9 @@ int main(void) { sensor[BAT] = OFF; sensor[BUS] = OFF; } - if ((open("/dev/i2c-0", O_RDWR)) > 0) // Test if I2C Bus 0 is present + if (((test = open("/dev/i2c-0", O_RDWR))) > 0) // Test if I2C Bus 0 is present { + close(test); sensor[MINUS_X] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); sensor[MINUS_Y] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); sensor[MINUS_Z] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); From 0c6805f1cdeb2e949316fa917c65b25029818e5f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 16:04:38 -0400 Subject: [PATCH 022/194] Update main.c --- afsk/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index ffe98214..609b9452 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -57,7 +57,7 @@ #define SENSOR_45 9 #define SENSOR_4A 12 #define VOLTAGE 0 -#define CURRENT 1 +#define CURRENTV 1 #define POWER 2 #define VBATT 15 @@ -479,17 +479,17 @@ int get_tlm(int tlm[][5]) { */ // printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL)); - tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENT], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENT], NULL)/10) % 100; // +X current [4] + tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENTV], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi + tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENTV], NULL)/10) % 100; // +X current [4] tlm[1][C] = (int) (99.5 - current/10) % 100; // X- current [10] - tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENT], NULL)/10) % 100; // +Y current [7] + tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENTV], NULL)/10) % 100; // +Y current [7] tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10] - tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENT], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel + tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENTV], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel tlm[2][C] = (int) (99.5 - z_current/10) % 100; // -Z current (was timestamp) // tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100; - tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENT], NULL)/10.0) % 100; // NiMH Battery current + tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENTV], NULL)/10.0) % 100; // NiMH Battery current tlm[3][A] = abs((int)((strtof(ina219[SENSOR_45 + VOLTAGE], NULL) * 10) - 65.5) % 100); tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0) % 100; // 5V supply to Pi From b1f6e12f535baa3a468bb8e7fab5a0f6b241bf5f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 16:08:41 -0400 Subject: [PATCH 023/194] Update main.c --- afsk/main.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 609b9452..ccd5a1d2 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -104,7 +104,10 @@ int x_calValue; int y_fd; // I2C bus 0 address 0x41 int z_fd; // I2C bos 0 address 0x44 int sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -float voltsBus[8], voltsShunt[8], current[8], power[8]; +float voltsBus[8]; +float voltsShunt[8]; +float current[8]; +float power[8]; int main(void) { @@ -410,7 +413,7 @@ int get_tlm(int tlm[][5]) { } */ // read i2c current sensors // - double current = 0, voltage = 0, power = 0, y_current = 0, y_voltage, y_power = 0, z_current = 0, z_voltage = 0, z_power = 0; + double x_current = 0, voltage = 0, power = 0, y_current = 0, y_voltage, y_power = 0, z_current = 0, z_voltage = 0, z_power = 0; if (x_fd != -1) { // wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); // wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config); @@ -430,10 +433,10 @@ int get_tlm(int tlm[][5]) { */ float shuntVolts = getShuntVoltage_mV(x_fd); float busVolts = getBusVoltage_V(x_fd); - current = getCurrent_mA(x_fd); + x_current = getCurrent_mA(x_fd); power = getPower_mW(x_fd); voltage = shuntVolts + busVolts; - printf("-X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n", busVolts, shuntVolts, current, power); + printf("-X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n", busVolts, shuntVolts, x_current, power); int count; for (count = 0; count < 8; count++) @@ -461,7 +464,7 @@ int get_tlm(int tlm[][5]) { // delay(500); // } /* wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); - current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; + x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, config); @@ -475,13 +478,13 @@ int get_tlm(int tlm[][5]) { z_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; } printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n", - current, power, y_current, y_power, z_current, z_power); + x_current, power, y_current, y_power, z_current, z_power); */ // printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL)); tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENTV], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENTV], NULL)/10) % 100; // +X current [4] - tlm[1][C] = (int) (99.5 - current/10) % 100; // X- current [10] + tlm[1][C] = (int) (99.5 - x_current/10) % 100; // X- current [10] tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENTV], NULL)/10) % 100; // +Y current [7] tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10] From 89f794331e1dd3d200a29831578e09ccaeff42bb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 16:09:38 -0400 Subject: [PATCH 024/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index ccd5a1d2..ef43cf37 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -446,7 +446,7 @@ int get_tlm(int tlm[][5]) { setCalibration_16V_400mA(sensor[count]); voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; voltsBus[count] = getBusVoltage_V(sensor[count]); - current[count] = getCurrent_mA(sensor[count]; + current[count] = getCurrent_mA(sensor[count]); power[count] = getPower_mW(sensor[count]); } else From 0a36cc2f07b605299d151bb84c0ee861564b04de Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 16:10:42 -0400 Subject: [PATCH 025/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index ef43cf37..16f7d492 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -457,7 +457,7 @@ int get_tlm(int tlm[][5]) { power[count] = 0; } printf(" sensor[%d] voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", - count, busVolts[count], voltsShunt[count], current[count], power[count]); + count, voltsBus[count], voltsShunt[count], current[count], power[count]); } From b24d1fcf8315446c8a31e8f407a0bb329699e290 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 16:12:14 -0400 Subject: [PATCH 026/194] Update main.c --- afsk/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 16f7d492..b03740ac 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -413,7 +413,7 @@ int get_tlm(int tlm[][5]) { } */ // read i2c current sensors // - double x_current = 0, voltage = 0, power = 0, y_current = 0, y_voltage, y_power = 0, z_current = 0, z_voltage = 0, z_power = 0; + double x_current = 0, voltage = 0, x_power = 0, y_current = 0, y_voltage, y_power = 0, z_current = 0, z_voltage = 0, z_power = 0; if (x_fd != -1) { // wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); // wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config); @@ -465,7 +465,7 @@ int get_tlm(int tlm[][5]) { // } /* wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; - power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; + x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, config); wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); @@ -478,7 +478,7 @@ int get_tlm(int tlm[][5]) { z_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; } printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n", - x_current, power, y_current, y_power, z_current, z_power); + x_current, x_power, y_current, y_power, z_current, z_power); */ // printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL)); From ed6452ed25413be526862eaf1bbda94c23e64426 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 16:14:40 -0400 Subject: [PATCH 027/194] Update main.c --- afsk/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index b03740ac..e8b8e269 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -437,7 +437,8 @@ int get_tlm(int tlm[][5]) { power = getPower_mW(x_fd); voltage = shuntVolts + busVolts; printf("-X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n", busVolts, shuntVolts, x_current, power); - + + } int count; for (count = 0; count < 8; count++) { From f6a088812697fb92e6031df780ae66c13b6cb44c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 16:15:59 -0400 Subject: [PATCH 028/194] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index e8b8e269..0ad6ab1b 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -434,9 +434,9 @@ int get_tlm(int tlm[][5]) { float shuntVolts = getShuntVoltage_mV(x_fd); float busVolts = getBusVoltage_V(x_fd); x_current = getCurrent_mA(x_fd); - power = getPower_mW(x_fd); + x_power = getPower_mW(x_fd); voltage = shuntVolts + busVolts; - printf("-X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n", busVolts, shuntVolts, x_current, power); + printf("-X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n", busVolts, shuntVolts, x_current, x_power); } int count; From f720278ce41e67ea28765d1f18c0401864b9c591 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sat, 6 Jul 2019 16:51:06 -0400 Subject: [PATCH 029/194] Update main.c --- afsk/main.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 0ad6ab1b..b60f8db7 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -440,7 +440,7 @@ int get_tlm(int tlm[][5]) { } int count; - for (count = 0; count < 8; count++) + for (count = 0; count < 7; count++) { if (sensor[count] != OFF) { @@ -460,7 +460,27 @@ int get_tlm(int tlm[][5]) { printf(" sensor[%d] voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", count, voltsBus[count], voltsShunt[count], current[count], power[count]); } + if (sensor[count] != OFF) // count = 7 MoPower V2 INA219 + { + setCalibration_16V_400mA(sensor[count]); + voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; + voltsBus[count] = getBusVoltage_V(sensor[count]); + current[count] = getCurrent_mA(sensor[count]) * 4; + power[count] = getPower_mW(sensor[count]) *2; + } + else + { + voltsShunt[count] = 0; + voltsBus[count] = 0; + current[count] = 0; + power[count] = 0; + } + printf(" sensor[%d] voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", + count, voltsBus[count], voltsShunt[count], current[count], power[count]); + + + // delay(500); // } From 16cd6764596b98e819de178ea8f82448c0ca3aa3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 7 Jul 2019 01:18:07 -0400 Subject: [PATCH 030/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index b60f8db7..8514ac94 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -195,7 +195,7 @@ int main(void) { // x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); x_fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); - fprintf("stderr,Opening of -X fd %d\n", x_fd); + fprintf(stderr,"Opening of -X fd %d\n", x_fd); y_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); printf("Opening of -Y fd %d\n", y_fd); z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); From cd14848514703bbfe5161b73bba1f04d42df0167 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 7 Jul 2019 01:57:24 -0400 Subject: [PATCH 031/194] Update main.c --- afsk/main.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 8514ac94..7cad8c9b 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -82,6 +82,7 @@ void trans_x25(); void setCalibration_32V_2A(int fd); void setCalibration_32V_1A(int fd); void setCalibration_16V_400mA(int fd); +void setCalibration_16V_2A(int fd); float getBusVoltage_V(int fd); float getShuntVoltage_mV(int fd); float getCurrent_mA(int fd); @@ -460,23 +461,23 @@ int get_tlm(int tlm[][5]) { printf(" sensor[%d] voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", count, voltsBus[count], voltsShunt[count], current[count], power[count]); } - if (sensor[count] != OFF) // count = 7 MoPower V2 INA219 + if (sensor[BUS] != OFF) // For MoPower V2 INA219 { - setCalibration_16V_400mA(sensor[count]); - voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; - voltsBus[count] = getBusVoltage_V(sensor[count]); - current[count] = getCurrent_mA(sensor[count]) * 4; - power[count] = getPower_mW(sensor[count]) *2; + setCalibration_16V_2A(sensor[BUS]); + voltsShunt[BUS] = getShuntVoltage_mV(sensor[BUS])/1000; + voltsBus[BUS] = getBusVoltage_V(sensor[BUS]); + current[BUS] = getCurrent_mA(sensor[BUS]) * 4; + power[BUS] = getPower_mW(sensor[BUS]) *2; } else { - voltsShunt[count] = 0; - voltsBus[count] = 0; - current[count] = 0; - power[count] = 0; + voltsShunt[BUS] = 0; + voltsBus[BUS] = 0; + current[BUS] = 0; + power[BUS] = 0; } printf(" sensor[%d] voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", - count, voltsBus[count], voltsShunt[count], current[count], power[count]); + count, voltsBus[BUS], voltsShunt[BUS], current[BUS], power[BUS]); From fbf6fa8c0c2c13e56c78a5c9683954b277751b8f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 7 Jul 2019 02:01:34 -0400 Subject: [PATCH 032/194] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 7cad8c9b..79122286 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -466,8 +466,8 @@ int get_tlm(int tlm[][5]) { setCalibration_16V_2A(sensor[BUS]); voltsShunt[BUS] = getShuntVoltage_mV(sensor[BUS])/1000; voltsBus[BUS] = getBusVoltage_V(sensor[BUS]); - current[BUS] = getCurrent_mA(sensor[BUS]) * 4; - power[BUS] = getPower_mW(sensor[BUS]) *2; + current[BUS] = getCurrent_mA(sensor[BUS]); // * 4; + power[BUS] = getPower_mW(sensor[BUS]); // *2; } else { From a59e0c30882bde8855351f0eacd5d7925b966dab Mon Sep 17 00:00:00 2001 From: jmclemo6 Date: Fri, 12 Jul 2019 02:11:42 -0400 Subject: [PATCH 033/194] Add function and struct to read sensor data. --- afsk/main.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/afsk/main.c b/afsk/main.c index c8ea7caf..d9c3ad4f 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -35,6 +35,7 @@ #include #include #include "ina219.h" +#include #define CALLSIGN "" // Put your callsign here! @@ -88,6 +89,42 @@ int x_calValue; int y_fd; // I2C bus 0 address 0x41 int z_fd; // I2C bos 0 address 0x44 +struct SensorData { + double power; + double current; +}; + +/** + * @brief Read the data from one of the i2c current sensors. + * + * Reads the current data from the requested i2c current sensor and + * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) + * results in a SensorData struct being returned that has both its #current and #power members + * set to NAN. + * + * WARNING: This function currently relies on the global variables x_calValue, config, x_currentDivider, and x_powerMultiplier. + * + * @param sensor A file descriptor that can be used to read from the sensor. + * @return struct SensorData A struct that contains the power and current reading from the requested sensor. + */ +struct SensorData read_sensor_data(int sensor) { + struct SensorData data = { + .power = NAN, + .current = NAN + }; + + if (sensor < 0) { + return data; + } + + wiringPiI2CWriteReg16(sensor, INA219_REG_CALIBRATION, x_calValue); + wiringPiI2CWriteReg16(sensor, INA219_REG_CONFIG, config); + wiringPiI2CWriteReg16(sensor, INA219_REG_CALIBRATION, x_calValue); + data.current = wiringPiI2CReadReg16(sensor, INA219_REG_CURRENT) / x_currentDivider; + data.power = wiringPiI2CReadReg16(sensor, INA219_REG_POWER) * x_powerMultiplier; + + return data; +} int main(void) { From 73675b2f9f0322dec2aca9410d6b818b69a7cafb Mon Sep 17 00:00:00 2001 From: jmclemo6 Date: Fri, 12 Jul 2019 02:15:59 -0400 Subject: [PATCH 034/194] Change i2c sensor reading code to use the read_sensor_data function --- afsk/main.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index d9c3ad4f..79323b2c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -391,37 +391,22 @@ int get_tlm(int tlm[][5]) { } */ // read i2c current sensors // - double current = 0, power = 0, y_current = 0, y_power = 0, z_current = 0, z_power = 0; - if (x_fd != -1) { - wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); - wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config); - wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); - current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; - power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; - wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); - wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, config); - wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); - y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; - y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; - wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue); - wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, config); - wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue); - z_current = wiringPiI2CReadReg16(z_fd, INA219_REG_CURRENT) / x_currentDivider; - z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; - } + struct SensorData x_data = read_sensor_data(x_fd); + struct SensorData y_data = read_sensor_data(y_fd); + struct SensorData z_data = read_sensor_data(z_fd); printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n", - current, power, y_current, y_power, z_current, z_power); + x_data.current, x_data.power, y_data.current, y_data.power, z_data.current, z_data.power); // printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL)); tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENT], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENT], NULL)/10) % 100; // +X current [4] - tlm[1][C] = (int) (99.5 - current/10) % 100; // X- current [10] + tlm[1][C] = (int) (99.5 - x_data.current/10) % 100; // X- current [10] tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENT], NULL)/10) % 100; // +Y current [7] - tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10] + tlm[2][A] = (int) (99.5 - y_data.current/10) % 100; // -Y current [10] tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENT], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][C] = (int) (99.5 - z_current/10) % 100; // -Z current (was timestamp) + tlm[2][C] = (int) (99.5 - z_data.current/10) % 100; // -Z current (was timestamp) // tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100; tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENT], NULL)/10.0) % 100; // NiMH Battery current From 2bfa17abfd5031d66c4dd28ed7ed8e4b0e9f9b36 Mon Sep 17 00:00:00 2001 From: Jacob McLemore Date: Tue, 16 Jul 2019 13:40:07 +0100 Subject: [PATCH 035/194] Fix indentation in read_sensor_data --- afsk/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 79323b2c..58f90813 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -117,11 +117,11 @@ struct SensorData read_sensor_data(int sensor) { return data; } - wiringPiI2CWriteReg16(sensor, INA219_REG_CALIBRATION, x_calValue); - wiringPiI2CWriteReg16(sensor, INA219_REG_CONFIG, config); - wiringPiI2CWriteReg16(sensor, INA219_REG_CALIBRATION, x_calValue); - data.current = wiringPiI2CReadReg16(sensor, INA219_REG_CURRENT) / x_currentDivider; - data.power = wiringPiI2CReadReg16(sensor, INA219_REG_POWER) * x_powerMultiplier; + wiringPiI2CWriteReg16(sensor, INA219_REG_CALIBRATION, x_calValue); + wiringPiI2CWriteReg16(sensor, INA219_REG_CONFIG, config); + wiringPiI2CWriteReg16(sensor, INA219_REG_CALIBRATION, x_calValue); + data.current = wiringPiI2CReadReg16(sensor, INA219_REG_CURRENT) / x_currentDivider; + data.power = wiringPiI2CReadReg16(sensor, INA219_REG_POWER) * x_powerMultiplier; return data; } From bd5b35c7849b30d38760c13486f91a9d7c891ea1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 10:42:26 -0400 Subject: [PATCH 036/194] renamed config to x_config --- afsk/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 2760c35b..f5a52c42 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -93,7 +93,7 @@ int upper_digit(int number); int lower_digit(int number); int charging = 0; -uint16_t config = (0x2000 | 0x1800 | 0x0180 | 0x0018 | 0x0007 ); +uint16_t x_config = (0x2000 | 0x1800 | 0x0180 | 0x0018 | 0x0007 ); int x_fd; // I2C bus 0 address 0x40 int x_powerMultiplier; @@ -151,7 +151,7 @@ int main(int argc, char *argv[]) { x_calValue = 4096; //8192; x_powerMultiplier = 2; x_currentDivider = 10; - config = INA219_CONFIG_BVOLTAGERANGE_32V | + x_config = INA219_CONFIG_BVOLTAGERANGE_32V | INA219_CONFIG_GAIN_320MV | // 40MV | INA219_CONFIG_BADCRES_12BIT | // INA219_CONFIG_SADCRES_12BIT_4S_2130US | @@ -213,7 +213,7 @@ int main(int argc, char *argv[]) { x_calValue = 8192; x_powerMultiplier = 1; x_currentDivider = 20; - config = INA219_CONFIG_BVOLTAGERANGE_16V | + x_config = INA219_CONFIG_BVOLTAGERANGE_16V | INA219_CONFIG_GAIN_40MV | INA219_CONFIG_BADCRES_12BIT | INA219_CONFIG_SADCRES_12BIT_4S_2130US | @@ -415,7 +415,7 @@ int get_tlm(int tlm[][5]) { double x_current = 0, voltage = 0, x_power = 0, y_current = 0, y_voltage, y_power = 0, z_current = 0, z_voltage = 0, z_power = 0; if (x_fd != -1) { // wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); -// wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config); +// wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, x_config); setCalibration_16V_400mA(x_fd); @@ -491,12 +491,12 @@ int get_tlm(int tlm[][5]) { x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); - wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, config); + wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue); - wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, config); + wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue); z_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; z_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; From ff183d7378a5a95ab99e11c5f89b145a52229205 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 10:43:43 -0400 Subject: [PATCH 037/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index f5a52c42..8c0363c0 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -213,7 +213,7 @@ int main(int argc, char *argv[]) { x_calValue = 8192; x_powerMultiplier = 1; x_currentDivider = 20; - x_config = INA219_CONFIG_BVOLTAGERANGE_16V | + config = INA219_CONFIG_BVOLTAGERANGE_16V | INA219_CONFIG_GAIN_40MV | INA219_CONFIG_BADCRES_12BIT | INA219_CONFIG_SADCRES_12BIT_4S_2130US | From 4f031fa8132cd2832adb0469ecc2d7f15c115ea7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 10:45:37 -0400 Subject: [PATCH 038/194] commented out extra curly bracket --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 8c0363c0..6ae03fdb 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -205,7 +205,7 @@ int main(int argc, char *argv[]) { sensor[MINUS_Y] = OFF; sensor[MINUS_Z] = OFF; } - } +// } Extra close bracket?? } // new INA219 current reading code From 9b31ba1370a1c32c82e3a8f060fc2bc2c549342a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 10:48:42 -0400 Subject: [PATCH 039/194] commented out arduinoI2C --- afsk/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 6ae03fdb..c47fa0d3 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -213,7 +213,7 @@ int main(int argc, char *argv[]) { x_calValue = 8192; x_powerMultiplier = 1; x_currentDivider = 20; - config = INA219_CONFIG_BVOLTAGERANGE_16V | + x_config = INA219_CONFIG_BVOLTAGERANGE_16V | INA219_CONFIG_GAIN_40MV | INA219_CONFIG_BADCRES_12BIT | INA219_CONFIG_SADCRES_12BIT_4S_2130US | @@ -291,8 +291,8 @@ int main(int argc, char *argv[]) { printf("%s",tlm_str); strcat(str, tlm_str); } - - if (arduinoI2C > 0) { /* Read Arduino payload */ +/* + if (arduinoI2C > 0) { // Read Arduino payload for(int reg = 0; reg < 4; reg++) { sprintf(tlm_str, " %04x",wiringPiI2CReadReg16(arduinoI2C,reg)); #ifdef DEBUG_LOGGING @@ -303,6 +303,7 @@ int main(int argc, char *argv[]) { usleep(100000); } } +*/ printf("\n"); digitalWrite (0, LOW); From ea059afeb64668907fda2eb3f455537d54ef439c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 10:49:36 -0400 Subject: [PATCH 040/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index c47fa0d3..626ad2f7 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -298,7 +298,7 @@ int main(int argc, char *argv[]) { #ifdef DEBUG_LOGGING printf("%s \n",tlm_str); #endif - strcat(str,tlm_str); /* Append payload telemetry */ + strcat(str,tlm_str); // Append payload telemetry printf("%s",tlm_str); usleep(100000); } From c979313e9fd17c0469b4e65c97c6f20be91d7765 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 11:10:28 -0400 Subject: [PATCH 041/194] Compiling now, no -x, -y, or -z current; removed CALLSIGN --- afsk/main.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 626ad2f7..d6d0b0d8 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -33,7 +33,6 @@ #include #include "ina219.h" -#define CALLSIGN "" // Put your callsign here! #define VBATT 15 #define ADC5 17 #define ADC6 18 @@ -247,9 +246,6 @@ int main(int argc, char *argv[]) { init_rf(); -// ax25_init(&hax25, (uint8_t *) "CubeSatSim", '2', (uint8_t *) CALLSIGN, '2', -// ax25_init(&hax25, (uint8_t *) "CQ", '1', (uint8_t *) CALLSIGN, '1', - ax25_init(&hax25, (uint8_t *) dest_addr, '1', (uint8_t *) src_addr, '1', AX25_PREAMBLE_LEN, AX25_POSTAMBLE_LEN); From f7aa30efee5944eb16f188c54702d6654025c3a4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 11:18:07 -0400 Subject: [PATCH 042/194] fixed x_fd, cleanup of rest --- afsk/main.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index d6d0b0d8..b2d9fabf 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -165,9 +165,7 @@ int main(int argc, char *argv[]) { z_fd = -1; } else { -// x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); - x_fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); - + x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); fprintf(stderr,"Opening of -X fd %d\n", x_fd); y_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); printf("Opening of -Y fd %d\n", y_fd); @@ -185,6 +183,7 @@ int main(int argc, char *argv[]) { sensor[BUS] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a); } else { + printf("ERROR: /dev/i2c-1 not present \n"); sensor[PLUS_X] = OFF; sensor[PLUS_Y] = OFF; sensor[PLUS_Z] = OFF; @@ -200,6 +199,7 @@ int main(int argc, char *argv[]) { } else { + printf("ERROR: /dev/i2c-0 not present \n"); sensor[MINUS_X] = OFF; sensor[MINUS_Y] = OFF; sensor[MINUS_Z] = OFF; @@ -208,7 +208,7 @@ int main(int argc, char *argv[]) { } // new INA219 current reading code - +/* x_calValue = 8192; x_powerMultiplier = 1; x_currentDivider = 20; @@ -238,11 +238,11 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Opening of -Z fd %d\n", z_fd); #endif } - +*/ int ret; uint8_t data[1024]; - tx_freq_hz -= tx_channel * 50000 + 85000; // subtracting rx offset of 90kHz + tx_freq_hz -= tx_channel * 50000; init_rf(); @@ -275,10 +275,6 @@ int main(int argc, char *argv[]) { int channel; for (channel = 1; channel < 7; channel++) { - #ifdef DEBUG_LOGGING - printf("%d %d %d %d \n", tlm[channel][1], tlm[channel][2], tlm[channel][3], tlm[channel][4]); - #endif - sprintf(tlm_str, "%d%d%d %d%d%d %d%d%d %d%d%d ", channel, upper_digit(tlm[channel][1]), lower_digit(tlm[channel][1]), channel, upper_digit(tlm[channel][2]), lower_digit(tlm[channel][2]), From 1fd7a2f0dea27b56f87750a52554e018dd7d4017 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 11:27:44 -0400 Subject: [PATCH 043/194] Update main.c --- afsk/main.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index b2d9fabf..5fac9e6b 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -412,9 +412,9 @@ int get_tlm(int tlm[][5]) { setCalibration_16V_400mA(x_fd); -// int blink; -// for (blink = 1; blink < 20 ;blink++) { -/* delay(500); + int blink; + for (blink = 1; blink < 20 ;blink++) { + delay(500); int shuntVolts = wiringPiI2CReadReg16(x_fd, INA219_REG_SHUNTVOLTAGE); // * 0.01; delay(500); int busVolts = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE); // * 0.001; @@ -422,21 +422,24 @@ int get_tlm(int tlm[][5]) { double volts = busVolts * 0.001 + shuntVolts * 0.01; printf("********** -X 0x40 volts %4.2f busvoltage %d shutVoltage %d\n", volts, busVolts, shuntVolts); -*/ +/* float shuntVolts = getShuntVoltage_mV(x_fd); float busVolts = getBusVoltage_V(x_fd); x_current = getCurrent_mA(x_fd); x_power = getPower_mW(x_fd); voltage = shuntVolts + busVolts; +*/ #ifdef DEBUG_LOGGING - printf("-X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n", busVolts, shuntVolts, x_current, x_power); - #endif - } + printf("-X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n\n", busVolts, shuntVolts, x_current, x_power); + #endif + } + } int count; for (count = 0; count < 7; count++) { if (sensor[count] != OFF) { + printf("Reading of sensnsor[%d]\n", count); setCalibration_16V_400mA(sensor[count]); voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; voltsBus[count] = getBusVoltage_V(sensor[count]); @@ -457,6 +460,7 @@ int get_tlm(int tlm[][5]) { } if (sensor[BUS] != OFF) // For MoPower V2 INA219 { + printf("Reading of sensnsor[%d] \n", BUS); setCalibration_16V_2A(sensor[BUS]); voltsShunt[BUS] = getShuntVoltage_mV(sensor[BUS])/1000; voltsBus[BUS] = getBusVoltage_V(sensor[BUS]); From 28353dd3deee66d0dde30750a598fcfe9ee9b4ee Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 11:33:38 -0400 Subject: [PATCH 044/194] switched x_fd to wireReadRegister --- afsk/main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 5fac9e6b..e41d3535 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -407,17 +407,18 @@ int get_tlm(int tlm[][5]) { // read i2c current sensors // double x_current = 0, voltage = 0, x_power = 0, y_current = 0, y_voltage, y_power = 0, z_current = 0, z_voltage = 0, z_power = 0; if (x_fd != -1) { -// wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); -// wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, x_config); + wireWriteRegister(x_fd, INA219_REG_CALIBRATION, x_calValue); + wireWriteRegister(x_fd, INA219_REG_CONFIG, x_config); setCalibration_16V_400mA(x_fd); int blink; - for (blink = 1; blink < 20 ;blink++) { + for (blink = 1; blink < 4 ;blink++) { delay(500); - int shuntVolts = wiringPiI2CReadReg16(x_fd, INA219_REG_SHUNTVOLTAGE); // * 0.01; + int shuntVolts = wireReadRegister(x_fd, INA219_REG_SHUNTVOLTAGE); // * 0.01; + delay(500); - int busVolts = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE); // * 0.001; + int busVolts = wireReadRegister(x_fd, INA219_REG_BUSVOLTAGE); // * 0.001; busVolts = (int16_t)((busVolts >> 3) * 4); double volts = busVolts * 0.001 + shuntVolts * 0.01; From 397ba72eaf0bcf61723f7f3f84ff0b3cb0888163 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 11:39:47 -0400 Subject: [PATCH 045/194] cleanup of x_fd printfs --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index e41d3535..44494e6f 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -422,7 +422,7 @@ int get_tlm(int tlm[][5]) { busVolts = (int16_t)((busVolts >> 3) * 4); double volts = busVolts * 0.001 + shuntVolts * 0.01; - printf("********** -X 0x40 volts %4.2f busvoltage %d shutVoltage %d\n", volts, busVolts, shuntVolts); +// printf("********** -X 0x40 volts %4.2f busvoltage %d shutVoltage %d\n", volts, busVolts, shuntVolts); /* float shuntVolts = getShuntVoltage_mV(x_fd); float busVolts = getBusVoltage_V(x_fd); @@ -431,7 +431,7 @@ int get_tlm(int tlm[][5]) { voltage = shuntVolts + busVolts; */ #ifdef DEBUG_LOGGING - printf("-X 0x40 busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n\n", busVolts, shuntVolts, x_current, x_power); + printf("-X 0x40 volts %4.2f busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n\n", volts, busVolts, shuntVolts, x_current, x_power); #endif } } From 6c495cd29c6be3010c379e8f8f9a811a718e093c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 12:19:16 -0400 Subject: [PATCH 046/194] added #include "Adafruit_INA219/Adafruit_INA219.h" --- afsk/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/afsk/main.c b/afsk/main.c index 44494e6f..597d0c29 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -32,6 +32,7 @@ #include #include #include "ina219.h" +#include "Adafruit_INA219/Adafruit_INA219.h" #define VBATT 15 #define ADC5 17 From 4a9c9f97c79f40b3e054ef74bc1b8b976576edb6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 12:21:14 -0400 Subject: [PATCH 047/194] fixed location of Adafruit_INA219.h --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 597d0c29..d3eceb2d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -32,7 +32,7 @@ #include #include #include "ina219.h" -#include "Adafruit_INA219/Adafruit_INA219.h" +#include "../Adafruit_INA219/Adafruit_INA219.h" #define VBATT 15 #define ADC5 17 From 9fc67b8e39b4a69cc03e882b132d78618f2a09dc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 12:25:06 -0400 Subject: [PATCH 048/194] removed ina219.h since replaced by Adafruit --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index d3eceb2d..f290745d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -31,7 +31,7 @@ #include #include #include -#include "ina219.h" +//#include "ina219.h" #include "../Adafruit_INA219/Adafruit_INA219.h" #define VBATT 15 From 9877a9caf154b765e88dbb14140567149931c3dd Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 12:30:49 -0400 Subject: [PATCH 049/194] replaced INA219_CONFIG_GAIN_8_320MV --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index f290745d..459f89d0 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -152,7 +152,7 @@ int main(int argc, char *argv[]) { x_powerMultiplier = 2; x_currentDivider = 10; x_config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_320MV | // 40MV | + INA219_CONFIG_GAIN_8_320MV | // 40MV | INA219_CONFIG_BADCRES_12BIT | // INA219_CONFIG_SADCRES_12BIT_4S_2130US | INA219_CONFIG_SADCRES_12BIT_1S_532US | From 58419e72a4311d088f0f54a95c00b7c50911b08d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 13:08:12 -0400 Subject: [PATCH 050/194] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 459f89d0..25b55b7f 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -98,7 +98,7 @@ uint16_t x_config = (0x2000 | 0x1800 | 0x0180 | 0x0018 | 0x0007 ); int x_fd; // I2C bus 0 address 0x40 int x_powerMultiplier; int x_currentDivider; -int x_calValue; +uint16_t x_calValue; int y_fd; // I2C bus 0 address 0x41 int z_fd; // I2C bos 0 address 0x44 int sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 @@ -432,7 +432,7 @@ int get_tlm(int tlm[][5]) { voltage = shuntVolts + busVolts; */ #ifdef DEBUG_LOGGING - printf("-X 0x40 volts %4.2f busVolts %4.2f shuntVolts %4.2f current %4.2f power %4.2f \n\n", volts, busVolts, shuntVolts, x_current, x_power); + printf("-X 0x40 volts %4.2f busVolts %d shuntVolts %d current %4.2f power %4.2f \n\n", volts, busVolts, shuntVolts); #endif } } From 8d5ecd3633c0c5f19df53dd45c294e8f56684ea1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 13:13:42 -0400 Subject: [PATCH 051/194] fixed debug loging warning --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 25b55b7f..d5b1d2f2 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -432,7 +432,7 @@ int get_tlm(int tlm[][5]) { voltage = shuntVolts + busVolts; */ #ifdef DEBUG_LOGGING - printf("-X 0x40 volts %4.2f busVolts %d shuntVolts %d current %4.2f power %4.2f \n\n", volts, busVolts, shuntVolts); + printf("-X 0x40 volts %4.2f busVolts %d shuntVolts %d \n\n", volts, busVolts, shuntVolts); #endif } } From 58eadd263ee5069474dc08f2af73d6ba92d60bdb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Sun, 21 Jul 2019 13:48:04 -0400 Subject: [PATCH 052/194] changed printf for sensor data --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index d5b1d2f2..7a385d1a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -441,7 +441,7 @@ int get_tlm(int tlm[][5]) { { if (sensor[count] != OFF) { - printf("Reading of sensnsor[%d]\n", count); + printf("Read sensnsor[%d] ", count); setCalibration_16V_400mA(sensor[count]); voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; voltsBus[count] = getBusVoltage_V(sensor[count]); @@ -456,7 +456,7 @@ int get_tlm(int tlm[][5]) { power[count] = 0; } #ifdef DEBUG_LOGGING - printf(" sensor[%d] voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", + printf("voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", count, voltsBus[count], voltsShunt[count], current[count], power[count]); #endif } From ab7e10a6d637cf3bee6bae0093b52f19bcf6816a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 03:20:59 -0400 Subject: [PATCH 053/194] putting back master code for x_fd, y_fd, and z_fd --- afsk/main.c | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 7a385d1a..262dff0a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -406,36 +406,29 @@ int get_tlm(int tlm[][5]) { } // read i2c current sensors // - double x_current = 0, voltage = 0, x_power = 0, y_current = 0, y_voltage, y_power = 0, z_current = 0, z_voltage = 0, z_power = 0; +// code added back from master + double x_current = 0, power = 0, y_current = 0, y_power = 0, z_current = 0, z_power = 0; if (x_fd != -1) { - wireWriteRegister(x_fd, INA219_REG_CALIBRATION, x_calValue); - wireWriteRegister(x_fd, INA219_REG_CONFIG, x_config); - - setCalibration_16V_400mA(x_fd); - - int blink; - for (blink = 1; blink < 4 ;blink++) { - delay(500); - int shuntVolts = wireReadRegister(x_fd, INA219_REG_SHUNTVOLTAGE); // * 0.01; - - delay(500); - int busVolts = wireReadRegister(x_fd, INA219_REG_BUSVOLTAGE); // * 0.001; - busVolts = (int16_t)((busVolts >> 3) * 4); - double volts = busVolts * 0.001 + shuntVolts * 0.01; - -// printf("********** -X 0x40 volts %4.2f busvoltage %d shutVoltage %d\n", volts, busVolts, shuntVolts); -/* - float shuntVolts = getShuntVoltage_mV(x_fd); - float busVolts = getBusVoltage_V(x_fd); - x_current = getCurrent_mA(x_fd); - x_power = getPower_mW(x_fd); - voltage = shuntVolts + busVolts; -*/ - #ifdef DEBUG_LOGGING - printf("-X 0x40 volts %4.2f busVolts %d shuntVolts %d \n\n", volts, busVolts, shuntVolts); - #endif - } - } + wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); + wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config); + wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); + x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; + power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; + wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); + wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, config); + wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); + y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; + y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; + wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); + wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, config); + wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); + z_current = wiringPiI2CReadReg16(z_fd, INA219_REG_CURRENT) / x_currentDivider; + z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; + } + printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n", + x_current, power, y_current, y_power, z_current, z_power); +// end of master code + int count; for (count = 0; count < 7; count++) { From 6b73a5a8eeea4913cf92f3bc2af4bc21e4fd8c4a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 03:30:20 -0400 Subject: [PATCH 054/194] x_calValue cleanup with code from master --- afsk/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 262dff0a..ee6e846b 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -98,7 +98,7 @@ uint16_t x_config = (0x2000 | 0x1800 | 0x0180 | 0x0018 | 0x0007 ); int x_fd; // I2C bus 0 address 0x40 int x_powerMultiplier; int x_currentDivider; -uint16_t x_calValue; +int x_calValue_x; int y_fd; // I2C bus 0 address 0x41 int z_fd; // I2C bos 0 address 0x44 int sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 @@ -148,11 +148,11 @@ int main(int argc, char *argv[]) { fprintf(stderr,"tempSensor: %d \n",tempSensor); #endif - x_calValue = 4096; //8192; - x_powerMultiplier = 2; - x_currentDivider = 10; + x_calValue_x = 8192; + x_powerMultiplier = 1; + x_currentDivider = 20; x_config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_8_320MV | // 40MV | + INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | // INA219_CONFIG_SADCRES_12BIT_4S_2130US | INA219_CONFIG_SADCRES_12BIT_1S_532US | From e87ea997f0011d13f2862299a12e413e795e33d9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 03:33:49 -0400 Subject: [PATCH 055/194] fixed config and x_power from master --- afsk/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index ee6e846b..674857db 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -407,26 +407,26 @@ int get_tlm(int tlm[][5]) { // read i2c current sensors // // code added back from master - double x_current = 0, power = 0, y_current = 0, y_power = 0, z_current = 0, z_power = 0; + double x_current = 0, x_power = 0, y_current = 0, y_power = 0, z_current = 0, z_power = 0; if (x_fd != -1) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); - wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, config); + wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; - power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; + x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); - wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, config); + wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); - wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, config); + wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); z_current = wiringPiI2CReadReg16(z_fd, INA219_REG_CURRENT) / x_currentDivider; z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; } printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n", - x_current, power, y_current, y_power, z_current, z_power); + x_current, x_power, y_current, y_power, z_current, z_power); // end of master code int count; From 4babd587122188118f112f1e0f877615593ce7de Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 03:35:28 -0400 Subject: [PATCH 056/194] fixed printf --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 674857db..613d099b 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -450,7 +450,7 @@ int get_tlm(int tlm[][5]) { } #ifdef DEBUG_LOGGING printf("voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", - count, voltsBus[count], voltsShunt[count], current[count], power[count]); + voltsBus[count], voltsShunt[count], current[count], power[count]); #endif } if (sensor[BUS] != OFF) // For MoPower V2 INA219 From 235fd7d6dd244d6df3ffa9ea799b5c3226f6a706 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 03:37:01 -0400 Subject: [PATCH 057/194] removed debug ina219[] printf --- afsk/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 613d099b..fa350e56 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -398,9 +398,9 @@ int get_tlm(int tlm[][5]) { while (data2 != NULL) { strcpy(ina219[i], data2); - #ifdef DEBUG_LOGGING - printf ("ina219[%d]=%s\n",i,ina219[i]); - #endif +// #ifdef DEBUG_LOGGING +// printf ("ina219[%d]=%s\n",i,ina219[i]); +// #endif data2 = strtok (NULL, " "); i++; } From 1addf19abc7706c567a94439458cb75c285afaed Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 03:58:36 -0400 Subject: [PATCH 058/194] changed to all I2C telemetry --- afsk/main.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index fa350e56..ba3c8d3b 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -498,20 +498,27 @@ int get_tlm(int tlm[][5]) { */ // printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL)); - tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENTV], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENTV], NULL)/10) % 100; // +X current [4] +// tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENTV], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi + tlm[1][A] = (int)(voltsBus[BUS] / 15 + 0.5) % 100; // Current of 5V supply to Pi +// tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENTV], NULL)/10) % 100; // +X current [4] + tlm[1][B] = (int) (99.5 - current[PLUS_X]/10) % 100; // +X current [4] tlm[1][C] = (int) (99.5 - x_current/10) % 100; // X- current [10] - tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENTV], NULL)/10) % 100; // +Y current [7] +// tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENTV], NULL)/10) % 100; // +Y current [7] + tlm[1][D] = (int) (99.5 - current[PLUS_Y]/10) % 100; // +Y current [7] tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10] - tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENTV], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel +// tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENTV], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel + tlm[2][B] = (int) (99.5 - current[PLUS_Z]/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel tlm[2][C] = (int) (99.5 - z_current/10) % 100; // -Z current (was timestamp) // tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100; - tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENTV], NULL)/10.0) % 100; // NiMH Battery current +// tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENTV], NULL)/10.0) % 100; // NiMH Battery current + tlm[2][D] = (int)(50.5 + current[BAT]/10.0) % 100; // NiMH Battery current - tlm[3][A] = abs((int)((strtof(ina219[SENSOR_45 + VOLTAGE], NULL) * 10) - 65.5) % 100); - tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0) % 100; // 5V supply to Pi +// tlm[3][A] = abs((int)((strtof(ina219[SENSOR_45 + VOLTAGE], NULL) * 10) - 65.5) % 100); + tlm[3][A] = abs((int)((voltsBus[BAT] * 10) - 65.5) % 100); +// tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0) % 100; // 5V supply to Pi + tlm[3][B] = (int)(voltsBus[BUS] * 10.0) % 100; // 5V supply to Pi if (tempSensor != -1) { int tempValue = wiringPiI2CReadReg16(tempSensor, 0); From dc17fd64ed47309870a6c62ecc27b665e6d16a2a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 07:51:23 -0400 Subject: [PATCH 059/194] Added debug flag to Adafruit_INA219 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b8eb6573..a545bd17 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,7 @@ radioafsk: Adafruit_INA219/Adafruit_INA219.h Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.c Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.h - cd Adafruit_INA219; gcc -I -pedantic -Wconversion -Wall -Wextra -c Adafruit_INA219.c; cd .. + cd Adafruit_INA219; gcc $(DEBUG_BEHAVIOR) -I -pedantic -Wconversion -Wall -Wextra -c Adafruit_INA219.c; cd .. ax5043/generated/configcommon.o: ax5043/generated/configcommon.c ax5043/generated/configcommon.o: ax5043/generated/configrx.h From 17d99e839ba19f5a0f87a69ce9079bb964e77a83 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:14:25 -0400 Subject: [PATCH 060/194] added x_voltage, y_voltage, and z_voltage readings --- afsk/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index ba3c8d3b..85bfdaff 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -407,26 +407,30 @@ int get_tlm(int tlm[][5]) { // read i2c current sensors // // code added back from master - double x_current = 0, x_power = 0, y_current = 0, y_power = 0, z_current = 0, z_power = 0; + double x_current = 0, x_voltage = 0, x_power = 0, y_current = 0, y_voltage = 0, y_power = 0, + z_current = 0, z_voltage = 0, z_power = 0; if (x_fd != -1) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; + x_voltage = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE) / 1000; x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; + y_voltage = wiringPiI2CReadReg16(y_fd, INA219_REG_BUSVOLTAGE) / 1000; y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); z_current = wiringPiI2CReadReg16(z_fd, INA219_REG_CURRENT) / x_currentDivider; + z_voltage = wiringPiI2CReadReg16(z_fd, INA219_REG_BUSVOLTAGE) / 1000; z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; - } - printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n", - x_current, x_power, y_current, y_power, z_current, z_power); + } + printf("-X %4.2f V %4.2f mA power %4.2f mW -Y %4.2f V %4.2f mA %4.2f mW -Z %4.2f V %4.2f mA %4.2f mW \n", + x_voltage, x_current, x_power, y_voltage, y_current, y_power, z_voltage, z_current, z_power); // end of master code int count; From e46e82f18aac80ee03bf418ffb8f02855c5aba2d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:19:44 -0400 Subject: [PATCH 061/194] cleanup of V, mA, and mW printfs --- afsk/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 85bfdaff..7963a2c5 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -429,7 +429,7 @@ int get_tlm(int tlm[][5]) { z_voltage = wiringPiI2CReadReg16(z_fd, INA219_REG_BUSVOLTAGE) / 1000; z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; } - printf("-X %4.2f V %4.2f mA power %4.2f mW -Y %4.2f V %4.2f mA %4.2f mW -Z %4.2f V %4.2f mA %4.2f mW \n", + printf("-X %4.2f V %4.2fmA %4.2fmW -Y %4.2fV %4.2fmA %4.2fmW -Z %4.2fV %4.2fmA %4.2fmW \n", x_voltage, x_current, x_power, y_voltage, y_current, y_power, z_voltage, z_current, z_power); // end of master code @@ -453,7 +453,7 @@ int get_tlm(int tlm[][5]) { power[count] = 0; } #ifdef DEBUG_LOGGING - printf("voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", + printf("%4.2fV %4.2fV %4.2fmA %4.2fmW \n", voltsBus[count], voltsShunt[count], current[count], power[count]); #endif } @@ -474,8 +474,8 @@ int get_tlm(int tlm[][5]) { power[BUS] = 0; } #ifdef DEBUG_LOGGING - printf(" sensor[%d] voltsBus %4.2f voltsShunt %4.2f current %4.2f power %4.2f \n", - count, voltsBus[BUS], voltsShunt[BUS], current[BUS], power[BUS]); + printf("%4.2fV %4.2fmA %4.2fmW \n", + voltsBus[BUS], voltsShunt[BUS], current[BUS], power[BUS]); #endif From b9b8d7e826ae7372dce68fc9006469dd5addf889 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:20:54 -0400 Subject: [PATCH 062/194] fixed V printf --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 7963a2c5..9188ab5a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -474,7 +474,7 @@ int get_tlm(int tlm[][5]) { power[BUS] = 0; } #ifdef DEBUG_LOGGING - printf("%4.2fV %4.2fmA %4.2fmW \n", + printf("%4.2fV %4.2fV %4.2fmA %4.2fmW \n", voltsBus[BUS], voltsShunt[BUS], current[BUS], power[BUS]); #endif From eddd071771a444771ce653f1f368b1ba6adeec1a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:25:18 -0400 Subject: [PATCH 063/194] changed temp printf --- afsk/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 9188ab5a..67d523a0 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -526,14 +526,15 @@ int get_tlm(int tlm[][5]) { if (tempSensor != -1) { int tempValue = wiringPiI2CReadReg16(tempSensor, 0); - #ifdef DEBUG_LOGGING - printf("Temp Sensor Read: %x\n", tempValue); - #endif uint8_t upper = (uint8_t) (tempValue >> 8); uint8_t lower = (uint8_t) (tempValue & 0xff); float temp = (float)lower + ((float)upper / 0x100); - + + #ifdef DEBUG_LOGGING + printf("Temp Sensor Read: %6.1f\n", temp); + #endif + tlm[4][A] = (int)((95.8 - temp)/1.48 + 0.5) % 100; } From 09bc98a60a66e391fd1873efbcc91c67ed12c996 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:27:18 -0400 Subject: [PATCH 064/194] got rid of "sensnsor" --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 67d523a0..50fdbbda 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -438,7 +438,7 @@ int get_tlm(int tlm[][5]) { { if (sensor[count] != OFF) { - printf("Read sensnsor[%d] ", count); + printf("Read sensor[%d] ", count); setCalibration_16V_400mA(sensor[count]); voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; voltsBus[count] = getBusVoltage_V(sensor[count]); @@ -459,7 +459,7 @@ int get_tlm(int tlm[][5]) { } if (sensor[BUS] != OFF) // For MoPower V2 INA219 { - printf("Reading of sensnsor[%d] \n", BUS); + printf("Reading of sensor[%d] ", BUS); setCalibration_16V_2A(sensor[BUS]); voltsShunt[BUS] = getShuntVoltage_mV(sensor[BUS])/1000; voltsBus[BUS] = getBusVoltage_V(sensor[BUS]); From 03261b9cfe4f2dfd15c5aca87ff4d0b1a872d7da Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:30:15 -0400 Subject: [PATCH 065/194] added missing #ifdef DEBUG_LOGGING around printfs --- afsk/main.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 50fdbbda..d9ad66a9 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -428,9 +428,12 @@ int get_tlm(int tlm[][5]) { z_current = wiringPiI2CReadReg16(z_fd, INA219_REG_CURRENT) / x_currentDivider; z_voltage = wiringPiI2CReadReg16(z_fd, INA219_REG_BUSVOLTAGE) / 1000; z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; - } - printf("-X %4.2f V %4.2fmA %4.2fmW -Y %4.2fV %4.2fmA %4.2fmW -Z %4.2fV %4.2fmA %4.2fmW \n", + } + #ifdef DEBUG_LOGGING + printf("-X %4.2f V %4.2fmA %4.2fmW -Y %4.2fV %4.2fmA %4.2fmW -Z %4.2fV %4.2fmA %4.2fmW \n", x_voltage, x_current, x_power, y_voltage, y_current, y_power, z_voltage, z_current, z_power); + #endif + // end of master code int count; @@ -438,7 +441,9 @@ int get_tlm(int tlm[][5]) { { if (sensor[count] != OFF) { - printf("Read sensor[%d] ", count); + #ifdef DEBUG_LOGGING + printf("Read sensor[%d] ", count); + #endif setCalibration_16V_400mA(sensor[count]); voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; voltsBus[count] = getBusVoltage_V(sensor[count]); @@ -459,7 +464,9 @@ int get_tlm(int tlm[][5]) { } if (sensor[BUS] != OFF) // For MoPower V2 INA219 { - printf("Reading of sensor[%d] ", BUS); + #ifdef DEBUG_LOGGING + printf("Read sensor[%d] ", BUS); + #endif setCalibration_16V_2A(sensor[BUS]); voltsShunt[BUS] = getShuntVoltage_mV(sensor[BUS])/1000; voltsBus[BUS] = getBusVoltage_V(sensor[BUS]); From 52a9087bf04a2ab7bca390acd6b14774dbfa6151 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:35:53 -0400 Subject: [PATCH 066/194] reconfigures power and voltage to eliminate no debug compiler warnings --- afsk/main.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index d9ad66a9..9210c968 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -407,28 +407,36 @@ int get_tlm(int tlm[][5]) { // read i2c current sensors // // code added back from master - double x_current = 0, x_voltage = 0, x_power = 0, y_current = 0, y_voltage = 0, y_power = 0, - z_current = 0, z_voltage = 0, z_power = 0; + double x_current, y_current, z_current; if (x_fd != -1) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; - x_voltage = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE) / 1000; - x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; + #ifdef DEBUG_LOGGING + double x_voltage, x_power; + x_voltage = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE) / 1000; + x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; + #endif wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; - y_voltage = wiringPiI2CReadReg16(y_fd, INA219_REG_BUSVOLTAGE) / 1000; - y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; + #ifdef DEBUG_LOGGING + double y_voltage, y_power; + y_voltage = wiringPiI2CReadReg16(y_fd, INA219_REG_BUSVOLTAGE) / 1000; + y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; + #endif wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); z_current = wiringPiI2CReadReg16(z_fd, INA219_REG_CURRENT) / x_currentDivider; - z_voltage = wiringPiI2CReadReg16(z_fd, INA219_REG_BUSVOLTAGE) / 1000; - z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; - } + #ifdef DEBUG_LOGGING + double z_voltage, z_power; + z_voltage = wiringPiI2CReadReg16(z_fd, INA219_REG_BUSVOLTAGE) / 1000; + z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; + #endif + } #ifdef DEBUG_LOGGING printf("-X %4.2f V %4.2fmA %4.2fmW -Y %4.2fV %4.2fmA %4.2fmW -Z %4.2fV %4.2fmA %4.2fmW \n", x_voltage, x_current, x_power, y_voltage, y_current, y_power, z_voltage, z_current, z_power); From accfbe77475940ba4c41a3e947a41248a442a14e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:40:48 -0400 Subject: [PATCH 067/194] fixed #DEBUG LOGGING of x_fd, y_fd, and z_fd --- afsk/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 9210c968..2b37ccb5 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -167,11 +167,11 @@ int main(int argc, char *argv[]) { } else { x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); - fprintf(stderr,"Opening of -X fd %d\n", x_fd); y_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); - printf("Opening of -Y fd %d\n", y_fd); - z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); - printf("Opening of -Z fd %d\n", z_fd); + z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); + #ifdef DEBUG_LOGGING + fprintf(stderr, "Opening of -X %d, -Y %d, -Z %d\n", x_fd, y_fd, z_fd); + #endif int test; if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present From 0427a73b1ebe53f4f19db545c7e6b287be0a7b59 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:43:58 -0400 Subject: [PATCH 068/194] commented out unneeded #defines --- afsk/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 2b37ccb5..d64cb0e9 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -33,7 +33,7 @@ #include //#include "ina219.h" #include "../Adafruit_INA219/Adafruit_INA219.h" - +/* #define VBATT 15 #define ADC5 17 #define ADC6 18 @@ -42,11 +42,12 @@ #define TIME 8 #define UCTEMP 30 #define UPTIME_SEC 8 +*/ #define A 1 #define B 2 #define C 3 #define D 4 - +/* #define SENSOR_40 0 #define SENSOR_41 3 #define SENSOR_44 6 @@ -55,6 +56,7 @@ #define VOLTAGE 0 #define CURRENTV 1 #define POWER 2 +*/ #define VBATT 15 #define PLUS_X 0 #define PLUS_Y 1 From eb6cff57d8de67b146f90c9b124ae10c8d9f0d0a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:46:41 -0400 Subject: [PATCH 069/194] fixed x_voltage, x_power definitions --- afsk/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index d64cb0e9..c67755fb 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -410,13 +410,15 @@ int get_tlm(int tlm[][5]) { // read i2c current sensors // // code added back from master double x_current, y_current, z_current; + #ifdef DEBUG_LOGGING + double x_voltage, x_power, y_voltage, y_power, z_voltage, z_power; + #endif if (x_fd != -1) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; - #ifdef DEBUG_LOGGING - double x_voltage, x_power; + #ifdef DEBUG_LOGGING x_voltage = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE) / 1000; x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; #endif @@ -425,7 +427,6 @@ int get_tlm(int tlm[][5]) { wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; #ifdef DEBUG_LOGGING - double y_voltage, y_power; y_voltage = wiringPiI2CReadReg16(y_fd, INA219_REG_BUSVOLTAGE) / 1000; y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; #endif @@ -434,7 +435,6 @@ int get_tlm(int tlm[][5]) { wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); z_current = wiringPiI2CReadReg16(z_fd, INA219_REG_CURRENT) / x_currentDivider; #ifdef DEBUG_LOGGING - double z_voltage, z_power; z_voltage = wiringPiI2CReadReg16(z_fd, INA219_REG_BUSVOLTAGE) / 1000; z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; #endif From 57112c38b17934772bbdc64af3d446da441ffe57 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:48:11 -0400 Subject: [PATCH 070/194] Changed -1 to OFF --- afsk/main.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index c67755fb..58e4697a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -67,6 +67,7 @@ #define MINUS_Z 6 #define BUS 7 #define OFF -1 + uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; uint32_t tx_channel = 0; @@ -140,7 +141,7 @@ int main(int argc, char *argv[]) { if (file_i2c < 0) { fprintf(stderr,"ERROR: /dev/ic2-3 bus not present\n"); - tempSensor = -1; + tempSensor = OFF; } else { tempSensor = wiringPiI2CSetupInterface("/dev/i2c-3", 0x48); @@ -163,9 +164,9 @@ int main(int argc, char *argv[]) { if ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0) { fprintf(stderr,"ERROR: /dev/ic2-0 bus not present\n"); - x_fd = -1; - y_fd = -1; - z_fd = -1; + x_fd = OFF; + y_fd = OFF; + z_fd = OFF; } else { x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); @@ -413,7 +414,7 @@ int get_tlm(int tlm[][5]) { #ifdef DEBUG_LOGGING double x_voltage, x_power, y_voltage, y_power, z_voltage, z_power; #endif - if (x_fd != -1) { + if (x_fd != OFF) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, x_config); wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); @@ -541,7 +542,7 @@ int get_tlm(int tlm[][5]) { // tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0) % 100; // 5V supply to Pi tlm[3][B] = (int)(voltsBus[BUS] * 10.0) % 100; // 5V supply to Pi - if (tempSensor != -1) { + if (tempSensor != OFF) { int tempValue = wiringPiI2CReadReg16(tempSensor, 0); uint8_t upper = (uint8_t) (tempValue >> 8); From 29522b3220706c1221954115c77f772857d23112 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 08:51:09 -0400 Subject: [PATCH 071/194] changed to %+4.2f for sign alignment --- afsk/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 58e4697a..bac73628 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -441,7 +441,7 @@ int get_tlm(int tlm[][5]) { #endif } #ifdef DEBUG_LOGGING - printf("-X %4.2f V %4.2fmA %4.2fmW -Y %4.2fV %4.2fmA %4.2fmW -Z %4.2fV %4.2fmA %4.2fmW \n", + printf("-X %+4.2f V %+4.2fmA %+4.2fmW -Y %+4.2fV %+4.2fmA %+4.2fmW -Z %+4.2fV %+4.2fmA %+4.2fmW \n", x_voltage, x_current, x_power, y_voltage, y_current, y_power, z_voltage, z_current, z_power); #endif @@ -469,7 +469,7 @@ int get_tlm(int tlm[][5]) { power[count] = 0; } #ifdef DEBUG_LOGGING - printf("%4.2fV %4.2fV %4.2fmA %4.2fmW \n", + printf("%+4.2fV %+4.2fV %+4.2fmA %+4.2fmW \n", voltsBus[count], voltsShunt[count], current[count], power[count]); #endif } @@ -492,7 +492,7 @@ int get_tlm(int tlm[][5]) { power[BUS] = 0; } #ifdef DEBUG_LOGGING - printf("%4.2fV %4.2fV %4.2fmA %4.2fmW \n", + printf("%+4.2fV %+4.2fV %+4.2fmA %+4.2fmW \n", voltsBus[BUS], voltsShunt[BUS], current[BUS], power[BUS]); #endif From ee45b621755ed36addbd815ae6f14503f7c7baf3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 10:39:58 -0400 Subject: [PATCH 072/194] switched master code from 1 to 0 to test --- afsk/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index bac73628..ebc84d0f 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) { INA219_CONFIG_SADCRES_12BIT_1S_532US | INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - if ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0) + if ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0) { fprintf(stderr,"ERROR: /dev/ic2-0 bus not present\n"); x_fd = OFF; @@ -169,9 +169,9 @@ int main(int argc, char *argv[]) { z_fd = OFF; } else { - x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); - y_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); - z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); + x_fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); // switched to 1 from 0 + y_fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x41); // switched to 1 from 0 + z_fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x44); // switched to 1 from 0 #ifdef DEBUG_LOGGING fprintf(stderr, "Opening of -X %d, -Y %d, -Z %d\n", x_fd, y_fd, z_fd); #endif @@ -180,7 +180,7 @@ int main(int argc, char *argv[]) { if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present { close(test); - sensor[PLUS_X] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); + sensor[PLUS_X] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); sensor[PLUS_Y] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x41); sensor[PLUS_Z] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x44); sensor[BAT] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x45); From de2c89411d016bb25f215dc50538eb5756622583 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 10:52:34 -0400 Subject: [PATCH 073/194] turning off master code i2c-1 read as a test --- afsk/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index ebc84d0f..d24085ca 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) { INA219_CONFIG_SADCRES_12BIT_1S_532US | INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - if ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0) + if (1) // ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0) // turning off { fprintf(stderr,"ERROR: /dev/ic2-0 bus not present\n"); x_fd = OFF; @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) { #ifdef DEBUG_LOGGING fprintf(stderr, "Opening of -X %d, -Y %d, -Z %d\n", x_fd, y_fd, z_fd); #endif - + } // moved here int test; if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present { @@ -209,7 +209,7 @@ int main(int argc, char *argv[]) { sensor[MINUS_Z] = OFF; } // } Extra close bracket?? - } +// } // move up! // new INA219 current reading code /* From 6d2b7ae7983e758890995ddf3dbb9f497f079105 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 11:21:13 -0400 Subject: [PATCH 074/194] reverted bus switch, testing new busVolts calculation --- afsk/main.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index d24085ca..5234616f 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) { INA219_CONFIG_SADCRES_12BIT_1S_532US | INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - if (1) // ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0) // turning off + if ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0) { fprintf(stderr,"ERROR: /dev/ic2-0 bus not present\n"); x_fd = OFF; @@ -169,9 +169,9 @@ int main(int argc, char *argv[]) { z_fd = OFF; } else { - x_fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); // switched to 1 from 0 - y_fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x41); // switched to 1 from 0 - z_fd = wiringPiI2CSetupInterface("/dev/i2c-1", 0x44); // switched to 1 from 0 + x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); + y_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); + z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); #ifdef DEBUG_LOGGING fprintf(stderr, "Opening of -X %d, -Y %d, -Z %d\n", x_fd, y_fd, z_fd); #endif @@ -413,6 +413,7 @@ int get_tlm(int tlm[][5]) { double x_current, y_current, z_current; #ifdef DEBUG_LOGGING double x_voltage, x_power, y_voltage, y_power, z_voltage, z_power; + uint16_t value; #endif if (x_fd != OFF) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); @@ -420,7 +421,9 @@ int get_tlm(int tlm[][5]) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; #ifdef DEBUG_LOGGING - x_voltage = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE) / 1000; +// x_voltage = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE) / 1000; + value = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE); + x_voltage = ((double)(value >> 3) * 4) / 1000; x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; #endif wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); From b10a98064af7e043566a4851dad8288d943c14d5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 11:28:22 -0400 Subject: [PATCH 075/194] fixed value type --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 5234616f..93515782 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -413,7 +413,7 @@ int get_tlm(int tlm[][5]) { double x_current, y_current, z_current; #ifdef DEBUG_LOGGING double x_voltage, x_power, y_voltage, y_power, z_voltage, z_power; - uint16_t value; + int value; #endif if (x_fd != OFF) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); From 3998bc3165be699ea1bae3811b7ca226a9c02080 Mon Sep 17 00:00:00 2001 From: Alan Johnston Date: Mon, 22 Jul 2019 11:50:24 -0400 Subject: [PATCH 076/194] -X, -Y, and -Z voltage working! --- afsk/main.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 93515782..22adfd16 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -413,7 +413,7 @@ int get_tlm(int tlm[][5]) { double x_current, y_current, z_current; #ifdef DEBUG_LOGGING double x_voltage, x_power, y_voltage, y_power, z_voltage, z_power; - int value; + uint16_t value; #endif if (x_fd != OFF) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); @@ -422,7 +422,7 @@ int get_tlm(int tlm[][5]) { x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; #ifdef DEBUG_LOGGING // x_voltage = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE) / 1000; - value = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE); + value = (uint16_t)wireReadRegister(x_fd, INA219_REG_BUSVOLTAGE); x_voltage = ((double)(value >> 3) * 4) / 1000; x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; #endif @@ -431,7 +431,9 @@ int get_tlm(int tlm[][5]) { wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; #ifdef DEBUG_LOGGING - y_voltage = wiringPiI2CReadReg16(y_fd, INA219_REG_BUSVOLTAGE) / 1000; +// y_voltage = wiringPiI2CReadReg16(y_fd, INA219_REG_BUSVOLTAGE) / 1000; + value = (uint16_t)wireReadRegister(y_fd, INA219_REG_BUSVOLTAGE); + y_voltage = ((double)(value >> 3) * 4) / 1000; y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; #endif wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); @@ -439,7 +441,9 @@ int get_tlm(int tlm[][5]) { wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); z_current = wiringPiI2CReadReg16(z_fd, INA219_REG_CURRENT) / x_currentDivider; #ifdef DEBUG_LOGGING - z_voltage = wiringPiI2CReadReg16(z_fd, INA219_REG_BUSVOLTAGE) / 1000; +// z_voltage = wiringPiI2CReadReg16(z_fd, INA219_REG_BUSVOLTAGE) / 1000; + value = (uint16_t)wireReadRegister(z_fd, INA219_REG_BUSVOLTAGE); + z_voltage = ((double)(value >> 3) * 4) / 1000; z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; #endif } From 1171effa927ac3645363b6c7148f3f6f46268ebc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 13:36:09 -0400 Subject: [PATCH 077/194] disable old code to test new code --- afsk/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 22adfd16..4ee3bb9c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -415,6 +415,7 @@ int get_tlm(int tlm[][5]) { double x_voltage, x_power, y_voltage, y_power, z_voltage, z_power; uint16_t value; #endif +/* Disable old code if (x_fd != OFF) { wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, x_config); @@ -451,7 +452,7 @@ int get_tlm(int tlm[][5]) { printf("-X %+4.2f V %+4.2fmA %+4.2fmW -Y %+4.2fV %+4.2fmA %+4.2fmW -Z %+4.2fV %+4.2fmA %+4.2fmW \n", x_voltage, x_current, x_power, y_voltage, y_current, y_power, z_voltage, z_current, z_power); #endif - +*/ // end of master code int count; From f2260ebc63c2f3470f325ac82a1abd041f556c75 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 14:17:58 -0400 Subject: [PATCH 078/194] commented out last of x_fd, y_fd, and z_fd --- afsk/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 4ee3bb9c..7e20c097 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -150,7 +150,8 @@ int main(int argc, char *argv[]) { #ifdef DEBUG_LOGGING fprintf(stderr,"tempSensor: %d \n",tempSensor); #endif - + +/* start of old master code x_calValue_x = 8192; x_powerMultiplier = 1; x_currentDivider = 20; @@ -176,6 +177,7 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Opening of -X %d, -Y %d, -Z %d\n", x_fd, y_fd, z_fd); #endif } // moved here +end of old code */ int test; if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present { From e6fd3b3dca206bf61b84e563cb1f2384eef43d04 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 14:26:16 -0400 Subject: [PATCH 079/194] changed order of current and bus reading to match old code --- afsk/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 7e20c097..7ec2d60f 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -466,9 +466,9 @@ int get_tlm(int tlm[][5]) { printf("Read sensor[%d] ", count); #endif setCalibration_16V_400mA(sensor[count]); - voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; - voltsBus[count] = getBusVoltage_V(sensor[count]); current[count] = getCurrent_mA(sensor[count]); + voltsBus[count] = getBusVoltage_V(sensor[count]); + voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; power[count] = getPower_mW(sensor[count]); } else @@ -489,9 +489,9 @@ int get_tlm(int tlm[][5]) { printf("Read sensor[%d] ", BUS); #endif setCalibration_16V_2A(sensor[BUS]); - voltsShunt[BUS] = getShuntVoltage_mV(sensor[BUS])/1000; - voltsBus[BUS] = getBusVoltage_V(sensor[BUS]); current[BUS] = getCurrent_mA(sensor[BUS]); // * 4; + voltsBus[BUS] = getBusVoltage_V(sensor[BUS]); + voltsShunt[BUS] = getShuntVoltage_mV(sensor[BUS])/1000; power[BUS] = getPower_mW(sensor[BUS]); // *2; } else From 8db31fc5c3860fc8064ab363da2611cdf029a37a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Mon, 22 Jul 2019 14:32:23 -0400 Subject: [PATCH 080/194] commented out readcurrenty.py call --- afsk/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 7ec2d60f..3ca2df41 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -388,7 +388,8 @@ int upper_digit(int number) { } int get_tlm(int tlm[][5]) { - // Reading I2C voltage and current sensors + // Reading I2C voltage and current sensors +/* char cmdbuffer[1000]; FILE* file = popen("sudo python /home/pi/CubeSatSim/python/readcurrent.py 2>&1", "r"); fgets(cmdbuffer, 999, file); @@ -409,7 +410,8 @@ int get_tlm(int tlm[][5]) { data2 = strtok (NULL, " "); i++; } - +*/ + // read i2c current sensors // // code added back from master double x_current, y_current, z_current; From 61240b40ec7c42ef7fbe89cd1227f1fba0c2f738 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 01:04:45 -0400 Subject: [PATCH 081/194] changed to all sensor[] tlm --- afsk/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 3ca2df41..4880bb61 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -536,14 +536,17 @@ int get_tlm(int tlm[][5]) { tlm[1][A] = (int)(voltsBus[BUS] / 15 + 0.5) % 100; // Current of 5V supply to Pi // tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENTV], NULL)/10) % 100; // +X current [4] tlm[1][B] = (int) (99.5 - current[PLUS_X]/10) % 100; // +X current [4] - tlm[1][C] = (int) (99.5 - x_current/10) % 100; // X- current [10] +// tlm[1][C] = (int) (99.5 - x_current/10) % 100; // X- current [10] + tlm[1][C] = (int) (99.5 - current[MINUS_X]/10) % 100; // X- current [10] // tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENTV], NULL)/10) % 100; // +Y current [7] tlm[1][D] = (int) (99.5 - current[PLUS_Y]/10) % 100; // +Y current [7] - tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10] +// tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10] + tlm[2][A] = (int) (99.5 - current[MINUS_Y]/10) % 100; // -Y current [10] // tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENTV], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel tlm[2][B] = (int) (99.5 - current[PLUS_Z]/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][C] = (int) (99.5 - z_current/10) % 100; // -Z current (was timestamp) +// tlm[2][C] = (int) (99.5 - z_current/10) % 100; // -Z current (was timestamp) + tlm[2][C] = (int) (99.5 - current[MINUS_Z]/10) % 100; // -Z current (was timestamp) // tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100; // tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENTV], NULL)/10.0) % 100; // NiMH Battery current From 025e6effb7a4da4fcb90731c65a7e9bdfda18161 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 02:10:06 -0400 Subject: [PATCH 082/194] created config structure --- afsk/main.c | 155 ++++++++++++++++++++++++---------------------------- 1 file changed, 72 insertions(+), 83 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index af9bdabd..8d030189 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -105,11 +105,21 @@ int x_calValue_x; int y_fd; // I2C bus 0 address 0x41 int z_fd; // I2C bos 0 address 0x44 +struct SensorConfig { + int fd; + uint16_t config; + int calValue; + int powerMultiplier; + int currentDivider; +}; + struct SensorData { - double power; double current; + double voltage; + double power; }; + /** * @brief Read the data from one of the i2c current sensors. * @@ -123,27 +133,43 @@ struct SensorData { * @param sensor A file descriptor that can be used to read from the sensor. * @return struct SensorData A struct that contains the power and current reading from the requested sensor. */ -struct SensorData read_sensor_data(int sensor) { +struct SensorData read_sensor_data(struct SensorConfig sensor) { struct SensorData data = { - .power = NAN, - .current = NAN - }; + .current = NAN, + .voltage = NAN + .power = NAN }; - if (sensor < 0) { + if (sensor.fd < 0) { return data; } + + data.current = 2000 / sensor.currentDivider; + data.voltage = 10; + data.power = 3 * sensor.powerMultiplier; - wiringPiI2CWriteReg16(sensor, INA219_REG_CALIBRATION, x_calValue); - wiringPiI2CWriteReg16(sensor, INA219_REG_CONFIG, config); - wiringPiI2CWriteReg16(sensor, INA219_REG_CALIBRATION, x_calValue); - data.current = wiringPiI2CReadReg16(sensor, INA219_REG_CURRENT) / x_currentDivider; - data.power = wiringPiI2CReadReg16(sensor, INA219_REG_POWER) * x_powerMultiplier; + return data; +} +struct SensorConfig config_sensor(int sensor) { + struct SensorConfig data; + + data.fd = sensor; + data.config = INA219_CONFIG_BVOLTAGERANGE_32V | + INA219_CONFIG_GAIN_1_40MV | + INA219_CONFIG_BADCRES_12BIT | + // INA219_CONFIG_SADCRES_12BIT_4S_2130US | + INA219_CONFIG_SADCRES_12BIT_1S_532US | + INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;; + data.calValue = 8192; + data.powerMultiplier = 2; + data.currentDivider = 20; + return data; } -int sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -float voltsBus[8]; + +struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 +struct SensorData data[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2float voltsBus[8]; float voltsShunt[8]; float current[8]; float power[8]; @@ -189,7 +215,7 @@ int main(int argc, char *argv[]) { #ifdef DEBUG_LOGGING fprintf(stderr,"tempSensor: %d \n",tempSensor); #endif - + /* start of old master code x_calValue_x = 8192; x_powerMultiplier = 1; @@ -221,37 +247,38 @@ end of old code */ if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present { close(test); - sensor[PLUS_X] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x40); - sensor[PLUS_Y] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x41); - sensor[PLUS_Z] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x44); - sensor[BAT] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x45); - sensor[BUS] = wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a); + sensor[PLUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x40)); + sensor[PLUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x41)); + sensor[PLUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x44)); + sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45)); + sensor[BUS] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a)); } else { printf("ERROR: /dev/i2c-1 not present \n"); - sensor[PLUS_X] = OFF; - sensor[PLUS_Y] = OFF; - sensor[PLUS_Z] = OFF; - sensor[BAT] = OFF; - sensor[BUS] = OFF; + sensor[PLUS_X] = config_sensor(OFF); + sensor[PLUS_Y] = config_sensor(OFF); + sensor[PLUS_Z] = config_sensor(OFF); + sensor[BAT] = config_sensor(OFF); + sensor[BUS] = config_sensor(OFF); } if (((test = open("/dev/i2c-0", O_RDWR))) > 0) // Test if I2C Bus 0 is present { close(test); - sensor[MINUS_X] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); - sensor[MINUS_Y] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); - sensor[MINUS_Z] = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); + sensor[MINUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x40)); + sensor[MINUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x41)); + sensor[MINUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x44)); } else { printf("ERROR: /dev/i2c-0 not present \n"); - sensor[MINUS_X] = OFF; - sensor[MINUS_Y] = OFF; - sensor[MINUS_Z] = OFF; + sensor[MINUS_X] = config_sensor(OFF); + sensor[MINUS_Y] = config_sensor(OFF); + sensor[MINUS_Z] = config_sensor(OFF); } -// } Extra close bracket?? -// } // move up! - + #ifdef DEBUG_LOGGING + printf("Sensor[0] config %d %d %d %d %d\n", + sensor[0].fd, sensor[0].config, sensor[0].calValue, sensor[0].currentDivider, sensor[0].powerMultiplier); + #endif // new INA219 current reading code /* x_calValue = 8192; @@ -497,61 +524,23 @@ int get_tlm(int tlm[][5]) { #endif */ - struct SensorData x_data = read_sensor_data(x_fd); - struct SensorData y_data = read_sensor_data(y_fd); - struct SensorData z_data = read_sensor_data(z_fd); + // struct SensorData x_data = read_sensor_data(x_fd); + // struct SensorData y_data = read_sensor_data(y_fd); + // struct SensorData z_data = read_sensor_data(z_fd); int count; - for (count = 0; count < 7; count++) - { - if (sensor[count] != OFF) - { - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] ", count); - #endif - setCalibration_16V_400mA(sensor[count]); - current[count] = getCurrent_mA(sensor[count]); - voltsBus[count] = getBusVoltage_V(sensor[count]); - voltsShunt[count] = getShuntVoltage_mV(sensor[count])/1000; - power[count] = getPower_mW(sensor[count]); - } - else - { - voltsShunt[count] = 0; - voltsBus[count] = 0; - current[count] = 0; - power[count] = 0; - } - #ifdef DEBUG_LOGGING - printf("%+4.2fV %+4.2fV %+4.2fmA %+4.2fmW \n", - voltsBus[count], voltsShunt[count], current[count], power[count]); - #endif - } - if (sensor[BUS] != OFF) // For MoPower V2 INA219 + for (count = 0; count < 8; count++) { - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] ", BUS); + #ifdef DEBUG_LOGGING + printf("Read sensor[%d] ", count); #endif - setCalibration_16V_2A(sensor[BUS]); - current[BUS] = getCurrent_mA(sensor[BUS]); // * 4; - voltsBus[BUS] = getBusVoltage_V(sensor[BUS]); - voltsShunt[BUS] = getShuntVoltage_mV(sensor[BUS])/1000; - power[BUS] = getPower_mW(sensor[BUS]); // *2; - } - else - { - voltsShunt[BUS] = 0; - voltsBus[BUS] = 0; - current[BUS] = 0; - power[BUS] = 0; - } - #ifdef DEBUG_LOGGING - printf("%+4.2fV %+4.2fV %+4.2fmA %+4.2fmW \n", - voltsBus[BUS], voltsShunt[BUS], current[BUS], power[BUS]); - #endif - - + data[count] = read_sensor_data(sensor[count]); + #ifdef DEBUG_LOGGING + printf("%+4.2fV %+4.2fmA %+4.2fmW \n", + sensor[count].volts, sensor[count].current, sensor[count].power); + #endif + } // delay(500); // } From 87332dc6a274de4fe23102e4997c57c5a724e9db Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 02:12:24 -0400 Subject: [PATCH 083/194] fixed initialization of struct --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 8d030189..d6c44763 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -136,7 +136,7 @@ struct SensorData { struct SensorData read_sensor_data(struct SensorConfig sensor) { struct SensorData data = { .current = NAN, - .voltage = NAN + .voltage = NAN, .power = NAN }; if (sensor.fd < 0) { From 8ea8eaffb586a006fbb8c30439fc1859e30f2ea5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 02:13:26 -0400 Subject: [PATCH 084/194] fixed references to data struct --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index d6c44763..b29f318d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -538,7 +538,7 @@ int get_tlm(int tlm[][5]) { #ifdef DEBUG_LOGGING printf("%+4.2fV %+4.2fmA %+4.2fmW \n", - sensor[count].volts, sensor[count].current, sensor[count].power); + data[count].volts, data[count].current, data[count].power); #endif } From 278f79d7c8cb0e5aa3b24a0db35656c82f537f8e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 02:15:50 -0400 Subject: [PATCH 085/194] fixed typos --- afsk/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index b29f318d..94c90923 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -169,7 +169,8 @@ struct SensorConfig config_sensor(int sensor) { struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData data[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2float voltsBus[8]; +struct SensorData data[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2float +voltsBus[8]; float voltsShunt[8]; float current[8]; float power[8]; @@ -538,7 +539,7 @@ int get_tlm(int tlm[][5]) { #ifdef DEBUG_LOGGING printf("%+4.2fV %+4.2fmA %+4.2fmW \n", - data[count].volts, data[count].current, data[count].power); + data[count].voltage, data[count].current, data[count].power); #endif } From 8c591373ca5acb97ec3730846349dbe1e00335b2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 03:15:10 -0400 Subject: [PATCH 086/194] added sensor reading to the read_sensor_data function --- afsk/main.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 94c90923..f668b8a6 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -142,10 +142,16 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { if (sensor.fd < 0) { return data; } - - data.current = 2000 / sensor.currentDivider; - data.voltage = 10; - data.power = 3 * sensor.powerMultiplier; + + wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, sensor.calValue); + wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, sensor.config); + wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, sensor.calValue); + data.current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / sensor.currentDivider; + #ifdef DEBUG_LOGGING + value = (uint16_t)wireReadRegister(x_fd, INA219_REG_BUSVOLTAGE); + data.voltage = ((double)(value >> 3) * 4) / 1000; + data.power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * sensor.powerMultiplier; + #endif return data; } @@ -169,7 +175,7 @@ struct SensorConfig config_sensor(int sensor) { struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData data[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2float +struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2float voltsBus[8]; float voltsShunt[8]; float current[8]; @@ -535,11 +541,11 @@ int get_tlm(int tlm[][5]) { #ifdef DEBUG_LOGGING printf("Read sensor[%d] ", count); #endif - data[count] = read_sensor_data(sensor[count]); + reading[count] = read_sensor_data(sensor[count]); #ifdef DEBUG_LOGGING printf("%+4.2fV %+4.2fmA %+4.2fmW \n", - data[count].voltage, data[count].current, data[count].power); + reading[count].voltage, reading[count].current, reading[count].power); #endif } @@ -565,28 +571,28 @@ int get_tlm(int tlm[][5]) { // printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL)); // tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENTV], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][A] = (int)(voltsBus[BUS] / 15 + 0.5) % 100; // Current of 5V supply to Pi + tlm[1][A] = (int)(reading[BUS].voltage / 15 + 0.5) % 100; // Current of 5V supply to Pi // tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENTV], NULL)/10) % 100; // +X current [4] - tlm[1][B] = (int) (99.5 - current[PLUS_X]/10) % 100; // +X current [4] + tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10) % 100; // +X current [4] // tlm[1][C] = (int) (99.5 - x_current/10) % 100; // X- current [10] - tlm[1][C] = (int) (99.5 - current[MINUS_X]/10) % 100; // X- current [10] + tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10) % 100; // X- current [10] // tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENTV], NULL)/10) % 100; // +Y current [7] - tlm[1][D] = (int) (99.5 - current[PLUS_Y]/10) % 100; // +Y current [7] + tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10) % 100; // +Y current [7] // tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10] - tlm[2][A] = (int) (99.5 - current[MINUS_Y]/10) % 100; // -Y current [10] + tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10) % 100; // -Y current [10] // tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENTV], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][B] = (int) (99.5 - current[PLUS_Z]/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel + tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel // tlm[2][C] = (int) (99.5 - z_current/10) % 100; // -Z current (was timestamp) - tlm[2][C] = (int) (99.5 - current[MINUS_Z]/10) % 100; // -Z current (was timestamp) + tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10) % 100; // -Z current (was timestamp) // tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100; // tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENTV], NULL)/10.0) % 100; // NiMH Battery current - tlm[2][D] = (int)(50.5 + current[BAT]/10.0) % 100; // NiMH Battery current + tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current // tlm[3][A] = abs((int)((strtof(ina219[SENSOR_45 + VOLTAGE], NULL) * 10) - 65.5) % 100); - tlm[3][A] = abs((int)((voltsBus[BAT] * 10) - 65.5) % 100); + tlm[3][A] = abs((int)((reading[BAT].voltage * 10) - 65.5) % 100); // tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0) % 100; // 5V supply to Pi - tlm[3][B] = (int)(voltsBus[BUS] * 10.0) % 100; // 5V supply to Pi + tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi if (tempSensor != OFF) { int tempValue = wiringPiI2CReadReg16(tempSensor, 0); From 47e2d82e045f89c5384ff7878cf982eb4ec44744 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 03:17:08 -0400 Subject: [PATCH 087/194] fixed x_fd in function call --- afsk/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index f668b8a6..9837a8a2 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -143,14 +143,14 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { return data; } - wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, sensor.config); - wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, sensor.calValue); - data.current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / sensor.currentDivider; + wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); + wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); + wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); + data.current = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT) / sensor.currentDivider; #ifdef DEBUG_LOGGING - value = (uint16_t)wireReadRegister(x_fd, INA219_REG_BUSVOLTAGE); + uint16_t value = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value >> 3) * 4) / 1000; - data.power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * sensor.powerMultiplier; + data.power = wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * sensor.powerMultiplier; #endif return data; From 86687fea6e31d10c4365bc551aaaed24e26c3fb1 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 03:18:47 -0400 Subject: [PATCH 088/194] fixed compiler warnings --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 9837a8a2..b7e6459d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -175,8 +175,8 @@ struct SensorConfig config_sensor(int sensor) { struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2float -voltsBus[8]; +struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 +float voltsBus[8]; float voltsShunt[8]; float current[8]; float power[8]; From 589a8179821fcd96bb87b6fd18906c7dacc891e3 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 03:40:25 -0400 Subject: [PATCH 089/194] added 400mA and 2A configurations --- afsk/main.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index b7e6459d..ba2a3226 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -156,7 +156,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { return data; } -struct SensorConfig config_sensor(int sensor) { +struct SensorConfig config_sensor(int sensor, int milliAmps) { struct SensorConfig data; data.fd = sensor; @@ -166,10 +166,16 @@ struct SensorConfig config_sensor(int sensor) { // INA219_CONFIG_SADCRES_12BIT_4S_2130US | INA219_CONFIG_SADCRES_12BIT_1S_532US | INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;; - data.calValue = 8192; - data.powerMultiplier = 2; - data.currentDivider = 20; - + if (milliAmps = 400) { // 16V 400mA configuration + data.calValue = 8192; + data.powerMultiplier = 1; // 2; + data.currentDivider = 40; // 20; + } + else { // 16V 2A configuration + data.calValue = 40960; + data.powerMultiplier = 2; // 2; + data.currentDivider = 20; // 20; + } return data; } @@ -254,11 +260,11 @@ end of old code */ if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present { close(test); - sensor[PLUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x40)); - sensor[PLUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x41)); - sensor[PLUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x44)); - sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45)); - sensor[BUS] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a)); + sensor[PLUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x40) 400); + sensor[PLUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x41) 400); + sensor[PLUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x44) 400); + sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45) 400); + sensor[BUS] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a), 2400); } else { printf("ERROR: /dev/i2c-1 not present \n"); @@ -271,9 +277,9 @@ end of old code */ if (((test = open("/dev/i2c-0", O_RDWR))) > 0) // Test if I2C Bus 0 is present { close(test); - sensor[MINUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x40)); - sensor[MINUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x41)); - sensor[MINUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x44)); + sensor[MINUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x40), 400); + sensor[MINUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x41), 400); + sensor[MINUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x44), 400); } else { @@ -285,7 +291,9 @@ end of old code */ #ifdef DEBUG_LOGGING printf("Sensor[0] config %d %d %d %d %d\n", sensor[0].fd, sensor[0].config, sensor[0].calValue, sensor[0].currentDivider, sensor[0].powerMultiplier); - #endif + printf("Sensor[BUS] config %d %d %d %d %d\n", + sensor[BUS].fd, sensor[BUS].config, sensor[BUS].calValue, sensor[BUS].currentDivider, sensor[BUS].powerMultiplier); + #endif // new INA219 current reading code /* x_calValue = 8192; From 69d4f1a6a7896868d9e5c357c2a1fb6f6f2ff2c7 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 03:42:12 -0400 Subject: [PATCH 090/194] fixed typos in config function --- afsk/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index ba2a3226..04187977 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -166,7 +166,7 @@ struct SensorConfig config_sensor(int sensor, int milliAmps) { // INA219_CONFIG_SADCRES_12BIT_4S_2130US | INA219_CONFIG_SADCRES_12BIT_1S_532US | INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;; - if (milliAmps = 400) { // 16V 400mA configuration + if (milliAmps == 400) { // 16V 400mA configuration data.calValue = 8192; data.powerMultiplier = 1; // 2; data.currentDivider = 40; // 20; @@ -260,10 +260,10 @@ end of old code */ if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present { close(test); - sensor[PLUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x40) 400); - sensor[PLUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x41) 400); - sensor[PLUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x44) 400); - sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45) 400); + sensor[PLUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x40), 400); + sensor[PLUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x41), 400); + sensor[PLUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x44), 400); + sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45), 400); sensor[BUS] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a), 2400); } else { From a84d5297ee4481be52668aefd0343940261a152f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 03:43:40 -0400 Subject: [PATCH 091/194] typos --- afsk/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 04187977..c511808c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -268,11 +268,11 @@ end of old code */ } else { printf("ERROR: /dev/i2c-1 not present \n"); - sensor[PLUS_X] = config_sensor(OFF); - sensor[PLUS_Y] = config_sensor(OFF); - sensor[PLUS_Z] = config_sensor(OFF); - sensor[BAT] = config_sensor(OFF); - sensor[BUS] = config_sensor(OFF); + sensor[PLUS_X] = config_sensor(OFF, 0); + sensor[PLUS_Y] = config_sensor(OFF, 0); + sensor[PLUS_Z] = config_sensor(OFF, 0); + sensor[BAT] = config_sensor(OFF, 0); + sensor[BUS] = config_sensor(OFF, 0); } if (((test = open("/dev/i2c-0", O_RDWR))) > 0) // Test if I2C Bus 0 is present { @@ -284,9 +284,9 @@ end of old code */ } else { printf("ERROR: /dev/i2c-0 not present \n"); - sensor[MINUS_X] = config_sensor(OFF); - sensor[MINUS_Y] = config_sensor(OFF); - sensor[MINUS_Z] = config_sensor(OFF); + sensor[MINUS_X] = config_sensor(OFF, 0); + sensor[MINUS_Y] = config_sensor(OFF, 0); + sensor[MINUS_Z] = config_sensor(OFF, 0); } #ifdef DEBUG_LOGGING printf("Sensor[0] config %d %d %d %d %d\n", From 6816d503b5139f91dc88fe4a634a0c7377727a51 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 03:54:50 -0400 Subject: [PATCH 092/194] changed data.config from Adafruit Lib --- afsk/main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index c511808c..508d34be 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -160,18 +160,27 @@ struct SensorConfig config_sensor(int sensor, int milliAmps) { struct SensorConfig data; data.fd = sensor; - data.config = INA219_CONFIG_BVOLTAGERANGE_32V | +/* data.config = INA219_CONFIG_BVOLTAGERANGE_32V | INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | // INA219_CONFIG_SADCRES_12BIT_4S_2130US | INA219_CONFIG_SADCRES_12BIT_1S_532US | INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;; +*/ if (milliAmps == 400) { // 16V 400mA configuration + data.config = INA219_CONFIG_BVOLTAGERANGE_16V | + INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | + INA219_CONFIG_SADCRES_12BIT_1S_532US | + INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; data.calValue = 8192; data.powerMultiplier = 1; // 2; data.currentDivider = 40; // 20; } else { // 16V 2A configuration + data.config = INA219_CONFIG_BVOLTAGERANGE_16V | + INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | + INA219_CONFIG_SADCRES_12BIT_1S_532US | + INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; data.calValue = 40960; data.powerMultiplier = 2; // 2; data.currentDivider = 20; // 20; From fa4850f5558edb2f21aada5b87b7aac447f90f25 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 04:05:14 -0400 Subject: [PATCH 093/194] added 2x multiply to fix current values --- afsk/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 508d34be..2a8e54ca 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -173,8 +173,8 @@ struct SensorConfig config_sensor(int sensor, int milliAmps) { INA219_CONFIG_SADCRES_12BIT_1S_532US | INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; data.calValue = 8192; - data.powerMultiplier = 1; // 2; - data.currentDivider = 40; // 20; + data.powerMultiplier = 1; + data.currentDivider = 20; // 40; in Adafruit config } else { // 16V 2A configuration data.config = INA219_CONFIG_BVOLTAGERANGE_16V | @@ -183,7 +183,7 @@ struct SensorConfig config_sensor(int sensor, int milliAmps) { INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; data.calValue = 40960; data.powerMultiplier = 2; // 2; - data.currentDivider = 20; // 20; + data.currentDivider = 10; // 20; in Adafruit config } return data; } From cb9d4609da9bd50d530da7e78d7e1109226d8dd2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 05:09:21 -0400 Subject: [PATCH 094/194] always get voltage and power, cleanup --- afsk/main.c | 82 +++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 2a8e54ca..5d20ecc1 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -147,54 +147,53 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); data.current = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT) / sensor.currentDivider; - #ifdef DEBUG_LOGGING - uint16_t value = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); - data.voltage = ((double)(value >> 3) * 4) / 1000; - data.power = wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * sensor.powerMultiplier; - #endif + uint16_t value = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); + data.voltage = ((double)(value >> 3) * 4) / 1000; + data.power = wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * sensor.powerMultiplier; return data; } - struct SensorConfig config_sensor(int sensor, int milliAmps) { struct SensorConfig data; data.fd = sensor; -/* data.config = INA219_CONFIG_BVOLTAGERANGE_32V | + data.config = INA219_CONFIG_BVOLTAGERANGE_32V | INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | // INA219_CONFIG_SADCRES_12BIT_4S_2130US | INA219_CONFIG_SADCRES_12BIT_1S_532US | INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;; -*/ + if (milliAmps == 400) { // 16V 400mA configuration - data.config = INA219_CONFIG_BVOLTAGERANGE_16V | +/* data.config = INA219_CONFIG_BVOLTAGERANGE_16V | INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; + INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; */ data.calValue = 8192; data.powerMultiplier = 1; data.currentDivider = 20; // 40; in Adafruit config } else { // 16V 2A configuration - data.config = INA219_CONFIG_BVOLTAGERANGE_16V | +/* data.config = INA219_CONFIG_BVOLTAGERANGE_16V | INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; + INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; */ data.calValue = 40960; - data.powerMultiplier = 2; // 2; + data.powerMultiplier = 2; data.currentDivider = 10; // 20; in Adafruit config } return data; } - struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 + +/* float voltsBus[8]; float voltsShunt[8]; float current[8]; float power[8]; +*/ char src_addr[5] = ""; char dest_addr[5] = "CQ"; @@ -204,15 +203,15 @@ int main(int argc, char *argv[]) { strcpy(src_addr, argv[1]); } - wiringPiSetup () ; - pinMode (0, OUTPUT) ; - int blink; - for (blink = 1; blink < 4 ;blink++) - { - digitalWrite (0, HIGH) ; delay (500) ; - digitalWrite (0, LOW) ; delay (500) ; - } - digitalWrite (0, HIGH) ; + wiringPiSetup (); + pinMode (0, OUTPUT); +// int blink; +// for (blink = 1; blink < 4 ;blink++) +// { +// digitalWrite (0, HIGH) ; delay (500) ; +// digitalWrite (0, LOW) ; delay (500) ; +// } +// digitalWrite (0, HIGH) ; setSpiChannel(SPI_CHANNEL); setSpiSpeed(SPI_SPEED); @@ -272,16 +271,16 @@ end of old code */ sensor[PLUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x40), 400); sensor[PLUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x41), 400); sensor[PLUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x44), 400); - sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45), 400); - sensor[BUS] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a), 2400); + sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45), 400); + sensor[BUS] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a), 2400); } else { printf("ERROR: /dev/i2c-1 not present \n"); sensor[PLUS_X] = config_sensor(OFF, 0); sensor[PLUS_Y] = config_sensor(OFF, 0); sensor[PLUS_Z] = config_sensor(OFF, 0); - sensor[BAT] = config_sensor(OFF, 0); - sensor[BUS] = config_sensor(OFF, 0); + sensor[BAT] = config_sensor(OFF, 0); + sensor[BUS] = config_sensor(OFF, 0); } if (((test = open("/dev/i2c-0", O_RDWR))) > 0) // Test if I2C Bus 0 is present { @@ -555,14 +554,10 @@ int get_tlm(int tlm[][5]) { int count; for (count = 0; count < 8; count++) { - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] ", count); - #endif - reading[count] = read_sensor_data(sensor[count]); - + reading[count] = read_sensor_data(sensor[count]); #ifdef DEBUG_LOGGING - printf("%+4.2fV %+4.2fmA %+4.2fmW \n", - reading[count].voltage, reading[count].current, reading[count].power); + printf("Read sensor[%d] %+4.2fV %+4.2fmA %+4.2fmW \n", + count, reading[count].voltage, reading[count].current, reading[count].power); #endif } @@ -588,32 +583,31 @@ int get_tlm(int tlm[][5]) { // printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL)); // tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENTV], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][A] = (int)(reading[BUS].voltage / 15 + 0.5) % 100; // Current of 5V supply to Pi + tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi // tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENTV], NULL)/10) % 100; // +X current [4] - tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10) % 100; // +X current [4] + tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4] // tlm[1][C] = (int) (99.5 - x_current/10) % 100; // X- current [10] - tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10) % 100; // X- current [10] + tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10] // tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENTV], NULL)/10) % 100; // +Y current [7] - tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10) % 100; // +Y current [7] + tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7] // tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10] - tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10) % 100; // -Y current [10] + tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10] // tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENTV], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel + tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel // tlm[2][C] = (int) (99.5 - z_current/10) % 100; // -Z current (was timestamp) - tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10) % 100; // -Z current (was timestamp) + tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp) // tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100; // tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENTV], NULL)/10.0) % 100; // NiMH Battery current tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current // tlm[3][A] = abs((int)((strtof(ina219[SENSOR_45 + VOLTAGE], NULL) * 10) - 65.5) % 100); - tlm[3][A] = abs((int)((reading[BAT].voltage * 10) - 65.5) % 100); + tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); // tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0) % 100; // 5V supply to Pi tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi if (tempSensor != OFF) { int tempValue = wiringPiI2CReadReg16(tempSensor, 0); - uint8_t upper = (uint8_t) (tempValue >> 8); uint8_t lower = (uint8_t) (tempValue & 0xff); float temp = (float)lower + ((float)upper / 0x100); @@ -630,9 +624,11 @@ int get_tlm(int tlm[][5]) { double cpuTemp; fscanf (cpuTempSensor, "%lf", &cpuTemp); cpuTemp /= 1000; + #ifdef DEBUG_LOGGING printf("CPU Temp Read: %6.1f\n", cpuTemp); #endif + tlm[4][B] = (int)((95.8 - cpuTemp)/1.48 + 0.5) % 100; fclose (cpuTempSensor); } From eb884ce0e66f4c1015049aa87dc361dba966a2e6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 06:17:32 -0400 Subject: [PATCH 095/194] cleanup of commented out code --- afsk/main.c | 316 ++++++---------------------------------------------- 1 file changed, 32 insertions(+), 284 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 5d20ecc1..6e1ab846 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -1,5 +1,5 @@ /* - * Transmits CubeSat Telemetry at 440MHz in AO-7 format + * Transmits CubeSat Telemetry at 434.9MHz in AO-7 format * * Copyright Alan B. Johnston * @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -#include //Needed for I2C port +#include #include #include #include @@ -32,32 +32,13 @@ #include #include #include -#include "../Adafruit_INA219/Adafruit_INA219.h" -/* -#define VBATT 15 -#define ADC5 17 -#define ADC6 18 -#define ADC7 19 -#define ADC8 20 -#define TIME 8 -#define UCTEMP 30 -#define UPTIME_SEC 8 -*/ +#include "../Adafruit_INA219/Adafruit_INA219.h" // From Adafruit INA219 library for Arduino + #define A 1 #define B 2 #define C 3 #define D 4 -/* -#define SENSOR_40 0 -#define SENSOR_41 3 -#define SENSOR_44 6 -#define SENSOR_45 9 -#define SENSOR_4A 12 -#define VOLTAGE 0 -#define CURRENTV 1 -#define POWER 2 -*/ -#define VBATT 15 + #define PLUS_X 0 #define PLUS_Y 1 #define PLUS_Z 2 @@ -79,15 +60,6 @@ int get_tlm(int tlm[][5]); long int timestamp; void config_x25(); void trans_x25(); -void setCalibration_32V_2A(int fd); -void setCalibration_32V_1A(int fd); -void setCalibration_16V_400mA(int fd); -void setCalibration_16V_2A(int fd); -float getBusVoltage_V(int fd); -float getShuntVoltage_mV(int fd); -float getCurrent_mA(int fd); -float getPower_mW(int fd); -void powerSave(int fd, int on); //long int timestamp; int tempSensor; @@ -98,13 +70,6 @@ int charging = 0; uint16_t x_config = (0x2000 | 0x1800 | 0x0180 | 0x0018 | 0x0007 ); -int x_fd; // I2C bus 0 address 0x40 -int x_powerMultiplier; -int x_currentDivider; -int x_calValue_x; -int y_fd; // I2C bus 0 address 0x41 -int z_fd; // I2C bos 0 address 0x44 - struct SensorConfig { int fd; uint16_t config; @@ -128,7 +93,6 @@ struct SensorData { * results in a SensorData struct being returned that has both its #current and #power members * set to NAN. * - * WARNING: This function currently relies on the global variables x_calValue, config, x_currentDivider, and x_powerMultiplier. * * @param sensor A file descriptor that can be used to read from the sensor. * @return struct SensorData A struct that contains the power and current reading from the requested sensor. @@ -158,26 +122,17 @@ struct SensorConfig config_sensor(int sensor, int milliAmps) { data.fd = sensor; data.config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_1_40MV | - INA219_CONFIG_BADCRES_12BIT | - // INA219_CONFIG_SADCRES_12BIT_4S_2130US | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;; + INA219_CONFIG_GAIN_1_40MV | + INA219_CONFIG_BADCRES_12BIT | + INA219_CONFIG_SADCRES_12BIT_1S_532US | + INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - if (milliAmps == 400) { // 16V 400mA configuration -/* data.config = INA219_CONFIG_BVOLTAGERANGE_16V | - INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; */ + if (milliAmps == 400) { // INA219 16V 400mA configuration data.calValue = 8192; data.powerMultiplier = 1; data.currentDivider = 20; // 40; in Adafruit config } - else { // 16V 2A configuration -/* data.config = INA219_CONFIG_BVOLTAGERANGE_16V | - INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; */ + else { // INA219 16V 2A configuration data.calValue = 40960; data.powerMultiplier = 2; data.currentDivider = 10; // 20; in Adafruit config @@ -188,13 +143,7 @@ struct SensorConfig config_sensor(int sensor, int milliAmps) { struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -/* -float voltsBus[8]; -float voltsShunt[8]; -float current[8]; -float power[8]; -*/ -char src_addr[5] = ""; +/char src_addr[5] = ""; char dest_addr[5] = "CQ"; int main(int argc, char *argv[]) { @@ -205,13 +154,6 @@ int main(int argc, char *argv[]) { wiringPiSetup (); pinMode (0, OUTPUT); -// int blink; -// for (blink = 1; blink < 4 ;blink++) -// { -// digitalWrite (0, HIGH) ; delay (500) ; -// digitalWrite (0, LOW) ; delay (500) ; -// } -// digitalWrite (0, HIGH) ; setSpiChannel(SPI_CHANNEL); setSpiSpeed(SPI_SPEED); @@ -223,7 +165,7 @@ int main(int argc, char *argv[]) { timestamp = time(NULL); int file_i2c = access("/dev/i2c-3", W_OK | R_OK); - //char *filenam1e = (char*)"/dev/i2c-3"; + if (file_i2c < 0) { fprintf(stderr,"ERROR: /dev/ic2-3 bus not present\n"); @@ -237,33 +179,6 @@ int main(int argc, char *argv[]) { fprintf(stderr,"tempSensor: %d \n",tempSensor); #endif -/* start of old master code - x_calValue_x = 8192; - x_powerMultiplier = 1; - x_currentDivider = 20; - x_config = INA219_CONFIG_BVOLTAGERANGE_32V | - INA219_CONFIG_GAIN_1_40MV | - INA219_CONFIG_BADCRES_12BIT | - // INA219_CONFIG_SADCRES_12BIT_4S_2130US | - INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - - if ((file_i2c = open("/dev/i2c-0", O_RDWR)) < 0) - { - fprintf(stderr,"ERROR: /dev/ic2-0 bus not present\n"); - x_fd = OFF; - y_fd = OFF; - z_fd = OFF; - } else - { - x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); - y_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); - z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); - #ifdef DEBUG_LOGGING - fprintf(stderr, "Opening of -X %d, -Y %d, -Z %d\n", x_fd, y_fd, z_fd); - #endif - } // moved here -end of old code */ int test; if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present { @@ -302,38 +217,7 @@ end of old code */ printf("Sensor[BUS] config %d %d %d %d %d\n", sensor[BUS].fd, sensor[BUS].config, sensor[BUS].calValue, sensor[BUS].currentDivider, sensor[BUS].powerMultiplier); #endif -// new INA219 current reading code -/* - x_calValue = 8192; - x_powerMultiplier = 1; - x_currentDivider = 20; - x_config = INA219_CONFIG_BVOLTAGERANGE_16V | - INA219_CONFIG_GAIN_40MV | - INA219_CONFIG_BADCRES_12BIT | - INA219_CONFIG_SADCRES_12BIT_4S_2130US | - //INA219_CONFIG_SADCRES_12BIT_1S_532US | - INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; - - file_i2c = access("/dev/i2c-0", W_OK | R_OK); - if (file_i2c < 0) - { - fprintf(stderr,"ERROR: /dev/ic2-0 bus not present\n"); - x_fd = -1; // Disable reading -X, -Y, and -Z telemetry - y_fd = -1; - z_fd = -1; - } else - { - x_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x40); - y_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x41); - z_fd = wiringPiI2CSetupInterface("/dev/i2c-0", 0x44); - #ifdef DEBUG_LOGGING - fprintf(stderr, "Opening of -X fd %d\n", x_fd); - fprintf(stderr, "Opening of -Y fd %d\n", y_fd); - fprintf(stderr, "Opening of -Z fd %d\n", z_fd); - #endif - } -*/ int ret; uint8_t data[1024]; @@ -341,7 +225,7 @@ end of old code */ init_rf(); - ax25_init(&hax25, (uint8_t *) dest_addr, '1', (uint8_t *) src_addr, '1', + ax25_init(&hax25, (uint8_t *) dest_addr, '1', (uint8_t *) src_addr, '1', AX25_PREAMBLE_LEN, AX25_POSTAMBLE_LEN); @@ -378,34 +262,10 @@ end of old code */ printf("%s",tlm_str); strcat(str, tlm_str); } -/* - if (arduinoI2C > 0) { // Read Arduino payload - for(int reg = 0; reg < 4; reg++) { - sprintf(tlm_str, " %04x",wiringPiI2CReadReg16(arduinoI2C,reg)); - #ifdef DEBUG_LOGGING - printf("%s \n",tlm_str); - #endif - strcat(str,tlm_str); // Append payload telemetry - printf("%s",tlm_str); - usleep(100000); - } - } -*/ printf("\n"); digitalWrite (0, LOW); -/* -char cmdbuffer[1000]; - - if (charging) { - FILE* file1 = popen("/home/pi/mopower/mpcmd LED_STAT=1", "r"); - fgets(cmdbuffer, 999, file1); - pclose(file1); - -// printf("LED state: %s\n", cmdbuffer); - } -*/ #ifdef DEBUG_LOGGING fprintf(stderr,"INFO: Transmitting X.25 packet\n"); #endif @@ -421,13 +281,6 @@ char cmdbuffer[1000]; ax5043_wait_for_transmit(); digitalWrite (0, HIGH); -/* - FILE* file2 = popen("/home/pi/mopower/mpcmd LED_STAT=0", "r"); - fgets(cmdbuffer, 999, file2); - pclose(file2); - -// printf("LED state: %s\n", cmdbuffer); -*/ if (ret) { fprintf(stderr, "ERROR: Failed to transmit entire AX.25 frame with error code %d\n", @@ -478,133 +331,28 @@ int upper_digit(int number) { int get_tlm(int tlm[][5]) { // Reading I2C voltage and current sensors -/* - char cmdbuffer[1000]; - FILE* file = popen("sudo python /home/pi/CubeSatSim/python/readcurrent.py 2>&1", "r"); - fgets(cmdbuffer, 999, file); - pclose(file); - #ifdef DEBUG_LOGGING - fprintf(stderr,"I2C Sensor data: %s\n", cmdbuffer); - #endif - - char ina219[16][20]; // voltage, currents, and power from the INA219 current sensors x4a, x40, x41, x44, and x45. - int i = 0; - char * data2 = strtok (cmdbuffer," "); - - while (data2 != NULL) { - strcpy(ina219[i], data2); -// #ifdef DEBUG_LOGGING -// printf ("ina219[%d]=%s\n",i,ina219[i]); -// #endif - data2 = strtok (NULL, " "); - i++; - } -*/ - -// read i2c current sensors // -// code added back from master - double x_current, y_current, z_current; + int count; + for (count = 0; count < 8; count++) + { + reading[count] = read_sensor_data(sensor[count]); #ifdef DEBUG_LOGGING - double x_voltage, x_power, y_voltage, y_power, z_voltage, z_power; - uint16_t value; + printf("Read sensor[%d] %+4.2fV %+4.2fmA %+4.2fmW \n", + count, reading[count].voltage, reading[count].current, reading[count].power); #endif -/* Disable old code - if (x_fd != OFF) { - wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); - wiringPiI2CWriteReg16(x_fd, INA219_REG_CONFIG, x_config); - wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue_x); - x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; - #ifdef DEBUG_LOGGING -// x_voltage = wiringPiI2CReadReg16(x_fd, INA219_REG_BUSVOLTAGE) / 1000; - value = (uint16_t)wireReadRegister(x_fd, INA219_REG_BUSVOLTAGE); - x_voltage = ((double)(value >> 3) * 4) / 1000; - x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; - #endif - wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); - wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, x_config); - wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue_x); - y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; - #ifdef DEBUG_LOGGING -// y_voltage = wiringPiI2CReadReg16(y_fd, INA219_REG_BUSVOLTAGE) / 1000; - value = (uint16_t)wireReadRegister(y_fd, INA219_REG_BUSVOLTAGE); - y_voltage = ((double)(value >> 3) * 4) / 1000; - y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; - #endif - wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); - wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, x_config); - wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue_x); - z_current = wiringPiI2CReadReg16(z_fd, INA219_REG_CURRENT) / x_currentDivider; - #ifdef DEBUG_LOGGING -// z_voltage = wiringPiI2CReadReg16(z_fd, INA219_REG_BUSVOLTAGE) / 1000; - value = (uint16_t)wireReadRegister(z_fd, INA219_REG_BUSVOLTAGE); - z_voltage = ((double)(value >> 3) * 4) / 1000; - z_power = wiringPiI2CReadReg16(z_fd, INA219_REG_POWER) * x_powerMultiplier; - #endif - } - #ifdef DEBUG_LOGGING - printf("-X %+4.2f V %+4.2fmA %+4.2fmW -Y %+4.2fV %+4.2fmA %+4.2fmW -Z %+4.2fV %+4.2fmA %+4.2fmW \n", - x_voltage, x_current, x_power, y_voltage, y_current, y_power, z_voltage, z_current, z_power); - #endif -*/ - - // struct SensorData x_data = read_sensor_data(x_fd); - // struct SensorData y_data = read_sensor_data(y_fd); - // struct SensorData z_data = read_sensor_data(z_fd); - - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); - #ifdef DEBUG_LOGGING - printf("Read sensor[%d] %+4.2fV %+4.2fmA %+4.2fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); - #endif - } + } -// delay(500); - // } -/* wiringPiI2CWriteReg16(x_fd, INA219_REG_CALIBRATION, x_calValue); - x_current = wiringPiI2CReadReg16(x_fd, INA219_REG_CURRENT) / x_currentDivider; - x_power = wiringPiI2CReadReg16(x_fd, INA219_REG_POWER) * x_powerMultiplier; - wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); - wiringPiI2CWriteReg16(y_fd, INA219_REG_CONFIG, x_config); - wiringPiI2CWriteReg16(y_fd, INA219_REG_CALIBRATION, x_calValue); - y_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; - y_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; - wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue); - wiringPiI2CWriteReg16(z_fd, INA219_REG_CONFIG, x_config); - wiringPiI2CWriteReg16(z_fd, INA219_REG_CALIBRATION, x_calValue); - z_current = wiringPiI2CReadReg16(y_fd, INA219_REG_CURRENT) / x_currentDivider; - z_power = wiringPiI2CReadReg16(y_fd, INA219_REG_POWER) * x_powerMultiplier; - } - printf("-X 0x40 current %4.2f power %4.2f -Y 0x41 current %4.2f power %4.2f -Z 0x44 current %4.2f power %4.2f \n", - x_current, x_power, y_current, y_power, z_current, z_power); -*/ -// printf("1B: ina219[%d]: %s val: %f \n", SENSOR_40 + CURRENT, ina219[SENSOR_40 + CURRENT], strtof(ina219[SENSOR_40 + CURRENT], NULL)); - -// tlm[1][A] = (int)(strtof(ina219[SENSOR_4A + CURRENTV], NULL) / 15 + 0.5) % 100; // Current of 5V supply to Pi - tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi -// tlm[1][B] = (int) (99.5 - strtof(ina219[SENSOR_40 + CURRENTV], NULL)/10) % 100; // +X current [4] - tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4] -// tlm[1][C] = (int) (99.5 - x_current/10) % 100; // X- current [10] - tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10] -// tlm[1][D] = (int) (99.5 - strtof(ina219[SENSOR_41 + CURRENTV], NULL)/10) % 100; // +Y current [7] - tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7] - -// tlm[2][A] = (int) (99.5 - y_current/10) % 100; // -Y current [10] - tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10] -// tlm[2][B] = (int) (99.5 - strtof(ina219[SENSOR_44 + CURRENTV], NULL)/10) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel - tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel -// tlm[2][C] = (int) (99.5 - z_current/10) % 100; // -Z current (was timestamp) - tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp) -// tlm[2][C] = (int)((time(NULL) - timestamp) / 15) % 100; -// tlm[2][D] = (int)(50.5 + strtof(ina219[SENSOR_45 + CURRENTV], NULL)/10.0) % 100; // NiMH Battery current - tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current + tlm[1][A] = (int)(reading[BUS].voltage /15.0 + 0.5) % 100; // Current of 5V supply to Pi + tlm[1][B] = (int) (99.5 - reading[PLUS_X].current/10.0) % 100; // +X current [4] + tlm[1][C] = (int) (99.5 - reading[MINUS_X].current/10.0) % 100; // X- current [10] + tlm[1][D] = (int) (99.5 - reading[PLUS_Y].current/10.0) % 100; // +Y current [7] + + tlm[2][A] = (int) (99.5 - reading[MINUS_Y].current/10.0) % 100; // -Y current [10] + tlm[2][B] = (int) (99.5 - reading[PLUS_Z].current/10.0) % 100; // +Z current [10] // was 70/2m transponder power, AO-7 didn't have a Z panel + tlm[2][C] = (int) (99.5 - reading[MINUS_Z].current/10.0) % 100; // -Z current (was timestamp) + tlm[2][D] = (int)(50.5 + reading[BAT].current/10.0) % 100; // NiMH Battery current -// tlm[3][A] = abs((int)((strtof(ina219[SENSOR_45 + VOLTAGE], NULL) * 10) - 65.5) % 100); - tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); -// tlm[3][B] = (int)(strtof(ina219[SENSOR_4A + VOLTAGE], NULL) * 10.0) % 100; // 5V supply to Pi - tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi + tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); + tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi if (tempSensor != OFF) { int tempValue = wiringPiI2CReadReg16(tempSensor, 0); From 001eb01124d60e66fac6f54a3657271dfa6df982 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 06:19:22 -0400 Subject: [PATCH 096/194] typo fix --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 6e1ab846..6e7939d3 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -143,7 +143,7 @@ struct SensorConfig config_sensor(int sensor, int milliAmps) { struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -/char src_addr[5] = ""; +char src_addr[5] = ""; char dest_addr[5] = "CQ"; int main(int argc, char *argv[]) { From ed5d4844e5879a9d81ef24c25c4578640b48708a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 06:25:21 -0400 Subject: [PATCH 097/194] fixed printf formatting --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 6e7939d3..cebb700c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -336,7 +336,7 @@ int get_tlm(int tlm[][5]) { { reading[count] = read_sensor_data(sensor[count]); #ifdef DEBUG_LOGGING - printf("Read sensor[%d] %+4.2fV %+4.2fmA %+4.2fmW \n", + printf("Read sensor[%d] % 05.1fV % 05.1fmA % 05.1fmW \n", count, reading[count].voltage, reading[count].current, reading[count].power); #endif } From b6b7cc235ce48f62b284d78208b8c0c38d0f2022 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 06:27:34 -0400 Subject: [PATCH 098/194] print formatting --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index cebb700c..eddf09e5 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -336,7 +336,7 @@ int get_tlm(int tlm[][5]) { { reading[count] = read_sensor_data(sensor[count]); #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 05.1fV % 05.1fmA % 05.1fmW \n", + printf("Read sensor[%d] % 6.1fV % 6.1fmA % 6.1fmW \n", count, reading[count].voltage, reading[count].current, reading[count].power); #endif } From 0da6174626f6e841546464c09efd3dfec88f347f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 06:31:51 -0400 Subject: [PATCH 099/194] formatting cleanup --- afsk/main.c | 76 ++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index eddf09e5..9fc7e7e8 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -179,44 +179,44 @@ int main(int argc, char *argv[]) { fprintf(stderr,"tempSensor: %d \n",tempSensor); #endif - int test; - if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present - { - close(test); - sensor[PLUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x40), 400); - sensor[PLUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x41), 400); - sensor[PLUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x44), 400); - sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45), 400); - sensor[BUS] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a), 2400); - } else - { - printf("ERROR: /dev/i2c-1 not present \n"); - sensor[PLUS_X] = config_sensor(OFF, 0); - sensor[PLUS_Y] = config_sensor(OFF, 0); - sensor[PLUS_Z] = config_sensor(OFF, 0); - sensor[BAT] = config_sensor(OFF, 0); - sensor[BUS] = config_sensor(OFF, 0); - } - if (((test = open("/dev/i2c-0", O_RDWR))) > 0) // Test if I2C Bus 0 is present - { - close(test); - sensor[MINUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x40), 400); - sensor[MINUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x41), 400); - sensor[MINUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x44), 400); - - } else - { - printf("ERROR: /dev/i2c-0 not present \n"); - sensor[MINUS_X] = config_sensor(OFF, 0); - sensor[MINUS_Y] = config_sensor(OFF, 0); - sensor[MINUS_Z] = config_sensor(OFF, 0); - } - #ifdef DEBUG_LOGGING - printf("Sensor[0] config %d %d %d %d %d\n", + int test; + if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present + { + close(test); + sensor[PLUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x40), 400); + sensor[PLUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x41), 400); + sensor[PLUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x44), 400); + sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45), 400); + sensor[BUS] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a), 2400); + } else + { + printf("ERROR: /dev/i2c-1 not present \n"); + sensor[PLUS_X] = config_sensor(OFF, 0); + sensor[PLUS_Y] = config_sensor(OFF, 0); + sensor[PLUS_Z] = config_sensor(OFF, 0); + sensor[BAT] = config_sensor(OFF, 0); + sensor[BUS] = config_sensor(OFF, 0); + } + if (((test = open("/dev/i2c-0", O_RDWR))) > 0) // Test if I2C Bus 0 is present + { + close(test); + sensor[MINUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x40), 400); + sensor[MINUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x41), 400); + sensor[MINUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x44), 400); + + } else + { + printf("ERROR: /dev/i2c-0 not present \n"); + sensor[MINUS_X] = config_sensor(OFF, 0); + sensor[MINUS_Y] = config_sensor(OFF, 0); + sensor[MINUS_Z] = config_sensor(OFF, 0); + } + #ifdef DEBUG_LOGGING + printf("Sensor[0] config %d %d %d %d %d\n", sensor[0].fd, sensor[0].config, sensor[0].calValue, sensor[0].currentDivider, sensor[0].powerMultiplier); - printf("Sensor[BUS] config %d %d %d %d %d\n", + printf("Sensor[BUS] config %d %d %d %d %d\n", sensor[BUS].fd, sensor[BUS].config, sensor[BUS].calValue, sensor[BUS].currentDivider, sensor[BUS].powerMultiplier); - #endif + #endif int ret; uint8_t data[1024]; @@ -330,13 +330,13 @@ int upper_digit(int number) { } int get_tlm(int tlm[][5]) { - // Reading I2C voltage and current sensors +// Reading I2C voltage and current sensors int count; for (count = 0; count < 8; count++) { reading[count] = read_sensor_data(sensor[count]); #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 6.1fV % 6.1fmA % 6.1fmW \n", + printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", count, reading[count].voltage, reading[count].current, reading[count].power); #endif } From 05dde0a0efc425e3691abb63f805c51e4e91b559 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 07:55:56 -0400 Subject: [PATCH 100/194] added #ifdef SATNOGS to curl uploading code and cleanup --- afsk/ax25.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/afsk/ax25.c b/afsk/ax25.c index f597ae12..cc3270c8 100644 --- a/afsk/ax25.c +++ b/afsk/ax25.c @@ -91,9 +91,9 @@ int ax25_tx_frame(ax25_conf_t *hax25, ax5043_conf_t *hax, memcpy(__tx_buffer, hax25->addr_field, hax25->addr_field_len); memcpy(__tx_buffer + hax25->addr_field_len, payload, len); - - printf("\n"); - + +#ifdef SATNOGS + printf("\n"); char post_data[1024]; char hex_data[512]; char hex_octet[4]; @@ -107,16 +107,12 @@ int ax25_tx_frame(ax25_conf_t *hax25, ax5043_conf_t *hax, for(jj = 0; jj < 118; jj++) { sprintf(hex_octet, "%02x",__tx_buffer[jj]); strcat(hex_data, hex_octet); - } - //memset(post_data,0,strlen(post_data)); - //printf("2:%s\n",post_data); - - //sprintf(post_data,"curl --data \"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour + 4, tm.tm_min, tm.tm_sec, hex_data); + } // Note assumes EDT, change offset (+4) to UTC sprintf(post_data,"noradID=99999&source=KU2Y×tamp=%d-%d-%dT%d:%d:%d.500Z&frame=%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, (tm.tm_hour + 4) % 24, tm.tm_min, tm.tm_sec, hex_data); - //printf("%s&locator=longLat&longitude=75.3492W&latitude=40.0376N&&azimuth=360&elevation=90.0\" https://db.satnogs.org/api/telemetry/\n\n", hex_data); - printf("curl post data: %s\n",post_data); - CURL *curl; + printf("curl post data: %s\n",post_data); + + CURL *curl; CURLcode res; curl_global_init(CURL_GLOBAL_ALL); @@ -137,12 +133,13 @@ int ax25_tx_frame(ax25_conf_t *hax25, ax5043_conf_t *hax, res = curl_easy_perform(curl); /* Check for errors */ if(res != CURLE_OK) - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(res)); + fprintf(stderr, "ERROR: AX25.C curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); - } + } +#endif return ax5043_tx_frame(hax, __tx_buffer, len + hax25->addr_field_len, hax25->preamble_len, hax25->postable_len, 1000); From 7d963a0c0c8d01ecc7e4f3284775542af963e2a8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 08:31:42 -0400 Subject: [PATCH 101/194] added (float) to current divider and power multiplier --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 9fc7e7e8..9cec60ef 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -110,10 +110,10 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - data.current = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT) / sensor.currentDivider; + data.current = (float)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT) / (float)sensor.currentDivider; uint16_t value = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value >> 3) * 4) / 1000; - data.power = wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * sensor.powerMultiplier; + data.power = (float)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float)sensor.powerMultiplier; return data; } From d3a321fda1a38fdc2d931e3adee1262071e9abcd Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 08:35:40 -0400 Subject: [PATCH 102/194] added int16_t to current I2CRead --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 9cec60ef..cc7d1e5c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -110,7 +110,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - data.current = (float)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT) / (float)sensor.currentDivider; + data.current = (float)((int16_6)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; uint16_t value = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value >> 3) * 4) / 1000; data.power = (float)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float)sensor.powerMultiplier; From c23c37ac21fe9c2ed816e3710c5039afa21081fb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 08:37:58 -0400 Subject: [PATCH 103/194] type in unit16_t --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index cc7d1e5c..39e2f9f0 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -110,10 +110,10 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - data.current = (float)((int16_6)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; + data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; uint16_t value = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value >> 3) * 4) / 1000; - data.power = (float)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float)sensor.powerMultiplier; + data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; return data; } From 7d06c943726790b306b20a9e2c8ba9447771a6fb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 08:43:05 -0400 Subject: [PATCH 104/194] switched to two wiringPiI2CRead 8 bit reads instead of 16 bit read --- afsk/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 39e2f9f0..bea38537 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -110,7 +110,9 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; +// data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; + int16_t value = (uint16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + data.current = (float)value / (float)sensor.currentDivider;; uint16_t value = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; From a5dcb9b2cb9b218235d183911343226fc7523bf6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 08:48:22 -0400 Subject: [PATCH 105/194] fixed int16_t for current calc --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index bea38537..7543c61b 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -111,7 +111,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); // data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; - int16_t value = (uint16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); data.current = (float)value / (float)sensor.currentDivider;; uint16_t value = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value >> 3) * 4) / 1000; From faa41d1c3587aa545b76d16d1241ec07a3c3259b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 08:52:11 -0400 Subject: [PATCH 106/194] defined value and value2 --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 7543c61b..f7a205fc 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -113,8 +113,8 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { // data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); data.current = (float)value / (float)sensor.currentDivider;; - uint16_t value = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); - data.voltage = ((double)(value >> 3) * 4) / 1000; + uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); + data.voltage = ((double)(value2 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; return data; From b3be89474782ecb02dfca601273b37c3be48c732 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 08:58:54 -0400 Subject: [PATCH 107/194] added printf to see values --- afsk/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index f7a205fc..6a81e415 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -111,8 +111,11 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); // data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; + int16_t value0 = (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); - data.current = (float)value / (float)sensor.currentDivider;; + float value1 = (float) value; + data.current = value1 / (float)sensor.currentDivider; + printf("********* value0 %d value1 %d value %d data.current %f \n", value0, value1, value, data.current); uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value2 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; From 221df1fe095acf91080e344b5f18ea192045f30b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 08:59:57 -0400 Subject: [PATCH 108/194] typo --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 6a81e415..be3d5d53 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -115,7 +115,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); float value1 = (float) value; data.current = value1 / (float)sensor.currentDivider; - printf("********* value0 %d value1 %d value %d data.current %f \n", value0, value1, value, data.current); + printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current); uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value2 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; From 053a867ebdbe8241531f0b9be266f90e83cbc0cb Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 09:04:59 -0400 Subject: [PATCH 109/194] added register write --- afsk/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index be3d5d53..c9ca77a8 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -111,7 +111,9 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); // data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; - int16_t value0 = (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); + int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); + wiringPiI2CWrite(fd, INA219_REG_CURRENT); + delay(1); // Max 12-bit conversion time is 586us per sample int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); float value1 = (float) value; data.current = value1 / (float)sensor.currentDivider; From d8a28a9179d2e8412d89baa0f23f922f02ca8194 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 09:05:51 -0400 Subject: [PATCH 110/194] fixed fd in write --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index c9ca77a8..f6e05662 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -112,7 +112,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); // data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - wiringPiI2CWrite(fd, INA219_REG_CURRENT); + wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); delay(1); // Max 12-bit conversion time is 586us per sample int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); float value1 = (float) value; From 1ac88664e0e04416ea6b920d29a64ef1bcc4b38c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 09:16:53 -0400 Subject: [PATCH 111/194] changing ints --- afsk/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index f6e05662..ed6db849 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -114,7 +114,10 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); delay(1); // Max 12-bit conversion time is 586us per sample - int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + int byte = wiringPiI2CRead(sensor.fd); + delay(1); // Max 12-bit conversion time is 586us per sample + //int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + int16_t value = (( ((int16_t)byte) << 8 ) | (int16_t)wiringPiI2CRead (sensor.fd)); float value1 = (float) value; data.current = value1 / (float)sensor.currentDivider; printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current); From ffcaff8c2d8b054fb927ede64f814878e4e7ae51 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 10:43:16 -0400 Subject: [PATCH 112/194] another change --- afsk/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index ed6db849..a8a878d0 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -117,7 +117,8 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { int byte = wiringPiI2CRead(sensor.fd); delay(1); // Max 12-bit conversion time is 586us per sample //int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); - int16_t value = (( ((int16_t)byte) << 8 ) | (int16_t)wiringPiI2CRead (sensor.fd)); + //int16_t value = (( ((int16_t)byte) << 8 ) | (int16_t)wiringPiI2CRead (sensor.fd)); + int16_t value = (int16_t)(( ((uint16_t)byte) << 8 ) | (uint16_t)wiringPiI2CRead (sensor.fd)); float value1 = (float) value; data.current = value1 / (float)sensor.currentDivider; printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current); From 55d68e0b10da1ae7dab5261edc5ea79684452ba2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 10:47:41 -0400 Subject: [PATCH 113/194] uint8_t --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index a8a878d0..5fcd8943 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -118,7 +118,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { delay(1); // Max 12-bit conversion time is 586us per sample //int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); //int16_t value = (( ((int16_t)byte) << 8 ) | (int16_t)wiringPiI2CRead (sensor.fd)); - int16_t value = (int16_t)(( ((uint16_t)byte) << 8 ) | (uint16_t)wiringPiI2CRead (sensor.fd)); + int16_t value = (int16_t)(( ((uint8_t)byte) << 8 ) | (uint8_t)wiringPiI2CRead (sensor.fd)); float value1 = (float) value; data.current = value1 / (float)sensor.currentDivider; printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current); From d40e214b39034477c3bb39f2bb96242f84a12001 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 10:52:10 -0400 Subject: [PATCH 114/194] revert --- afsk/main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 5fcd8943..177d62e0 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -110,7 +110,8 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); -// data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; + data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; +/* int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); delay(1); // Max 12-bit conversion time is 586us per sample @@ -119,9 +120,10 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { //int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); //int16_t value = (( ((int16_t)byte) << 8 ) | (int16_t)wiringPiI2CRead (sensor.fd)); int16_t value = (int16_t)(( ((uint8_t)byte) << 8 ) | (uint8_t)wiringPiI2CRead (sensor.fd)); - float value1 = (float) value; - data.current = value1 / (float)sensor.currentDivider; + float value1 = (float) value; + data.current = value1 / (float)sensor.currentDivider; printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current); +*/ uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value2 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; From cbfa6829c4a61572b810e0a235877c81bd62e80b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 10:57:36 -0400 Subject: [PATCH 115/194] printf in 3 values --- afsk/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 177d62e0..623c0709 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -110,8 +110,12 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - data.current = (float)((int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT)) / (float)sensor.currentDivider; -/* + int16_t valuec1 = (wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); + float valuec3 = (float)(valuec2); + data.current = valuec3 / (float)sensor.currentDivider; + printf("****** valuec1 %d valuec2 %f valuec3 %f \n", valuec1, valuec2, valuec3); + + /* int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); delay(1); // Max 12-bit conversion time is 586us per sample From 29cd1da1c75b1c581e490fd0f4b4518feac59d6b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:05:12 -0400 Subject: [PATCH 116/194] 3 steps --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 623c0709..55fc4471 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -110,7 +110,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int16_t valuec1 = (wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); + int16_t valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); float valuec3 = (float)(valuec2); data.current = valuec3 / (float)sensor.currentDivider; printf("****** valuec1 %d valuec2 %f valuec3 %f \n", valuec1, valuec2, valuec3); From 51868dc7390d2a05f16188f31607515850eca49a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:07:44 -0400 Subject: [PATCH 117/194] Update main.c --- afsk/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 55fc4471..b0d8fb34 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -111,9 +111,9 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); int16_t valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - float valuec3 = (float)(valuec2); - data.current = valuec3 / (float)sensor.currentDivider; - printf("****** valuec1 %d valuec2 %f valuec3 %f \n", valuec1, valuec2, valuec3); + float valuec2 = (float)(valuec1); + data.current = valuec2 / (float)sensor.currentDivider; + printf("****** valuec1 %d valuec2 %f valuec3 %f current %f\n", valuec1, valuec2, valuec3, data.current); /* int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); From f233dfb8377c3ee1a3136f93083d86885a2430a9 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:08:28 -0400 Subject: [PATCH 118/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index b0d8fb34..01e32624 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -113,7 +113,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { int16_t valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); float valuec2 = (float)(valuec1); data.current = valuec2 / (float)sensor.currentDivider; - printf("****** valuec1 %d valuec2 %f valuec3 %f current %f\n", valuec1, valuec2, valuec3, data.current); + printf("****** valuec1 %d valuec2 %f current %f\n", valuec1, valuec2, data.current); /* int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); From aefe4c9469cdaf73d0a93aec617e9b9dbb592af4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:12:03 -0400 Subject: [PATCH 119/194] 3 step --- afsk/main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 01e32624..7f99425c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -110,10 +110,11 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int16_t valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - float valuec2 = (float)(valuec1); + int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); + uint16_t valuec2 = (uint16_t)valuec1; + float valuec3 = (float)(valuec2); data.current = valuec2 / (float)sensor.currentDivider; - printf("****** valuec1 %d valuec2 %f current %f\n", valuec1, valuec2, data.current); + printf("****** valuec1 %d valuec2 %f valuec3 %f current %f\n", valuec1, valuec2, value c3, data.current); /* int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); From 8a3ad9a14f3276fcdd7dadfcff9778c356fbbe3e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:12:36 -0400 Subject: [PATCH 120/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 7f99425c..3725d461 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -114,7 +114,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { uint16_t valuec2 = (uint16_t)valuec1; float valuec3 = (float)(valuec2); data.current = valuec2 / (float)sensor.currentDivider; - printf("****** valuec1 %d valuec2 %f valuec3 %f current %f\n", valuec1, valuec2, value c3, data.current); + printf("****** valuec1 %d valuec2 %f valuec3 %f current %f\n", valuec1, valuec2, valuec3, data.current); /* int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); From 854d1ca98014fc26cd25f2141512e01fedfd46be Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:13:14 -0400 Subject: [PATCH 121/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 3725d461..a2d076ab 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -114,7 +114,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { uint16_t valuec2 = (uint16_t)valuec1; float valuec3 = (float)(valuec2); data.current = valuec2 / (float)sensor.currentDivider; - printf("****** valuec1 %d valuec2 %f valuec3 %f current %f\n", valuec1, valuec2, valuec3, data.current); + printf("****** valuec1 %d valuec2 %d valuec3 %f current %f\n", valuec1, valuec2, valuec3, data.current); /* int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); From be25eb5d88e85e8858e27e3cdf3aa914d68e9a60 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:24:29 -0400 Subject: [PATCH 122/194] two's c --- afsk/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index a2d076ab..ee85e1c3 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -112,9 +112,10 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); uint16_t valuec2 = (uint16_t)valuec1; + int twos = (2 ^ 16 - value2) * (-1); float valuec3 = (float)(valuec2); data.current = valuec2 / (float)sensor.currentDivider; - printf("****** valuec1 %d valuec2 %d valuec3 %f current %f\n", valuec1, valuec2, valuec3, data.current); + printf("****** valuec1 %d valuec2 %d valuec3 %f current %f two's %d \n", valuec1, valuec2, valuec3, data.current, twos); /* int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); From 64cff2c6c5b6e723f9a4ba01c40a5ecea225b03e Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:25:10 -0400 Subject: [PATCH 123/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index ee85e1c3..d61e48e3 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -112,7 +112,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); uint16_t valuec2 = (uint16_t)valuec1; - int twos = (2 ^ 16 - value2) * (-1); + int twos = (2 ^ 16 - valuec2) * (-1); float valuec3 = (float)(valuec2); data.current = valuec2 / (float)sensor.currentDivider; printf("****** valuec1 %d valuec2 %d valuec3 %f current %f two's %d \n", valuec1, valuec2, valuec3, data.current, twos); From 5a83e38f646e0015376016335a7e5889c1079197 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:25:54 -0400 Subject: [PATCH 124/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index d61e48e3..ae2f715c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -112,7 +112,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); uint16_t valuec2 = (uint16_t)valuec1; - int twos = (2 ^ 16 - valuec2) * (-1); + int twos = ((2 ^ 16) - valuec2) * (-1); float valuec3 = (float)(valuec2); data.current = valuec2 / (float)sensor.currentDivider; printf("****** valuec1 %d valuec2 %d valuec3 %f current %f two's %d \n", valuec1, valuec2, valuec3, data.current, twos); From 3674229adefd825575d1e0eae42d2c2f9a72aff0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:35:35 -0400 Subject: [PATCH 125/194] twosToInt --- afsk/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index ae2f715c..2aa7e9dc 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -112,7 +112,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); uint16_t valuec2 = (uint16_t)valuec1; - int twos = ((2 ^ 16) - valuec2) * (-1); + int twos = twosToInt(valuec2, 16); float valuec3 = (float)(valuec2); data.current = valuec2 / (float)sensor.currentDivider; printf("****** valuec1 %d valuec2 %d valuec3 %f current %f two's %d \n", valuec1, valuec2, valuec3, data.current, twos); @@ -416,3 +416,14 @@ int get_tlm(int tlm[][5]) { return 0; } + +int twosToInt( val, len) { // Convert twos compliment to integer + + printf("############## val: %d", val); + + if(val & (1 << len - 1)) + val = val - (1 << len); + printf("len: %d return: %d \n", len, val); + + return(val); +} From ef1961a4ff7a03196d5040a8b449404b7e0899e4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:36:22 -0400 Subject: [PATCH 126/194] Update main.c --- afsk/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/afsk/main.c b/afsk/main.c index 2aa7e9dc..816b9a03 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -56,6 +56,7 @@ ax5043_conf_t hax5043; ax25_conf_t hax25; static void init_rf(); +int twosToInt( val, len); int get_tlm(int tlm[][5]); long int timestamp; void config_x25(); From 9164aed39538cc6235069d41bba3beb725243c82 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:37:21 -0400 Subject: [PATCH 127/194] Update main.c --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 816b9a03..b2f61858 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -113,7 +113,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); uint16_t valuec2 = (uint16_t)valuec1; - int twos = twosToInt(valuec2, 16); + int twos = twosToInt(valuec1, 16); float valuec3 = (float)(valuec2); data.current = valuec2 / (float)sensor.currentDivider; printf("****** valuec1 %d valuec2 %d valuec3 %f current %f two's %d \n", valuec1, valuec2, valuec3, data.current, twos); @@ -418,7 +418,7 @@ int get_tlm(int tlm[][5]) { return 0; } -int twosToInt( val, len) { // Convert twos compliment to integer +int twosToInt(int val,int len) { // Convert twos compliment to integer printf("############## val: %d", val); From b6f6fb80927014cd63eb41f4a0ee7e3558663b07 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:38:14 -0400 Subject: [PATCH 128/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index b2f61858..e607c3ad 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -422,7 +422,7 @@ int twosToInt(int val,int len) { // Convert twos compliment to integer printf("############## val: %d", val); - if(val & (1 << len - 1)) + if(val & (1 << (len - 1))) val = val - (1 << len); printf("len: %d return: %d \n", len, val); From dcbaf2ea98103c1adcf532fb22f1cf13ed0aa8a5 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:38:51 -0400 Subject: [PATCH 129/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index e607c3ad..68950ac1 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -56,7 +56,7 @@ ax5043_conf_t hax5043; ax25_conf_t hax25; static void init_rf(); -int twosToInt( val, len); +int twosToInt(int val, int len); int get_tlm(int tlm[][5]); long int timestamp; void config_x25(); From 8399d4ebfb549c703d774e22a2b35d44dc22536a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:41:08 -0400 Subject: [PATCH 130/194] use twos --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 68950ac1..5cfee176 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -114,7 +114,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); uint16_t valuec2 = (uint16_t)valuec1; int twos = twosToInt(valuec1, 16); - float valuec3 = (float)(valuec2); + float valuec3 = (float)(twos); data.current = valuec2 / (float)sensor.currentDivider; printf("****** valuec1 %d valuec2 %d valuec3 %f current %f two's %d \n", valuec1, valuec2, valuec3, data.current, twos); From c2d331fbd838cacdbf331e9dd8f2be65b3381514 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:43:19 -0400 Subject: [PATCH 131/194] fix current calc --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 5cfee176..e952545f 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -115,7 +115,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { uint16_t valuec2 = (uint16_t)valuec1; int twos = twosToInt(valuec1, 16); float valuec3 = (float)(twos); - data.current = valuec2 / (float)sensor.currentDivider; + data.current = valuec3 / (float)sensor.currentDivider; printf("****** valuec1 %d valuec2 %d valuec3 %f current %f two's %d \n", valuec1, valuec2, valuec3, data.current, twos); /* From 757321b085d71cae74783b5c5cd5942837180eb8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Tue, 23 Jul 2019 11:48:13 -0400 Subject: [PATCH 132/194] removed extra printfs --- afsk/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index e952545f..2624e485 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -112,11 +112,11 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - uint16_t valuec2 = (uint16_t)valuec1; + //uint16_t valuec2 = (uint16_t)valuec1; int twos = twosToInt(valuec1, 16); float valuec3 = (float)(twos); data.current = valuec3 / (float)sensor.currentDivider; - printf("****** valuec1 %d valuec2 %d valuec3 %f current %f two's %d \n", valuec1, valuec2, valuec3, data.current, twos); + //printf("****** valuec1 %d valuec2 %d valuec3 %f current %f two's %d \n", valuec1, valuec2, valuec3, data.current, twos); /* int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); @@ -419,12 +419,13 @@ int get_tlm(int tlm[][5]) { } int twosToInt(int val,int len) { // Convert twos compliment to integer +// from https://www.raspberrypi.org/forums/viewtopic.php?t=55815 - printf("############## val: %d", val); +// printf("############## val: %d", val); if(val & (1 << (len - 1))) val = val - (1 << len); - printf("len: %d return: %d \n", len, val); +// printf("len: %d return: %d \n", len, val); return(val); } From e0f01d9b8ec6e68fa51c1083ccfb5e4480c7142f Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 02:48:53 -0400 Subject: [PATCH 133/194] reading shunt voltage and manually calculating current --- afsk/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/afsk/main.c b/afsk/main.c index 2624e485..44a1fc93 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -131,6 +131,11 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { data.current = value1 / (float)sensor.currentDivider; printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current); */ + valuec1 = wireReadRegister(sensor.fd, INA219_REG_SHUNTVOLTAGE); + twos = twosToInt(valuec1, 16); + valuec3 = ((float)twos)/sensor.calValue); + printf("@@@@@@@ Register: %d Shunt: %d Calc Current: %f \n", valuec1, twos, valuec3); + uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value2 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; From 2719d43034f91eddf4a144d0452cdb066fdeb233 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 02:49:48 -0400 Subject: [PATCH 134/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 44a1fc93..aa566a71 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -133,7 +133,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { */ valuec1 = wireReadRegister(sensor.fd, INA219_REG_SHUNTVOLTAGE); twos = twosToInt(valuec1, 16); - valuec3 = ((float)twos)/sensor.calValue); + valuec3 = ((float)twos)/sensor.calValue; printf("@@@@@@@ Register: %d Shunt: %d Calc Current: %f \n", valuec1, twos, valuec3); uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); From 83522ab8f1114066ddcc14e2fe0b09f88826c806 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 02:51:28 -0400 Subject: [PATCH 135/194] fixed shunt calc --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index aa566a71..2f48ceec 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -133,7 +133,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { */ valuec1 = wireReadRegister(sensor.fd, INA219_REG_SHUNTVOLTAGE); twos = twosToInt(valuec1, 16); - valuec3 = ((float)twos)/sensor.calValue; + valuec3 = ((float)twos) * sensor.calValue; printf("@@@@@@@ Register: %d Shunt: %d Calc Current: %f \n", valuec1, twos, valuec3); uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); From b3160db85c268e965916113a268fc63cdf9fc410 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 02:52:41 -0400 Subject: [PATCH 136/194] Tried 12 bits --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 2f48ceec..031fc4bd 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -132,7 +132,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current); */ valuec1 = wireReadRegister(sensor.fd, INA219_REG_SHUNTVOLTAGE); - twos = twosToInt(valuec1, 16); + twos = twosToInt(valuec1, 12); valuec3 = ((float)twos) * sensor.calValue; printf("@@@@@@@ Register: %d Shunt: %d Calc Current: %f \n", valuec1, twos, valuec3); From 4f278865a3a474028088e451f2bc5548eb5ab3ae Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 02:54:57 -0400 Subject: [PATCH 137/194] back to 16, fixed current shunt calc --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 031fc4bd..f2cb53c2 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -132,8 +132,8 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current); */ valuec1 = wireReadRegister(sensor.fd, INA219_REG_SHUNTVOLTAGE); - twos = twosToInt(valuec1, 12); - valuec3 = ((float)twos) * sensor.calValue; + twos = twosToInt(valuec1, 16); + valuec3 = ((float)twos) * (float) sensor.calValue / 4096.0; printf("@@@@@@@ Register: %d Shunt: %d Calc Current: %f \n", valuec1, twos, valuec3); uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); From 55c17eb66d43df08337b7653a1bc1550bfb76955 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 03:15:08 -0400 Subject: [PATCH 138/194] cleanup --- afsk/main.c | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index f2cb53c2..49b0174d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -85,18 +85,17 @@ struct SensorData { double power; }; - /** * @brief Read the data from one of the i2c current sensors. * - * Reads the current data from the requested i2c current sensor and + * Reads the current data from the requested i2c current sensor configuration and * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) * results in a SensorData struct being returned that has both its #current and #power members * set to NAN. * - * - * @param sensor A file descriptor that can be used to read from the sensor. - * @return struct SensorData A struct that contains the power and current reading from the requested sensor. + * @param sensor A structure containing sensor configuration including the file descriptor. + * @return struct SensorData A struct that contains the current, voltage, and power readings + * from the requested sensor. */ struct SensorData read_sensor_data(struct SensorConfig sensor) { struct SensorData data = { @@ -112,36 +111,27 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - //uint16_t valuec2 = (uint16_t)valuec1; - int twos = twosToInt(valuec1, 16); + int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly float valuec3 = (float)(twos); data.current = valuec3 / (float)sensor.currentDivider; - //printf("****** valuec1 %d valuec2 %d valuec3 %f current %f two's %d \n", valuec1, valuec2, valuec3, data.current, twos); - - /* - int16_t value0 = 1; // (int16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); - delay(1); // Max 12-bit conversion time is 586us per sample - int byte = wiringPiI2CRead(sensor.fd); - delay(1); // Max 12-bit conversion time is 586us per sample - //int16_t value = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); - //int16_t value = (( ((int16_t)byte) << 8 ) | (int16_t)wiringPiI2CRead (sensor.fd)); - int16_t value = (int16_t)(( ((uint8_t)byte) << 8 ) | (uint8_t)wiringPiI2CRead (sensor.fd)); - float value1 = (float) value; - data.current = value1 / (float)sensor.currentDivider; - printf("********* value0 %d value1 %f value %d data.current %f \n", value0, value1, value, data.current); -*/ - valuec1 = wireReadRegister(sensor.fd, INA219_REG_SHUNTVOLTAGE); - twos = twosToInt(valuec1, 16); - valuec3 = ((float)twos) * (float) sensor.calValue / 4096.0; - printf("@@@@@@@ Register: %d Shunt: %d Calc Current: %f \n", valuec1, twos, valuec3); - uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value2 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; return data; } + +/** + * @brief Configures an i2c current sensor. + * + * Calculates the configuration values of the i2c sensor so that + * current, voltage, and power can be read using read_sensor_data. + * Supports 16V 400mA and 16V 2.0A settings. + * + * @param sensor A file descriptor that can be used to read from the sensor. + * @param milliAmps The mA configuration, either 400mA or 2A are supported. + * @return struct SensorConfig A struct that contains the configuraton of the sensor. + */ struct SensorConfig config_sensor(int sensor, int milliAmps) { struct SensorConfig data; From 02ea0b9fca7c664768996c9315ec09b3618db95a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 03:20:17 -0400 Subject: [PATCH 139/194] cleanup --- afsk/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 49b0174d..b0c2e8be 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -17,6 +17,9 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see . + * + * INA219 Raspberry Pi wiringPi code is based on Adafruit Arduino wire code + * from https://github.com/adafruit/Adafruit_INA219. */ #include @@ -32,7 +35,7 @@ #include #include #include -#include "../Adafruit_INA219/Adafruit_INA219.h" // From Adafruit INA219 library for Arduino +#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino #define A 1 #define B 2 @@ -416,11 +419,8 @@ int get_tlm(int tlm[][5]) { int twosToInt(int val,int len) { // Convert twos compliment to integer // from https://www.raspberrypi.org/forums/viewtopic.php?t=55815 -// printf("############## val: %d", val); - if(val & (1 << (len - 1))) val = val - (1 << len); -// printf("len: %d return: %d \n", len, val); return(val); } From c9858eb37b5fa2aadb4bb6b41b1a6773359b5499 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 03:23:21 -0400 Subject: [PATCH 140/194] removed Adafruit_INA219.c as no longer used --- Makefile | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 0fb5a0d4..b1963206 100644 --- a/Makefile +++ b/Makefile @@ -89,14 +89,8 @@ radioafsk: libax5043.a radioafsk: afsk/ax25.o radioafsk: afsk/ax5043.o radioafsk: afsk/main.o -radioafsk: afsk/ina219.h -radioafsk: Adafruit_INA219/Adafruit_INA219.o -radioafsk: Adafruit_INA219/Adafruit_INA219.h - gcc $(DEBUG_BEHAVIOR) -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o Adafruit_INA219/Adafruit_INA219.o -lwiringPi -lax5043 -lcurl - -Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.c -Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.h - cd Adafruit_INA219; gcc $(DEBUG_BEHAVIOR) -I -pedantic -Wconversion -Wall -Wextra -c Adafruit_INA219.c; cd .. +radioafsk: Adafruit_INA219.h + gcc $(DEBUG_BEHAVIOR) -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o -lwiringPi -lax5043 -lcurl ax5043/generated/configcommon.o: ax5043/generated/configcommon.c ax5043/generated/configcommon.o: ax5043/generated/configrx.h From 8b0c90e827a03b38420734b812593c61f22d8b4c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 03:27:45 -0400 Subject: [PATCH 141/194] fixed Adadfruit_INA219.h handling --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b1963206..3831255d 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,6 @@ radioafsk: libax5043.a radioafsk: afsk/ax25.o radioafsk: afsk/ax5043.o radioafsk: afsk/main.o -radioafsk: Adafruit_INA219.h gcc $(DEBUG_BEHAVIOR) -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o -lwiringPi -lax5043 -lcurl ax5043/generated/configcommon.o: ax5043/generated/configcommon.c @@ -231,6 +230,7 @@ afsk/main.o: afsk/status.h afsk/main.o: afsk/ax5043.h afsk/main.o: afsk/ax25.h afsk/main.o: ax5043/spi/ax5043spi.h +afsk/main.o: afsk/Adafruit_INA219.h cd afsk; gcc -std=gnu99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c main.c; cd .. afsk/send_afsk.o: afsk/send_afsk.c From 38110e17c7a6bd5d325ee4a2d0ce90829723bc25 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 03:29:58 -0400 Subject: [PATCH 142/194] replaced last wireReadRegister with wiringPiI2CReadReg16 --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index b0c2e8be..42b49265 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -117,7 +117,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly float valuec3 = (float)(twos); data.current = valuec3 / (float)sensor.currentDivider; - uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); + uint16_t value2 = (uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value2 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; From 9420a0b4d77934a4bea670396dce08946e8b1be2 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 03:37:42 -0400 Subject: [PATCH 143/194] fixing voltage read problem --- afsk/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 42b49265..1d6af9d2 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -117,8 +117,11 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly float valuec3 = (float)(twos); data.current = valuec3 / (float)sensor.currentDivider; - uint16_t value2 = (uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_BUSVOLTAGE); - data.voltage = ((double)(value2 >> 3) * 4) / 1000; +// uint16_t value2 = (uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_BUSVOLTAGE); +// data.voltage = ((double)(value2 >> 3) * 4) / 1000; + valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_BUSVOLTAGE); + data.voltage = ((double)((uint16_t)valuec1 >> 3) * 4) / 1000; + data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; return data; From 3efa5c1b62e107915b2e11c477a82c1e225d0a2d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 03:47:04 -0400 Subject: [PATCH 144/194] reverted Adafruit removal --- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3831255d..56d8fe56 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,12 @@ radioafsk: libax5043.a radioafsk: afsk/ax25.o radioafsk: afsk/ax5043.o radioafsk: afsk/main.o - gcc $(DEBUG_BEHAVIOR) -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o -lwiringPi -lax5043 -lcurl +radioafsk: Adafruit_INA219/Adafruit_INA219.o + gcc $(DEBUG_BEHAVIOR) -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o Adafruit_INA219/Adafruit_INA219.o -lwiringPi -lax5043 -lcurl + +Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.c +Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.h + cd Adafruit_INA219; gcc $(DEBUG_BEHAVIOR) -I -pedantic -Wconversion -Wall -Wextra -c Adafruit_INA219.c; cd .. ax5043/generated/configcommon.o: ax5043/generated/configcommon.c ax5043/generated/configcommon.o: ax5043/generated/configrx.h @@ -230,7 +235,7 @@ afsk/main.o: afsk/status.h afsk/main.o: afsk/ax5043.h afsk/main.o: afsk/ax25.h afsk/main.o: ax5043/spi/ax5043spi.h -afsk/main.o: afsk/Adafruit_INA219.h +afsk/main.o: Adafruit_INA219/Adafruit_INA219.h cd afsk; gcc -std=gnu99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c main.c; cd .. afsk/send_afsk.o: afsk/send_afsk.c From 16478e9d0bc86be82ecd6de4ac3cdb9eb2c86843 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 03:49:55 -0400 Subject: [PATCH 145/194] reverted removal of wireReadRegister --- afsk/main.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 1d6af9d2..9ef41aa5 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -35,7 +35,7 @@ #include #include #include -#include "Adafruit_INA219.h" // From Adafruit INA219 library for Arduino +#include "../Adafruit_INA219/Adafruit_INA219.h" // From Adafruit INA219 library for Arduino #define A 1 #define B 2 @@ -117,11 +117,8 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly float valuec3 = (float)(twos); data.current = valuec3 / (float)sensor.currentDivider; -// uint16_t value2 = (uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_BUSVOLTAGE); -// data.voltage = ((double)(value2 >> 3) * 4) / 1000; - valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_BUSVOLTAGE); - data.voltage = ((double)((uint16_t)valuec1 >> 3) * 4) / 1000; - + uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); + data.voltage = ((double)(value2 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; return data; From c7c630042938ec0f964256d89f4539fc93415f39 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 03:56:55 -0400 Subject: [PATCH 146/194] wireReadRegister for current change --- afsk/main.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 9ef41aa5..042d8858 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -113,10 +113,15 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly - float valuec3 = (float)(twos); - data.current = valuec3 / (float)sensor.currentDivider; +// int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); +// int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly +// float valuec3 = (float)(twos); +// data.current = valuec3 / (float)sensor.currentDivider; + + uint16_t valuex = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_CURRENT); + data.current = (double)valuex / (double)sensor.currentDivider; + + uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value2 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; From 7d79af0af9aaccdb7824af3587eff618d509b31d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 04:04:38 -0400 Subject: [PATCH 147/194] copied code from wireRead but with int16_t --- afsk/main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 042d8858..59b167e9 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -118,9 +118,13 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { // float valuec3 = (float)(twos); // data.current = valuec3 / (float)sensor.currentDivider; - uint16_t valuex = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_CURRENT); + wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); + delay(1); // Max 12-bit conversion time is 586us per sample + int16_t valuex = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + +// uint16_t valuex = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_CURRENT); data.current = (double)valuex / (double)sensor.currentDivider; - + printf("&&&&&&&& valuex %d current %f \n", valuex, data.current); uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value2 >> 3) * 4) / 1000; From 751da0655e0e52301f5f9062f513d43d9509ed45 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 04:08:39 -0400 Subject: [PATCH 148/194] separate value1 and value2 byte reads --- afsk/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 59b167e9..686267b1 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -120,11 +120,13 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); delay(1); // Max 12-bit conversion time is 586us per sample - int16_t valuex = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + int value1 = wiringPiI2CRead(sensor.fd); + int value2 = wiringPiI2CRead(sensor.fd); + int16_t valuex = (int16_t)(value1 << 8 ) | value2); // uint16_t valuex = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_CURRENT); data.current = (double)valuex / (double)sensor.currentDivider; - printf("&&&&&&&& valuex %d current %f \n", valuex, data.current); + printf("&&&&&&&& value1 %d value2 %d valuex %d current %f \n", value1, value2, valuex, data.current); uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value2 >> 3) * 4) / 1000; From af3c96f3c3a54a1232c3c71d76172a042b194ffc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 04:09:54 -0400 Subject: [PATCH 149/194] fixed typo --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 686267b1..b209f05d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -122,7 +122,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { delay(1); // Max 12-bit conversion time is 586us per sample int value1 = wiringPiI2CRead(sensor.fd); int value2 = wiringPiI2CRead(sensor.fd); - int16_t valuex = (int16_t)(value1 << 8 ) | value2); + int16_t valuex = (int16_t)((value1 << 8) | value2); // uint16_t valuex = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_CURRENT); data.current = (double)valuex / (double)sensor.currentDivider; From 0f9e1e0835b7ba9796d0996853cd27ee88c5805c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 04:11:01 -0400 Subject: [PATCH 150/194] typo --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index b209f05d..7493dbca 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -128,8 +128,8 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { data.current = (double)valuex / (double)sensor.currentDivider; printf("&&&&&&&& value1 %d value2 %d valuex %d current %f \n", value1, value2, valuex, data.current); - uint16_t value2 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); - data.voltage = ((double)(value2 >> 3) * 4) / 1000; + uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); + data.voltage = ((double)(value3 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; return data; From f7cf243f36acd1760ab75c6fba505b7ee35a4b30 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 04:49:46 -0400 Subject: [PATCH 151/194] reverted to previously working with wireRead --- afsk/main.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 7493dbca..436b7d74 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -113,21 +113,10 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); -// int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); -// int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly -// float valuec3 = (float)(twos); -// data.current = valuec3 / (float)sensor.currentDivider; - - wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); - delay(1); // Max 12-bit conversion time is 586us per sample - int value1 = wiringPiI2CRead(sensor.fd); - int value2 = wiringPiI2CRead(sensor.fd); - int16_t valuex = (int16_t)((value1 << 8) | value2); - -// uint16_t valuex = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_CURRENT); - data.current = (double)valuex / (double)sensor.currentDivider; - printf("&&&&&&&& value1 %d value2 %d valuex %d current %f \n", value1, value2, valuex, data.current); - + int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); + int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly + float valuec3 = (float)(twos); + data.current = valuec3 / (float)sensor.currentDivider; uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); data.voltage = ((double)(value3 >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; From 647a746081e1cb571eb3d65c673df28a2e8d32b4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 06:02:31 -0400 Subject: [PATCH 152/194] removing wireRead by including code --- afsk/main.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 436b7d74..78f0fa89 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -117,9 +117,26 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly float valuec3 = (float)(twos); data.current = valuec3 / (float)sensor.currentDivider; - uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); - data.voltage = ((double)(value3 >> 3) * 4) / 1000; - data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; + +// uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); +// data.voltage = ((double)(value3 >> 3) * 4) / 1000; + + value; + + // _i2c->beginTransmission(ina219_i2caddr); + // _i2c->write(reg); // Register + // _i2c->endTransmission(); + wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); + + delay(1); // Max 12-bit conversion time is 586us per sample + + // _i2c->requestFrom(ina219_i2caddr, (uint8_t)2); + // Shift values to create properly formed integer + // *value = ((_i2c->read() << 8) | _i2c->read()); + uint16_t valueV = (uint16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + data.voltage = ((double)(valueV >> 3) * 4) / 1000; + + data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; return data; } From 4bcd29327ee40f99bed872445c0ce1d31010b877 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 06:03:20 -0400 Subject: [PATCH 153/194] typo --- afsk/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 78f0fa89..4d48efef 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -121,9 +121,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { // uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); // data.voltage = ((double)(value3 >> 3) * 4) / 1000; - value; - - // _i2c->beginTransmission(ina219_i2caddr); + // _i2c->beginTransmission(ina219_i2caddr); // _i2c->write(reg); // Register // _i2c->endTransmission(); wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); From c2c56d3944fbcca79166447fb6067a60ace38637 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 06:07:13 -0400 Subject: [PATCH 154/194] cleanup after paste and replacing current code too --- afsk/main.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 4d48efef..a1b93c92 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -113,25 +113,24 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly - float valuec3 = (float)(twos); + +// int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); +// int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly +// float valuec3 = (float)(twos); + + wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); + delay(1); // Max 12-bit conversion time is 586us per sample + int16_t valueC = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + + float valuec3 = (float)(valueC); data.current = valuec3 / (float)sensor.currentDivider; // uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); // data.voltage = ((double)(value3 >> 3) * 4) / 1000; - // _i2c->beginTransmission(ina219_i2caddr); - // _i2c->write(reg); // Register - // _i2c->endTransmission(); - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); - - delay(1); // Max 12-bit conversion time is 586us per sample - - // _i2c->requestFrom(ina219_i2caddr, (uint8_t)2); - // Shift values to create properly formed integer - // *value = ((_i2c->read() << 8) | _i2c->read()); - uint16_t valueV = (uint16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); + delay(1); // Max 12-bit conversion time is 586us per sample + uint16_t valueV = (uint16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); data.voltage = ((double)(valueV >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; From 200b33ed85758ea3802f30ee4c38e86678666ec8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 06:09:56 -0400 Subject: [PATCH 155/194] tried 2'c complement manual --- afsk/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index a1b93c92..e6019861 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -120,9 +120,9 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); delay(1); // Max 12-bit conversion time is 586us per sample - int16_t valueC = (int16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); - - float valuec3 = (float)(valueC); + int valueC = ((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); + int twos = twosToInt(valueC, 16); + float valuec3 = (float)(twos); data.current = valuec3 / (float)sensor.currentDivider; // uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); From 6a51214407f6e3b222599f5c031d1063cf17bb5d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 06:12:36 -0400 Subject: [PATCH 156/194] 50ms delay --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index e6019861..4b65bb8e 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -117,7 +117,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { // int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); // int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly // float valuec3 = (float)(twos); - + delay(50); wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); delay(1); // Max 12-bit conversion time is 586us per sample int valueC = ((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); From bc9d9125e8cbba7ab00656ef3e81186ead69161c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 06:13:33 -0400 Subject: [PATCH 157/194] Update main.c --- afsk/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 4b65bb8e..5012e747 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -134,7 +134,6 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { data.voltage = ((double)(valueV >> 3) * 4) / 1000; data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; - return data; } From ad35fdedbabe6358127e781df965b479d4bbbaed Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 06:15:58 -0400 Subject: [PATCH 158/194] Update main.c --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 5012e747..c2510b1d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -119,7 +119,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { // float valuec3 = (float)(twos); delay(50); wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); - delay(1); // Max 12-bit conversion time is 586us per sample + delay(50); // Max 12-bit conversion time is 586us per sample int valueC = ((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); int twos = twosToInt(valueC, 16); float valuec3 = (float)(twos); From d3e546fba5aec35cf636a1a282dfb3a05f91a3be Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 06:17:43 -0400 Subject: [PATCH 159/194] reverted current read --- afsk/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index c2510b1d..03505029 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -114,15 +114,15 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); -// int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); -// int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly -// float valuec3 = (float)(twos); - delay(50); - wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); - delay(50); // Max 12-bit conversion time is 586us per sample - int valueC = ((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); - int twos = twosToInt(valueC, 16); + int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); + int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly float valuec3 = (float)(twos); +// delay(50); +// wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); +// delay(50); // Max 12-bit conversion time is 586us per sample +// int valueC = ((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); +// int twos = twosToInt(valueC, 16); +// float valuec3 = (float)(twos); data.current = valuec3 / (float)sensor.currentDivider; // uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); From 8e98c1be1932429aeeeee86f657043fbfead6f16 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 08:11:57 -0400 Subject: [PATCH 160/194] cleaned up current, voltage, and power readings --- afsk/main.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 03505029..14c6585d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -114,26 +114,31 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); - int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly - float valuec3 = (float)(twos); +// int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); +// int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly +// float valuec3 = (float)(twos); + // delay(50); // wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); // delay(50); // Max 12-bit conversion time is 586us per sample // int valueC = ((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); // int twos = twosToInt(valueC, 16); // float valuec3 = (float)(twos); - data.current = valuec3 / (float)sensor.currentDivider; +// data.current = valuec3 / (float)sensor.currentDivider; + int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); + data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; // uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); // data.voltage = ((double)(value3 >> 3) * 4) / 1000; wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); delay(1); // Max 12-bit conversion time is 586us per sample - uint16_t valueV = (uint16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); - data.voltage = ((double)(valueV >> 3) * 4) / 1000; +// uint16_t valueV = (uint16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); +// data.voltage = ((double)(valueV >> 3) * 4) / 1000; + value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); + data.voltage = ((float)(value >> 3) * 4) / 1000; - data.power = (float)((uint16_t)wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER)) * (float)sensor.powerMultiplier; + data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; return data; } From a9df2d2b3815f40925965152b83cdd98f3ef4f0b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 08:20:33 -0400 Subject: [PATCH 161/194] changed power reading --- afsk/main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 14c6585d..fbced484 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -138,7 +138,12 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); data.voltage = ((float)(value >> 3) * 4) / 1000; - data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; +// data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; + + wiringPiI2CWrite(sensor.fd, INA219_REG_POWER); + delay(1); // Max 12-bit conversion time is 586us per sample + value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); + data.power = (float) value * (float) sensor.powerMultiplier; return data; } From d7fb15541d8a0b0df3709bf0a6e504a6e5911a20 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 08:22:06 -0400 Subject: [PATCH 162/194] added calc write before power --- afsk/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index fbced484..5cc47ba4 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -139,7 +139,8 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { data.voltage = ((float)(value >> 3) * 4) / 1000; // data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - + a + wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWrite(sensor.fd, INA219_REG_POWER); delay(1); // Max 12-bit conversion time is 586us per sample value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); From 52819fa7adc95d97353c334a013bdaaeb086090c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 08:22:43 -0400 Subject: [PATCH 163/194] a --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 5cc47ba4..7da0a81c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -139,7 +139,7 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { data.voltage = ((float)(value >> 3) * 4) / 1000; // data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - a + wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWrite(sensor.fd, INA219_REG_POWER); delay(1); // Max 12-bit conversion time is 586us per sample From f0849cd11d14c1d7f4c39630fc51eb498d0defa6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 08:24:30 -0400 Subject: [PATCH 164/194] added calc and config --- afsk/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 7da0a81c..cce7a415 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -139,7 +139,8 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { data.voltage = ((float)(value >> 3) * 4) / 1000; // data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - + wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); + wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWrite(sensor.fd, INA219_REG_POWER); delay(1); // Max 12-bit conversion time is 586us per sample From a931999042c3850d2fbb14de6fff7821fc273b17 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 08:26:30 -0400 Subject: [PATCH 165/194] swapped order of voltage and power reading --- afsk/main.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index cce7a415..a7242c2a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -131,13 +131,6 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { // uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); // data.voltage = ((double)(value3 >> 3) * 4) / 1000; - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); - delay(1); // Max 12-bit conversion time is 586us per sample -// uint16_t valueV = (uint16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); -// data.voltage = ((double)(valueV >> 3) * 4) / 1000; - value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.voltage = ((float)(value >> 3) * 4) / 1000; - // data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); @@ -146,6 +139,16 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { delay(1); // Max 12-bit conversion time is 586us per sample value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); data.power = (float) value * (float) sensor.powerMultiplier; + + wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); + delay(1); // Max 12-bit conversion time is 586us per sample +// uint16_t valueV = (uint16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); +// data.voltage = ((double)(valueV >> 3) * 4) / 1000; + value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); + data.voltage = ((float)(value >> 3) * 4) / 1000; + + + return data; } From 550d93b61511809713746316565546c27ef2f6ed Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 08:31:53 -0400 Subject: [PATCH 166/194] reset --- afsk/main.c | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index a7242c2a..258e09cb 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -109,46 +109,20 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { if (sensor.fd < 0) { return data; } - + // doesn't read negative currents accurately, shows -0.1mA wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - -// int valuec1 = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); -// int twos = twosToInt(valuec1, 16); // currently doesn't read negative currents correctly -// float valuec3 = (float)(twos); - -// delay(50); -// wiringPiI2CWrite(sensor.fd, INA219_REG_CURRENT); -// delay(50); // Max 12-bit conversion time is 586us per sample -// int valueC = ((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); -// int twos = twosToInt(valueC, 16); -// float valuec3 = (float)(twos); -// data.current = valuec3 / (float)sensor.currentDivider; int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; -// uint16_t value3 = (uint16_t)wireReadRegister(sensor.fd, INA219_REG_BUSVOLTAGE); -// data.voltage = ((double)(value3 >> 3) * 4) / 1000; - -// data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); - wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); - wiringPiI2CWrite(sensor.fd, INA219_REG_POWER); - delay(1); // Max 12-bit conversion time is 586us per sample - value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.power = (float) value * (float) sensor.powerMultiplier; - wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); delay(1); // Max 12-bit conversion time is 586us per sample -// uint16_t valueV = (uint16_t)((wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd)); -// data.voltage = ((double)(valueV >> 3) * 4) / 1000; value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); - data.voltage = ((float)(value >> 3) * 4) / 1000; - - - + data.voltage = ((float)(value >> 3) * 4) / 1000; + // power has very low resolution, seems to step in 512mW values + data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; + return data; } From 95b816e9aa5e6319dfe594438c0d03107555d019 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 09:08:49 -0400 Subject: [PATCH 167/194] rewrote confg_sensor --- afsk/main.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 258e09cb..9b5e644a 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -72,7 +72,7 @@ int upper_digit(int number); int lower_digit(int number); int charging = 0; -uint16_t x_config = (0x2000 | 0x1800 | 0x0180 | 0x0018 | 0x0007 ); +//uint16_t x_config = (0x2000 | 0x1800 | 0x0180 | 0x0018 | 0x0007 ); struct SensorConfig { int fd; @@ -137,10 +137,17 @@ struct SensorData read_sensor_data(struct SensorConfig sensor) { * @param milliAmps The mA configuration, either 400mA or 2A are supported. * @return struct SensorConfig A struct that contains the configuraton of the sensor. */ -struct SensorConfig config_sensor(int sensor, int milliAmps) { +//struct SensorConfig config_sensor(int sensor, int milliAmps) { +struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { struct SensorConfig data; - data.fd = sensor; + if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing + data.fd = OFF; + return (data); + } + + data.fd = wiringPiI2CSetupInterface(bus, address); + data.config = INA219_CONFIG_BVOLTAGERANGE_32V | INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT | @@ -198,17 +205,27 @@ int main(int argc, char *argv[]) { #ifdef DEBUG_LOGGING fprintf(stderr,"tempSensor: %d \n",tempSensor); #endif - + + sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); + sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); + sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); + sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); + sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2400); + sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); + sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); + sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); + +/* int test; if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present { - close(test); + close(test); sensor[PLUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x40), 400); sensor[PLUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x41), 400); sensor[PLUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x44), 400); sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45), 400); sensor[BUS] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a), 2400); - } else +} else { printf("ERROR: /dev/i2c-1 not present \n"); sensor[PLUS_X] = config_sensor(OFF, 0); @@ -223,7 +240,6 @@ int main(int argc, char *argv[]) { sensor[MINUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x40), 400); sensor[MINUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x41), 400); sensor[MINUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x44), 400); - } else { printf("ERROR: /dev/i2c-0 not present \n"); @@ -231,7 +247,8 @@ int main(int argc, char *argv[]) { sensor[MINUS_Y] = config_sensor(OFF, 0); sensor[MINUS_Z] = config_sensor(OFF, 0); } - #ifdef DEBUG_LOGGING +*/ +#ifdef DEBUG_LOGGING printf("Sensor[0] config %d %d %d %d %d\n", sensor[0].fd, sensor[0].config, sensor[0].calValue, sensor[0].currentDivider, sensor[0].powerMultiplier); printf("Sensor[BUS] config %d %d %d %d %d\n", From 598dcbb2a1264d42c4a5af20f8e390147e9f053b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 09:16:51 -0400 Subject: [PATCH 168/194] simplified configuration --- afsk/main.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 9b5e644a..dc2e4922 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -142,6 +142,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { struct SensorConfig data; if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing + printf("ERROR: % bus not present \n", bus); data.fd = OFF; return (data); } @@ -164,6 +165,11 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { data.powerMultiplier = 2; data.currentDivider = 10; // 20; in Adafruit config } + + #ifdef DEBUG_LOGGING + printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd + data.config, data.calValue, data.currentDivider, data.powerMultiplier); + #endif return data; } @@ -191,6 +197,8 @@ int main(int argc, char *argv[]) { timestamp = time(NULL); + tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); +/* int file_i2c = access("/dev/i2c-3", W_OK | R_OK); if (file_i2c < 0) @@ -201,7 +209,8 @@ int main(int argc, char *argv[]) { { tempSensor = wiringPiI2CSetupInterface("/dev/i2c-3", 0x48); } - +*/ + #ifdef DEBUG_LOGGING fprintf(stderr,"tempSensor: %d \n",tempSensor); #endif @@ -248,13 +257,6 @@ int main(int argc, char *argv[]) { sensor[MINUS_Z] = config_sensor(OFF, 0); } */ -#ifdef DEBUG_LOGGING - printf("Sensor[0] config %d %d %d %d %d\n", - sensor[0].fd, sensor[0].config, sensor[0].calValue, sensor[0].currentDivider, sensor[0].powerMultiplier); - printf("Sensor[BUS] config %d %d %d %d %d\n", - sensor[BUS].fd, sensor[BUS].config, sensor[BUS].calValue, sensor[BUS].currentDivider, sensor[BUS].powerMultiplier); - #endif - int ret; uint8_t data[1024]; From a1607d6eb316c7ae978d45b51ed0533095b161cc Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 09:17:53 -0400 Subject: [PATCH 169/194] typos --- afsk/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index dc2e4922..18a8bf99 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -142,7 +142,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { struct SensorConfig data; if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing - printf("ERROR: % bus not present \n", bus); + printf("ERROR: %s bus not present \n", bus); data.fd = OFF; return (data); } @@ -167,7 +167,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { } #ifdef DEBUG_LOGGING - printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd + printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, data.config, data.calValue, data.currentDivider, data.powerMultiplier); #endif return data; From 81a605c3a6d110f0ef1bb8be6662e31db0469cd8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 09:22:21 -0400 Subject: [PATCH 170/194] changed tempSensor into struct --- afsk/main.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 18a8bf99..827decab 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -65,9 +65,6 @@ long int timestamp; void config_x25(); void trans_x25(); -//long int timestamp; -int tempSensor; - int upper_digit(int number); int lower_digit(int number); int charging = 0; @@ -175,6 +172,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 +struct tempSensor; char src_addr[5] = ""; char dest_addr[5] = "CQ"; @@ -210,11 +208,11 @@ int main(int argc, char *argv[]) { tempSensor = wiringPiI2CSetupInterface("/dev/i2c-3", 0x48); } */ - +/* #ifdef DEBUG_LOGGING fprintf(stderr,"tempSensor: %d \n",tempSensor); #endif - +*/ sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); @@ -393,8 +391,8 @@ int get_tlm(int tlm[][5]) { tlm[3][A] = abs((int)((reading[BAT].voltage * 10.0) - 65.5) % 100); tlm[3][B] = (int)(reading[BUS].voltage * 10.0) % 100; // 5V supply to Pi - if (tempSensor != OFF) { - int tempValue = wiringPiI2CReadReg16(tempSensor, 0); + if (tempSensor.fd != OFF) { + int tempValue = wiringPiI2CReadReg16(tempSensor.fd, 0); uint8_t upper = (uint8_t) (tempValue >> 8); uint8_t lower = (uint8_t) (tempValue & 0xff); float temp = (float)lower + ((float)upper / 0x100); From 211c94a92268f3930f6ca8ea61b126b1b425e743 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 09:23:36 -0400 Subject: [PATCH 171/194] typo --- afsk/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/main.c b/afsk/main.c index 827decab..8ea6181d 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -172,7 +172,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct tempSensor; +struct SensorConfig tempSensor; char src_addr[5] = ""; char dest_addr[5] = "CQ"; From 9b6ae0f0273ae988e4da5fbba5d50c760fe8f8a8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 09:27:15 -0400 Subject: [PATCH 172/194] old code removal --- afsk/main.c | 70 ++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 60 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index 8ea6181d..b4886b0c 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -196,65 +196,16 @@ int main(int argc, char *argv[]) { timestamp = time(NULL); tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); -/* - int file_i2c = access("/dev/i2c-3", W_OK | R_OK); - - if (file_i2c < 0) - { - fprintf(stderr,"ERROR: /dev/ic2-3 bus not present\n"); - tempSensor = OFF; - } else - { - tempSensor = wiringPiI2CSetupInterface("/dev/i2c-3", 0x48); - } -*/ -/* - #ifdef DEBUG_LOGGING - fprintf(stderr,"tempSensor: %d \n",tempSensor); - #endif -*/ - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2400); - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - -/* - int test; - if (((test = open("/dev/i2c-1", O_RDWR))) > 0) // Test if I2C Bus 1 is present - { - close(test); - sensor[PLUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x40), 400); - sensor[PLUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x41), 400); - sensor[PLUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x44), 400); - sensor[BAT] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x45), 400); - sensor[BUS] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-1", 0x4a), 2400); -} else - { - printf("ERROR: /dev/i2c-1 not present \n"); - sensor[PLUS_X] = config_sensor(OFF, 0); - sensor[PLUS_Y] = config_sensor(OFF, 0); - sensor[PLUS_Z] = config_sensor(OFF, 0); - sensor[BAT] = config_sensor(OFF, 0); - sensor[BUS] = config_sensor(OFF, 0); - } - if (((test = open("/dev/i2c-0", O_RDWR))) > 0) // Test if I2C Bus 0 is present - { - close(test); - sensor[MINUS_X] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x40), 400); - sensor[MINUS_Y] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x41), 400); - sensor[MINUS_Z] = config_sensor(wiringPiI2CSetupInterface("/dev/i2c-0", 0x44), 400); - } else - { - printf("ERROR: /dev/i2c-0 not present \n"); - sensor[MINUS_X] = config_sensor(OFF, 0); - sensor[MINUS_Y] = config_sensor(OFF, 0); - sensor[MINUS_Z] = config_sensor(OFF, 0); - } -*/ + + sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); + sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); + sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); + sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); + sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); + sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); + sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); + sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); + int ret; uint8_t data[1024]; @@ -285,7 +236,6 @@ int main(int argc, char *argv[]) { char header_str[] = "\x03\xf0hi hi "; strcpy(str, header_str); - // printf("%s-1>CQ-1:hi hi ", CALLSIGN); printf("%s-1>%s-1:hi hi ", (uint8_t *)src_addr, (uint8_t *)dest_addr); From 1189628e9f580da48bcb40a2942757f51baec03c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 09:28:48 -0400 Subject: [PATCH 173/194] turned on SatNOGS upload --- afsk/ax25.c | 1 + 1 file changed, 1 insertion(+) diff --git a/afsk/ax25.c b/afsk/ax25.c index cc3270c8..db43fc09 100644 --- a/afsk/ax25.c +++ b/afsk/ax25.c @@ -18,6 +18,7 @@ * along with this program. If not, see . */ +#define SATNOGS; #include #include "ax25.h" #include From 29506570f11247280a836efe6aa82773f5c91ed8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:04:51 -0400 Subject: [PATCH 174/194] turned off SatNOGS upload --- afsk/ax25.c | 1 - 1 file changed, 1 deletion(-) diff --git a/afsk/ax25.c b/afsk/ax25.c index db43fc09..cc3270c8 100644 --- a/afsk/ax25.c +++ b/afsk/ax25.c @@ -18,7 +18,6 @@ * along with this program. If not, see . */ -#define SATNOGS; #include #include "ax25.h" #include From 94d5e94cf3fcd3acca0bbc5827a8cb82b1dd869d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:10:55 -0400 Subject: [PATCH 175/194] initial add of telemetry display function --- afsk/telem.c | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 afsk/telem.c diff --git a/afsk/telem.c b/afsk/telem.c new file mode 100644 index 00000000..1d29794e --- /dev/null +++ b/afsk/telem.c @@ -0,0 +1,211 @@ +/* + * Generates telemetry for CubeSat Simulator + * + * Copyright Alan B. Johnston + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * INA219 Raspberry Pi wiringPi code is based on Adafruit Arduino wire code + * from https://github.com/adafruit/Adafruit_INA219. + */ + +#include +#include +#include +#include +#include +#include "status.h" +#include "ax5043.h" +#include "ax25.h" +#include "spi/ax5043spi.h" +#include +#include +#include +#include +#include "../Adafruit_INA219/Adafruit_INA219.h" // From Adafruit INA219 library for Arduino + +#define A 1 +#define B 2 +#define C 3 +#define D 4 + +#define PLUS_X 0 +#define PLUS_Y 1 +#define PLUS_Z 2 +#define BAT 3 +#define MINUS_X 4 +#define MINUS_Y 5 +#define MINUS_Z 6 +#define BUS 7 +#define OFF -1 + +uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; +uint32_t tx_channel = 0; + +ax5043_conf_t hax5043; +ax25_conf_t hax25; + +static void init_rf(); +int twosToInt(int val, int len); +int get_tlm(int tlm[][5]); +long int timestamp; +void config_x25(); +void trans_x25(); + +int upper_digit(int number); +int lower_digit(int number); +int charging = 0; + +//uint16_t x_config = (0x2000 | 0x1800 | 0x0180 | 0x0018 | 0x0007 ); + +struct SensorConfig { + int fd; + uint16_t config; + int calValue; + int powerMultiplier; + int currentDivider; +}; + +struct SensorData { + double current; + double voltage; + double power; +}; + +/** + * @brief Read the data from one of the i2c current sensors. + * + * Reads the current data from the requested i2c current sensor configuration and + * stores it into a SensorData struct. An invalid file descriptor (i.e. less than zero) + * results in a SensorData struct being returned that has both its #current and #power members + * set to NAN. + * + * @param sensor A structure containing sensor configuration including the file descriptor. + * @return struct SensorData A struct that contains the current, voltage, and power readings + * from the requested sensor. + */ +struct SensorData read_sensor_data(struct SensorConfig sensor) { + struct SensorData data = { + .current = NAN, + .voltage = NAN, + .power = NAN }; + + if (sensor.fd < 0) { + return data; + } + // doesn't read negative currents accurately, shows -0.1mA + wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); + wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CONFIG, sensor.config); + wiringPiI2CWriteReg16(sensor.fd, INA219_REG_CALIBRATION, sensor.calValue); + int value = wiringPiI2CReadReg16(sensor.fd, INA219_REG_CURRENT); + data.current = (float) twosToInt(value, 16) / (float) sensor.currentDivider; + + wiringPiI2CWrite(sensor.fd, INA219_REG_BUSVOLTAGE); + delay(1); // Max 12-bit conversion time is 586us per sample + value = (wiringPiI2CRead(sensor.fd) << 8 ) | wiringPiI2CRead (sensor.fd); + data.voltage = ((float)(value >> 3) * 4) / 1000; + // power has very low resolution, seems to step in 512mW values + data.power = (float) wiringPiI2CReadReg16(sensor.fd, INA219_REG_POWER) * (float) sensor.powerMultiplier; + + return data; +} + +/** + * @brief Configures an i2c current sensor. + * + * Calculates the configuration values of the i2c sensor so that + * current, voltage, and power can be read using read_sensor_data. + * Supports 16V 400mA and 16V 2.0A settings. + * + * @param sensor A file descriptor that can be used to read from the sensor. + * @param milliAmps The mA configuration, either 400mA or 2A are supported. + * @return struct SensorConfig A struct that contains the configuraton of the sensor. + */ +//struct SensorConfig config_sensor(int sensor, int milliAmps) { +struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { + struct SensorConfig data; + + if (access(bus, W_OK | R_OK) < 0) { // Test if I2C Bus is missing + printf("ERROR: %s bus not present \n", bus); + data.fd = OFF; + return (data); + } + + data.fd = wiringPiI2CSetupInterface(bus, address); + + data.config = INA219_CONFIG_BVOLTAGERANGE_32V | + INA219_CONFIG_GAIN_1_40MV | + INA219_CONFIG_BADCRES_12BIT | + INA219_CONFIG_SADCRES_12BIT_1S_532US | + INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS; + + if (milliAmps == 400) { // INA219 16V 400mA configuration + data.calValue = 8192; + data.powerMultiplier = 1; + data.currentDivider = 20; // 40; in Adafruit config + } + else { // INA219 16V 2A configuration + data.calValue = 40960; + data.powerMultiplier = 2; + data.currentDivider = 10; // 20; in Adafruit config + } + + #ifdef DEBUG_LOGGING + printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, + data.config, data.calValue, data.currentDivider, data.powerMultiplier); + #endif + return data; +} + +struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 +struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 +struct SensorConfig tempSensor; + +char src_addr[5] = ""; +char dest_addr[5] = "CQ"; + +int main(int argc, char *argv[]) { + + if (argc > 1) { + strcpy(src_addr, argv[1]); + } + + wiringPiSetup (); + pinMode (0, OUTPUT); + + tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); + + sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); + sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); + sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); + sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); + sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); + sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); + sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); + sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); + + + + return 0; +} + + +int twosToInt(int val,int len) { // Convert twos compliment to integer +// from https://www.raspberrypi.org/forums/viewtopic.php?t=55815 + + if(val & (1 << (len - 1))) + val = val - (1 << len); + + return(val); +} From 9a35338330221b1b9c0b31e173dabecfbdc1e627 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:15:49 -0400 Subject: [PATCH 176/194] removed Adafruit_INA219/* and added telem.c and telem --- Makefile | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 56d8fe56..a598feea 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ clean: rm -f */*/*.o rm -rf ax5043/doc/html rm -rf ax5043/doc/latex + rm -f telem docs: mkdir -p ax5043/doc; cd ax5043; doxygen Doxyfile @@ -89,12 +90,10 @@ radioafsk: libax5043.a radioafsk: afsk/ax25.o radioafsk: afsk/ax5043.o radioafsk: afsk/main.o -radioafsk: Adafruit_INA219/Adafruit_INA219.o - gcc $(DEBUG_BEHAVIOR) -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o Adafruit_INA219/Adafruit_INA219.o -lwiringPi -lax5043 -lcurl + gcc $(DEBUG_BEHAVIOR) -o radioafsk -pedantic -Wall -Wextra -L./ afsk/ax25.o afsk/ax5043.o afsk/main.o -lwiringPi -lax5043 -lcurl -Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.c -Adafruit_INA219/Adafruit_INA219.o: Adafruit_INA219/Adafruit_INA219.h - cd Adafruit_INA219; gcc $(DEBUG_BEHAVIOR) -I -pedantic -Wconversion -Wall -Wextra -c Adafruit_INA219.c; cd .. +telem: afsk/telem.o + gcc $(DEBUG_BEHAVIOR) -o telem -pedantic -Wall -Wextra -L./ afsk/telem.o -lwiringPi ax5043/generated/configcommon.o: ax5043/generated/configcommon.c ax5043/generated/configcommon.o: ax5043/generated/configrx.h @@ -235,9 +234,13 @@ afsk/main.o: afsk/status.h afsk/main.o: afsk/ax5043.h afsk/main.o: afsk/ax25.h afsk/main.o: ax5043/spi/ax5043spi.h -afsk/main.o: Adafruit_INA219/Adafruit_INA219.h +afsk/main.o: Adafruit_INA219.h cd afsk; gcc -std=gnu99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c main.c; cd .. +afsk/telem.o: afsk/telem.c +afsk/telem.o: Adafruit_INA219.h + cd afsk; gcc -std=gnu99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c telem.c; cd .. + afsk/send_afsk.o: afsk/send_afsk.c afsk/send_afsk.o: afsk/send_afsk.h afsk/send_afsk.o: afsk/status.h From 336a73da762144512ec6754642186c1d9a8f06b8 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:18:24 -0400 Subject: [PATCH 177/194] fixed Adafruit .h typo --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a598feea..fb4b81ef 100644 --- a/Makefile +++ b/Makefile @@ -234,11 +234,11 @@ afsk/main.o: afsk/status.h afsk/main.o: afsk/ax5043.h afsk/main.o: afsk/ax25.h afsk/main.o: ax5043/spi/ax5043spi.h -afsk/main.o: Adafruit_INA219.h +afsk/main.o: afsk/Adafruit_INA219.h cd afsk; gcc -std=gnu99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c main.c; cd .. afsk/telem.o: afsk/telem.c -afsk/telem.o: Adafruit_INA219.h +afsk/telem.o: afsk/Adafruit_INA219.h cd afsk; gcc -std=gnu99 $(DEBUG_BEHAVIOR) -I ../ax5043 -pedantic -Wconversion -Wall -Wextra -c telem.c; cd .. afsk/send_afsk.o: afsk/send_afsk.c From 2cf1191f3a07c986e8cd370afa2753c0a02ca261 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:23:27 -0400 Subject: [PATCH 178/194] cleanup --- afsk/telem.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 1d29794e..0c50fd87 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -63,12 +63,6 @@ long int timestamp; void config_x25(); void trans_x25(); -int upper_digit(int number); -int lower_digit(int number); -int charging = 0; - -//uint16_t x_config = (0x2000 | 0x1800 | 0x0180 | 0x0018 | 0x0007 ); - struct SensorConfig { int fd; uint16_t config; From 1e6acd036f9e78897ba41cb56a4989e8d7ef37f4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:25:18 -0400 Subject: [PATCH 179/194] add telem executable --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index fb4b81ef..54601dfc 100644 --- a/Makefile +++ b/Makefile @@ -2,11 +2,13 @@ all: DEBUG_BEHAVIOR= all: libax5043.a all: radioafsk all: radiocw +all: telem debug: DEBUG_BEHAVIOR = -DDEBUG_LOGGING debug: libax5043.a debug: radioafsk debug: radiocw +debug: telem rebuild: clean rebuild: all From 916d025e065eaa7f993d89b175b1d7a4bb8b4ce4 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:27:18 -0400 Subject: [PATCH 180/194] remove stuff --- afsk/telem.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 0c50fd87..a61880a9 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -50,18 +50,7 @@ #define BUS 7 #define OFF -1 -uint32_t tx_freq_hz = 434900000 + FREQUENCY_OFFSET; -uint32_t tx_channel = 0; - -ax5043_conf_t hax5043; -ax25_conf_t hax25; - -static void init_rf(); int twosToInt(int val, int len); -int get_tlm(int tlm[][5]); -long int timestamp; -void config_x25(); -void trans_x25(); struct SensorConfig { int fd; @@ -166,9 +155,6 @@ struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus on struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 struct SensorConfig tempSensor; -char src_addr[5] = ""; -char dest_addr[5] = "CQ"; - int main(int argc, char *argv[]) { if (argc > 1) { @@ -176,7 +162,6 @@ int main(int argc, char *argv[]) { } wiringPiSetup (); - pinMode (0, OUTPUT); tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); From 8b8e0774d430635dbc811258b887c840e7738b3c Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:28:16 -0400 Subject: [PATCH 181/194] removed command line argument processing --- afsk/telem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index a61880a9..c62585d7 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -158,7 +158,7 @@ struct SensorConfig tempSensor; int main(int argc, char *argv[]) { if (argc > 1) { - strcpy(src_addr, argv[1]); + ; } wiringPiSetup (); From 64670a843b2ebfa45af7f1caaeae66a32632b027 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:31:05 -0400 Subject: [PATCH 182/194] Added in sensor read and printf --- afsk/telem.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/afsk/telem.c b/afsk/telem.c index c62585d7..a0ccaaf7 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -174,7 +174,16 @@ int main(int argc, char *argv[]) { sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - +// Reading I2C voltage and current sensors + int count; + for (count = 0; count < 8; count++) + { + reading[count] = read_sensor_data(sensor[count]); +// #ifdef DEBUG_LOGGING + printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + count, reading[count].voltage, reading[count].current, reading[count].power); +// #endif + } return 0; } From 9a84a873e062a841118e1bc28cbde93dcdcba89a Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:36:42 -0400 Subject: [PATCH 183/194] added telem printfs --- afsk/telem.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index a0ccaaf7..53f24999 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -144,10 +144,11 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { data.currentDivider = 10; // 20; in Adafruit config } - #ifdef DEBUG_LOGGING - printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, - data.config, data.calValue, data.currentDivider, data.powerMultiplier); - #endif + //#ifdef DEBUG_LOGGING +// printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, +// data.config, data.calValue, data.currentDivider, data.powerMultiplier); + printf("Sensor %s %x configuration: %d %d %d %d %d | ", bus, address); + //#endif return data; } @@ -165,13 +166,26 @@ int main(int argc, char *argv[]) { tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); + sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); + read_sensor_data(sensor[]); + printf("+X | [%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + PLUS_X, reading[PLUS_X].voltage, reading[PLUS_X].current, reading[PLUS_X].power); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); + read_sensor_data(sensor[]); + printf("+Y | [%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + PLUS_Y , reading[PLUS_Y].voltage, reading[PLUS_Y].current, reading[PLUS_Y].power); sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); +// read_sensor_data(sensor[]); +// printf("+ | [%d] % 4.2fV % 6.1fmA % 6.1fmW \n", +// , reading[].voltage, reading[].current, reading[].power); sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); + sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); + sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); + sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); + sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); // Reading I2C voltage and current sensors From 3d9f423b6f1c9a7b5eca9330dd87bb7efc16b80b Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:38:02 -0400 Subject: [PATCH 184/194] typos --- afsk/telem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 53f24999..caddc1bc 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -147,7 +147,7 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { //#ifdef DEBUG_LOGGING // printf("Sensor %s %x configuration: %d %d %d %d %d\n", bus, address, data.fd, // data.config, data.calValue, data.currentDivider, data.powerMultiplier); - printf("Sensor %s %x configuration: %d %d %d %d %d | ", bus, address); + printf("Sensor %s %x | ", bus, address); //#endif return data; } @@ -167,11 +167,11 @@ int main(int argc, char *argv[]) { tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - read_sensor_data(sensor[]); + read_sensor_data(sensor[PLUS_X]); printf("+X | [%d] % 4.2fV % 6.1fmA % 6.1fmW \n", PLUS_X, reading[PLUS_X].voltage, reading[PLUS_X].current, reading[PLUS_X].power); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - read_sensor_data(sensor[]); + read_sensor_data(sensor[PLUS_Y]); printf("+Y | [%d] % 4.2fV % 6.1fmA % 6.1fmW \n", PLUS_Y , reading[PLUS_Y].voltage, reading[PLUS_Y].current, reading[PLUS_Y].power); sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); From 70efb45f64df4183098223aa5f9698eea6663b16 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:41:41 -0400 Subject: [PATCH 185/194] removed double print --- afsk/telem.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index caddc1bc..f259f35d 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -163,16 +163,16 @@ int main(int argc, char *argv[]) { } wiringPiSetup (); + + printf"\n"); - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); read_sensor_data(sensor[PLUS_X]); - printf("+X | [%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", PLUS_X, reading[PLUS_X].voltage, reading[PLUS_X].current, reading[PLUS_X].power); sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); read_sensor_data(sensor[PLUS_Y]); - printf("+Y | [%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", PLUS_Y , reading[PLUS_Y].voltage, reading[PLUS_Y].current, reading[PLUS_Y].power); sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); // read_sensor_data(sensor[]); @@ -187,17 +187,10 @@ int main(int argc, char *argv[]) { sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); - -// Reading I2C voltage and current sensors - int count; - for (count = 0; count < 8; count++) - { - reading[count] = read_sensor_data(sensor[count]); -// #ifdef DEBUG_LOGGING - printf("Read sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - count, reading[count].voltage, reading[count].current, reading[count].power); -// #endif - } + + tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); + + printf"\n\n"); return 0; } From eb6263830d2e5c999a084c2d1800be02001e5b01 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:42:32 -0400 Subject: [PATCH 186/194] typos --- afsk/telem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index f259f35d..3b9e454d 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) { wiringPiSetup (); - printf"\n"); + printf("\n"); sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); read_sensor_data(sensor[PLUS_X]); @@ -190,7 +190,7 @@ int main(int argc, char *argv[]) { tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); - printf"\n\n"); + printf("\n\n"); return 0; } From 7d099f362a24f1f2670865bad9e198093d5e7338 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:47:25 -0400 Subject: [PATCH 187/194] added sensor read variable --- afsk/telem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 3b9e454d..cdbe39e7 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -167,13 +167,15 @@ int main(int argc, char *argv[]) { printf("\n"); sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - read_sensor_data(sensor[PLUS_X]); + reading = read_sensor_data(sensor[PLUS_X]); printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - PLUS_X, reading[PLUS_X].voltage, reading[PLUS_X].current, reading[PLUS_X].power); + PLUS_X, reading[PLUS_X].voltage, reading[PLUS_X].current, reading[PLUS_X].power); + sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - read_sensor_data(sensor[PLUS_Y]); + reading = read_sensor_data(sensor[PLUS_Y]); printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - PLUS_Y , reading[PLUS_Y].voltage, reading[PLUS_Y].current, reading[PLUS_Y].power); + PLUS_Y , reading[PLUS_Y].voltage, reading[PLUS_Y].current, reading[PLUS_Y].power); + sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); // read_sensor_data(sensor[]); // printf("+ | [%d] % 4.2fV % 6.1fmA % 6.1fmW \n", From 3db862c41bf782994a8777e431c0e950fec4ac95 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:58:43 -0400 Subject: [PATCH 188/194] added temp --- afsk/telem.c | 71 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index cdbe39e7..9c2ab81c 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -152,8 +152,8 @@ struct SensorConfig config_sensor(char *bus, int address, int milliAmps) { return data; } -struct SensorConfig sensor[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 -struct SensorData reading[8]; // 7 current sensors in Solar Power PCB plus one in MoPower UPS V2 +struct SensorConfig sensorV; +struct SensorData readingV; struct SensorConfig tempSensor; int main(int argc, char *argv[]) { @@ -166,32 +166,59 @@ int main(int argc, char *argv[]) { printf("\n"); - sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400); - reading = read_sensor_data(sensor[PLUS_X]); - printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - PLUS_X, reading[PLUS_X].voltage, reading[PLUS_X].current, reading[PLUS_X].power); + sensorV = config_sensor("/dev/i2c-1", 0x40, 400); + readingV = read_sensor_data(sensorV); + printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + PLUS_X, readingV.voltage, readingV.current, readingV.power); - sensor[PLUS_Y] = config_sensor("/dev/i2c-1", 0x41, 400); - reading = read_sensor_data(sensor[PLUS_Y]); - printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", - PLUS_Y , reading[PLUS_Y].voltage, reading[PLUS_Y].current, reading[PLUS_Y].power); + sensorV = config_sensor("/dev/i2c-1", 0x41, 400); + readingV = read_sensor_data(sensorV); + printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + PLUS_Y, readingV.voltage, readingV.current, readingV.power); - sensor[PLUS_Z] = config_sensor("/dev/i2c-1", 0x44, 400); -// read_sensor_data(sensor[]); -// printf("+ | [%d] % 4.2fV % 6.1fmA % 6.1fmW \n", -// , reading[].voltage, reading[].current, reading[].power); - sensor[BAT] = config_sensor("/dev/i2c-1", 0x45, 400); + sensorV = config_sensor("/dev/i2c-1", 0x44, 400); + readingV = read_sensor_data(sensorV); + printf("+Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + PLUS_Z, readingV.voltage, readingV.current, readingV.power); - sensor[BUS] = config_sensor("/dev/i2c-1", 0x4a, 2000); - - sensor[MINUS_X] = config_sensor("/dev/i2c-0", 0x40, 400); - - sensor[MINUS_Y] = config_sensor("/dev/i2c-0", 0x41, 400); - - sensor[MINUS_Z] = config_sensor("/dev/i2c-0", 0x44, 400); + sensorV = config_sensor("/dev/i2c-0", 0x40, 400); + readingV = read_sensor_data(sensorV); + printf("-X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + MINUS_X, readingV.voltage, readingV.current, readingV.power); + + sensorV = config_sensor("/dev/i2c-0", 0x41, 400); + readingV = read_sensor_data(sensorV); + printf("-Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + MINUS_Y, readingV.voltage, readingV.current, readingV.power); + + sensorV = config_sensor("/dev/i2c-0", 0x44, 400); + readingV = read_sensor_data(sensorV); + printf("-Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + MINUS_Z, readingV.voltage, readingV.current, readingV.power); + + + sensorV = config_sensor("/dev/i2c-1", 0x45, 400); + readingV = read_sensor_data(sensorV); + printf("Bat | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + BAT, readingV.voltage, readingV.current, readingV.power); + + sensorV = config_sensor("/dev/i2c-1", 0x4a, 2000); + readingV = read_sensor_data(sensorV); + printf("Bus | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + BUS, readingV.voltage, readingV.current, readingV.power); tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); + sensorV = config_sensor("/dev/i2c-1", 0x45, 400); + + if (sensorV.fd != OFF) { + int tempValue = wiringPiI2CReadReg16(SensorV.fd, 0); + uint8_t upper = (uint8_t) (tempValue >> 8); + uint8_t lower = (uint8_t) (tempValue & 0xff); + float temp = (float)lower + ((float)upper / 0x100); + printf("T | % 4.1f C \n", temp); + } + printf("\n\n"); return 0; From aa188e32f90030765e3168e1357a266236231455 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 11:59:49 -0400 Subject: [PATCH 189/194] fixed temp --- afsk/telem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 9c2ab81c..7fc07c44 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -207,12 +207,12 @@ int main(int argc, char *argv[]) { printf("Bus | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", BUS, readingV.voltage, readingV.current, readingV.power); - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); + sensorV = config_sensor("/dev/i2c-3", 0x48, 0); sensorV = config_sensor("/dev/i2c-1", 0x45, 400); if (sensorV.fd != OFF) { - int tempValue = wiringPiI2CReadReg16(SensorV.fd, 0); + int tempValue = wiringPiI2CReadReg16(sensorV.fd, 0); uint8_t upper = (uint8_t) (tempValue >> 8); uint8_t lower = (uint8_t) (tempValue & 0xff); float temp = (float)lower + ((float)upper / 0x100); From ff35fe22118e36a771857aa01a2dccd4a2d88a13 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 12:04:20 -0400 Subject: [PATCH 190/194] formatting fixes --- afsk/telem.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 7fc07c44..8a0cc81a 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -168,49 +168,46 @@ int main(int argc, char *argv[]) { sensorV = config_sensor("/dev/i2c-1", 0x40, 400); readingV = read_sensor_data(sensorV); - printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", PLUS_X, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-1", 0x41, 400); readingV = read_sensor_data(sensorV); - printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", PLUS_Y, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-1", 0x44, 400); readingV = read_sensor_data(sensorV); - printf("+Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("+Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", PLUS_Z, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-0", 0x40, 400); readingV = read_sensor_data(sensorV); - printf("-X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("-X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", MINUS_X, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-0", 0x41, 400); readingV = read_sensor_data(sensorV); - printf("-Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("-Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", MINUS_Y, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-0", 0x44, 400); readingV = read_sensor_data(sensorV); - printf("-Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("-Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", MINUS_Z, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-1", 0x45, 400); readingV = read_sensor_data(sensorV); - printf("Bat | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("Bat | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", BAT, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-1", 0x4a, 2000); readingV = read_sensor_data(sensorV); - printf("Bus | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("Bus | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", BUS, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-3", 0x48, 0); - - sensorV = config_sensor("/dev/i2c-1", 0x45, 400); - if (sensorV.fd != OFF) { int tempValue = wiringPiI2CReadReg16(sensorV.fd, 0); uint8_t upper = (uint8_t) (tempValue >> 8); From 1e784f1109802f1cbb13797e3ac314da9560dd78 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 12:06:03 -0400 Subject: [PATCH 191/194] printf fix --- afsk/telem.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/afsk/telem.c b/afsk/telem.c index 8a0cc81a..56e9778f 100644 --- a/afsk/telem.c +++ b/afsk/telem.c @@ -168,43 +168,43 @@ int main(int argc, char *argv[]) { sensorV = config_sensor("/dev/i2c-1", 0x40, 400); readingV = read_sensor_data(sensorV); - printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("+X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", PLUS_X, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-1", 0x41, 400); readingV = read_sensor_data(sensorV); - printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("+Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", PLUS_Y, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-1", 0x44, 400); readingV = read_sensor_data(sensorV); - printf("+Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("+Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", PLUS_Z, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-0", 0x40, 400); readingV = read_sensor_data(sensorV); - printf("-X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("-X | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", MINUS_X, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-0", 0x41, 400); readingV = read_sensor_data(sensorV); - printf("-Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("-Y | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", MINUS_Y, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-0", 0x44, 400); readingV = read_sensor_data(sensorV); - printf("-Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("-Z | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", MINUS_Z, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-1", 0x45, 400); readingV = read_sensor_data(sensorV); - printf("Bat | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("Bat | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", BAT, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-1", 0x4a, 2000); readingV = read_sensor_data(sensorV); - printf("Bus | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", + printf("Bus | sensor[%d] % 4.2fV % 6.1fmA % 6.1fmW \n", BUS, readingV.voltage, readingV.current, readingV.power); sensorV = config_sensor("/dev/i2c-3", 0x48, 0); From fa9b5ebc4030abf702e0a41ee0a434aa4ca38622 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 12:12:40 -0400 Subject: [PATCH 192/194] removed old file --- afsk/main.c.x25_only | 85 -------------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 afsk/main.c.x25_only diff --git a/afsk/main.c.x25_only b/afsk/main.c.x25_only deleted file mode 100644 index 7a67a49c..00000000 --- a/afsk/main.c.x25_only +++ /dev/null @@ -1,85 +0,0 @@ -/* - * A sample application transmitting AFSK at 1200 baud - * - * Portions Copyright (C) 2018 Jonathan Brandenburg - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include "status.h" -#include "ax5043.h" -#include "ax25.h" -#include "spi/ax5043spi.h" - -ax5043_conf_t hax5043; -ax25_conf_t hax25; - -static void init_rf(); - -int main(void) { - setSpiChannel(SPI_CHANNEL); - setSpiSpeed(SPI_SPEED); - initializeSpi(); - - init_rf(); - - ax25_init(&hax25, (uint8_t *) "CQ", '2', (uint8_t *) "DX", '2', - AX25_PREAMBLE_LEN, - AX25_POSTAMBLE_LEN); - - int ret; - uint8_t data[1024]; - // 0x03 is a UI frame - // 0x0F is no Level 3 protocol - const char *str = "\x03\x0fThis is an AX.25 Packet from CubeSatSim!!!"; - - /* Infinite loop */ - for (;;) { - sleep(2); - printf("INFO: Transmitting a packet\n"); - - memcpy(data, str, strnlen(str, 256)); - ret = ax25_tx_frame(&hax25, &hax5043, data, strnlen(str, 256)); - if (ret) { - fprintf(stderr, - "ERROR: Failed to transmit AX.25 frame with error code %d\n", - ret); - exit(EXIT_FAILURE); - } - ax5043_wait_for_transmit(); - if (ret) { - fprintf(stderr, - "ERROR: Failed to transmit entire AX.25 frame with error code %d\n", - ret); - exit(EXIT_FAILURE); - } - - } - - return 0; -} - -static void init_rf() { - int ret; - ret = ax5043_init(&hax5043, XTAL_FREQ_HZ, VCO_INTERNAL); - if (ret != PQWS_SUCCESS) { - fprintf(stderr, - "ERROR: Failed to initialize AX5043 with error code %d\n", ret); - exit(EXIT_FAILURE); - } -} From 0750ddba5659d5066ce75f7664ef124b1a4017c6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 12:13:02 -0400 Subject: [PATCH 193/194] removed old file --- afsk/ax5043.c.bk | 1162 ---------------------------------------------- 1 file changed, 1162 deletions(-) delete mode 100644 afsk/ax5043.c.bk diff --git a/afsk/ax5043.c.bk b/afsk/ax5043.c.bk deleted file mode 100644 index f5b31b91..00000000 --- a/afsk/ax5043.c.bk +++ /dev/null @@ -1,1162 +0,0 @@ -/* - * A sample application transmitting AFSK 1200 baud - * - * Portions Copyright (C) 2018 Libre Space Foundation - * Portions Copyright (C) 2018 Jonathan Brandenburg - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include "ax25.h" -#include "ax5043.h" -#include "status.h" -#include "utils.h" -#include "spi/ax5043spi.h" - -static uint8_t single_fifo_access = 0; - -static uint8_t __tx_buf[MAX_FRAME_LEN]; -static size_t __tx_buf_idx = 0; -static uint8_t __tx_fifo_chunk[AX5043_FIFO_MAX_SIZE]; -static uint32_t __tx_remaining = 0; - -/** - * FIFO command for the preamble. The third byte corresponds the length of - * the preamble and is set by the TX routine for every frame - */ -static uint8_t __preamble_cmd[4] = { AX5043_FIFO_REPEATDATA_CMD, -AX5043_FIFO_PKTSTART | AX5043_FIFO_RAW | AX5043_FIFO_NOCRC, 0, -AX25_SYNC_FLAG }; - -/** - * FIFO command for the postable. The third byte corresponds the length of - * the postable and is set by the TX routine for every frame - */ -static uint8_t __postamble_cmd[4] = { -AX5043_FIFO_REPEATDATA_CMD, -AX5043_FIFO_PKTSTART | AX5043_FIFO_PKTEND | AX5043_FIFO_RAW | AX5043_FIFO_NOCRC, - 0, AX25_SYNC_FLAG }; - -/** - * Indicates if a TX is currently active - */ -static volatile uint8_t __tx_active = 0; - -static ax5043_conf_t *__ax5043_conf = NULL; - -static inline int set_tx_black_magic_regs(); - -/** - * Checks if the AX5043 handler is valid - * @param conf the AX5043 configuration handler pointer - * @return 1 if it is valid 0 otherwise - */ -static uint8_t is_ax5043_conf_valid(ax5043_conf_t *conf) { - if (!conf || !conf->f_xtal) { - return 0; - } - return 1; -} - -/** - * Resets the AX5043 - * @param conf the AX5043 configuration handler - * @return 0 on success or appropriate negative error code - */ -int ax5043_reset_a(ax5043_conf_t *conf) { - int ret; - uint8_t val; - - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - conf->rf_init = 0; - usleep(100); - - /* Reset the chip using the appropriate register */ - val = BIT(7); - ret = ax5043_spi_write_8(conf, AX5043_REG_PWRMODE, val); - if (ret) { - return ret; - } - usleep(100); - /* Clear the reset bit, but keep REFEN and XOEN */ - ret = ax5043_spi_read_8(conf, &val, AX5043_REG_PWRMODE); - if (ret) { - return ret; - } - val &= (BIT(6) | BIT(5)); - ret = ax5043_spi_write_8(conf, AX5043_REG_PWRMODE, val); - if (ret) { - return ret; - } - usleep(100); - - ret = ax5043_set_power_mode(conf, POWERDOWN); - if (ret) { - return ret; - } - return PQWS_SUCCESS; -} - -/** - * Initialization routine for the AX5043 IC - * @param conf the AX5043 configuration handler - * @param spi the SPI handler - * @param f_xtal the frequency of the crystal or the TCXO - * @param vco the VCO mode - * @return 0 on success or appropriate negative error code - */ -int ax5043_init(ax5043_conf_t *conf, uint32_t f_xtal, vco_mode_t vco) { - int ret; - uint8_t revision; - uint8_t val; - printf("1 \n"); - - if (!conf) { - return -PQWS_INVALID_PARAM; - } - - /* Set the initial parameters */ - memset(conf, 0, sizeof(ax5043_conf_t)); - printf("2\n "); - switch (vco) { - case VCO_INTERNAL: - case VCO_EXTERNAL: - conf->vco = vco; - break; - default: - return -PQWS_INVALID_PARAM; - } - - conf->rf_init = 0; - conf->freqsel = -1; - conf->f_xtal = f_xtal; - if (conf->f_xtal > 24800000) { - conf->f_xtaldiv = 2; - } else { - conf->f_xtaldiv = 1; - } - printf("3\n "); - - ret = ax5043_reset_a(conf); - printf("4 \n"); - if (ret) { - return ret; - } - printf("5\n "); - - /* Try first to read the revision register of the AX5043 */ - ret = ax5043_spi_read_8(conf, &revision, AX5043_REG_REV); - printf("6 \n"); - if (ret) { - return ret; - } - - if (revision != AX5043_REV) { - return -PQWS_NO_RF_FOUND; - } - - /* To ensure communication try to write and read the scratch register */ - val = AX5043_SCRATCH_TEST; - printf("7 \n"); - ret = ax5043_spi_write_8(conf, AX5043_REG_SCRATCH, val); - printf("8 \n"); - if (ret) { - return ret; - } - - val = 0x0; - printf("9 \n"); - ret = ax5043_spi_read_8(conf, &val, AX5043_REG_SCRATCH); - printf("10 \n"); - if (ret) { - return ret; - } - - if (val != AX5043_SCRATCH_TEST) { - return -PQWS_NO_RF_FOUND; - } - - printf("11 \n"); - ret = ax5043_set_pll_params(conf); - printf("12 \n"); - if (ret) { - return ret; - } - - /* Write the performance register F35 based on the XTAL frequency */ - printf("13 \n"); - if (conf->f_xtaldiv == 1) { - ret = ax5043_spi_write_8(conf, 0xF35, 0x10); - } else { - ret = ax5043_spi_write_8(conf, 0xF35, 0x11); - } - printf("14 \n"); - if (ret) { - return ret; - } - - /* FIFO maximum chunk */ - printf("15 \n"); - ret = ax5043_spi_write_8(conf, AX5043_REG_PKTCHUNKSIZE, - AX5043_PKTCHUNKSIZE_240); - printf("15 \n"); - if (ret) { - return ret; - } - - /* Set RF parameters */ - printf("16 \n"); - ret = ax5043_freqsel(conf, FREQA_MODE); - printf("17 \n"); - if (ret) { - return ret; - } - - /* - * We use APRS for all transmitted frames. APRS is encapsulated in a - * AX.25 frame. For 9600 baudrate is FSK9600 G3RUH compatible modem - */ - printf("18 \n"); - ret = ax5043_aprs_framing_setup(conf); - printf("19 \n"); - if (ret) { - return ret; - } - - /* Setup TX only related parameters */ - printf("20 \n"); - ret = ax5043_conf_tx_path(conf); - printf("21 \n"); - if (ret) { - return ret; - } - - /* Set an internal copy for the ax5042_wait_for_transmit function */ - __ax5043_conf = conf; - - if (ret) { - return ret; - } - printf("22 \n"); - ax5043_enable_pwramp(conf, AX5043_EXT_PA_DISABLE); - printf("23 \n"); - return PQWS_SUCCESS; -} - -/** - * Performs TX specific configuration of the AX5043 - * @param conf the AX5043 configuration handler - * @return 0 on success or appropriate negative error code - */ -int ax5043_conf_tx_path(ax5043_conf_t *conf) { - printf("25 \n"); - int ret; - - printf("26 \n"); - ret = ax5043_set_tx_synth(conf); - printf("27 \n"); - if (ret) { - return ret; - } - - printf("28 \n"); - ret = ax5043_set_tx_baud(conf, TX_BAUDRATE); - printf("29 \n"); - if (ret) { - return ret; - } - - // printf("30 \n"); - ret = ax5043_set_tx_freq(conf, TX_FREQ_HZ); - printf("31\n "); - if (ret) { - return ret; - } - - /* Our TX is on single ended mode */ - //ret = ax5043_spi_write_8(conf, AX5043_REG_MODCFGA, - //AX5043_TX_SINGLE_ENDED); - //if (ret) { - // return ret; - //} - - /* Our TX is on double ended mode */ - printf("32 \n"); - ret = ax5043_spi_write_8(conf, AX5043_REG_MODCFGA, - AX5043_TX_DIFFERENTIAL); - printf("33 \n"); - if (ret) { - return ret; - } - - /* Set the rest of the performance registers for TX */ - printf("34 \n"); - ret = set_tx_black_magic_regs(conf); - printf("35 \n"); - if (ret) { - return ret; - } - - /* - * As our board has an external PA, reduce the output power to reduce - * the excess bandwidth emissions - */ - //ret = ax5043_spi_write_16(conf, AX5043_REG_TXPWRCOEFFB1, 0x01FF); - //if (ret) { - //return ret; - //} - - // Not using a PA, transmit half power - printf("36 \n"); - ret = ax5043_spi_write_16(conf, AX5043_REG_TXPWRCOEFFB1, 0x07FF); - printf("37 \n"); - if (ret) { - return ret; - } - - return PQWS_SUCCESS; -} - -/** - * Sets the power mode of the AX5043 - * @param conf the AX5043 configuration handler - * @param mode the power mode - * @return 0 on success or appropriate negative error code - */ -int ax5043_set_power_mode(ax5043_conf_t *conf, power_mode_t mode) { - int ret; - uint8_t val; - - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - /* Read the contents of the register */ - ret = ax5043_spi_read_8(conf, &val, AX5043_REG_PWRMODE); - if (ret) { - return ret; - } - - /* Keep REFEN and XOEN values */ - val &= (BIT(6) | BIT(5)); - - switch (mode) { - case POWERDOWN: - val |= AX5043_POWERDOWN; - break; - case DEEPSLEEP: - val |= AX5043_DEEPSLEEP; - break; - case STANDBY: - val |= AX5043_STANDBY; - break; - case FIFO_ENABLED: - val |= AX5043_FIFO_ENABLED; - break; - case RECEIVE_MODE: - val |= AX5043_RECEIVE_MODE; - break; - case RECEIVER_RUNNING: - val |= AX5043_RECEIVER_RUNNING; - break; - case RECEIVER_WOR: - val |= AX5043_RECEIVER_WOR; - break; - case TRANSMIT_MODE: - val |= AX5043_TRANSMIT_MODE; - break; - case FULLTX: - val |= AX5043_FULLTX; - break; - default: - return -PQWS_INVALID_PARAM; - } - return ax5043_spi_write_8(conf, AX5043_REG_PWRMODE, val); -} - -/** - * Sets the RF frequency of the TX. If the previous TX frequency is - * further enough than the new one, this function performs automatically - * auto-ranging. - * - * @param conf the AX5043 configuration handler - * @param freq the target RF frequency - * @return 0 on success or appropriate negative error code - */ -int ax5043_set_tx_freq(ax5043_conf_t *conf, uint32_t freq) { - int ret; - uint32_t prev_freq; - uint32_t reg_val; - uint8_t rfdiv = 0; - uint8_t pllcodediv = 0; - - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - /* Check the frequency range. The actual range depends on the VCO used */ - switch (conf->vco) { - case VCO_INTERNAL: - if (freq >= MIN_RF_FREQ_INT_VCO_RFDIV0 - && freq <= MAX_RF_FREQ_INT_VCO_RFDIV0) { - rfdiv = AX5043_RFDIV0; - } else if (freq >= MIN_RF_FREQ_INT_VCO_RFDIV1 - && freq <= MAX_RF_FREQ_INT_VCO_RFDIV1) { - rfdiv = AX5043_RFDIV1; - } else { - return -PQWS_INVALID_PARAM; - } - break; - case VCO_EXTERNAL: - fprintf(stderr, "ERROR: Unexpected use of external VCO\n"); - if (freq >= MIN_RF_FREQ_EXT_VCO_RFDIV0 - && freq <= MAX_RF_FREQ_EXT_VCO_RFDIV0) { - rfdiv = AX5043_RFDIV0; - } else if (freq >= MIN_RF_FREQ_EXT_VCO_RFDIV1 - && freq <= MAX_RF_FREQ_EXT_VCO_RFDIV1) { - rfdiv = AX5043_RFDIV1; - } else { - return -PQWS_INVALID_PARAM; - } - break; - default: - return -PQWS_INVALID_PARAM; - } - prev_freq = conf->tx_freq; - pllcodediv = rfdiv | (uint8_t) (conf->vco << 4); - - // Added by Jonathan Brandenburg - // Have an external inductor - pllcodediv |= BIT(5); - - ret = ax5043_spi_write_8(conf, AX5043_REG_PLLVCODIV, pllcodediv); - if (ret) { - return ret; - } - - /* Write properly the F34 performance register based on the RFDIV*/ - if (rfdiv == AX5043_RFDIV1) { - ret = ax5043_spi_write_8(conf, 0xF34, 0x28); - } else { - ret = ax5043_spi_write_8(conf, 0xF34, 0x08); - } - if (ret) { - return ret; - } - - /* - * Set the RF frequency - * Frequency should be avoided to be a multiple integer of the crystal - * frequency, so we always set to 1 the LSB - */ - reg_val = ((uint32_t) (((float) freq / (float) conf->f_xtal) * (1 << 24)) - | 0x1); - if (conf->freqsel == FREQA_MODE) { - ret = ax5043_spi_write_32(conf, AX5043_REG_FREQA3, reg_val); - } else { - ret = ax5043_spi_write_32(conf, AX5043_REG_FREQB3, reg_val); - } - if (ret) { - return ret; - } - - /* Considered that the frequency successfully changed */ - conf->tx_freq = freq; - - /* If the frequency difference is great enough perform autoranging */ - if (freq + 25000000 > prev_freq || freq - 25000000 < prev_freq) { - ax5043_autoranging(conf); - } - - return PQWS_SUCCESS; -} - -/** - * Set the TX baudrate - * @param conf the AX5043 configuration handler - * @param baud the baudrate - * @return 0 on success or negative error code - */ -int ax5043_set_tx_baud(ax5043_conf_t *conf, uint32_t baud) { - int ret = PQWS_SUCCESS; - uint32_t val; - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - val = (uint32_t) ((((float) baud) / (float) conf->f_xtal) * (1 << 24)) - | 0x1; - ret = ax5043_spi_write_24(conf, AX5043_REG_TXRATE2, val); - if (ret) { - return ret; - } - - conf->tx_baudrate = baud; - - /* Set the deviation to standard 3 KHz for FM */ - // For AFSK, FSKDEV = 0.858785 * fDeviation / fXTAL * 2^24 - // - val = (uint32_t) ((0.858785 * 3000.0f / (float) conf->f_xtal) * (1 << 24)) - | 0x1; - ret = ax5043_spi_write_24(conf, AX5043_REG_FSKDEV2, val); - if (ret) { - return ret; - } - - return PQWS_SUCCESS; -} - -/** - * Sets the currently used frequency registers (A or B) - * @param conf the AX5043 configuration handler - * @param f the frequency mode (A or B) - * @return 0 on success or appropriate negative error code - */ -int ax5043_freqsel(ax5043_conf_t *conf, freq_mode_t f) { - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - if (f != FREQA_MODE && f != FREQB_MODE) { - return -PQWS_INVALID_PARAM; - } - conf->freqsel = f; - return PQWS_SUCCESS; -} - -/** - * Sets the TX frequency synthesizer related configuration registers. - * @param conf the AX5043 configuration handler - * @return 0 on success or appropriate negative error code - */ -int ax5043_set_tx_synth(ax5043_conf_t *conf) { - int ret; - uint8_t val; - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - switch (conf->freqsel) { - case FREQA_MODE: - val = 0x0; - break; - case FREQB_MODE: - val = 1 << 7; - break; - default: - return -PQWS_INVALID_PARAM; - } - - /* Bypass external filter and use 100 kHZ loop bandwidth */ - val |= BIT(3) | BIT(0); - ret = ax5043_spi_write_8(conf, AX5043_REG_PLLLOOP, val); - if (ret) { - return ret; - } - - /* - * Set the charge pump current based on the loop bandwidth - * 68 uA @ 100 kHZ - */ - ret = ax5043_spi_write_8(conf, AX5043_REG_PLLCPI, (uint8_t) (68 / 8.5)); - if (ret) { - return ret; - } - ret = ax5043_spi_write_8(conf, AX5043_REG_XTALCAP, 0); - return ret; -} - -/** - * Sets the PLL related configuration registers. - * @param conf the AX5043 configuration handler - * @return 0 on success or appropriate negative error code - */ -int ax5043_set_pll_params(ax5043_conf_t *conf) { - int ret; - uint8_t i = 8; - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - /* Set VCO to manual */ - ret = ax5043_spi_write_8(conf, AX5043_REG_PLLVCOI, - AX5043_PLLVCOI_MANUAL | (1250 / 50)); - if (ret) { - return ret; - } - - /* - * According to the manual PLL ranging clock should be less than 1/10 - * of the PLL loop bandwidth. The smallest PLL bandwidth configuration - * is 100 kHz. - */ - // This this next line contains an error - //while (conf->f_xtal / (uint32_t) (1 << i) > 10000) { - while (conf->f_xtal / (uint32_t) (1 << i) > 100000) { - i++; - } - i = i > 15 ? 15 : i; - i = i < 8 ? 8 : i; - ret = ax5043_spi_write_8(conf, AX5043_REG_PLLRNGCLK, (uint8_t) (i - 8)); - return ret; -} - -/** - * Performs auto-ranging using the frequency registers configured by - * ax5043_freqsel(). - * - * @param conf the AX5043 configuration handler - * @return 0 on success or appropriate negative error code - */ -int ax5043_autoranging(ax5043_conf_t *conf) { - int ret = PQWS_SUCCESS; - uint16_t pllranging_reg; - uint8_t val = 0; - - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - switch (conf->freqsel) { - case FREQA_MODE: - pllranging_reg = AX5043_REG_PLLRANGINGA; - break; - case FREQB_MODE: - pllranging_reg = AX5043_REG_PLLRANGINGB; - break; - default: - return -PQWS_INVALID_PARAM; - } - - /* Write the initial VCO setting and start autoranging */ - val = BIT(4) | AX5043_VCOR_INIT; - ret = ax5043_spi_write_8(conf, pllranging_reg, val); - if (ret) { - return ret; - } - - usleep(10); - val = 0; - /* Wait until the autoranging is complete */ - while ((val & BIT(4)) == 0) { - ret = ax5043_spi_read_8(conf, &val, pllranging_reg); - if (ret) { - return ret; - } - } - - if (val & BIT(5)) { - return -PQWS_AX5043_AUTORANGING_ERROR; - } - - return PQWS_SUCCESS; -} - -/** - * - * @param conf the AX5043 configuration handler - * @return 0 on success or appropriate negative error code - */ -int ax5043_aprs_framing_setup(ax5043_conf_t *conf) { - int ret = PQWS_SUCCESS; - uint8_t val = 0; - - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - /* Set modulation */ - val = AX5043_MODULATION_AFSK; - ret = ax5043_spi_write_8(conf, AX5043_REG_MODULATION, val); - if (ret) { - return ret; - } - - // To set the space frequency, 1070 - // 1070 * 2^18 / fXTAL -> 1070 * 2^18 / 16000000 -> 18 -> 0x12 - - // To set the space frequency, 1200 - // 1200 * 2^18 / fXTAL -> 1200 * 2^18 / 16000000 -> 20 -> 0x14 - - ret = ax5043_spi_write_16(conf, AX5043_REG_AFSKSPACE1, 0x24); - if (ret) { - return ret; - } - - // To set the mark frequency, 1270 - // 1270 * 2^18 / fXTAL -> 1270 * 2^18 / 16000000 -> 21 -> 0x15 - - // To set the mark frequency, 1400 - // 1400 * 2^18 / fXTAL -> 1400 * 2^18 / 16000000 -> 23 -> 0x17 - - ret = ax5043_spi_write_16(conf, AX5043_REG_AFSKMARK1, 0x14); - if (ret) { - return ret; - } - - /* - * As we do not use any external filter, try to filter from - * the AX5043 the signal - */ - ret = ax5043_spi_write_8(conf, AX5043_REG_MODCFGF, - AX5043_FREQSHAPE_GAUSSIAN_BT_05); - if (ret) { - return ret; - } - - /* Set HDLC encoding: Differential = 1, Inverse = 1, Scrambling = 1 */ - //ax5043_spi_write_8(conf, AX5043_REG_ENCODING, - /* Set HDLC encoding: Differential = 1, Inverse = 1, Scrambling = 1 */ - ax5043_spi_write_8(conf, AX5043_REG_ENCODING, - AX5043_ENC_DIFF | AX5043_ENC_INV); - - /* HDLC framing */ - ax5043_spi_write_8(conf, AX5043_REG_FRAMING, - AX5043_HDLC_FRAMING | AX5043_CRC16_CCITT); - return ret; -} - -static int __tx_frame_end(ax5043_conf_t *conf) { - int ret; - - ax5043_enable_pwramp(conf, AX5043_EXT_PA_DISABLE); - - /* Set AX5043 to power down mode */ - ret = ax5043_set_power_mode(conf, POWERDOWN); - __tx_active = 0; - return ret; -} - -static int __tx_frame(ax5043_conf_t *conf, const uint8_t *in, uint32_t len, - uint8_t preamble_len, uint8_t postamble_len, uint32_t timeout_ms) { - int ret = PQWS_SUCCESS; - uint8_t data_cmd[3] = { AX5043_FIFO_VARIABLE_DATA_CMD, 0, 0 }; - size_t chunk_size = 0; - size_t avail; - uint8_t val; - uint32_t start = millis(); - - /* - * Apply preamble and postamble repetition length. Rest of the fields should - * remain unaltered - */ - __preamble_cmd[2] = preamble_len; - __postamble_cmd[2] = postamble_len; - - memcpy(__tx_fifo_chunk, __preamble_cmd, sizeof(__preamble_cmd)); - chunk_size = sizeof(__preamble_cmd); - __tx_buf_idx = 0; - - /* - * Always leave some space for the postamble. This greatly reduces the - * complexity of dealing with some corner cases - */ - avail = min_ul( - AX5043_FIFO_MAX_SIZE - sizeof(__preamble_cmd) - sizeof(data_cmd) - - sizeof(__postamble_cmd), len); - if (len == avail) { - data_cmd[1] = (uint8_t) (len + 1); - data_cmd[2] = AX5043_FIFO_PKTEND; - __tx_remaining = 0; - memcpy(__tx_fifo_chunk + chunk_size, data_cmd, sizeof(data_cmd)); - chunk_size += sizeof(data_cmd); - memcpy(__tx_fifo_chunk + chunk_size, in, len); - chunk_size += len; - /* - * At this point we are sure that the whole frame + postamble can fit in - * the FIFO chunk - */ - memcpy(__tx_fifo_chunk + chunk_size, __postamble_cmd, - sizeof(__postamble_cmd)); - chunk_size += sizeof(__postamble_cmd); - single_fifo_access = 1; - } else { - data_cmd[1] = (uint8_t) (avail + 1); - data_cmd[2] = 0; - memcpy(__tx_fifo_chunk + chunk_size, data_cmd, sizeof(data_cmd)); - chunk_size += sizeof(data_cmd); - memcpy(__tx_fifo_chunk + chunk_size, in, avail); - chunk_size += avail; - - memcpy(__tx_buf, in + avail, len - avail); - __tx_remaining = (uint32_t) (len - avail); - single_fifo_access = 0; - } - - /* Set AX5043 to FULLTX mode */ - ret = ax5043_set_power_mode(conf, FULLTX); - if (ret) { - return ret; - } - - ax5043_spi_wait_xtal(conf, 100); - - /* Wait for the FIFO to become ready */ - val = 0; - while (!val) { - ax5043_spi_read_8(conf, &val, AX5043_REG_POWSTAT); - /* Select only the modem power state */ - val &= AX5043_SVMODEM; - if (millis() - start > timeout_ms) { - ret = -PQWS_TIMEOUT; - break; - } - } - - /* Fire-up the first data to the FIFO */ - ret = ax5043_spi_write(conf, AX5043_REG_FIFODATA, __tx_fifo_chunk, - (uint32_t) chunk_size); - if (ret) { - return ret; - } - __tx_active = 1; - /* Commit to FIFO ! */ - ret = ax5043_spi_write_8(conf, AX5043_REG_FIFOSTAT, AX5043_FIFO_COMMIT_CMD); - - return ret; -} - -int ax5043_tx_frame(ax5043_conf_t *conf, const uint8_t *in, uint32_t len, - uint8_t preamble_len, uint8_t postamble_len, uint32_t timeout_ms) { - int ret = 0; - - /* Wait for the previous frame to be transmitted */ - while (__tx_active) { - ret++; - } - - ret = ax5043_enable_pwramp(conf, AX5043_EXT_PA_ENABLE); - if (ret) { - return ret; - } - - ret = __tx_frame(conf, in, len, preamble_len, postamble_len, timeout_ms); - return ret; -} - -/** - * Wait the crystal to become ready - * @param conf the AX5043 configuration handler - * @param timeout_ms the timeout in milliseconds - * @return 0 on success or appropriate negative error code - */ -int ax5043_spi_wait_xtal(ax5043_conf_t *conf, uint32_t timeout_ms) { - int ret; - uint8_t val = 0x0; - uint32_t start = millis(); - - while (!val) { - ret = ax5043_spi_read_8(conf, &val, AX5043_REG_XTALSTATUS); - if (ret) { - return ret; - } - if ((millis() - start) > timeout_ms) { - return -PQWS_TIMEOUT; - } - } - return 0; -} - -int ax5043_spi_read_8(ax5043_conf_t *conf, uint8_t *out, uint16_t reg) { - int ret = PQWS_SUCCESS; - - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - *out = ax5043ReadReg(reg); - - return ret; -} - -int ax5043_spi_read_16(ax5043_conf_t *conf, uint16_t *out, uint16_t reg) { - int ret = PQWS_SUCCESS; - - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - *out = ax5043ReadReg2(reg); - - return ret; -} - -int ax5043_spi_read_24(ax5043_conf_t *conf, uint32_t *out, uint16_t reg) { - int ret = PQWS_SUCCESS; - - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - *out = ax5043ReadReg3(reg); - - return ret; -} - -int ax5043_spi_read_32(ax5043_conf_t *conf, uint32_t *out, uint16_t reg) { - int ret = PQWS_SUCCESS; - - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - *out = ax5043ReadReg4(reg); - - return ret; -} - -int ax5043_spi_write(ax5043_conf_t *conf, uint16_t reg, const uint8_t *in, - uint32_t len) { - int ret = PQWS_SUCCESS; - - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - ax5043WriteRegN(reg, in, len); - - return ret; -} - -int ax5043_spi_write_8(ax5043_conf_t *conf, uint16_t reg, uint8_t in) { - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - //printf("Reg\t%04x\t%02x\n", reg, in); - - ax5043WriteReg(reg, in); - - return PQWS_SUCCESS; -} - -int ax5043_spi_write_16(ax5043_conf_t *conf, uint16_t reg, uint16_t in) { - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - //printf("Reg\t%04x\t%02x\n", reg, (in >> 8)&0xFF); - //printf("Reg\t%04x\t%02x\n", reg+1, (in >> 0)&0xFF); - - ax5043WriteReg2(reg, in); - - return PQWS_SUCCESS; -} - -int ax5043_spi_write_24(ax5043_conf_t *conf, uint16_t reg, uint32_t in) { - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - //printf("Reg\t%04x\t%02x\n", reg, (in >> 16)&0xFF); - //printf("Reg\t%04x\t%02x\n", reg+1, (in >> 8)&0xFF); - //printf("Reg\t%04x\t%02x\n", reg+2, (in >> 0)&0xFF); - - ax5043WriteReg3(reg, in); - - return PQWS_SUCCESS; -} - -int ax5043_spi_write_32(ax5043_conf_t *conf, uint16_t reg, uint32_t in) { - if (!is_ax5043_conf_valid(conf)) { - return -PQWS_INVALID_PARAM; - } - - //printf("Reg\t%04x\t%02x\n", reg, (in >> 24)&0xFF); - //printf("Reg\t%04x\t%02x\n", reg+1, (in >> 16)&0xFF); - //printf("Reg\t%04x\t%02x\n", reg+2, (in >> 8)&0xFF); - //printf("Reg\t%04x\t%02x\n", reg+3, (in >> 0)&0xFF); - - ax5043WriteReg4(reg, in); - - return PQWS_SUCCESS; -} - -/** - * Sets properly some undocumented TX registers - * @param conf the AX5043 configuration handler - * @return 0 on success or appropriate negative error code - */ -static inline int set_tx_black_magic_regs(ax5043_conf_t *conf) { - int ret; - ret = ax5043_spi_write_8(conf, 0xF00, 0x0F); - if (ret) { - return ret; - } - - ret = ax5043_spi_write_8(conf, 0xF0C, 0x0); - if (ret) { - return ret; - } - - // Added by Jonathan Brandenburg - ret = ax5043_spi_write_8(conf, 0xF0D, 0x03); - if (ret) { - return ret; - } - - // Added by Jonathan Brandenburg - ret = ax5043_spi_write_8(conf, 0xF10, 0x03); - if (ret) { - return ret; - } - - // The following line is used for a TCXO - //ret = ax5043_spi_write_8(conf, 0xF11, 0x0); - // The following line is used for a crystal - ret = ax5043_spi_write_8(conf, 0xF11, 0x07); - if (ret) { - return ret; - } - - ret = ax5043_spi_write_8(conf, 0xF1C, 0x07); - if (ret) { - return ret; - } - - ret = ax5043_spi_write_8(conf, 0xF44, 0x24); - if (ret) { - return ret; - } - - /* Dafuq? Got it from RadioLab */ - ret = ax5043_spi_write_8(conf, 0xF18, 0x06); - return ret; -} - -/** - * Enables/Disables the power amplifier pin - * @param conf the AX5043 configuration handler - * @param enable 1 to enable 0 to disable - * @return 0 on success or appropriate negative error code - */ -int ax5043_enable_pwramp(ax5043_conf_t *conf, uint8_t enable) { - int ret; - ax5043_set_antsel(conf, enable); - ret = ax5043_spi_write_8(conf, AX5043_REG_PWRAMP, ~enable & 0x1); - - if (ret) { - usleep(PWRAMP_RAMP_PERIOD_US); - } - return ret; -} - -int ax5043_set_antsel(ax5043_conf_t *conf, uint8_t val) { - return ax5043_spi_write_8(conf, AX5043_REG_PINFUNCANTSEL, val & 0x1); -} - -/** - * Wait for the AX5043 to finish transmitting, putting new data in the FIFO as space becomes available - * @return 0 on success, or appropriate negative error code - */ -int ax5043_wait_for_transmit() { - if (!single_fifo_access) { - while (__tx_active) { - static int transmittedPostamble = 0; - - //usleep(100); - - int ret; - uint8_t data_cmd[3] = { AX5043_FIFO_VARIABLE_DATA_CMD, 0, 0 }; - size_t avail; - size_t chunk_size; - - if (!__ax5043_conf) { - return -PQWS_INVALID_PARAM; - } - - /* Determine if TX is done */ - uint8_t radiostate = 0; - ret = ax5043_spi_read_8(__ax5043_conf, &radiostate, - AX5043_REG_RADIOSTATE); - if (ret) { - return ret; - } - radiostate &= 0x0f; - - if (radiostate == 0) { - /* tx is done */ - __tx_frame_end(__ax5043_conf); - transmittedPostamble = 0; - printf("INFO: TX done\n"); - return PQWS_SUCCESS; - } - - /* Determine FIFO free space */ - uint16_t fifofree = 0; - ret = ax5043_spi_read_16(__ax5043_conf, &fifofree, - AX5043_REG_FIFOFREE1); - if (ret) { - return ret; - } - - /* If FIFO has free space fill in data */ - if (fifofree > AX5043_FIFO_FREE_THR && (__tx_remaining || !transmittedPostamble)) { - - /* Always left some space for the postamble for a simplified logic */ - avail = min_ul( - AX5043_FIFO_FREE_THR - sizeof(data_cmd) - sizeof(__postamble_cmd), - __tx_remaining); - - data_cmd[1] = (uint8_t) (avail + 1); - chunk_size = sizeof(data_cmd) + avail; - memcpy(__tx_fifo_chunk + sizeof(data_cmd), __tx_buf + __tx_buf_idx, - avail); - - if (avail == __tx_remaining) { - transmittedPostamble = 1; - - data_cmd[2] = AX5043_FIFO_PKTEND; - memcpy(__tx_fifo_chunk + chunk_size, __postamble_cmd, - sizeof(__postamble_cmd)); - chunk_size += sizeof(__postamble_cmd); - } - memcpy(__tx_fifo_chunk, data_cmd, sizeof(data_cmd)); - ax5043_spi_write(__ax5043_conf, AX5043_REG_FIFODATA, - __tx_fifo_chunk, (uint32_t) chunk_size); - /* Commit to FIFO ! */ - ret = ax5043_spi_write_8(__ax5043_conf, AX5043_REG_FIFOSTAT, - AX5043_FIFO_COMMIT_CMD); - - __tx_remaining -= (uint32_t) avail; - __tx_buf_idx += avail; - - } - } - } else { - while (__tx_active) { - int ret; - /* Determine if TX is done */ - uint8_t radiostate = 0; - ret = ax5043_spi_read_8(__ax5043_conf, &radiostate, - AX5043_REG_RADIOSTATE); - if (ret) { - return ret; - } - radiostate &= 0x0f; - if (radiostate == 0) { - /* tx is done */ - __tx_active = 0; - printf("INFO: TX done\n"); - } - } - } - - return PQWS_SUCCESS; -} From a76d43c0c5097c4ed7e4c8b3272eeca3269f3d1d Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Wed, 24 Jul 2019 12:21:52 -0400 Subject: [PATCH 194/194] old code removal --- afsk/main.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/afsk/main.c b/afsk/main.c index b4886b0c..bfd86ffa 100644 --- a/afsk/main.c +++ b/afsk/main.c @@ -61,15 +61,10 @@ ax25_conf_t hax25; static void init_rf(); int twosToInt(int val, int len); int get_tlm(int tlm[][5]); -long int timestamp; void config_x25(); void trans_x25(); - int upper_digit(int number); int lower_digit(int number); -int charging = 0; - -//uint16_t x_config = (0x2000 | 0x1800 | 0x0180 | 0x0018 | 0x0007 ); struct SensorConfig { int fd; @@ -193,8 +188,6 @@ int main(int argc, char *argv[]) { int tlm[7][5]; memset(tlm, 0, sizeof tlm); - timestamp = time(NULL); - tempSensor = config_sensor("/dev/i2c-3", 0x48, 0); sensor[PLUS_X] = config_sensor("/dev/i2c-1", 0x40, 400);