a.binder %!s(int64=5) %!d(string=hai) anos
pai
achega
83a716d455

+ 3 - 2
SE/stuff/P5_Automation_can-dev-res/P5_Automation_can-dev-res.ino

@@ -82,6 +82,7 @@
 //#define HAS_ROTTARY_SW
 
 //#define DEBUG_I2C_driver_Adafruit_PWMServoDriver
+//#define DEBUG_CAN
 
 //#define HAS__PCINT_setup //to allow interrupts
 
@@ -549,8 +550,8 @@ void loop() {
               #endif
 }
  // Serial.println(time);
-      #include "_SlaveID_loop1.h" //todo PCINT
-      #include "_ControllerID_loop1.h"  //todo make default
+      #include "___loop/_SlaveID_loop1.h" //todo PCINT
+      #include "___loop/_ControllerID_loop1.h"  //todo make default
   
   #include "___loop/__main_loop_end.h"
   // DISPLAY_DEV.setCursor(10,10);

+ 27 - 1
SE/stuff/P5_Automation_can-dev-res/_CAN_setup.h

@@ -1,11 +1,20 @@
  //if(CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
+
+#ifdef DEBUG_CAN || DEBUG
+    Serial.print("#44 _CAN_setup.h will CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK ");
+#endif
+
   if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
      /* TODO 
      LCDarray1="MCP2515 Init Okay";
      LCDarray2="500KBPS 16MHZ";
      Serial.print(LCDarray1 + LCDarray2);
      */
-   
+            
+         #ifdef DEBUG_CAN || DEBUG
+             Serial.print("       [CAN_OK]   ");
+         #endif
+
     #if defined(HAS_LCD1602)
      /* TODO
       LCD_print(LCDarray1, LCDarray2, LCDtim/5);
@@ -19,6 +28,12 @@
       */ 
     #endif
   } else { 
+  
+          #ifdef DEBUG_CAN || DEBUG
+             Serial.print("  #33     [CAN_ERROR]   ");
+         #endif
+
+  
     /* TODO LCDarray1 = "MCP2515 Init Failed";
      LCDarray2 = "CAN_CSpin: "; 
      LCDarray2.concat(CAN_CSpin);  
@@ -66,7 +81,18 @@
           delay(LCDtim);
           */ 
          #endif
+         
+          #ifdef DEBUG_CAN || DEBUG
+             Serial.print("  #366 will    [CAN0.setMode(MCP_NORMAL)]   ");
+         #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
 
+         #ifdef DEBUG_CAN || DEBUG
+             Serial.println("  #94 EOF   MCP can setup.  ");
+         #endif
+
+
   //EOF CAN

+ 1 - 1
SE/stuff/P5_Automation_can-dev-res/_DISPLAY_struct.h

@@ -90,7 +90,7 @@ typedef struct ARDUINO_ARRAY_INDEX_T_TO_DELETE_S   DISPLAY_ARDUINO_ARRAY_INDEX_T
  
  
  const DISPLAY_CURSOR_Y_CHARS_T DISPLAY_CURSOR_Y_CHARS_DEBUG = 10 ; //todo 10 linia do debugu??
- 
+ const DISPLAY_CURSOR_Y_CHARS_T DISPLAY_CURSOR_Y_CHARS_CAN_DEBUG = 11 ; //todo 10 linia do debugu?? CAN
  
  
 

+ 2 - 2
SE/stuff/P5_Automation_can-dev-res/_ROTTARY_SW/_ROTTARY_SW_loop.h

@@ -31,11 +31,11 @@ DISPLAY__CURSOR_Y_CHARS__SET(DISPLAY_PHYSICAL_CHAR_A,
                           DISPLAY_A ,
                           DISPLAY_T_ARDUINO_ATTR_ARRAY_A , 
                           DISPLAY_PHYSICAL_CHAR_A, 
-                           DISPLAY_pos_seq_A_NEXT,
+                           DISPLAY_pos_seq_A_NEXT + DISPLAY_pos_seq_A_IMMEDIATE,
                             DISPLAY_array16_AA,
                             DISPLAY_TARGET_DISPLAY128,
                            millis() , // time_seq_id_T time_seq_id_A;
-                           millis(), //time_min_run_T time_min_run_A;
+                           millis()+5000, //time_min_run_T time_min_run_A;
                           //queue
                          Slave_Ports_Status_QUEUE_A,
                          TASK_TYPE_T_Slave_Ports_broadcast____  ,  //TASK_TYPE_A,

+ 22 - 3
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_Protocol_CAN_struct.h

@@ -14,7 +14,7 @@ typedef int _LOCAL_Controller_ID_T ;
 typedef int _CAN_SENDER_ID_T ; 
 typedef int _CAN_REMOTE_ID_T ; 
 
-
+const int _CAN_8_EMPTY = 0x07 ;
 //#define _Slave_ID_BROADCAST_T  _Slave_ID_BROADCAST  0xFF ; 
 
  #if ! defined(Active_ControllerID)
@@ -39,7 +39,7 @@ typedef int _CAN_REMOTE_ID_T ;
   Exp_state_T  Exp_state;    //5
   int  Exp_state_ttl;  //6
   int  Broadcast_state;  //7
-  const int _CAN_8 = 0x07 ; //8 - nbot used
+  const int _CAN_8 = _CAN_8_EMPTY  ; //0x07 ; //8 - nbot used
 } ;
  
  
@@ -54,7 +54,7 @@ typedef int _CAN_REMOTE_ID_T ;
   Exp_state_T  Exp_state;    //5
   int  Exp_state_ttl;  //6
   int  Broadcast_state;  //7
-  const int _CAN_8 = 0x07 ; //8 - nbot used
+  const int _CAN_8 = _CAN_8_EMPTY; //0x07 ; //8 - nbot used
 } ;
 
  
