_Slave_Ports.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. #include "_Slave_Ports_ttl_decrement.h"
  2. typedef struct {
  3. const char * const _Protocol;
  4. int _Slave_ID;
  5. int PortTypes; //0xFF = 1111 1111 { PWM, .....} = 0x80
  6. // byte has_Address;
  7. int Address ;
  8. // byte has_Local_Port;
  9. int LocalPort;
  10. int Exp_state; /*0xFF = 1111 1111
  11. 0x00 = 0000 0000 = OFF = 0V
  12. 0x01 = 0000 0001 = ON = PWM max
  13. {
  14. bit 1 - OFF = 0V
  15. bit 2 - ON = PWM max
  16. bit 3 - not allocated
  17. bit 4 - not allocated
  18. bit 2 - not allocated
  19. bit 5 - not allocated
  20. bit 6 - not allocated
  21. bit 7 - not allocated
  22. bit 8 - not allocated
  23. }*/
  24. int Exp_state_ttl; // 0x00 = odswiezyc
  25. } _Slave_Port;
  26. _Slave_Port _Slave_Ports[] = {
  27. {"CAN", 0x102, 0x01, 0x00, 0x00, 0x00, 0x00 }
  28. //,
  29. //{"CAN", 0x102, 0x01, 0x00, 0x01, 0xFF, 0x6d } //testowy ttl
  30. };
  31. struct _Slave_Ports_queue_tasksS {
  32. int queueID;
  33. int _Slave_Ports_queue_task_type ; /*
  34. { 0x01 _Slave_Ports_ttl_decrement,
  35. 0x02 request_confirm_Exp_state ,
  36. 0x03 request_set__new_Exp_state,
  37. }
  38. */
  39. int _Slave_Port_link; //todo link
  40. long time_seq_id;
  41. long time_min_run;
  42. } ;
  43. typedef struct _Slave_Ports_queue_tasksS _Slave_Ports_queue_tasksT;
  44. _Slave_Ports_queue_tasksT _Slave_Ports_queue_tasks_LIST[11];
  45. void _Slave_Ports_queue__INIT( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST) {
  46. Serial.println("_Slave_Ports_queue__INIT");
  47. int i;
  48. for(i=0;i<10;i++) {
  49. _Slave_Ports_queue_tasks_LIST[i].queueID = 0;
  50. _Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type = 0x00;
  51. _Slave_Ports_queue_tasks_LIST[i]._Slave_Port_link = 0x00;
  52. _Slave_Ports_queue_tasks_LIST[i].time_seq_id = 0;
  53. _Slave_Ports_queue_tasks_LIST[i].time_min_run = 0;
  54. // _Slave_Ports_queue_tasks_LIST[i]=_Slave_Ports_queue_tasks_LIST[i];
  55. }
  56. }
  57. char _Slave_Ports_queue_task_type_DESC( int _Slave_Ports_queue_task_type ) {//, int* res
  58. /* if(_Slave_Ports_queue_task_type == 0x01) res=0x99; //res="_Slave_Ports_ttl_decrement";
  59. else if(_Slave_Ports_queue_task_type == 0x02) res=0x99; //res="request_confirm_Exp_state";
  60. else if(_Slave_Ports_queue_task_type == 0x03) res=0x99; //res="request_set__new_Exp_state";
  61. else {
  62. res=0x99; // res="_UNKNOIWN";
  63. Serial.print("#82 Get ["); Serial.print(_Slave_Ports_queue_task_type); Serial.println("] #82 [U] ");
  64. }
  65. */
  66. // char return_i;
  67. Serial.print("=["); Serial.print(_Slave_Ports_queue_task_type); Serial.print("] ");
  68. if(_Slave_Ports_queue_task_type == 0x01) Serial.print("_Slave_Ports_ttl_decrement"); // return "_Slave_Ports_ttl_decrement";
  69. else if(_Slave_Ports_queue_task_type == 0x02) Serial.print("request_confirm_Exp_state"); //return "request_confirm_Exp_state";
  70. else if(_Slave_Ports_queue_task_type == 0x03) Serial.print("request_set__new_Exp_state"); //return "request_set__new_Exp_state";
  71. else //return_i = "_UNKNOIWN"; //return "_UNKNOIWN";
  72. Serial.print("_UNKNOIWN");
  73. // Serial.print((String)return_i);
  74. // return return_i ;
  75. }
  76. //Queue<_Slave_Ports_queueT> _Slave_Ports_queue = Queue<_Slave_Ports_queueT>(5);
  77. void _Slave_Ports_queue__list( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST) {
  78. int i;
  79. Serial.println("#100 _Slave_Ports_queue_tasks_LIST): ");
  80. //Serial.println(sizeof(_Slave_Ports_queue_tasks_LIST));
  81. for(i=0;i<=10;i++) { //sizeof(_LCD_print_buffors)
  82. 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 ) {
  83. } else {
  84. Serial.print(" $i[");
  85. Serial.print(i);
  86. Serial.print("] queueID: ");
  87. Serial.print(_Slave_Ports_queue_tasks_LIST[i].queueID);
  88. Serial.print("] _Slave_Ports_queue_task_type: ");
  89. //Slave_Ports_queue_task_type_DESC(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type);
  90. int res = _Slave_Ports_queue_task_type_DESC(_Slave_Ports_queue_tasks_LIST[i]._Slave_Ports_queue_task_type); Serial.print(res);
  91. // 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
  92. Serial.print("] _Slave_Port_link: ");
  93. Serial.print(_Slave_Ports_queue_tasks_LIST[i]._Slave_Port_link);
  94. Serial.print("] time_seq_id: ");
  95. Serial.print(_Slave_Ports_queue_tasks_LIST[i].time_seq_id);
  96. Serial.print("] time_min_run: ");
  97. Serial.println(_Slave_Ports_queue_tasks_LIST[i].time_min_run);
  98. }
  99. }
  100. }
  101. /*
  102. struct _Slave_Ports_queue_tasksS {
  103. int queueID;
  104. int _Slave_Ports_queue_task_type ; /*
  105. { 0x01 _Slave_Ports_ttl_decrement,
  106. 0x02 request_confirm_Exp_state ,
  107. 0x03 request_set__new_Exp_state,
  108. 0x04 _Slave_Ports_ttl_decrement }
  109. int _Slave_Port_link; //todo link
  110. long time_seq_id;
  111. long time_min_run;
  112. } ;
  113. */
  114. 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 //,
  115. //int _Slave_Ports_queue_peek , int _Slave_Ports_queue_push , int _Slave_Ports_queue_peek_new
  116. ) {
  117. Serial.println(".");
  118. Serial.print("#152 _Slave_Ports_queue__add peek: [");
  119. int _Slave_Ports_queue_peek = _Slave_Ports_queue.peek() ;
  120. int _Slave_Ports_queue_back = _Slave_Ports_queue.back() ;
  121. // int _Slave_Ports_queue_push_new_ref;
  122. // if(_Slave_Ports_queue_back > _Slave_Ports_queue_peek)
  123. Serial.print(_Slave_Ports_queue_peek); Serial.print("] cur back["); Serial.print(_Slave_Ports_queue_back); Serial.print("] ");
  124. _Slave_Ports_queue.push(_Slave_Ports_queue_back + 1);
  125. int _Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ;
  126. // int _Slave_Ports_queue__push = _Slave_Ports_queue__peek + 1 ;
  127. Serial.print("] new peek[");
  128. Serial.print(_Slave_Ports_queue_peek_new ); Serial.print("] planned["); Serial.print(_Slave_Ports_queue_back + 1 );
  129. Serial.print("] front["); Serial.print(_Slave_Ports_queue.front()); Serial.print("] back["); Serial.print(_Slave_Ports_queue.back()); Serial.println("] ");
  130. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ].queueID=_Slave_Ports_queue_back + 1 ;
  131. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ]._Slave_Ports_queue_task_type=_Slave_Ports_queue_task_type ;
  132. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ]._Slave_Port_link=_Slave_Port_link ;
  133. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ].time_seq_id=time_seq_id ;
  134. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_back + 1 ].time_min_run=time_min_run ;
  135. }
  136. /*
  137. void _Slave_Ports_queue__add(const _Slave_Ports_queue_tasksT* &_Slave_Ports_queue_tasks_LIST ,
  138. int _Slave_Ports_queue_task_type, int _Slave_Port_link, long time_seq_id, long time_min_run //,
  139. //int _Slave_Ports_queue_peek , int _Slave_Ports_queue_push , int _Slave_Ports_queue_peek_new
  140. ) {
  141. Serial.print("#152 _Slave_Ports_queue__add peek: [");
  142. int _Slave_Ports_queue_peek = _Slave_Ports_queue.peek() ;
  143. Serial.print(_Slave_Ports_queue_peek);
  144. int _Slave_Ports_queue_push = _Slave_Ports_queue_peek + 1;
  145. int _Slave_Ports_queue_peek_new = _Slave_Ports_queue_push ; //_Slave_Ports_queue.peek() ;
  146. // int _Slave_Ports_queue__push = _Slave_Ports_queue__peek + 1 ;
  147. Serial.print("] new peek[");
  148. Serial.print(_Slave_Ports_queue_peek_new ); Serial.print("] planned["); Serial.print(_Slave_Ports_queue_peek + 1 ); Serial.println("]");
  149. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new].queueID=_Slave_Ports_queue_peek_new;
  150. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new]._Slave_Ports_queue_task_type=_Slave_Ports_queue_task_type ;
  151. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new]._Slave_Port_link=_Slave_Port_link ;
  152. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new].time_seq_id=time_seq_id ;
  153. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_peek_new].time_min_run=time_min_run ;
  154. //return _Slave_Ports_queue_tasks_LIST;
  155. }
  156. */
  157. void _Slave_Ports_ttl_decrement_POP(_Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST,int _Slave_Ports_queue_pop , _Slave_Port* _Slave_Ports) {
  158. Serial.print("#213 _Slave_Ports_ttl_decrement_POP. sizeof _Slave_Ports["); Serial.print(sizeof(_Slave_Ports));
  159. int i;
  160. for(i=0;i<=100;i++) {
  161. if(_Slave_Ports[i]._Protocol == "CAN") {
  162. if(_Slave_Ports[i].Exp_state_ttl > 0x00 ) {
  163. 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("] ");
  164. }
  165. }
  166. }
  167. /*
  168. const char * const _Protocol;
  169. int _Slave_ID;
  170. int PortTypes; //0xFF = 1111 1111 { PWM, .....} = 0x80
  171. // byte has_Address;
  172. int Address ;
  173. // byte has_Local_Port;
  174. int LocalPort;
  175. int Exp_state; /*0xFF = 1111 1111
  176. 0x00 = 0000 0000 = OFF = 0V
  177. 0x01 = 0000 0001 = ON = PWM max
  178. {
  179. bit 1 - OFF = 0V
  180. bit 2 - ON = PWM max
  181. bit 3 - not allocated
  182. bit 4 - not allocated
  183. bit 2 - not allocated
  184. bit 5 - not allocated
  185. bit 6 - not allocated
  186. bit 7 - not allocated
  187. bit 8 - not allocated
  188. int Exp_state_ttl; // 0x00 = odswiezyc
  189. */
  190. }
  191. void _Slave_Ports_queue__POP( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST,
  192. int _Slave_Ports_queue_count,
  193. int _Slave_Ports_queue_pop,
  194. int _Slave_Ports_queue_front,
  195. int _Slave_Ports_queue_back,
  196. int _Slave_Ports_queue_peek,
  197. int LCDtim, _Slave_Port* _Slave_Ports) {
  198. //int count = _Slave_Ports_queuev.count();
  199. //int _Slave_Ports_queue_pop _Slave_Ports_queuev.pop();
  200. Serial.print("#180 run _Slave_Ports_queue__POP cnt "); Serial.print(_Slave_Ports_queue_count); Serial.print(" , pop: "); Serial.println(_Slave_Ports_queue_pop);
  201. if (_Slave_Ports_queue_count > 0) {
  202. String LCDarray1 = "`Slave_Ports_queue size [";
  203. LCDarray1.concat(_Slave_Ports_queue_count);
  204. LCDarray1.concat("] Oldest[");
  205. LCDarray1.concat(_Slave_Ports_queue_pop);
  206. LCDarray1.concat("] Curr[");
  207. LCDarray1.concat(_Slave_Ports_queue_front);
  208. String LCDarray2 = "] last[";
  209. LCDarray2.concat(_Slave_Ports_queue_back);
  210. LCDarray2.concat("] Next[");
  211. LCDarray2.concat(_Slave_Ports_queue_peek);
  212. Serial.print(LCDarray1);
  213. Serial.println(LCDarray2);
  214. LCD_print(LCDarray1, LCDarray2, LCDtim / 3 ) ;
  215. if(_Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].queueID == 0 and
  216. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].queueID == 0 and
  217. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type == 0 and
  218. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Port_link == 0 and
  219. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].time_seq_id == 0 and
  220. _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop].time_min_run == 0 ) {
  221. String LCDarray1 = "#206 Error with queue";
  222. String LCDarray2 = "ID: ";
  223. LCDarray2.concat( _Slave_Ports_queue_pop); LCDarray2.concat("] ");
  224. Serial.print(LCDarray1);
  225. Serial.println(LCDarray2);
  226. LCD_print(LCDarray1, LCDarray2, LCDtim / 3 ) ;
  227. } else {
  228. String LCDarray1 = " Running task";
  229. String LCDarray2 = "ID: ";
  230. LCDarray2.concat( _Slave_Ports_queue_pop); LCDarray2.concat("] ");
  231. Serial.print(LCDarray1);
  232. Serial.println(LCDarray2);
  233. LCD_print(LCDarray1, LCDarray2, LCDtim / 3 ) ;
  234. if( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type = 0x01 ) {
  235. Serial.print("#224 running _Slave_Ports_ttl_decrement = "); Serial.println( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);
  236. #include "_Slave_Ports_ttl_decrement.h"
  237. _Slave_Ports_ttl_decrement_POP(_Slave_Ports_queue_tasks_LIST, _Slave_Ports_queue_pop , _Slave_Ports ) ;
  238. } else {
  239. Serial.print("Error unsupported type "); Serial.println( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);
  240. }
  241. }
  242. } else {
  243. String LCDarray1 = "Nothing to";
  244. String LCDarray2 = "process...";
  245. Serial.print(LCDarray1);
  246. Serial.println(LCDarray2);
  247. Serial.print(" #364 scount ");
  248. Serial.print(_Slave_Ports_queue_count);
  249. Serial.print(" _Slave_Ports_queue.front(): ");
  250. Serial.print(_Slave_Ports_queue_front);
  251. Serial.print(" _Slave_Ports_queue.back(): ");
  252. Serial.print(_Slave_Ports_queue_back);
  253. Serial.print(" _Slave_Ports_queue.peek(): ");
  254. Serial.println(_Slave_Ports_queue_peek);
  255. LCD_print(LCDarray1, LCDarray2, LCDtim / 3 ) ;
  256. }
  257. }
  258. /*
  259. struct _Slave_Port
  260. {
  261. char _Protocol ;
  262. int _Slave_ID;
  263. char Port_Type;
  264. int Address;
  265. int LocalPort ;
  266. void (*fn)();
  267. };
  268. struct _Slave_Port {
  269. }
  270. #define _Slave_Port = { "CAN" , 0x102 , "PWM", 0x00, 0 }
  271. */
  272. /* #define __CAN_Ports { _Slave1_ID } ;
  273. #define __CAN_Ports_PWM { _Slave1_ID
  274. {0x00 , 0 } ,
  275. {0x00 , 1 }
  276. } ;
  277. */
  278. /*
  279. typedef struct
  280. {
  281. int Slave1_ID;
  282. String PortType;
  283. int Address;
  284. int LocalPort ;
  285. }
  286. */
  287. /*
  288. struct buttons
  289. {
  290. int color[3];
  291. int positions[4];
  292. char init[20];
  293. void (*fn)();
  294. };
  295. //void func1();
  296. //void func2();
  297. buttons test[] =
  298. {
  299. { {0,0,0}, {0,0,100,100}, "getSomething", func1 },
  300. { {40,40,40}, {50,50,10,10}, "somethingElse", func2 },
  301. };
  302. */
  303. /*
  304. typedef struct {
  305. const char * const l_name;
  306. byte x_m;
  307. byte y_m;
  308. boolean period[4];
  309. } myStruct;
  310. myStruct structs[] = {
  311. {"My Name", 0, 0, {true, true, false, false}},
  312. {"My Second Name", 0, 0, {true, false, true, false}}
  313. };
  314. */
  315. //#define _CAN_P_0x102_PWM0x00_0 { _Slave1_ID , "PWM", 0x00, 0 }
  316. //#define _CAN_P_0x102_PWM0x00_1 { _Slave1_ID , "PWM", 0x00, 1 }
  317. // char _Slave_Ports ;
  318. // _Slave_Ports[0] = "_CAN_P_0x102_PWM0x00_0" ;
  319. // _Slave_Ports[1] = "_CAN_P_0x102_PWM0x00_1" ;
  320. // char *_Slave_Ports[] = { "_CAN_P_0x102_PWM0x00_0", "_CAN_P_0x102_PWM0x00_1" } ;