handfsm.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. HandStableState hState = HandStableState.Cast(m_State);
  34. if(hState)
  35. return hState.GetCurrentStateID();
  36. return HandStateID.UNKNOWN;
  37. }
  38. /**@fn SyncStateFromID
  39. * @brief load from database - reverse lookup for state from saved id
  40. * @param[in] id the id stored in database during save
  41. **/
  42. protected bool SyncStateFromID (int id)
  43. {
  44. /*if (id == 0)
  45. return false;
  46. int s0 = id & 0x000000ff;
  47. int s1 = id & 0x0000ff00;
  48. int count = m_Transitions.Count();
  49. bool set0 = false;
  50. bool set1 = false;
  51. for (int i = 0; i < count; ++i)
  52. {
  53. HandTransition t = m_Transitions.Get(i);
  54. if (!set0 && t.m_srcState && s0 == t.m_srcState.GetCurrentStateID())
  55. {
  56. m_States[0] = t.m_srcState;
  57. set0 = true;
  58. }
  59. if (!set1 && t.m_srcState && s1 == t.m_srcState.GetCurrentStateID())
  60. {
  61. m_States[1] = t.m_srcState;
  62. set1 = true;
  63. }
  64. if (set0 && set1)
  65. return true;
  66. }*/
  67. return false;
  68. }
  69. /**@fn OnStoreLoad
  70. * @brief load state of fsm
  71. **/
  72. bool OnStoreLoad (ParamsReadContext ctx, int version)
  73. {
  74. /*int id = 0;
  75. ctx.Read(id);
  76. if (SyncStateFromID(id))
  77. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] OnStoreLoad - loaded current state from id=" + id);
  78. else
  79. Print("[hndfsm] Warning! OnStoreLoad - cannot load curent hand state, id=" + id);*/
  80. return true;
  81. }
  82. /**@fn OnStoreSave
  83. * @brief save state of fsm
  84. **/
  85. void OnStoreSave (ParamsWriteContext ctx)
  86. {
  87. /*int id = GetCurrentStateID();
  88. ctx.Write(id);
  89. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] OnStoreSave - saving current state=" + GetCurrentState() + " id=" + id);*/
  90. }
  91. /**@fn NetSyncCurrentStateID
  92. * @brief Engine callback - network synchronization of FSM's state. not intended to direct use.
  93. **/
  94. void NetSyncCurrentStateID (int id)
  95. {
  96. /*if (SyncStateFromID(id))
  97. if (LogManager.IsInventoryHFSMLogEnable()) hndDebugPrint("[hndfsm] NetSyncCurrentStateID - loaded current state from id=" + id);
  98. else
  99. Print("[hndfsm] NetSyncCurrentStateID called with null, ignoring request to set current fsm state.");*/
  100. }
  101. };