Пример #1
0
// Cluster: On/off, server
EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand *cmd)
{
  boolean wasHandled = FALSE;
  if (!cmd->mfgSpecific) {
    switch (cmd->commandId) {
    case ZCL_OFF_COMMAND_ID:
      {
        // Command is fixed length: 0
        wasHandled = emberAfOnOffClusterOffCallback();
        break;
      }
    case ZCL_ON_COMMAND_ID:
      {
        // Command is fixed length: 0
        wasHandled = emberAfOnOffClusterOnCallback();
        break;
      }
    case ZCL_TOGGLE_COMMAND_ID:
      {
        // Command is fixed length: 0
        wasHandled = emberAfOnOffClusterToggleCallback();
        break;
      }
    }
  }
  return status(wasHandled, cmd->mfgSpecific);
}
// Cluster: On/off, server
EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand *cmd) {
	boolean wasHandled = FALSE;
	int8u OnOfffCmdBeforeNumber;
	if (!cmd->mfgSpecific) {
		switch (cmd->apsFrame->destinationEndpoint){
			case 1 : OnOfffCmdBeforeNumber = 1;
			break;
			case 3 : OnOfffCmdBeforeNumber = 2;
			break;
			case 5 : OnOfffCmdBeforeNumber = 3;
			break;
			case 7 : OnOfffCmdBeforeNumber = 4;
			break;
			case LedLightOptionEndpoint:
					 OnOfffCmdBeforeNumber = 5;
			break;
		}
		if (CommonGetDurationTime(OnOffCmdBeforeTimer[OnOfffCmdBeforeNumber]) > 1000){
			OnOffCmdBeforeTimer[OnOfffCmdBeforeNumber] = (int16u)halCommonGetInt32uMillisecondTick();
			switch (cmd->commandId) {
				case ZCL_OFF_COMMAND_ID: {
					// Command is fixed length: 0
					wasHandled = emberAfOnOffClusterOffCallback();
					break;
				}
				case ZCL_ON_COMMAND_ID: {
					// Command is fixed length: 0
					wasHandled = emberAfOnOffClusterOnCallback();
					break;
				}
				case ZCL_TOGGLE_COMMAND_ID: {
					// Command is fixed length: 0
					wasHandled = emberAfOnOffClusterToggleCallback();
					break;
				}
			}



		//	User Controller Command
			int8u CurrentState;
			emberAfReadServerAttribute(cmd->apsFrame->destinationEndpoint,
						ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, &CurrentState,
						sizeof(CurrentState));
			if (status(wasHandled, cmd->mfgSpecific) == EMBER_ZCL_STATUS_SUCCESS) {
				if (cmd->apsFrame->destinationEndpoint == LedLightOptionEndpoint) {
					if (CurrentState == 1) {
						halClearLed(LED_LIGHT);
					}
					else{
						halSetLed(LED_LIGHT);
					}
				}
				else {
					if (CurrentState == 1) {
						UartSendSwitchControlNumber(
								(((cmd->apsFrame->destinationEndpoint) >> 1) + 1),
								OnRelay);
					} else {
						UartSendSwitchControlNumber(
								(((cmd->apsFrame->destinationEndpoint) >> 1) + 1),
								OffRelay);
					}

					//	 	Send to Bind Device

					SendViaBindingTable(cmd->apsFrame->destinationEndpoint,
							CurrentState, OnOffType);

					//		Send On-Off AttributeResponse, Zipato stupid update :D-----------------------------//
					SendOnOffControlReadAttribute(cmd->apsFrame->destinationEndpoint,
							CurrentState);

					// on-off led

					if (CurrentState == 1) {
						CommonSetLed(cmd->apsFrame->destinationEndpoint >> 1);
					} else {