//
//  EATagItem.swift
//  BTConnect_SWIFT
//
//  Created by 류은주 on 2017. 12. 5..
//  Copyright © 2017년 ATID. All rights reserved.
//

import Foundation

//var data = value.components(separatedBy: ",")
//var val1: Data? = data[1].hexToBytes()
//var val1Data: Data? = val1?.subdata(with: NSRange(location: 0, length: 2))
//var val1Int = CFSwapInt16(Int(val1Data?.bytes))
//var tmp1 = Int16(val1Int & 0xffff)
//var val2: Data? = data[2].hexToBytes()
//var val2Data: Data? = val2?.subdata(with: NSRange(location: 0, length: 2))
//var val2Int = CFSwapInt16(Int(val2Data?.bytes))
//var tmp2 = Int16(val2Int & 0xffff)
//var tmpPhase = Int(tmp2)

class EATagItems: NSObject {
    var tag = ""
    var count: Int = 0
    var rssi: Float = 0.0
    var phase: Float = 0.0
    

//        + (id)itemWith:(NSString *)value {
//    EATagItem *item = [[EATagItem alloc] initWith:value];
//    return item;
//    }
//    + (id)itemWith:(NSString *)tag rssi:(float)rssi phase:(float)phase {
//    EATagItem *item = [[EATagItem alloc] init];
//    [item setTag:tag];
//    [item setRssi:rssi];
//    [item setPhase:phase];
//    [item setCount:1];
//
//    return item;
//    };
    
    func itemWith(tag: String, rssi: Float, phase:Float) -> EATagItems {
        let item = EATagItems()
        item.tag = tag
        item.rssi = rssi
        item.phase = phase
        item.count += 1
        return item
    }
    
    func updateRssi(rssi: Float, phase:Float) {
        self.rssi = rssi
        self.phase = phase
    }
        func setValue(_ tag: String, rssi: Float, phase: Float) -> EATagItems
        {
            let item = EATagItems()
            item.tag = tag
            item.rssi = rssi
            item.phase = phase
            item.count = 1
            return item
        }
//
//    func init(_ value: String) -> id{
//        super.init()
//
//        let data = value.components(separatedBy: ",")
//        print("Data Array : \(data)")
//        if data.count > 1 {
//            let val1: Data? = data[1].hexToBytes()
//            let val1Data: Data? = val1?.subdata(with: NSRange(location: 0, length: 2))
//            let val1Int = CFSwapInt16(Int(val1Data?.bytes))
//            let tmp1 = Int16(val1Int & 0xffff)
//            print("Short Val 1 : \(tmp1) [\(val1)]")
//            rssi = tmp1 / 10.0
//        }
//        if data.count() > 2 {
//            var val2: Data? = data[2].hexToBytes()
//            var val2Data: Data? = val2?.subdata(with: NSRange(location: 0, length: 2))
//            var val2Int = CFSwapInt16(Int(val2Data?.bytes))
//            var tmp2 = Int16(val2Int & 0xffff)
//            print("Short Val 2 : \(tmp2) [\(val2)]")
//            var tmpPhase = Int(tmp2)
//            tmpPhase = tmpPhase & 0x7f
//            if tmpPhase > 0x40 {
//                tmpPhase = (0x80 - tmpPhase) * -1
//            }
//            phase = tmpPhase / 64.0 * 180.0
//        }
//        tag = data[0]
//        count = 1
//
//        return self
//    }
    func test() {
        print("EATagItem test FUNC")
    }
//    func updateRssi(_ rssi: Float, withPhase phase: Float) {
//        rssi = rssi
//        phase = phase
//    }

}
