a.binder 5 years ago
parent
commit
4e7518e739
42 changed files with 910 additions and 1037 deletions
  1. 45 159
      SE/stuff/P5_Automation_can-dev-res/P5_Automation_can-dev-res.ino
  2. 0 40
      SE/stuff/P5_Automation_can-dev-res/Slave_Ports_Status_QUEUE.h
  3. 0 129
      SE/stuff/P5_Automation_can-dev-res/Slave_Ports_Status_S.h
  4. 9 0
      SE/stuff/P5_Automation_can-dev-res/_CAN_init.h
  5. 59 0
      SE/stuff/P5_Automation_can-dev-res/_CAN_setup.h
  6. 0 19
      SE/stuff/P5_Automation_can-dev-res/_DISPLAY_init.h
  7. 20 0
      SE/stuff/P5_Automation_can-dev-res/_DISPLAY_struct.h
  8. 1 0
      SE/stuff/P5_Automation_can-dev-res/_I2C_driver_Adafruit_PWMServoDriver_func.h
  9. 4 0
      SE/stuff/P5_Automation_can-dev-res/_I2C_driver_Adafruit_PWMServoDriver_init.h
  10. 0 0
      SE/stuff/P5_Automation_can-dev-res/_I2C_driver_Adafruit_PWMServoDriver_setup.h
  11. 1 0
      SE/stuff/P5_Automation_can-dev-res/_I2C_driver_Adafruit_PWMServoDriver_struct.h
  12. 0 39
      SE/stuff/P5_Automation_can-dev-res/_LCD1602_init.h
  13. 2 0
      SE/stuff/P5_Automation_can-dev-res/_LCD1602_setup.h
  14. 86 0
      SE/stuff/P5_Automation_can-dev-res/_LCD1602_struct.h
  15. 0 0
      SE/stuff/P5_Automation_can-dev-res/_PCINT_func_loop.h
  16. 12 0
      SE/stuff/P5_Automation_can-dev-res/_PortStates_struct.h
  17. 9 0
      SE/stuff/P5_Automation_can-dev-res/_PortTypes_struct.h
  18. 4 0
      SE/stuff/P5_Automation_can-dev-res/_Port_Broadcast_state_struct.h
  19. 4 0
      SE/stuff/P5_Automation_can-dev-res/_Port_Exp_state_ttl_struct.h
  20. 6 0
      SE/stuff/P5_Automation_can-dev-res/_Port_I2C_driver_struct.h
  21. 1 0
      SE/stuff/P5_Automation_can-dev-res/_Port_ID_sruct.h
  22. 29 427
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports.h
  23. 0 32
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Protocol_CAN.h
  24. 4 4
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Protocol_CAN_func.h
  25. 77 0
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Protocol_CAN_struct.h
  26. 103 0
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Status_QUEUE_func.h
  27. 42 0
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Status_QUEUE_struct.h
  28. 51 0
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Status_func.h
  29. 65 0
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Status_struct.h
  30. 0 140
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Struct.h
  31. 152 0
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_broadcast_func.h
  32. 0 0
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_func_loop.h
  33. 0 47
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_ttl_decrement_POP.h
  34. 21 0
      SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_ttl_decrement_func.h
  35. 22 0
      SE/stuff/P5_Automation_can-dev-res/_TASK_TYPES_func.h
  36. 21 0
      SE/stuff/P5_Automation_can-dev-res/_TASK_TYPES_struct.h
  37. 0 0
      SE/stuff/P5_Automation_can-dev-res/_TFT_ILI9163C_init.h
  38. 9 0
      SE/stuff/P5_Automation_can-dev-res/_TFT_ILI9163C_setup.h
  39. 17 0
      SE/stuff/P5_Automation_can-dev-res/__main_loop_end.h
  40. 31 0
      SE/stuff/P5_Automation_can-dev-res/__main_setup.h
  41. 3 1
      SE/stuff/P5_Automation_can-dev-res/config_Active_ControllerID.h
  42. 0 0
      SE/stuff/P5_Automation_can-dev-res/config_Slave_Ports_LOCAL_init.h

+ 45 - 159
SE/stuff/P5_Automation_can-dev-res/P5_Automation_can-dev-res.ino

@@ -87,10 +87,13 @@
 //#define Active_ControllerID _ControllerID 
 //#define Active_ControllerID _Slave1_ID 
 
-
-
-
-#include "_Slave_Ports_Struct.h"
+// #define HAS_I2C_driver_Adafruit_PWMServoDriver
+#include "_DISPLAY_struct.h"
+#include "_Port_ID_sruct.h"
+#include "_I2C_driver_Adafruit_PWMServoDriver_struct.h"
+#include "_TASK_TYPES_struct.h"
+#include "_Slave_Ports_Status_QUEUE_struct.h"
+//#include "Slave_Ports_Status_QUEUE.h"
 #include "Queue.h"
  
  Queue<int> _Slave_Ports_queue = Queue<int>(10);
@@ -112,12 +115,13 @@
   // initialize the library with the numbers of the interface pins
   //LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
   //LiquidCrystal lcd(4, 6, 53, 51, 50, 52  );
-  #include "LCD1602.h"
+  #include "_LCD1602_struct.h"
+  #include "_LCD1602_init.h"
 #endif
 
 
 #if defined(HAS_TFT_ILI9163C)
-  #include "_TFT_ILI9163C.h"
+  #include "_TFT_ILI9163C_init.h"
 
 #endif
 
@@ -126,14 +130,7 @@
 //BEGIN CAN
 
 
-#include <mcp_can.h>
-#include <SPI.h>
-
-long unsigned int CANrxId;
-unsigned char CANlen = 0;
-unsigned char CANrxBuf[8];
-const int CAN_CSpin = 53 , CAN_INTpin = 10 ;
-MCP_CAN CAN0(CAN_CSpin);                          // Set CS to pin 10
+#include "_CAN_init.h"
 //EOF CAN
 
 
@@ -141,18 +138,26 @@ MCP_CAN CAN0(CAN_CSpin);                          // Set CS to pin 10
 
 
  //REMOTE PORTS DEFINITIONS
- #include "_Slave_Ports_Protocol.h"
- #include "Slave_Ports_Status_S.h"
+ #include "_PortTypes_struct.h"
+ #include "_PortStates_struct.h"
+ #include "_Port_Exp_state_ttl_struct.h"
+ #include "_Port_Broadcast_state_struct.h"
+ #include "_Port_I2C_driver_struct.h"
+ #include "_Slave_Ports_Status_struct.h"
+ #include "_Slave_Ports_Protocol_CAN_struct.h"
  
-_Slave_Port _Slave_Ports[] = {
-  {"CAN", 0x102, 0x07, 0x00, 0x00, 0x00, 0x00 }
-  //,
-  //{"CAN", 0x102, 0x01, 0x00, 0x01, 0xFF, 0x6d } //testowy ttl
-};
 
     Slave_Ports_Status_T  Slave_Ports_Status_A[100];
     Slave_Ports_Status_add_port_count_T lave_Ports_Status_add_port_count_A = 0;
-    #include "_Slave_Ports_LOCAL.h"
+    
+    
+#include "_TASK_TYPES_func.h"
+#include "_Slave_Ports_Status_QUEUE_func.h"
+#include "_Slave_Ports_Protocol_CAN_func.h"
+#include "_Slave_Ports_Status_func.h"
+#include "_Slave_Ports_broadcast_func.h"
+#include "_Slave_Ports_ttl_decrement_func.h"
+
   #include "_Slave_Ports.h"
  // #include "_Slave_Ports_ttl_decrement_POP.h"
   // #define _CAN_P_0x102_PWM0x00_0 { _Slave1_ID , "PWM", 0x00, 0 } 
@@ -178,13 +183,16 @@ _Slave_Port _Slave_Ports[] = {
 #if defined(HAS_ROTTARY_SW)
  #include "_ROTTARY_SW.h"
 #endif
-// include the library code
-/**********************************************************/
-//EOF BEGIN 1602
+
+
+#if defined(HAS_I2C_driver_Adafruit_PWMServoDriver)
+ #include "_I2C_driver_Adafruit_PWMServoDriver_init.h"
+#endif
 
 
 #include "_PCINT.h"
 
+#include "config_Slave_Ports_LOCAL_init.h"
 
 void setup() {
     Serial.begin(115200);
@@ -221,85 +229,16 @@ void setup() {
   
   // put your setup code here, to run once:
   #if defined(HAS_LCD1602)
-  lcd.begin(16, 2);
-     LCD_print(LCDarray1, LCDarray2, LCDtim/5);
+   #include "_LCD1602_setup.h"
   #endif
 
   #if defined(HAS_TFT_ILI9163C)
-
-  
- TFT_ILI9163C display = TFT_ILI9163C(TFT_ILI9163C_CSpin, TFT_ILI9163C_DCpin, TFT_ILI9163C__RSTpin);
-  float p = 3.1415926;
-     display.begin();
-     display.clearScreen();
-     display.setCursor(0,0);
-     display.print(LCDarray1);
-     display.setCursor(0,10);
-     display.print(LCDarray2);
-     delay(LCDtim); 
-  #endif
-
+    #include "_TFT_ILI9163C_setup.h"
+  #endif 
+ 
   //BEGIN CAN
+  #include "_CAN_setup.h"
  
-  //if(CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
-  if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
-     LCDarray1="MCP2515 Init Okay";
-     LCDarray2="500KBPS 16MHZ";
-   Serial.print(LCDarray1 + LCDarray2);
-    #if defined(HAS_LCD1602)
-      LCD_print(LCDarray1, LCDarray2, LCDtim/5);
-    #endif
-    #if defined(HAS_TFT_ILI9163C)
-      delay(LCDtim);  
-      display.setCursor(0,20); 
-      display.print("MCP2515 Init Okay!!\r\n");
-      delay(LCDtim); 
-    #endif
-  } else { 
-     LCDarray1 = "MCP2515 Init Failed";
-     LCDarray2 = "CAN_CSpin: "; 
-     LCDarray2.concat(CAN_CSpin);  
-     LCDarray2.concat("CAN_INTpin: ");
-     LCDarray2.concat(CAN_INTpin);    
-    Serial.print(LCDarray1);
-      #if defined(HAS_LCD1602)
-          LCD_print(LCDarray1, LCDarray2, LCDtim / 2 ) ;
-      #endif
-      #if defined(HAS_TFT_ILI9163C)
-        delay(LCDtim);  
-        display.setCursor(0,20); 
-        display.print(LCDarray1);
-        delay(LCDtim); 
-         display.setCursor(0,50); 
-         display.print(LCDarray2);
-         delay(LCDtim); 
-      #endif
-  }
-
-
-       #if Active_ControllerID == _Slave1_ID 
-        #include "_SlaveID_setup.h"
-       #elif Active_ControllerID == _ControllerID
-          LCDarray1 = "Master Module       ";
-          LCDarray2 = "enabling remotes        ";
-       #endif
-        Serial.println("");
-         #if defined(HAS_LCD1602)
-          LCD_print(LCDarray1, LCDarray2, LCDtim / 5 ) ;
-          delay(LCDtim * 10); 
-         #endif
-         #if defined(HAS_TFT_ILI9163C)
-          delay(LCDtim);  
-          display.setCursor(0,30); 
-          display.print(LCDarray1); display.print(" ");
-          display.print(LCDarray2);
-
-          delay(LCDtim); 
-         #endif
-        CAN0.setMode(MCP_NORMAL);                // Change to normal mode to allow messages to be transmitted
-        pinMode(CAN_INTpin, INPUT);                       // Setting pin 2 for /INT input
-
-  //EOF CAN
    #if defined(HAS_LCD1602) 
       LCDarray1 = "loop.... ";
       LCDarray2 = "....";
@@ -307,37 +246,7 @@ void setup() {
      
     #endif
 
-
-//_Slave_Ports_queue.push(_LCD_print_queue.peek() + 1);
- Serial.println("#298 _Slave_Ports_queue__list");
- _Slave_Ports_queue__INIT(_Slave_Ports_queue_tasks_LIST);
-_Slave_Ports_queue__list(_Slave_Ports_queue_tasks_LIST);
-  int _Slave_Ports_queue_peek =  _Slave_Ports_queue.peek() ;
-//  int _Slave_Ports_queue_push = _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1) ; 
-  //int _Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ; _Slave_Ports_queue__add(  *_Slave_Ports_queue_tasks_LIST, 0x01 ,0x00 ,100, 5000 ) ;  // _Slave_Ports_queue_peek, _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1), _Slave_Ports_queue.peek());
-//void _Slave_Ports_queue__add( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST,int _Slave_Ports_queue_task_type,int _Slave_Port_link,long time_seq_id, long time_min_run //, 
-_Slave_Ports_queue__add(  _Slave_Ports_queue_tasks_LIST,  TASK_TYPE_T_Slave_Ports_broadcast____ ,0x00 ,100, 5000 ) ;  //        "_Slave_Ports_broadcast", //4
-_Slave_Ports_queue__add(  _Slave_Ports_queue_tasks_LIST,  TASK_TYPE_T_Slave_Ports_set_I2C______ ,0x00 ,100, 5000 ) ;  //"_Slave_Ports_set_I2C" //5  - to set ports associated on PW
-
- //  _Slave_Ports_queue_peek =  _Slave_Ports_queue.peek() ; 
-   //_Slave_Ports_queue_push =  _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1) ;  
-   //_Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ; 
-//_Slave_Ports_queue__add(  _Slave_Ports_queue_tasks_LIST, 0x02 ,0x00 ,100, 5000, _Slave_Ports_queue_peek, _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1), _Slave_Ports_queue.peek());
-//   _Slave_Ports_queue_peek =  _Slave_Ports_queue.peek() ; 
-   //_Slave_Ports_queue_push =  _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1) ; 
-  // _Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ; 
-//_Slave_Ports_queue__add(  _Slave_Ports_queue_tasks_LIST, 0x03 ,0x00 ,100, 5000, _Slave_Ports_queue_peek, 
-//_Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1),
-//_Slave_Ports_queue.peek());
-
- Serial.println("#301 _Slave_Ports_queue__list");
-_Slave_Ports_queue__list(_Slave_Ports_queue_tasks_LIST);
-Serial.print("#304 _Slave_Ports_queue.count(), "); Serial.println(_Slave_Ports_queue.count());
-  
-   
- //  _Slave_Ports_queue__add(  _Slave_Ports_queue_tasks_LIST, 0x03 ,0x00 ,100, 5000 ) ;  
- //Serial.println("#323 _Slave_Ports_queue__list"); _Slave_Ports_queue__list(_Slave_Ports_queue_tasks_LIST);
-// Serial.print("#324 _Slave_Ports_queue.count(), "); Serial.println(_Slave_Ports_queue.count());
+ #include "__main_setup.h"
 
 }
 
@@ -360,39 +269,16 @@ void loop() {
   time = millis();
   Serial.print("Time: " );
   Serial.println(time);
-  // put your main code here, to run repeatedly:
-  //BEGIN CAN
-   
-  // #if Active_ControllerID == _Slave1_ID
-      #include "_SlaveID_loop1.h"
-  //  #elif Active_ControllerID == _ControllerID
-         #include "_ControllerID_loop1.h"
-         
-   // #endif
-  
-  
-  _Slave_Ports_queue__list(_Slave_Ports_queue_tasks_LIST) ;
-  int _Slave_Ports_queue_count = _Slave_Ports_queue.count();
-  int _Slave_Ports_queue_front = _Slave_Ports_queue.front();
-  int _Slave_Ports_queue_back =  _Slave_Ports_queue.back();
-  int _Slave_Ports_queue_peek = _Slave_Ports_queue.peek();
-  int _Slave_Ports_queue_pop = _Slave_Ports_queue.pop();
- _Slave_Ports_queue__POP( _Slave_Ports_queue_tasks_LIST, 
- _Slave_Ports_queue_count, 
- _Slave_Ports_queue_pop, 
- _Slave_Ports_queue_front, 
- _Slave_Ports_queue_back,
- _Slave_Ports_queue_peek,
- LCDtim, _Slave_Ports);
-
-  //_LCD_print_buffors_list(_LCD_print_buffors) ;
-  //_LCD_print_screens_list(_LCD_print_screens);
+      #include "_SlaveID_loop1.h" //todo PCINT
+      #include "_ControllerID_loop1.h"  //todo make default
   
+  #include "__main_loop_end.h"
+ 
   delay(5000);
   
 }
 
 
 
-#include "_PCINT_func.h"
-#include "_Slave_Ports_func.h"
+#include "_PCINT_func_loop.h" //todo empty implement display etc
+#include "_Slave_Ports_func_loop.h" //todo implement

+ 0 - 40
SE/stuff/P5_Automation_can-dev-res/Slave_Ports_Status_QUEUE.h

@@ -1,40 +0,0 @@
-
-
-
-/*
-typedef struct
-{
-  uint8_t CNF1;
-} TASK_TYPE_T;
-
-
-*/
-
-
-
-
-#ifndef Slave_Ports_Status_QUEUE
-
-
-#define TASK_TYPE_T_NOT_USED_________________ 0x00
-#define TASK_TYPE_T_Slave_Ports_ttl_decrement 0x01
-#define TASK_TYPE_T_request_confirm_Exp_state 0x02
-#define TASK_TYPE_T_request_set_new_Exp_state 0x03
-#define TASK_TYPE_T_Slave_Ports_broadcast____ 0x04
-#define TASK_TYPE_T_Slave_Ports_set_I2C______ 0x05
-
-
-    #define Slave_Ports_Status_QUEUE
-    
-     struct Slave_Ports_Status_QUEUE_S {
-      int _queue_id ; //current queue task
-       int TASK_TYPE_A ; 
-       long time_seq_id;
-       long time_min_run;
-    } ;
-    
-    
-    typedef struct Slave_Ports_Status_QUEUE_S Slave_Ports_Status_QUEUE_T;
-
-    
-#endif

+ 0 - 129
SE/stuff/P5_Automation_can-dev-res/Slave_Ports_Status_S.h

@@ -1,129 +0,0 @@
-
-
-#ifndef Slave_Ports_Status_S_h
-#define Slave_Ports_Status_S_h
-
-
- #define    I2C_driver_NOT_USED_  0x00
- #define    I2C_driver_Adafruit_PWMServoDriver    0x01
-
-
-
- #define    PortTypes_PWM  0x01
- #define    PortTypes_I2C  0x02
- #define    PortTypes_EXP  0x03
- #define    PortTypes_P2M_EXP_I2C  0x07
-
-
- #define    Exp_state_OFF  0x01
- #define    Exp_state_ON  0x02
-
-
-
- #define    Exp_state_ttl_TO_REFRESH  0x01
-
- #define    Broadcast_state_TO_REFRESH  0x01 
-
-#define I2C_port_DEFAULT 0x01
-
- struct Slave_Ports_Status_S {
-  int  Port_ID ; //global id for device //const char * const _Protocol;
-  int  _Slave_ID; //Device which orginated port   //remote id - use FF for broadcast
-  int  PortTypes;  //0xFF  =  1111 1111 s
-                                          /*
-                                          {
-                                      bit 1 - PWM port
-                                      bit 2 - on I2C managed port
-                                      bit 3 - expanded port with LocalPort address
-                                      bit 4 - not allocated
-                                      bit 2 - not allocated
-                                      bit 5 - not allocated
-                                      bit 6 - not allocated
-                                      bit 7 - not allocated
-                                      bit 8 - not allocated
-                                    } 
-                                           */
- // byte has_Address;
-  int  Address ;
- // byte has_Local_Port;
-  int  LocalPort;
-  int  Exp_state;                  /*0xFF  =  1111 1111
-                                    0x00  =  0000 0001  = OFF = 0V
-                                    0x01  =  0000 0002  = ON = PWM max
-                                    {
-                                      bit 1 - OFF = 0V
-                                      bit 2 - ON = PWM max
-                                      bit 3 - not allocated
-                                      bit 4 - not allocated
-                                      bit 2 - not allocated
-                                      bit 5 - not allocated
-                                      bit 6 - not allocated
-                                      bit 7 - not allocated
-                                      bit 8 - not allocated
-                                    }*/
-  int  Exp_state_ttl;  // 0x01 = odswiezyc
-  int  Broadcast_state; //0x00 - not broadcast; 0x01
-  int I2C_port ; //0x01 - default port, 0x00 - not I2C connected
-  int I2C_driver; //0x00 - not driver, 0x01 Adafruit_PWMServoDriver.h
- // int IS_Local; // Define if port is local or remote added
-  
-} ;
-
-typedef struct Slave_Ports_Status_S Slave_Ports_Status_T;
-
-typedef int Slave_Ports_Status_add_port_count_T;
-Slave_Ports_Status_add_port_count_T Slave_Ports_Status_add_port_count_A ;
-
- void Slave_Ports_Status_add_port(
- Slave_Ports_Status_T* Slave_Ports_Status_A , Slave_Ports_Status_add_port_count_T* Slave_Ports_Status_add_port_count_A,
- 
-                int  Port_ID,
-                int  _Slave_ID,
-                int  PortTypes,
-                int  Address,
-                int  LocalPort,
-                int  Exp_state,
-                int  Exp_state_ttl,
-                int  Broadcast_state,
-                int I2C_port,
-                //int I2C_driver
-                int I2C_driver
-                )
-{
-        int i = Slave_Ports_Status_add_port_count_A ;
-    if(Slave_Ports_Status_add_port_count_A == 0) {
-      Slave_Ports_Status_add_port_count_A ++;
-     Slave_Ports_Status_A[i].Port_ID=0x00;
-     Slave_Ports_Status_A[i]._Slave_ID=0x00;
-     Slave_Ports_Status_A[i].PortTypes=0x00;
-     Slave_Ports_Status_A[i].Address=0x00;
-     Slave_Ports_Status_A[i].LocalPort=0x00;
-     Slave_Ports_Status_A[i].Exp_state=0x00;
-     Slave_Ports_Status_A[i].Exp_state_ttl=0x00;
-     Slave_Ports_Status_A[i].Broadcast_state=0x00;
-     Slave_Ports_Status_A[i].I2C_port=0x00;
-     Slave_Ports_Status_A[i].I2C_driver=0x00;
-     Slave_Ports_Status_add_port_count_A ++;
-     
-   
-   
-    }
-    
-    Slave_Ports_Status_A[i + 1].Port_ID = Port_ID ;
-    Slave_Ports_Status_A[i + 1]._Slave_ID = _Slave_ID ;
-    Slave_Ports_Status_A[i + 1].PortTypes = PortTypes ;
-    Slave_Ports_Status_A[i + 1].Address = Address ;
-    Slave_Ports_Status_A[i + 1].LocalPort = LocalPort ;
-    Slave_Ports_Status_A[i + 1].Exp_state = Exp_state ;
-    Slave_Ports_Status_A[i + 1].Exp_state_ttl = Exp_state_ttl ;
-    Slave_Ports_Status_A[i + 1].Broadcast_state = Broadcast_state ;
-    Slave_Ports_Status_A[i + 1].I2C_port = I2C_port ;
-    Slave_Ports_Status_A[i + 1].I2C_driver = I2C_driver ;
-  //  Slave_Ports_Status_A[Slave_Ports_Status_add_port_count_A + 1].I2C_driver = I2C_driver_F(I2C_driver) ;
-
-    Slave_Ports_Status_add_port_count_A ++;
-  
-}
-
-#endif
-

+ 9 - 0
SE/stuff/P5_Automation_can-dev-res/_CAN_init.h

@@ -0,0 +1,9 @@
+
+#include <mcp_can.h>
+#include <SPI.h>
+
+long unsigned int CANrxId;
+unsigned char CANlen = 0;
+unsigned char CANrxBuf[8];
+const int CAN_CSpin = 53 , CAN_INTpin = 10 ;
+MCP_CAN CAN0(CAN_CSpin);                          // Set CS to pin 10

+ 59 - 0
SE/stuff/P5_Automation_can-dev-res/_CAN_setup.h

@@ -0,0 +1,59 @@
+ //if(CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
+  if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
+     LCDarray1="MCP2515 Init Okay";
+     LCDarray2="500KBPS 16MHZ";
+   Serial.print(LCDarray1 + LCDarray2);
+    #if defined(HAS_LCD1602)
+      LCD_print(LCDarray1, LCDarray2, LCDtim/5);
+    #endif
+    #if defined(HAS_TFT_ILI9163C)
+      delay(LCDtim);  
+      display.setCursor(0,20); 
+      display.print("MCP2515 Init Okay!!\r\n");
+      delay(LCDtim); 
+    #endif
+  } else { 
+     LCDarray1 = "MCP2515 Init Failed";
+     LCDarray2 = "CAN_CSpin: "; 
+     LCDarray2.concat(CAN_CSpin);  
+     LCDarray2.concat("CAN_INTpin: ");
+     LCDarray2.concat(CAN_INTpin);    
+    Serial.print(LCDarray1);
+      #if defined(HAS_LCD1602)
+          LCD_print(LCDarray1, LCDarray2, LCDtim / 2 ) ;
+      #endif
+      #if defined(HAS_TFT_ILI9163C)
+        delay(LCDtim);  
+        display.setCursor(0,20); 
+        display.print(LCDarray1);
+        delay(LCDtim); 
+         display.setCursor(0,50); 
+         display.print(LCDarray2);
+         delay(LCDtim); 
+      #endif
+  }
+
+
+       #if Active_ControllerID == _Slave1_ID 
+        #include "_SlaveID_setup.h"
+       #elif Active_ControllerID == _ControllerID
+          LCDarray1 = "Master Module       ";
+          LCDarray2 = "enabling remotes        ";
+       #endif
+        Serial.println("");
+         #if defined(HAS_LCD1602)
+          LCD_print(LCDarray1, LCDarray2, LCDtim / 5 ) ;
+          delay(LCDtim * 10); 
+         #endif
+         #if defined(HAS_TFT_ILI9163C)
+          delay(LCDtim);  
+          display.setCursor(0,30); 
+          display.print(LCDarray1); display.print(" ");
+          display.print(LCDarray2);
+
+          delay(LCDtim); 
+         #endif
+        CAN0.setMode(MCP_NORMAL);                // Change to normal mode to allow messages to be transmitted
+        pinMode(CAN_INTpin, INPUT);                       // Setting pin 2 for /INT input
+
+  //EOF CAN

+ 0 - 19
SE/stuff/P5_Automation_can-dev-res/_DISPLAY_init.h

@@ -1,21 +1,2 @@
 int LCDtim = 250 ;//the value of delay time
 
-
-typedef  char LCDarray16_T[16] ;
-
-
-typedef  int LCD_pos_seq_T ; //reqiested position in LCD
-    #define  LCD_pos_seq_A_NEXT 0x01
-
-typedef  int LCD_pos_id_T ; //reqiested position id in LCD
-
- 
-
- struct _DISPLAY_LCD {
-      int _queue_id ; //current queue task
-       LCD_pos_seq_T LCD_pos_seq_A = LCD_pos_seq_A_NEXT;
-       LCD_pos_id_T LCD_pos_id_A;
-       LCDarray16_T LCDarray16_A ; 
-       long time_seq_id;
-       long time_min_run;
-    } ;

+ 20 - 0
SE/stuff/P5_Automation_can-dev-res/_DISPLAY_struct.h

@@ -0,0 +1,20 @@
+
+
+typedef  char LCDarray16_T[16] ;
+
+
+typedef  int LCD_pos_seq_T ; //reqiested position in LCD
+    #define  LCD_pos_seq_A_NEXT 0x01
+
+typedef  int LCD_pos_id_T ; //reqiested position id in LCD
+
+ 
+
+ struct _DISPLAY_LCD {
+      int _queue_id ; //current queue task
+       LCD_pos_seq_T LCD_pos_seq_A = LCD_pos_seq_A_NEXT;
+       LCD_pos_id_T LCD_pos_id_A;
+       LCDarray16_T LCDarray16_A ; 
+       long time_seq_id;
+       long time_min_run;
+    } ;

+ 1 - 0
SE/stuff/P5_Automation_can-dev-res/_I2C_driver_Adafruit_PWMServoDriver_func.h

@@ -0,0 +1 @@
+//I2C_driver_Adafruit_PWMServoDriver

+ 4 - 0
SE/stuff/P5_Automation_can-dev-res/_I2C_driver_Adafruit_PWMServoDriver_init.h

@@ -0,0 +1,4 @@
+//I2C_driver_Adafruit_PWMServoDriver
+
+#include <Wire.h>
+#include <Adafruit_PWMServoDriver.h>

+ 0 - 0
SE/stuff/P5_Automation_can-dev-res/_PCINT_func.h → SE/stuff/P5_Automation_can-dev-res/_I2C_driver_Adafruit_PWMServoDriver_setup.h


+ 1 - 0
SE/stuff/P5_Automation_can-dev-res/_I2C_driver_Adafruit_PWMServoDriver_struct.h

@@ -0,0 +1 @@
+//I2C_driver_Adafruit_PWMServoDriver

+ 0 - 39
SE/stuff/P5_Automation_can-dev-res/LCD1602.h → SE/stuff/P5_Automation_can-dev-res/_LCD1602_init.h

@@ -2,45 +2,6 @@
 
 Queue<int> _LCD_print_queue = Queue<int>(5);
 
- const int LCD1602rs=12, LCD1602en=11, LCD1602db4=5, LCD1602db5=4, LCD1602db6=3, LCD1602db7=2; // lcd keypad shield pins
-  LiquidCrystal lcd(LCD1602rs, LCD1602en, LCD1602db4, LCD1602db5, LCD1602db6, LCD1602db7);
-  int lcdPos = 0 ;
-
- 
- struct _LCD_print_bufforS {
-  int screenID;
-  int cursor1;
-  int cursor2;
- int character ;
- long time_seq_id;
- long time_min_run;
-} ;
-
-typedef struct _LCD_print_bufforS _LCD_print_bufforT;
-
-//struct LCDarray1S {
-//   char LCDarray1[16];
-//}
-
-struct _LCD_print_screenS {
-  int screenID;
-  char LCDarray1;
-  char LCDarray2;
-   long time_seq_id;
-   long time_min_run;
-  // _LCD_print_bufforT ;
-} ;
-
-
-typedef struct _LCD_print_screenS _LCD_print_screensT;
-
-
-//_LCD_print_buffor _LCD_print_buffors[] = {  0 , 0, "T", 10000, 50000 } ;
-
-//_LCD_print_screen _LCD_print_screens[] = { 1 , _LCD_print_buffors } ;
-
-
-//void LCD_print_background_add( int[], int , int , int , char  ,long , long  ) ;
 
  _LCD_print_bufforT _LCD_print_buffors[1];
  _LCD_print_screensT _LCD_print_screens[10];

+ 2 - 0
SE/stuff/P5_Automation_can-dev-res/_LCD1602_setup.h

@@ -0,0 +1,2 @@
+ lcd.begin(16, 2);
+     LCD_print(LCDarray1, LCDarray2, LCDtim/5);

+ 86 - 0
SE/stuff/P5_Automation_can-dev-res/_LCD1602_struct.h

@@ -0,0 +1,86 @@
+                            
+
+
+ 
+ struct _LCD_print_bufforS {
+  int screenID;
+  int cursor1;
+  int cursor2;
+ int character ;
+ long time_seq_id;
+ long time_min_run;
+} ;
+
+typedef struct _LCD_print_bufforS _LCD_print_bufforT;
+
+//struct LCDarray1S {
+//   char LCDarray1[16];
+//}
+
+struct _LCD_print_screenS {
+  int screenID;
+  char LCDarray1;
+  char LCDarray2;
+   long time_seq_id;
+   long time_min_run;
+  // _LCD_print_bufforT ;
+} ;
+
+
+typedef struct _LCD_print_screenS _LCD_print_screensT;
+
+   int b_ascii_value = character;
+
+
+      
+
+/*
+
+struct record
+{
+   int bookId;
+   int qtyInStock;
+
+};
+typedef struct record Record;
+
+void sold(int id, Record* records) {
+  int i;
+  for(i=0;i<3;i++) {
+    if(records[i].bookId == id) {
+      records[i].qtyInStock--;
+    }
+  }
+}
+*/
+/*
+void updateId(int id, int new_id, Record* records) {
+  int i;
+  for(i=0;i<3;i++) {
+    if(records[i].bookId == id) {
+        records[i].bookid = new_id;
+    }
+  }
+}
+*/
+/*
+void updateQty(int id, int new_qty, Record* records) {
+  int i;
+  for(i=0;i<3;i++) {
+    if(records[i].bookId == id) {
+        records[i].qtyInStock = new_qty;
+    }
+  }
+}
+*/
+
+
+}           
+                            
+String make_str16(String str){
+    for(int i = 0; i < (16 - str.length()); i++)
+        str += ' ';  
+    return str;
+}
+                
+                                      

