Subversion Repositories HomeAutomation

Rev

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

  1.  
  2. #include "sns_irTransceive.h"
  3.  
  4. #ifdef sns_irTransceive_USEEEPROM
  5. #include "sns_irTransceive_eeprom.h"
  6. struct eeprom_sns_irTransceive EEMEM eeprom_sns_irTransceive =
  7. {
  8.     {
  9.         /* Define initialization values on the EEPROM variables here.
  10.         This will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips.
  11.         Write the values in the exact same order as the struct is defined in the *.h file. */
  12.         CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO,
  13.         0,
  14.         CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO,
  15.         0,
  16.         CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO,
  17.         0,
  18.     },
  19.     0   /* crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts */
  20. };
  21. #endif
  22.  
  23. #if IR_RX_ENABLE==1
  24. struct {
  25.     uint8_t             state;
  26.     uint8_t             modfreq;
  27.     uint16_t            *rxbuf;
  28.     uint8_t             rxlen;
  29.     uint8_t             timerNum;
  30.     Ir_Protocol_Data_t  proto;
  31.     uint8_t             newData;
  32. } irRxChannel[IR_SUPPORTED_NUM_CHANNELS];
  33. #endif
  34.  
  35. #if IR_TX_ENABLE==1
  36. struct {
  37.     uint8_t             state;
  38.     uint8_t             modfreq;
  39.     uint16_t            *txbuf;
  40.     uint8_t             txlen;
  41.     uint8_t             timerNum;
  42.     uint8_t             repeatCount;
  43.     Ir_Protocol_Data_t  proto;
  44.     uint8_t             stopSend;
  45.     uint8_t             sendComplete;
  46.     // pronto params
  47.     uint8_t             sendingPronto;
  48.     uint8_t             onceSeqLen;
  49.     uint8_t             repSeqLen;
  50.     uint8_t             numberOfRepeats;
  51. } irTxChannel[IR_SUPPORTED_NUM_CHANNELS];
  52. #endif
  53.  
  54. uint16_t    buf[IR_SUPPORTED_NUM_CHANNELS][MAX_NR_TIMES];
  55.  
  56. StdCan_Msg_t        irTxMsg;
  57.  
  58. #if (sns_irTransceive_SEND_DEBUG==1)
  59. void send_debug(uint16_t *buffer, uint8_t len) {
  60.     StdCan_Msg_t dbgIrTxMsg;
  61.     /* the protocol is unknown so the raw ir-data is sent, makes it easier to develop a new protocol */
  62.  
  63.     StdCan_Set_class(dbgIrTxMsg.Header, CAN_MODULE_CLASS_SNS);
  64.     StdCan_Set_direction(dbgIrTxMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  65.     dbgIrTxMsg.Length = 8;
  66.     dbgIrTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  67.     dbgIrTxMsg.Header.ModuleId = sns_irTransceive_ID;
  68.     dbgIrTxMsg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRRAW;
  69.     for (uint8_t i = 0; i < len>>2; i++) {
  70.         uint8_t index = i<<2;
  71.  
  72.         dbgIrTxMsg.Data[0] = (buffer[index]>>8)&0xff;
  73.         dbgIrTxMsg.Data[1] = (buffer[index]>>0)&0xff;
  74.         dbgIrTxMsg.Data[2] = (buffer[index+1]>>8)&0xff;
  75.         dbgIrTxMsg.Data[3] = (buffer[index+1]>>0)&0xff;
  76.         dbgIrTxMsg.Data[4] = (buffer[index+2]>>8)&0xff;
  77.         dbgIrTxMsg.Data[5] = (buffer[index+2]>>0)&0xff;
  78.         dbgIrTxMsg.Data[6] = (buffer[index+3]>>8)&0xff;
  79.         dbgIrTxMsg.Data[7] = (buffer[index+3]>>0)&0xff;
  80.                
  81.         /* buffers will be filled when sending more than 2-3 messages, so retry until sent */
  82.         while (StdCan_Put(&dbgIrTxMsg) != StdCan_Ret_OK) {}
  83.         _delay_ms(1);
  84.     }
  85.    
  86.     uint8_t lastpacketcnt = len&0x03;
  87.     if (lastpacketcnt > 0) {
  88.         dbgIrTxMsg.Length = lastpacketcnt<<1;
  89.         for (uint8_t i = 0; i < lastpacketcnt; i++) {
  90.             dbgIrTxMsg.Data[i<<1] = (buffer[(len&0xfc)|i]>>8)&0xff;
  91.             dbgIrTxMsg.Data[(i<<1)+1] = (buffer[(len&0xfc)|i]>>0)&0xff;
  92.         }
  93.         /* buffers will be filled when sending more than 2-3 messages, so retry until sent */
  94.         while (StdCan_Put(&dbgIrTxMsg) != StdCan_Ret_OK) {}
  95.         _delay_ms(1);
  96.     }
  97.  
  98. }
  99. #endif
  100.  
  101. #define sns_irTransceive_BaseFrq (4145146ULL)
  102.  
  103. #ifndef sns_irTransceive_PRONTO_SUPPORT
  104. #define sns_irTransceive_PRONTO_SUPPORT 0
  105. #endif
  106.  
  107. #if sns_irTransceive_PRONTO_SUPPORT==1
  108. volatile uint32_t sns_irTransceive_LastPronto=0;
  109. static uint8_t activeChannel = 0;
  110. #define sns_irTransceive_MAXTIMING (16*1000)
  111.  
  112. void send_pronto(uint16_t *buffer, uint8_t len, uint8_t channel, uint8_t modfreq) {
  113.     StdCan_Msg_t msg;
  114.  
  115.     StdCan_Set_class(msg.Header, CAN_MODULE_CLASS_SNS);
  116.     StdCan_Set_direction(msg.Header, DIRECTIONFLAG_FROM_OWNER);
  117.     msg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  118.     msg.Header.ModuleId = sns_irTransceive_ID;
  119.    
  120.     /* Send timing command */
  121.     msg.Length = 5;
  122.     msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOTIMING;
  123.     uint32_t currentTime=Timer_GetTicks();
  124.     if ((currentTime < sns_irTransceive_LastPronto+sns_irTransceive_MAXTIMING) && (sns_irTransceive_LastPronto != 0))
  125.     {
  126.         msg.Data[0] = 0xff;
  127.         msg.Data[1] = 0x10;
  128.         msg.Data[2] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>16)&0xff;
  129.         msg.Data[3] = (((currentTime-sns_irTransceive_LastPronto)*1000)>>8)&0xff;
  130.         msg.Data[4] = ((currentTime-sns_irTransceive_LastPronto)*1000)&0xff;
  131.         while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  132.         _delay_ms(1);
  133.     }
  134.     sns_irTransceive_LastPronto=currentTime;
  135.  
  136.     /* Send pronto start */
  137.     msg.Length = 8;
  138.     msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTART;
  139.  
  140.     msg.Data[0] = ((channel<<4)|0x0);   /* Channel and Prontoformat 0x000 */
  141.     msg.Data[1] = 0x00;
  142.     msg.Data[2] = 0x00; /* Freq divider */
  143.     msg.Data[3] = modfreq;
  144.     msg.Data[4] = 0x00; /* Once seq length, first byte always 0 */
  145.     msg.Data[5] = len/2;
  146.     msg.Data[6] = 0x00; /* Repeat seq length, always 0 for ir receive */
  147.     msg.Data[7] = 0x00;
  148.    
  149.     while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  150.     _delay_ms(1);
  151.  
  152.     /* Send pronto data */
  153.     uint16_t divider = ((1000000ULL*modfreq)/sns_irTransceive_BaseFrq);
  154.     msg.Header.Command = CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1;
  155.     /* Counter for buffer */
  156.     uint8_t i = 0;
  157.     /* Counter for filling can frame data */
  158.     uint8_t j = 0;
  159.     /* Remember byte if data does not fit 8 bit */
  160.     uint8_t mem = 0;
  161.     while (i < len)
  162.     {
  163.         if (mem > 0)
  164.         {
  165.             /* If byte was memorized then buffer it */
  166.             msg.Data[j] = mem;
  167.             /* Clear memory */
  168.             mem = 0;
  169.         }
  170.         else
  171.         {
  172.             uint16_t data = buffer[i]/divider;
  173.             if (data >= 256)
  174.             {
  175.                 /* If data does not fit into 8 bit, then split, memorize low byte */
  176.                 mem = data&0xff;
  177.                 /* Buffer high byte */
  178.                 msg.Data[j] = (data>>8)&0xff;
  179.                 j++;
  180.                 if (j==8)
  181.                 {
  182.                     /* If send buffer is full, send frame */
  183.                     /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */
  184.                     while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  185.                     _delay_ms(1);
  186.                     j=0;
  187.                     msg.Header.Command++;
  188.                 }
  189.                 /* Set complementary burst pair to 0 to indicate 16bit transmission */
  190.                 msg.Data[j] = 0;
  191.             }
  192.             else
  193.             {
  194.                 msg.Data[j] = data&0xff;
  195.             }
  196.            
  197.             i++;
  198.         }
  199.        
  200.         j++;
  201.         if (j==8)
  202.         {
  203.             /* If send buffer is full, send frame */
  204.             /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */
  205.             while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  206.             _delay_ms(1);
  207.             j=0;
  208.             msg.Header.Command++;
  209.         }
  210.     }
  211.    
  212.     /* End with 25ms, TODO fix uglyness */
  213.     msg.Data[j] = ((IR_MAX_PULSE_WIDTH/divider)>>8)&0xff;
  214.     j++;
  215.     if (j==8)
  216.     {
  217.         /* If send buffer is full, send frame */
  218.         /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */
  219.         while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  220.         _delay_ms(1);
  221.         j=0;
  222.         msg.Header.Command++;
  223.     }
  224.     msg.Data[j] = 0;
  225.     j++;
  226.     msg.Data[j] = (IR_MAX_PULSE_WIDTH/divider)&0xff;
  227.     j++;
  228.     if (j==8)
  229.     {
  230.         /* If send buffer is full, send frame */
  231.         /* can buffers will be filled when sending more than 2-3 messages, so retry until sent */
  232.         while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  233.         _delay_ms(1);
  234.         j=0;
  235.         msg.Header.Command++;
  236.     }
  237.    
  238.     /* Msg command kept from for loop, but increase 16 to send ProntoEnd */
  239.     msg.Header.Command+=16;
  240.     msg.Length = j;
  241.     /* data kept from loop, if any */
  242.     /* buffers will be filled when sending more than 2-3 messages, so retry until sent */
  243.     while (StdCan_Put(&msg) != StdCan_Ret_OK) {}
  244.     _delay_ms(1);
  245. }
  246. #endif
  247.  
  248.  
  249. #if IR_RX_ENABLE==1
  250. void sns_irTransceive_RX_done_callback(uint8_t channel, uint16_t *buffer, uint8_t len)
  251. {
  252.     if (channel < IR_SUPPORTED_NUM_CHANNELS)
  253.     {
  254.         irRxChannel[channel].newData = TRUE;
  255.         irRxChannel[channel].rxlen = len;
  256.     }
  257. }
  258. #endif
  259.  
  260.  
  261. #if IR_TX_ENABLE==1
  262. void sns_irTransceive_TX_done_callback(uint8_t channel)
  263. {
  264.     if (channel < IR_SUPPORTED_NUM_CHANNELS)
  265.     {
  266.         irTxChannel[channel].sendComplete = TRUE;
  267.     }
  268. }
  269. #endif
  270.  
  271.  
  272. void sns_irTransceive_setConfig(uint8_t channel, uint8_t config, uint8_t power, uint8_t modfreq)
  273. {
  274.     if (channel < IR_SUPPORTED_NUM_CHANNELS && config <= CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_RECEIVE && power < 4)
  275.     {
  276. #if IR_RX_ENABLE==1
  277.         if (config == CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_RECEIVE)
  278.         {
  279. #if IR_TX_ENABLE==1
  280.             irTxChannel[channel].state = sns_irTransceive_STATE_DISABLED;
  281. #endif
  282.             irRxChannel[channel].modfreq = modfreq;
  283.             irRxChannel[channel].rxbuf = buf[channel];
  284.             switch (channel)
  285.             {
  286.                 case 0:
  287.                     gpio_clr_pin(sns_irTransceive_VCC_EN0_PIN);
  288.                     IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN);
  289.                     break;
  290.                 case 1:
  291.                     gpio_clr_pin(sns_irTransceive_VCC_EN1_PIN);
  292.                     IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN);
  293.                     break;
  294.                 case 2:
  295.                     gpio_clr_pin(sns_irTransceive_VCC_EN2_PIN);
  296.                     IrTransceiver_InitRxChannel(channel, irRxChannel[channel].rxbuf, sns_irTransceive_RX_done_callback, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN);
  297.                     break;
  298.             }
  299.             irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING;
  300.         }
  301. #endif
  302.  
  303. #if IR_TX_ENABLE==1
  304.         if (config == CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_TRANSMIT)
  305.         {
  306. #if IR_RX_ENABLE==1
  307.             irRxChannel[channel].state = sns_irTransceive_STATE_DISABLED;
  308. #endif
  309.             irTxChannel[channel].modfreq = modfreq;
  310.             irTxChannel[channel].txbuf = buf[channel];
  311.             switch (channel)
  312.             {
  313.                 case 0:
  314. #if IR_RX_ENABLE==1
  315.                     gpio_set_pin(sns_irTransceive_VCC_EN0_PIN);
  316.                     IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX0_PCINT, sns_irTransceive_RX0_PIN);
  317. #endif
  318.                     IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX0_PIN);
  319.  
  320. #if sns_irTransceive_ENABLE_PCA95xx==1
  321.                     Pca95xx_set_out(sns_irTransceive_TX0_PWRl);
  322.                     Pca95xx_set_out(sns_irTransceive_TX0_PWRh);
  323.                     if (power&0x1)
  324.                     {
  325.                         Pca95xx_set_in(sns_irTransceive_TX0_PWRl);
  326.                     }
  327.                     if (power&0x2)
  328.                     {
  329.                         Pca95xx_set_in(sns_irTransceive_TX0_PWRh);
  330.                     }
  331. #endif
  332.                     break;
  333.                 case 1:
  334. #if IR_RX_ENABLE==1
  335.                     gpio_set_pin(sns_irTransceive_VCC_EN1_PIN);
  336.                     IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX1_PCINT, sns_irTransceive_RX1_PIN);
  337. #endif
  338.                     IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX1_PIN);
  339.                    
  340. #if sns_irTransceive_ENABLE_PCA95xx==1
  341.                     Pca95xx_set_out(sns_irTransceive_TX1_PWRl);
  342.                     Pca95xx_set_out(sns_irTransceive_TX1_PWRh);
  343.                     if (power&0x1)
  344.                     {
  345.                         Pca95xx_set_in(sns_irTransceive_TX1_PWRl);
  346.                     }
  347.                     if (power&0x2)
  348.                     {
  349.                         Pca95xx_set_in(sns_irTransceive_TX1_PWRh);
  350.                     }
  351. #endif
  352.                     break;
  353.                 case 2:
  354. #if IR_RX_ENABLE==1
  355.                     gpio_set_pin(sns_irTransceive_VCC_EN2_PIN);
  356.                     IrTransceiver_DeInitRxChannel(channel, sns_irTransceive_RX2_PCINT, sns_irTransceive_RX2_PIN);
  357. #endif
  358.                     IrTransceiver_InitTxChannel(channel, sns_irTransceive_TX_done_callback, sns_irTransceive_TX2_PIN);
  359.                    
  360. #if sns_irTransceive_ENABLE_PCA95xx==1
  361.                     Pca95xx_set_out(sns_irTransceive_TX2_PWRl);
  362.                     Pca95xx_set_out(sns_irTransceive_TX2_PWRh);
  363.                     if (power&0x1)
  364.                     {
  365.                         Pca95xx_set_in(sns_irTransceive_TX2_PWRl);
  366.                     }
  367.                     if (power&0x2)
  368.                     {
  369.                         Pca95xx_set_in(sns_irTransceive_TX2_PWRh);
  370.                     }
  371. #endif
  372.                     break;
  373.             }
  374.             irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
  375.         }
  376. #endif
  377.     }
  378. }
  379.  
  380.  
  381. void sns_irTransceive_Init(void)
  382. {
  383.     StdCan_Set_class(irTxMsg.Header, CAN_MODULE_CLASS_SNS);
  384.     StdCan_Set_direction(irTxMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  385.     irTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  386.     irTxMsg.Header.ModuleId = sns_irTransceive_ID;
  387.     irTxMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_IR;
  388.     irTxMsg.Length = 6;
  389.  
  390.     for (uint8_t i = 0; i < IR_SUPPORTED_NUM_CHANNELS; i++)
  391.     {
  392. #if IR_RX_ENABLE==1
  393.         irRxChannel[i].state = sns_irTransceive_STATE_DISABLED;
  394.         irRxChannel[i].newData = FALSE;
  395.         irRxChannel[i].rxlen = 0;
  396.         irRxChannel[i].proto.timeout=0;
  397.         irRxChannel[i].proto.data=0;
  398.         irRxChannel[i].proto.repeats=0;
  399.         irRxChannel[i].proto.protocol=0;
  400. #endif
  401.  
  402. #if IR_TX_ENABLE==1
  403.         irTxChannel[i].state = sns_irTransceive_STATE_DISABLED;
  404.         irTxChannel[i].sendComplete = FALSE;
  405.         irTxChannel[i].repeatCount = 0;
  406.         irTxChannel[i].txlen = 0;
  407.         irTxChannel[i].proto.data=0;
  408.         irTxChannel[i].proto.repeats=0;
  409.         irTxChannel[i].proto.framecnt=0;
  410.         irTxChannel[i].proto.protocol=0;
  411. #endif
  412.     }
  413.    
  414. #if IR_RX_ENABLE==1
  415.     // TODO: hardcoded to 3 channels?? /jm
  416.     irRxChannel[0].timerNum=sns_irTransceive_RX0_REPEATE_TIMER;
  417.     irRxChannel[1].timerNum=sns_irTransceive_RX1_REPEATE_TIMER;
  418.     irRxChannel[2].timerNum=sns_irTransceive_RX2_REPEATE_TIMER;
  419. #endif
  420.  
  421. #if IR_TX_ENABLE==1
  422.     // TODO: hardcoded to 3 channels?? /jm
  423.     irTxChannel[0].timerNum=sns_irTransceive_TX0_REPEATE_TIMER;
  424.     irTxChannel[1].timerNum=sns_irTransceive_TX1_REPEATE_TIMER;
  425.     irTxChannel[2].timerNum=sns_irTransceive_TX2_REPEATE_TIMER;
  426. #endif
  427.    
  428.     IrTransceiver_Init();
  429.     /* Configure all TX VCC pins as outputs and disable them */
  430.     gpio_set_out(sns_irTransceive_VCC_EN0_PIN);
  431.     gpio_set_out(sns_irTransceive_VCC_EN1_PIN);
  432.     gpio_set_out(sns_irTransceive_VCC_EN2_PIN);
  433.     gpio_set_pin(sns_irTransceive_VCC_EN0_PIN);
  434.     gpio_set_pin(sns_irTransceive_VCC_EN1_PIN);
  435.     gpio_set_pin(sns_irTransceive_VCC_EN2_PIN);
  436.  
  437. #if IR_TX_ENABLE==1
  438.     gpio_set_out(sns_irTransceive_MOD_PIN);
  439.     gpio_set_out(sns_irTransceive_TX0_PIN);
  440.     gpio_set_out(sns_irTransceive_TX1_PIN);
  441.     gpio_set_out(sns_irTransceive_TX2_PIN);
  442. #if IR_TX_ACTIVE_LOW==1
  443.     gpio_set_pin(sns_irTransceive_TX0_PIN);
  444.     gpio_set_pin(sns_irTransceive_TX1_PIN);
  445.     gpio_set_pin(sns_irTransceive_TX2_PIN);
  446. #endif
  447. #endif
  448.    
  449.     /* IR tx power pins on PCA95xx */
  450. #if sns_irTransceive_ENABLE_PCA95xx==1
  451.     Pca95xx_Init(0);
  452.  
  453.     Pca95xx_clr_pin(sns_irTransceive_TX0_PWRl);
  454.     Pca95xx_set_out(sns_irTransceive_TX0_PWRl);
  455.     Pca95xx_clr_pin(sns_irTransceive_TX0_PWRh);
  456.     Pca95xx_set_out(sns_irTransceive_TX0_PWRh);
  457.    
  458.     Pca95xx_clr_pin(sns_irTransceive_TX1_PWRl);
  459.     Pca95xx_set_out(sns_irTransceive_TX1_PWRl);
  460.     Pca95xx_clr_pin(sns_irTransceive_TX1_PWRh);
  461.     Pca95xx_set_out(sns_irTransceive_TX1_PWRh);
  462.    
  463.     Pca95xx_clr_pin(sns_irTransceive_TX2_PWRl);
  464.     Pca95xx_set_out(sns_irTransceive_TX2_PWRl);
  465.     Pca95xx_clr_pin(sns_irTransceive_TX2_PWRh);
  466.     Pca95xx_set_out(sns_irTransceive_TX2_PWRh);
  467. #endif
  468.  
  469. #ifdef sns_irTransceive_USEEEPROM
  470.     if (EEDATA_OK)
  471.     {
  472.       /* Use stored data to set initial values for the module */
  473.         sns_irTransceive_setConfig(0, eeprom_read_byte(EEDATA.ch0_config), eeprom_read_byte(EEDATA.ch0_txpower), eeprom_read_byte(EEDATA.ch0_modfreq));
  474.         sns_irTransceive_setConfig(1, eeprom_read_byte(EEDATA.ch1_config), eeprom_read_byte(EEDATA.ch1_txpower), eeprom_read_byte(EEDATA.ch1_modfreq));
  475.         sns_irTransceive_setConfig(2, eeprom_read_byte(EEDATA.ch2_config), eeprom_read_byte(EEDATA.ch2_txpower), eeprom_read_byte(EEDATA.ch2_modfreq));
  476.     }
  477.     else
  478.     {  
  479.     /* The CRC of the EEPROM is not correct, store default values and update CRC */
  480.         eeprom_write_byte_crc(EEDATA.ch0_config, CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO, WITHOUT_CRC);
  481.         eeprom_write_byte_crc(EEDATA.ch0_txpower, 0, WITHOUT_CRC);
  482.         eeprom_write_byte_crc(EEDATA.ch0_modfreq, sns_irTransceive_BaseFrq/38000, WITHOUT_CRC);
  483.         eeprom_write_byte_crc(EEDATA.ch1_config, CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO, WITHOUT_CRC);
  484.         eeprom_write_byte_crc(EEDATA.ch1_txpower, 0, WITHOUT_CRC);
  485.         eeprom_write_byte_crc(EEDATA.ch1_modfreq, sns_irTransceive_BaseFrq/38000, WITHOUT_CRC);
  486.         eeprom_write_byte_crc(EEDATA.ch2_config, CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_AUTO, WITHOUT_CRC);
  487.         eeprom_write_byte_crc(EEDATA.ch2_txpower, 0, WITHOUT_CRC);
  488.         eeprom_write_byte_crc(EEDATA.ch2_modfreq, sns_irTransceive_BaseFrq/38000, WITHOUT_CRC);
  489.         EEDATA_UPDATE_CRC;
  490.     }
  491. #endif 
  492. }
  493.  
  494. void sns_irTransceive_Process(void)
  495. {
  496.     for (uint8_t channel=0; channel < IR_SUPPORTED_NUM_CHANNELS; channel++)
  497.     {
  498.  
  499. #if IR_RX_ENABLE==1
  500.         switch (irRxChannel[channel].state)
  501.         {
  502.         case sns_irTransceive_STATE_IDLE:
  503.             irRxChannel[channel].state = sns_irTransceive_STATE_START_RECEIVE;
  504.             break;
  505.  
  506.         case sns_irTransceive_STATE_START_RECEIVE:
  507.             IrTransceiver_ResetRx(channel);
  508.             cli();
  509.             irRxChannel[channel].newData = FALSE;
  510.             sei();
  511.             irRxChannel[channel].state = sns_irTransceive_STATE_RECEIVING;
  512.             break;
  513.        
  514.         case sns_irTransceive_STATE_RECEIVING:
  515.             if (irRxChannel[channel].newData == TRUE) {
  516.                 //TODO: move this line to the RX callback
  517.                 IrTransceiver_DisableRx(channel);
  518.                 cli();
  519.                 irRxChannel[channel].newData = FALSE;
  520.                 sei();
  521.  
  522.                 /* Let protocol driver parse and then send on CAN */
  523.                 uint8_t res2 = parseProtocol(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen, &irRxChannel[channel].proto);
  524.                 if (res2 == IR_OK && irRxChannel[channel].proto.protocol != IR_PROTO_UNKNOWN) {
  525.                     irTxMsg.Data[0] = 0xf&CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED;
  526.                     irTxMsg.Data[0] |= channel<<4;
  527.                     irTxMsg.Data[1] = irRxChannel[channel].proto.protocol;
  528.                     irTxMsg.Data[2] = (irRxChannel[channel].proto.data>>24)&0xff;
  529.                     irTxMsg.Data[3] = (irRxChannel[channel].proto.data>>16)&0xff;
  530.                     irTxMsg.Data[4] = (irRxChannel[channel].proto.data>>8)&0xff;
  531.                     irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff;
  532.  
  533.                     StdCan_Put(&irTxMsg);
  534.                 }
  535.                 else if (irRxChannel[channel].proto.protocol == IR_PROTO_UNKNOWN)
  536.                 {
  537. #if (sns_irTransceive_SEND_DEBUG==1)
  538.                     send_debug(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen);
  539.                     irRxChannel[channel].proto.timeout=300;
  540. #elif sns_irTransceive_PRONTO_SUPPORT==1
  541.                     send_pronto(irRxChannel[channel].rxbuf, irRxChannel[channel].rxlen, channel, irRxChannel[channel].modfreq);
  542.                     irRxChannel[channel].proto.timeout=1;
  543. #endif
  544.                 }
  545.  
  546.                 /* Enable the receiver again */
  547.                 IrTransceiver_EnableRx(channel);
  548.  
  549.                 irRxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE;
  550.             }
  551.             break;
  552.  
  553.         case sns_irTransceive_STATE_START_PAUSE:
  554.             /* set a timer so we can send release button event when no new IR is arriving */
  555.             Timer_SetTimeout(irRxChannel[channel].timerNum, irRxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
  556.             irRxChannel[channel].state = sns_irTransceive_STATE_PAUSING;
  557.             break;
  558.  
  559.         case sns_irTransceive_STATE_PAUSING:
  560.             /* reset timer if new IR arrived */
  561.             if (irRxChannel[channel].newData == TRUE || IrTransceiver_GetStoreEnableRx(channel) == TRUE) {
  562.                 cli();
  563.                 irRxChannel[channel].newData = FALSE;
  564.                 sei();
  565.                 Timer_SetTimeout(irRxChannel[channel].timerNum, irRxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
  566.             }
  567.        
  568.             if (Timer_Expired(irRxChannel[channel].timerNum)) {
  569.                 irRxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
  570.             }
  571.             break;
  572.  
  573.         case sns_irTransceive_STATE_START_IDLE:
  574.             if (irRxChannel[channel].proto.protocol != IR_PROTO_UNKNOWN) {
  575.                 /* Send button release command on CAN */
  576.                 irTxMsg.Data[0] = 0xf&CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED;
  577.                 irTxMsg.Data[0] |= channel<<4;
  578.                 irTxMsg.Data[1] = irRxChannel[channel].proto.protocol;
  579.                 irTxMsg.Data[2] = (irRxChannel[channel].proto.data>>24)&0xff;
  580.                 irTxMsg.Data[3] = (irRxChannel[channel].proto.data>>16)&0xff;
  581.                 irTxMsg.Data[4] = (irRxChannel[channel].proto.data>>8)&0xff;
  582.                 irTxMsg.Data[5] = irRxChannel[channel].proto.data&0xff;
  583.  
  584.                 StdCan_Put(&irTxMsg);
  585.             }
  586.             irRxChannel[channel].state = sns_irTransceive_STATE_IDLE;
  587.             break;
  588.  
  589.         default:
  590.             break;
  591.         }
  592. #endif
  593.  
  594. #if IR_TX_ENABLE==1
  595.         switch (irTxChannel[channel].state)
  596.         {
  597.         case sns_irTransceive_STATE_IDLE:
  598.             /* transmission is started when a command is received on can */
  599.             break;
  600.  
  601.         case sns_irTransceive_STATE_START_TRANSMIT:
  602.             if (expandProtocol(irTxChannel[channel].txbuf, &irTxChannel[channel].txlen, &irTxChannel[channel].proto) == IR_OK)
  603.             {
  604.                 IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen);
  605.                 irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING;
  606.             }
  607.             else
  608.             {
  609.                 irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
  610.             }
  611.             break;
  612.  
  613.         case sns_irTransceive_STATE_START_TRANSMIT_PRONTO:
  614.             IrTransceiver_Transmit(channel, irTxChannel[channel].txbuf, 0, irTxChannel[channel].txlen);
  615.             irTxChannel[channel].state = sns_irTransceive_STATE_TRANSMITTING;
  616.             irTxChannel[channel].sendingPronto = TRUE;
  617.             break;
  618.            
  619.         case sns_irTransceive_STATE_TRANSMITTING:
  620.             if (irTxChannel[channel].sendComplete == TRUE)
  621.             {
  622.                 cli();
  623.                 irTxChannel[channel].sendComplete = FALSE;
  624.                 sei();
  625.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_PAUSE;
  626.             }
  627.             break;
  628.  
  629.         case sns_irTransceive_STATE_START_PAUSE:
  630.             if (irTxChannel[channel].repeatCount < irTxChannel[channel].proto.repeats)
  631.             {
  632.                 irTxChannel[channel].repeatCount++;
  633.             }
  634.            
  635.             Timer_SetTimeout(irTxChannel[channel].timerNum, irTxChannel[channel].proto.timeout, TimerTypeOneShot, 0);
  636.  
  637.             if (irTxChannel[channel].proto.framecnt != 255)
  638.             {
  639.                 irTxChannel[channel].proto.framecnt++;
  640.             }
  641.            
  642.             irTxChannel[channel].state = sns_irTransceive_STATE_PAUSING;
  643.             break;
  644.  
  645.         case sns_irTransceive_STATE_PAUSING:
  646.             if (Timer_Expired(irTxChannel[channel].timerNum))
  647.             {
  648.                 if (irTxChannel[channel].sendingPronto) {
  649.                     irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT_PRONTO;
  650.                 }
  651.                 else {
  652.                     irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT;
  653.                 }
  654.             }
  655.            
  656.             /* transmission is stopped when such command is recevied on can */
  657.             if (irTxChannel[channel].stopSend == TRUE && irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats)
  658.             {
  659.                 //TODO maybe send message on can for status? to confirm stopped sending, ready for new command
  660.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
  661.             }
  662.  
  663.             if (irTxChannel[channel].sendingPronto &&  irTxChannel[channel].repeatCount >= irTxChannel[channel].proto.repeats)
  664.             {
  665.                 irTxChannel[channel].state = sns_irTransceive_STATE_START_IDLE;
  666.             }
  667.  
  668.             break;
  669.  
  670.         case sns_irTransceive_STATE_START_IDLE:
  671.             irTxChannel[channel].stopSend = FALSE;
  672.             irTxChannel[channel].repeatCount = 0;
  673.             irTxChannel[channel].proto.framecnt = 0;
  674.             irTxChannel[channel].sendingPronto = FALSE;
  675.  
  676.             irTxChannel[channel].state = sns_irTransceive_STATE_IDLE;
  677.             break;
  678.  
  679.         default:
  680.             break;
  681.         }
  682. #endif
  683.  
  684.     }
  685. }
  686.  
  687.  
  688. /* Handle incoming CAN data */
  689. void sns_irTransceive_HandleMessage(StdCan_Msg_t *rxMsg)
  690. {
  691.     if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
  692.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
  693.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_IRTRANSCEIVE &&
  694.         rxMsg->Header.ModuleId == sns_irTransceive_ID)
  695.     {
  696.         switch (rxMsg->Header.Command)
  697.         {
  698. #if IR_TX_ENABLE==1
  699.         case CAN_MODULE_CMD_PHYSICAL_IR: {
  700.             uint8_t channel = rxMsg->Data[0]>>4;
  701.             if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_PRESSED && channel < IR_SUPPORTED_NUM_CHANNELS)
  702.             {
  703.                 if (irTxChannel[channel].state == sns_irTransceive_STATE_IDLE)
  704.                 {
  705.                     irTxChannel[channel].proto.protocol = rxMsg->Data[1];
  706.  
  707.                     irTxChannel[channel].proto.data = rxMsg->Data[2];
  708.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  709.                     irTxChannel[channel].proto.data |= rxMsg->Data[3];
  710.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  711.                     irTxChannel[channel].proto.data |= rxMsg->Data[4];
  712.                     irTxChannel[channel].proto.data = irTxChannel[channel].proto.data<<8;
  713.                     irTxChannel[channel].proto.data |= rxMsg->Data[5];
  714.  
  715.                     irTxChannel[channel].state = sns_irTransceive_STATE_START_TRANSMIT;
  716.                 }
  717.             }
  718.             else if ((0xf&rxMsg->Data[0]) == CAN_MODULE_ENUM_PHYSICAL_IR_STATUS_RELEASED && channel < IR_SUPPORTED_NUM_CHANNELS)
  719.             {
  720.                 if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE)
  721.                 {
  722.                     irTxChannel[channel].stopSend = TRUE;
  723.                 }
  724.             }
  725.             break;
  726.         }
  727.        
  728. #if sns_irTransceive_PRONTO_SUPPORT==1
  729.         /* TODO: add struct which stores pronto info:
  730.         channel, pronto receive state, buffer length of once burst pairs, buffer length of repeat burst pairs */
  731.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTART: {
  732.  
  733.             uint8_t channel = rxMsg->Data[0]>>4;
  734.             if (channel >= IR_SUPPORTED_NUM_CHANNELS) {
  735.                 // invalid channel
  736.                 break;
  737.             }
  738.  
  739.             printf("TxSt=%03d", irTxChannel[channel].state);
  740.  
  741.             if (irTxChannel[channel].state != sns_irTransceive_STATE_IDLE) {
  742.                 // busy
  743.                 break;
  744.             }
  745.  
  746.             /* TODO: check pronto state, response is different if already sending data */
  747.             uint16_t format = (uint16_t)(rxMsg->Data[0] & 0x0F) << 8 | (uint16_t)(rxMsg->Data[1]);
  748.             if (format != 0) {
  749.                 // unsupported format
  750.                 break;
  751.             }
  752.  
  753.             irTxChannel[channel].state = sns_irTransceive_STATE_PREPARING_PRONTO;
  754.             irTxChannel[channel].txlen = 0;
  755.            
  756.             //irTxChannel[channel].modfreq = rxMsg->Data[2];
  757.             irTxChannel[channel].modfreq = (((F_CPU/2000)/IR_NEC_F_MOD) -1); // for testing
  758.             irTxChannel[channel].proto.modfreq = (((F_CPU/2000)/IR_NEC_F_MOD) -1);
  759.             irTxChannel[channel].proto.timeout = 100;
  760.             irTxChannel[channel].proto.repeats = 2;
  761.  
  762.             irTxChannel[channel].onceSeqLen = rxMsg->Data[3];
  763.             irTxChannel[channel].repSeqLen = rxMsg->Data[4];
  764.  
  765.             activeChannel = channel;
  766.  
  767.             /* TODO: Send response frame */
  768.             break;
  769.         }
  770.  
  771.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOSTOP:
  772.             /* TODO: stop sending IR */
  773.            
  774.             /* TODO: Send response frame */
  775.             break;
  776.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOCONTINUE:
  777.             /* TODO: reset timeout to continue sending repeat sequences */
  778.            
  779.             /* TODO: Send response frame */
  780.             break;
  781.  
  782.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA1:  /* Fall through */
  783.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA2:  /* Fall through */
  784.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA3:  /* Fall through */
  785.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA4:  /* Fall through */
  786.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA5:  /* Fall through */
  787.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA6:  /* Fall through */
  788.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA7:  /* Fall through */
  789.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA8:  /* Fall through */
  790.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA9:  /* Fall through */
  791.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA10: /* Fall through */
  792.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA11: /* Fall through */
  793.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA12: /* Fall through */
  794.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA13: /* Fall through */
  795.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA14: /* Fall through */
  796.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA15: /* Fall through */
  797.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTODATA16: {
  798.             if (activeChannel>=IR_SUPPORTED_NUM_CHANNELS) {
  799.                 break;
  800.             }
  801.             if (irTxChannel[activeChannel].state!=sns_irTransceive_STATE_PREPARING_PRONTO) {
  802.                 // invalid state
  803.                 break;
  804.             }
  805.             if ((uint16_t)irTxChannel[activeChannel].txlen+(uint16_t)rxMsg->Length >= MAX_NR_TIMES) {
  806.                 // too long
  807.                 break;
  808.             }
  809.             for (uint8_t i=0; i<rxMsg->Length; i++) {
  810.                 // TODO: (109 * 1) / (4.145146 MHz) = 27, fix formula with modfreq
  811.                 irTxChannel[activeChannel].txbuf[irTxChannel[activeChannel].txlen++] = 27*rxMsg->Data[i];
  812.             }
  813.             break;
  814.         }
  815.  
  816.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND1:   /* Fall through */
  817.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND2:   /* Fall through */
  818.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND3:   /* Fall through */
  819.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND4:   /* Fall through */
  820.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND5:   /* Fall through */
  821.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND6:   /* Fall through */
  822.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND7:   /* Fall through */
  823.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND8:   /* Fall through */
  824.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND9:   /* Fall through */
  825.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND10:  /* Fall through */
  826.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND11:  /* Fall through */
  827.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND12:  /* Fall through */
  828.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND13:  /* Fall through */
  829.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND14:  /* Fall through */
  830.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND15:  /* Fall through */
  831.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND16:  /* Fall through */
  832.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRPRONTOEND17: {
  833.             if (activeChannel>=IR_SUPPORTED_NUM_CHANNELS) {
  834.                 break;
  835.             }
  836.             if (irTxChannel[activeChannel].state!=sns_irTransceive_STATE_PREPARING_PRONTO) {
  837.                 // invalid state
  838.                 break;
  839.             }
  840.             if ((uint16_t)irTxChannel[activeChannel].txlen + (uint16_t)(rxMsg->Length-1) >= MAX_NR_TIMES) {
  841.                 // too long
  842.                 break;
  843.             }
  844.             // end packet does not always contain data, last byte is reserved
  845.             for (uint8_t i=0; i<rxMsg->Length-1; i++) {
  846.                 // TODO: (109 * 1) / (4.145146 MHz) = 27, fix formula with modfreq
  847.                 irTxChannel[activeChannel].txbuf[irTxChannel[activeChannel].txlen++] = 27*rxMsg->Data[i];
  848.             }
  849.             // last byte tells what to do with IR data (nr of repeats)
  850.             irTxChannel[activeChannel].numberOfRepeats = rxMsg->Data[rxMsg->Length-1];
  851.  
  852.             // send
  853.             irTxChannel[activeChannel].state = sns_irTransceive_STATE_START_TRANSMIT_PRONTO;
  854.  
  855.             irTxChannel[activeChannel].sendingPronto = TRUE;
  856.  
  857.             /* TODO: Send response frame */
  858.  
  859.             break;
  860.         }
  861.  
  862. /* TODO: In IR state machine add sending a response frame when ir stops sending, also implement pronto repeat */
  863. #endif
  864. #endif
  865.        
  866.         case CAN_MODULE_CMD_IRTRANSCEIVE_IRCONFIG: {
  867.             uint8_t channel = rxMsg->Data[0]>>4;
  868.             uint8_t config = rxMsg->Data[0] & 0x0f;
  869.             uint8_t power = rxMsg->Data[1]>>6;
  870.             uint8_t modfreq = rxMsg->Data[2];
  871.            
  872.             sns_irTransceive_setConfig(channel, config, power, modfreq);
  873.  
  874. #ifdef sns_irTransceive_USEEEPROM
  875.             if (channel < IR_SUPPORTED_NUM_CHANNELS && config <= CAN_MODULE_ENUM_IRTRANSCEIVE_IRCONFIG_DIRECTION_RECEIVE && power < 4)
  876.             {
  877.                 switch (channel)
  878.                 {
  879.                     case 0:
  880.                         eeprom_write_byte_crc(EEDATA.ch0_config, config, WITHOUT_CRC);
  881.                         eeprom_write_byte_crc(EEDATA.ch0_txpower, power, WITHOUT_CRC);
  882.                         eeprom_write_byte_crc(EEDATA.ch0_modfreq, modfreq, WITHOUT_CRC);
  883.                         break;
  884.                     case 1:
  885.                         eeprom_write_byte_crc(EEDATA.ch1_config, config, WITHOUT_CRC);
  886.                         eeprom_write_byte_crc(EEDATA.ch1_txpower, power, WITHOUT_CRC);
  887.                         eeprom_write_byte_crc(EEDATA.ch1_modfreq, modfreq, WITHOUT_CRC);
  888.                         break;
  889.                     case 2:
  890.                         eeprom_write_byte_crc(EEDATA.ch2_config, config, WITHOUT_CRC);
  891.                         eeprom_write_byte_crc(EEDATA.ch2_txpower, power, WITHOUT_CRC);
  892.                         eeprom_write_byte_crc(EEDATA.ch2_modfreq, modfreq, WITHOUT_CRC);
  893.                         break;
  894.                     default:
  895.                         break;
  896.                 }
  897.                 EEDATA_UPDATE_CRC;
  898.             }
  899. #endif 
  900.             break;
  901.         }
  902.            
  903.         default:
  904.             break;
  905.            
  906.         }
  907.     }
  908. }
  909.  
  910. void sns_irTransceive_List(uint8_t ModuleSequenceNumber)
  911. {
  912.     StdCan_Msg_t txMsg;
  913.    
  914.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  915.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  916.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSCEIVE;
  917.  
  918.     txMsg.Header.ModuleId = sns_irTransceive_ID;
  919.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  920.     txMsg.Length = 6;
  921.  
  922.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  923.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  924.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  925.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  926.    
  927.     txMsg.Data[4] = NUMBER_OF_MODULES;
  928.     txMsg.Data[5] = ModuleSequenceNumber;
  929.    
  930.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  931. }
  932.