Subversion Repositories HomeAutomation

Rev

Rev 2033 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. #include "sns_rfid.h"
  3.  
  4. #include "rfid.h"
  5.  
  6. uint8_t sns_rfid_got_card = 0;
  7.  
  8. void sns_rfid_Init(void)
  9. {
  10.     rfid_init();
  11. }
  12.  
  13. void sns_rfid_Process(void)
  14. {
  15.     uint8_t version;
  16.     uint32_t id;
  17.     if( 0 == rfid_fetch( &version, &id ) ) {
  18.         if( !sns_rfid_got_card ) {
  19.             sns_rfid_got_card = 1;
  20.             sns_rfid_card.id      = id;
  21.             sns_rfid_card.version = version;
  22.             // Card arrived
  23.             sns_rfid_HandleCardEvent(1);
  24.         }
  25.         Timer_SetTimeout(sns_rfid_CARD_LEFT_TIMER, sns_rfid_CARD_LEFT_TIME, TimerTypeOneShot, 0);
  26.     }
  27.     if ( Timer_Expired(sns_rfid_CARD_LEFT_TIMER) ) {
  28.         sns_rfid_got_card = 0;
  29.         // Card left
  30.         sns_rfid_HandleCardEvent(0);
  31.     }
  32. }
  33.  
  34. void sns_rfid_HandleCardEvent( uint8_t event ) {
  35.     StdCan_Msg_t txMsg;
  36.  
  37.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); ///TODO: Change this to the actual class type
  38.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  39.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFID; ///TODO: Change this to the actual module type
  40.     txMsg.Header.ModuleId = sns_rfid_ID;
  41.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  42.     txMsg.Length = 6;
  43.  
  44.     txMsg.Data[0] = event;
  45.     txMsg.Data[1] =  sns_rfid_card.version;
  46.     txMsg.Data[2] =  sns_rfid_card.id&0xff;
  47.     txMsg.Data[3] = (sns_rfid_card.id>>8)&0xff;
  48.     txMsg.Data[4] = (sns_rfid_card.id>>16)&0xff;
  49.     txMsg.Data[5] = (sns_rfid_card.id>>24)&0xff;
  50.  
  51.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  52. }
  53.  
  54. void sns_rfid_HandleMessage(StdCan_Msg_t *rxMsg)
  55. {
  56. /*  if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS && ///TODO: Change this to the actual class type
  57.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
  58.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_RFID && ///TODO: Change this to the actual module type
  59.         rxMsg->Header.ModuleId == sns_rfid_ID)
  60.     {
  61.         switch (rxMsg->Header.Command)
  62.         {
  63.         case CAN_CMD_MODULE_DUMMY:
  64.         ///TODO: Do something dummy
  65.         break;
  66.         }
  67.     }*/
  68. }
  69.  
  70. void sns_rfid_List(uint8_t ModuleSequenceNumber)
  71. {
  72.     StdCan_Msg_t txMsg;
  73.  
  74.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); ///TODO: Change this to the actual class type
  75.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  76.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFID; ///TODO: Change this to the actual module type
  77.     txMsg.Header.ModuleId = sns_rfid_ID;
  78.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  79.     txMsg.Length = 6;
  80.  
  81.     uint32_t HwId=BIOS_GetHwId();
  82.     txMsg.Data[0] = HwId&0xff;
  83.     txMsg.Data[1] = (HwId>>8)&0xff;
  84.     txMsg.Data[2] = (HwId>>16)&0xff;
  85.     txMsg.Data[3] = (HwId>>24)&0xff;
  86.  
  87.     txMsg.Data[4] = NUMBER_OF_MODULES;
  88.     txMsg.Data[5] = ModuleSequenceNumber;
  89.  
  90.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  91. }
  92.