Subversion Repositories HomeAutomation

Rev

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