+ 0 - 0
SE/stuff/P5_Automation_can-dev-res/_PCINT_func_loop.h


+ 12 - 0
SE/stuff/P5_Automation_can-dev-res/_PortStates_struct.h

@@ -0,0 +1,12 @@
+
+typedef  byte Exp_state_T ;
+
+ const  Exp_state_T Exp_state_OFF        =  B00000001 ; 
+ const  Exp_state_T Exp_state_ON         =  B00000010 ;
+ const  Exp_state_T Exp_state_ERROR      =  B10000000 ;
+ //const  Exp_state_T Exp_state_TOGGLE     =  B10000000 ;
+
+
+ #define    Exp_state_OFF  0x01
+ #define    Exp_state_ON  0x02
+

+ 9 - 0
SE/stuff/P5_Automation_can-dev-res/_PortTypes_struct.h

@@ -0,0 +1,9 @@
+//USED IN _Slave_Ports_Status_struct.h
+
+typedef  byte PortTypes_T ;
+
+ const  PortTypes_T PortTypes_PWM         =  B00000001 ; 
+ const  PortTypes_T PortTypes_I2C         =  B00000010 ; // 0x02
+ const  PortTypes_T PortTypes_EXP         =  B00000100 ; // 0x03
+ const  PortTypes_T PortTypes_P2M_EXP_I2C =  PortTypes_PWM + PortTypes_I2C + PortTypes_EXP  ; //0x07 ;
+

+ 4 - 0
SE/stuff/P5_Automation_can-dev-res/_Port_Broadcast_state_struct.h

@@ -0,0 +1,4 @@
+
+typedef int Broadcast_state_T ; 
+
+const Broadcast_state_T  Broadcast_state_TO_REFRESH = 0x01 ;

+ 4 - 0
SE/stuff/P5_Automation_can-dev-res/_Port_Exp_state_ttl_struct.h

@@ -0,0 +1,4 @@
+
+typedef int Exp_state_ttl_T ; 
+
+const Exp_state_ttl_T  Exp_state_ttl_TO_REFRESH = 0x01 ;

+ 6 - 0
SE/stuff/P5_Automation_can-dev-res/_Port_I2C_driver_struct.h

@@ -0,0 +1,6 @@
+
+typedef int I2C_driver_T ; 
+
+const I2C_driver_T  EI2C_driver_NOT_USED_ = 0x00 ;
+const I2C_driver_T  I2C_driver_Adafruit_PWMServoDriver = 0x01 ;
+

+ 1 - 0
SE/stuff/P5_Automation_can-dev-res/_Port_ID_sruct.h

@@ -0,0 +1 @@
+typedef int Port_ID_T ; 

+ 29 - 427
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports.h

@@ -1,333 +1,23 @@
+//_Slave_Ports.h
+
 #include "_Slave_Ports_ttl_decrement.h"
 //#include "_Slave_Ports_Protocol.h"
-#include "Slave_Ports_Status_QUEUE.h"
-//#include "Slave_Ports_Status_S.h"
-
-/*
- * 
-_Slave_Port _Slave_Ports[] = {
-  {"CAN", 0x102, 0x01, 0x00, 0x00, 0x00, 0x00 }
-  //,
-  //{"CAN", 0x102, 0x01, 0x00, 0x01, 0xFF, 0x6d } //testowy ttl
-};
-*/
-//#include "_Slave_Ports_LOCAL.h"
-//#include "_Slave_Ports_queue_task_type_LIST.h"
-#include "Slave_Ports_Status_QUEUE.h"
-
-
-
-_Slave_Ports_queue_tasksT _Slave_Ports_queue_tasks_LIST[11];
-
-
-
-  
-
-
-void _Slave_Ports_queue__INIT( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST) {
-  Serial.println("_Slave_Ports_queue__INIT");
-   int i;
-  for(i=0;i<10;i++) {
-   _Slave_Ports_queue_tasks_LIST[i].queueID = 0;
-     _Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type = 0x00;
-      _Slave_Ports_queue_tasks_LIST[i]._Slave_Port_link = 0x00;
-       _Slave_Ports_queue_tasks_LIST[i].time_seq_id = 0;
-        _Slave_Ports_queue_tasks_LIST[i].time_min_run = 0;
-        
-      //  _Slave_Ports_queue_tasks_LIST[i]=_Slave_Ports_queue_tasks_LIST[i];
-   }
-   
-}
-
-
-void _Slave_Ports_queue_task_type_DESC( int _Slave_Ports_queue_task_type ) {//, int* res
-        if(_Slave_Ports_queue_task_type == TASK_TYPE_T_NOT_USED_________________) { 
-            Serial.println("TASK_TYPE_T_NOT_USED_________________"); 
-        } else if(_Slave_Ports_queue_task_type == TASK_TYPE_T_Slave_Ports_ttl_decrement) { Serial.println("TASK_TYPE_T_Slave_Ports_ttl_decrement");
-        } else if(_Slave_Ports_queue_task_type == TASK_TYPE_T_request_confirm_Exp_state) { Serial.println("TASK_TYPE_T_request_confirm_Exp_state");
-        } else if(_Slave_Ports_queue_task_type == TASK_TYPE_T_request_set_new_Exp_state) { Serial.println("TASK_TYPE_T_request_set_new_Exp_state");
-        } else if(_Slave_Ports_queue_task_type == TASK_TYPE_T_Slave_Ports_broadcast____) { Serial.println("TASK_TYPE_T_Slave_Ports_broadcast____");
-        } else if(_Slave_Ports_queue_task_type == TASK_TYPE_T_Slave_Ports_set_I2C______) { Serial.println("TASK_TYPE_T_Slave_Ports_set_I2C______");
-        } else  { Serial.println("106 unknown _Slave_Ports_queue_task_type");
-        }
-}
-
-
-//Queue<_Slave_Ports_queueT> _Slave_Ports_queue = Queue<_Slave_Ports_queueT>(5);
-void _Slave_Ports_queue__list( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST) {
-  int i;
-    Serial.println("#100 _Slave_Ports_queue_tasks_LIST): ");
-    //Serial.println(sizeof(_Slave_Ports_queue_tasks_LIST));
-        for(i=0;i<=10;i++) { //sizeof(_LCD_print_buffors)
-
-          if(_Slave_Ports_queue_tasks_LIST[i].queueID == 0 and _Slave_Ports_queue_tasks_LIST[i].queueID == 0 and _Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type == 0 and _Slave_Ports_queue_tasks_LIST[i]._Slave_Port_link == 0 and _Slave_Ports_queue_tasks_LIST[i].time_seq_id == 0 and _Slave_Ports_queue_tasks_LIST[i].time_min_run == 0 ) {
-            
-          } else {
-                Serial.print(" $i[");
-                Serial.print(i);
-
-                 Serial.print("] queueID: ");
-                Serial.print(_Slave_Ports_queue_tasks_LIST[i].queueID);
-
-                   
-
-                 Serial.print("] _Slave_Ports_queue_task_type: ");
-                                 Serial.print(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type);
-                  Serial.print("] desc: ");
-                 //Slave_Ports_queue_task_type_DESC(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type);
-                 //char res;
-                 // res = _Slave_Ports_queue_task_type_DESC(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type);  Serial.print(res);
-                  
-                //  Serial.print(" - map[");  Serial.print(_Slave_Ports_queue_task_type_LIST[_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type]);  Serial.print("]"); 
-               _Slave_Ports_queue_task_type_DESC(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type) ; //(res); //_Slave_Ports_queue_task_type_DESC(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type
-
-  
-                 Serial.print("] _Slave_Port_link: ");
-                Serial.print(_Slave_Ports_queue_tasks_LIST[i]._Slave_Port_link);
-                     
-                     
-                    Serial.print("] time_seq_id: ");
-                Serial.print(_Slave_Ports_queue_tasks_LIST[i].time_seq_id);
-
-                     Serial.print("] time_min_run: ");
-                Serial.println(_Slave_Ports_queue_tasks_LIST[i].time_min_run);
-                }
-  
-        }
-}
-
-/*
- struct _Slave_Ports_queue_tasksS {
-  int queueID;
-  int _Slave_Ports_queue_task_type ; /*
-              { 0x01 _Slave_Ports_ttl_decrement, 
-                 0x02  request_confirm_Exp_state ,
-                 0x03  request_set_new_Exp_state,
-                 0x04   _Slave_Ports_ttl_decrement }
- 
-  int _Slave_Port_link; //todo link
- long time_seq_id;
- long time_min_run;
-} ;
-
- */
-void _Slave_Ports_queue__add( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST,int _Slave_Ports_queue_task_type,int _Slave_Port_link,long time_seq_id, long time_min_run //, 
-//int _Slave_Ports_queue_peek , int _Slave_Ports_queue_push , int _Slave_Ports_queue_peek_new
-) {
-  Serial.println(".");
-      Serial.print("#152 _Slave_Ports_queue__add  peek: ["); 
-       int _Slave_Ports_queue_peek = _Slave_Ports_queue.peek() ;
-       int _Slave_Ports_queue_back = _Slave_Ports_queue.back() ;
-     //  int _Slave_Ports_queue_push_new_ref;
-      // if(_Slave_Ports_queue_back > _Slave_Ports_queue_peek)
-      Serial.print(_Slave_Ports_queue_peek);  Serial.print("] cur back[");  Serial.print(_Slave_Ports_queue_back); Serial.print("] ");
-      
-     
-     _Slave_Ports_queue.push(_Slave_Ports_queue_back + 1);
-      int _Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ;
-     // int _Slave_Ports_queue__push = _Slave_Ports_queue__peek + 1 ;
-             Serial.print("] new peek[");
-             Serial.print(_Slave_Ports_queue_peek_new );    Serial.print("]  planned["); Serial.print(_Slave_Ports_queue_back + 1 );  
-             Serial.print("] front[");   Serial.print(_Slave_Ports_queue.front());   Serial.print("] back[");   Serial.print(_Slave_Ports_queue.back());  Serial.println("] ");
-
- 
-             
-     _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ].queueID=_Slave_Ports_queue_back + 1 ;
-     _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ]._Slave_Ports_queue_task_type=_Slave_Ports_queue_task_type ;
-     _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ]._Slave_Port_link=_Slave_Port_link ;
-     _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ].time_seq_id=time_seq_id ;
-     _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ].time_min_run=time_min_run ;
-    
-}
-
-/*
- void _Slave_Ports_queue__add(const _Slave_Ports_queue_tasksT*  &_Slave_Ports_queue_tasks_LIST  ,
-int _Slave_Ports_queue_task_type, int _Slave_Port_link, long time_seq_id, long time_min_run //, 
-//int _Slave_Ports_queue_peek , int _Slave_Ports_queue_push , int _Slave_Ports_queue_peek_new
-) {
-      Serial.print("#152 _Slave_Ports_queue__add  peek: ["); 
-       int _Slave_Ports_queue_peek = _Slave_Ports_queue.peek() ;
-      Serial.print(_Slave_Ports_queue_peek);
-      
-     
-      int _Slave_Ports_queue_push = _Slave_Ports_queue_peek + 1;
-      int _Slave_Ports_queue_peek_new = _Slave_Ports_queue_push ; //_Slave_Ports_queue.peek() ;
-     // int _Slave_Ports_queue__push = _Slave_Ports_queue__peek + 1 ;
-             Serial.print("] new peek[");
-             Serial.print(_Slave_Ports_queue_peek_new );    Serial.print("]  planned["); Serial.print(_Slave_Ports_queue_peek + 1 );   Serial.println("]");
-     _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new].queueID=_Slave_Ports_queue_peek_new;
-     _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new]._Slave_Ports_queue_task_type=_Slave_Ports_queue_task_type ;
-     _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new]._Slave_Port_link=_Slave_Port_link ;
-     _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new].time_seq_id=time_seq_id ;
-     _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new].time_min_run=time_min_run ;
-
-    //return _Slave_Ports_queue_tasks_LIST;
-}
-
-
-*/
-
-
-#include "_Slave_Ports_ttl_decrement_POP.h"
-
- void _Slave_Ports_broadcast_POP(_Slave_Ports_queue_tasksT*  _Slave_Ports_queue_tasks_LIST, int _Slave_Ports_queue_pop ,  _Slave_Port*  _Slave_Ports, int LCDtim ) {
-        Serial.println("#251 _Slave_Ports_broadcast_POP");
-          int i;
-          for(i=0;i<=100;i++) {
-            if(_Slave_Ports[i]._Protocol == "CAN") {
-              Serial.print(" ind:"); Serial.print(i);  Serial.print("] Prot:");
-              Serial.print(_Slave_Ports[i]._Protocol);
-              Serial.print(" , ID:"); 
-              Serial.print(_Slave_Ports[i]._Slave_ID, HEX); Serial.print(" , PortTypes:");
-             Serial.print(_Slave_Ports[i].PortTypes, HEX); Serial.print(" , Addr:"); Serial.print(_Slave_Ports[i].Address, HEX);
-              Serial.print(" , Local:"); Serial.print(_Slave_Ports[i].LocalPort);
-              Serial.print(" , Exp state:"); Serial.print(_Slave_Ports[i].Exp_state);
-                Serial.print(" , Exp_state_ttl"); Serial.println(_Slave_Ports[i].Exp_state_ttl);  
-
-
-                        Serial.println(" Prepared data");
-                        #if defined(HAS_LCD1602)                              
-                             String LCDarray1 = "P[";
-                             LCDarray1.concat(_Slave_Ports[i]._Protocol); LCDarray1.concat("] ID["); LCDarray1.concat(String(_Slave_Ports[i]._Slave_ID, HEX)); LCDarray1.concat("] T["); LCDarray1.concat(String(_Slave_Ports[i].PortTypes, HEX));
-                            // lcd.print(LCDarray1);
-                            String LCDarray2 = " >"; LCDarray2.concat(String(_Slave_Ports[i].Address, HEX)); LCDarray2.concat( "< {"); LCDarray2.concat( String(_Slave_Ports[i].LocalPort, HEX)); LCDarray2.concat( "} =[" ); LCDarray2.concat(String(_Slave_Ports[i].Exp_state, HEX) ); LCDarray2.concat("] ?[" ) ;
-                                 LCDarray2.concat(String(_Slave_Ports[i].Exp_state_ttl, HEX)) ; LCDarray2.concat("]") ;
-                                 LCD_print(LCDarray1, LCDarray2, LCDtim / 2 ) ;
-                        #endif
-                        //                        (0)           (1)           (2)                       (3)                         (4)                         (5)                     (6)                   
-                      byte data[8] = {_Slave_Ports[i].Address,  0x04, _Slave_Ports[i].LocalPort, _Slave_Ports[i].PortTypes, _Slave_Ports[i].LocalPort, _Slave_Ports[i].Exp_state, _Slave_Ports[i].Exp_state_ttl, 0x07};
-                     // byte data[8] = {element.Address,          0x04, element.LocalPort,          element.PortTypes,                element.LocalPort,         element.Exp_state,         element.Exp_state_ttl, 0x07};
-                  Serial.print("#303 byte data[8] 1[");   Serial.print(_Slave_Ports[i].Address);   Serial.print("] 2[");  Serial.print(0x04);   Serial.print("] 3["); 
-                       Serial.print(_Slave_Ports[i].LocalPort);   Serial.print("] 4[");    Serial.print(_Slave_Ports[i].PortTypes);   Serial.print("] 5[");  Serial.print(_Slave_Ports[i].Exp_state);   Serial.print("] 6[");
-                        Serial.print( _Slave_Ports[i].Exp_state_ttl);   Serial.print("] 7[");  Serial.print(0x07);   Serial.println("] ");
-                 byte sndStat = CAN0.sendMsgBuf(_Slave_Ports[i]._Slave_ID, 0, 8, data);
-              //    byte sndStat ;
-                          if(sndStat == CAN_OK){
-                            Serial.println("Message Sent Successfully!");
-                             String LCDarray1 = "Message Sent";
-                             String LCDarray2 = "Successfully";
-                          } else {
-                            Serial.println("Error Sending Message...");
-                            String LCDarray1 = "Error Sending";
-                            String LCDarray2 = "Message...";
-                          }
-
-                            #if defined(HAS_LCD1602)
-                                    LCD_print(LCDarray1,LCDarray2,LCDtim);
-                                  /*
-                                   delay(LCDtim * 5);  
-                                    //lcd.setCursor(0,1); 
-                                    lcd.print(lcdPattern);
-                                    //lcd.print(lcdPos % 10);
-                                  if(lcdPos >= 16) { 
-                                    //lcd.print("N");
-                                    lcd.setCursor(0,1); 
-                                    lcdPos = 0;
-                                    if(lcdPattern=="s") lcdPattern = "S" ;
-                                    else lcdPattern = "s" ;
-                                  }
-                                    lcdPos ++;
-                                    |*/
-                                 #endif
-                                //  #if defined(HAS_TFT_ILI9163C)
-                                //    delay(LCDtim);  
-                                //    display.setCursor(0,60); 
-                               //     display.print(LCDarray1); display.print(" "); display.print(LCDarray2);
-                               //   #endif
-
-                                      delay(5000);   // send data per 100ms
-                }
-
-
-                          
-                                
-                     
-
-             
-
-
-                
-            }
-          
-
-          /*
-           for (auto element: _Slave_Ports) {
-            ind++;
-              Serial.print(" ind:"); Serial.print(ind);  Serial.print("] Prot:"); Serial.print(element._Protocol); Serial.print(" , ID:"); Serial.print(element._Slave_ID); Serial.print(" , PortTypes:");
-             Serial.print(element.PortTypes); Serial.print(" , Addr:"); Serial.print(element.Address);
-              Serial.print(" , Local:"); Serial.print(element.LocalPort);
-              Serial.print(" , Exp state:"); Serial.print(element.Exp_state);
-                Serial.print(" , Exp_state_ttl"); Serial.println(element.Exp_state_ttl);  
-                if(element._Protocol == "CAN") { 
-                       Serial.println(" Prepared data");
-                        #if defined(HAS_LCD1602)                              
-                               
-                             String LCDarray1 = "P[";
-                             LCDarray1.concat(element._Protocol); LCDarray1.concat("] ID["); LCDarray1.concat(String(element._Slave_ID, HEX)); LCDarray1.concat("] T["); LCDarray1.concat(String(element.PortTypes, HEX));
-                            // lcd.print(LCDarray1);
-                            String LCDarray2 = " >"; LCDarray2.concat(String(element.Address, HEX)); LCDarray2.concat( "< {"); LCDarray2.concat( String(element.LocalPort, HEX)); LCDarray2.concat( "} =[" ); LCDarray2.concat(String(element.Exp_state, HEX) ); LCDarray2.concat("] ?[" ) ;
-                                 LCDarray2.concat(String(element.Exp_state_ttl, HEX)) ; LCDarray2.concat("]") ;
-                                 LCD_print(LCDarray1, LCDarray2, LCDtim / 2 ) ;
-                        #endif
-                      byte data[8] = {element.Address, 0x04, element.LocalPort, element.PortTypes, element.LocalPort, element.Exp_state, element.Exp_state_ttl, 0x07};
-                  // }
-                 byte sndStat = CAN0.sendMsgBuf(element._Slave_ID, 0, 8, data);
-                 
-                          if(sndStat == CAN_OK){
-                            Serial.println("Message Sent Successfully!");
-                             String LCDarray1 = "Message Sent";
-                             String LCDarray2 = "Successfully";
-                          } else {
-                            Serial.println("Error Sending Message...");
-                            String LCDarray1 = "Error Sending";
-                            String LCDarray2 = "Message...";
-                          }
-                }
 
+//#include "Slave_Ports_Status_S.h"
 
-                          
-                                  #if defined(HAS_LCD1602)
 
-                                  
-                                   delay(LCDtim * 5);  
-                                    //lcd.setCursor(0,1); 
-                                    lcd.print(lcdPattern);
-                                    //lcd.print(lcdPos % 10);
-                                  if(lcdPos >= 16) { 
-                                    //lcd.print("N");
-                                    lcd.setCursor(0,1); 
-                                    lcdPos = 0;
-                                    if(lcdPattern=="s") lcdPattern = "S" ;
-                                    else lcdPattern = "s" ;
-                                  }
-                                    lcdPos ++;
-                          #endif
-                                  #if defined(HAS_TFT_ILI9163C)
-                                    delay(LCDtim);  
-                                    display.setCursor(0,60); 
-                                    display.print(LCDarray1); display.print(" "); display.print(LCDarray2);
-                                  #endif
-                          delay(5000);   // send data per 100ms
+Slave_Ports_Status_QUEUE_T Slave_Ports_Status_QUEUE_A[11];
 
-             
-            }*/
-          
-          
-           
-          
-         // byte sndStat = CAN0.sendMsgBuf(_Slave1_ID, 0, 8, data);
 
 
- } //EOF _Slave_Ports_broadcast_POP
- 
 
