handfsm.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. void hndDebugPrint (string s)
  2. {
  3. #ifdef INV_DEBUG
  4. PrintToRPT("" + s); // comment/uncomment to hide/see debug logs
  5. #else
  6. //Print("" + s); // comment/uncomment to hide/see debug logs
  7. #endif
  8. }
  9. void hndDebugSpam (string s)
  10. {
  11. #ifdef INV_DEBUG_SPAM
  12. PrintToRPT("" + s); // comment/uncomment to hide/see debug logs
  13. #else
  14. //Print("" + s); // comment/uncomment to hide/see debug logs
  15. #endif
  16. }
  17. void hndDebugSpamALot (string s)
  18. {
  19. #ifdef INV_DEBUG_SPAM_FREQ
  20. PrintToRPT("" + s); // comment/uncomment to hide/see debug logs
  21. #else
  22. //Print("" + s); // comment/uncomment to hide/see debug logs
  23. #endif
  24. }
  25. typedef FSMTransition<HandStateBase, HandEventBase, HandActionBase, HandGuardBase> HandTransition;
  26. /**@class HandFSM
  27. * @brief Hand finite state machine
  28. **/
  29. class HandFSM extends HFSMBase<HandStateBase, HandEventBase, HandActionBase, HandGuardBase>
  30. {
  31. int GetCurrentStateID ()
  32. {
  33. /*if (m_States.Count() == 2)
  34. {
  35. int s0 = m_States[0].GetCurrentStateID();
  36. int s1 = m_States[1].GetCurrentStateID() << 8;
  37. return s1 | s0;
  38. }*/
  39. return 0;
  40. }
  41. /**@fn SyncStateFromID
  42. * @brief load from database - reverse lookup for state from saved id
  43. * @param[in] id the id stored in database during save
  44. **/
  45. protected bool SyncStateFromID (int id)
  46. {
  47. /*if (id == 0)
  48. return false;
  49. int s0 = id & 0x000000ff;
  50. int s1 = id & 0x0000ff00;
  51. int count = m_Transitions.Count();
  52. bool set0 = false;
  53. bool set1 = false;
  54. for (int i = 0; i < count; ++i)
  55. {
  56. HandTransition t = m_Transitions.Get(i);
  57. if (!set0 && t.m_srcState && s0 == t.m_srcState.GetCurrentStateID())
  58. {
  59. m_States[0] = t.m_srcState;
  60. set0 = true;
  61. }
  62. if (!set1 && t.m_srcState && s1 == t.m_srcState.GetCurrentStateID())
  63. {
  64. m_States[1] = t.m_srcState;
  65. set1 = true;
  66. }
  67. if (set0 && set1)
  68. return true;
  69. }*/
  70. return false;
  71. }
  72. /**@fn OnStoreLoad
  73. * @brief load state of fsm
  74. **/
  75. bool OnStoreLoad (ParamsReadContext ctx, int version)
  76. {
  77. /*int id = 0;
  78. ctx.Read(id);
  79. if (SyncStateFromID(id))
  80. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] OnStoreLoad - loaded current state from id=" + id);
  81. else
  82. Print("[hndfsm] Warning! OnStoreLoad - cannot load curent hand state, id=" + id);*/
  83. return true;
  84. }
  85. /**@fn OnStoreSave
  86. * @brief save state of fsm
  87. **/
  88. void OnStoreSave (ParamsWriteContext ctx)
  89. {
  90. /*int id = GetCurrentStateID();
  91. ctx.Write(id);
  92. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] OnStoreSave - saving current state=" + GetCurrentState() + " id=" + id);*/
  93. }
  94. /**@fn NetSyncCurrentStateID
  95. * @brief Engine callback - network synchronization of FSM's state. not intended to direct use.
  96. **/
  97. void NetSyncCurrentStateID (int id)
  98. {
  99. /*if (SyncStateFromID(id))
  100. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] NetSyncCurrentStateID - loaded current state from id=" + id);
  101. else
  102. Print("[hndfsm] NetSyncCurrentStateID called with null, ignoring request to set current fsm state.");*/
  103. }
  104. };