How to use SetPaused method of local Package

Best K6 code snippet using local.SetPaused

bufferflow_grbl.go

Source:bufferflow_grbl.go Github

copy

Full Screen

...35 ErrorCode string36}37func (b *BufferflowGrbl) Init() {38 b.lock = &sync.Mutex{}39 b.SetPaused(false, 1)40 log.Println("Initting GRBL buffer flow")41 // b.BufferMax = 127 //max buffer size 127 bytes available42 b.BufferMax = 125 // changed to be safe with extra chars43 b.q = NewQueue()44 //create channels45 b.sem = make(chan int)46 //define regex47 b.reNewLine, _ = regexp.Compile("\\r{0,1}\\n{1,2}") //\\r{0,1}48 b.ok, _ = regexp.Compile("^ok")49 b.err, _ = regexp.Compile("^error")50 b.initline, _ = regexp.Compile("^Grbl")51 b.qry, _ = regexp.Compile("\\?")52 b.rpt, _ = regexp.Compile("^<")53 //initialize query loop54 b.rptQueryLoop(b.parent_serport)55}56func (b *BufferflowGrbl) RewriteSerialData(cmd string, id string) string {57 return ""58}59func (b *BufferflowGrbl) BlockUntilReady(cmd string, id string) (bool, bool, string) {60 log.Printf("BlockUntilReady() start\n")61 b.q.Push(cmd, id)62 log.Printf("New line length: %v, buffer size increased to:%v\n", len(cmd), b.q.LenOfCmds())63 log.Println(b.q)64 if b.q.LenOfCmds() >= b.BufferMax {65 b.SetPaused(true, 0)66 log.Printf("Buffer Full - Will send this command when space is available")67 }68 if b.GetPaused() {69 log.Println("It appears we are being asked to pause, so we will wait on b.sem")70 // We are being asked to pause our sending of commands71 // clear all b.sem signals so when we block below, we truly block72 b.ClearOutSemaphore()73 log.Println("Blocking on b.sem until told from OnIncomingData to go")74 unblockType, ok := <-b.sem // will block until told from OnIncomingData to go75 log.Printf("Done blocking cuz got b.sem semaphore release. ok:%v, unblockType:%v\n", ok, unblockType)76 // we get an unblockType of 1 for normal unblocks77 // we get an unblockType of 2 when we're being asked to wipe the buffer, i.e. from a % cmd78 if unblockType == 2 {79 log.Println("This was an unblock of type 2, which means we're being asked to wipe internal buffer. so return false.")80 // returning false asks the calling method to wipe the serial send once81 // this function returns82 return false, false, ""83 }84 log.Printf("BlockUntilReady(cmd:%q, id:%v) end\n", cmd, id)85 }86 return true, true, ""87}88func (b *BufferflowGrbl) OnIncomingData(data string) {89 log.Printf("OnIncomingData() start. data:%q\n", data)90 b.LatestData += data91 //it was found ok was only received with status responses until the grbl buffer is full.92 //b.LatestData = regexp.MustCompile(">\\r\\nok").ReplaceAllString(b.LatestData, ">") //remove oks from status responses93 arrLines := b.reNewLine.Split(b.LatestData, -1)94 log.Printf("arrLines:%v\n", arrLines)95 if len(arrLines) > 1 {96 // that means we found a newline and have 2 or greater array values97 // so we need to analyze our arrLines[] lines but keep last line98 // for next trip into OnIncomingData99 log.Printf("We have data lines to analyze. numLines:%v\n", len(arrLines))100 } else {101 // we don't have a newline yet, so just exit and move on102 // we don't have to reset b.LatestData because we ended up103 // without any newlines so maybe we will next time into this method104 log.Printf("Did not find newline yet, so nothing to analyze\n")105 return106 }107 // if we made it here we have lines to analyze108 // so analyze all of them except the last line109 for index, element := range arrLines[:len(arrLines)-1] {110 log.Printf("Working on element:%v, index:%v", element, index)111 //check for 'ok' or 'error' response indicating a gcode line has been processed112 if b.ok.MatchString(element) || b.err.MatchString(element) {113 if b.q.Len() > 0 {114 doneCmd, id := b.q.Poll()115 if b.ok.MatchString(element) {116 // Send cmd:"Complete" back117 m := DataCmdComplete{"Complete", id, b.Port, b.q.LenOfCmds(), doneCmd}118 bm, err := json.Marshal(m)119 if err == nil {120 h.broadcastSys <- bm121 }122 } else if b.err.MatchString(element) {123 // Send cmd:"Error" back124 log.Printf("Error Response Received:%v, id:%v", doneCmd, id)125 arrErrors := strings.SplitN(element, ":", 2)126 errCode := ""127 if len(arrErrors) == 2 {128 errCode = arrErrors[1]129 }130 m := DataCmdError{DataCmdComplete{"Error", id, b.Port, b.q.LenOfCmds(), doneCmd}, errCode}131 bm, err := json.Marshal(m)132 if err == nil {133 h.broadcastSys <- bm134 }135 }136 log.Printf("Buffer decreased to itemCnt:%v, lenOfBuf:%v\n", b.q.Len(), b.q.LenOfCmds())137 } else {138 log.Printf("We should NEVER get here cuz we should have a command in the queue to dequeue when we get the r:{} response. If you see this debug stmt this is BAD!!!!")139 }140 if b.q.LenOfCmds() < b.BufferMax {141 log.Printf("Grbl just completed a line of gcode\n")142 // if we are paused, tell us to unpause cuz we have clean buffer room now143 if b.GetPaused() {144 b.SetPaused(false, 1)145 }146 }147 //check for the grbl init line indicating the arduino is ready to accept commands148 //could also pull version from this string, if we find a need for that later149 } else if b.initline.MatchString(element) {150 //grbl init line received, clear anything from current buffer and unpause151 b.LocalBufferWipe(b.parent_serport)152 //unpause buffer but wipe the command in the queue as grbl has restarted.153 if b.GetPaused() {154 b.SetPaused(false, 2)155 }156 b.version = element //save element in version157 //Check for report output, compare to last report output, if different return to client to update status; otherwise ignore status.158 } else if b.rpt.MatchString(element) {159 if element == b.LastStatus {160 log.Println("Grbl status has not changed, not reporting to client")161 continue //skip this element as the cnc position has not changed, and move on to the next element.162 }163 b.LastStatus = element //if we make it here something has changed with the status string and laststatus needs updating164 }165 // handle communication back to client166 m := DataPerLine{b.Port, element + "\n"}167 bm, err := json.Marshal(m)168 if err == nil {169 h.broadcastSys <- bm170 }171 } // for loop172 // now wipe the LatestData to only have the last line that we did not analyze173 // because we didn't know/think that was a full command yet174 b.LatestData = arrLines[len(arrLines)-1]175 //time.Sleep(3000 * time.Millisecond)176 log.Printf("OnIncomingData() end.\n")177}178// Clean out b.sem so it can truly block179func (b *BufferflowGrbl) ClearOutSemaphore() {180 ctr := 0181 keepLooping := true182 for keepLooping {183 select {184 case d, ok := <-b.sem:185 log.Printf("Consuming b.sem queue to clear it before we block. ok:%v, d:%v\n", ok, string(d))186 ctr++187 if ok == false {188 keepLooping = false189 }190 default:191 keepLooping = false192 log.Println("Hit default in select clause")193 }194 }195 log.Printf("Done consuming b.sem queue so we're good to block on it now. ctr:%v\n", ctr)196 // ok, all b.sem signals are now consumed into la-la land197}198func (b *BufferflowGrbl) BreakApartCommands(cmd string) []string {199 // add newline after !~%200 log.Printf("Command Before Break-Apart: %q\n", cmd)201 cmds := strings.Split(cmd, "\n")202 finalCmds := []string{}203 for _, item := range cmds {204 //remove comments and whitespace from item205 item = regexp.MustCompile("\\(.*?\\)").ReplaceAllString(item, "")206 item = regexp.MustCompile(";.*").ReplaceAllString(item, "")207 item = strings.Replace(item, " ", "", -1)208 if len(item) > utf8.RuneCountInString(item) { // If item contains UTF-8 chars other than ASCII. Extended ASCII must be extracted from UTF8 code point209 r := []rune(item) // Note : Extended ASCII are used for some realtime commands210 a := make([]byte, len(r))211 for idx, element := range r {212 a[idx] = byte(element)213 }214 item = string(a)215 }216 217 if item == "*init*" { //return init string to update grbl widget when already connected to grbl218 m := DataPerLine{b.Port, b.version + "\n"}219 bm, err := json.Marshal(m)220 if err == nil {221 h.broadcastSys <- bm222 }223 } else if item == "*status*" { //return status when client first connects to existing open port224 m := DataPerLine{b.Port, b.LastStatus + "\n"}225 bm, err := json.Marshal(m)226 if err == nil {227 h.broadcastSys <- bm228 }229 } else if b.SeeIfSpecificCommandsShouldSkipBuffer(item) { // realtime commands don't need '\n'230 log.Printf("Query added without newline: %q\n", item)231 finalCmds = append(finalCmds, item) //append query request without newline character232 } else if item == "%" {233 log.Printf("Wiping Grbl BufferFlow")234 b.LocalBufferWipe(b.parent_serport)235 //dont add this command to the list of finalCmds236 } else if item != "" {237 log.Printf("Re-adding newline to item:%q\n", item)238 s := item + "\n"239 finalCmds = append(finalCmds, s)240 log.Printf("New cmd item:%q\n", s)241 }242 }243 log.Printf("Final array of cmds after BreakApartCommands(). finalCmds:%v\n", finalCmds)244 return finalCmds245 //return []string{cmd} //do not process string246}247func (b *BufferflowGrbl) Pause() {248 b.SetPaused(true, 0)249 //b.BypassMode = false // turn off bypassmode in case it's on250 log.Println("Paused buffer on next BlockUntilReady() call")251}252func (b *BufferflowGrbl) Unpause() {253 //unpause buffer by setting paused to false and passing a 1 to b.sem254 b.SetPaused(false, 1)255 log.Println("Unpaused buffer inside BlockUntilReady() call")256}257func (b *BufferflowGrbl) SeeIfSpecificCommandsShouldSkipBuffer(cmd string) bool {258 if len(cmd) != 1 { // Skip buffer commands (=realtime commands) are always single byte259 return false260 }261 c := cmd[0] // Extract ASCII code262 return c == '!' || c == '~' || c == '?' || c == 0x18 || c >= 0x80 263 // remove comments264 //cmd = regexp.MustCompile("\\(.*?\\)").ReplaceAllString(cmd, "")265 //cmd = regexp.MustCompile(";.*").ReplaceAllString(cmd, "")266 // adding some new regexp to match real-time commands for grbl 1 version 267 //if match, _ := regexp.MatchString("[!~\\?]|(\u0018)|[\u0080-\u00FF]", cmd); match {268 // log.Printf("Found cmd that should skip buffer. cmd:%q\n", cmd)269 // return true270 //}271 //return false272}273func (b *BufferflowGrbl) SeeIfSpecificCommandsShouldPauseBuffer(cmd string) bool {274 // remove comments275 //cmd = regexp.MustCompile("\\(.*?\\)").ReplaceAllString(cmd, "")276 //cmd = regexp.MustCompile(";.*").ReplaceAllString(cmd, "")277 //if match, _ := regexp.MatchString("[!]", cmd); match {278 // log.Printf("Found cmd that should pause buffer. cmd:%v\n", cmd)279 // return true280 //}281 return false // No command should stop the transmission282}283func (b *BufferflowGrbl) SeeIfSpecificCommandsShouldUnpauseBuffer(cmd string) bool {284 //cmd = regexp.MustCompile("\\(.*?\\)").ReplaceAllString(cmd, "")285 //cmd = regexp.MustCompile(";.*").ReplaceAllString(cmd, "")286 //if match, _ := regexp.MatchString("[~]", cmd); match {287 // log.Printf("Found cmd that should unpause buffer. cmd:%v\n", cmd)288 // return true289 //}290 return false // No command should stop the transmission291}292func (b *BufferflowGrbl) SeeIfSpecificCommandsShouldWipeBuffer(cmd string) bool {293 //cmd = regexp.MustCompile("\\(.*?\\)").ReplaceAllString(cmd, "")294 //cmd = regexp.MustCompile(";.*").ReplaceAllString(cmd, "")295 if match, _ := regexp.MatchString("(\u0018)", cmd); match {296 log.Printf("Found cmd that should wipe out and reset buffer. cmd:%v\n", cmd)297 //b.q.Delete() //delete tracking queue, all buffered commands will be wiped.298 //log.Println("Buffer variables cleared for new input.")299 return true300 }301 return false302}303func (b *BufferflowGrbl) SeeIfSpecificCommandsReturnNoResponse(cmd string) bool {304 /*305 // remove comments306 cmd = b.reComment.ReplaceAllString(cmd, "")307 cmd = b.reComment2.ReplaceAllString(cmd, "")308 if match := b.reNoResponse.MatchString(cmd); match {309 log.Printf("Found cmd that does not get a response from TinyG. cmd:%v\n", cmd)310 return true311 }312 */313 return false314}315func (b *BufferflowGrbl) ReleaseLock() {316 log.Println("Lock being released in GRBL buffer")317 b.q.Delete()318 log.Println("ReleaseLock(), so we will send signal of 2 to b.sem to unpause the BlockUntilReady() thread")319 //release lock, send signal 2 to b.sem320 b.SetPaused(false, 2)321}322func (b *BufferflowGrbl) IsBufferGloballySendingBackIncomingData() bool {323 //telling json server that we are handling client responses324 return true325}326//Use this function to open a connection, write directly to serial port and close connection.327//This is used for sending query requests outside of the normal buffered operations that will pause to wait for room in the grbl buffer328//'?' is asynchronous to the normal buffer load and does not need to be paused when buffer full329func (b *BufferflowGrbl) rptQueryLoop(p *serport) {330 b.parent_serport = p //make note of this port for use in clearing the buffer later, on error.331 ticker := time.NewTicker(250 * time.Millisecond)332 b.quit = make(chan int)333 go func() {334 for {335 select {336 case <-ticker.C:337 n2, err := p.portIo.Write([]byte("?"))338 log.Print("Just wrote ", n2, " bytes to serial: ?")339 if err != nil {340 errstr := "Error writing to " + p.portConf.Name + " " + err.Error() + " Closing port."341 log.Print(errstr)342 h.broadcastSys <- []byte(errstr)343 ticker.Stop() //stop query loop if we can't write to the port344 break345 }346 case <-b.quit:347 ticker.Stop()348 return349 }350 }351 }()352}353func (b *BufferflowGrbl) Close() {354 //stop the status query loop when the serial port is closed off.355 log.Println("Stopping the status query loop")356 b.quit <- 1357}358// Gets the paused state of this buffer359// go-routine safe.360func (b *BufferflowGrbl) GetPaused() bool {361 b.lock.Lock()362 defer b.lock.Unlock()363 return b.Paused364}365// Sets the paused state of this buffer366// go-routine safe.367func (b *BufferflowGrbl) SetPaused(isPaused bool, semRelease int) {368 b.lock.Lock()369 defer b.lock.Unlock()370 b.Paused = isPaused371 //if we are unpausing the buffer, we need to send a signal to release the channel372 if isPaused == false {373 go func() {374 // sending a 2 asks BlockUntilReady() to cancel the send375 b.sem <- semRelease376 defer func() {377 log.Printf("Unpause Semaphore just got consumed by the BlockUntilReady()\n")378 }()379 }()380 }381}...

Full Screen

Full Screen

bufferflow_marlin.go

Source:bufferflow_marlin.go Github

copy

Full Screen

...30 rpt *regexp.Regexp31}32func (b *BufferflowMarlin) Init() {33 b.lock = &sync.Mutex{}34 b.SetPaused(false, 1)35 log.Println("Initting MARLIN buffer flow")36 b.BufferMax = 127 //max buffer size 127 bytes available37 b.q = NewQueue()38 //create channels39 b.sem = make(chan int)40 //define regex41 b.reNewLine, _ = regexp.Compile("\\r{0,1}\\n{1,2}") //\\r{0,1}42 b.ok, _ = regexp.Compile("^ok")43 b.err, _ = regexp.Compile("^error")44 b.initline, _ = regexp.Compile("^echo:Marlin")45 b.qry, _ = regexp.Compile("\\?")46 b.rpt, _ = regexp.Compile("^X:")47 //initialize query loop48 b.rptQueryLoop(b.parent_serport) // Disable the query loop49}50func (b *BufferflowMarlin) RewriteSerialData(cmd string, id string) string {51 return ""52}53func (b *BufferflowMarlin) BlockUntilReady(cmd string, id string) (bool, bool, string) {54 log.Printf("BlockUntilReady() start\n")55 b.q.Push(cmd, id)56 log.Printf("New line length: %v, buffer size increased to:%v\n", len(cmd), b.q.LenOfCmds())57 log.Println(b.q)58 if b.q.LenOfCmds() >= b.BufferMax {59 b.SetPaused(true, 0)60 log.Printf("Buffer Full - Will send this command when space is available")61 }62 if b.GetPaused() {63 log.Println("It appears we are being asked to pause, so we will wait on b.sem")64 // We are being asked to pause our sending of commands65 // clear all b.sem signals so when we block below, we truly block66 b.ClearOutSemaphore()67 log.Println("Blocking on b.sem until told from OnIncomingData to go")68 unblockType, ok := <-b.sem // will block until told from OnIncomingData to go69 log.Printf("Done blocking cuz got b.sem semaphore release. ok:%v, unblockType:%v\n", ok, unblockType)70 // we get an unblockType of 1 for normal unblocks71 // we get an unblockType of 2 when we're being asked to wipe the buffer, i.e. from a % cmd72 if unblockType == 2 {73 log.Println("This was an unblock of type 2, which means we're being asked to wipe internal buffer. so return false.")74 // returning false asks the calling method to wipe the serial send once75 // this function returns76 return false, false, ""77 }78 log.Printf("BlockUntilReady(cmd:%v, id:%v) end\n", cmd, id)79 }80 return true, true, ""81}82func (b *BufferflowMarlin) OnIncomingData(data string) {83 log.Printf("OnIncomingData() start. data:%q\n", data)84 b.LatestData += data85 //it was found ok was only received with status responses until the MARLIN buffer is full.86 //b.LatestData = regexp.MustCompile(">\\r\\nok").ReplaceAllString(b.LatestData, ">") //remove oks from status responses87 arrLines := b.reNewLine.Split(b.LatestData, -1)88 log.Printf("arrLines:%v\n", arrLines)89 if len(arrLines) > 1 {90 // that means we found a newline and have 2 or greater array values91 // so we need to analyze our arrLines[] lines but keep last line92 // for next trip into OnIncomingData93 log.Printf("We have data lines to analyze. numLines:%v\n", len(arrLines))94 } else {95 // we don't have a newline yet, so just exit and move on96 // we don't have to reset b.LatestData because we ended up97 // without any newlines so maybe we will next time into this method98 log.Printf("Did not find newline yet, so nothing to analyze\n")99 return100 }101 // if we made it here we have lines to analyze102 // so analyze all of them except the last line103 for index, element := range arrLines[:len(arrLines)-1] {104 log.Printf("Working on element:%v, index:%v", element, index)105 //check for 'ok' or 'error' response indicating a gcode line has been processed106 if b.ok.MatchString(element) || b.err.MatchString(element) {107 if b.q.Len() > 0 {108 doneCmd, id := b.q.Poll()109 if b.ok.MatchString(element) {110 // Send cmd:"Complete" back111 m := DataCmdComplete{"Complete", id, b.Port, b.q.LenOfCmds(), doneCmd}112 bm, err := json.Marshal(m)113 if err == nil {114 h.broadcastSys <- bm115 }116 } else if b.err.MatchString(element) {117 // Send cmd:"Error" back118 log.Printf("Error Response Received:%v, id:%v", doneCmd, id)119 m := DataCmdComplete{"Error", id, b.Port, b.q.LenOfCmds(), doneCmd}120 bm, err := json.Marshal(m)121 if err == nil {122 h.broadcastSys <- bm123 }124 }125 log.Printf("Buffer decreased to itemCnt:%v, lenOfBuf:%v\n", b.q.Len(), b.q.LenOfCmds())126 } else {127 log.Printf("We should NEVER get here cuz we should have a command in the queue to dequeue when we get the r:{} response. If you see this debug stmt this is BAD!!!!")128 }129 if b.q.LenOfCmds() < b.BufferMax {130 log.Printf("Marlin just completed a line of gcode\n")131 // if we are paused, tell us to unpause cuz we have clean buffer room now132 if b.GetPaused() {133 b.SetPaused(false, 1)134 }135 }136 //check for the marlin init line indicating the arduino is ready to accept commands137 //could also pull version from this string, if we find a need for that later138 } else if b.initline.MatchString(element) {139 //marlin init line received, clear anything from current buffer and unpause140 b.LocalBufferWipe(b.parent_serport)141 //unpause buffer but wipe the command in the queue as marlin has restarted.142 if b.GetPaused() {143 b.SetPaused(false, 2)144 }145 b.version = element //save element in version146 //Check for report output, compare to last report output, if different return to client to update status; otherwise ignore status.147 } else if b.rpt.MatchString(element) {148 //if element == b.LastStatus {149 // log.Println("Marlin status has not changed, not reporting to client")150 // continue //skip this element as the cnc position has not changed, and move on to the next element.151 //}152 b.LastStatus = element //if we make it here something has changed with the status string and laststatus needs updating153 }154 // handle communication back to client155 m := DataPerLine{b.Port, element + "\n"}156 bm, err := json.Marshal(m)157 if err == nil {158 h.broadcastSys <- bm159 }160 } // for loop161 // now wipe the LatestData to only have the last line that we did not analyze162 // because we didn't know/think that was a full command yet163 b.LatestData = arrLines[len(arrLines)-1]164 //time.Sleep(3000 * time.Millisecond)165 log.Printf("OnIncomingData() end.\n")166}167// Clean out b.sem so it can truly block168func (b *BufferflowMarlin) ClearOutSemaphore() {169 ctr := 0170 keepLooping := true171 for keepLooping {172 select {173 case d, ok := <-b.sem:174 log.Printf("Consuming b.sem queue to clear it before we block. ok:%v, d:%v\n", ok, string(d))175 ctr++176 if ok == false {177 keepLooping = false178 }179 default:180 keepLooping = false181 log.Println("Hit default in select clause")182 }183 }184 log.Printf("Done consuming b.sem queue so we're good to block on it now. ctr:%v\n", ctr)185 // ok, all b.sem signals are now consumed into la-la land186}187func (b *BufferflowMarlin) BreakApartCommands(cmd string) []string {188 // add newline after !~%189 log.Printf("Command Before Break-Apart: %q\n", cmd)190 cmds := strings.Split(cmd, "\n")191 finalCmds := []string{}192 for _, item := range cmds {193 //remove comments and whitespace from item194 item = regexp.MustCompile("\\(.*?\\)").ReplaceAllString(item, "")195 item = regexp.MustCompile(";.*").ReplaceAllString(item, "")196 item = strings.Replace(item, " ", "", -1)197 if item == "*init*" { //return init string to update marlin widget when already connected to marlin198 m := DataPerLine{b.Port, b.version + "\n"}199 bm, err := json.Marshal(m)200 if err == nil {201 h.broadcastSys <- bm202 }203 } else if item == "*status*" { //return status when client first connects to existing open port204 m := DataPerLine{b.Port, b.LastStatus + "\n"}205 bm, err := json.Marshal(m)206 if err == nil {207 h.broadcastSys <- bm208 }209 } else if item == "?" {210 log.Printf("Query added without newline: %q\n", item)211 finalCmds = append(finalCmds, item) //append query request without newline character212 } else if item == "%" {213 log.Printf("Wiping Marlin BufferFlow")214 b.LocalBufferWipe(b.parent_serport)215 //dont add this command to the list of finalCmds216 } else if item != "" {217 log.Printf("Re-adding newline to item:%v\n", item)218 s := item + "\n"219 finalCmds = append(finalCmds, s)220 log.Printf("New cmd item:%v\n", s)221 }222 }223 log.Printf("Final array of cmds after BreakApartCommands(). finalCmds:%v\n", finalCmds)224 return finalCmds225 //return []string{cmd} //do not process string226}227func (b *BufferflowMarlin) Pause() {228 b.SetPaused(true, 0)229 //b.BypassMode = false // turn off bypassmode in case it's on230 log.Println("Paused buffer on next BlockUntilReady() call")231}232func (b *BufferflowMarlin) Unpause() {233 //unpause buffer by setting paused to false and passing a 1 to b.sem234 b.SetPaused(false, 1)235 log.Println("Unpaused buffer inside BlockUntilReady() call")236}237func (b *BufferflowMarlin) SeeIfSpecificCommandsShouldSkipBuffer(cmd string) bool {238 // remove comments239 //cmd = regexp.MustCompile("\\(.*?\\)").ReplaceAllString(cmd, "")240 //cmd = regexp.MustCompile(";.*").ReplaceAllString(cmd, "")241 if match, _ := regexp.MatchString("[!~\\?]|(\u0018)", cmd); match {242 log.Printf("Found cmd that should skip buffer. cmd:%v\n", cmd)243 return true244 }245 return false246}247func (b *BufferflowMarlin) SeeIfSpecificCommandsShouldPauseBuffer(cmd string) bool {248 // remove comments249 //cmd = regexp.MustCompile("\\(.*?\\)").ReplaceAllString(cmd, "")250 //cmd = regexp.MustCompile(";.*").ReplaceAllString(cmd, "")251 if match, _ := regexp.MatchString("[!]", cmd); match {252 log.Printf("Found cmd that should pause buffer. cmd:%v\n", cmd)253 return true254 }255 return false256}257func (b *BufferflowMarlin) SeeIfSpecificCommandsShouldUnpauseBuffer(cmd string) bool {258 //cmd = regexp.MustCompile("\\(.*?\\)").ReplaceAllString(cmd, "")259 //cmd = regexp.MustCompile(";.*").ReplaceAllString(cmd, "")260 if match, _ := regexp.MatchString("[~]", cmd); match {261 log.Printf("Found cmd that should unpause buffer. cmd:%v\n", cmd)262 return true263 }264 return false265}266func (b *BufferflowMarlin) SeeIfSpecificCommandsShouldWipeBuffer(cmd string) bool {267 //cmd = regexp.MustCompile("\\(.*?\\)").ReplaceAllString(cmd, "")268 //cmd = regexp.MustCompile(";.*").ReplaceAllString(cmd, "")269 if match, _ := regexp.MatchString("(\u0018)", cmd); match {270 log.Printf("Found cmd that should wipe out and reset buffer. cmd:%v\n", cmd)271 //b.q.Delete() //delete tracking queue, all buffered commands will be wiped.272 //log.Println("Buffer variables cleared for new input.")273 return true274 }275 return false276}277func (b *BufferflowMarlin) SeeIfSpecificCommandsReturnNoResponse(cmd string) bool {278 /*279 // remove comments280 cmd = b.reComment.ReplaceAllString(cmd, "")281 cmd = b.reComment2.ReplaceAllString(cmd, "")282 if match := b.reNoResponse.MatchString(cmd); match {283 log.Printf("Found cmd that does not get a response from TinyG. cmd:%v\n", cmd)284 return true285 }286 */287 return false288}289func (b *BufferflowMarlin) ReleaseLock() {290 log.Println("Lock being released in Marlin buffer")291 b.q.Delete()292 log.Println("ReleaseLock(), so we will send signal of 2 to b.sem to unpause the BlockUntilReady() thread")293 //release lock, send signal 2 to b.sem294 b.SetPaused(false, 2)295}296func (b *BufferflowMarlin) IsBufferGloballySendingBackIncomingData() bool {297 //telling json server that we are handling client responses298 return true299}300//Use this function to open a connection, write directly to serial port and close connection.301//This is used for sending query requests outside of the normal buffered operations that will pause to wait for room in the marlin buffer302//'?' is asynchronous to the normal buffer load and does not need to be paused when buffer full303func (b *BufferflowMarlin) rptQueryLoop(p *serport) {304 b.parent_serport = p //make note of this port for use in clearing the buffer later, on error.305 ticker := time.NewTicker(2000 * time.Millisecond)306 b.quit = make(chan int)307 go func() {308 for {309 select {310 case <-ticker.C:311 n2, err := p.portIo.Write([]byte("M114\n"))312 log.Print("Just wrote ", n2, " bytes to serial: M114")313 if err != nil {314 errstr := "Error writing to " + p.portConf.Name + " " + err.Error() + " Closing port."315 log.Print(errstr)316 h.broadcastSys <- []byte(errstr)317 ticker.Stop() //stop query loop if we can't write to the port318 break319 }320 case <-b.quit:321 ticker.Stop()322 return323 }324 }325 }()326}327func (b *BufferflowMarlin) Close() {328 //stop the status query loop when the serial port is closed off.329 log.Println("Stopping the status query loop")330 b.quit <- 1331}332// Gets the paused state of this buffer333// go-routine safe.334func (b *BufferflowMarlin) GetPaused() bool {335 b.lock.Lock()336 defer b.lock.Unlock()337 return b.Paused338}339// Sets the paused state of this buffer340// go-routine safe.341func (b *BufferflowMarlin) SetPaused(isPaused bool, semRelease int) {342 b.lock.Lock()343 defer b.lock.Unlock()344 b.Paused = isPaused345 //if we are unpausing the buffer, we need to send a signal to release the channel346 if isPaused == false {347 go func() {348 // sending a 2 asks BlockUntilReady() to cancel the send349 b.sem <- semRelease350 defer func() {351 log.Printf("Unpause Semaphore just got consumed by the BlockUntilReady()\n")352 }()353 }()354 }355}...

Full Screen

Full Screen

SetPaused

Using AI Code Generation

copy

Full Screen

1local := &Local{}2local.SetPaused(true)3local := &Local{}4local.SetPaused(true)5local := &Local{}6local.SetPaused(true)7local := &Local{}8local.SetPaused(true)9local := &Local{}10local.SetPaused(true)11local := &Local{}12local.SetPaused(true)13local := &Local{}14local.SetPaused(true)15local := &Local{}16local.SetPaused(true)17local := &Local{}18local.SetPaused(true)19local := &Local{}20local.SetPaused(true)21local := &Local{}22local.SetPaused(true)23local := &Local{}24local.SetPaused(true)25local := &Local{}26local.SetPaused(true)27local := &Local{}28local.SetPaused(true)29local := &Local{}30local.SetPaused(true)31local := &Local{}32local.SetPaused(true)33local := &Local{}34local.SetPaused(true)35local := &Local{}36local.SetPaused(true)

Full Screen

Full Screen

SetPaused

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println("Hello, playground")4}5import "fmt"6func main() {7 fmt.Println("Hello, playground")8}9import "fmt"10func main() {11 fmt.Println("Hello, playground")12}13import "fmt"14func main() {15 fmt.Println("Hello, playground")16}17import "fmt"18func main() {19 fmt.Println("Hello, playground")20}21import "fmt"22func main() {23 fmt.Println("Hello, playground")24}25import "fmt"26func main() {27 fmt.Println("Hello, playground")28}29import "fmt"30func main() {31 fmt.Println("Hello, playground")32}33import "fmt"34func main() {35 fmt.Println("Hello, playground")36}37import "fmt"38func main() {39 fmt.Println("Hello, playground")40}41import "fmt"42func main() {43 fmt.Println("Hello, playground")44}45import "fmt"46func main() {47 fmt.Println("Hello, playground")48}49import "fmt"50func main() {51 fmt.Println("Hello, playground")52}53import "fmt"54func main() {55 fmt.Println("Hello, playground")56}57import "fmt"58func main() {59 fmt.Println("Hello, playground")60}61import "fmt"62func main() {63 fmt.Println("Hello, playground")64}65import "fmt"66func main() {67 fmt.Println("Hello, playground")68}69import "fmt"70func main() {

Full Screen

Full Screen

SetPaused

Using AI Code Generation

copy

Full Screen

1var obj = new Local();2obj.SetPaused(true);3var obj = new Local();4obj.SetPaused(true);5var obj = new Local();6obj.SetPaused(true);7var obj = new Local();8obj.SetPaused(true);9var obj = new Local();10obj.SetPaused(true);11var obj = new Local();12obj.SetPaused(true);13var obj = new Local();14obj.SetPaused(true);15var obj = new Local();16obj.SetPaused(true);17var obj = new Local();18obj.SetPaused(true);19var obj = new Local();20obj.SetPaused(true);21var obj = new Local();22obj.SetPaused(true);23var obj = new Local();24obj.SetPaused(true);25var obj = new Local();26obj.SetPaused(true);27var obj = new Local();28obj.SetPaused(true);29var obj = new Local();30obj.SetPaused(true);31var obj = new Local();32obj.SetPaused(true);33var obj = new Local();34obj.SetPaused(true);

Full Screen

Full Screen

SetPaused

Using AI Code Generation

copy

Full Screen

1import "fmt"2type Person struct {3}4func (p *Person) SetPaused() {5fmt.Println("SetPaused")6}7func main() {8p := &Person{}9p.SetPaused()10}11import "fmt"12type Person struct {13}14func (p *Person) SetPaused() {15fmt.Println("SetPaused")16}17func main() {18p := &Person{}19p.SetPaused()20}21import "fmt"22type Person struct {23}24func (p *Person) SetPaused() {25fmt.Println("SetPaused")26}27func main() {28p := &Person{}29p.SetPaused()30}31import "fmt"32import "example.com/1"33func main() {34p := &1.Person{}35p.SetPaused()36}37./2.go:9: p.SetPaused undefined (type *1.Person has no field or method SetPaused)

Full Screen

Full Screen

SetPaused

Using AI Code Generation

copy

Full Screen

1import (2type Test struct {3}4func (t *Test) SetPaused() {5}6func main() {7 t := new(Test)8 fmt.Println(t)9 t.SetPaused()10}11import (12type Test struct {13}14func (t *Test) SetPaused() {15}16func main() {17 t := new(Test)18 fmt.Println(t)19 t.SetPaused()20}21import (22type Test struct {23}24func (t *Test) SetPaused() {25}26func main() {27 t := new(Test)28 fmt.Println(t)29 t.SetPaused()30}31import (32type Test struct {33}34func (t *Test) SetPaused() {35}36func main() {37 t := new(Test)38 fmt.Println(t)39 t.SetPaused()40}41import (42type Test struct {43}44func (t *Test) SetPaused() {45}46func main() {47 t := new(Test)48 fmt.Println(t)49 t.SetPaused()50}51import (52type Test struct {53}54func (t *Test) SetPaused() {55}56func main() {57 t := new(Test)58 fmt.Println(t)59 t.SetPaused()60}61import (62type Test struct {63}64func (t *Test) SetPaused() {65}66func main() {67 t := new(Test)68 fmt.Println(t)69 t.SetPaused()70}71import (72type Test struct {73}74func (t *Test) SetPaused() {

Full Screen

Full Screen

SetPaused

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello World!")4 p := new(Pause)5 p.SetPaused(true)6 fmt.Println(p)7}8type Pause struct {9}10func (p *Pause) SetPaused(paused bool) {11}12func (p *Pause) IsPaused() bool {13}14func (p *Pause) PauseIfRequired() {15 if p.paused {16 fmt.Println("Paused")17 time.Sleep(5 * time.Second)18 fmt.Println("Unpaused")19 }20}21import (22func main() {23 fmt.Println("Hello World!")24 p := new(Pause)25 p.SetPaused(true)26 fmt.Println(p)27}28type Pause struct {29}30func (p *Pause) SetPaused(paused bool) {31}32func (p *Pause) IsPaused() bool {33}34func (p *Pause) PauseIfRequired() {35 if p.paused {36 fmt.Println("Paused")37 time.Sleep(5 * time.Second)38 fmt.Println("Unpaused")39 }40}41import (42func main() {43 fmt.Println("Hello World!")44 p := new(Pause)45 p.SetPaused(true)46 fmt.Println(p)47}48type Pause struct {49}50func (p *Pause) SetPaused(paused bool) {51}52func (p *Pause) IsPaused() bool {53}54func (p *Pause) PauseIfRequired() {55 if p.paused {56 fmt.Println("Paused")57 time.Sleep(5 * time.Second)58 fmt.Println("Unpaused")59 }60}61import (62func main() {63 fmt.Println("Hello World!")64 p := new(Pause)65 p.SetPaused(true)66 fmt.Println(p)67}68type Pause struct {69}70func (p *Pause) SetPaused(paused bool) {71}72func (p *Pause) IsPaused

Full Screen

Full Screen

SetPaused

Using AI Code Generation

copy

Full Screen

1import (2type Test struct {3}4func (t *Test) SetPaused() {5 runtime.GC()6}7func SetPaused() {8 runtime.GC()9}10func main() {11 t = &Test{}12 go func() {13 for {14 t.SetPaused()15 time.Sleep(time.Millisecond * 100)16 }17 }()18 go func() {19 for {20 SetPaused()21 time.Sleep(time.Millisecond * 100)22 }23 }()24 for {25 time.Sleep(time.Second)26 }27}28I am trying to write a simple program in Go. I have a class Test which has a method SetPaused(). I am creating a new instance of the class Test and calling the method SetPaused() on that instance. I am also calling the method SetPaused() on the class Test. I am calling both the methods in a go routine. I am trying to understand the difference between the two methods. I am observing that the method SetPaused() on the class Test is not getting called. I am not sure why this is happening. Can someone please help me understand the difference between the two methods and why one is not getting called?29func main() {30 t = &Test{}31 go func() {32 for {33 t.SetPaused()34 time.Sleep(time.Millisecond * 100)35 }36 }()37 go func() {

Full Screen

Full Screen

SetPaused

Using AI Code Generation

copy

Full Screen

1func SetPaused(pause bool) {2}3func main() {4}5import (6func main() {7}8func SetPaused(pause bool) {9}10import (11func main() {12}13func SetPaused(pause bool) {14}15The 1.go file contains the code that is compiled to a .so file. The 2.go and 3.go files contain the code that is compiled to an executable. The 1.go file contains the code that is shared between the 2.go and 3.go files. The 1.go file can't import the 2.go and 3.go files because they import the 1.go file. This is a circular dependency. This is why the 1.go file is compiled to a .so file

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful