STM32 chipId and 1st CAN driver prototype

This commit is contained in:
2024-02-22 21:58:07 +03:00
parent 1133883b25
commit 3c9e30b28a
9 changed files with 574 additions and 41 deletions

View File

@@ -13,6 +13,9 @@
-DMULTIVENT_DISABLE -DMULTIVENT_DISABLE
-DMOTOR_DISABLE -DMOTOR_DISABLE
-D CANDRV
-D THERMOSTAT_CHECK_PERIOD=5000
-DENABLE_HWSERIAL1 -DENABLE_HWSERIAL1
-DdebugSerialPort=Serial1 -DdebugSerialPort=Serial1
@@ -21,8 +24,8 @@
#-DFLASH_DATA_SECTOR #-DFLASH_DATA_SECTOR
#-DFLASH_PAGE_NUMBER #-DFLASH_PAGE_NUMBER
-D PIO_FRAMEWORK_ARDUINO_ENABLE_MASS_STORAGE # -D PIO_FRAMEWORK_ARDUINO_ENABLE_MASS_STORAGE
-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC_AND_MSC # -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC_AND_MSC
#-DdebugSerialPort=SerialUSB #-DdebugSerialPort=SerialUSB
#-DSerialPortType=USBSerial #-DSerialPortType=USBSerial

322
lighthub/candriver.cpp Normal file
View File

@@ -0,0 +1,322 @@
#ifdef CANDRV
#include <candriver.h>
#include <Arduino.h>
#include <main.h>
#if defined(ARDUINO_ARCH_STM32)
#include <STM32_CAN.h>
STM32_CAN STMCan( CAN1, ALT, RX_SIZE_64, TX_SIZE_16 );
#endif
#if defined(ARDUINO_ARCH_ESP32)
#include <CAN.h>
#endif
#if defined(__SAM3X8E__)
#include <due_can.h>
#endif
#include <config.h>
//#include <systemconfigdata.h>
extern systemConfig sysConf;
void printFrame(datagram_t * frame, uint8_t len ) {
debugSerial.print(" Data: 0x");
for (int count = 0; count < len; count++) {
debugSerial.print(frame->data[count], HEX);
debugSerial.print(" ");
}
debugSerial.println();
}
bool canDriver::upTime(uint32_t ut)
{
// return 0;
canid_t id;
datagram_t packet;
id.reserve=0;
id.status=1;
id.payloadType=payloadType::metric;
id.deviceId=controllerId;
id.itemId=metricType::UpTime;
packet.metric1=ut;
debugSerial<<("UpTime")<<endl;
return write (id.id, &packet, 4);
}
bool canDriver::salt(uint32_t salt)
{
canid_t id;
datagram_t packet;
id.reserve=0;
id.status=1;
id.payloadType=payloadType::metric;
id.deviceId=controllerId;
id.itemId=metricType::Salt;
packet.metric1=salt;
debugSerial<<("Salt")<<endl;
return write (id.id, &packet, 4);
}
bool canDriver::lookupMAC()
{
// return 0;
canid_t id;
datagram_t packet;
bool res;
id.reserve=0;
id.status=0;
id.payloadType=payloadType::lookupMAC;
id.deviceId=0;
id.itemId=0; //CRC?
memcpy(packet.mac,sysConf.mac,6);
debugSerial<<("Lookup MAC")<<endl;
res=write (id.id, &packet, 6);
if (res) state=canState::MACLookup;
else state=canState::Error;
responseTimer=millisNZ();
return res;
}
bool canDriver::sendRemoteID(macAddress mac)
{
canid_t id;
//datagram_t packet;
bool res=false;
id.reserve=0;
id.status=1; //response
id.payloadType=payloadType::lookupMAC;
id.deviceId=100; //Retrieved controllerID
id.itemId=200; //CRC of remote config
//packet.data[0]=1;
debugSerial<<("Send remote ID")<<endl;
res = write (id.id);//,&packet,8);
if (res) state=canState::HaveId;
else state=canState::Error;
// responseTimer=millisNZ(); ????????
return res;
}
bool canDriver::begin()
{
ready=false;
//STM32
#if defined(ARDUINO_ARCH_STM32)
//Can= new STM32_CAN( CAN1, ALT );
//if (!Can) return false;
STMCan.begin(); //with retransmission
STMCan.setBaudRate(125000);
// STMCan.setFilter( 0, 0x153, 0x1FFFFFFF );
#endif
//ESP
#if defined(ARDUINO_ARCH_ESP32)
CAN.setPins(GPIO_NUM_35,GPIO_NUM_5);//(rx, tx);
// start the CAN bus at 500 kbps
if (!CAN.begin(125000)) {return false; }
#endif
#if defined(__SAM3X8E__)
Can0.begin(CAN_BPS_125K);
#endif
debugSerial<<"CAN initialized"<<endl;
ready=true;
return true;
}
void canDriver::Poll()
{
// return ;
if (!ready) return;
//STM32
#if defined(ARDUINO_ARCH_STM32)
if (STMCan.read(CAN_RX_msg))
{
processPacket( CAN_RX_msg.id, (datagram_t*) CAN_RX_msg.buf,CAN_RX_msg.len);
}
#endif
#if defined(ARDUINO_ARCH_ESP32)
// try to parse packet
int packetSize = CAN.parsePacket();
if (packetSize ){//|| CAN.packetId() != -1) {
// received a packet
debugSerialPort.print("Received ");
if (CAN.packetExtended()) {
debugSerialPort.print("extended ");
}
if (CAN.packetRtr()) {
// Remote transmission request, packet contains no data
debugSerialPort.print("RTR ");
}
debugSerialPort.print("packet with id 0x");
debugSerialPort.print(CAN.packetId(), HEX);
if (CAN.packetRtr()) {
debugSerialPort.print(" and requested length ");
debugSerialPort.println(CAN.packetDlc());
} else {
debugSerialPort.print(" and length ");
//debugSerialPort.println(packetSize);
debugSerialPort.println(CAN.packetDlc());
datagram_t packet;
// only print packet data for non-RTR packets
int i=0;
while (CAN.available()) {
packet.data[i++]=CAN.read();
//debugSerialPort.print((char)CAN.read());
if (i>=8) break;
}
debugSerialPort.println();
processPacket( CAN.packetId(), &packet,i);
}
}
#endif
//DUE
#if defined(__SAM3X8E__)
CAN_FRAME incoming;
if (Can0.available() > 0) {
Can0.read(incoming);
printFrame(incoming);
}
#endif
//State machine
switch (state)
{
case canState::MACLookup:
if (isTimeOver(responseTimer,millis(),1000UL))
{
responseTimer=millisNZ();
state=canState::Error;
errorSerial<<"CAN Timeout"<<endl;
}
break;
case canState::Error:
if (isTimeOver(responseTimer,millis(),10000UL))
lookupMAC();
break;
// case canState::HaveId:
}
}
bool canDriver::processPacket(uint32_t rawid, datagram_t *packet, uint8_t len, bool rtr)
{
canid_t id;
id.id = rawid;
debugSerial.print("CAN Received ");
debugSerialPort.print(len);
debugSerialPort.print(" bytes id 0x");
debugSerialPort.println(id.id,HEX);
printFrame(packet,len);
if (id.status)
//Responces
switch (state)
{
case canState::MACLookup:
if ((id.payloadType == payloadType::lookupMAC) && (len>=6))
{
debugSerial<<"Got Controller CAN addr: "<<id.deviceId<<endl;
controllerId=id.deviceId;
}
return true;
case canState::HaveId:
break;
case canState::Error:
return false;
}
else //Requests
{
if (id.payloadType == payloadType::lookupMAC)
{
return sendRemoteID(packet->mac);
//debugSerial<<"ID requested"<<endl;
}
}
return false;
}
bool canDriver::write(uint32_t msg_id, datagram_t * buf, uint8_t size)
{ //return 0;
if (!ready) errorSerial<<"CAN not initialized"<<endl;
bool res;
if (size>8) size = 8;
//STM32
#if defined(ARDUINO_ARCH_STM32)
//if (!Can) return 0;
if (buf) for(uint8_t i=0;i<size; i++) CAN_TX_msg.buf[i]=buf->data[i];
CAN_TX_msg.id = msg_id;
CAN_TX_msg.flags.extended = 1; // To enable extended ID
CAN_TX_msg.len=size;
if (res=STMCan.write(CAN_TX_msg)) debugSerial<<("CAN Wrote ")<<size<<" bytes"<<endl;
else debugSerial.println("CAN Write error");
return res;
#endif
//ESP
#if defined(ARDUINO_ARCH_ESP32)
CAN.beginExtendedPacket(msg_id,size);
CAN.write(buf->data,size);
//for(uint8_t i=0;i<size; i++) CAN.write(buf[i]);
if (res=CAN.endPacket()) debugSerial.println("CAN Wrote");
else debugSerial.println("CAN Write error");
return res;
#endif
#if defined(__SAM3X8E__)
CAN_FRAME outGoting;
outgoing.id = 0x400;
outgoing.extended = true;
outgoing.priority = 4; //0-15 lower is higher priority
outgoing.data.s0 = 0xFEED;
outgoing.data.byte[2] = 0xDD;
outgoing.data.byte[3] = 0x55;
outgoing.data.high = 0xDEADBEEF;
Can0.sendFrame(outgoing);
#endif
}
#endif

