Skip to content

Commit

Permalink
Merge pull request #127 from nielsonm236/QOS1-implementation
Browse files Browse the repository at this point in the history
HA Toggle Header fixes
  • Loading branch information
nielsonm236 authored Nov 29, 2022
2 parents b1bf39a + bb23f62 commit eeec0c0
Show file tree
Hide file tree
Showing 19 changed files with 1,969 additions and 1,533 deletions.
2 changes: 1 addition & 1 deletion NetworkModule/.Idea_Groups/Vector_File.grp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Group File Created by IDEA
# Project: <NetworkModule>
# Sat Oct 15 06:37:27 2022
# Mon Nov 28 19:28:29 2022
#
"networkmodule_vector.o"
598 changes: 281 additions & 317 deletions NetworkModule/.Idea_Temp/COBJ.TMP

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions NetworkModule/.Idea_Temp/IDEA.ERR
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,13 @@ uip.o:
uip_arp.o:
uip_tcpapphub.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)memcmp.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)memmov.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)strcat0.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)strcmp0.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)strlen0.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libisl0.sm8)strncm.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)fctcpy.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)bmulx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)eeprom.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)imul.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)itolx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)itoly.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ladc.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ladd.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lcmp.o:
Expand All @@ -72,15 +70,13 @@ uip_tcpapphub.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgor.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgsbc.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgsub.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lgursh.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lneg.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lreg.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ltor.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)ludiv.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lumod.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)lzmp.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)rtol.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)sdivx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)smul.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)utolx.o:
(C:\Program Files (x86)\COSMIC\FSE_Compilers\CXSTM8\lib\libm0.sm8)xreg.o:
Expand Down
2 changes: 1 addition & 1 deletion NetworkModule/.Idea_Temp/IDEABLD.BAT
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
REM COMMAND FILE BUILT BY IDEA
REM Sat Oct 15 06:37:23 2022
REM Mon Nov 28 19:28:25 2022
REM
cxstm8 -v -l +strict +debug +modsl0 +split +warn "networkmodule_vector.c"
cxstm8 -v -l +strict +debug +modsl0 +split +warn "ds18b20.c" "enc28j60.c" "gpio.c" "httpd.c" "i2c.c" "main.c" "mqtt.c" "mqtt_pal.c" "spi.c" "timer.c" "uart.c" "uip.c" "uip_arp.c" "uip_tcpapphub.c"
Expand Down
84 changes: 12 additions & 72 deletions NetworkModule/DS18B20.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@
#include "uart.h"
#include "uipopt.h"

// #if BUILD_SUPPORT == BROWSER_ONLY_BUILD || BUILD_SUPPORT == MQTT_BUILD
// extern uint8_t DS18B20_scratch_byte[2]; // Array to store scratchpad bytes
uint8_t DS18B20_scratch_byte[2]; // Array to store scratchpad bytes
// read from DS18B20
// extern uint8_t DS18B20_scratch[5][2]; // Stores the temperature measurement
uint8_t DS18B20_scratch[5][2]; // Stores the temperature measurement
// for the DS18B20s

Expand Down Expand Up @@ -82,7 +79,6 @@ uint8_t ROM[8]; // ROM bytes
// [7] = CRC
uint8_t lastDiscrep = 0; // last discrepancy
uint8_t doneFlag = 0; // Done flag
// extern uint8_t FoundROM[5][8]; // Table of ROM codes
uint8_t FoundROM[5][8]; // Table of ROM codes
// [x][0] = Family Code
// [x][1] = LSByte serial number
Expand All @@ -94,20 +90,11 @@ uint8_t FoundROM[5][8]; // Table of ROM codes
// [x][7] = CRC
extern int numROMs; // Count of DS18B20 devices found

// extern uint8_t temp_FoundROM[5][8]; // Temporary table of old ROM codes
// // [x][0] = Family Code
// // [x][1] = LSByte serial number
// // [x][2] = byte 2 serial number
// // [x][3] = byte 3 serial number
// // [x][4] = byte 4 serial number
// // [x][5] = byte 5 serial number
// // [x][6] = MSByte serial number
// // [x][7] = CRC
uint8_t new_FoundROM_crc; // Used in calculation of the CRC for
// uint8_t new_FoundROM_crc; // Used in calculation of the CRC for
// the FoundROM table. Used to determine
// if a table change has occurred.
uint8_t old_FoundROM_crc; // Stores the prior FoundROM table CRC.
extern uint8_t redefine_temp_sensors; // Flag used to signal the need
// uint8_t old_FoundROM_crc; // Stores the prior FoundROM table CRC.
// extern uint8_t redefine_temp_sensors; // Flag used to signal the need
// to redefine the HA temp sensors
// via Auto Discovery messages

