void linearAct_sendPosition(uint8_t dummy) {
	StdCan_Msg_t txMsg;
	uint16_t w_tmp;
	
	StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); 
	StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_LINEARACT; 
	txMsg.Header.ModuleId = act_linearAct_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_LINEARACT_POSITION;	
	txMsg.Length = 3;
	
	w_tmp = linearAct_getPosition();
	
	txMsg.Data[0] = w_tmp >> 8;
	txMsg.Data[1] = w_tmp;
	
	txMsg.Data[2] = direction;									

	//while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
	StdCan_Put(&txMsg);										// No problem if we miss one	
}
Beispiel #2
0
void sns_irTransmit_List(uint8_t ModuleSequenceNumber)
{
	StdCan_Msg_t txMsg;
	
	StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
	StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRTRANSMIT;
	txMsg.Header.ModuleId = sns_irTransmit_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
	txMsg.Length = 6;

	txMsg.Data[0] = NODE_HW_ID_BYTE0;
	txMsg.Data[1] = NODE_HW_ID_BYTE1;
	txMsg.Data[2] = NODE_HW_ID_BYTE2;
	txMsg.Data[3] = NODE_HW_ID_BYTE3;
	
	txMsg.Data[4] = NUMBER_OF_MODULES;
	txMsg.Data[5] = ModuleSequenceNumber;
	
	while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
Beispiel #3
0
void sns_rfid_HandleCardEvent( uint8_t event ) {
    StdCan_Msg_t txMsg;

    gpio_set_statement( event, sns_rfid_STATUS_LED );

    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); ///TODO: Change this to the actual class type
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFID; ///TODO: Change this to the actual module type
    txMsg.Header.ModuleId = sns_rfid_ID;
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
    txMsg.Length = 6;

    txMsg.Data[0] = event;
    txMsg.Data[1] =  sns_rfid_card.version;
    txMsg.Data[2] =  sns_rfid_card.id&0xff;
    txMsg.Data[3] = (sns_rfid_card.id>>8)&0xff;
    txMsg.Data[4] = (sns_rfid_card.id>>16)&0xff;
    txMsg.Data[5] = (sns_rfid_card.id>>24)&0xff;

    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
Beispiel #4
0
void act_output_List(uint8_t ModuleSequenceNumber)
{
	StdCan_Msg_t txMsg;
	StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
	StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_OUTPUT;
	txMsg.Header.ModuleId = act_output_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
	txMsg.Length = 6;

	uint32_t HwId=BIOS_GetHwId();
	txMsg.Data[0] = HwId&0xff;
	txMsg.Data[1] = (HwId>>8)&0xff;
	txMsg.Data[2] = (HwId>>16)&0xff;
	txMsg.Data[3] = (HwId>>24)&0xff;
	
	txMsg.Data[4] = NUMBER_OF_MODULES;
	txMsg.Data[5] = ModuleSequenceNumber;
	
	while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
void sns_BusVoltage_Process(void)
{
	///TODO: Stuff that needs doing is done here
	if (Timer_Expired(sns_BusVoltage_TIMER)) {
		uint16_t busVoltage = ADC_Get(BUSVOLTAGEAD);
		busVoltage = (busVoltage & 0x03ff) * ADC_FACTOR;
		
		StdCan_Msg_t txMsg;
		StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
		StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
		txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_BUSVOLTAGE;
		txMsg.Header.ModuleId = sns_BusVoltage_ID;
		txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_VOLTAGE;
		txMsg.Length = 3;
		txMsg.Data[0] = 0;
		txMsg.Data[1] = (busVoltage>>(ADC_SCALE-6+8))&0xff;
		txMsg.Data[2] = (busVoltage>>(ADC_SCALE-6))&0xff;

		StdCan_Put(&txMsg);
	}
}
Beispiel #6
0
void ReadTemperature(void)
{
	static uint8_t SearchSensorsTimeout = sns_ds18x20_SEARCH_TIMEOUT;
	static uint8_t CurrentSensor = 0;
	uint8_t subzero, cel, cel_frac_bits = 0;
	StdCan_Msg_t txMsg;

	StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
	StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_DS18X20;
	txMsg.Header.ModuleId = sns_ds18x20_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_TEMPERATURE_CELSIUS;
	txMsg.Length = 3;

	txMsg.Data[0] = SensorIds[CurrentSensor];

	if (DS18X20_read_meas(&gSensorIDs[CurrentSensor][0], &subzero, &cel, &cel_frac_bits) == DS18X20_OK)
	{
		int16_t temp = cel;

		temp = temp << 6;

		temp += (cel_frac_bits << 2);

		if (subzero)
		{
			temp = -temp;
		}

		txMsg.Data[1] = (uint8_t)(temp >> 8);
		txMsg.Data[2] = (uint8_t)(temp & 0xff);

#ifdef CHN_LOADED
		for( uint8_t i=0; i<DS18x20_MAXSENSORS; i++) {
			if( sns_ds18s20_sensorids[i] == SensorIds[CurrentSensor] ) {
			        chn_ChnMaster_UpdateChannel( sns_ds18x20_CHN_CHANNEL + i, (temp<<2) + 25600 );
			}
		}
#endif
	}
Beispiel #7
0
void sns_rfid_List(uint8_t ModuleSequenceNumber)
{
    StdCan_Msg_t txMsg;

    StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS); ///TODO: Change this to the actual class type
    StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
    txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_RFID; ///TODO: Change this to the actual module type
    txMsg.Header.ModuleId = sns_rfid_ID;
    txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
    txMsg.Length = 6;

    uint32_t HwId=BIOS_GetHwId();
    txMsg.Data[0] = HwId&0xff;
    txMsg.Data[1] = (HwId>>8)&0xff;
    txMsg.Data[2] = (HwId>>16)&0xff;
    txMsg.Data[3] = (HwId>>24)&0xff;

    txMsg.Data[4] = NUMBER_OF_MODULES;
    txMsg.Data[5] = ModuleSequenceNumber;

    while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
Beispiel #8
0
void linearAct_sendLimits (uint8_t dummy) {
	StdCan_Msg_t txMsg;

	StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); 
	StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_LINEARACT; 
	txMsg.Header.ModuleId = act_linearAct_ID;
	txMsg.Header.Command = CAN_MODULE_CMD_LINEARACT_LIMITS;	
	txMsg.Length = 8;
	
	txMsg.Data[0] = min >> 8;
	txMsg.Data[1] = min;
		
	txMsg.Data[2] = low >> 8;
	txMsg.Data[3] = low;
			
	txMsg.Data[4] = high >> 8;
	txMsg.Data[5] = high;

	txMsg.Data[6] = max >> 8;
	txMsg.Data[7] = max;
		
	while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
}
void act_protectedOutput_HandleMessage(StdCan_Msg_t *rxMsg) {
	if (	StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
		StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
		rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_PROTECTEDOUTPUT && 
		rxMsg->Header.ModuleId == act_protectedOutput_ID)
	{
		switch (rxMsg->Header.Command) {
			
			case CAN_MODULE_CMD_PHYSICAL_SETPIN:
				/*
				 * This message is used to activate/deactivate
				 * an output channel.
				 */
				if (rxMsg->Length == 2) {
					uint8_t channel = rxMsg->Data[0];
					if (channel >= 0 && channel < act_protectedOutput_CH_COUNT) {
						chTargetState[channel] = rxMsg->Data[1];
						readDiagPin();
#if act_protectedOutput_FORCED_RETRIES == 1
						updateOutput(1);
#else
						updateOutput(0);
#endif
#if act_protectedOutput_EEPROM_ENABLED == 1
						// output states changed, store to EE after this timer delay
						Timer_SetTimeout(act_protectedOutput_STORE_VALUE_TIMEOUT, act_protectedOutput_STORE_VALUE_TIMEOUT_TIME_S*1000, TimerTypeOneShot, 0);
#endif
					}
					StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER);
					rxMsg->Length = 2;
					while (StdCan_Put(rxMsg) != StdCan_Ret_OK);
				}
				break;
		}
	}
}
Beispiel #10
0
void send_debug(uint16_t *buffer, uint8_t len) {

	/* the protocol is unknown so the raw ir-data is sent, makes it easier to develop a new protocol */

	StdCan_Set_class(irTxMsg.Header, CAN_MODULE_CLASS_SNS);
	StdCan_Set_direction(irTxMsg.Header, DIRECTIONFLAG_FROM_OWNER);
	irTxMsg.Length = 8;
	irTxMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IRRECEIVE;
	irTxMsg.Header.ModuleId = sns_irReceive_ID;
	irTxMsg.Header.Command = CAN_MODULE_CMD_IRRECEIVE_IRRAW;
	for (uint8_t i = 0; i < len>>2; i++) {
		uint8_t index = i<<2;

		irTxMsg.Data[0] = (buffer[index]>>8)&0xff;
		irTxMsg.Data[1] = (buffer[index]>>0)&0xff;
		irTxMsg.Data[2] = (buffer[index+1]>>8)&0xff;
		irTxMsg.Data[3] = (buffer[index+1]>>0)&0xff;
		irTxMsg.Data[4] = (buffer[index+2]>>8)&0xff;
		irTxMsg.Data[5] = (buffer[index+2]>>0)&0xff;
		irTxMsg.Data[6] = (buffer[index+3]>>8)&0xff;
		irTxMsg.Data[7] = (buffer[index+3]>>0)&0xff;
				
		/* buffers will be filled when sending more than 2-3 messages, so retry until sent */
		while (StdCan_Put(&irTxMsg) != StdCan_Ret_OK) {}
	}
	
	uint8_t lastpacketcnt = len&0x03;
	if (lastpacketcnt > 0) {
		irTxMsg.Length = lastpacketcnt<<1;
		for (uint8_t i = 0; i < lastpacketcnt; i++) {
			irTxMsg.Data[i<<1] = (buffer[(len&0xfc)|i]>>8)&0xff;
			irTxMsg.Data[(i<<1)+1] = (buffer[(len&0xfc)|i]>>0)&0xff;
		}
		/* buffers will be filled when sending more than 2-3 messages, so retry until sent */
		while (StdCan_Put(&irTxMsg) != StdCan_Ret_OK) {}
	}
void sns_inputAnalog_Process(void)
{
	/* When the timer has overflowed the AD channels shall be read */
	if (Timer_Expired(sns_inputAnalog_TIMER)) 
	{
		StdCan_Msg_t txMsg;
		StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
		StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
		txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_INPUTANALOG;
		txMsg.Header.ModuleId = sns_inputAnalog_ID;

		uint16_t AdValue=0;
		/* For each channel */
		for (uint8_t i=0; i<sns_inputAnalog_NUM_SUPPORTED; i++)
		{
			/* Do reading of AD channel */
			switch (i)
			{
				case 0:
					AdValue = ADC_Get(sns_inputAnalog0AD);
					break;
				case 1:
					AdValue = ADC_Get(sns_inputAnalog1AD);
					break;
				case 2:
					AdValue = ADC_Get(sns_inputAnalog2AD);
					break;
				case 3:
					AdValue = ADC_Get(sns_inputAnalog3AD);
					break;
			}
			
			/* If this channel is configured as periodic transmission of voltage */
			if (sns_inputAnalog_Config[i].Type == CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_SETTING_PERIODICMEASURE)
			{
				/* Count periodicity */
				sns_inputAnalog_Sensor[i].PeriodCnt += sns_inputAnalog_POLL_PERIOD_MS;
				/* If periodicity overflowed or AD value changed more than threshold since last sent value */
				if (sns_inputAnalog_Sensor[i].PeriodCnt >= sns_inputAnalog_Config[i].Periodicity ||
					MAX(AdValue,sns_inputAnalog_Sensor[i].LastSentAdVal)-MIN(AdValue,sns_inputAnalog_Sensor[i].LastSentAdVal) > sns_inputAnalog_Config[i].LowTh)
				//if (sns_inputAnalog_Sensor[i].PeriodCnt >= sns_inputAnalog_Config[i].Periodicity ||
				//	abs(AdValue-sns_inputAnalog_Sensor[i].LastSentAdVal) > sns_inputAnalog_Config[i].LowTh)
				{
					/* Reset periodicity counter */
					sns_inputAnalog_Sensor[i].PeriodCnt = 0;
					/* Store value as last sent */
					sns_inputAnalog_Sensor[i].LastSentAdVal = AdValue;
					
					/* send sensor value on CAN with command CAN_MODULE_CMD_PHYSICAL_VOLTAGE */
					txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_VOLTAGE;
					txMsg.Length = 3;
					/* The channel should be transmitted in byte 0 */
					txMsg.Data[0] = i;
					
					uint8_t analogScale = 10;
					/* Select parameters for AD conversion */
					switch (i)
					{
						case 0:
							analogScale = sns_inputAnalog0Scale;
							AdValue = AdValue * sns_inputAnalog0Factor;
							break;
						case 1:
							analogScale = sns_inputAnalog1Scale;
							AdValue = AdValue * sns_inputAnalog1Factor;
							break;
						case 2:
							analogScale = sns_inputAnalog2Scale;
							AdValue = AdValue * sns_inputAnalog2Factor;
							break;
						case 3:
							analogScale = sns_inputAnalog3Scale;
							AdValue = AdValue * sns_inputAnalog3Factor;
							break;
					}
					txMsg.Data[1] = (AdValue>>(analogScale-6+8))&0xff;
					txMsg.Data[2] = (AdValue>>(analogScale-6))&0xff;
					
					/* Send value on CAN */
					while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
				}
			}
			/* If this channel is configured as digital input */
			else if (sns_inputAnalog_Config[i].Type == CAN_MODULE_ENUM_INPUTANALOG_ANALOGCONFIG_SETTING_DIGITALINPUT)
Beispiel #12
0
void sns_counter_HandleMessage(StdCan_Msg_t *rxMsg)
{
	if (	StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
		StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
		rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_COUNTER &&
		rxMsg->Header.ModuleId == sns_counter_ID)
	{
		StdCan_Msg_t txMsg;

		StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
		StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
		txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_COUNTER;
		txMsg.Header.ModuleId = sns_counter_ID;

		switch (rxMsg->Header.Command)
		{
		case CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL:
			if (rxMsg->Length > 0)
			{
				sns_counter_ReportInterval = rxMsg->Data[0];
				Timer_SetTimeout(sns_counter_SEND_TIMER, sns_counter_ReportInterval*1000 , TimerTypeFreeRunning, 0);
			}
			txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_REPORT_INTERVAL;
			txMsg.Length = 1;
			txMsg.Data[0] = sns_counter_ReportInterval;
			StdCan_Put(&txMsg);
			break;
		case CAN_MODULE_CMD_COUNTER_SETCOUNTER:
			if (rxMsg->Length != 5)
				break;
			if (
#ifdef sns_counter_CH0
				(rxMsg->Data[0] != 0) &&
#endif
#ifdef sns_counter_CH1
				(rxMsg->Data[0] != 1) &&
#endif
#ifdef sns_counter_CH2
				(rxMsg->Data[0] != 2) &&
#endif
#ifdef sns_counter_CH3
				(rxMsg->Data[0] != 3) &&
#endif
#ifdef sns_counter_CH4
				(rxMsg->Data[0] != 4) &&
#endif
#ifdef sns_counter_CH5
				(rxMsg->Data[0] != 5) &&
#endif
#ifdef sns_counter_CH6
				(rxMsg->Data[0] != 6) &&
#endif
#ifdef sns_counter_CH7
				(rxMsg->Data[0] != 7) &&
#endif
				1)
				break;
			Count[rxMsg->Data[0]] = rxMsg->Data[4];
			Count[rxMsg->Data[0]] += ((uint32_t)rxMsg->Data[3])<<8;
			Count[rxMsg->Data[0]] += ((uint32_t)rxMsg->Data[2])<<16;
			Count[rxMsg->Data[0]] += ((uint32_t)rxMsg->Data[1])<<24;
			txMsg.Header.Command = CAN_MODULE_CMD_COUNTER_SETCOUNTER;
			txMsg.Length = 5;
			txMsg.Data[0] = rxMsg->Data[0];	// CH
			txMsg.Data[4] = (uint8_t)Count[rxMsg->Data[0]] & 0xff;
			txMsg.Data[3] = (uint8_t)(Count[rxMsg->Data[0]] >> 8) & 0xff;
			txMsg.Data[2] = (uint8_t)(Count[rxMsg->Data[0]] >> 16) & 0xff;
			txMsg.Data[1] = (uint8_t)(Count[rxMsg->Data[0]] >> 24) & 0xff;
			StdCan_Put(&txMsg);
			break;
		}
	}
Beispiel #13
0
void sns_flower_Process(void)
{
	static uint8_t measureState=0;
	static uint16_t results[6];
	static uint16_t resultsInv[6];
	uint16_t temp;
	static uint8_t flowerChannelToSend = 0;
  
	
	if (Timer_Expired(sns_flower_WAIT_TIMER)) {
		
		gpio_set_out(sns_flower_highSide_PIN);
		gpio_set_out(sns_flower_lowSide_PIN);
		gpio_set_pin(sns_flower_highSide_PIN);
		gpio_clr_pin(sns_flower_lowSide_PIN);
		measureState=0;
		Timer_SetTimeout(sns_flower_MEASUREMENT_TIMER, sns_flower_MEASUREMENT_PERIOD_MS , TimerTypeOneShot, 0);
	}
	
	if (Timer_Expired(sns_flower_MEASUREMENT_TIMER)) {
		StdCan_Msg_t txMsg;
		StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
		StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
		txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_VOLTAGECURRENT;
		txMsg.Header.ModuleId = sns_flower_ID;
		txMsg.Length = 3;
		switch (measureState) {
			case 0:
#ifdef sns_flower0AD
				results[0] = ADC_Get(sns_flower0AD);
#endif
#ifdef sns_flower1AD
				results[1] = ADC_Get(sns_flower1AD);
#endif
#ifdef sns_flower2AD
				results[2] = ADC_Get(sns_flower2AD);
#endif
#ifdef sns_flower3AD
				results[3] = ADC_Get(sns_flower3AD);
#endif
#ifdef sns_flower4AD
				results[4] = ADC_Get(sns_flower4AD);
#endif
#ifdef sns_flower5AD
				results[5] = ADC_Get(sns_flower5AD);
#endif	
				gpio_clr_pin(sns_flower_highSide_PIN);
				gpio_set_pin(sns_flower_lowSide_PIN);
				measureState=1;
				Timer_SetTimeout(sns_flower_MEASUREMENT_TIMER, sns_flower_MEASUREMENT_PERIOD_MS , TimerTypeOneShot, 0);
				break;
			case 1:
#ifdef sns_flower0AD
				resultsInv[0] = 1023-ADC_Get(sns_flower0AD);
#endif
#ifdef sns_flower1AD
				resultsInv[1] = 1023-ADC_Get(sns_flower1AD);
#endif
#ifdef sns_flower2AD
				resultsInv[2] = 1023-ADC_Get(sns_flower2AD);
#endif
#ifdef sns_flower3AD
				resultsInv[3] = 1023-ADC_Get(sns_flower3AD);
#endif
#ifdef sns_flower4AD
				resultsInv[4] = 1023-ADC_Get(sns_flower4AD);
#endif
#ifdef sns_flower5AD
				resultsInv[5] = 1023-ADC_Get(sns_flower5AD);
#endif	
				gpio_clr_pin(sns_flower_highSide_PIN);
				gpio_clr_pin(sns_flower_lowSide_PIN);
				gpio_set_in(sns_flower_highSide_PIN);
				gpio_set_in(sns_flower_lowSide_PIN);
				measureState=2;
				flowerChannelToSend=0;
				Timer_SetTimeout(sns_flower_MEASUREMENT_TIMER, sns_flower_MEASUREMENT_PERIOD_MS , TimerTypeOneShot, 0);
				break;
			case 2:	
				  switch(flowerChannelToSend) {
					  case 0:
#ifdef sns_flower0AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 0;
						temp = (uint16_t)((float)(results[0]+resultsInv[0])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 1;
# if  !(defined(sns_flower1AD) || defined(sns_flower2AD) || defined(sns_flower3AD) || defined(sns_flower4AD) || defined(sns_flower5AD))
						flowerChannelToSend = 0;
						measureState=0;
# endif
						break;
#endif
					case 1:
#ifdef sns_flower1AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 1;
						temp = (uint16_t)((float)(results[1]+resultsInv[1])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 2;
# if  !(defined(sns_flower2AD) || defined(sns_flower3AD) || defined(sns_flower4AD) || defined(sns_flower5AD))
						flowerChannelToSend = 0;
						measureState=0;
# endif
						break;
#endif
					case 2:
#ifdef sns_flower2AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 2;
						temp = (uint16_t)((float)(results[2]+resultsInv[2])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 3;
#if  !(defined(sns_flower3AD) || defined(sns_flower4AD) || defined(sns_flower5AD))
						flowerChannelToSend = 0;
						measureState=0;
#endif
						break;
#endif
					case 3:
#ifdef sns_flower3AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 3;
						temp = (uint16_t)((float)(results[3]+resultsInv[3])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 4;
#if  !( defined(sns_flower4AD) || defined(sns_flower5AD))
						flowerChannelToSend = 0;
						measureState=0;
#endif
						break;
#endif
					case 4:
#ifdef sns_flower4AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 4;
						temp = (uint16_t)((float)(results[4]+resultsInv[4])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 5;
#if  !(defined(sns_flower5AD))
						flowerChannelToSend = 0;
						measureState=0;
#endif
						break;
#endif
					case 5:
#ifdef sns_flower5AD
						txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PERCENT;
						txMsg.Data[0] = 5;
						temp = (uint16_t)((float)(results[5]+resultsInv[5])*4.888);
						txMsg.Data[1] = (temp>>8)&0xff;
						txMsg.Data[2] = (temp)&0xff;

						while (StdCan_Put(&txMsg) != StdCan_Ret_OK) {}
						flowerChannelToSend = 0;
						measureState=0;
						break;
#endif
					default:
						measureState=0;
						break;
				}
				if (measureState != 0) {
					Timer_SetTimeout(sns_flower_MEASUREMENT_TIMER, sns_flower_CAN_MSG_PAUS_MS , TimerTypeOneShot, 0);
				}
				break;
		}
  
	}
}
void act_hd44780_Process(void)
{
#if act_hd44780_USE_AUTO_BL == 1
  if (autoMode == CAN_MODULE_ENUM_HD44789_LCD_BACKLIGHT_AUTOLIGHT_ON) {
    #if (act_hd44780_TYPE==0)
      if ( OCR0A == 0) {
    #else
      if ( OCR0B == 0) {
    #endif

      } else {
      uint16_t Voltage = (0x3ff & ADC_Get(act_hd44780_LIGHTSENSOR_AD));
    #if (act_hd44780_TYPE==0)
	OCR0A = Voltage/4;
	if (OCR0A == 0) {
	  OCR0A = 1;
	}
    #else
	OCR0B = Voltage/4;
	if (OCR0B == 0) {
	  OCR0B = 1;
	}
    #endif
      }
  }
#endif


#if (act_hd44780_TYPE==0)
	if (OCR0A==0 && (TCCR0A & ((1<<COM0A1)|(1<<WGM01)|(1<<WGM00))) == ((1<<COM0A1)|(1<<WGM01)|(1<<WGM00)))
	{
		TCCR0A &= ~((1<<COM0A1)|(1<<WGM01)|(1<<WGM00));
	}
	if (OCR0A!=0 && (TCCR0A & ((1<<COM0A1)|(1<<WGM01)|(1<<WGM00))) != ((1<<COM0A1)|(1<<WGM01)|(1<<WGM00)))
	{
		TCCR0A |= (1<<COM0A1)|(1<<WGM01)|(1<<WGM00);
	}
#endif
		
		

		
		
}

void act_hd44780_HandleMessage(StdCan_Msg_t *rxMsg)
{
	StdCan_Msg_t txMsg;
	uint8_t n = 0;

	if (	StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
		StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
		rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_HD44789 &&
		rxMsg->Header.ModuleId == act_hd44780_ID)
	{
		switch (rxMsg->Header.Command)
		{
		case CAN_MODULE_CMD_HD44789_LCD_CLEAR:
		lcd_clrscr();
		break;

		case CAN_MODULE_CMD_HD44789_LCD_CURSOR:
		lcd_gotoxy(rxMsg->Data[0], rxMsg->Data[1]);
		break;

		case CAN_MODULE_CMD_HD44789_LCD_TEXTAT:
		lcd_gotoxy(rxMsg->Data[0], rxMsg->Data[1]);
		for (n = 2; n < rxMsg->Length; n++)
		{
			lcd_putc((char)rxMsg->Data[n]);
		}
		break;
/*
		case CAN_MODULE_CMD_HD44789_LCD_CLEARROW:
		lcd_gotoxy(0, rxMsg->Data[0]);
		for (n = 0; n < act_hd44780_WIDTH; n++)
		{
			lcd_putc(' ');
		}
		break;
*/
		case CAN_MODULE_CMD_HD44789_LCD_TEXT:
		for (n = 0; n < rxMsg->Length; n++)
		{
			lcd_putc((char)rxMsg->Data[n]);
		}
		break;

		case CAN_MODULE_CMD_HD44789_LCD_SIZE:
		StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
		StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
		txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_HD44789;
		txMsg.Header.ModuleId = act_hd44780_ID;
		txMsg.Header.Command = CAN_MODULE_CMD_HD44789_LCD_SIZE;
		txMsg.Length = 2;

		txMsg.Data[0] = act_hd44780_WIDTH;
		txMsg.Data[1] = act_hd44780_HEIGHT;

		while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
		break;

		case CAN_MODULE_CMD_HD44789_LCD_BACKLIGHT:
		if (rxMsg->Length > 0) {
#if (act_hd44780_TYPE==0)
			OCR0A = rxMsg->Data[0];
#else
			OCR0B = rxMsg->Data[0];
#endif
#if act_hd44780_USE_AUTO_BL == 1
			if (rxMsg->Length == 2) {
				autoMode = rxMsg->Data[0]; 
			}
#endif
		}

		StdCan_Msg_t txMsg;

		StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
		StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
		txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_HD44789;
		txMsg.Header.ModuleId = act_hd44780_ID;
		txMsg.Header.Command = CAN_MODULE_CMD_HD44789_LCD_BACKLIGHT;
		txMsg.Length = 1;

#if (act_hd44780_TYPE==0)
			txMsg.Data[0] = OCR0A;
#else
			txMsg.Data[0] = OCR0B;
#endif
#if act_hd44780_USE_AUTO_BL == 1
		txMsg.Data[1] = autoMode;
		txMsg.Length = 2;
#endif
		while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
		break;
		}
	}
}
Beispiel #15
0
void act_output_HandleMessage(StdCan_Msg_t *rxMsg)
{
	if (	StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
		StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
		rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_OUTPUT && 
		rxMsg->Header.ModuleId == act_output_ID)
	{
		uint8_t index = 0;
		uint8_t value = 0;
		switch (rxMsg->Header.Command)
		{
		case CAN_MODULE_CMD_PHYSICAL_SETPIN:
			
			index = 0;
			if (rxMsg->Length == 2) {
	#ifdef	act_output_CH0
				if (rxMsg->Data[0] == 0) {
					chnValue[index] = rxMsg->Data[1];
	#if act_output_CH0PCA95xxIO==0
					gpio_set_statement(chnValue[index],act_output_CH0);
	#else
					Pca95xx_set_statement(chnValue[index],act_output_CH0);
	#endif
				}
				index++;
	#endif
	#ifdef	act_output_CH1
				if (rxMsg->Data[0] == 1) {
					chnValue[index] = rxMsg->Data[1];
	#if act_output_CH1PCA95xxIO==0
					gpio_set_statement(chnValue[index],act_output_CH1);
	#else
					Pca95xx_set_statement(chnValue[index],act_output_CH1);
	#endif
				}
				index++;
	#endif
	#ifdef	act_output_CH2
				if (rxMsg->Data[0] == 2) {
					chnValue[index] = rxMsg->Data[1];
	#if act_output_CH2PCA95xxIO==0
					gpio_set_statement(chnValue[index],act_output_CH2);
	#else
					Pca95xx_set_statement(chnValue[index],act_output_CH2);
	#endif
				}
				index++;
	#endif
	#ifdef	act_output_CH3
				if (rxMsg->Data[0] == 3) {
					chnValue[index] = rxMsg->Data[1];
	#if act_output_CH3PCA95xxIO==0
					gpio_set_statement(chnValue[index],act_output_CH3);
	#else
					Pca95xx_set_statement(chnValue[index],act_output_CH3);
	#endif
				}
				index++;
	#endif
	#ifdef	act_output_CH4
				if (rxMsg->Data[0] == 4) {
					chnValue[index] = rxMsg->Data[1];
	#if act_output_CH4PCA95xxIO==0
					gpio_set_statement(chnValue[index],act_output_CH4);
	#else

					Pca95xx_set_statement(chnValue[index],act_output_CH4);
	#endif
				}
				index++;
	#endif
	#ifdef	act_output_CH5
				if (rxMsg->Data[0] == 5) {
					chnValue[index] = rxMsg->Data[1];
	#if act_output_CH5PCA95xxIO==0
					gpio_set_statement(chnValue[index],act_output_CH5);
	#else
					Pca95xx_set_statement(chnValue[index],act_output_CH5);
	#endif
				}
				index++;
	#endif
	#ifdef	act_output_CH6
				if (rxMsg->Data[0] == 6) {
					chnValue[index] = rxMsg->Data[1];
	#if act_output_CH6PCA95xxIO==0
					gpio_set_statement(chnValue[index],act_output_CH6);
	#else
					Pca95xx_set_statement(chnValue[index],act_output_CH6);
	#endif
				}
				index++;
	#endif
	#ifdef	act_output_CH7
				if (rxMsg->Data[0] == 7) {
					chnValue[index] = rxMsg->Data[1];
	#if act_output_CH7PCA95xxIO==0
					gpio_set_statement(chnValue[index],act_output_CH7);
	#else
					Pca95xx_set_statement(chnValue[index],act_output_CH7);
	#endif
				}
				index++;
	#endif	  
	#ifdef	act_output_CH8
				if (rxMsg->Data[0] == 8) {
					chnValue[index] = rxMsg->Data[1];
	#if act_output_CH8PCA95xxIO==0
					gpio_set_statement(chnValue[index],act_output_CH8);
	#else
					Pca95xx_set_statement(chnValue[index],act_output_CH8);
	#endif
				}
				index++;
	#endif	  
	#ifdef	act_output_CH9
				if (rxMsg->Data[0] == 9) {
					chnValue[index] = rxMsg->Data[1];
	#if act_output_CH9PCA95xxIO==0
					gpio_set_statement(chnValue[index],act_output_CH9);
	#else
					Pca95xx_set_statement(chnValue[index],act_output_CH9);
	#endif
				}
				index++;
	#endif	  
				Timer_SetTimeout(act_output_STORE_VALUE_TIMEOUT, act_output_STORE_VALUE_TIMEOUT_TIME_S*1000, TimerTypeOneShot, 0);
				StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER);
				rxMsg->Length = 2;
				while (StdCan_Put(rxMsg) != StdCan_Ret_OK);
			} else {
				index = 0;
		#ifdef	act_output_CH0
				if (rxMsg->Data[0] == 0) {value = chnValue[index];}
				index++;
		#endif
		#ifdef	act_output_CH1
				if (rxMsg->Data[0] == 1) {value = chnValue[index];}
				index++;
		#endif
		#ifdef	act_output_CH2
				if (rxMsg->Data[0] == 2) {value = chnValue[index];}
				index++;
		#endif
		#ifdef	act_output_CH3
				if (rxMsg->Data[0] == 3) {value = chnValue[index];}
				index++;
		#endif
		#ifdef	act_output_CH4
				if (rxMsg->Data[0] == 4) {value = chnValue[index];}
				index++;
		#endif
		#ifdef	act_output_CH5
				if (rxMsg->Data[0] == 5) {value = chnValue[index];}
				index++;
		#endif
		#ifdef	act_output_CH6
				if (rxMsg->Data[0] == 6) {value = chnValue[index];}
				index++;
		#endif
		#ifdef	act_output_CH7
				if (rxMsg->Data[0] == 7) {value = chnValue[index];}
				index++;
		#endif	  	
		#ifdef	act_output_CH8
				if (rxMsg->Data[0] == 8) {value = chnValue[index];}
				index++;
		#endif	  	
		#ifdef	act_output_CH9
				if (rxMsg->Data[0] == 9) {value = chnValue[index];}
				index++;
		#endif	  	
				rxMsg->Data[1] = value;
				StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER);
				rxMsg->Length = 2;
				while (StdCan_Put(rxMsg) != StdCan_Ret_OK);

			}
		break;
		}
	}
}
void act_protectedOutput_Process() {

#if act_protectedOutput_EEPROM_ENABLED == 1
	if (Timer_Expired(act_protectedOutput_STORE_VALUE_TIMEOUT)) {
#if	act_protectedOutput_CH_COUNT >= 1
		eeprom_write_byte_crc(EEDATA.ch0, chTargetState[0], WITHOUT_CRC);
#endif
#if	act_protectedOutput_CH_COUNT >= 2
		eeprom_write_byte_crc(EEDATA.ch1, chTargetState[1], WITHOUT_CRC);
#endif
#if	act_protectedOutput_CH_COUNT >= 3
		eeprom_write_byte_crc(EEDATA.ch2, chTargetState[2], WITHOUT_CRC);
#endif
#if	act_protectedOutput_CH_COUNT >= 4
		eeprom_write_byte_crc(EEDATA.ch3, chTargetState[3], WITHOUT_CRC);
#endif
		EEDATA_UPDATE_CRC;
	}
#endif

	// shall we retry to set target output state?
	if (Timer_Expired(act_protectedOutput_RETRY_TIMER)) {
		// read DIAG pin again and update outputs accordingly
		readDiagPin();
#if act_protectedOutput_FORCED_RETRIES == 1
		// forced retry to set output states, regardless of DIAG
		updateOutput(1);
		// read DIAG pin again and hope we have a better flag
		readDiagPin();
#else
		// if DIAG allows it, retry to set the output states
		updateOutput(0);
#endif
		if (diagState == DIAG_ASSERTED) {
			// if DIAG was still asserted, initiate another timer run
			Timer_SetTimeout(act_protectedOutput_RETRY_TIMER, act_protectedOutput_RETRY_TIMER_TIME_S*1000, TimerTypeOneShot, 0);
		}
		else {
			// things went back to normal. report this
			diagReportPending = 1;
		}
	}
	
	// shall we report diag status to CAN?
	if (diagReportPending) {
		StdCan_Msg_t txMsg;
		StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
		StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
		txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_PROTECTEDOUTPUT;
		txMsg.Header.ModuleId = act_protectedOutput_ID;
		txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PINSTATUS;
		txMsg.Length = 2;
		txMsg.Data[0] = 0; //TODO: add support for more channels
		// we follow the standard SNS_INPUT format, but the data corresponds to the "health" rather than physical level
		if (diagState == DIAG_NORMAL) {
			txMsg.Data[1] = 1;	//healthy, target output state stable
		} else {
			txMsg.Data[1] = 0;	//not healthy, DIAG pin ASSERTED, not in target output state
		}
		while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
		diagReportPending = 0;
	}
}