125
lighthub/candriver.h Normal file
View File

@@ -0,0 +1,125 @@
#pragma once
#ifdef CANDRV
#if defined(ARDUINO_ARCH_STM32)
#if !defined(HAL_CAN_MODULE_ENABLED)
#define HAL_CAN_MODULE_ENABLED
#endif
#include <STM32_CAN.h>
#endif
#include <itemCmd.h>
//#include <config.h> NO!
typedef uint8_t macAddress[6];
#pragma pack(push, 1)
typedef union
{
uint32_t id;
struct
{
uint16_t itemId;
uint8_t deviceId;
uint8_t payloadType:4;
uint8_t status:1;
uint8_t reserve:3; //0
};
} canid_t;
enum payloadType
{
itemCommand=1,
lookupMAC=2,
configFrame=3,
OTAFrame=4,
auth=5,
metric=6,
sysCmd=7
};
enum metricType
{
MAC=1,
IP=2,
NetMask=3,
GW=4,
DNS=5,
UpTime=6,
Salt=7
};
enum commandType
{
reboot=1,
get=2,
save=3,
load=4
};
#define MAXCANID 0x1FFFFFFF
// Request item status: id.status=1;deviceId=[0xFF | deviceId];itemId=x; RTR bit=true
// Request on config: id.status=0;deviceId=0;itemId=x payload.mac=mac;crc16=crc_current_config
typedef union {
uint8_t data[8];
struct {
itemCmdStore cmd;
itemArgStore param;
};
struct {
macAddress mac;
uint16_t currentConfCRC;
};
struct {
uint8_t sysCmd;
uint8_t sysCmdData[7];
};
struct {
uint32_t metric1;
uint32_t metric2;
};
} datagram_t;
enum canState
{
Unknown=0,
MACLookup=2,
HaveId=3,
ConfigFrameRequested=4,
ConfigFrameReceived=5,
ConfigLoaded=6,
Error=7
};
#pragma pack(pop)
class canDriver
{
public:
canDriver(){ready=false; controllerId=0; responseTimer=0; state=canState::Unknown;};
bool upTime(uint32_t ut);
bool salt(uint32_t salt);
bool lookupMAC();
bool sendRemoteID(macAddress mac);
bool begin();
void Poll();
bool processPacket(uint32_t rawid, datagram_t *packet, uint8_t len, bool rtr=false);
bool write(uint32_t msg_id, datagram_t * buf = NULL, uint8_t size=0);
private:
#if defined(ARDUINO_ARCH_STM32)
CAN_message_t CAN_RX_msg;
CAN_message_t CAN_TX_msg;
#endif
bool ready;
uint8_t controllerId;
canState state;
uint32_t responseTimer;
};
#endif //

View File