Expand Down Expand Up @@ -174,7 +161,6 @@ void get_temperature()
int i;
uint8_t j;
uint8_t device_num;
// extern uint8_t DS18B20_scratch[5][2];

// Read current temperature from up to 5 devices
for (device_num = 0; device_num < 5; device_num++) {
Expand Down Expand Up @@ -257,7 +243,6 @@ void convert_temperature(uint8_t device_num, uint8_t degCorF)
//
int16_t whole_temp;
uint8_t decimal_temp;
// extern uint8_t DS18B20_scratch[5][2];
uint8_t sign_char;

// Convert temperature reading to string.
Expand Down Expand Up @@ -398,10 +383,6 @@ void convert_temperature(uint8_t device_num, uint8_t degCorF)
whole_temp++;
sign_char = '-';
}
// else {
// // Positive number
// sign_char = ' ';
// }

// Extract whole temp and decimal temp parts of the DS18B20
// values
Expand Down Expand Up @@ -452,7 +433,6 @@ void convert_temperature(uint8_t device_num, uint8_t degCorF)
whole_temp = (int16_t)(F_temp2 / 16);
// Now calculate the "decimal" part of the display in degrees F
decimal_temp = (uint8_t)(F_temp2 & 0xf);
// sign_char = ' ';
if (F_temp2 < 0) {
// Must use twos complement if the degrees F result is negative
whole_temp = whole_temp * -1;
Expand Down Expand Up @@ -599,9 +579,9 @@ void one_wire_low(int wait)
void init_DS18B20(void)
{
// Initialize variables used in DS18B20 operation
new_FoundROM_crc = 0;
old_FoundROM_crc = 0;
redefine_temp_sensors = 0;
// new_FoundROM_crc = 0;
// old_FoundROM_crc = 0;
// redefine_temp_sensors = 0;
// Initialize temperature sensor arrays
memset(&DS18B20_scratch[0][0], 0, 10);
memset(&FoundROM[0][0], 0, 40);
Expand Down Expand Up @@ -635,9 +615,6 @@ void FindDevices(void)

numROMs = -1; // -1 indicates no devices
if (!reset_pulse()) { //Begins when a presence is detected

// UARTPrintf("\r\nPresence detected\r\n");

if (First()) { //Begins when at least one part is found
do {
numROMs++; // On first pass this increments numROMs to index 0
Expand All @@ -658,32 +635,14 @@ void FindDevices(void)
}
// Add up the crc values for each entry to act as a CRC for the FoundROM
// table
new_FoundROM_crc = (uint8_t)(FoundROM[0][7] + FoundROM[1][7] + FoundROM[2][7] + FoundROM[3][7] + FoundROM[4][7]);

// UARTPrintf("\r\nDS18B20 FindDevices numROMs = ");
// if (numROMs >= 0) {
// emb_itoa(numROMs, OctetArray, 10, 2);
// UARTPrintf(OctetArray);
// }
// else if (numROMs == -1) UARTPrintf("-1");
// else UARTPrintf("unitialized");
// UARTPrintf("\r\n");

if (new_FoundROM_crc != old_FoundROM_crc) {
// new_FoundROM_crc = (uint8_t)(FoundROM[0][7] + FoundROM[1][7] + FoundROM[2][7] + FoundROM[3][7] + FoundROM[4][7]);

// if (new_FoundROM_crc != old_FoundROM_crc) {
// Signal the main loop that the temp sensors need to be updated in the
// Browser display and over MQTT
redefine_temp_sensors = 1;
old_FoundROM_crc = new_FoundROM_crc;
}

// UARTPrintf("new_FoundROM_crc = ");
// emb_itoa(new_FoundROM_crc, OctetArray, 16, 2);
// UARTPrintf(OctetArray);
// UARTPrintf(" redefine_temp_sensors = ");
// emb_itoa(redefine_temp_sensors, OctetArray, 16, 2);
// UARTPrintf(OctetArray);
// UARTPrintf("\r\n");

// redefine_temp_sensors = 1;
// old_FoundROM_crc = new_FoundROM_crc;
// }
}


Expand Down Expand Up @@ -761,25 +720,8 @@ uint8_t Next(void)
}
} while(n < 8); //loop until through all ROM bytes 0-7

// {
// uint8_t i;
// UARTPrintf("\r\nROM bytes: ");
// for (i=0; i<8; i++) {
// emb_itoa(ROM[i], OctetArray, 16, 2);
// UARTPrintf(OctetArray);
// UARTPrintf(" ");
// }
// UARTPrintf("\r\n");
// }

// Calculate CRC for first 7 ROM bytes
crc = dallas_crc8(ROM, 7);

// UARTPrintf("\r\nDS18B20 CRC:");
// if (crc != ROM[7]) UARTPrintf("Fail");
// else UARTPrintf("Pass");
// UARTPrintf("\r\n");


if (m < 65 || (crc != ROM[7])) lastDiscrep = 0;
// if search was unsuccessful then reset the last discrepancy to 0
Expand Down Expand Up @@ -817,5 +759,3 @@ uint8_t dallas_crc8(uint8_t *data, uint8_t size)
}
return crc;
}

