diff --git a/bthome_phy6222/source/ble_ota.c b/bthome_phy6222/source/ble_ota.c index b1b99fd..3202e0e 100644 --- a/bthome_phy6222/source/ble_ota.c +++ b/bthome_phy6222/source/ble_ota.c @@ -6,9 +6,10 @@ #include "config.h" #if OTA_TYPE #include "OSAL.h" -#include "sbp_profile.h" #include "flash.h" #include "ble_ota.h" +#include "sbp_profile.h" +#include "thb2_peripheral.h" /******************************************************************************* * CONSTANTS */ @@ -91,19 +92,13 @@ uint32_t get_crc32_16bytes(unsigned int crc_init, unsigned char *data) { } -void ota_timer(void) { - -} - - int ota_parser(unsigned char *pout, unsigned char *pmsg, unsigned int msg_size) { uint32_t tmp; uint16_t crc; uint16_t ota_adr = pmsg[0] | (pmsg[1] << 8); uint8_t flash_check[16]; - uint8_t err_flg = OTA_SUCCESS; - if(msg_size > 2) { - // ota_reload_imer(); + int err_flg = OTA_SUCCESS; + if(msg_size >= 2) { if (ota_adr >= CMD_OTA_START) { if (ota_adr == CMD_OTA_START) { if(msg_size == 2 + 4) { @@ -139,10 +134,9 @@ int ota_parser(unsigned char *pout, unsigned char *pmsg, unsigned int msg_size) } else err_flg = OTA_PKT_SIZE_ERR; // size error } else if (ota_adr == CMD_OTA_END) { - //@TODO go to reboot or start app - //ota_timer() - //terminateConnection(0x13); - //timer(reboot) + //go to reboot or start app + GAPRole_TerminateConnection(); + hal_system_soft_reset(); } else err_flg = OTA_UNKNOWN_CMD; // unknown commad } else if(ota.err_flag) { @@ -215,7 +209,7 @@ int ota_parser(unsigned char *pout, unsigned char *pmsg, unsigned int msg_size) err_flg = OTA_NO_PARAM; } else err_flg = OTA_PKT_SIZE_ERR; // size error - if (err_flg) { + if (err_flg != OTA_SUCCESS) { ota.err_flag = err_flg; //send/Notify? osal_memcpy(pout, &ota, 20); diff --git a/bthome_phy6222/source/config.h b/bthome_phy6222/source/config.h index 027577f..f04e58c 100644 --- a/bthome_phy6222/source/config.h +++ b/bthome_phy6222/source/config.h @@ -37,7 +37,7 @@ #define DEVICE_TH05 21 #ifndef DEVICE -#define DEVICE DEVICE_THB2 +#define DEVICE DEVICE_BTH01 #endif #define OTA_TYPE_NONE 0 @@ -86,6 +86,25 @@ #define DEF_HARDWARE_REVISION "0001" #define DEF_MANUFACTURE_NAME_STR "Tuya" +#elif DEVICE == DEVICE_TH05 +/* Model: TH05 */ + +#define ADC_PIN_USE_OUT 1 // hal_gpio_write(ADC_PIN, 1); +#define ADC_PIN GPIO_P11 +#define ADC_CHL ADC_CH1N_P11 + +#define I2C_SDA GPIO_P33 // CHT8305_SDA +#define I2C_SCL GPIO_P34 // CHT8305_SCL +#define GPIO_SPWR GPIO_P00 // питание сенсора CHT8305_VDD +#define GPIO_KEY GPIO_P14 +#define GPIO_LED GPIO_P15 +#define LED_ON 1 +#define LED_OFF 0 + +#define DEF_MODEL_NUMBER_STR "TH05" +#define DEF_HARDWARE_REVISION "0001" +#define DEF_MANUFACTURE_NAME_STR "Tuya" + #else #error "DEVICE Not released!" #endif diff --git a/bthome_phy6222/source/sbp_profile.c b/bthome_phy6222/source/sbp_profile.c index f750af1..0baa97e 100644 --- a/bthome_phy6222/source/sbp_profile.c +++ b/bthome_phy6222/source/sbp_profile.c @@ -82,8 +82,9 @@ static CONST gattAttrType_t simpleProfileService = { ATT_BT_UUID_SIZE, simplePro #if OTA_TYPE // Simple Profile Characteristic 1 Properties -static CONST uint8_t simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_WRITE_NO_RSP; +static CONST uint8_t simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_WRITE_NO_RSP | GATT_PROP_NOTIFY; //static CONST uint8_t simpleProfileChar1UserDesp[] = "OTA\0"; // Simple Profile Characteristic 1 User Description +static gattCharCfg_t simpleProfileChar1Config[GATT_MAX_NUM_CONN]; // static uint8_t ota_in_buffer[20]; // Characteristic 1 Value static uint8_t ota_in_len; @@ -102,9 +103,9 @@ static uint8_t cmd_in_len; // Characteristic 2 Value * Profile Attributes - Table */ #if OTA_TYPE -#define SERVAPP_NUM_ATTR_SUPPORTED 6 +#define SERVAPP_NUM_ATTR_SUPPORTED 7 #define OTA_DATA_ATTR_IDX 2 // Position of OTA in attribute array -#define CDM_DATA_ATTR_IDX 4 // Position of CMD in attribute array +#define CDM_DATA_ATTR_IDX 5 // Position of CMD in attribute array #else #define SERVAPP_NUM_ATTR_SUPPORTED 4 #define CDM_DATA_ATTR_IDX 2 // Position of CMD in attribute array @@ -134,6 +135,13 @@ static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] = 0, (uint8_t *)&ota_in_buffer[0] }, + // Characteristic 1 configuration + { + { ATT_BT_UUID_SIZE, clientCharCfgUUID }, + GATT_PERMIT_READ | GATT_PERMIT_WRITE, + 0, + (uint8_t *)simpleProfileChar1Config + }, #if 0 // Characteristic 1 User Description { @@ -367,7 +375,8 @@ static bStatus_t simpleProfile_ReadAttrCB( uint16_t connHandle, gattAttribute_t ota_in_len = len; LOG("OTA receive data = 0x "); LOG_DUMP_BYTE(pAttr->pValue, len); - osal_set_event(simpleBLEPeripheral_TaskID, SBP_OTADATA); + if(len >= 2) + osal_set_event(simpleBLEPeripheral_TaskID, SBP_OTADATA); } break; #endif // OTA_TYPE @@ -442,7 +451,7 @@ void new_cmd_data(void) { void new_ota_data(void) { attHandleValueNoti_t noti; noti.handle = simpleProfileAttrTbl[OTA_DATA_ATTR_IDX].handle; - noti.len = ota_parser(noti.value, cmd_in_buffer, cmd_in_len); + noti.len = ota_parser(noti.value, ota_in_buffer, ota_in_len); if(noti.len) { GATT_Notification(gapRole_ConnectionHandle, ¬i, FALSE ); }