@@ -75,3 +75,22 @@ typedef int _CAN_SEND_2_T  ; //2 byte = 8
 
 typedef  byte _Slave_Ports_Protocol_CAN_broadcast_AS[8]  ;
 
+byte CAN_broadcast_to_data(_Slave_Ports_Protocol_CAN_broadcast_T 
+            &_Slave_Ports_Protocol_CAN_broadcast_A) {
+        //_Slave_Ports_Protocol_CAN_broadcast_AS
+       _Slave_Ports_Protocol_CAN_broadcast_AS  return_c[8] = {
+                       // 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07
+                         byte(_Slave_Ports_Protocol_CAN_broadcast_A._CAN_SENDER_ID),
+                         byte(_Slave_Ports_Protocol_CAN_broadcast_A._CAN_REMOTE_ID),
+                         byte(_Slave_Ports_Protocol_CAN_broadcast_A.Port_ID),
+                         byte(_Slave_Ports_Protocol_CAN_broadcast_A.PortTypes),
+                         byte(_Slave_Ports_Protocol_CAN_broadcast_A.Exp_state),
+                         byte(_Slave_Ports_Protocol_CAN_broadcast_A.Exp_state_ttl),
+                         byte(_Slave_Ports_Protocol_CAN_broadcast_A.Broadcast_state),
+                         byte(_Slave_Ports_Protocol_CAN_broadcast_A._CAN_8)
+                        
+                      } ;
+        
+        return return_c;
+        
+}

+ 60 - 6
SE/stuff/P5_Automation_can-dev-res/_Slave_Ports_broadcast_func.h