- void _Slave_Ports_queue__POP( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST, 
+ void _Slave_Ports_queue__POP( Slave_Ports_Status_QUEUE_T* Slave_Ports_Status_QUEUE_A, 
  int _Slave_Ports_queue_count, 
  int _Slave_Ports_queue_pop, 
  int _Slave_Ports_queue_front, 
  int _Slave_Ports_queue_back,
  int _Slave_Ports_queue_peek,
- int LCDtim,  _Slave_Port* _Slave_Ports) {
+ int LCDtim,   Slave_Ports_Status_T*  Slave_Ports_Status_A) {
    //int count = _Slave_Ports_queuev.count();
    //int _Slave_Ports_queue_pop _Slave_Ports_queuev.pop();
   Serial.print("#180 run _Slave_Ports_queue__POP cnt "); Serial.print(_Slave_Ports_queue_count); Serial.print(" , pop: "); Serial.println(_Slave_Ports_queue_pop);
@@ -353,12 +43,12 @@ int _Slave_Ports_queue_task_type, int _Slave_Port_link, long time_seq_id, long t
     Serial.println(LCDarray2);
 //    LCD_print(LCDarray1, LCDarray2, LCDtim / 3 ) ;
 
-              if(_Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].queueID == 0 and 
-                _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].queueID == 0 and 
-                  _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type == 0 and 
-                    _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Port_link == 0 and 
-                      _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].time_seq_id == 0 and 
-                        _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].time_min_run == 0 ) {
+              if(Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].QUEUE_ID_A == 0 and 
+                Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].QUEUE_ID_A == 0 and 
+                  Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].TASK_TYPE_A == 0 and 
+                    //Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].TASK_PORT_ASSOC_A == 0 and 
+                      Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].time_seq_id == 0 and 
+                        Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].time_min_run == 0 ) {
                    String LCDarray1 = "#206 Error with queue";
                    String LCDarray2 = "ID: ";
                     LCDarray2.concat( _Slave_Ports_queue_pop);  LCDarray2.concat("] ");
@@ -370,25 +60,28 @@ int _Slave_Ports_queue_task_type, int _Slave_Port_link, long time_seq_id, long t
                    String LCDarray2 = "ID: ";
                     LCDarray2.concat( _Slave_Ports_queue_pop);  LCDarray2.concat("] task_type[");
                       
-                        LCDarray2.concat( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);  LCDarray2.concat("] ");
+                        LCDarray2.concat( Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].TASK_TYPE_A);  LCDarray2.concat("] ");
                    
                    Serial.print(LCDarray1);
                    Serial.println(LCDarray2);
             //        LCD_print(LCDarray1, LCDarray2, LCDtim / 3 ) ;
 
-                        if( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type == 0x01 ) {
-                           Serial.print("#224 running _Slave_Ports_ttl_decrement = ");     Serial.println( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);
-                            #include "_Slave_Ports_ttl_decrement.h"
-                           _Slave_Ports_ttl_decrement_POP(_Slave_Ports_queue_tasks_LIST, _Slave_Ports_queue_pop ,  _Slave_Ports ) ; 
-                           
-                        } else if( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type == 0x04 ) {
-                           Serial.print("#337 running _Slave_Ports_broadcast = ");     Serial.println( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);
-                            #include "_Slave_Ports_ttl_decrement.h"
-                           _Slave_Ports_broadcast_POP(_Slave_Ports_queue_tasks_LIST, _Slave_Ports_queue_pop ,  _Slave_Ports, LCDtim ) ; 
-                           
-                        }  else {
-                            Serial.print("Error unsupported type ");     Serial.println( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);
-                        }
+
+                     switch (Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].TASK_TYPE_A) {
+                            case TASK_TYPE_T_Slave_Ports_ttl_decrement:    // your hand is on the sensor
+                                      Serial.print("#224 running _Slave_Ports_ttl_decrement = ");     Serial.println( Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].TASK_TYPE_A);
+                                      //#include "_Slave_Ports_ttl_decrement.h"
+                                      _Slave_Ports_ttl_decrement_POP(Slave_Ports_Status_QUEUE_A, _Slave_Ports_queue_pop ,  Slave_Ports_Status_A ) ;  
+                                      break;
+                                      
+                            case TASK_TYPE_T_Slave_Ports_broadcast____:
+                                      Serial.print("#337 running _Slave_Ports_broadcast = ");     Serial.println( Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].TASK_TYPE_A);
+                                     // #include "_Slave_Ports_ttl_decrement.h"
+                                     _Slave_Ports_broadcast_POP(Slave_Ports_Status_QUEUE_A, _Slave_Ports_queue_pop ,  Slave_Ports_Status_A, LCDtim ) ; 
+                                     break;
+
+                             Serial.print("Error unsupported type ");     Serial.println( Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_pop].TASK_TYPE_A);     
+                     }
 
                     
               }
@@ -434,94 +127,3 @@ int _Slave_Ports_queue_task_type, int _Slave_Port_link, long time_seq_id, long t
 
 
 
-
-
-
-
-
-
-
-
-/*
-struct _Slave_Port
-{ 
-  char _Protocol ;
-  int _Slave_ID;
-  char Port_Type;
-  int Address;
-  int LocalPort ;
-  void (*fn)();
-};
-
-
-struct _Slave_Port {
-   
-}
-
-#define _Slave_Port =   { "CAN" , 0x102 , "PWM", 0x00, 0  } 
-
-*/
-
-  /* #define __CAN_Ports { _Slave1_ID } ;
-
-
-   #define __CAN_Ports_PWM { _Slave1_ID 
-    {0x00 , 0 } ,
-    {0x00 , 1 }
-   } ;
-
-   */
-/*
-   typedef struct
- {
-     int Slave1_ID;
-     String PortType;
-     int Address;
-     int LocalPort ;
- } 
-
-*/
-/*
-
-struct buttons
-{ 
-  int color[3];
-  int positions[4];
-  char init[20];
-  void (*fn)();
-};
-
-//void func1();
-//void func2();
-
-  
-buttons test[] = 
-{
-  { {0,0,0},    {0,0,100,100}, "getSomething",  func1 },
-  { {40,40,40}, {50,50,10,10}, "somethingElse", func2 },
-};
-*/
-
-/*
-typedef struct  {
-  const char * const l_name;
-  byte x_m;
-  byte y_m;
-  boolean period[4];
-} myStruct;
-
-myStruct structs[] = {
-  {"My Name", 0, 0, {true, true, false, false}},
-  {"My Second Name", 0, 0, {true, false, true, false}}
-};
-*/
-
-
-
- //#define _CAN_P_0x102_PWM0x00_0 { _Slave1_ID , "PWM", 0x00, 0 } 
- //#define _CAN_P_0x102_PWM0x00_1 { _Slave1_ID , "PWM", 0x00, 1 } 
- // char _Slave_Ports ;
- // _Slave_Ports[0] = "_CAN_P_0x102_PWM0x00_0"  ;
- // _Slave_Ports[1] = "_CAN_P_0x102_PWM0x00_1"  ;
-
- // char *_Slave_Ports[] = { "_CAN_P_0x102_PWM0x00_0", "_CAN_P_0x102_PWM0x00_1" } ;

+ 0 - 32
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Protocol_CAN.h

@@ -1,32 +0,0 @@
-
-
-
-/*
-byte data[8] = {element.Address, -1 
-                 _Slave_Ports_queue_task_type_LIST, -2  type of protocol task
-                 element.LocalPort, -3
-                 element.PortTypes, -4
-                 element.LocalPort, -5
-                 element.Exp_state, -6
-                  element.Exp_state_ttl, -7
-                  packet_ttl }; 
-*/
-
-const byte _Slave_Ports_Protocol_CAN_COUNT = 32;
-
-//byte sndStat = CAN0.sendMsgBuf(_Slave_Ports[i]._Slave_ID, 0, 8, data);
-
-
-const char _Slave_Ports_Protocol_CAN_LIST[][_Slave_Ports_Protocol_CAN_COUNT] = {
-        "REMOTE_ID", //0 - use 0xFF fof broadcast
-        "NOT_USED_ZERO", //1
-        "_Slave_Ports_queue_task_type",  //2
-        "LocalPort",  //3
-        "PortTypes", //4
-         "LocalPort", //5  - to set ports associated on PW
-          "Exp_state", //6
-           "Exp_state_ttl", //7
-          "_MSG_TTL" //8 like in tcp/ip
-        }; 
-        
-        

+ 4 - 4
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Protocol.h → SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Protocol_CAN_func.h

