Esempio n. 1
0
IoObject *IoAppleSensors_smsVector(IoAppleSensors *self, IoObject *locals, IoMessage *m)
{
	/*doc AppleSensors smsVector(aVector)
		Sets aVector to the current x, y and z accelerometer values. 
		Returns true on success and false on failure.
	*/
	IoSeq *vector = IoMessage_locals_seqArgAt_(m, locals, 0);
	float *f = IoSeq_floatPointerOfLength_(vector, 3);
	int err;

	if (smsType == -1)
	{
		smsType = detect_sms();
	}

	int v[3] = {0, 0, 0};

	err = read_sms(smsType, &v[0], &v[1], &v[3]);
	
	f[0] = v[0];
	f[1] = v[1];
	f[2] = v[2];

	return err ? IOTRUE(self) : IOFALSE(self);
}
Esempio n. 2
0
uint8_t pdu_parser(uint8_t *pdu) 
{
    uint8_t i = 3;
    uint8_t ret_val = 1;
    int16_t write_len = 0;
    uint16_t reply_len = 0;

    SMS_DEBUG("pdu_parser called: %d\n", pdu[i]);
    if (pdu[i++] == '+') {
        SMS_DEBUG("pdu_parser called: %d\n", pdu[i]);
        if (!strncmp((char *) pdu + i, "CMGL", 4)) {    
            SMS_DEBUG("messages will be received\r\n");
            uint8_t smsc_len, sender_len;
            if (reply_len == 0) {
                while (pdu[++i] != '\n');
                i ++;
                /* get length of smsc number */
                sscanf((char *) pdu + i, "%02hhX", &smsc_len);
                /* we ignore some flags "0000" */
                i += (smsc_len * 2) + 4;
                /* get data length */
                sscanf((char *) pdu + i, "%02hhX", &sender_len);
                /* get number of message sender */
                strncpy(nummer, (char *) pdu + i, sender_len + 5);
                nummer[sender_len + 5] = '\0';
                i = i + sender_len + 5 + 18;
                read_sms((uint8_t *) pdu + i);
            }
            
            SMS_DEBUG("ecmd: %s\n", text);
            do {
                if (reply_len < (int16_t)sizeof(write_buffer)) {
                    write_len = ecmd_parse_command((char *) text, 
                                              write_buffer + reply_len, 
                                              sizeof(write_buffer) - reply_len - 1);
                    SMS_DEBUG("ret_len ecmd parser: %d\r\n", write_len);
                    if (is_ECMD_AGAIN(write_len)) {
                        reply_len += -(10 + write_len);
                        *(write_buffer + reply_len) = ' ';
                        reply_len++;
                    } 
                    else if (write_len > 0) {
                        SMS_DEBUG("finished: \"%s\"\n", write_buffer);
                        ret_val = 0;
                        reply_len += write_len;
                        break;
                    }
                    SMS_DEBUG("%s\n", write_buffer);
                }
                else {
                    break;
                }
            } while (write_len <= 0);
           
            write_buffer[reply_len] = '\0';
            sms_send((uint8_t *) nummer, (uint8_t *) write_buffer, NULL, 1);
        }
    }
    return ret_val;
}
Esempio n. 3
0
File: unimotion.c Progetto: ADTSH/io
int read_sms_scaled(int type, int *x, int *y, int *z)
{
    int _x, _y, _z;
    int ret;

    ret = read_sms(type, &_x, &_y, &_z);
    if ( !ret )
        return 0;

    *x = _x + dsv[type].xscale;
    *y = _y + dsv[type].yscale;
    *z = _z + dsv[type].zscale;

    return ret;
}
Esempio n. 4
0
File: unimotion.c Progetto: ADTSH/io
int read_sms_real(int type, double *x, double *y, double *z)
{
    int _x, _y, _z;
    int xscale, yscale, zscale;
    double xreal, yreal, zreal;
    int ret;
    Boolean ok;

    // start with the "calibrated" (offset applied) value
    ret = read_sms(type, &_x, &_y, &_z);
    if ( !ret )
        return 0;

    static CFStringRef app = CFSTR("com.ramsayl.UniMotion");
    static CFStringRef xrealstr = CFSTR("x_real");
    static CFStringRef yrealstr = CFSTR("y_real");
    static CFStringRef zrealstr = CFSTR("z_real");
    static CFStringRef xscalestr = CFSTR("x_scale");
    static CFStringRef yscalestr = CFSTR("y_scale");
    static CFStringRef zscalestr = CFSTR("z_scale");

#define codeblock(x,_x,xreal,xscale) \
    ok = getPrefDouble(xreal##str, app, &xreal); \
    if ( ok ) { \
        *x = _x * xreal; /* use x_real if it's there */ \
    } else { \
        xscale = CFPreferencesGetAppIntegerValue(xscale##str, app, &ok); \
        if ( ok ) { \
            *x = _x / (double)xscale; /* try x_scale next */ \
        } else { \
            *x = _x * drv[type].xreal; /* fall back to "standard" values */ \
        } \
    }

    codeblock(x,_x,xreal,xscale);
    codeblock(y,_y,yreal,yscale);
    codeblock(z,_z,zreal,zscale);

#undef codeblock

    return 1;
}