Subversion Repositories HomeAutomation

Rev

Rev 1550 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. #include "sns_LM335.h"
  3.  
  4. uint8_t sns_LM335_ReportInterval = (uint8_t)sns_LM335_SEND_PERIOD;
  5.  
  6. void sns_LM335_Init(void)
  7. {
  8.     ///TODO: Initialize hardware etc here
  9.     ADC_Init();
  10.     Timer_SetTimeout(sns_LM335_TIMER, sns_LM335_ReportInterval*1000 , TimerTypeFreeRunning, 0);
  11. }
  12.  
  13. void sns_LM335_Process(void)
  14. {
  15.     ///TODO: Stuff that needs doing is done here
  16.     if (Timer_Expired(sns_LM335_TIMER)) {
  17.         uint16_t temperature = ADC_Get(LM335AD);
  18.         /* Use 5 volt as reference */
  19.         //temperature = temperature * 5;
  20. // modification to LM335
  21. //  temperature = temperature *6400;
  22.     //  temperature = temperature * 5/1023;
  23. //temperature = (temperature ) * 31;
  24. // temperature = temperature-273;
  25.   //    temperature = 0;
  26. //      temperature = temperature *31.28 -273*64;
  27.         temperature = temperature *31.28 -273*64;
  28.  
  29.  
  30.         StdCan_Msg_t txMsg;
  31.         StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  32.         StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  33.         txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_LM335;
  34.         txMsg.Header.ModuleId = sns_LM335_ID;
  35.         txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_TEMPERATURE_CELSIUS;
  36.         txMsg.Length = 3;
  37.         txMsg.Data[0] = 0;
  38.         txMsg.Data[1] = (temperature>>8)&0xff;
  39.         txMsg.Data[2] = (temperature)&0xff;
  40.  
  41.         StdCan_Put(&txMsg);
  42.     }  // if
  43. }
  44.  
  45. void sns_LM335_HandleMessage(StdCan_Msg_t *rxMsg)
  46. {
  47.     if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
  48.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
  49.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_LM335 &&
  50.         rxMsg->Header.ModuleId == sns_LM335_ID)
  51.     {
  52.         switch (rxMsg->Header.Command)
  53.         {
  54.         case CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL:
  55.         if (rxMsg->Length > 0)
  56.         {
  57.             sns_LM335_ReportInterval = rxMsg->Data[0];
  58.             Timer_SetTimeout(sns_LM335_TIMER, sns_LM335_ReportInterval*1000 , TimerTypeFreeRunning, 0);
  59.         }
  60.  
  61.         StdCan_Msg_t txMsg;
  62.  
  63.         StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  64.         StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  65.         txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_LM335;
  66.         txMsg.Header.ModuleId = sns_LM335_ID;
  67.         txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL;
  68.         txMsg.Length = 1;
  69.  
  70.         txMsg.Data[0] = sns_LM335_ReportInterval;
  71.  
  72.         StdCan_Put(&txMsg);
  73.         break;
  74.         }
  75.     }
  76. }
  77.  
  78. void sns_LM335_List(uint8_t ModuleSequenceNumber)
  79. {
  80.     StdCan_Msg_t txMsg;
  81.    
  82.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); ///TODO: Change this to the actual class type
  83.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  84.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_LM335; ///TODO: Change this to the actual module type
  85.     txMsg.Header.ModuleId = sns_LM335_ID;
  86.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  87.     txMsg.Length = 6;
  88.  
  89.     uint32_t HwId=BIOS_GetHwId();
  90.     txMsg.Data[0] = HwId&0xff;
  91.     txMsg.Data[1] = (HwId>>8)&0xff;
  92.     txMsg.Data[2] = (HwId>>16)&0xff;
  93.     txMsg.Data[3] = (HwId>>24)&0xff;
  94.    
  95.     txMsg.Data[4] = NUMBER_OF_MODULES;
  96.     txMsg.Data[5] = ModuleSequenceNumber;
  97.    
  98.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  99. }
  100.