@@ -3,12 +3,12 @@
 void _Slave_Ports_Protocol_CAN_broadcast_AF(_Slave_Ports_Protocol_CAN_broadcast_T _Slave_Ports_Protocol_CAN_broadcast_A, byte* _Slave_Ports_Protocol_CAN_broadcast_B ) {
    //byte dataa = {10, 12, 13, 4, 5, 6, 7, 8}; 
     //   return dataa;
-     _Slave_Ports_Protocol_CAN_broadcast_B[1] = _Slave_Ports_Protocol_CAN_broadcast_A._Slave_ID_BROADCAST ;
-     _Slave_Ports_Protocol_CAN_broadcast_B[2] = _Slave_Ports_Protocol_CAN_broadcast_A._SENDER ;
+     _Slave_Ports_Protocol_CAN_broadcast_B[1] = _Slave_Ports_Protocol_CAN_broadcast_A._CAN_REMOTE_ID ;
+     _Slave_Ports_Protocol_CAN_broadcast_B[2] = _Slave_Ports_Protocol_CAN_broadcast_A._CAN_SENDER_ID ;
      _Slave_Ports_Protocol_CAN_broadcast_B[3] = _Slave_Ports_Protocol_CAN_broadcast_A.Port_ID ;
      _Slave_Ports_Protocol_CAN_broadcast_B[4] = _Slave_Ports_Protocol_CAN_broadcast_A.PortTypes ;
-     _Slave_Ports_Protocol_CAN_broadcast_B[5] =  _Slave_Ports_Protocol_CAN_broadcast_A.Exp_state ;
-     _Slave_Ports_Protocol_CAN_broadcast_B[6] =  _Slave_Ports_Protocol_CAN_broadcast_A.Exp_state_ttl ;
+     _Slave_Ports_Protocol_CAN_broadcast_B[5] = _Slave_Ports_Protocol_CAN_broadcast_A.Exp_state ;
+     _Slave_Ports_Protocol_CAN_broadcast_B[6] = _Slave_Ports_Protocol_CAN_broadcast_A.Exp_state_ttl ;
      _Slave_Ports_Protocol_CAN_broadcast_B[7] = _Slave_Ports_Protocol_CAN_broadcast_A.Broadcast_state ;
      _Slave_Ports_Protocol_CAN_broadcast_B[8] = _Slave_Ports_Protocol_CAN_broadcast_A._CAN_8 ;
         

+ 77 - 0
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Protocol_CAN_struct.h

@@ -0,0 +1,77 @@
+
+
+
+
+
+
+//typedef int _SENDER_T  ;
+
+#define _CAN_REMOTE_ID_BROADCAST 0xFF
+
+typedef int _REMOTE_Controller_ID_T ;
+
+typedef int _LOCAL_Controller_ID_T ;
+typedef int _CAN_SENDER_ID_T ; 
+typedef int _CAN_REMOTE_ID_T ; 
+
+
+//#define _Slave_ID_BROADCAST_T  _Slave_ID_BROADCAST  0xFF ; 
+
+ #if ! defined(Active_ControllerID)
+    #error "#9 not defined Active_ControllerID"
+ 
+ #endif 
+ 
+ //byte sndStat = CAN0.sendMsgBuf(_Slave_Ports[i]._Slave_ID, 0, 8, data);
+
+ //byte data[8] = {_Slave_Ports[i].Address,  0x04, _Slave_Ports[i].LocalPort, _Slave_Ports[i].PortTypes, _Slave_Ports[i].LocalPort, _Slave_Ports[i].Exp_state, _Slave_Ports[i].Exp_state_ttl, 0x07};
+
+ 
+ 
+ 
+ struct _Slave_Ports_Protocol_CAN_message_S {
+  _CAN_REMOTE_ID_T _CAN_REMOTE_ID  ;   // 1remote id - use FF for broadcast
+  const _CAN_SENDER_ID_T _CAN_SENDER_ID = Active_ControllerID ; //2 sender //Device which orginated port 
+  int  Port_ID ; //3 global id for device //const char * const _Protocol;
+  PortTypes_T  PortTypes;  //4 0xFF  =  1111 1111 s
+  //int  Address ; //
+  //int  LocalPort; //
+  Exp_state_T  Exp_state;    //5
+  int  Exp_state_ttl;  //6
+  int  Broadcast_state;  //7
+  const int _CAN_8 = 0x07 ; //8 - nbot used
+} ;
+ 
+ 
+ 
+ struct _Slave_Ports_Protocol_CAN_broadcast_S {
+  const _CAN_REMOTE_ID_T  _CAN_REMOTE_ID = _CAN_REMOTE_ID_BROADCAST ;   // 1remote id - use FF for broadcast
+  const _CAN_SENDER_ID_T  _CAN_SENDER_ID = Active_ControllerID ; //2 sender //Device which orginated port 
+  int  Port_ID ; //3 global id for device //const char * const _Protocol;
+  PortTypes_T  PortTypes;  //4 0xFF  =  1111 1111 s
+  //int  Address ; //
+  //int  LocalPort; //
+  Exp_state_T  Exp_state;    //5
+  int  Exp_state_ttl;  //6
+  int  Broadcast_state;  //7
+  const int _CAN_8 = 0x07 ; //8 - nbot used
+} ;
+
+ 
+typedef struct _Slave_Ports_Protocol_CAN_broadcast_S _Slave_Ports_Protocol_CAN_broadcast_T;
+
+
+
+typedef int _CAN_SEND_1_T  ; //1 byte = 0
+typedef int _CAN_SEND_2_T  ; //2 byte = 8 
+
+ struct _Slave_Ports_Protocol_CAN_SEND_S {
+     const _CAN_SENDER_ID_T _CAN_SENDER_ID = Active_ControllerID ;
+     const  _CAN_SEND_1_T  _CAN_SEND_1 = 0 ;
+     const  _CAN_SEND_2_T  _CAN_SEND_2 = 8 ;
+     _Slave_Ports_Protocol_CAN_broadcast_T _Slave_Ports_Protocol_CAN_broadcast_A ;
+} ;
+
+
+typedef  byte _Slave_Ports_Protocol_CAN_broadcast_AS[8]  ;
+

+ 103 - 0
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Status_QUEUE_func.h

@@ -0,0 +1,103 @@
+
+  
+
+void _Slave_Ports_queue__INIT( Slave_Ports_Status_QUEUE_T* Slave_Ports_Status_QUEUE_A) {
+  Serial.println("_Slave_Ports_queue__INIT");
+   int i;
+  for(i=0;i<10;i++) {
+  
+   Slave_Ports_Status_QUEUE_A[i].QUEUE_ID_A = 0;
+     Slave_Ports_Status_QUEUE_A[i].TASK_TYPE_A = TASK_TYPE_T_NOT_USED_________________;
+      Slave_Ports_Status_QUEUE_A[i].TASK_PORT_ASSOC_A = {} ;
+       Slave_Ports_Status_QUEUE_A[i].time_seq_id = 0;
+        Slave_Ports_Status_QUEUE_A[i].time_min_run = 0;
+        
+      //  Slave_Ports_Status_QUEUE_A[i]=Slave_Ports_Status_QUEUE_A[i];
+   }
+   
+}
+
+
+void _Slave_Ports_queue__add( Slave_Ports_Status_QUEUE_T* Slave_Ports_Status_QUEUE_A,
+TASK_TYPE_T TASK_TYPE_A,
+TASK_PORT_ASSOC_T TASK_PORT_ASSOC_A,
+long time_seq_id, 
+long time_min_run //, 
+//int _Slave_Ports_queue_peek , int _Slave_Ports_queue_push , int _Slave_Ports_queue_peek_new
+) {
+  Serial.println(".");
+      Serial.print("#152 _Slave_Ports_queue__add  peek: ["); 
+       int _Slave_Ports_queue_peek = _Slave_Ports_queue.peek() ;
+       int _Slave_Ports_queue_back = _Slave_Ports_queue.back() ;
+     //  int _Slave_Ports_queue_push_new_ref;
+      // if(_Slave_Ports_queue_back > _Slave_Ports_queue_peek)
+      Serial.print(_Slave_Ports_queue_peek);  Serial.print("] cur back[");  Serial.print(_Slave_Ports_queue_back); Serial.print("] ");
+      
+     
+     _Slave_Ports_queue.push(_Slave_Ports_queue_back + 1);
+      int _Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ;
+     // int _Slave_Ports_queue__push = _Slave_Ports_queue__peek + 1 ;
+             Serial.print("] new peek[");
+             Serial.print(_Slave_Ports_queue_peek_new );    Serial.print("]  planned["); Serial.print(_Slave_Ports_queue_back + 1 );  
+             Serial.print("] front[");   Serial.print(_Slave_Ports_queue.front());   Serial.print("] back[");   Serial.print(_Slave_Ports_queue.back());  Serial.println("] ");
+
+ 
+             
+     Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_back + 1 ].QUEUE_ID_A=_Slave_Ports_queue_back + 1 ;
+     Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_back + 1 ].TASK_TYPE_A=TASK_TYPE_A ;
+     Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_back + 1 ].TASK_PORT_ASSOC_A=TASK_PORT_ASSOC_A ;
+     Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_back + 1 ].time_seq_id=time_seq_id ;
+     Slave_Ports_Status_QUEUE_A[_Slave_Ports_queue_back + 1 ].time_min_run=time_min_run ;
+    
+}
+
+
+
+
+//Queue<_Slave_Ports_queueT> _Slave_Ports_queue = Queue<_Slave_Ports_queueT>(5);
+void _Slave_Ports_queue__list( Slave_Ports_Status_QUEUE_T* Slave_Ports_Status_QUEUE_A) {
+  int i;
+    Serial.println("#100 Slave_Ports_Status_QUEUE_A): ");
+    //Serial.println(sizeof(Slave_Ports_Status_QUEUE_A));
+        for(i=0;i<=10;i++) { //sizeof(_LCD_print_buffors)
+
+          if(Slave_Ports_Status_QUEUE_A[i].QUEUE_ID_A == 0 and
+                 Slave_Ports_Status_QUEUE_A[i].TASK_TYPE_A == 0 and
+                // Slave_Ports_Status_QUEUE_A[i].TASK_PORT_ASSOC_A == {} and 
+                 Slave_Ports_Status_QUEUE_A[i].time_seq_id == 0 and 
+                 Slave_Ports_Status_QUEUE_A[i].time_min_run == 0 ) {
+            
+          } else {
+                Serial.print(" $i[");
+                Serial.print(i);
+
+                 Serial.print("] QUEUE_ID_A: ");
+                Serial.print(Slave_Ports_Status_QUEUE_A[i].QUEUE_ID_A);
+
+                   
+
+                 Serial.print("] TASK_TYPE_A: ");
+                                 Serial.print(Slave_Ports_Status_QUEUE_A[i].TASK_TYPE_A);
+                  Serial.print("] desc: ");
+                 //Slave_Ports_queue_task_type_DESC(Slave_Ports_Status_QUEUE_A[i].TASK_TYPE_A);
+                 //char res;
+                 // res = _Slave_Ports_queue_task_type_DESC(Slave_Ports_Status_QUEUE_A[i]._Slave_Ports_queue_task_type);  Serial.print(res);
+                  
+                //  Serial.print(" - map[");  Serial.print(_Slave_Ports_queue_task_type_LIST[Slave_Ports_Status_QUEUE_A[i].TASK_TYPE_A]);  Serial.print("]"); 
+               _Slave_Ports_queue_task_type_DESC(Slave_Ports_Status_QUEUE_A[i].TASK_TYPE_A) ; //(res); //_Slave_Ports_queue_task_type_DESC(Slave_Ports_Status_QUEUE_A[i]._Slave_Ports_queue_task_type
+
+  
+                 Serial.print("] TASK_PORT_ASSOC_A: ");
+                Serial.print(Slave_Ports_Status_QUEUE_A[i].TASK_PORT_ASSOC_A.Port_ID);
+                     
+                     
+                    Serial.print("] time_seq_id: ");
+                Serial.print(Slave_Ports_Status_QUEUE_A[i].time_seq_id);
+
+                     Serial.print("] time_min_run: ");
+                Serial.println(Slave_Ports_Status_QUEUE_A[i].time_min_run);
+                }
+  
+        }
+}
+

+ 42 - 0
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Status_QUEUE_struct.h

@@ -0,0 +1,42 @@
+
+
+typedef int QUEUE_ID_T ;
+
+
+
+     struct Slave_Ports_Status_QUEUE_S {
+      QUEUE_ID_T QUEUE_ID_A ; //current queue task
+       TASK_TYPE_T TASK_TYPE_A ; 
+        TASK_PORT_ASSOC_T TASK_PORT_ASSOC_A; //todo link
+       long time_seq_id;
+       long time_min_run;
+    } ;
+    
+    
+    typedef struct Slave_Ports_Status_QUEUE_S Slave_Ports_Status_QUEUE_T;
+
+
+
+
+
+
+
+ struct _Slave_Ports_queue_tasksS {
+  int queueID;
+  int _Slave_Ports_queue_task_type ; /*
+              { 0x01 _Slave_Ports_ttl_decrement, 
+                 0x02  request_confirm_Exp_state ,
+                 0x03  request_set_new_Exp_state,
+                 0x04 
+                  }
+  */
+  int _Slave_Port_link; //todo link
+ long time_seq_id;
+ long time_min_run;
+} ;
+
+typedef struct _Slave_Ports_queue_tasksS _Slave_Ports_queue_tasksT;
+
+
+
+

+ 51 - 0
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Status_func.h

@@ -0,0 +1,51 @@
+
+ void Slave_Ports_Status_add_port(
+ Slave_Ports_Status_T* Slave_Ports_Status_A , Slave_Ports_Status_add_port_count_T* Slave_Ports_Status_add_port_count_A,
+ 
+                int  Port_ID,
+                int  _Slave_ID,
+                PortTypes_T  PortTypes,
+                int  Address,
+                int  LocalPort,
+                int  Exp_state,
+                int  Exp_state_ttl,
+                int  Broadcast_state,
+                int I2C_port,
+                //int I2C_driver
+                int I2C_driver
+                )
+{
+        int i = Slave_Ports_Status_add_port_count_A ;
+    if(Slave_Ports_Status_add_port_count_A == 0) {
+      Slave_Ports_Status_add_port_count_A ++;
+     Slave_Ports_Status_A[i].Port_ID=0x00;
+     Slave_Ports_Status_A[i]._Slave_ID=0x00;
+     Slave_Ports_Status_A[i].PortTypes=0x00;
+     Slave_Ports_Status_A[i].Address=0x00;
+     Slave_Ports_Status_A[i].LocalPort=0x00;
+     Slave_Ports_Status_A[i].Exp_state=0x00;
+     Slave_Ports_Status_A[i].Exp_state_ttl=0x00;
+     Slave_Ports_Status_A[i].Broadcast_state=0x00;
+     Slave_Ports_Status_A[i].I2C_port=0x00;
+     Slave_Ports_Status_A[i].I2C_driver=0x00;
+     Slave_Ports_Status_add_port_count_A ++;
+     
+   
+   
+    }
+    
+    Slave_Ports_Status_A[i + 1].Port_ID = Port_ID ;
+    Slave_Ports_Status_A[i + 1]._Slave_ID = _Slave_ID ;
+    Slave_Ports_Status_A[i + 1].PortTypes = PortTypes ;
+    Slave_Ports_Status_A[i + 1].Address = Address ;
+    Slave_Ports_Status_A[i + 1].LocalPort = LocalPort ;
+    Slave_Ports_Status_A[i + 1].Exp_state = Exp_state ;
+    Slave_Ports_Status_A[i + 1].Exp_state_ttl = Exp_state_ttl ;
+    Slave_Ports_Status_A[i + 1].Broadcast_state = Broadcast_state ;
+    Slave_Ports_Status_A[i + 1].I2C_port = I2C_port ;
+    Slave_Ports_Status_A[i + 1].I2C_driver = I2C_driver ;
+  //  Slave_Ports_Status_A[Slave_Ports_Status_add_port_count_A + 1].I2C_driver = I2C_driver_F(I2C_driver) ;
+
+    Slave_Ports_Status_add_port_count_A ++;
+  
+}

+ 65 - 0
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Status_struct.h

@@ -0,0 +1,65 @@
+
+
+//#ifndef Slave_Ports_Status_S_h
+//#define Slave_Ports_Status_S_h
+
+
+
+typedef boolean IS_Local_T ;
+const IS_Local_T IS_Local_FALSE = false ;
+const IS_Local_T IS_Local_TRUE = true ;
+
+
+#define I2C_port_DEFAULT 0x01
+
+ struct Slave_Ports_Status_S {
+  Port_ID_T  Port_ID ; //global id for device //const char * const _Protocol;
+  int  _Slave_ID; //Device which orginated port   //remote id - use FF for broadcast
+  PortTypes_T  PortTypes;  //0xFF  =  1111 1111 s
+                                          /*
+                                          {
+                                      bit 1 - PWM port
+                                      bit 2 - on I2C managed port
+                                      bit 3 - expanded port with LocalPort address
+                                      bit 4 - not allocated
+                                      bit 2 - not allocated
+                                      bit 5 - not allocated
+                                      bit 6 - not allocated
+                                      bit 7 - not allocated
+                                      bit 8 - not allocated
+                                    } 
+                                           */
+ // byte has_Address;
+  int  Address ;
+ // byte has_Local_Port;
+  int  LocalPort;
+  Exp_state_T  Exp_state;                  /*0xFF  =  1111 1111
+                                    0x00  =  0000 0001  = OFF = 0V
+                                    0x01  =  0000 0002  = ON = PWM max
+                                    {
+                                      bit 1 - OFF = 0V
+                                      bit 2 - ON = PWM max
+                                      bit 3 - not allocated
+                                      bit 4 - not allocated
+                                      bit 2 - not allocated
+                                      bit 5 - not allocated
+                                      bit 6 - not allocated
+                                      bit 7 - not allocated
+                                      bit 8 - not allocated
+                                    }*/
+  Exp_state_ttl_T  Exp_state_ttl;  // 0x01 = odswiezyc
+  Broadcast_state_T  Broadcast_state; //0x00 - not broadcast; 0x01
+  int I2C_port ; //0x01 - default port, 0x00 - not I2C connected
+  I2C_driver_T I2C_driver; //0x00 - not driver, 0x01 Adafruit_PWMServoDriver.h
+  IS_Local_T IS_Local_A; // Define if port is local or remote added
+  
+} ;
+
+typedef struct Slave_Ports_Status_S Slave_Ports_Status_T;
+
+typedef int Slave_Ports_Status_add_port_count_T;
+typedef Slave_Ports_Status_add_port_count_T Slave_Ports_Status_add_port_count_A ;
+
+
+//#endif
+

