_Slave_Ports.h 28 KB

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