static VMINT32 measurement(VM_THREAD_HANDLE thread_handle, void* user_data) { VMINT measured_result; handle_details* details; hx711_task current_task; write_console("thread enter\n"); details = (handle_details*) user_data; get_task(details, ¤t_task); enter_standby(¤t_task); while (1) { get_task(details, ¤t_task); if (current_task.op == TERMINATE) { break; } if (current_task.op == WAIT) { enter_standby(¤t_task); continue; } if (current_task.op != A128) { wait_result(¤t_task); read_result(¤t_task); clock_setup_pulses(¤t_task); } wait_result(¤t_task); measured_result = read_result(¤t_task); current_task.callback(current_task.callback_env, measured_result); enter_standby(¤t_task); } write_console("thread exit\n"); enter_standby(¤t_task); vm_mutex_lock(&details->mutex); vm_dcl_close(current_task.sda_handle); vm_dcl_close(current_task.scl_handle); current_task.callback(current_task.callback_env, 0); vm_free(details); return 0; }
time_t sc_time(time_t * t) { command_int_t * command = (command_int_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); memcpy(command->id, CMD_TIME, 4); build_send_packet(sizeof(command_int_t)); wait_result(); return syscall_retval; }
int sc_closedir(DIR *dir) { command_int_t * command = (command_int_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); memcpy(command->id, CMD_CLOSEDIR, 4); command->value0 = htonl(dir); build_send_packet(sizeof(command_int_t)); wait_result(); return syscall_retval; }
DIR * sc_opendir(const char *name) { command_string_t * command = (command_string_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); int namelen = strlen(name); memcpy(command->id, CMD_OPENDIR, 4); memcpy(command->string, name, namelen+1); build_send_packet(sizeof(command_string_t)+namelen); wait_result(); return (DIR *)syscall_retval; }
int sc_write(int fd, const void *buf, size_t count) { command_3int_t * command = (command_3int_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); memcpy(command->id, CMD_WRITE, 4); command->value0 = htonl(fd); command->value1 = htonl(buf); command->value2 = htonl(count); build_send_packet(sizeof(command_3int_t)); wait_result(); return syscall_retval; }
int sc_fstat(int filedes, dcload_stat_t *buf) { command_3int_t * command = (command_3int_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); memcpy(command->id, CMD_FSTAT, 4); command->value0 = htonl(filedes); command->value1 = htonl(buf); command->value2 = htonl(sizeof(struct dcload_stat)); build_send_packet(sizeof(command_3int_t)); wait_result(); return syscall_retval; }
off_t sc_lseek(int fildes, off_t offset, int whence) { command_3int_t * command = (command_3int_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); memcpy(command->id, CMD_LSEEK, 4); command->value0 = htonl(fildes); command->value1 = htonl(offset); command->value2 = htonl(whence); build_send_packet(sizeof(command_3int_t)); wait_result(); return syscall_retval; }
int sc_chdir(const char *path) { command_string_t * command = (command_string_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); int namelen = strlen(path); memcpy(command->id, CMD_CHDIR, 4); memcpy(command->string, path, namelen + 1); build_send_packet(sizeof(command_string_t)+namelen); wait_result(); return syscall_retval; }
int sc_stat(const char *file_name, struct dcload_stat *buf) { command_2int_string_t * command = (command_2int_string_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); int namelen = strlen(file_name); memcpy(command->id, CMD_STAT, 4); memcpy(command->string, file_name, namelen+1); command->value0 = htonl(buf); command->value1 = htonl(sizeof(struct dcload_stat)); build_send_packet(sizeof(command_2int_string_t)+namelen); wait_result(); return syscall_retval; }
struct dcload_dirent *sc_readdir(DIR *dir) { command_3int_t * command = (command_3int_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); memcpy(command->id, CMD_READDIR, 4); command->value0 = htonl(dir); command->value1 = htonl(&our_dir); command->value2 = htonl(sizeof(struct dcload_dirent)); build_send_packet(sizeof(command_3int_t)); wait_result(); if (syscall_retval) return &our_dir; else return 0; }
int sc_chmod(const char *path, int mode) { command_int_string_t * command = (command_int_string_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); int namelen = strlen(path); memcpy(command->id, CMD_CHMOD, 4); command->value0 = htonl(mode); memcpy(command->string, path, namelen+1); build_send_packet(sizeof(command_int_string_t)+namelen); wait_result(); return syscall_retval; }
int sc_link(const char *oldpath, const char *newpath) { command_string_t * command = (command_string_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); int namelen1 = strlen(oldpath); int namelen2 = strlen(newpath); memcpy(command->id, CMD_LINK, 4); memcpy(command->string, oldpath, namelen1 + 1); memcpy(command->string + namelen1 + 1, newpath, namelen2 + 1); build_send_packet(sizeof(command_string_t)+namelen1+namelen2+1); wait_result(); return syscall_retval; }
int sc_utime(const char *filename, struct utimbuf *buf) { command_3int_string_t * command = (command_3int_string_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); int namelen = strlen(filename); memcpy(command->id, CMD_UTIME, 4); memcpy(command->string, filename, namelen+1); command->value0 = htonl(buf); if (!buf) { command->value1 = htonl(buf->actime); command->value2 = htonl(buf->modtime); } build_send_packet(sizeof(command_3int_string_t)+namelen); wait_result(); return syscall_retval; }
int sc_open(const char *pathname, int flags, ...) { va_list ap; command_2int_string_t * command = (command_2int_string_t *)(pkt_buf + ETHER_H_LEN + IP_H_LEN + UDP_H_LEN); int namelen = strlen(pathname); memcpy(command->id, CMD_OPEN, 4); va_start(ap, flags); command->value0 = htonl(flags); command->value1 = htonl(va_arg(ap, int)); va_end(ap); memcpy(command->string, pathname, namelen+1); build_send_packet(sizeof(command_2int_string_t)+namelen); wait_result(); return syscall_retval; }
static char *run_command(char *command) { fprintf(stdout, "%s\n", command); return wait_result(); }