+ 0 - 140
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Struct.h

@@ -1,140 +0,0 @@
-
-
-
-
-typedef struct  {
-  const char * const _Protocol;
-  int _Slave_ID; //remote id - use FF for broadcast
-  int PortTypes;  //0xFF  =  1111 1111 s
-                                          /*
-                                          {
-                                      bit 1 - PWM port
-                                      bit 2 - on I2C managed port
-                                      bit 3 - expanded port with LocalPort address
-                                      bit 4 - not allocated
-                                      bit 2 - not allocated
-                                      bit 5 - not allocated
-                                      bit 6 - not allocated
-                                      bit 7 - not allocated
-                                      bit 8 - not allocated
-                                    } 
-                                           */
- // byte has_Address;
-  int Address ;
- // byte has_Local_Port;
-  int LocalPort;
-  int Exp_state;                  /*0xFF  =  1111 1111
-                                    0x00  =  0000 0000  = OFF = 0V
-                                    0x01  =  0000 0001  = ON = PWM max
-                                    {
-                                      bit 1 - OFF = 0V
-                                      bit 2 - ON = PWM max
-                                      bit 3 - not allocated
-                                      bit 4 - not allocated
-                                      bit 2 - not allocated
-                                      bit 5 - not allocated
-                                      bit 6 - not allocated
-                                      bit 7 - not allocated
-                                      bit 8 - not allocated
-                                    }*/
-  int Exp_state_ttl;  // 0x00 = odswiezyc
-  //int Broadcast_state; //0x00 - not broadcast; 0x01
-} _Slave_Port;
-
-
-
-
-
-
-
-
-
-
-
-
-
- struct _Slave_Ports_queue_tasksS {
-  int queueID;
-  int _Slave_Ports_queue_task_type ; /*
-              { 0x01 _Slave_Ports_ttl_decrement, 
-                 0x02  request_confirm_Exp_state ,
-                 0x03  request_set_new_Exp_state,
-                 0x04 
-                  }
-  */
-  int _Slave_Port_link; //todo link
- long time_seq_id;
- long time_min_run;
-} ;
-
-typedef struct _Slave_Ports_queue_tasksS _Slave_Ports_queue_tasksT;
-
-
-
-
-
-
-
-typedef int _Slave_ID_BROADCAST_T  ;
-typedef int _SENDER_T  ;
-
-
-//#define _Slave_ID_BROADCAST_T  _Slave_ID_BROADCAST  0xFF ; 
-
- #if ! defined(Active_ControllerID)
-    #error "#9 not defined Active_ControllerID"
- 
- #endif 
-
- struct _Slave_Ports_Protocol_CAN_broadcast_S {
-  const   _Slave_ID_BROADCAST_T  _Slave_ID_BROADCAST = 0xFF ;   // 1remote id - use FF for broadcast
-  const _SENDER_T _SENDER = Active_ControllerID ; //2 sender //Device which orginated port 
-  int  Port_ID ; //3 global id for device //const char * const _Protocol;
-  int  PortTypes;  //4 0xFF  =  1111 1111 s
-  //int  Address ; //
-  //int  LocalPort; //
-  int  Exp_state;    //5
-  int  Exp_state_ttl;  //6
-  int  Broadcast_state;  //7
-  const int _CAN_8 = 0x07 ; //8 - nbot used
-} ;
-
-typedef struct _Slave_Ports_Protocol_CAN_broadcast_S _Slave_Ports_Protocol_CAN_broadcast_T;
-
-
-
-typedef int _CAN_SEND_1_T  ; //1 byte = 0
-typedef int _CAN_SEND_2_T  ; //2 byte = 8 
-
- struct _Slave_Ports_Protocol_CAN_SEND_S {
-     const _SENDER_T _SENDER = Active_ControllerID ;
-     const  _CAN_SEND_1_T  _CAN_SEND_1 = 0 ;
-     const  _CAN_SEND_2_T  _CAN_SEND_2 = 8 ;
-     _Slave_Ports_Protocol_CAN_broadcast_T _Slave_Ports_Protocol_CAN_broadcast_A ;
-} ;
-
-//typedef  byte _Slave_Ports_Protocol_CAN_broadcast_AS[8] ;
-
-/*
-
- struct _Slave_Ports_Protocol_CAN_broadcast_AS {
-  const byte  _Slave_ID_BROADCAST = 0xFF ;   // 1remote id - use FF for broadcast
-  const byte _SENDER = Active_ControllerID ; //2 sender //Device which orginated port 
-  byte  Port_ID ; //3 global id for device //const char * const _Protocol;
-  byte  PortTypes;  //4 0xFF  =  1111 1111 s
-  //int  Address ; //
-  //int  LocalPort; //
-  byte  Exp_state;    //5
-  byte  Exp_state_ttl;  //6
-  byte  Broadcast_state;  //7
-  const byte _CAN_8 = 0x07 ; //8 - nbot used
-} ;
-*/
-
-
-typedef  byte _Slave_Ports_Protocol_CAN_broadcast_AS[8]  ;
-
-
-
-
-

+ 152 - 0
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_broadcast_func.h

@@ -0,0 +1,152 @@
+
+
+ void _Slave_Ports_broadcast_POP(Slave_Ports_Status_QUEUE_T*  Slave_Ports_Status_QUEUE_A, int _Slave_Ports_queue_pop ,  Slave_Ports_Status_T*  Slave_Ports_Status_A, int LCDtim ) {
+        Serial.println("#251 _Slave_Ports_broadcast_POP");
+          int i;
+          for(i=0;i<=100;i++) {
+            if(Slave_Ports_Status_A[i].Broadcast_state == Broadcast_state_TO_REFRESH and Slave_Ports_Status_A[i].IS_Local_A == IS_Local_TRUE) {
+              Serial.print(" ind:"); Serial.print(i);  Serial.print("] IS_Local_A:");
+              Serial.print(Slave_Ports_Status_A[i].IS_Local_A);
+              Serial.print(" , ID:"); 
+              Serial.print(Slave_Ports_Status_A[i].Port_ID, HEX); Serial.print(" , PortTypes:");
+             Serial.print(Slave_Ports_Status_A[i].PortTypes, HEX); Serial.print(" , Addr:"); Serial.print(Slave_Ports_Status_A[i].Address, HEX);
+              Serial.print(" , Local:"); Serial.print(Slave_Ports_Status_A[i].LocalPort);
+              Serial.print(" , Exp state:"); Serial.print(Slave_Ports_Status_A[i].Exp_state);
+                Serial.print(" , Exp_state_ttl"); Serial.println(Slave_Ports_Status_A[i].Exp_state_ttl);  
+
+
+                        Serial.println(" Prepared data");
+                        #if defined(HAS_LCD1602)                              
+                             String LCDarray1 = "L[";
+                             LCDarray1.concat(Slave_Ports_Status_A[i].IS_Local_A); LCDarray1.concat("] ID["); LCDarray1.concat(String(Slave_Ports_Status_A[i].Port_ID, HEX)); LCDarray1.concat("] T["); LCDarray1.concat(String(Slave_Ports_Status_A[i].PortTypes, HEX));
+                            // lcd.print(LCDarray1);
+                            String LCDarray2 = " >"; LCDarray2.concat(String(Slave_Ports_Status_A[i].Address, HEX)); LCDarray2.concat( "< {"); LCDarray2.concat( String(Slave_Ports_Status_A[i].LocalPort, HEX)); LCDarray2.concat( "} =[" ); LCDarray2.concat(String(Slave_Ports_Status_A[i].Exp_state, HEX) ); LCDarray2.concat("] ?[" ) ;
+                                 LCDarray2.concat(String(Slave_Ports_Status_A[i].Exp_state_ttl, HEX)) ; LCDarray2.concat("]") ;
+                                 LCD_print(LCDarray1, LCDarray2, LCDtim / 2 ) ;
+                        #endif
+                        //                        (0)           (1)           (2)                       (3)                         (4)                         (5)                     (6)                   
+                      byte data[8] = {Slave_Ports_Status_A[i].Address,  0x04, Slave_Ports_Status_A[i].LocalPort, Slave_Ports_Status_A[i].PortTypes, Slave_Ports_Status_A[i].LocalPort, Slave_Ports_Status_A[i].Exp_state, Slave_Ports_Status_A[i].Exp_state_ttl, 0x07};
+                     // byte data[8] = {element.Address,          0x04, element.LocalPort,          element.PortTypes,                element.LocalPort,         element.Exp_state,         element.Exp_state_ttl, 0x07};
+                  Serial.print("#303 byte data[8] 1[");   Serial.print(Slave_Ports_Status_A[i].Address);   Serial.print("] 2[");  Serial.print(0x04);   Serial.print("] 3["); 
+                       Serial.print(Slave_Ports_Status_A[i].LocalPort);   Serial.print("] 4[");    Serial.print(Slave_Ports_Status_A[i].PortTypes);   Serial.print("] 5[");  Serial.print(Slave_Ports_Status_A[i].Exp_state);   Serial.print("] 6[");
+                        Serial.print( Slave_Ports_Status_A[i].Exp_state_ttl);   Serial.print("] 7[");  Serial.print(0x07);   Serial.println("] ");
+                 byte sndStat = CAN0.sendMsgBuf(Slave_Ports_Status_A[i].Port_ID, 0, 8, data);
+              //    byte sndStat ;
+                          if(sndStat == CAN_OK){
+                            Serial.println("Message Sent Successfully!");
+                             String LCDarray1 = "Message Sent";
+                             String LCDarray2 = "Successfully";
+                          } else {
+                            Serial.println("Error Sending Message...");
+                            String LCDarray1 = "Error Sending";
+                            String LCDarray2 = "Message...";
+                          }
+
+                            #if defined(HAS_LCD1602)
+                                    LCD_print(LCDarray1,LCDarray2,LCDtim);
+                                  /*
+                                   delay(LCDtim * 5);  
+                                    //lcd.setCursor(0,1); 
+                                    lcd.print(lcdPattern);
+                                    //lcd.print(lcdPos % 10);
+                                  if(lcdPos >= 16) { 
+                                    //lcd.print("N");
+                                    lcd.setCursor(0,1); 
+                                    lcdPos = 0;
+                                    if(lcdPattern=="s") lcdPattern = "S" ;
+                                    else lcdPattern = "s" ;
+                                  }
+                                    lcdPos ++;
+                                    |*/
+                                 #endif
+                                //  #if defined(HAS_TFT_ILI9163C)
+                                //    delay(LCDtim);  
+                                //    display.setCursor(0,60); 
+                               //     display.print(LCDarray1); display.print(" "); display.print(LCDarray2);
+                               //   #endif
+
+                                      delay(5000);   // send data per 100ms
+                }
+
+
+                          
+                                
+                     
+
+             
+
+
+                
+            }
+          
+
+          /*
+           for (auto element: Slave_Ports_Status_A) {
+            ind++;
+              Serial.print(" ind:"); Serial.print(ind);  Serial.print("] Prot:"); Serial.print(element._Protocol); Serial.print(" , ID:"); Serial.print(element.Port_ID); Serial.print(" , PortTypes:");
+             Serial.print(element.PortTypes); Serial.print(" , Addr:"); Serial.print(element.Address);
+              Serial.print(" , Local:"); Serial.print(element.LocalPort);
+              Serial.print(" , Exp state:"); Serial.print(element.Exp_state);
+                Serial.print(" , Exp_state_ttl"); Serial.println(element.Exp_state_ttl);  
+                if(element._Protocol == "CAN") { 
+                       Serial.println(" Prepared data");
+                        #if defined(HAS_LCD1602)                              
+                               
+                             String LCDarray1 = "P[";
+                             LCDarray1.concat(element._Protocol); LCDarray1.concat("] ID["); LCDarray1.concat(String(element.Port_ID, HEX)); LCDarray1.concat("] T["); LCDarray1.concat(String(element.PortTypes, HEX));
+                            // lcd.print(LCDarray1);
+                            String LCDarray2 = " >"; LCDarray2.concat(String(element.Address, HEX)); LCDarray2.concat( "< {"); LCDarray2.concat( String(element.LocalPort, HEX)); LCDarray2.concat( "} =[" ); LCDarray2.concat(String(element.Exp_state, HEX) ); LCDarray2.concat("] ?[" ) ;
+                                 LCDarray2.concat(String(element.Exp_state_ttl, HEX)) ; LCDarray2.concat("]") ;
+                                 LCD_print(LCDarray1, LCDarray2, LCDtim / 2 ) ;
+                        #endif
+                      byte data[8] = {element.Address, 0x04, element.LocalPort, element.PortTypes, element.LocalPort, element.Exp_state, element.Exp_state_ttl, 0x07};
+                  // }
+                 byte sndStat = CAN0.sendMsgBuf(element.Port_ID, 0, 8, data);
+                 
+                          if(sndStat == CAN_OK){
+                            Serial.println("Message Sent Successfully!");
+                             String LCDarray1 = "Message Sent";
+                             String LCDarray2 = "Successfully";
+                          } else {
+                            Serial.println("Error Sending Message...");
+                            String LCDarray1 = "Error Sending";
+                            String LCDarray2 = "Message...";
+                          }
+                }
+
+
+                          
+                                  #if defined(HAS_LCD1602)
+
+                                  
+                                   delay(LCDtim * 5);  
+                                    //lcd.setCursor(0,1); 
+                                    lcd.print(lcdPattern);
+                                    //lcd.print(lcdPos % 10);
+                                  if(lcdPos >= 16) { 
+                                    //lcd.print("N");
+                                    lcd.setCursor(0,1); 
+                                    lcdPos = 0;
+                                    if(lcdPattern=="s") lcdPattern = "S" ;
+                                    else lcdPattern = "s" ;
+                                  }
+                                    lcdPos ++;
+                          #endif
+                                  #if defined(HAS_TFT_ILI9163C)
+                                    delay(LCDtim);  
+                                    display.setCursor(0,60); 
+                                    display.print(LCDarray1); display.print(" "); display.print(LCDarray2);
+                                  #endif
+                          delay(5000);   // send data per 100ms
+
+             
+            }*/
+          
+          
+           
+          
+         // byte sndStat = CAN0.sendMsgBuf(_Slave1_ID, 0, 8, data);
+
+
+ } //EOF _Slave_Ports_broadcast_POP
+ 

