_Slave_Ports.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. //#include "_Slave_Ports_ttl_decrement.h"
  2. typedef struct {
  3. const char * const _Protocol;
  4. int _Slave_ID; //remote id - use FF for broadcast
  5. int PortTypes; //0xFF = 1111 1111 s
  6. /*
  7. {
  8. bit 1 - PWM port
  9. bit 2 - on I2C managed port
  10. bit 3 - expanded port with LocalPort address
  11. bit 4 - not allocated
  12. bit 2 - not allocated
  13. bit 5 - not allocated
  14. bit 6 - not allocated
  15. bit 7 - not allocated
  16. bit 8 - not allocated
  17. }
  18. */
  19. // byte has_Address;
  20. int Address ;
  21. // byte has_Local_Port;
  22. int LocalPort;
  23. int Exp_state; /*0xFF = 1111 1111
  24. 0x00 = 0000 0000 = OFF = 0V
  25. 0x01 = 0000 0001 = ON = PWM max
  26. {
  27. bit 1 - OFF = 0V
  28. bit 2 - ON = PWM max
  29. bit 3 - not allocated
  30. bit 4 - not allocated
  31. bit 2 - not allocated
  32. bit 5 - not allocated
  33. bit 6 - not allocated
  34. bit 7 - not allocated
  35. bit 8 - not allocated
  36. }*/
  37. int Exp_state_ttl; // 0x00 = odswiezyc
  38. int Broadcast_state; //0x00 - not broadcast; 0x01
  39. } _Slave_Port;
  40. /*
  41. *
  42. _Slave_Port _Slave_Ports[] = {
  43. {"CAN", 0x102, 0x01, 0x00, 0x00, 0x00, 0x00 }
  44. //,
  45. //{"CAN", 0x102, 0x01, 0x00, 0x01, 0xFF, 0x6d } //testowy ttl
  46. };
  47. */
  48. #include "_Slave_Ports_LOCAL.h"
  49. struct _Slave_Ports_queue_tasksS {
  50. int queueID;
  51. int _Slave_Ports_queue_task_type ; /*
  52. { 0x01 _Slave_Ports_ttl_decrement,
  53. 0x02 request_confirm_Exp_state ,
  54. 0x03 request_set_new_Exp_state,
  55. 0x04
  56. }
  57. */
  58. int _Slave_Port_link; //todo link
  59. long time_seq_id;
  60. long time_min_run;
  61. } ;
  62. typedef struct _Slave_Ports_queue_tasksS _Slave_Ports_queue_tasksT;
  63. _Slave_Ports_queue_tasksT _Slave_Ports_queue_tasks_LIST[11];
  64. void _Slave_Ports_queue__INIT( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST) {
  65. Serial.println("_Slave_Ports_queue__INIT");
  66. int i;
  67. for(i=0;i<10;i++) {
  68. _Slave_Ports_queue_tasks_LIST[i].queueID = 0;
  69. _Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type = 0x00;
  70. _Slave_Ports_queue_tasks_LIST[i]._Slave_Port_link = 0x00;
  71. _Slave_Ports_queue_tasks_LIST[i].time_seq_id = 0;
  72. _Slave_Ports_queue_tasks_LIST[i].time_min_run = 0;
  73. // _Slave_Ports_queue_tasks_LIST[i]=_Slave_Ports_queue_tasks_LIST[i];
  74. }
  75. }
  76. void _Slave_Ports_queue_task_type_DESC( int _Slave_Ports_queue_task_type ) {//, int* res
  77. /* if(_Slave_Ports_queue_task_type == 0x01) res=0x99; //res="_Slave_Ports_ttl_decrement";
  78. else if(_Slave_Ports_queue_task_type == 0x02) res=0x99; //res="request_confirm_Exp_state";
  79. else if(_Slave_Ports_queue_task_type == 0x03) res=0x99; //res="request_set_new_Exp_state";
  80. else {
  81. res=0x99; // res="_UNKNOIWN";
  82. Serial.print("#82 Get ["); Serial.print(_Slave_Ports_queue_task_type); Serial.println("] #82 [U] ");
  83. }
  84. *//*
  85. // char return_i;
  86. Serial.print("=["); Serial.print(_Slave_Ports_queue_task_type); Serial.print("] ");
  87. if(_Slave_Ports_queue_task_type == 0x01) Serial.print("_Slave_Ports_ttl_decrement"); // return "_Slave_Ports_ttl_decrement";
  88. else if(_Slave_Ports_queue_task_type == 0x02) Serial.print("request_confirm_Exp_state"); //return "request_confirm_Exp_state";
  89. else if(_Slave_Ports_queue_task_type == 0x03) Serial.print("request_set_new_Exp_state"); //return "request_set__new_Exp_state";
  90. else //return_i = "_UNKNOIWN"; //return "_UNKNOIWN";
  91. Serial.print("_UNKNOIWN");
  92. // Serial.print((String)return_i);
  93. // return return_i ;
  94. */
  95. //Serial.print(_Slave_Ports_queue_task_type[_Slave_Ports_queue_task_type]);
  96. Serial.print(_Slave_Ports_queue_task_type_LIST[_Slave_Ports_queue_task_type]);
  97. // String ret = "aaaaxxx";
  98. //return ret;
  99. }
  100. //Queue<_Slave_Ports_queueT> _Slave_Ports_queue = Queue<_Slave_Ports_queueT>(5);
  101. void _Slave_Ports_queue__list( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST) {
  102. int i;
  103. Serial.println("#100 _Slave_Ports_queue_tasks_LIST): ");
  104. //Serial.println(sizeof(_Slave_Ports_queue_tasks_LIST));
  105. for(i=0;i<=10;i++) { //sizeof(_LCD_print_buffors)
  106. 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 ) {
  107. } else {
  108. Serial.print(" $i[");
  109. Serial.print(i);
  110. Serial.print("] queueID: ");
  111. Serial.print(_Slave_Ports_queue_tasks_LIST[i].queueID);
  112. Serial.print("] _Slave_Ports_queue_task_type: ");
  113. Serial.print(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type);
  114. Serial.print("] desc: ");
  115. //Slave_Ports_queue_task_type_DESC(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type);
  116. //char res;
  117. // res = _Slave_Ports_queue_task_type_DESC(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type); Serial.print(res);
  118. _Slave_Ports_queue_task_type_DESC(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type);
  119. Serial.print(" - map["); Serial.print(_Slave_Ports_queue_task_type_LIST[_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type]); Serial.print("]");
  120. // 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
  121. Serial.print("] _Slave_Port_link: ");
  122. Serial.print(_Slave_Ports_queue_tasks_LIST[i]._Slave_Port_link);
  123. Serial.print("] time_seq_id: ");
  124. Serial.print(_Slave_Ports_queue_tasks_LIST[i].time_seq_id);
  125. Serial.print("] time_min_run: ");
  126. Serial.println(_Slave_Ports_queue_tasks_LIST[i].time_min_run);
  127. }
  128. }
  129. }
  130. /*
  131. struct _Slave_Ports_queue_tasksS {
  132. int queueID;
  133. int _Slave_Ports_queue_task_type ; /*
  134. { 0x01 _Slave_Ports_ttl_decrement,
  135. 0x02 request_confirm_Exp_state ,
  136. 0x03 request_set_new_Exp_state,
  137. 0x04 _Slave_Ports_ttl_decrement }
  138. int _Slave_Port_link; //todo link
  139. long time_seq_id;
  140. long time_min_run;
  141. } ;
  142. */
  143. 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 //,
  144. //int _Slave_Ports_queue_peek , int _Slave_Ports_queue_push , int _Slave_Ports_queue_peek_new
  145. ) {
  146. Serial.println(".");
  147. Serial.print("#152 _Slave_Ports_queue__add peek: [");
  148. int _Slave_Ports_queue_peek = _Slave_Ports_queue.peek() ;
  149. int _Slave_Ports_queue_back = _Slave_Ports_queue.back() ;
  150. // int _Slave_Ports_queue_push_new_ref;
  151. // if(_Slave_Ports_queue_back > _Slave_Ports_queue_peek)
  152. Serial.print(_Slave_Ports_queue_peek); Serial.print("] cur back["); Serial.print(_Slave_Ports_queue_back); Serial.print("] ");
  153. _Slave_Ports_queue.push(_Slave_Ports_queue_back + 1);
  154. int _Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ;
  155. // int _Slave_Ports_queue__push = _Slave_Ports_queue__peek + 1 ;
  156. Serial.print("] new peek[");
  157. Serial.print(_Slave_Ports_queue_peek_new ); Serial.print("] planned["); Serial.print(_Slave_Ports_queue_back + 1 );
  158. Serial.print("] front["); Serial.print(_Slave_Ports_queue.front()); Serial.print("] back["); Serial.print(_Slave_Ports_queue.back()); Serial.println("] ");
  159. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ].queueID=_Slave_Ports_queue_back + 1 ;
  160. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ]._Slave_Ports_queue_task_type=_Slave_Ports_queue_task_type ;
  161. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ]._Slave_Port_link=_Slave_Port_link ;
  162. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ].time_seq_id=time_seq_id ;
  163. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ].time_min_run=time_min_run ;
  164. }
  165. /*
  166. void _Slave_Ports_queue__add(const _Slave_Ports_queue_tasksT* &_Slave_Ports_queue_tasks_LIST ,
  167. int _Slave_Ports_queue_task_type, int _Slave_Port_link, long time_seq_id, long time_min_run //,
  168. //int _Slave_Ports_queue_peek , int _Slave_Ports_queue_push , int _Slave_Ports_queue_peek_new
  169. ) {
  170. Serial.print("#152 _Slave_Ports_queue__add peek: [");
  171. int _Slave_Ports_queue_peek = _Slave_Ports_queue.peek() ;
  172. Serial.print(_Slave_Ports_queue_peek);
  173. int _Slave_Ports_queue_push = _Slave_Ports_queue_peek + 1;
  174. int _Slave_Ports_queue_peek_new = _Slave_Ports_queue_push ; //_Slave_Ports_queue.peek() ;
  175. // int _Slave_Ports_queue__push = _Slave_Ports_queue__peek + 1 ;
  176. Serial.print("] new peek[");
  177. Serial.print(_Slave_Ports_queue_peek_new ); Serial.print("] planned["); Serial.print(_Slave_Ports_queue_peek + 1 ); Serial.println("]");
  178. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new].queueID=_Slave_Ports_queue_peek_new;
  179. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new]._Slave_Ports_queue_task_type=_Slave_Ports_queue_task_type ;
  180. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new]._Slave_Port_link=_Slave_Port_link ;
  181. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new].time_seq_id=time_seq_id ;
  182. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new].time_min_run=time_min_run ;
  183. //return _Slave_Ports_queue_tasks_LIST;
  184. }
  185. */
  186. void _Slave_Ports_ttl_decrement_POP(_Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST,int _Slave_Ports_queue_pop , _Slave_Port* _Slave_Ports) {
  187. Serial.print("#213 _Slave_Ports_ttl_decrement_POP. sizeof _Slave_Ports["); Serial.print(sizeof(_Slave_Ports));
  188. int i;
  189. for(i=0;i<=100;i++) {
  190. if(_Slave_Ports[i]._Protocol == "CAN") {
  191. if(_Slave_Ports[i].Exp_state_ttl > 0x00 ) {
  192. 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("] ");
  193. }
  194. }
  195. }
  196. /*
  197. const char * const _Protocol;
  198. int _Slave_ID;
  199. int PortTypes; //0xFF = 1111 1111 { PWM, .....} = 0x80
  200. // byte has_Address;
  201. int Address ;
  202. // byte has_Local_Port;
  203. int LocalPort;
  204. int Exp_state; /*0xFF = 1111 1111
  205. 0x00 = 0000 0000 = OFF = 0V
  206. 0x01 = 0000 0001 = ON = PWM max
  207. {
  208. bit 1 - OFF = 0V
  209. bit 2 - ON = PWM max
  210. bit 3 - not allocated
  211. bit 4 - not allocated
  212. bit 2 - not allocated
  213. bit 5 - not allocated
  214. bit 6 - not allocated
  215. bit 7 - not allocated
  216. bit 8 - not allocated
  217. int Exp_state_ttl; // 0x00 = odswiezyc
  218. */
  219. }
  220. 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 ) {
  221. Serial.println("#251 _Slave_Ports_broadcast_POP");
  222. int i = 0;
  223. // int count = Slave_Ports_Status_C.get_count() ;
  224. //Slave_Ports_Status_S Slave_Ports_Status_A[1] ;
  225. /* for(i=0;i<=10;i++) {
  226. Slave_Ports_Status_S Slave_Ports_Status_AP = Slave_Ports_Status_C.get_port(i);
  227. //i++;
  228. // if( Slave_Ports_Status_A[i].Port_ID == 0 ) break;
  229. Serial.print("#293 i[");
  230. Serial.print(i); Serial.print("] Port_ID[");
  231. Serial.print(Slave_Ports_Status_AP.Port_ID); Serial.print("] PortTypes[");
  232. Serial.print(Slave_Ports_Status_AP.PortTypes); Serial.println("] ");
  233. delay(5000);
  234. }
  235. */
  236. /*for(i=0;i<=100;i++) {
  237. if(_Slave_Ports[i]._Protocol == "CAN") {
  238. Serial.print(" ind:"); Serial.print(i); Serial.print("] Prot:");
  239. Serial.print(_Slave_Ports[i]._Protocol);
  240. Serial.print(" , ID:");
  241. Serial.print(_Slave_Ports[i]._Slave_ID, HEX); Serial.print(" , PortTypes:");
  242. Serial.print(_Slave_Ports[i].PortTypes, HEX); Serial.print(" , Addr:"); Serial.print(_Slave_Ports[i].Address, HEX);
  243. Serial.print(" , Local:"); Serial.print(_Slave_Ports[i].LocalPort);
  244. Serial.print(" , Exp state:"); Serial.print(_Slave_Ports[i].Exp_state);
  245. Serial.print(" , Exp_state_ttl"); Serial.println(_Slave_Ports[i].Exp_state_ttl);
  246. Serial.println("#299 Prepared data");
  247. #if defined(HAS_LCD1602)
  248. // String LCDarray1 = "P[";
  249. LCD_print1(" Prepared data P[", LCDtim / 2);
  250. Serial.println("#303");
  251. LCD_print1(_Slave_Ports[i]._Protocol, LCDtim / 2);
  252. Serial.println("#305");
  253. // 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));
  254. // lcd.print(LCDarray1);
  255. // 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("] ?[" ) ;
  256. // LCDarray2.concat(String(_Slave_Ports[i].Exp_state_ttl, HEX)) ; LCDarray2.concat("]") ;
  257. // LCD_print(LCDarray1, LCDarray2, LCDtim / 2 ) ;
  258. #endif
  259. // (0) (1) (2) (3) (4) (5) (6)
  260. _Slave_Ports_Protocol_CAN_broadcast_T _Slave_Ports_Protocol_CAN_broadcast_A;
  261. // _Slave_Ports_Protocol_CAN_broadcast_A[1]._Slave_ID_BROADCAST = 0xFF;
  262. // _Slave_Ports_Protocol_CAN_broadcast_A[1]._SENDER = Active_ControllerID ;
  263. _Slave_Ports_Protocol_CAN_broadcast_A.Port_ID = i ;
  264. _Slave_Ports_Protocol_CAN_broadcast_A.PortTypes = _Slave_Ports[i].PortTypes ;
  265. _Slave_Ports_Protocol_CAN_broadcast_A.Exp_state = _Slave_Ports[i].Exp_state ;
  266. _Slave_Ports_Protocol_CAN_broadcast_A.Exp_state_ttl = _Slave_Ports[i].Exp_state_ttl ;
  267. _Slave_Ports_Protocol_CAN_broadcast_A.Broadcast_state = _Slave_Ports[i].Broadcast_state ;
  268. //_Slave_Ports_Protocol_CAN_broadcast_A[1]._CAN_8 = 0x07 ;
  269. /* byte data[8] = { _Slave_Ports_Protocol_CAN_broadcast_A._Slave_ID_BROADCAST,
  270. _Slave_Ports_Protocol_CAN_broadcast_A._SENDER,
  271. _Slave_Ports_Protocol_CAN_broadcast_A.Port_ID,
  272. _Slave_Ports_Protocol_CAN_broadcast_A.PortTypes,
  273. _Slave_Ports_Protocol_CAN_broadcast_A.Exp_state,
  274. _Slave_Ports_Protocol_CAN_broadcast_A.Exp_state_ttl,
  275. _Slave_Ports_Protocol_CAN_broadcast_A.Broadcast_state,
  276. _Slave_Ports_Protocol_CAN_broadcast_A._CAN_8
  277. } ;
  278. //_Slave_Ports_Protocol_CAN_broadcast_AS _Slave_Ports_Protocol_CAN_broadcast_B[8];
  279. //byte _Slave_Ports_Protocol_CAN_broadcast_B[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  280. byte _Slave_Ports_Protocol_CAN_broadcast_B[8] ;
  281. _Slave_Ports_Protocol_CAN_broadcast_AF(_Slave_Ports_Protocol_CAN_broadcast_A, _Slave_Ports_Protocol_CAN_broadcast_B);
  282. //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};
  283. //_Slave_Ports_Protocol_CAN_broadcast_AS data = _Slave_Ports_Protocol_CAN_broadcast_F(_Slave_Ports_Protocol_CAN_broadcast_A) ;
  284. // byte data[8] = {element.Address, 0x04, element.LocalPort, element.PortTypes, element.LocalPort, element.Exp_state, element.Exp_state_ttl, 0x07};
  285. // byte data[8] = { _Slave_Ports_Protocol_CAN_broadcast_A };
  286. // _Slave_Ports_Protocol_CAN_broadcast_AS data = _Slave_Ports_Protocol_CAN_broadcast_AF(_Slave_Ports_Protocol_CAN_broadcast_A);
  287. /* Serial.print("#303 byte data[8] 1["); Serial.print(_Slave_Ports[i].Address); Serial.print("] 2["); Serial.print(0x04); Serial.print("] 3[");
  288. 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[");
  289. Serial.print( _Slave_Ports[i].Exp_state_ttl); Serial.print("] 7["); Serial.print(0x07); Serial.println("] ");
  290. Serial.print("#343 byte data[8] ");
  291. // Serial.print((char)data);
  292. Serial.println("]");
  293. byte sndStat = CAN0.sendMsgBuf(_Slave_Ports[i]._Slave_ID, 0, 8, _Slave_Ports_Protocol_CAN_broadcast_B); //_Slave_Ports_Protocol_CAN_broadcast_A //data
  294. // byte sndStat ;
  295. if(sndStat == CAN_OK){
  296. Serial.println("#349 Message Sent Successfully!");
  297. String LCDarray1 = "Message Sent";
  298. String LCDarray2 = "Successfully";
  299. #if defined(HAS_LCD1602)
  300. LCD_print(LCDarray1,LCDarray2,LCDtim);
  301. #endif
  302. } else {
  303. Serial.println("#356 Error Sending Message...");
  304. String LCDarray1 = "Error Sending";
  305. String LCDarray2 = "Message...";
  306. #if defined(HAS_LCD1602)
  307. LCD_print(LCDarray1,LCDarray2,LCDtim);
  308. #endif
  309. }
  310. /*
  311. #if defined(HAS_LCD1602)
  312. // LCD_print(LCDarray1,LCDarray2,LCDtim);
  313. /*
  314. delay(LCDtim * 5);
  315. //lcd.setCursor(0,1);
  316. lcd.print(lcdPattern);
  317. //lcd.print(lcdPos % 10);
  318. if(lcdPos >= 16) {
  319. //lcd.print("N");
  320. lcd.setCursor(0,1);
  321. lcdPos = 0;
  322. if(lcdPattern=="s") lcdPattern = "S" ;
  323. else lcdPattern = "s" ;
  324. }
  325. lcdPos ++;
  326. |
  327. #endif
  328. #if defined(HAS_TFT_ILI9163C)
  329. delay(LCDtim);
  330. display.setCursor(0,60);
  331. display.print(LCDarray1); display.print(" "); display.print(LCDarray2);
  332. #endif
  333. delay(1000); // send data per 100ms
  334. }
  335. */
  336. // }
  337. } //EOF _Slave_Ports_broadcast_POP
  338. void _Slave_Ports_queue__POP( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST,
  339. int _Slave_Ports_queue_count,
  340. int _Slave_Ports_queue_pop,
  341. int _Slave_Ports_queue_front,
  342. int _Slave_Ports_queue_back,
  343. int _Slave_Ports_queue_peek,
  344. int LCDtim, _Slave_Port* _Slave_Ports) {
  345. //int count = _Slave_Ports_queuev.count();
  346. //int _Slave_Ports_queue_pop _Slave_Ports_queuev.pop();
  347. Serial.print("#180 run _Slave_Ports_queue__POP cnt "); Serial.print(_Slave_Ports_queue_count); Serial.print(" , pop: "); Serial.println(_Slave_Ports_queue_pop);
  348. if (_Slave_Ports_queue_count > 0) {
  349. Serial.println("#472");
  350. /* String LCDarray1 = "`Slave_Ports_queue size [";
  351. Serial.println("#474");
  352. LCDarray1.concat(_Slave_Ports_queue_count);
  353. Serial.println("#476");
  354. //LCDarray1.concat("] Oldest[");
  355. Serial.println("#477");
  356. LCDarray1.concat(_Slave_Ports_queue_pop);
  357. Serial.println("#478");
  358. LCDarray1.concat("] Curr[");
  359. LCDarray1.concat(_Slave_Ports_queue_front);
  360. String LCDarray2 = "] last[";
  361. LCDarray2.concat(_Slave_Ports_queue_back);
  362. LCDarray2.concat("] Next[");
  363. LCDarray2.concat(_Slave_Ports_queue_peek);
  364. Serial.print(LCDarray1);
  365. Serial.println(LCDarray2);
  366. LCD_print(LCDarray1, LCDarray2, LCDtim / 3 ) ;
  367. */
  368. if(_Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].queueID == 0 and
  369. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].queueID == 0 and
  370. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type == 0 and
  371. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Port_link == 0 and
  372. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].time_seq_id == 0 and
  373. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].time_min_run == 0 ) {
  374. /* String LCDarray1 = "#206 Error with queue";
  375. String LCDarray2 = "ID: ";
  376. LCDarray2.concat( _Slave_Ports_queue_pop); LCDarray2.concat("] ");
  377. Serial.print(LCDarray1);
  378. Serial.println(LCDarray2);
  379. LCD_print(LCDarray1, LCDarray2, LCDtim / 3 ) ;
  380. */
  381. Serial.println("#507");
  382. } else {
  383. Serial.println("#509");
  384. /*
  385. String LCDarray1 = "#407 Running task";
  386. String LCDarray2 = "ID: ";
  387. LCDarray2.concat( _Slave_Ports_queue_pop); LCDarray2.concat("] task_type[");
  388. LCDarray2.concat( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type); LCDarray2.concat("] ");
  389. Serial.print(LCDarray1);
  390. Serial.println(LCDarray2);
  391. LCD_print(LCDarray1, LCDarray2, LCDtim / 3 ) ;
  392. */
  393. if( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type == 0x01 ) {
  394. Serial.print("#224 running _Slave_Ports_ttl_decrement = "); Serial.println( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);
  395. _Slave_Ports_ttl_decrement_POP(_Slave_Ports_queue_tasks_LIST, _Slave_Ports_queue_pop , _Slave_Ports ) ;
  396. } else if( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type == 0x04 ) {
  397. Serial.print("#337 running _Slave_Ports_broadcast = "); Serial.println( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);
  398. _Slave_Ports_broadcast_POP(_Slave_Ports_queue_tasks_LIST, _Slave_Ports_queue_pop , _Slave_Ports, LCDtim ) ;
  399. } else {
  400. Serial.print("Error unsupported type "); Serial.println( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);
  401. }
  402. }
  403. } else {
  404. String LCDarray1 = "Nothing to";
  405. String LCDarray2 = "process...";
  406. //LCDarray2.reserve(16);
  407. Serial.print(LCDarray1);
  408. Serial.println(LCDarray2);
  409. // Serial.print("#32 String LCDarray2 len");
  410. // int LCDarray2_length = LCDarray2.length;
  411. /* Serial.print(LCDarray2.length());
  412. Serial.println("] now ");
  413. LCDarray2 = make_str16(LCDarray2);
  414. Serial.print(LCDarray2.length());
  415. Serial.println("] next #338");
  416. for(int i = 0; i < (17 - LCDarray2.length()); i++)
  417. LCDarray2 += 'x';
  418. Serial.print(LCDarray2.length());
  419. Serial.println("] ");
  420. */
  421. Serial.print(" #364 scount ");
  422. Serial.print(_Slave_Ports_queue_count);
  423. Serial.print(" _Slave_Ports_queue.front(): ");
  424. Serial.print(_Slave_Ports_queue_front);
  425. Serial.print(" _Slave_Ports_queue.back(): ");
  426. Serial.print(_Slave_Ports_queue_back);
  427. Serial.print(" _Slave_Ports_queue.peek(): ");
  428. Serial.println(_Slave_Ports_queue_peek);
  429. #if defined(HAS_LCD1602)
  430. LCD_print(LCDarray1, LCDarray2, LCDtim / 3 ) ;
  431. #endif
  432. }
  433. }
  434. /*
  435. struct _Slave_Port
  436. {
  437. char _Protocol ;
  438. int _Slave_ID;
  439. char Port_Type;
  440. int Address;
  441. int LocalPort ;
  442. void (*fn)();
  443. };
  444. struct _Slave_Port {
  445. }
  446. #define _Slave_Port = { "CAN" , 0x102 , "PWM", 0x00, 0 }
  447. */
  448. /* #define __CAN_Ports { _Slave1_ID } ;
  449. #define __CAN_Ports_PWM { _Slave1_ID
  450. {0x00 , 0 } ,
  451. {0x00 , 1 }
  452. } ;
  453. */
  454. /*
  455. typedef struct
  456. {
  457. int Slave1_ID;
  458. String PortType;
  459. int Address;
  460. int LocalPort ;
  461. }
  462. */
  463. /*
  464. struct buttons
  465. {
  466. int color[3];
  467. int positions[4];
  468. char init[20];
  469. void (*fn)();
  470. };
  471. //void func1();
  472. //void func2();
  473. buttons test[] =
  474. {
  475. { {0,0,0}, {0,0,100,100}, "getSomething", func1 },
  476. { {40,40,40}, {50,50,10,10}, "somethingElse", func2 },
  477. };
  478. */
  479. /*
  480. typedef struct {
  481. const char * const l_name;
  482. byte x_m;
  483. byte y_m;
  484. boolean period[4];
  485. } myStruct;
  486. myStruct structs[] = {
  487. {"My Name", 0, 0, {true, true, false, false}},
  488. {"My Second Name", 0, 0, {true, false, true, false}}
  489. };
  490. */
  491. //#define _CAN_P_0x102_PWM0x00_0 { _Slave1_ID , "PWM", 0x00, 0 }
  492. //#define _CAN_P_0x102_PWM0x00_1 { _Slave1_ID , "PWM", 0x00, 1 }
  493. // char _Slave_Ports ;
  494. // _Slave_Ports[0] = "_CAN_P_0x102_PWM0x00_0" ;
  495. // _Slave_Ports[1] = "_CAN_P_0x102_PWM0x00_1" ;
  496. // char *_Slave_Ports[] = { "_CAN_P_0x102_PWM0x00_0", "_CAN_P_0x102_PWM0x00_1" } ;