static bool handleRead(int size, const byte *msg, CONTEXT *context) { byte bind = msg[1]; byte *expr = (byte *) &msg[2]; byte slaveAddress = evalWord8Expr(&expr, context); byte byteCount = evalWord8Expr(&expr, context); byte *localMem, *local; int byteAvail; Wire.requestFrom((int) slaveAddress, (int) byteCount); byteAvail = Wire.available(); if (byteCount < byteAvail) { #ifdef DEBUG sendStringf("I2C: M"); #endif } else if (byteCount > byteAvail) { #ifdef DEBUG sendStringf("I2C: F"); #endif } localMem = (byte *) malloc(byteAvail+3); local = &localMem[3]; localMem[0] = EXPR_LIST8; localMem[1] = EXPR_LIT; localMem[2] = byteAvail; for (int i = 0; i < byteAvail; i++) { *local++ = Wire.read(); } if (context && context->bind) { putBindListPtr(context, bind, localMem); } else { sendReply(byteAvail+3, I2C_RESP_READ, localMem, context, bind); free(localMem); } return false; }
int8_t readRefInt8(int refIndex) { if (haskinoRefs[refIndex].ref != NULL) return *((int8_t *) haskinoRefs[refIndex].ref); else { #ifdef DEBUG sendStringf("rRI8: %d", refIndex); #endif return false; } }
uint32_t readRefWord32(int refIndex) { if (haskinoRefs[refIndex].ref != NULL) return *((uint32_t *) haskinoRefs[refIndex].ref); else { #ifdef DEBUG sendStringf("rRW32: %d", refIndex); #endif return false; } }
bool readRefBool(int refIndex) { if (haskinoRefs[refIndex].ref != NULL) return *((bool *) haskinoRefs[refIndex].ref); else { #ifdef DEBUG sendStringf("rRB: %d", refIndex); #endif return false; } }
float readRefFloat(int refIndex) { if (haskinoRefs[refIndex].ref != NULL) return *((float *) haskinoRefs[refIndex].ref); else { #ifdef DEBUG sendStringf("rRF: %d", refIndex); #endif return false; } }
uint8_t *readRefList8(int refIndex) { if (haskinoRefs[refIndex].ref != NULL) return (uint8_t *) haskinoRefs[refIndex].ref; else { #ifdef DEBUG sendStringf("rRL8: %d", refIndex); #endif return false; } }
static bool handleQueryAll(int size, const byte *msg, CONTEXT *context) { byte bind = msg[1]; TASK *task = firstTask; int taskCount = getTaskCount(); byte* localMem = (byte *) malloc(taskCount+2); byte* local = &localMem[2]; int i = 0; if (!localMem) { #ifdef DEBUG sendStringf("hQA: M"); #endif return false; } localMem[0] = EXPR_L(EXPR_LIT); while(task != NULL && i < taskCount) { *local++ = task->id; task = task->next; i++; } localMem[1] = i; if (context->codeBlock || context->task) { putBindListPtr(context, bind, localMem); } else { sendReply(i+2, SCHED_RESP_QUERY_ALL, localMem, context, bind); free(localMem); } return false; }