a.binder преди 5 години
родител
ревизия
baa461cad7
променени са 2 файла, в които са добавени 446 реда и са изтрити 0 реда
  1. 246 0
      SE/stuff/Slave_Ports_Status/Slave_Ports_Status.cpp
  2. 200 0
      SE/stuff/Slave_Ports_Status/Slave_Ports_Status.h

+ 246 - 0
SE/stuff/Slave_Ports_Status/Slave_Ports_Status.cpp

@@ -0,0 +1,246 @@
+#include "Slave_Ports_Status.h"
+
+/*Slave_Ports_Status::Slave_Ports_Status(Client& client) : m_client(client) {
+    m_accountName = NULL;
+    m_appKeyName = NULL;
+    m_appKeyValue = NULL;
+    m_path = NULL;
+    m_nextChar = NULL;
+    m_nextState = END;
+}
+*/
+
+/*
+Slave_Ports_Status::Slave_Ports_Status(Client& client) : m_client(client) {
+    m_accountName = NULL;
+    m_appKeyName = NULL;
+    m_appKeyValue = NULL;
+    m_path = NULL;
+    m_nextChar = NULL;
+    m_nextState = END;
+}
+*/
+/*
+
+void Slave_Ports_Status::push() { //
+
+
+}
+*/
+
+
+
+Slave_Ports_Status::Slave_Ports_Status(){
+    Serial.print("#35 Slave_Ports_Status::Slave_Ports_Status():");
+    _count = 0 ;
+   Slave_Ports_Status_T Slave_Ports_Status_A[10];
+   // Slave_Ports_Status_QUEUE_T Slave_Ports_Status_QUEUE_A[10] ;
+    //_queue_id_current = 0 ;
+    //_queue_count = 0;
+}
+
+
+
+/*
+inline int Slave_Ports_Status::add(Slave_Ports_Status_T item)
+{
+  
+  Serial.print("Add item...  _count["); Serial.print(item.Port_ID);
+  
+   Serial.print("] 0 ["); Serial.print(item.Port_ID);
+   Serial.print("1 ["); Serial.print(item._Slave_ID);
+   Serial.print("2 ["); Serial.print(item.PortTypes);
+   Serial.print("3 ["); Serial.print(item.Address);
+   Serial.print("4 ["); Serial.print(item.LocalPort);
+   Serial.print("5 ["); Serial.print(item.Exp_state);
+   Serial.print("6 ["); Serial.print(item.Exp_state_ttl);
+   Serial.print("7 ["); Serial.print(item.Broadcast_state);
+   Serial.println("]"); 
+   
+   return 1 ;
+}
+*/
+
+
+ 
+/*
+  void Slave_Ports_Status::I2C_driver_FS(int  I2C_driver) { //char*
+  
+   
+    // Serial.print("I2C_driver_FS[");
+     //Serial.print(I2C_driver_F(_NOT_USED_));
+     if(I2C_driver_NOT_USED_  == I2C_driver) {
+       Serial.println("_NOT_USED_");
+                       
+      // I2C_driver_FT =  "_NOT_USED______________";
+       //return  "_NOT_USED______________";
+     }
+       else if( I2C_driver_Adafruit_PWMServoDriver == I2C_driver) {
+       Serial.println("Adafruit_PWMServoDriver");
+                       //12345678901234567890134
+     //   I2C_driver_FT = "Adafruit_PWMServoDriver";
+      // return  "Adafruit_PWMServoDriver";
+     } else {
+        Serial.print("_UNKNOWN_");
+       //  I2C_driver_FT = "_UNKNOWN_______________";
+      //  return  "_UNKNOWN_______________";
+     }
+   
+     
+ // sprintf(I2C_driver_FT, "%02d", 1);
+ // return I2C_driver_FT;
+ }
+ 
+*/
+
+
+ void Slave_Ports_Status::add_port(
+                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
+                )
+{
+  
+  Serial.print("#112 add_port   _count[");
+   Serial.print(this->_count);
+   Serial.print("]  _count + 1["); Serial.print(this->_count + 1);
+   Serial.print("] Port_ID["); Serial.print(Port_ID);
+   Serial.print("] _Slave_ID[0x"); Serial.print( _Slave_ID);
+   Serial.print("] PortTypes["); Serial.print(PortTypes);
+   Serial.print("] Address["); Serial.print(Address);
+   Serial.print("] LocalPort["); Serial.print(LocalPort);
+   Serial.print("] Exp_state["); Serial.print(Exp_state);
+//   Serial.print("] Exp_state_ttl["); Serial.print(Exp_state_ttl);
+//   Serial.print("] Broadcast_state["); Serial.print(Broadcast_state);
+//   Serial.print("] I2C_port["); Serial.print(I2C_port);
+ //  Serial.print("] I2C_driver["); I2C_driver_FS(I2C_driver);
+   //Serial.print("] I2C_driver_Rev["); 
+      //unsigned char LCDarray1buf[24];
+      //LCDarray1.toCharArray(LCDarray1buf, 24);
+  //  I2C_driver_FT[24]  =   I2C_driver_FS(I2C_driver_F(I2C_driver)) ;
+   Serial.println("]"); 
+    //Slave_Ports_Status_A[_count + 1].Port_ID = Port_ID ;
+    
+    if(this->_count == 0) {
+    
+     this->Slave_Ports_Status_A[_count ].Port_ID=0x00;
+     this->Slave_Ports_Status_A[_count ]._Slave_ID=0x00;
+     this->Slave_Ports_Status_A[_count ].PortTypes=0x00;
+     this->Slave_Ports_Status_A[_count ].Address=0x00;
+     this->Slave_Ports_Status_A[_count ].LocalPort=0x00;
+     this->Slave_Ports_Status_A[_count ].Exp_state=0x00;
+     this->Slave_Ports_Status_A[_count ].Exp_state_ttl=0x00;
+     this->Slave_Ports_Status_A[_count ].Broadcast_state=0x00;
+     this->Slave_Ports_Status_A[_count ].I2C_port=0x00;
+     this->Slave_Ports_Status_A[_count ].I2C_driver=0x00;
+     //_count ++;
+     
+     this->_count ++;
+    /* Slave_Ports_Status::add_port(
+                  Port_ID,
+                  _Slave_ID,
+                  PortTypes,
+                  Address,
+                  LocalPort,
+                  Exp_state,
+                  Exp_state_ttl,
+                  Broadcast_state,
+                 I2C_port,
+                 I2C_driver
+                );
+     */
+    }
+    
+    this->Slave_Ports_Status_A[_count + 1].Port_ID = Port_ID ;
+    this->Slave_Ports_Status_A[_count + 1]._Slave_ID = _Slave_ID ;
+    this->Slave_Ports_Status_A[_count + 1].PortTypes = PortTypes ;
+    this->Slave_Ports_Status_A[_count + 1].Address = Address ;
+    this->Slave_Ports_Status_A[_count + 1].LocalPort = LocalPort ;
+    this->Slave_Ports_Status_A[_count + 1].Exp_state = Exp_state ;
+    this->Slave_Ports_Status_A[_count + 1].Exp_state_ttl = Exp_state_ttl ;
+    this->Slave_Ports_Status_A[_count + 1].Broadcast_state = Broadcast_state ;
+    this->Slave_Ports_Status_A[_count + 1].I2C_port = I2C_port ;
+    this->Slave_Ports_Status_A[_count + 1].I2C_driver = I2C_driver ;
+//    Slave_Ports_Status_A[_count + 1].I2C_driver = I2C_driver_F(I2C_driver) ;
+    this->_count ++;
+  
+}
+
+
+bool Slave_Ports_Status::add_empty()
+{
+  Serial.println("add_empty");
+}
+
+
+void Slave_Ports_Status::list_ports()
+{
+  Serial.print("print_ports#154   _count["); Serial.print(_count); Serial.println("] ");
+    int i;
+    for(i=2;i<=_count;i++) {
+ 
+         Serial.print(" #IND["); Serial.print(i); 
+         Serial.print("] Port_ID["); Serial.print(Slave_Ports_Status_A[i].Port_ID, HEX);
+         Serial.print("] _Slave_ID[0x"); Serial.print( Slave_Ports_Status_A[i]._Slave_ID, HEX );
+         Serial.print("] PortTypes["); Serial.print(Slave_Ports_Status_A[i].PortTypes, HEX);
+      //   Serial.println("] Address [");
+         Serial.print("] Address["); //Serial.print(Slave_Ports_Status_A[i].Address, HEX);
+         Serial.print("] LocalPort["); Serial.print(Slave_Ports_Status_A[i].LocalPort);
+         Serial.print("] Exp_state["); Serial.print(Slave_Ports_Status_A[i].Exp_state, HEX);
+        Serial.print("] Exp_state_ttl["); Serial.print(Slave_Ports_Status_A[i].Exp_state_ttl, HEX);
+         Serial.print("] Broadcast_state["); Serial.print(Slave_Ports_Status_A[i].Broadcast_state, HEX);
+         Serial.print("] I2C_port["); Serial.print(Slave_Ports_Status_A[i].I2C_port, HEX);
+      //   Serial.print("] I2C_driver[");   Serial.print(Slave_Ports_Status_A[i].I2C_driver.CNF1);
+         
+          // I2C_driver_FT[24]  = I2C_driver_FS(Slave_Ports_Status_A[i].I2C_driver);
+          //  Serial.print(I2C_driver_FT[24]);
+         Serial.println("]"); 
+         
+         
+   }
+   
+   
+}
+
+/*
+
+Slave_Ports_Status_S Slave_Ports_Status::get_port(int  Port_ID)
+{
+ // Serial.print("list_ports#154   _count["); Serial.print(_count); Serial.println("] ");
+    //int i;
+    //for(i=2;i<=_count;i++) {
+        return Slave_Ports_Status_A[Port_ID];         
+         
+  // }
+   //return Slave_Ports_Status_A;
+}
+
+
+*/
+
+Slave_Ports_Status::~Slave_Ports_Status(){
+     delete[] Slave_Ports_Status_A;
+    //Serial.print("#40 free ~Slave_Ports_Status");
+}
+
+/*
+int Slave_Ports_Status::get_count()
+    {
+            return _count;         
+    }
+
+*/
+
+/*
+ byte Slave_Ports_Status::_Slave_Ports_Protocol_CAN_broadcast_F() {
+}
+*/
+