+ 0 - 0
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_func.h → SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_func_loop.h


+ 0 - 47
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_ttl_decrement_POP.h

@@ -1,47 +0,0 @@
-
-
-#ifndef _Slave_Ports_ttl_decrement_POP_F
-
-#define _Slave_Ports_ttl_decrement_POP_F
-
- void _Slave_Ports_ttl_decrement_POP(_Slave_Ports_queue_tasksT*  _Slave_Ports_queue_tasks_LIST,int _Slave_Ports_queue_pop ,  _Slave_Port* _Slave_Ports) {
-     Serial.print("#213 _Slave_Ports_ttl_decrement_POP.   sizeof _Slave_Ports[");     Serial.print(sizeof(_Slave_Ports));
-    int i;
-    for(i=0;i<=100;i++) {
-      if(_Slave_Ports[i]._Protocol == "CAN") {
-            if(_Slave_Ports[i].Exp_state_ttl > 0x00 ) {
-               Serial.print("#217 ttl min for: Prot[");  Serial.print(_Slave_Ports[i]._Protocol);   Serial.print("] ttl[");  Serial.print(_Slave_Ports[i].Exp_state_ttl);  Serial.print(" id[");  Serial.print(i);   Serial.println("]  "); 
-            }
-
-      }
-    }
-
-
- /*
-   const char * const _Protocol;
-  int _Slave_ID;
-  int PortTypes;  //0xFF  =  1111 1111 {  PWM,  .....} = 0x80
- // byte has_Address;
-  int Address ;
- // byte has_Local_Port;
-  int LocalPort;
-  int Exp_state;                  /*0xFF  =  1111 1111
-                                    0x00  =  0000 0000  = OFF = 0V
-                                    0x01  =  0000 0001  = ON = PWM max
-                                    {
-                                      bit 1 - OFF = 0V
-                                      bit 2 - ON = PWM max
-                                      bit 3 - not allocated
-                                      bit 4 - not allocated
-                                      bit 2 - not allocated
-                                      bit 5 - not allocated
-                                      bit 6 - not allocated
-                                      bit 7 - not allocated
-                                      bit 8 - not allocated
-                                   
-  int Exp_state_ttl;  // 0x00 = odswiezyc
-
-  */
- 
- } 
-#endif

+ 21 - 0
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_ttl_decrement_func.h

@@ -0,0 +1,21 @@
+//_Slave_Ports_ttl_decrement_POP.h
+
+//#ifndef _Slave_Ports_ttl_decrement_POP_F
+
+//#define _Slave_Ports_ttl_decrement_POP_F
+
+ void _Slave_Ports_ttl_decrement_POP(Slave_Ports_Status_QUEUE_T*  Slave_Ports_Status_QUEUE_A,int _Slave_Ports_queue_pop ,  Slave_Ports_Status_T* Slave_Ports_Status_A) {
+     Serial.print("#213 _Slave_Ports_ttl_decrement_POP.   sizeof Slave_Ports_Status_A[");     Serial.print(sizeof(Slave_Ports_Status_A));
+    int i;
+    for(i=0;i<=100;i++) {
+      if(Slave_Ports_Status_A[i].LocalPort > 0) {
+            if(Slave_Ports_Status_A[i].Exp_state_ttl == Exp_state_ttl_TO_REFRESH ) {
+               Serial.print("#217 ttl min for: LocalPort[");  Serial.print(Slave_Ports_Status_A[i].LocalPort);   Serial.print("] ttl[");  Serial.print(Slave_Ports_Status_A[i].Exp_state_ttl);
+                 Serial.print(" Port_ID[");  Serial.print(Slave_Ports_Status_A[i].Port_ID);   Serial.println("]  ");   Serial.print(" id[");  Serial.print(i);   Serial.println("]  "); 
+            }
+
+      }
+    }
+
+ } 
+//#endif

+ 22 - 0
SE/stuff/P5_Automation_can-dev-res/_TASK_TYPES_func.h

@@ -0,0 +1,22 @@
+
+
+void _Slave_Ports_queue_task_type_DESC( int _Slave_Ports_queue_task_type ) {//, int* res        
+         switch (_Slave_Ports_queue_task_type) {
+                case TASK_TYPE_T_Slave_Ports_ttl_decrement:   
+                  Serial.println("TASK_TYPE_T_Slave_Ports_ttl_decrement");
+                  break;
+                case TASK_TYPE_T_request_confirm_Exp_state:   
+                  Serial.println("TASK_TYPE_T_request_confirm_Exp_state");
+                  break;
+                case TASK_TYPE_T_request_set_new_Exp_state:  
+                  Serial.println("TASK_TYPE_T_request_set_new_Exp_state");
+                  break;
+                case TASK_TYPE_T_Slave_Ports_broadcast____:  
+                  Serial.println("TASK_TYPE_T_Slave_Ports_broadcast____");
+                  break;
+                case TASK_TYPE_T_Slave_Ports_set_I2C______:  
+                  Serial.println("TASK_TYPE_T_Slave_Ports_set_I2C______");
+                  break;
+                Serial.println("106 unknown _Slave_Ports_queue_task_type");
+          }
+}

+ 21 - 0
SE/stuff/P5_Automation_can-dev-res/_TASK_TYPES_struct.h

@@ -0,0 +1,21 @@
+
+typedef int TASK_TYPE_T ;
+
+
+const TASK_TYPE_T TASK_TYPE_T_NOT_USED_________________ = 0x00 ;
+const TASK_TYPE_T TASK_TYPE_T_Slave_Ports_ttl_decrement = 0x01 ;
+const TASK_TYPE_T TASK_TYPE_T_request_confirm_Exp_state = 0x02 ;
+const TASK_TYPE_T TASK_TYPE_T_request_set_new_Exp_state = 0x03 ;
+const TASK_TYPE_T TASK_TYPE_T_Slave_Ports_broadcast____ = 0x04 ;
+const TASK_TYPE_T TASK_TYPE_T_Slave_Ports_set_I2C______ = 0x05 ;
+
+
+
+struct TASK_PORT_ASSOC_S {
+    Port_ID_T  Port_ID;
+} ; //To associate some port to TASK
+
+typedef struct TASK_PORT_ASSOC_S TASK_PORT_ASSOC_T ;
+
+const TASK_PORT_ASSOC_T TASK_PORT_ASSOC_EMPTY = {};
+

+ 0 - 0
SE/stuff/P5_Automation_can-dev-res/_TFT_ILI9163C.h → SE/stuff/P5_Automation_can-dev-res/_TFT_ILI9163C_init.h


+ 9 - 0
SE/stuff/P5_Automation_can-dev-res/_TFT_ILI9163C_setup.h

@@ -0,0 +1,9 @@
+TFT_ILI9163C display = TFT_ILI9163C(TFT_ILI9163C_CSpin, TFT_ILI9163C_DCpin, TFT_ILI9163C__RSTpin);
+  float p = 3.1415926;
+     display.begin();
+     display.clearScreen();
+     display.setCursor(0,0);
+     display.print(LCDarray1);
+     display.setCursor(0,10);
+     display.print(LCDarray2);
+     delay(LCDtim); 

+ 17 - 0
SE/stuff/P5_Automation_can-dev-res/__main_loop_end.h

@@ -0,0 +1,17 @@
+ _Slave_Ports_queue__list(Slave_Ports_Status_QUEUE_A) ;
+  int _Slave_Ports_queue_count = _Slave_Ports_queue.count();
+  int _Slave_Ports_queue_front = _Slave_Ports_queue.front();
+  int _Slave_Ports_queue_back =  _Slave_Ports_queue.back();
+  int _Slave_Ports_queue_peek = _Slave_Ports_queue.peek();
+  int _Slave_Ports_queue_pop = _Slave_Ports_queue.pop();
+ _Slave_Ports_queue__POP( Slave_Ports_Status_QUEUE_A, 
+ _Slave_Ports_queue_count, 
+ _Slave_Ports_queue_pop, 
+ _Slave_Ports_queue_front, 
+ _Slave_Ports_queue_back,
+ _Slave_Ports_queue_peek,
+ LCDtim, Slave_Ports_Status_A);
+
+  //_LCD_print_buffors_list(_LCD_print_buffors) ;
+  //_LCD_print_screens_list(_LCD_print_screens);
+  

+ 31 - 0
SE/stuff/P5_Automation_can-dev-res/__main_setup.h

@@ -0,0 +1,31 @@
+//__main_setup.h
+//_Slave_Ports_queue.push(_LCD_print_queue.peek() + 1);
+ Serial.println("#298 _Slave_Ports_queue__list");
+ _Slave_Ports_queue__INIT(Slave_Ports_Status_QUEUE_A);
+_Slave_Ports_queue__list(Slave_Ports_Status_QUEUE_A);
+  int _Slave_Ports_queue_peek =  _Slave_Ports_queue.peek() ;
+//  int _Slave_Ports_queue_push = _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1) ; 
+  //int _Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ; _Slave_Ports_queue__add(  *Slave_Ports_Status_QUEUE_A, 0x01 ,0x00 ,100, 5000 ) ;  // _Slave_Ports_queue_peek, _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1), _Slave_Ports_queue.peek());
+ 
+_Slave_Ports_queue__add(  Slave_Ports_Status_QUEUE_A,  TASK_TYPE_T_Slave_Ports_broadcast____ ,TASK_PORT_ASSOC_EMPTY ,100, 5000 ) ;  //        "_Slave_Ports_broadcast", //4
+_Slave_Ports_queue__add(  Slave_Ports_Status_QUEUE_A,  TASK_TYPE_T_Slave_Ports_set_I2C______ ,TASK_PORT_ASSOC_EMPTY ,100, 5000 ) ;  //"_Slave_Ports_set_I2C" //5  - to set ports associated on PW
+
+ //  _Slave_Ports_queue_peek =  _Slave_Ports_queue.peek() ; 
+   //_Slave_Ports_queue_push =  _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1) ;  
+   //_Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ; 
+//_Slave_Ports_queue__add(  Slave_Ports_Status_QUEUE_A, 0x02 ,0x00 ,100, 5000, _Slave_Ports_queue_peek, _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1), _Slave_Ports_queue.peek());
+//   _Slave_Ports_queue_peek =  _Slave_Ports_queue.peek() ; 
+   //_Slave_Ports_queue_push =  _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1) ; 
+  // _Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ; 
+//_Slave_Ports_queue__add(  Slave_Ports_Status_QUEUE_A, 0x03 ,0x00 ,100, 5000, _Slave_Ports_queue_peek, 
+//_Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1),
+//_Slave_Ports_queue.peek());
+
+ Serial.println("#301 _Slave_Ports_queue__list");
+_Slave_Ports_queue__list(Slave_Ports_Status_QUEUE_A);
+Serial.print("#304 _Slave_Ports_queue.count(), "); Serial.println(_Slave_Ports_queue.count());
+  
+   
+ //  _Slave_Ports_queue__add(  Slave_Ports_Status_QUEUE_A, 0x03 ,0x00 ,100, 5000 ) ;  
+ //Serial.println("#323 _Slave_Ports_queue__list"); _Slave_Ports_queue__list(Slave_Ports_Status_QUEUE_A);
+// Serial.print("#324 _Slave_Ports_queue.count(), "); Serial.println(_Slave_Ports_queue.count());

+ 3 - 1
SE/stuff/P5_Automation_can-dev-res/config_Active_ControllerID.h

@@ -1,6 +1,8 @@
 #define Active_ControllerID _ControllerID 
-
+#define Active_ControllerID _Slave1_ID 
 
 #define HAS_TFT_ILI9163C 
 // #define HAS_LCD1602 
 #define HAS_ROTTARY_SW
+
+#define HAS_I2C_driver_Adafruit_PWMServoDriver

+ 0 - 0
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_LOCAL.h → SE/stuff/P5_Automation_can-dev-res/config_Slave_Ports_LOCAL_init.h