@@ -30,7 +30,7 @@
           int i;
           for(i=ARDUINO_ARRAY_INDEX_FIRST;i<=Slave_Ports_Status_T_ARDUINO_ATTR_ARRAY_A.ARDUINO_ARRAY_INDEX_CURRENT_A;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) {
-            #if defined(DEBUG)
+            #ifdef DEBUG || DEBUG_CAN
                 if(DEBUG > 4) {
                     Serial.print(" ind:"); Serial.print(i);  Serial.print("] IS_Local_A:");
                     Serial.print(Slave_Ports_Status_A[i].IS_Local_A);
@@ -49,11 +49,13 @@
                          //message.concat(Slave_Ports_Status_A[i].Port_ID);
                          //DISPLAY_array16_T  DISPLAY_array16_AAT ;
                          //message.toCharArray(DISPLAY_array16_AAT, message.length());
+                           DISPLAY__CURSOR_Y_CHARS__SET(DISPLAY_PHYSICAL_CHAR_A, 
+                                DISPLAY_CURSOR_Y_CHARS_CAN_DEBUG);
                   DISPLAY__print(
                           DISPLAY_A ,
                           DISPLAY_T_ARDUINO_ATTR_ARRAY_A , 
                           DISPLAY_PHYSICAL_CHAR_A, 
-                           DISPLAY_pos_seq_A_NEXT,
+                           DISPLAY_pos_seq_A_NEXT + DISPLAY_pos_seq_A_IMMEDIATE,
                             DISPLAY_array16_I( "#53 BCAST  " + char( Slave_Ports_Status_A[i].Port_ID  ) , 2), //message,
                             DISPLAY_TARGET_DISPLAY128,
                            millis() , // time_seq_id_T time_seq_id_A;
@@ -80,16 +82,68 @@
                   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);
+                
+                
+                
+                DISPLAY__CURSOR_Y_CHARS__SET(DISPLAY_PHYSICAL_CHAR_A, 
+                                DISPLAY_CURSOR_Y_CHARS_CAN_DEBUG);
+          DISPLAY_array16_T  DISPLAY_array16_AA="" ;
+          //( "OUT I2C 0X40[2]" + encoderPos * 5 , 2), //message,          
+          _Slave_Ports_Protocol_CAN_broadcast_T CAN_broadcast_A={};
+               // CAN_broadcast_A._CAN_REMOTE_ID = _CAN_REMOTE_ID_BROADCAST ;
+               // CAN_broadcast_A._CAN_SENDER_ID = Active_ControllerID ;
+                CAN_broadcast_A.Port_ID = Slave_Ports_Status_A[i].Port_ID ;
+                CAN_broadcast_A.PortTypes = Slave_Ports_Status_A[i].PortTypes ; 
+                CAN_broadcast_A.Exp_state = Slave_Ports_Status_A[i].Exp_state ;  
+                CAN_broadcast_A.Exp_state_ttl = Slave_Ports_Status_A[i].Exp_state_ttl ;
+                CAN_broadcast_A.Broadcast_state = Slave_Ports_Status_A[i].Broadcast_state ;
+                
+               // CAN_broadcast_A._CAN_8 = _CAN_8_EMPTY ;
+                
+                  
+                
+          String message = "CAN BCAST "; message.concat(i); message.concat(".");  message.concat(Slave_Ports_Status_A[i].Port_ID);  message.concat(" >>>"); 
+              
+                  message.toCharArray(DISPLAY_array16_AA, message.length());
+                     DISPLAY__print(
+                          DISPLAY_A ,
+                          DISPLAY_T_ARDUINO_ATTR_ARRAY_A , 
+                          DISPLAY_PHYSICAL_CHAR_A, 
+                           DISPLAY_pos_seq_A_NEXT,
+                            DISPLAY_array16_AA,
+                            DISPLAY_TARGET_DISPLAY128,
+                           millis() , // time_seq_id_T time_seq_id_A;
+                           millis()+5000, //time_min_run_T time_min_run_A;
+                          //queue
+                         Slave_Ports_Status_QUEUE_A,
+                         TASK_TYPE_T_Slave_Ports_broadcast____  ,  //TASK_TYPE_A,
+                         {  } //TASK_PORT_ASSOC_A Slave_Ports_Status_A[i].Port_ID
+                         
+                         ); 
+                
+                
+                
+                
+                
+                
+                
+                
+             //    byte sndStat = CAN0.sendMsgBuf(Slave_Ports_Status_A[i].Port_ID, 0, 8, data);
+                 //byte CAN_broadcast_A8[8];
+             byte    CAN_broadcast_A8 = CAN_broadcast_to_data(CAN_broadcast_A);
+                
+                 byte sndStat = CAN0.sendMsgBuf(Active_ControllerID, 0, 8, CAN_broadcast_A8);
               //    byte sndStat ;
                           if(sndStat == CAN_OK){
                             Serial.println("#921 Message Sent Successfully!");
                              //String LCDarray1 = "Message Sent";
                              //String LCDarray2 = "Successfully";
+                              DISPLAY__CURSOR_Y_CHARS__SET(DISPLAY_PHYSICAL_CHAR_A, 
+                                DISPLAY_CURSOR_Y_CHARS_CAN_DEBUG);
                               DISPLAY__print( DISPLAY_A ,
                                                DISPLAY_T_ARDUINO_ATTR_ARRAY_A , 
                                                DISPLAY_PHYSICAL_CHAR_A, 
-                                                DISPLAY_pos_seq_A_NEXT,
+                                                DISPLAY_pos_seq_A_NEXT + DISPLAY_pos_seq_A_IMMEDIATE,
                                                  DISPLAY_array16_I( "#92MSG Sent OK " + char( Slave_Ports_Status_A[i].Port_ID  ) , 2), //message,
                                                  DISPLAY_TARGET_DISPLAY128,
                                                 millis() , // time_seq_id_T time_seq_id_A;
@@ -100,11 +154,11 @@
                                               { Slave_Ports_Status_A[i].Port_ID } //TASK_PORT_ASSOC_A
                                               ); 
                           } else {
-                            Serial.println("Error Sending Message...");
+                            Serial.print("Error Sending Message...  [");    Serial.print(sndStat);  Serial.println("]   "); 
                             DISPLAY__print( DISPLAY_A ,
                                                DISPLAY_T_ARDUINO_ATTR_ARRAY_A , 
                                                DISPLAY_PHYSICAL_CHAR_A, 
-                                                DISPLAY_pos_seq_A_NEXT,
+                                                DISPLAY_pos_seq_A_NEXT + DISPLAY_pos_seq_A_IMMEDIATE,
                                                  DISPLAY_array16_I( "#107MSG ERROR " + char( Slave_Ports_Status_A[i].Port_ID  ) , 2), //message,
                                                  DISPLAY_TARGET_DISPLAY128,
                                                 millis() , // time_seq_id_T time_seq_id_A;

+ 3 - 1
SE/stuff/P5_Automation_can-dev-res/___CONFIG/0x101/config_Active_ControllerID_0x101.h

@@ -12,4 +12,6 @@
 //#define DISABLE_LOOP //To debug and disable any output
 
 #define DEBUG_I2C
-//#define HAS_DEBUG_ACTION_TRIG
+//#define HAS_DEBUG_ACTION_TRIG
+
+#define DEBUG_CAN

+ 0 - 0
SE/stuff/P5_Automation_can-dev-res/_ControllerID_loop1.h → SE/stuff/P5_Automation_can-dev-res/___loop/_ControllerID_loop1.h


+ 0 - 0
SE/stuff/P5_Automation_can-dev-res/_SlaveID_loop1.h → SE/stuff/P5_Automation_can-dev-res/___loop/_SlaveID_loop1.h