// #endif // BUILD_SUPPORT == BROWSER_ONLY_BUILD || BUILD_SUPPORT == MQTT_BUILD
32 changes: 30 additions & 2 deletions NetworkModule/Enc28j60.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,26 @@ uint16_t Enc28j60Receive(uint8_t* pBuffer)
// Check for buffer overflow - RXERIF (bit 0) of EIR register
// If overflow increment the error counter
if (Enc28j60ReadReg(BANKX_EIR) & 0x01) {

#if DEBUG_SUPPORT != 11
UARTPrintf("Enc28j60Receive OVERFLOW detected\r\n");
#endif // DEBUG_SUPPORT != 11

RXERIF_counter++;
// Clear RXERIF
Enc28j60ClearMaskReg(BANKX_EIR, (1<<BANKX_EIR_RXERIF));
}

// Check for at least 1 waiting packet in the buffer
Enc28j60SwitchBank(BANK1);
if (Enc28j60ReadReg(BANK1_EPKTCNT) == 0) return 0;
if (Enc28j60ReadReg(BANK1_EPKTCNT) == 0) {
return 0;
}
else {
// #if DEBUG_SUPPORT != 11
// UARTPrintf("Enc28j60Receive NO PACKETS detected\r\n");
// #endif // DEBUG_SUPPORT != 11
}

select();

Expand All @@ -670,7 +682,14 @@ uint16_t Enc28j60Receive(uint8_t* pBuffer)
// host or client we connect to. For this reason we know we can throw away
// any packet that exceeds MAXFRAME.
//
if (nBytes <= ENC28J60_MAXFRAME) SpiReadChunk(pBuffer, nBytes);
if (nBytes <= ENC28J60_MAXFRAME) {
SpiReadChunk(pBuffer, nBytes);
}
else {
#if DEBUG_SUPPORT != 11
UARTPrintf("Enc28j60Receive MAXFRAME exceeded\r\n");
#endif // DEBUG_SUPPORT != 11
}

deselect();

Expand All @@ -693,6 +712,15 @@ uint16_t Enc28j60Receive(uint8_t* pBuffer)

// And decrement PacketCounter
Enc28j60SetMaskReg(BANKX_ECON2 , (1<<BANKX_ECON2_PKTDEC));

#if DEBUG_SUPPORT != 11
if (nBytes > 500) {
UARTPrintf("Enc28j60Received nBytes = ");
emb_itoa(nBytes, OctetArray, 10, 3);
UARTPrintf(OctetArray);
UARTPrintf("\r\n");
}
#endif // DEBUG_SUPPORT != 11

return nBytes;
}
Expand Down
2 changes: 2 additions & 0 deletions NetworkModule/Enc28j60.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
#define ENC28J60_LEDB 12

// Maximum frame length in bytes to prevent possible buffer overflows
// The factor pushing the MAXFRAME is the size of the largest Home Assistant
// Config message plus headers.
// #define ENC28J60_MAXFRAME 500
#define ENC28J60_MAXFRAME 550

Expand Down
6 changes: 3 additions & 3 deletions NetworkModule/Gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ extern uint8_t stored_pin_control[16]; // Per pin control settings stored in
// clever implementation.

// Ccreate a variable with the structure of the port registers and define
// it's position on the memory location of the port registers
// this way we can manipulate this data as an array of ports
volatile struct io_registers io_reg[ NUM_PORTS ] @0x5000; // make room for PA .. PG starting at 0x5000
// its position on the memory location of the port registers. This way we
// can manipulate this data as an array of ports.
volatile struct io_registers io_reg[ NUM_PORTS ] @0x5000; // Make room for PA .. PG starting at 0x5000

// Define the pair PORT:BIT for each of the 16 I/Os
const struct io_mapping io_map[16] = {
Expand Down
Loading

0 comments on commit eeec0c0

Please sign in to comment.