@@ -67,6 +67,11 @@ static char syslogDeviceHostname[16];
flashStream sysConfStream; flashStream sysConfStream;
systemConfig sysConf(&sysConfStream); systemConfig sysConf(&sysConfStream);
#ifdef CANDRV
canDriver LHCAN;
#endif
extern long timer0_overflow_count; extern long timer0_overflow_count;
#ifdef WIFI_ENABLE #ifdef WIFI_ENABLE
WiFiClient ethClient; WiFiClient ethClient;
@@ -104,7 +109,7 @@ const char verval_P[] PROGMEM = QUOTE(PIO_SRC_REV);
char cryptoKey[] = QUOTE(SHAREDSECRET); char cryptoKey[] = QUOTE(SHAREDSECRET);
#endif #endif
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
UID UniqueID; UID UniqueID;
#endif #endif
@@ -482,7 +487,7 @@ else
return;// -7; return;// -7;
} }
#endif //NOIP
void printMACAddress() { void printMACAddress() {
//macAddress * mac = sysConf.getMAC(); //macAddress * mac = sysConf.getMAC();
@@ -494,7 +499,7 @@ void printMACAddress() {
} }
} }
#endif //NOIP
char* getStringFromConfig(aJsonObject * a, int i) char* getStringFromConfig(aJsonObject * a, int i)
{ {
@@ -1677,18 +1682,7 @@ int cmdFunctionOTAPwd(int arg_cnt, char **args)
return 200; return 200;
} }
int cmdFunctionSetMac(int arg_cnt, char **args) {
char dummy;
uint8_t mac[6];
if (sscanf(args[1], "%x:%x:%x:%x:%x:%x%c", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5], &dummy) < 6) {
errorSerial<<F("could not parse: ")<<args[1];
return 400;
}
sysConf.setMAC(mac);
printMACAddress();
infoSerial<<F("Updated\n");
return 200;
}
int cmdFunctionGet(int arg_cnt, char **args) { int cmdFunctionGet(int arg_cnt, char **args) {
@@ -1736,6 +1730,23 @@ return 500;
#endif //NOIP #endif //NOIP
int cmdFunctionSetMac(int arg_cnt, char **args) {
char dummy;
uint8_t mac[6];
if (sscanf(args[1], "%x:%x:%x:%x:%x:%x%c", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5], &dummy) < 6) {
errorSerial<<F("could not parse: ")<<args[1];
return 400;
}
sysConf.setMAC(mac);
printMACAddress();
#ifdef CANDRV
LHCAN.lookupMAC();
#endif
infoSerial<<F("Updated\n");
return 200;
}
int cmdFunctionClearEEPROM(int arg_cnt, char **args){ int cmdFunctionClearEEPROM(int arg_cnt, char **args){
#ifdef FS_STORAGE #ifdef FS_STORAGE
if (SPIFFS.format()) infoSerial<<F("FS Formatted\n"); if (SPIFFS.format()) infoSerial<<F("FS Formatted\n");
@@ -2319,7 +2330,7 @@ while ((digitalRead(CONFIG_CLEAN_PIN)==LOW) && !needClean)
serialDebugLevel=sysConf.getSerialDebuglevel(); serialDebugLevel=sysConf.getSerialDebuglevel();
udpDebugLevel=sysConf.getUdpDebuglevel(); udpDebugLevel=sysConf.getUdpDebuglevel();
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
memset(&UniqueID,0,sizeof(UniqueID)); memset(&UniqueID,0,sizeof(UniqueID));
#endif #endif
@@ -2338,9 +2349,10 @@ while ((digitalRead(CONFIG_CLEAN_PIN)==LOW) && !needClean)
// Serial.print("Sig4="); // Serial.print("Sig4=");
// Serial.println(FLASH_START[0],HEX); // Serial.println(FLASH_START[0],HEX);
#if not defined(NOIP)
//#if not defined(NOIP)
setupMacAddress(); //тут почему-то не считывается из флэш setupMacAddress(); //тут почему-то не считывается из флэш
#endif //#endif
#ifdef _modbus #ifdef _modbus
#ifdef CONTROLLINO #ifdef CONTROLLINO
@@ -2394,7 +2406,12 @@ WiFi.onEvent(WiFiEvent);
#endif #endif
#endif //NOIP #endif //NOIP
loadConfigFromEEPROM(); loadConfigFromEEPROM();
#ifdef CANDRV
LHCAN.begin();
LHCAN.lookupMAC();
#endif
} }
void printFirmwareVersionAndBuildOptions() { void printFirmwareVersionAndBuildOptions() {
@@ -2584,15 +2601,21 @@ infoSerial<<F("\n(+)MERCURY");
#else #else
infoSerial<<F("\n(-)MERCURY"); infoSerial<<F("\n(-)MERCURY");
#endif #endif
#ifdef CANDRV
infoSerial<<F("\n(+)CAN");
#else
infoSerial<<F("\n(-)CAN");
#endif
//#ifdef IPMODBUS //#ifdef IPMODBUS
//infoSerial<<F("\n(+)IPMODBUS"); //infoSerial<<F("\n(+)IPMODBUS");
//#endif //#endif
infoSerial<<endl; infoSerial<<endl;
// WDT_Disable( WDT ) ; // WDT_Disable( WDT ) ;
#if defined(__SAM3X8E__) #if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
debugSerial<<F("Reading 128 bits unique identifier")<<endl ; debugSerial<<F("Reading unique identifier")<<endl ;
ReadUniqueID( UniqueID.UID_Long ) ; ReadUniqueID( UniqueID.UID_Long ) ;
infoSerial<< F ("ID: "); infoSerial<< F ("ID: ");
@@ -2611,7 +2634,8 @@ void publishStat(){
char intbuf[16]; char intbuf[16];
uint32_t ut = millis()/1000UL; uint32_t ut = millis()/1000UL;
#if not defined (NOIP) #if not defined (NOIP)
if (!mqttClient.connected() || ethernetIdleCount) return; if (mqttClient.connected() && !ethernetIdleCount)
{
setTopic(topic,sizeof(topic),T_DEV); setTopic(topic,sizeof(topic),T_DEV);
strncat_P(topic, stats_P, sizeof(topic)-1); strncat_P(topic, stats_P, sizeof(topic)-1);
strncat(topic, "/", sizeof(topic)); strncat(topic, "/", sizeof(topic));
@@ -2630,19 +2654,34 @@ void publishStat(){
strncat_P(topic, state_P, sizeof(topic)-1); strncat_P(topic, state_P, sizeof(topic)-1);
strncpy_P(intbuf, ready_P, sizeof(intbuf)-1); strncpy_P(intbuf, ready_P, sizeof(intbuf)-1);
mqttClient.publish(topic,intbuf,true); mqttClient.publish(topic,intbuf,true);
}
#endif //NOIP #endif //NOIP
#ifdef CRYPT #ifdef CRYPT
RNG.rand((uint8_t *) &cryptoSalt,sizeof(cryptoSalt)); RNG.rand((uint8_t *) &cryptoSalt,sizeof(cryptoSalt));
#if not defined (NOIP)
if (mqttClient.connected() && !ethernetIdleCount)
{
setTopic(topic,sizeof(topic),T_DEV); setTopic(topic,sizeof(topic),T_DEV);
//strncat_P(topic, stats_P, sizeof(topic)-1); //strncat_P(topic, stats_P, sizeof(topic)-1);
//strncat(topic, "/", sizeof(topic)); //strncat(topic, "/", sizeof(topic));
strncat_P(topic, salt_P, sizeof(topic)-1); strncat_P(topic, salt_P, sizeof(topic)-1);
printUlongValueToStr(intbuf, cryptoSalt); printUlongValueToStr(intbuf, cryptoSalt);
mqttClient.publish(topic,intbuf,true); mqttClient.publish(topic,intbuf,true);
}
#endif
#ifdef CANDRV
LHCAN.salt(cryptoSalt);
#endif
#endif #endif
#ifdef CANDRV
LHCAN.upTime(ut);
#endif
} }
#if not defined (NOIP) //#if not defined (NOIP)
void setupMacAddress() { void setupMacAddress() {
//Check MAC, stored in NVRAM //Check MAC, stored in NVRAM
@@ -2661,7 +2700,7 @@ if (!sysConf.getMAC()) {
WiFi.begin(); WiFi.begin();
WiFi.macAddress(sysConf.mac); WiFi.macAddress(sysConf.mac);
#elif defined(__SAM3X8E__) #elif defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
//Lets make MAC from MPU serial# //Lets make MAC from MPU serial#
sysConf.mac[0]=0xDE; sysConf.mac[0]=0xDE;
@@ -2674,8 +2713,12 @@ if (!sysConf.getMAC()) {
#endif #endif
} }
printMACAddress(); printMACAddress();
#ifdef CANDRV
// LHCAN.lookupMAC();
#endif
} }
#endif //NOIP //#endif //NOIP
void setupCmdArduino() { void setupCmdArduino() {
//cmdInit(uint32_t(SERIAL_BAUD)); //cmdInit(uint32_t(SERIAL_BAUD));
@@ -2757,9 +2800,8 @@ void loop_main() {
if (items) { if (items) {
if (isNotRetainingStatus()) pollingLoop(); if (isNotRetainingStatus()) pollingLoop();
yield(); yield();
thermoLoop();
} }
thermoLoop();
yield(); yield();
inputLoop(CHECK_INPUT); inputLoop(CHECK_INPUT);
@@ -2774,6 +2816,10 @@ void loop_main() {
if (initializedListeners) ipmodbusLoop(); if (initializedListeners) ipmodbusLoop();
#endif #endif
#ifdef CANDRV
LHCAN.Poll();
#endif
} }
//static uint32_t tm=0; //static uint32_t tm=0;
@@ -2814,6 +2860,10 @@ inputLoop(CHECK_INPUT);
#ifdef IPMODBUS #ifdef IPMODBUS
if (initializedListeners) ipmodbusLoop(); if (initializedListeners) ipmodbusLoop();
#endif #endif
#ifdef CANDRV
LHCAN.Poll();
#endif
} }
#if not defined (NOIP) #if not defined (NOIP)
@@ -2837,6 +2887,10 @@ void modbusIdle(void) {
yield(); yield();
inputLoop(CHECK_INPUT); inputLoop(CHECK_INPUT);
#ifdef CANDRV
LHCAN.Poll();
#endif
#if not defined (NOIP) #if not defined (NOIP)
if (lanLoop() > HAVE_IP_ADDRESS) if (lanLoop() > HAVE_IP_ADDRESS)
{ // Begin network runners { // Begin network runners
@@ -3042,8 +3096,17 @@ void thermoLoop(void) {
if (!isTimeOver(timerThermostatCheck,millis(),THERMOSTAT_CHECK_PERIOD)) if (!isTimeOver(timerThermostatCheck,millis(),THERMOSTAT_CHECK_PERIOD))
return; return;
timerThermostatCheck = millis();// + THERMOSTAT_CHECK_PERIOD;
publishStat();
#ifndef DISABLE_FREERAM_PRINT
//(thermostatCheckPrinted) ?
debugSerial<<F("RAM=")<<freeRam()<<F(" Locks:")<<configLocked<<F(" Timer:")<<timerCount<<endl;
#endif
if (!items) return; if (!items) return;
bool thermostatCheckPrinted = false; //bool thermostatCheckPrinted = false;
configLocked++; configLocked++;
for (aJsonObject *thermoItem = items->child; thermoItem; thermoItem = thermoItem->next) { for (aJsonObject *thermoItem = items->child; thermoItem; thermoItem = thermoItem->next) {
if ((thermoItem->type == aJson_Array) && (aJson.getArrayItem(thermoItem, I_TYPE)->valueint == CH_THERMO)) if ((thermoItem->type == aJson_Array) && (aJson.getArrayItem(thermoItem, I_TYPE)->valueint == CH_THERMO))
@@ -3092,17 +3155,11 @@ void thermoLoop(void) {
} }
} }
else debugSerial<<F(" Expired\n"); else debugSerial<<F(" Expired\n");
thermostatCheckPrinted = true; // thermostatCheckPrinted = true;
} //item is termostat } //item is termostat
} //for } //for
configLocked--; configLocked--;
timerThermostatCheck = millis();// + THERMOSTAT_CHECK_PERIOD;
publishStat();
#ifndef DISABLE_FREERAM_PRINT
(thermostatCheckPrinted) ? debugSerial<<F("\nRAM=")<<freeRam()<<F(" Locks:")<<configLocked: debugSerial<<F(" ")<<freeRam()<<F(" Locks:")<<configLocked;
debugSerial<<F(" Timer:")<<timerCount<<endl;
#endif
} }

View File

@@ -206,6 +206,9 @@ extern Streamlog errorSerial;
#include "stdarg.h" #include "stdarg.h"
#include "item.h" #include "item.h"
#include "inputs.h" #include "inputs.h"
#ifdef CANDRV
#include <candriver.h>
#endif
#ifdef _artnet #ifdef _artnet
extern Artnet *artnet; extern Artnet *artnet;
@@ -243,15 +246,17 @@ bool isNotRetainingStatus();
#if not defined (NOIP) #if not defined (NOIP)
void mqttCallback(char *topic, byte *payload, unsigned int length); void mqttCallback(char *topic, byte *payload, unsigned int length);
void printMACAddress();
lan_status lanLoop(); lan_status lanLoop();
int loadConfigFromHttp(); int loadConfigFromHttp();
void onInitialStateInitLAN(); void onInitialStateInitLAN();
void onMQTTConnect(); void onMQTTConnect();
void ip_ready_config_loaded_connecting_to_broker(); void ip_ready_config_loaded_connecting_to_broker();
void setupMacAddress();
#endif #endif
void setupMacAddress();
void printMACAddress();
#ifndef OWIRE_DISABLE #ifndef OWIRE_DISABLE
void Changed(int i, DeviceAddress addr, float currentTemp); void Changed(int i, DeviceAddress addr, float currentTemp);
#endif #endif

View File

@@ -129,7 +129,9 @@
#define INTERVAL_SLOW_POLLING 1000 #define INTERVAL_SLOW_POLLING 1000
//#define INTERVAL_POLLING 100 //#define INTERVAL_POLLING 100
#ifndef THERMOSTAT_CHECK_PERIOD
#define THERMOSTAT_CHECK_PERIOD 30000 #define THERMOSTAT_CHECK_PERIOD 30000
#endif
#ifndef OW_UPDATE_INTERVAL #ifndef OW_UPDATE_INTERVAL
#define OW_UPDATE_INTERVAL 5000 #define OW_UPDATE_INTERVAL 5000

View File

@@ -1,3 +1,4 @@
#pragma once
#define SYSCONF_OFFSET 0 #define SYSCONF_OFFSET 0
#define EEPROM_offset_NotAlligned SYSCONF_OFFSET+sizeof(systemConfigData) #define EEPROM_offset_NotAlligned SYSCONF_OFFSET+sizeof(systemConfigData)
#define SYSCONF_SIZE EEPROM_offsetJSON #define SYSCONF_SIZE EEPROM_offsetJSON

View File

@@ -368,6 +368,21 @@ uint32_t ReadUniqueID( uint32_t * pdwUniqueID )
return *(uint32_t *)(IFLASH1_ADDR + 128); // dont remove: SAM defect workaround - MPU dont leave Unique Identifier mode until read flash out UID of range return *(uint32_t *)(IFLASH1_ADDR + 128); // dont remove: SAM defect workaround - MPU dont leave Unique Identifier mode until read flash out UID of range
#elif defined(ARDUINO_ARCH_STM32)
#define UID_BASE 0x1FFFF7E8
uint16_t *idBase0 = (uint16_t*)(UID_BASE);
uint16_t *idBase1 = (uint16_t*)(UID_BASE + 0x02);
uint32_t *idBase2 = (uint32_t*)(UID_BASE + 0x04);
uint32_t *idBase3 = (uint32_t*)(UID_BASE + 0x08);
pdwUniqueID[0] = *idBase0;
pdwUniqueID[1] = *idBase1;
pdwUniqueID[2] = *idBase2;
pdwUniqueID[3] = *idBase3;
return 1;
#else #else
return 0; return 0;
#endif #endif

View File

@@ -258,7 +258,7 @@ lib_deps =
;ArduinoMDNS ;ArduinoMDNS
;ESPmDNS ;ESPmDNS
https://github.com/khoih-prog/TimerInterrupt_Generic.git https://github.com/khoih-prog/TimerInterrupt_Generic.git
https://github.com/sandeepmistry/arduino-CAN.git
[env:due] [env:due]
;Experimental target with universal Ethernet Library ;Experimental target with universal Ethernet Library
@@ -326,6 +326,8 @@ lib_deps =
ArduinoMDNS ArduinoMDNS
https://github.com/khoih-prog/TimerInterrupt_Generic.git https://github.com/khoih-prog/TimerInterrupt_Generic.git
rweather/Crypto rweather/Crypto
collin80/can_common
collin80/due_can
monitor_speed = 115200 monitor_speed = 115200
[env:mega2560slim] [env:mega2560slim]
@@ -977,6 +979,7 @@ lib_deps =
; ArduinoMDNS ; ArduinoMDNS
https://github.com/khoih-prog/TimerInterrupt_Generic.git https://github.com/khoih-prog/TimerInterrupt_Generic.git
;https://github.com/anklimov/ModbusMaster ;https://github.com/anklimov/ModbusMaster
pazi88/STM32_CAN
monitor_speed = 115200 monitor_speed = 115200