+ 200 - 0
SE/stuff/Slave_Ports_Status/Slave_Ports_Status.h

@@ -0,0 +1,200 @@
+
+#ifndef SLAVE_PORTS_STATUS_H
+#define SLAVE_PORTS_STATUS_H
+
+
+
+
+
+ #define    I2C_driver_NOT_USED_  0x00
+ #define    I2C_driver_Adafruit_PWMServoDriver    0x01
+
+
+
+#include <Arduino.h>
+
+
+            
+            #ifndef voidfuncptr_t
+            #define voidfuncptr_t voidfuncptr_t
+            typedef void (*voidfuncptr_t)(void); // void function pointer typedef
+            #endif
+            
+            
+            
+            #ifndef vfp_vpu32b_t
+            #define vfp_vpu32b_t vfp_vpu32b_t
+            typedef void (*vfp_vpu32b_t)(void*, uint32_t, bool);
+            #endif
+
+
+typedef struct
+{
+  uint8_t CNF1;
+} I2C_driver_T;
+
+
+static I2C_driver_T constexpr _NOT_USED_  = {0x00};
+static I2C_driver_T constexpr Adafruit_PWMServoDriver  = {0x01};
+
+/*
+typedef struct  {
+   char I2C_driver_TA[32];
+} I2C_driver_TS ;
+*/
+//typedef struct I2C_driver_TS I2C_driver_TT;
+
+
+//I2C_driver_TS I2C_driver_AA = { "_NOT_USED_" };
+                                
+//I2C_driver_AA[0] =  "_NOT_USED_" ;
+//I2C_driver_AA[0x01] =  "Adafruit_PWMServoDriver" ; 
+
+
+
+ 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 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
+  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;
+
+/*
+enum class Mode : uint8_t
+{
+  Normal     = 0x00,
+  Sleep      = 0x20,
+  Loopback   = 0x40,
+  ListenOnly = 0x60,
+  Config     = 0x80
+};
+
+
+*/
+
+
+  //char I2C_driver_FT[32] ;
+ static char I2C_driver_FT[24];
+
+
+
+
+
+#include "Slave_Ports_Status_QUEUE.h"
+
+
+
+
+
+class Slave_Ports_Status
+{
+
+
+//private:
+    
+  
+  
+    
+//public:
+  //  static Slave_Ports_Status *first;
+    //static Slave_Ports_Status *_data;
+public:
+        int _count;
+        
+        
+         //   int _queue_id_current  ;
+         //   int _queue_count ;
+            
+            
+         Slave_Ports_Status_T *Slave_Ports_Status_A;
+         //Slave_Ports_Status_QUEUE_T *Slave_Ports_Status_QUEUE_A ;
+       
+       
+        //  void push(Slave_Ports_Status_S const &item);
+          //void push();
+          //Slave_Ports_Status();
+          //  bool setMode();
+          //voidfuncptr_t func;					// address of coroutine function
+          Slave_Ports_Status();
+          
+          
+         
+          
+         /* inline int add(
+            Slave_Ports_Status_LIST_T Slave_Ports_Status_LIST_A , 
+            Slave_Ports_Status_T Slave_Ports_Status_A
+            ) {
+            };
+            */
+          void add_port(
+                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
+                //I2C_driver_T I2C_driver
+                );
+          bool add_empty();
+          void print_ports();
+          void list_ports();
+        //  Slave_Ports_Status_S get_port(int Port_ID);
+        //  int get_count();
+           
+           
+          // void I2C_driver_FS(int  I2C_driver) ;//char*
+           
+           // byte _Slave_Ports_Protocol_CAN_broadcast_F();
+           
+          ~Slave_Ports_Status();
+                    
+          
+       //   int queue__add_A(Slave_Ports_Status_QUEUE_T QUEUE_A);
+       //   int queue__add(TASK_TYPE_T, long int, long int);
+
+};
+
+
+#endif