etwmc / Personal-HomeKit-HAP

This project will provide source code to build a HomeKit support accessories.
MIT License
236 stars 85 forks source link

when i add a bridge, i got a Segmentation fault! #71

Closed robot0518 closed 7 years ago

robot0518 commented 7 years ago

this is my Accessory.cpp:

/*

include "Accessory.h"

include "PHKAccessory.h"

include "PHKNetworkIP.h"

include

include

using namespace std;

void identity(bool oldValue, bool newValue, connectionInfo *sender) { printf("Identify\n"); }

void identity2(bool oldValue, bool newValue, connectionInfo *sender) { printf("Identify\n"); }

AccessorySet *accSet;

void initAccessorySet() {

//currentDeviceType = deviceType_thermostat;

currentDeviceType = deviceType_bridge;

printf("Initial Thermostat_1\n");
accSet = &AccessorySet::getInstance();
Accessory *thermostatAcc_1 = new Accessory();
addInfoServiceToAccessory(thermostatAcc_1, "Vlin thermostat", "Vlin", "Vlin thermostat v1", "12345678", &identity);
accSet->addAccessory(thermostatAcc_1);

Service *thermostatService_1 = new Service(serviceType_thermostat);
thermostatAcc_1->addService(thermostatService_1);

stringCharacteristics *thermostatServiceName_1 = new stringCharacteristics(charType_serviceName, premission_read, 0);
thermostatServiceName_1->characteristics::setValue("thermostat");
thermostatAcc_1->addCharacteristics(thermostatService_1, thermostatServiceName_1);

intCharacteristics *thermostatCurrentMode_1 = new intCharacteristics(charType_currentHeatCoolMode, premission_read|premission_notify, 0, 2, 1, unit_none);
//thermostatCurrentMode->setValue("0");
thermostatAcc_1->addCharacteristics(thermostatService_1, thermostatCurrentMode_1);

intCharacteristics *thermostatTargetMode_1 = new intCharacteristics(charType_targetHeatCoolMode, premission_read|premission_write|premission_notify, 0, 3, 1, unit_none);
thermostatTargetMode_1->characteristics::setValue("1");
thermostatAcc_1->addCharacteristics(thermostatService_1, thermostatTargetMode_1);

floatCharacteristics *thermostatTargetTemperature_1 = new floatCharacteristics(charType_targetTemperature, premission_read|premission_write|premission_notify, 10.0, 38.0, 0.1, unit_celsius);
thermostatTargetTemperature_1->characteristics::setValue("26");
thermostatAcc_1->addCharacteristics(thermostatService_1,thermostatTargetTemperature_1);

floatCharacteristics *thermostatCurrentTemperature_1 = new floatCharacteristics(charType_currentTemperature, premission_read|premission_notify, 0, 100, 0.1, unit_celsius);
//thermostatCurrentTemperature->setValue("26");
thermostatCurrentTemperature_1->characteristics::setValue("20");
thermostatAcc_1->addCharacteristics(thermostatService_1,thermostatCurrentTemperature_1);

intCharacteristics *thermostateDisplayUnit_1 = new intCharacteristics(charType_temperatureUnit, premission_read|premission_write|premission_notify, 0, 1, 1, unit_none);
thermostateDisplayUnit_1->characteristics::setValue("0");
thermostatAcc_1->addCharacteristics(thermostatService_1, thermostateDisplayUnit_1);

Accessory *thermostatAcc_2 = new Accessory();
addInfoServiceToAccessory(thermostatAcc_2, "Vlin thermostat", "Vlin", "Vlin thermostat v1", "12345678", &identity2);
accSet->addAccessory(thermostatAcc_2);

Service *thermostatService = new Service(serviceType_thermostat);
thermostatAcc_2->addService(thermostatService);

stringCharacteristics *thermostatServiceName = new stringCharacteristics(charType_serviceName, premission_read, 0);
thermostatServiceName->characteristics::setValue("thermostat");
thermostatAcc_2->addCharacteristics(thermostatService, thermostatServiceName);

intCharacteristics *thermostatCurrentMode = new intCharacteristics(charType_currentHeatCoolMode, premission_read|premission_notify, 0, 2, 1, unit_none);
//thermostatCurrentMode->setValue("0");
thermostatAcc_2->addCharacteristics(thermostatService, thermostatCurrentMode);

intCharacteristics *thermostatTargetMode = new intCharacteristics(charType_targetHeatCoolMode, premission_read|premission_write|premission_notify, 0, 3, 1, unit_none);
thermostatTargetMode->characteristics::setValue("1");
thermostatAcc_2->addCharacteristics(thermostatService, thermostatTargetMode);

floatCharacteristics *thermostatTargetTemperature = new floatCharacteristics(charType_targetTemperature, premission_read|premission_write|premission_notify, 10.0, 38.0, 0.1, unit_celsius);
thermostatTargetTemperature->characteristics::setValue("30");
thermostatAcc_2->addCharacteristics(thermostatService,thermostatTargetTemperature);

floatCharacteristics *thermostatCurrentTemperature = new floatCharacteristics(charType_currentTemperature, premission_read|premission_notify, 0, 100, 0.1, unit_celsius);
//thermostatCurrentTemperature->setValue("26");
thermostatCurrentTemperature->characteristics::setValue("30");
thermostatAcc_2->addCharacteristics(thermostatService,thermostatCurrentTemperature);

intCharacteristics *thermostateDisplayUnit = new intCharacteristics(charType_temperatureUnit, premission_read|premission_write|premission_notify, 0, 1, 1, unit_none);
thermostateDisplayUnit->characteristics::setValue("0");
thermostatAcc_2->addCharacteristics(thermostatService, thermostateDisplayUnit);

};

robot0518 commented 7 years ago

it's my fault ! i reviewed the code and close it